diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-04-05 18:18:00 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-04-05 18:18:00 -0400 |
commit | 64dc9e2e7320f079b97c46b106133b58b8e18d40 (patch) | |
tree | ab010dc1337d44e29c2b32b7f11788620a91fe4f /drivers/usb | |
parent | 01a60e76b6392547ad3dca3ac05b9c886fa5da45 (diff) | |
parent | 9b192de60b5a584ee4ed967fb6758773c75e4643 (diff) |
Merge tag 'usb-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes:
usb: patches for v3.10 merge window
Here is the big Gadget & PHY pull request. Many of us have
been really busy lately getting multiple drivers to a better
position.
Since this pull request is so large, I will divide it in sections
so it's easier to grasp what's included.
- cleanups:
. UDC drivers no longer touch gadget->dev, that's now udc-core
responsibility
. Many more UDC drivers converted to usb_gadget_map/unmap_request()
. UDC drivers no longer initialize DMA-related fields from gadget's
device structure
. UDC drivers don't touch gadget.dev.driver directly
. UDC drivers don't assign gadget.dev.release directly
. Removal of some unused DMA_ADDR_INVALID
. Introduction of CONFIG_USB_PHY
. All phy drivers have been moved to drivers/usb/phy and renamed to
a common naming scheme
. Fix PHY layer so it never returns a NULL pointer, also fix all
callers to avoid using IS_ERR_OR_NULL()
. Sparse fixes all over the place
. drivers/usb/otg/ has been deleted
. Marvel drivers (mv_udc, ehci-mv, mv_otg and mv_u3d) improved clock
usage
- new features:
. UDC core now provides a generic way for tracking and reporting
UDC's state (not attached, resuming, suspended, addressed,
default, etc)
. twl4030-usb learned that it shouldn't be enabled during init
. Full DT support for DWC3 has been implemented
. ab8500-usb learned about pinctrl framework
. nop PHY learned about DeviceTree and regulators
. DWC3 learned about suspend/resume
. DWC3 can now be compiled in host-only and gadget-only (as well as
DRD) configurations
. UVC now enables streaming endpoint based on negotiated speed
. isp1301 now implements the PHY API properly
. configfs-based interface for gadget drivers which will lead to
the removal of all code which just combines functions together
to build functional gadget drivers.
. f_serial and f_obex were converted to new configfs interface while
maintaining old interface around.
- non-critical fixes:
. UVC gadget driver got fixes for Endpoint usage and stream calculation
. ab8500-usb fixed unbalanced clock and regulator API usage
. twl4030-usb got a fix for when OMAP3 is booted with cable connected
. fusb300_udc got a fix for DMA usage
. UVC got fixes for two assertions of the USB Video Class Compliance
specification revision 1.1
. build warning issues caused by recent addition of __must_check to
regulator API
These are all changes which deserve a mention, all other changes are related
to these one or minor spelling fixes and other similar tasks.
Signed-of-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb')
134 files changed, 6364 insertions, 4300 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 640ae6c6d2d2..2c481b808276 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig | |||
@@ -186,6 +186,4 @@ source "drivers/usb/atm/Kconfig" | |||
186 | 186 | ||
187 | source "drivers/usb/gadget/Kconfig" | 187 | source "drivers/usb/gadget/Kconfig" |
188 | 188 | ||
189 | source "drivers/usb/otg/Kconfig" | ||
190 | |||
191 | endif # USB_SUPPORT | 189 | endif # USB_SUPPORT |
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 8f5ebced5df0..c41feba8d5c0 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -6,8 +6,6 @@ | |||
6 | 6 | ||
7 | obj-$(CONFIG_USB) += core/ | 7 | obj-$(CONFIG_USB) += core/ |
8 | 8 | ||
9 | obj-$(CONFIG_USB_OTG_UTILS) += otg/ | ||
10 | |||
11 | obj-$(CONFIG_USB_DWC3) += dwc3/ | 9 | obj-$(CONFIG_USB_DWC3) += dwc3/ |
12 | 10 | ||
13 | obj-$(CONFIG_USB_MON) += mon/ | 11 | obj-$(CONFIG_USB_MON) += mon/ |
@@ -46,7 +44,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/ | |||
46 | obj-$(CONFIG_USB_SERIAL) += serial/ | 44 | obj-$(CONFIG_USB_SERIAL) += serial/ |
47 | 45 | ||
48 | obj-$(CONFIG_USB) += misc/ | 46 | obj-$(CONFIG_USB) += misc/ |
49 | obj-$(CONFIG_USB_OTG_UTILS) += phy/ | 47 | obj-$(CONFIG_USB_PHY) += phy/ |
50 | obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ | 48 | obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ |
51 | 49 | ||
52 | obj-$(CONFIG_USB_ATM) += atm/ | 50 | obj-$(CONFIG_USB_ATM) += atm/ |
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 3d90e6189731..519ead2443c5 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -1639,16 +1639,6 @@ static irqreturn_t udc_irq(struct ci13xxx *ci) | |||
1639 | } | 1639 | } |
1640 | 1640 | ||
1641 | /** | 1641 | /** |
1642 | * udc_release: driver release function | ||
1643 | * @dev: device | ||
1644 | * | ||
1645 | * Currently does nothing | ||
1646 | */ | ||
1647 | static void udc_release(struct device *dev) | ||
1648 | { | ||
1649 | } | ||
1650 | |||
1651 | /** | ||
1652 | * udc_start: initialize gadget role | 1642 | * udc_start: initialize gadget role |
1653 | * @ci: chipidea controller | 1643 | * @ci: chipidea controller |
1654 | */ | 1644 | */ |
@@ -1667,12 +1657,6 @@ static int udc_start(struct ci13xxx *ci) | |||
1667 | 1657 | ||
1668 | INIT_LIST_HEAD(&ci->gadget.ep_list); | 1658 | INIT_LIST_HEAD(&ci->gadget.ep_list); |
1669 | 1659 | ||
1670 | dev_set_name(&ci->gadget.dev, "gadget"); | ||
1671 | ci->gadget.dev.dma_mask = dev->dma_mask; | ||
1672 | ci->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask; | ||
1673 | ci->gadget.dev.parent = dev; | ||
1674 | ci->gadget.dev.release = udc_release; | ||
1675 | |||
1676 | /* alloc resources */ | 1660 | /* alloc resources */ |
1677 | ci->qh_pool = dma_pool_create("ci13xxx_qh", dev, | 1661 | ci->qh_pool = dma_pool_create("ci13xxx_qh", dev, |
1678 | sizeof(struct ci13xxx_qh), | 1662 | sizeof(struct ci13xxx_qh), |
@@ -1710,17 +1694,11 @@ static int udc_start(struct ci13xxx *ci) | |||
1710 | goto put_transceiver; | 1694 | goto put_transceiver; |
1711 | } | 1695 | } |
1712 | 1696 | ||
1713 | retval = device_register(&ci->gadget.dev); | ||
1714 | if (retval) { | ||
1715 | put_device(&ci->gadget.dev); | ||
1716 | goto put_transceiver; | ||
1717 | } | ||
1718 | |||
1719 | if (!IS_ERR_OR_NULL(ci->transceiver)) { | 1697 | if (!IS_ERR_OR_NULL(ci->transceiver)) { |
1720 | retval = otg_set_peripheral(ci->transceiver->otg, | 1698 | retval = otg_set_peripheral(ci->transceiver->otg, |
1721 | &ci->gadget); | 1699 | &ci->gadget); |
1722 | if (retval) | 1700 | if (retval) |
1723 | goto unreg_device; | 1701 | goto put_transceiver; |
1724 | } | 1702 | } |
1725 | 1703 | ||
1726 | retval = usb_add_gadget_udc(dev, &ci->gadget); | 1704 | retval = usb_add_gadget_udc(dev, &ci->gadget); |
@@ -1740,8 +1718,6 @@ remove_trans: | |||
1740 | } | 1718 | } |
1741 | 1719 | ||
1742 | dev_err(dev, "error = %i\n", retval); | 1720 | dev_err(dev, "error = %i\n", retval); |
1743 | unreg_device: | ||
1744 | device_unregister(&ci->gadget.dev); | ||
1745 | put_transceiver: | 1721 | put_transceiver: |
1746 | if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy) | 1722 | if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy) |
1747 | usb_put_phy(ci->transceiver); | 1723 | usb_put_phy(ci->transceiver); |
@@ -1776,7 +1752,6 @@ static void udc_stop(struct ci13xxx *ci) | |||
1776 | if (ci->global_phy) | 1752 | if (ci->global_phy) |
1777 | usb_put_phy(ci->transceiver); | 1753 | usb_put_phy(ci->transceiver); |
1778 | } | 1754 | } |
1779 | device_unregister(&ci->gadget.dev); | ||
1780 | /* my kobject is dynamic, I swear! */ | 1755 | /* my kobject is dynamic, I swear! */ |
1781 | memset(&ci->gadget, 0, sizeof(ci->gadget)); | 1756 | memset(&ci->gadget, 0, sizeof(ci->gadget)); |
1782 | } | 1757 | } |
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 68e9a2c5a01a..ea5ee9c21c35 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig | |||
@@ -1,7 +1,6 @@ | |||
1 | config USB_DWC3 | 1 | config USB_DWC3 |
2 | tristate "DesignWare USB3 DRD Core Support" | 2 | tristate "DesignWare USB3 DRD Core Support" |
3 | depends on (USB || USB_GADGET) && GENERIC_HARDIRQS | 3 | depends on (USB || USB_GADGET) && GENERIC_HARDIRQS |
4 | select USB_OTG_UTILS | ||
5 | select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD | 4 | select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD |
6 | help | 5 | help |
7 | Say Y or M here if your system has a Dual Role SuperSpeed | 6 | Say Y or M here if your system has a Dual Role SuperSpeed |
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index ffa6b004a84b..c35d49d39b76 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -140,7 +140,8 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc, | |||
140 | * Returns a pointer to the allocated event buffer structure on success | 140 | * Returns a pointer to the allocated event buffer structure on success |
141 | * otherwise ERR_PTR(errno). | 141 | * otherwise ERR_PTR(errno). |
142 | */ | 142 | */ |
143 | static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) | 143 | static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, |
144 | unsigned length) | ||
144 | { | 145 | { |
145 | struct dwc3_event_buffer *evt; | 146 | struct dwc3_event_buffer *evt; |
146 | 147 | ||
@@ -259,6 +260,17 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc) | |||
259 | } | 260 | } |
260 | } | 261 | } |
261 | 262 | ||
263 | static void dwc3_core_num_eps(struct dwc3 *dwc) | ||
264 | { | ||
265 | struct dwc3_hwparams *parms = &dwc->hwparams; | ||
266 | |||
267 | dwc->num_in_eps = DWC3_NUM_IN_EPS(parms); | ||
268 | dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps; | ||
269 | |||
270 | dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n", | ||
271 | dwc->num_in_eps, dwc->num_out_eps); | ||
272 | } | ||
273 | |||
262 | static void dwc3_cache_hwparams(struct dwc3 *dwc) | 274 | static void dwc3_cache_hwparams(struct dwc3 *dwc) |
263 | { | 275 | { |
264 | struct dwc3_hwparams *parms = &dwc->hwparams; | 276 | struct dwc3_hwparams *parms = &dwc->hwparams; |
@@ -335,13 +347,9 @@ static int dwc3_core_init(struct dwc3 *dwc) | |||
335 | if (dwc->revision < DWC3_REVISION_190A) | 347 | if (dwc->revision < DWC3_REVISION_190A) |
336 | reg |= DWC3_GCTL_U2RSTECN; | 348 | reg |= DWC3_GCTL_U2RSTECN; |
337 | 349 | ||
338 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); | 350 | dwc3_core_num_eps(dwc); |
339 | 351 | ||
340 | ret = dwc3_event_buffers_setup(dwc); | 352 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
341 | if (ret) { | ||
342 | dev_err(dwc->dev, "failed to setup event buffers\n"); | ||
343 | goto err0; | ||
344 | } | ||
345 | 353 | ||
346 | return 0; | 354 | return 0; |
347 | 355 | ||
@@ -351,8 +359,6 @@ err0: | |||
351 | 359 | ||
352 | static void dwc3_core_exit(struct dwc3 *dwc) | 360 | static void dwc3_core_exit(struct dwc3 *dwc) |
353 | { | 361 | { |
354 | dwc3_event_buffers_cleanup(dwc); | ||
355 | |||
356 | usb_phy_shutdown(dwc->usb2_phy); | 362 | usb_phy_shutdown(dwc->usb2_phy); |
357 | usb_phy_shutdown(dwc->usb3_phy); | 363 | usb_phy_shutdown(dwc->usb3_phy); |
358 | } | 364 | } |
@@ -428,12 +434,32 @@ static int dwc3_probe(struct platform_device *pdev) | |||
428 | dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); | 434 | dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); |
429 | } | 435 | } |
430 | 436 | ||
431 | if (IS_ERR_OR_NULL(dwc->usb2_phy)) { | 437 | if (IS_ERR(dwc->usb2_phy)) { |
438 | ret = PTR_ERR(dwc->usb2_phy); | ||
439 | |||
440 | /* | ||
441 | * if -ENXIO is returned, it means PHY layer wasn't | ||
442 | * enabled, so it makes no sense to return -EPROBE_DEFER | ||
443 | * in that case, since no PHY driver will ever probe. | ||
444 | */ | ||
445 | if (ret == -ENXIO) | ||
446 | return ret; | ||
447 | |||
432 | dev_err(dev, "no usb2 phy configured\n"); | 448 | dev_err(dev, "no usb2 phy configured\n"); |
433 | return -EPROBE_DEFER; | 449 | return -EPROBE_DEFER; |
434 | } | 450 | } |
435 | 451 | ||
436 | if (IS_ERR_OR_NULL(dwc->usb3_phy)) { | 452 | if (IS_ERR(dwc->usb3_phy)) { |
453 | ret = PTR_ERR(dwc->usb2_phy); | ||
454 | |||
455 | /* | ||
456 | * if -ENXIO is returned, it means PHY layer wasn't | ||
457 | * enabled, so it makes no sense to return -EPROBE_DEFER | ||
458 | * in that case, since no PHY driver will ever probe. | ||
459 | */ | ||
460 | if (ret == -ENXIO) | ||
461 | return ret; | ||
462 | |||
437 | dev_err(dev, "no usb3 phy configured\n"); | 463 | dev_err(dev, "no usb3 phy configured\n"); |
438 | return -EPROBE_DEFER; | 464 | return -EPROBE_DEFER; |
439 | } | 465 | } |
@@ -448,6 +474,10 @@ static int dwc3_probe(struct platform_device *pdev) | |||
448 | dwc->regs_size = resource_size(res); | 474 | dwc->regs_size = resource_size(res); |
449 | dwc->dev = dev; | 475 | dwc->dev = dev; |
450 | 476 | ||
477 | dev->dma_mask = dev->parent->dma_mask; | ||
478 | dev->dma_parms = dev->parent->dma_parms; | ||
479 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); | ||
480 | |||
451 | if (!strncmp("super", maximum_speed, 5)) | 481 | if (!strncmp("super", maximum_speed, 5)) |
452 | dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; | 482 | dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; |
453 | else if (!strncmp("high", maximum_speed, 4)) | 483 | else if (!strncmp("high", maximum_speed, 4)) |
@@ -480,7 +510,18 @@ static int dwc3_probe(struct platform_device *pdev) | |||
480 | goto err0; | 510 | goto err0; |
481 | } | 511 | } |
482 | 512 | ||
483 | mode = DWC3_MODE(dwc->hwparams.hwparams0); | 513 | ret = dwc3_event_buffers_setup(dwc); |
514 | if (ret) { | ||
515 | dev_err(dwc->dev, "failed to setup event buffers\n"); | ||
516 | goto err1; | ||
517 | } | ||
518 | |||
519 | if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) | ||
520 | mode = DWC3_MODE_HOST; | ||
521 | else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) | ||
522 | mode = DWC3_MODE_DEVICE; | ||
523 | else | ||
524 | mode = DWC3_MODE_DRD; | ||
484 | 525 | ||
485 | switch (mode) { | 526 | switch (mode) { |
486 | case DWC3_MODE_DEVICE: | 527 | case DWC3_MODE_DEVICE: |
@@ -488,7 +529,7 @@ static int dwc3_probe(struct platform_device *pdev) | |||
488 | ret = dwc3_gadget_init(dwc); | 529 | ret = dwc3_gadget_init(dwc); |
489 | if (ret) { | 530 | if (ret) { |
490 | dev_err(dev, "failed to initialize gadget\n"); | 531 | dev_err(dev, "failed to initialize gadget\n"); |
491 | goto err1; | 532 | goto err2; |
492 | } | 533 | } |
493 | break; | 534 | break; |
494 | case DWC3_MODE_HOST: | 535 | case DWC3_MODE_HOST: |
@@ -496,7 +537,7 @@ static int dwc3_probe(struct platform_device *pdev) | |||
496 | ret = dwc3_host_init(dwc); | 537 | ret = dwc3_host_init(dwc); |
497 | if (ret) { | 538 | if (ret) { |
498 | dev_err(dev, "failed to initialize host\n"); | 539 | dev_err(dev, "failed to initialize host\n"); |
499 | goto err1; | 540 | goto err2; |
500 | } | 541 | } |
501 | break; | 542 | break; |
502 | case DWC3_MODE_DRD: | 543 | case DWC3_MODE_DRD: |
@@ -504,32 +545,32 @@ static int dwc3_probe(struct platform_device *pdev) | |||
504 | ret = dwc3_host_init(dwc); | 545 | ret = dwc3_host_init(dwc); |
505 | if (ret) { | 546 | if (ret) { |
506 | dev_err(dev, "failed to initialize host\n"); | 547 | dev_err(dev, "failed to initialize host\n"); |
507 | goto err1; | 548 | goto err2; |
508 | } | 549 | } |
509 | 550 | ||
510 | ret = dwc3_gadget_init(dwc); | 551 | ret = dwc3_gadget_init(dwc); |
511 | if (ret) { | 552 | if (ret) { |
512 | dev_err(dev, "failed to initialize gadget\n"); | 553 | dev_err(dev, "failed to initialize gadget\n"); |
513 | goto err1; | 554 | goto err2; |
514 | } | 555 | } |
515 | break; | 556 | break; |
516 | default: | 557 | default: |
517 | dev_err(dev, "Unsupported mode of operation %d\n", mode); | 558 | dev_err(dev, "Unsupported mode of operation %d\n", mode); |
518 | goto err1; | 559 | goto err2; |
519 | } | 560 | } |
520 | dwc->mode = mode; | 561 | dwc->mode = mode; |
521 | 562 | ||
522 | ret = dwc3_debugfs_init(dwc); | 563 | ret = dwc3_debugfs_init(dwc); |
523 | if (ret) { | 564 | if (ret) { |
524 | dev_err(dev, "failed to initialize debugfs\n"); | 565 | dev_err(dev, "failed to initialize debugfs\n"); |
525 | goto err2; | 566 | goto err3; |
526 | } | 567 | } |
527 | 568 | ||
528 | pm_runtime_allow(dev); | 569 | pm_runtime_allow(dev); |
529 | 570 | ||
530 | return 0; | 571 | return 0; |
531 | 572 | ||
532 | err2: | 573 | err3: |
533 | switch (mode) { | 574 | switch (mode) { |
534 | case DWC3_MODE_DEVICE: | 575 | case DWC3_MODE_DEVICE: |
535 | dwc3_gadget_exit(dwc); | 576 | dwc3_gadget_exit(dwc); |
@@ -546,6 +587,9 @@ err2: | |||
546 | break; | 587 | break; |
547 | } | 588 | } |
548 | 589 | ||
590 | err2: | ||
591 | dwc3_event_buffers_cleanup(dwc); | ||
592 | |||
549 | err1: | 593 | err1: |
550 | dwc3_core_exit(dwc); | 594 | dwc3_core_exit(dwc); |
551 | 595 | ||
@@ -583,12 +627,130 @@ static int dwc3_remove(struct platform_device *pdev) | |||
583 | break; | 627 | break; |
584 | } | 628 | } |
585 | 629 | ||
630 | dwc3_event_buffers_cleanup(dwc); | ||
586 | dwc3_free_event_buffers(dwc); | 631 | dwc3_free_event_buffers(dwc); |
587 | dwc3_core_exit(dwc); | 632 | dwc3_core_exit(dwc); |
588 | 633 | ||
589 | return 0; | 634 | return 0; |
590 | } | 635 | } |
591 | 636 | ||
637 | #ifdef CONFIG_PM_SLEEP | ||
638 | static int dwc3_prepare(struct device *dev) | ||
639 | { | ||
640 | struct dwc3 *dwc = dev_get_drvdata(dev); | ||
641 | unsigned long flags; | ||
642 | |||
643 | spin_lock_irqsave(&dwc->lock, flags); | ||
644 | |||
645 | switch (dwc->mode) { | ||
646 | case DWC3_MODE_DEVICE: | ||
647 | case DWC3_MODE_DRD: | ||
648 | dwc3_gadget_prepare(dwc); | ||
649 | /* FALLTHROUGH */ | ||
650 | case DWC3_MODE_HOST: | ||
651 | default: | ||
652 | dwc3_event_buffers_cleanup(dwc); | ||
653 | break; | ||
654 | } | ||
655 | |||
656 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
657 | |||
658 | return 0; | ||
659 | } | ||
660 | |||
661 | static void dwc3_complete(struct device *dev) | ||
662 | { | ||
663 | struct dwc3 *dwc = dev_get_drvdata(dev); | ||
664 | unsigned long flags; | ||
665 | |||
666 | spin_lock_irqsave(&dwc->lock, flags); | ||
667 | |||
668 | switch (dwc->mode) { | ||
669 | case DWC3_MODE_DEVICE: | ||
670 | case DWC3_MODE_DRD: | ||
671 | dwc3_gadget_complete(dwc); | ||
672 | /* FALLTHROUGH */ | ||
673 | case DWC3_MODE_HOST: | ||
674 | default: | ||
675 | dwc3_event_buffers_setup(dwc); | ||
676 | break; | ||
677 | } | ||
678 | |||
679 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
680 | } | ||
681 | |||
682 | static int dwc3_suspend(struct device *dev) | ||
683 | { | ||
684 | struct dwc3 *dwc = dev_get_drvdata(dev); | ||
685 | unsigned long flags; | ||
686 | |||
687 | spin_lock_irqsave(&dwc->lock, flags); | ||
688 | |||
689 | switch (dwc->mode) { | ||
690 | case DWC3_MODE_DEVICE: | ||
691 | case DWC3_MODE_DRD: | ||
692 | dwc3_gadget_suspend(dwc); | ||
693 | /* FALLTHROUGH */ | ||
694 | case DWC3_MODE_HOST: | ||
695 | default: | ||
696 | /* do nothing */ | ||
697 | break; | ||
698 | } | ||
699 | |||
700 | dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL); | ||
701 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
702 | |||
703 | usb_phy_shutdown(dwc->usb3_phy); | ||
704 | usb_phy_shutdown(dwc->usb2_phy); | ||
705 | |||
706 | return 0; | ||
707 | } | ||
708 | |||
709 | static int dwc3_resume(struct device *dev) | ||
710 | { | ||
711 | struct dwc3 *dwc = dev_get_drvdata(dev); | ||
712 | unsigned long flags; | ||
713 | |||
714 | usb_phy_init(dwc->usb3_phy); | ||
715 | usb_phy_init(dwc->usb2_phy); | ||
716 | msleep(100); | ||
717 | |||
718 | spin_lock_irqsave(&dwc->lock, flags); | ||
719 | |||
720 | dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); | ||
721 | |||
722 | switch (dwc->mode) { | ||
723 | case DWC3_MODE_DEVICE: | ||
724 | case DWC3_MODE_DRD: | ||
725 | dwc3_gadget_resume(dwc); | ||
726 | /* FALLTHROUGH */ | ||
727 | case DWC3_MODE_HOST: | ||
728 | default: | ||
729 | /* do nothing */ | ||
730 | break; | ||
731 | } | ||
732 | |||
733 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
734 | |||
735 | pm_runtime_disable(dev); | ||
736 | pm_runtime_set_active(dev); | ||
737 | pm_runtime_enable(dev); | ||
738 | |||
739 | return 0; | ||
740 | } | ||
741 | |||
742 | static const struct dev_pm_ops dwc3_dev_pm_ops = { | ||
743 | .prepare = dwc3_prepare, | ||
744 | .complete = dwc3_complete, | ||
745 | |||
746 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) | ||
747 | }; | ||
748 | |||
749 | #define DWC3_PM_OPS &(dwc3_dev_pm_ops) | ||
750 | #else | ||
751 | #define DWC3_PM_OPS NULL | ||
752 | #endif | ||
753 | |||
592 | #ifdef CONFIG_OF | 754 | #ifdef CONFIG_OF |
593 | static const struct of_device_id of_dwc3_match[] = { | 755 | static const struct of_device_id of_dwc3_match[] = { |
594 | { | 756 | { |
@@ -605,6 +767,7 @@ static struct platform_driver dwc3_driver = { | |||
605 | .driver = { | 767 | .driver = { |
606 | .name = "dwc3", | 768 | .name = "dwc3", |
607 | .of_match_table = of_match_ptr(of_dwc3_match), | 769 | .of_match_table = of_match_ptr(of_dwc3_match), |
770 | .pm = DWC3_PM_OPS, | ||
608 | }, | 771 | }, |
609 | }; | 772 | }; |
610 | 773 | ||
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index b41750660235..b69d322e3cab 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h | |||
@@ -154,8 +154,9 @@ | |||
154 | /* OTG Registers */ | 154 | /* OTG Registers */ |
155 | #define DWC3_OCFG 0xcc00 | 155 | #define DWC3_OCFG 0xcc00 |
156 | #define DWC3_OCTL 0xcc04 | 156 | #define DWC3_OCTL 0xcc04 |
157 | #define DWC3_OEVTEN 0xcc08 | 157 | #define DWC3_OEVT 0xcc08 |
158 | #define DWC3_OSTS 0xcc0C | 158 | #define DWC3_OEVTEN 0xcc0C |
159 | #define DWC3_OSTS 0xcc10 | ||
159 | 160 | ||
160 | /* Bit fields */ | 161 | /* Bit fields */ |
161 | 162 | ||
@@ -369,6 +370,9 @@ struct dwc3_trb; | |||
369 | * @list: a list of event buffers | 370 | * @list: a list of event buffers |
370 | * @buf: _THE_ buffer | 371 | * @buf: _THE_ buffer |
371 | * @length: size of this buffer | 372 | * @length: size of this buffer |
373 | * @lpos: event offset | ||
374 | * @count: cache of last read event count register | ||
375 | * @flags: flags related to this event buffer | ||
372 | * @dma: dma_addr_t | 376 | * @dma: dma_addr_t |
373 | * @dwc: pointer to DWC controller | 377 | * @dwc: pointer to DWC controller |
374 | */ | 378 | */ |
@@ -376,6 +380,10 @@ struct dwc3_event_buffer { | |||
376 | void *buf; | 380 | void *buf; |
377 | unsigned length; | 381 | unsigned length; |
378 | unsigned int lpos; | 382 | unsigned int lpos; |
383 | unsigned int count; | ||
384 | unsigned int flags; | ||
385 | |||
386 | #define DWC3_EVENT_PENDING BIT(0) | ||
379 | 387 | ||
380 | dma_addr_t dma; | 388 | dma_addr_t dma; |
381 | 389 | ||
@@ -487,12 +495,6 @@ enum dwc3_link_state { | |||
487 | DWC3_LINK_STATE_MASK = 0x0f, | 495 | DWC3_LINK_STATE_MASK = 0x0f, |
488 | }; | 496 | }; |
489 | 497 | ||
490 | enum dwc3_device_state { | ||
491 | DWC3_DEFAULT_STATE, | ||
492 | DWC3_ADDRESS_STATE, | ||
493 | DWC3_CONFIGURED_STATE, | ||
494 | }; | ||
495 | |||
496 | /* TRB Length, PCM and Status */ | 498 | /* TRB Length, PCM and Status */ |
497 | #define DWC3_TRB_SIZE_MASK (0x00ffffff) | 499 | #define DWC3_TRB_SIZE_MASK (0x00ffffff) |
498 | #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) | 500 | #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) |
@@ -574,6 +576,14 @@ struct dwc3_hwparams { | |||
574 | /* HWPARAMS1 */ | 576 | /* HWPARAMS1 */ |
575 | #define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15) | 577 | #define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15) |
576 | 578 | ||
579 | /* HWPARAMS3 */ | ||
580 | #define DWC3_NUM_IN_EPS_MASK (0x1f << 18) | ||
581 | #define DWC3_NUM_EPS_MASK (0x3f << 12) | ||
582 | #define DWC3_NUM_EPS(p) (((p)->hwparams3 & \ | ||
583 | (DWC3_NUM_EPS_MASK)) >> 12) | ||
584 | #define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \ | ||
585 | (DWC3_NUM_IN_EPS_MASK)) >> 18) | ||
586 | |||
577 | /* HWPARAMS7 */ | 587 | /* HWPARAMS7 */ |
578 | #define DWC3_RAM1_DEPTH(n) ((n) & 0xffff) | 588 | #define DWC3_RAM1_DEPTH(n) ((n) & 0xffff) |
579 | 589 | ||
@@ -618,7 +628,6 @@ struct dwc3_scratchpad_array { | |||
618 | * @gadget_driver: pointer to the gadget driver | 628 | * @gadget_driver: pointer to the gadget driver |
619 | * @regs: base address for our registers | 629 | * @regs: base address for our registers |
620 | * @regs_size: address space size | 630 | * @regs_size: address space size |
621 | * @irq: IRQ number | ||
622 | * @num_event_buffers: calculated number of event buffers | 631 | * @num_event_buffers: calculated number of event buffers |
623 | * @u1u2: only used on revisions <1.83a for workaround | 632 | * @u1u2: only used on revisions <1.83a for workaround |
624 | * @maximum_speed: maximum speed requested (mainly for testing purposes) | 633 | * @maximum_speed: maximum speed requested (mainly for testing purposes) |
@@ -626,6 +635,8 @@ struct dwc3_scratchpad_array { | |||
626 | * @mode: mode of operation | 635 | * @mode: mode of operation |
627 | * @usb2_phy: pointer to USB2 PHY | 636 | * @usb2_phy: pointer to USB2 PHY |
628 | * @usb3_phy: pointer to USB3 PHY | 637 | * @usb3_phy: pointer to USB3 PHY |
638 | * @dcfg: saved contents of DCFG register | ||
639 | * @gctl: saved contents of GCTL register | ||
629 | * @is_selfpowered: true when we are selfpowered | 640 | * @is_selfpowered: true when we are selfpowered |
630 | * @three_stage_setup: set if we perform a three phase setup | 641 | * @three_stage_setup: set if we perform a three phase setup |
631 | * @ep0_bounced: true when we used bounce buffer | 642 | * @ep0_bounced: true when we used bounce buffer |
@@ -639,6 +650,8 @@ struct dwc3_scratchpad_array { | |||
639 | * @u2pel: parameter from Set SEL request. | 650 | * @u2pel: parameter from Set SEL request. |
640 | * @u1sel: parameter from Set SEL request. | 651 | * @u1sel: parameter from Set SEL request. |
641 | * @u1pel: parameter from Set SEL request. | 652 | * @u1pel: parameter from Set SEL request. |
653 | * @num_out_eps: number of out endpoints | ||
654 | * @num_in_eps: number of in endpoints | ||
642 | * @ep0_next_event: hold the next expected event | 655 | * @ep0_next_event: hold the next expected event |
643 | * @ep0state: state of endpoint zero | 656 | * @ep0state: state of endpoint zero |
644 | * @link_state: link state | 657 | * @link_state: link state |
@@ -656,8 +669,10 @@ struct dwc3 { | |||
656 | dma_addr_t ep0_trb_addr; | 669 | dma_addr_t ep0_trb_addr; |
657 | dma_addr_t ep0_bounce_addr; | 670 | dma_addr_t ep0_bounce_addr; |
658 | struct dwc3_request ep0_usb_req; | 671 | struct dwc3_request ep0_usb_req; |
672 | |||
659 | /* device lock */ | 673 | /* device lock */ |
660 | spinlock_t lock; | 674 | spinlock_t lock; |
675 | |||
661 | struct device *dev; | 676 | struct device *dev; |
662 | 677 | ||
663 | struct platform_device *xhci; | 678 | struct platform_device *xhci; |
@@ -675,6 +690,10 @@ struct dwc3 { | |||
675 | void __iomem *regs; | 690 | void __iomem *regs; |
676 | size_t regs_size; | 691 | size_t regs_size; |
677 | 692 | ||
693 | /* used for suspend/resume */ | ||
694 | u32 dcfg; | ||
695 | u32 gctl; | ||
696 | |||
678 | u32 num_event_buffers; | 697 | u32 num_event_buffers; |
679 | u32 u1u2; | 698 | u32 u1u2; |
680 | u32 maximum_speed; | 699 | u32 maximum_speed; |
@@ -694,6 +713,9 @@ struct dwc3 { | |||
694 | #define DWC3_REVISION_202A 0x5533202a | 713 | #define DWC3_REVISION_202A 0x5533202a |
695 | #define DWC3_REVISION_210A 0x5533210a | 714 | #define DWC3_REVISION_210A 0x5533210a |
696 | #define DWC3_REVISION_220A 0x5533220a | 715 | #define DWC3_REVISION_220A 0x5533220a |
716 | #define DWC3_REVISION_230A 0x5533230a | ||
717 | #define DWC3_REVISION_240A 0x5533240a | ||
718 | #define DWC3_REVISION_250A 0x5533250a | ||
697 | 719 | ||
698 | unsigned is_selfpowered:1; | 720 | unsigned is_selfpowered:1; |
699 | unsigned three_stage_setup:1; | 721 | unsigned three_stage_setup:1; |
@@ -704,11 +726,11 @@ struct dwc3 { | |||
704 | unsigned delayed_status:1; | 726 | unsigned delayed_status:1; |
705 | unsigned needs_fifo_resize:1; | 727 | unsigned needs_fifo_resize:1; |
706 | unsigned resize_fifos:1; | 728 | unsigned resize_fifos:1; |
729 | unsigned pullups_connected:1; | ||
707 | 730 | ||
708 | enum dwc3_ep0_next ep0_next_event; | 731 | enum dwc3_ep0_next ep0_next_event; |
709 | enum dwc3_ep0_state ep0state; | 732 | enum dwc3_ep0_state ep0state; |
710 | enum dwc3_link_state link_state; | 733 | enum dwc3_link_state link_state; |
711 | enum dwc3_device_state dev_state; | ||
712 | 734 | ||
713 | u16 isoch_delay; | 735 | u16 isoch_delay; |
714 | u16 u2sel; | 736 | u16 u2sel; |
@@ -718,6 +740,9 @@ struct dwc3 { | |||
718 | 740 | ||
719 | u8 speed; | 741 | u8 speed; |
720 | 742 | ||
743 | u8 num_out_eps; | ||
744 | u8 num_in_eps; | ||
745 | |||
721 | void *mem; | 746 | void *mem; |
722 | 747 | ||
723 | struct dwc3_hwparams hwparams; | 748 | struct dwc3_hwparams hwparams; |
@@ -884,4 +909,31 @@ static inline void dwc3_gadget_exit(struct dwc3 *dwc) | |||
884 | { } | 909 | { } |
885 | #endif | 910 | #endif |
886 | 911 | ||
912 | /* power management interface */ | ||
913 | #if !IS_ENABLED(CONFIG_USB_DWC3_HOST) | ||
914 | int dwc3_gadget_prepare(struct dwc3 *dwc); | ||
915 | void dwc3_gadget_complete(struct dwc3 *dwc); | ||
916 | int dwc3_gadget_suspend(struct dwc3 *dwc); | ||
917 | int dwc3_gadget_resume(struct dwc3 *dwc); | ||
918 | #else | ||
919 | static inline int dwc3_gadget_prepare(struct dwc3 *dwc) | ||
920 | { | ||
921 | return 0; | ||
922 | } | ||
923 | |||
924 | static inline void dwc3_gadget_complete(struct dwc3 *dwc) | ||
925 | { | ||
926 | } | ||
927 | |||
928 | static inline int dwc3_gadget_suspend(struct dwc3 *dwc) | ||
929 | { | ||
930 | return 0; | ||
931 | } | ||
932 | |||
933 | static inline int dwc3_gadget_resume(struct dwc3 *dwc) | ||
934 | { | ||
935 | return 0; | ||
936 | } | ||
937 | #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */ | ||
938 | |||
887 | #endif /* __DRIVERS_USB_DWC3_CORE_H */ | 939 | #endif /* __DRIVERS_USB_DWC3_CORE_H */ |
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index 4a752e730c5f..9e9f122162f2 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c | |||
@@ -59,7 +59,7 @@ | |||
59 | .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \ | 59 | .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \ |
60 | } | 60 | } |
61 | 61 | ||
62 | static struct debugfs_reg32 dwc3_regs[] = { | 62 | static const struct debugfs_reg32 dwc3_regs[] = { |
63 | dump_register(GSBUSCFG0), | 63 | dump_register(GSBUSCFG0), |
64 | dump_register(GSBUSCFG1), | 64 | dump_register(GSBUSCFG1), |
65 | dump_register(GTXTHRCFG), | 65 | dump_register(GTXTHRCFG), |
@@ -372,6 +372,7 @@ static struct debugfs_reg32 dwc3_regs[] = { | |||
372 | 372 | ||
373 | dump_register(OCFG), | 373 | dump_register(OCFG), |
374 | dump_register(OCTL), | 374 | dump_register(OCTL), |
375 | dump_register(OEVT), | ||
375 | dump_register(OEVTEN), | 376 | dump_register(OEVTEN), |
376 | dump_register(OSTS), | 377 | dump_register(OSTS), |
377 | }; | 378 | }; |
@@ -577,8 +578,14 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) | |||
577 | case DWC3_LINK_STATE_LPBK: | 578 | case DWC3_LINK_STATE_LPBK: |
578 | seq_printf(s, "Loopback\n"); | 579 | seq_printf(s, "Loopback\n"); |
579 | break; | 580 | break; |
581 | case DWC3_LINK_STATE_RESET: | ||
582 | seq_printf(s, "Reset\n"); | ||
583 | break; | ||
584 | case DWC3_LINK_STATE_RESUME: | ||
585 | seq_printf(s, "Resume\n"); | ||
586 | break; | ||
580 | default: | 587 | default: |
581 | seq_printf(s, "UNKNOWN %d\n", reg); | 588 | seq_printf(s, "UNKNOWN %d\n", state); |
582 | } | 589 | } |
583 | 590 | ||
584 | return 0; | 591 | return 0; |
@@ -661,28 +668,31 @@ int dwc3_debugfs_init(struct dwc3 *dwc) | |||
661 | goto err1; | 668 | goto err1; |
662 | } | 669 | } |
663 | 670 | ||
664 | #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) | 671 | if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) { |
665 | file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, | 672 | file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, |
666 | dwc, &dwc3_mode_fops); | 673 | dwc, &dwc3_mode_fops); |
667 | if (!file) { | 674 | if (!file) { |
668 | ret = -ENOMEM; | 675 | ret = -ENOMEM; |
669 | goto err1; | 676 | goto err1; |
670 | } | 677 | } |
671 | |||
672 | file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root, | ||
673 | dwc, &dwc3_testmode_fops); | ||
674 | if (!file) { | ||
675 | ret = -ENOMEM; | ||
676 | goto err1; | ||
677 | } | 678 | } |
678 | 679 | ||
679 | file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, | 680 | if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) || |
680 | dwc, &dwc3_link_state_fops); | 681 | IS_ENABLED(CONFIG_USB_DWC3_GADGET)) { |
681 | if (!file) { | 682 | file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root, |
682 | ret = -ENOMEM; | 683 | dwc, &dwc3_testmode_fops); |
683 | goto err1; | 684 | if (!file) { |
685 | ret = -ENOMEM; | ||
686 | goto err1; | ||
687 | } | ||
688 | |||
689 | file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, | ||
690 | dwc, &dwc3_link_state_fops); | ||
691 | if (!file) { | ||
692 | ret = -ENOMEM; | ||
693 | goto err1; | ||
694 | } | ||
684 | } | 695 | } |
685 | #endif | ||
686 | 696 | ||
687 | return 0; | 697 | return 0; |
688 | 698 | ||
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index b082bec7343e..a8afe6e26621 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c | |||
@@ -22,9 +22,9 @@ | |||
22 | #include <linux/usb/otg.h> | 22 | #include <linux/usb/otg.h> |
23 | #include <linux/usb/nop-usb-xceiv.h> | 23 | #include <linux/usb/nop-usb-xceiv.h> |
24 | #include <linux/of.h> | 24 | #include <linux/of.h> |
25 | #include <linux/of_platform.h> | ||
25 | 26 | ||
26 | struct dwc3_exynos { | 27 | struct dwc3_exynos { |
27 | struct platform_device *dwc3; | ||
28 | struct platform_device *usb2_phy; | 28 | struct platform_device *usb2_phy; |
29 | struct platform_device *usb3_phy; | 29 | struct platform_device *usb3_phy; |
30 | struct device *dev; | 30 | struct device *dev; |
@@ -86,21 +86,30 @@ err1: | |||
86 | return ret; | 86 | return ret; |
87 | } | 87 | } |
88 | 88 | ||
89 | static int dwc3_exynos_remove_child(struct device *dev, void *unused) | ||
90 | { | ||
91 | struct platform_device *pdev = to_platform_device(dev); | ||
92 | |||
93 | platform_device_unregister(pdev); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
89 | static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); | 98 | static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); |
90 | 99 | ||
91 | static int dwc3_exynos_probe(struct platform_device *pdev) | 100 | static int dwc3_exynos_probe(struct platform_device *pdev) |
92 | { | 101 | { |
93 | struct platform_device *dwc3; | ||
94 | struct dwc3_exynos *exynos; | 102 | struct dwc3_exynos *exynos; |
95 | struct clk *clk; | 103 | struct clk *clk; |
96 | struct device *dev = &pdev->dev; | 104 | struct device *dev = &pdev->dev; |
105 | struct device_node *node = dev->of_node; | ||
97 | 106 | ||
98 | int ret = -ENOMEM; | 107 | int ret = -ENOMEM; |
99 | 108 | ||
100 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); | 109 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); |
101 | if (!exynos) { | 110 | if (!exynos) { |
102 | dev_err(dev, "not enough memory\n"); | 111 | dev_err(dev, "not enough memory\n"); |
103 | return -ENOMEM; | 112 | goto err1; |
104 | } | 113 | } |
105 | 114 | ||
106 | /* | 115 | /* |
@@ -108,21 +117,15 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
108 | * Since shared usb code relies on it, set it here for now. | 117 | * Since shared usb code relies on it, set it here for now. |
109 | * Once we move to full device tree support this will vanish off. | 118 | * Once we move to full device tree support this will vanish off. |
110 | */ | 119 | */ |
111 | if (!pdev->dev.dma_mask) | 120 | if (!dev->dma_mask) |
112 | pdev->dev.dma_mask = &dwc3_exynos_dma_mask; | 121 | dev->dma_mask = &dwc3_exynos_dma_mask; |
113 | 122 | ||
114 | platform_set_drvdata(pdev, exynos); | 123 | platform_set_drvdata(pdev, exynos); |
115 | 124 | ||
116 | ret = dwc3_exynos_register_phys(exynos); | 125 | ret = dwc3_exynos_register_phys(exynos); |
117 | if (ret) { | 126 | if (ret) { |
118 | dev_err(dev, "couldn't register PHYs\n"); | 127 | dev_err(dev, "couldn't register PHYs\n"); |
119 | return ret; | 128 | goto err1; |
120 | } | ||
121 | |||
122 | dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); | ||
123 | if (!dwc3) { | ||
124 | dev_err(dev, "couldn't allocate dwc3 device\n"); | ||
125 | return -ENOMEM; | ||
126 | } | 129 | } |
127 | 130 | ||
128 | clk = devm_clk_get(dev, "usbdrd30"); | 131 | clk = devm_clk_get(dev, "usbdrd30"); |
@@ -132,37 +135,28 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
132 | goto err1; | 135 | goto err1; |
133 | } | 136 | } |
134 | 137 | ||
135 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); | ||
136 | |||
137 | dwc3->dev.parent = dev; | ||
138 | dwc3->dev.dma_mask = dev->dma_mask; | ||
139 | dwc3->dev.dma_parms = dev->dma_parms; | ||
140 | exynos->dwc3 = dwc3; | ||
141 | exynos->dev = dev; | 138 | exynos->dev = dev; |
142 | exynos->clk = clk; | 139 | exynos->clk = clk; |
143 | 140 | ||
144 | clk_enable(exynos->clk); | 141 | clk_prepare_enable(exynos->clk); |
145 | 142 | ||
146 | ret = platform_device_add_resources(dwc3, pdev->resource, | 143 | if (node) { |
147 | pdev->num_resources); | 144 | ret = of_platform_populate(node, NULL, NULL, dev); |
148 | if (ret) { | 145 | if (ret) { |
149 | dev_err(dev, "couldn't add resources to dwc3 device\n"); | 146 | dev_err(dev, "failed to add dwc3 core\n"); |
150 | goto err2; | 147 | goto err2; |
151 | } | 148 | } |
152 | 149 | } else { | |
153 | ret = platform_device_add(dwc3); | 150 | dev_err(dev, "no device node, failed to add dwc3 core\n"); |
154 | if (ret) { | 151 | ret = -ENODEV; |
155 | dev_err(dev, "failed to register dwc3 device\n"); | ||
156 | goto err2; | 152 | goto err2; |
157 | } | 153 | } |
158 | 154 | ||
159 | return 0; | 155 | return 0; |
160 | 156 | ||
161 | err2: | 157 | err2: |
162 | clk_disable(clk); | 158 | clk_disable_unprepare(clk); |
163 | err1: | 159 | err1: |
164 | platform_device_put(dwc3); | ||
165 | |||
166 | return ret; | 160 | return ret; |
167 | } | 161 | } |
168 | 162 | ||
@@ -170,11 +164,11 @@ static int dwc3_exynos_remove(struct platform_device *pdev) | |||
170 | { | 164 | { |
171 | struct dwc3_exynos *exynos = platform_get_drvdata(pdev); | 165 | struct dwc3_exynos *exynos = platform_get_drvdata(pdev); |
172 | 166 | ||
173 | platform_device_unregister(exynos->dwc3); | ||
174 | platform_device_unregister(exynos->usb2_phy); | 167 | platform_device_unregister(exynos->usb2_phy); |
175 | platform_device_unregister(exynos->usb3_phy); | 168 | platform_device_unregister(exynos->usb3_phy); |
169 | device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child); | ||
176 | 170 | ||
177 | clk_disable(exynos->clk); | 171 | clk_disable_unprepare(exynos->clk); |
178 | 172 | ||
179 | return 0; | 173 | return 0; |
180 | } | 174 | } |
@@ -187,12 +181,46 @@ static const struct of_device_id exynos_dwc3_match[] = { | |||
187 | MODULE_DEVICE_TABLE(of, exynos_dwc3_match); | 181 | MODULE_DEVICE_TABLE(of, exynos_dwc3_match); |
188 | #endif | 182 | #endif |
189 | 183 | ||
184 | #ifdef CONFIG_PM_SLEEP | ||
185 | static int dwc3_exynos_suspend(struct device *dev) | ||
186 | { | ||
187 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); | ||
188 | |||
189 | clk_disable(exynos->clk); | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int dwc3_exynos_resume(struct device *dev) | ||
195 | { | ||
196 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); | ||
197 | |||
198 | clk_enable(exynos->clk); | ||
199 | |||
200 | /* runtime set active to reflect active state. */ | ||
201 | pm_runtime_disable(dev); | ||
202 | pm_runtime_set_active(dev); | ||
203 | pm_runtime_enable(dev); | ||
204 | |||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = { | ||
209 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume) | ||
210 | }; | ||
211 | |||
212 | #define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops) | ||
213 | #else | ||
214 | #define DEV_PM_OPS NULL | ||
215 | #endif /* CONFIG_PM_SLEEP */ | ||
216 | |||
190 | static struct platform_driver dwc3_exynos_driver = { | 217 | static struct platform_driver dwc3_exynos_driver = { |
191 | .probe = dwc3_exynos_probe, | 218 | .probe = dwc3_exynos_probe, |
192 | .remove = dwc3_exynos_remove, | 219 | .remove = dwc3_exynos_remove, |
193 | .driver = { | 220 | .driver = { |
194 | .name = "exynos-dwc3", | 221 | .name = "exynos-dwc3", |
195 | .of_match_table = of_match_ptr(exynos_dwc3_match), | 222 | .of_match_table = of_match_ptr(exynos_dwc3_match), |
223 | .pm = DEV_PM_OPS, | ||
196 | }, | 224 | }, |
197 | }; | 225 | }; |
198 | 226 | ||
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index afa05e3c9cf4..34638b92500d 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -52,7 +52,6 @@ | |||
52 | #include <linux/of_platform.h> | 52 | #include <linux/of_platform.h> |
53 | 53 | ||
54 | #include <linux/usb/otg.h> | 54 | #include <linux/usb/otg.h> |
55 | #include <linux/usb/nop-usb-xceiv.h> | ||
56 | 55 | ||
57 | /* | 56 | /* |
58 | * All these registers belong to OMAP's Wrapper around the | 57 | * All these registers belong to OMAP's Wrapper around the |
@@ -117,20 +116,17 @@ struct dwc3_omap { | |||
117 | /* device lock */ | 116 | /* device lock */ |
118 | spinlock_t lock; | 117 | spinlock_t lock; |
119 | 118 | ||
120 | struct platform_device *usb2_phy; | ||
121 | struct platform_device *usb3_phy; | ||
122 | struct device *dev; | 119 | struct device *dev; |
123 | 120 | ||
124 | int irq; | 121 | int irq; |
125 | void __iomem *base; | 122 | void __iomem *base; |
126 | 123 | ||
127 | void *context; | 124 | u32 utmi_otg_status; |
128 | u32 resource_size; | ||
129 | 125 | ||
130 | u32 dma_status:1; | 126 | u32 dma_status:1; |
131 | }; | 127 | }; |
132 | 128 | ||
133 | struct dwc3_omap *_omap; | 129 | static struct dwc3_omap *_omap; |
134 | 130 | ||
135 | static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) | 131 | static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) |
136 | { | 132 | { |
@@ -142,11 +138,14 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value) | |||
142 | writel(value, base + offset); | 138 | writel(value, base + offset); |
143 | } | 139 | } |
144 | 140 | ||
145 | void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) | 141 | int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) |
146 | { | 142 | { |
147 | u32 val; | 143 | u32 val; |
148 | struct dwc3_omap *omap = _omap; | 144 | struct dwc3_omap *omap = _omap; |
149 | 145 | ||
146 | if (!omap) | ||
147 | return -EPROBE_DEFER; | ||
148 | |||
150 | switch (status) { | 149 | switch (status) { |
151 | case OMAP_DWC3_ID_GROUND: | 150 | case OMAP_DWC3_ID_GROUND: |
152 | dev_dbg(omap->dev, "ID GND\n"); | 151 | dev_dbg(omap->dev, "ID GND\n"); |
@@ -189,63 +188,9 @@ void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) | |||
189 | dev_dbg(omap->dev, "ID float\n"); | 188 | dev_dbg(omap->dev, "ID float\n"); |
190 | } | 189 | } |
191 | 190 | ||
192 | return; | ||
193 | } | ||
194 | EXPORT_SYMBOL_GPL(dwc3_omap_mailbox); | ||
195 | |||
196 | static int dwc3_omap_register_phys(struct dwc3_omap *omap) | ||
197 | { | ||
198 | struct nop_usb_xceiv_platform_data pdata; | ||
199 | struct platform_device *pdev; | ||
200 | int ret; | ||
201 | |||
202 | memset(&pdata, 0x00, sizeof(pdata)); | ||
203 | |||
204 | pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); | ||
205 | if (!pdev) | ||
206 | return -ENOMEM; | ||
207 | |||
208 | omap->usb2_phy = pdev; | ||
209 | pdata.type = USB_PHY_TYPE_USB2; | ||
210 | |||
211 | ret = platform_device_add_data(omap->usb2_phy, &pdata, sizeof(pdata)); | ||
212 | if (ret) | ||
213 | goto err1; | ||
214 | |||
215 | pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); | ||
216 | if (!pdev) { | ||
217 | ret = -ENOMEM; | ||
218 | goto err1; | ||
219 | } | ||
220 | |||
221 | omap->usb3_phy = pdev; | ||
222 | pdata.type = USB_PHY_TYPE_USB3; | ||
223 | |||
224 | ret = platform_device_add_data(omap->usb3_phy, &pdata, sizeof(pdata)); | ||
225 | if (ret) | ||
226 | goto err2; | ||
227 | |||
228 | ret = platform_device_add(omap->usb2_phy); | ||
229 | if (ret) | ||
230 | goto err2; | ||
231 | |||
232 | ret = platform_device_add(omap->usb3_phy); | ||
233 | if (ret) | ||
234 | goto err3; | ||
235 | |||
236 | return 0; | 191 | return 0; |
237 | |||
238 | err3: | ||
239 | platform_device_del(omap->usb2_phy); | ||
240 | |||
241 | err2: | ||
242 | platform_device_put(omap->usb3_phy); | ||
243 | |||
244 | err1: | ||
245 | platform_device_put(omap->usb2_phy); | ||
246 | |||
247 | return ret; | ||
248 | } | 192 | } |
193 | EXPORT_SYMBOL_GPL(dwc3_omap_mailbox); | ||
249 | 194 | ||
250 | static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) | 195 | static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) |
251 | { | 196 | { |
@@ -307,24 +252,57 @@ static int dwc3_omap_remove_core(struct device *dev, void *c) | |||
307 | return 0; | 252 | return 0; |
308 | } | 253 | } |
309 | 254 | ||
255 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) | ||
256 | { | ||
257 | u32 reg; | ||
258 | |||
259 | /* enable all IRQs */ | ||
260 | reg = USBOTGSS_IRQO_COREIRQ_ST; | ||
261 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); | ||
262 | |||
263 | reg = (USBOTGSS_IRQ1_OEVT | | ||
264 | USBOTGSS_IRQ1_DRVVBUS_RISE | | ||
265 | USBOTGSS_IRQ1_CHRGVBUS_RISE | | ||
266 | USBOTGSS_IRQ1_DISCHRGVBUS_RISE | | ||
267 | USBOTGSS_IRQ1_IDPULLUP_RISE | | ||
268 | USBOTGSS_IRQ1_DRVVBUS_FALL | | ||
269 | USBOTGSS_IRQ1_CHRGVBUS_FALL | | ||
270 | USBOTGSS_IRQ1_DISCHRGVBUS_FALL | | ||
271 | USBOTGSS_IRQ1_IDPULLUP_FALL); | ||
272 | |||
273 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); | ||
274 | } | ||
275 | |||
276 | static void dwc3_omap_disable_irqs(struct dwc3_omap *omap) | ||
277 | { | ||
278 | /* disable all IRQs */ | ||
279 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00); | ||
280 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00); | ||
281 | } | ||
282 | |||
283 | static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32); | ||
284 | |||
310 | static int dwc3_omap_probe(struct platform_device *pdev) | 285 | static int dwc3_omap_probe(struct platform_device *pdev) |
311 | { | 286 | { |
312 | struct dwc3_omap_data *pdata = pdev->dev.platform_data; | ||
313 | struct device_node *node = pdev->dev.of_node; | 287 | struct device_node *node = pdev->dev.of_node; |
314 | 288 | ||
315 | struct dwc3_omap *omap; | 289 | struct dwc3_omap *omap; |
316 | struct resource *res; | 290 | struct resource *res; |
317 | struct device *dev = &pdev->dev; | 291 | struct device *dev = &pdev->dev; |
318 | 292 | ||
319 | int size; | ||
320 | int ret = -ENOMEM; | 293 | int ret = -ENOMEM; |
321 | int irq; | 294 | int irq; |
322 | 295 | ||
323 | const u32 *utmi_mode; | 296 | int utmi_mode = 0; |
297 | |||
324 | u32 reg; | 298 | u32 reg; |
325 | 299 | ||
326 | void __iomem *base; | 300 | void __iomem *base; |
327 | void *context; | 301 | |
302 | if (!node) { | ||
303 | dev_err(dev, "device node not found\n"); | ||
304 | return -EINVAL; | ||
305 | } | ||
328 | 306 | ||
329 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); | 307 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
330 | if (!omap) { | 308 | if (!omap) { |
@@ -334,13 +312,13 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
334 | 312 | ||
335 | platform_set_drvdata(pdev, omap); | 313 | platform_set_drvdata(pdev, omap); |
336 | 314 | ||
337 | irq = platform_get_irq(pdev, 1); | 315 | irq = platform_get_irq(pdev, 0); |
338 | if (irq < 0) { | 316 | if (irq < 0) { |
339 | dev_err(dev, "missing IRQ resource\n"); | 317 | dev_err(dev, "missing IRQ resource\n"); |
340 | return -EINVAL; | 318 | return -EINVAL; |
341 | } | 319 | } |
342 | 320 | ||
343 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | 321 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
344 | if (!res) { | 322 | if (!res) { |
345 | dev_err(dev, "missing memory base resource\n"); | 323 | dev_err(dev, "missing memory base resource\n"); |
346 | return -EINVAL; | 324 | return -EINVAL; |
@@ -352,25 +330,12 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
352 | return -ENOMEM; | 330 | return -ENOMEM; |
353 | } | 331 | } |
354 | 332 | ||
355 | ret = dwc3_omap_register_phys(omap); | ||
356 | if (ret) { | ||
357 | dev_err(dev, "couldn't register PHYs\n"); | ||
358 | return ret; | ||
359 | } | ||
360 | |||
361 | context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL); | ||
362 | if (!context) { | ||
363 | dev_err(dev, "couldn't allocate dwc3 context memory\n"); | ||
364 | return -ENOMEM; | ||
365 | } | ||
366 | |||
367 | spin_lock_init(&omap->lock); | 333 | spin_lock_init(&omap->lock); |
368 | 334 | ||
369 | omap->resource_size = resource_size(res); | ||
370 | omap->context = context; | ||
371 | omap->dev = dev; | 335 | omap->dev = dev; |
372 | omap->irq = irq; | 336 | omap->irq = irq; |
373 | omap->base = base; | 337 | omap->base = base; |
338 | dev->dma_mask = &dwc3_omap_dma_mask; | ||
374 | 339 | ||
375 | /* | 340 | /* |
376 | * REVISIT if we ever have two instances of the wrapper, we will be | 341 | * REVISIT if we ever have two instances of the wrapper, we will be |
@@ -387,25 +352,17 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
387 | 352 | ||
388 | reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); | 353 | reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
389 | 354 | ||
390 | utmi_mode = of_get_property(node, "utmi-mode", &size); | 355 | of_property_read_u32(node, "utmi-mode", &utmi_mode); |
391 | if (utmi_mode && size == sizeof(*utmi_mode)) { | 356 | |
392 | reg |= *utmi_mode; | 357 | switch (utmi_mode) { |
393 | } else { | 358 | case DWC3_OMAP_UTMI_MODE_SW: |
394 | if (!pdata) { | 359 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
395 | dev_dbg(dev, "missing platform data\n"); | 360 | break; |
396 | } else { | 361 | case DWC3_OMAP_UTMI_MODE_HW: |
397 | switch (pdata->utmi_mode) { | 362 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
398 | case DWC3_OMAP_UTMI_MODE_SW: | 363 | break; |
399 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | 364 | default: |
400 | break; | 365 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode); |
401 | case DWC3_OMAP_UTMI_MODE_HW: | ||
402 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | ||
403 | break; | ||
404 | default: | ||
405 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", | ||
406 | pdata->utmi_mode); | ||
407 | } | ||
408 | } | ||
409 | } | 366 | } |
410 | 367 | ||
411 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); | 368 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); |
@@ -422,29 +379,12 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
422 | return ret; | 379 | return ret; |
423 | } | 380 | } |
424 | 381 | ||
425 | /* enable all IRQs */ | 382 | dwc3_omap_enable_irqs(omap); |
426 | reg = USBOTGSS_IRQO_COREIRQ_ST; | ||
427 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); | ||
428 | 383 | ||
429 | reg = (USBOTGSS_IRQ1_OEVT | | 384 | ret = of_platform_populate(node, NULL, NULL, dev); |
430 | USBOTGSS_IRQ1_DRVVBUS_RISE | | 385 | if (ret) { |
431 | USBOTGSS_IRQ1_CHRGVBUS_RISE | | 386 | dev_err(&pdev->dev, "failed to create dwc3 core\n"); |
432 | USBOTGSS_IRQ1_DISCHRGVBUS_RISE | | 387 | return ret; |
433 | USBOTGSS_IRQ1_IDPULLUP_RISE | | ||
434 | USBOTGSS_IRQ1_DRVVBUS_FALL | | ||
435 | USBOTGSS_IRQ1_CHRGVBUS_FALL | | ||
436 | USBOTGSS_IRQ1_DISCHRGVBUS_FALL | | ||
437 | USBOTGSS_IRQ1_IDPULLUP_FALL); | ||
438 | |||
439 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); | ||
440 | |||
441 | if (node) { | ||
442 | ret = of_platform_populate(node, NULL, NULL, dev); | ||
443 | if (ret) { | ||
444 | dev_err(&pdev->dev, | ||
445 | "failed to add create dwc3 core\n"); | ||
446 | return ret; | ||
447 | } | ||
448 | } | 388 | } |
449 | 389 | ||
450 | return 0; | 390 | return 0; |
@@ -454,8 +394,7 @@ static int dwc3_omap_remove(struct platform_device *pdev) | |||
454 | { | 394 | { |
455 | struct dwc3_omap *omap = platform_get_drvdata(pdev); | 395 | struct dwc3_omap *omap = platform_get_drvdata(pdev); |
456 | 396 | ||
457 | platform_device_unregister(omap->usb2_phy); | 397 | dwc3_omap_disable_irqs(omap); |
458 | platform_device_unregister(omap->usb3_phy); | ||
459 | pm_runtime_put_sync(&pdev->dev); | 398 | pm_runtime_put_sync(&pdev->dev); |
460 | pm_runtime_disable(&pdev->dev); | 399 | pm_runtime_disable(&pdev->dev); |
461 | device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); | 400 | device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); |
@@ -465,18 +404,72 @@ static int dwc3_omap_remove(struct platform_device *pdev) | |||
465 | 404 | ||
466 | static const struct of_device_id of_dwc3_match[] = { | 405 | static const struct of_device_id of_dwc3_match[] = { |
467 | { | 406 | { |
468 | "ti,dwc3", | 407 | .compatible = "ti,dwc3" |
469 | }, | 408 | }, |
470 | { }, | 409 | { }, |
471 | }; | 410 | }; |
472 | MODULE_DEVICE_TABLE(of, of_dwc3_match); | 411 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
473 | 412 | ||
413 | #ifdef CONFIG_PM_SLEEP | ||
414 | static int dwc3_omap_prepare(struct device *dev) | ||
415 | { | ||
416 | struct dwc3_omap *omap = dev_get_drvdata(dev); | ||
417 | |||
418 | dwc3_omap_disable_irqs(omap); | ||
419 | |||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | static void dwc3_omap_complete(struct device *dev) | ||
424 | { | ||
425 | struct dwc3_omap *omap = dev_get_drvdata(dev); | ||
426 | |||
427 | dwc3_omap_enable_irqs(omap); | ||
428 | } | ||
429 | |||
430 | static int dwc3_omap_suspend(struct device *dev) | ||
431 | { | ||
432 | struct dwc3_omap *omap = dev_get_drvdata(dev); | ||
433 | |||
434 | omap->utmi_otg_status = dwc3_omap_readl(omap->base, | ||
435 | USBOTGSS_UTMI_OTG_STATUS); | ||
436 | |||
437 | return 0; | ||
438 | } | ||
439 | |||
440 | static int dwc3_omap_resume(struct device *dev) | ||
441 | { | ||
442 | struct dwc3_omap *omap = dev_get_drvdata(dev); | ||
443 | |||
444 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, | ||
445 | omap->utmi_otg_status); | ||
446 | |||
447 | pm_runtime_disable(dev); | ||
448 | pm_runtime_set_active(dev); | ||
449 | pm_runtime_enable(dev); | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { | ||
455 | .prepare = dwc3_omap_prepare, | ||
456 | .complete = dwc3_omap_complete, | ||
457 | |||
458 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) | ||
459 | }; | ||
460 | |||
461 | #define DEV_PM_OPS (&dwc3_omap_dev_pm_ops) | ||
462 | #else | ||
463 | #define DEV_PM_OPS NULL | ||
464 | #endif /* CONFIG_PM_SLEEP */ | ||
465 | |||
474 | static struct platform_driver dwc3_omap_driver = { | 466 | static struct platform_driver dwc3_omap_driver = { |
475 | .probe = dwc3_omap_probe, | 467 | .probe = dwc3_omap_probe, |
476 | .remove = dwc3_omap_remove, | 468 | .remove = dwc3_omap_remove, |
477 | .driver = { | 469 | .driver = { |
478 | .name = "omap-dwc3", | 470 | .name = "omap-dwc3", |
479 | .of_match_table = of_dwc3_match, | 471 | .of_match_table = of_dwc3_match, |
472 | .pm = DEV_PM_OPS, | ||
480 | }, | 473 | }, |
481 | }; | 474 | }; |
482 | 475 | ||
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index e8d77689a322..227d4a7acad7 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -212,11 +212,49 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = { | |||
212 | }; | 212 | }; |
213 | MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); | 213 | MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); |
214 | 214 | ||
215 | #ifdef CONFIG_PM | ||
216 | static int dwc3_pci_suspend(struct device *dev) | ||
217 | { | ||
218 | struct pci_dev *pci = to_pci_dev(dev); | ||
219 | |||
220 | pci_disable_device(pci); | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int dwc3_pci_resume(struct device *dev) | ||
226 | { | ||
227 | struct pci_dev *pci = to_pci_dev(dev); | ||
228 | int ret; | ||
229 | |||
230 | ret = pci_enable_device(pci); | ||
231 | if (ret) { | ||
232 | dev_err(dev, "can't re-enable device --> %d\n", ret); | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | pci_set_master(pci); | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static const struct dev_pm_ops dwc3_pci_dev_pm_ops = { | ||
242 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume) | ||
243 | }; | ||
244 | |||
245 | #define DEV_PM_OPS (&dwc3_pci_dev_pm_ops) | ||
246 | #else | ||
247 | #define DEV_PM_OPS NULL | ||
248 | #endif /* CONFIG_PM */ | ||
249 | |||
215 | static struct pci_driver dwc3_pci_driver = { | 250 | static struct pci_driver dwc3_pci_driver = { |
216 | .name = "dwc3-pci", | 251 | .name = "dwc3-pci", |
217 | .id_table = dwc3_pci_id_table, | 252 | .id_table = dwc3_pci_id_table, |
218 | .probe = dwc3_pci_probe, | 253 | .probe = dwc3_pci_probe, |
219 | .remove = dwc3_pci_remove, | 254 | .remove = dwc3_pci_remove, |
255 | .driver = { | ||
256 | .pm = DEV_PM_OPS, | ||
257 | }, | ||
220 | }; | 258 | }; |
221 | 259 | ||
222 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); | 260 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 1d139ca05ef1..5acbb948b704 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c | |||
@@ -394,10 +394,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, | |||
394 | u32 wIndex; | 394 | u32 wIndex; |
395 | u32 reg; | 395 | u32 reg; |
396 | int ret; | 396 | int ret; |
397 | enum usb_device_state state; | ||
397 | 398 | ||
398 | wValue = le16_to_cpu(ctrl->wValue); | 399 | wValue = le16_to_cpu(ctrl->wValue); |
399 | wIndex = le16_to_cpu(ctrl->wIndex); | 400 | wIndex = le16_to_cpu(ctrl->wIndex); |
400 | recip = ctrl->bRequestType & USB_RECIP_MASK; | 401 | recip = ctrl->bRequestType & USB_RECIP_MASK; |
402 | state = dwc->gadget.state; | ||
403 | |||
401 | switch (recip) { | 404 | switch (recip) { |
402 | case USB_RECIP_DEVICE: | 405 | case USB_RECIP_DEVICE: |
403 | 406 | ||
@@ -409,7 +412,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, | |||
409 | * default control pipe | 412 | * default control pipe |
410 | */ | 413 | */ |
411 | case USB_DEVICE_U1_ENABLE: | 414 | case USB_DEVICE_U1_ENABLE: |
412 | if (dwc->dev_state != DWC3_CONFIGURED_STATE) | 415 | if (state != USB_STATE_CONFIGURED) |
413 | return -EINVAL; | 416 | return -EINVAL; |
414 | if (dwc->speed != DWC3_DSTS_SUPERSPEED) | 417 | if (dwc->speed != DWC3_DSTS_SUPERSPEED) |
415 | return -EINVAL; | 418 | return -EINVAL; |
@@ -423,7 +426,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, | |||
423 | break; | 426 | break; |
424 | 427 | ||
425 | case USB_DEVICE_U2_ENABLE: | 428 | case USB_DEVICE_U2_ENABLE: |
426 | if (dwc->dev_state != DWC3_CONFIGURED_STATE) | 429 | if (state != USB_STATE_CONFIGURED) |
427 | return -EINVAL; | 430 | return -EINVAL; |
428 | if (dwc->speed != DWC3_DSTS_SUPERSPEED) | 431 | if (dwc->speed != DWC3_DSTS_SUPERSPEED) |
429 | return -EINVAL; | 432 | return -EINVAL; |
@@ -493,6 +496,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, | |||
493 | 496 | ||
494 | static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | 497 | static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
495 | { | 498 | { |
499 | enum usb_device_state state = dwc->gadget.state; | ||
496 | u32 addr; | 500 | u32 addr; |
497 | u32 reg; | 501 | u32 reg; |
498 | 502 | ||
@@ -502,7 +506,7 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
502 | return -EINVAL; | 506 | return -EINVAL; |
503 | } | 507 | } |
504 | 508 | ||
505 | if (dwc->dev_state == DWC3_CONFIGURED_STATE) { | 509 | if (state == USB_STATE_CONFIGURED) { |
506 | dev_dbg(dwc->dev, "trying to set address when configured\n"); | 510 | dev_dbg(dwc->dev, "trying to set address when configured\n"); |
507 | return -EINVAL; | 511 | return -EINVAL; |
508 | } | 512 | } |
@@ -513,9 +517,9 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
513 | dwc3_writel(dwc->regs, DWC3_DCFG, reg); | 517 | dwc3_writel(dwc->regs, DWC3_DCFG, reg); |
514 | 518 | ||
515 | if (addr) | 519 | if (addr) |
516 | dwc->dev_state = DWC3_ADDRESS_STATE; | 520 | usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); |
517 | else | 521 | else |
518 | dwc->dev_state = DWC3_DEFAULT_STATE; | 522 | usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); |
519 | 523 | ||
520 | return 0; | 524 | return 0; |
521 | } | 525 | } |
@@ -532,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
532 | 536 | ||
533 | static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | 537 | static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
534 | { | 538 | { |
539 | enum usb_device_state state = dwc->gadget.state; | ||
535 | u32 cfg; | 540 | u32 cfg; |
536 | int ret; | 541 | int ret; |
537 | u32 reg; | 542 | u32 reg; |
@@ -539,16 +544,18 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
539 | dwc->start_config_issued = false; | 544 | dwc->start_config_issued = false; |
540 | cfg = le16_to_cpu(ctrl->wValue); | 545 | cfg = le16_to_cpu(ctrl->wValue); |
541 | 546 | ||
542 | switch (dwc->dev_state) { | 547 | switch (state) { |
543 | case DWC3_DEFAULT_STATE: | 548 | case USB_STATE_DEFAULT: |
544 | return -EINVAL; | 549 | return -EINVAL; |
545 | break; | 550 | break; |
546 | 551 | ||
547 | case DWC3_ADDRESS_STATE: | 552 | case USB_STATE_ADDRESS: |
548 | ret = dwc3_ep0_delegate_req(dwc, ctrl); | 553 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
549 | /* if the cfg matches and the cfg is non zero */ | 554 | /* if the cfg matches and the cfg is non zero */ |
550 | if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { | 555 | if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { |
551 | dwc->dev_state = DWC3_CONFIGURED_STATE; | 556 | usb_gadget_set_state(&dwc->gadget, |
557 | USB_STATE_CONFIGURED); | ||
558 | |||
552 | /* | 559 | /* |
553 | * Enable transition to U1/U2 state when | 560 | * Enable transition to U1/U2 state when |
554 | * nothing is pending from application. | 561 | * nothing is pending from application. |
@@ -562,10 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
562 | } | 569 | } |
563 | break; | 570 | break; |
564 | 571 | ||
565 | case DWC3_CONFIGURED_STATE: | 572 | case USB_STATE_CONFIGURED: |
566 | ret = dwc3_ep0_delegate_req(dwc, ctrl); | 573 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
567 | if (!cfg) | 574 | if (!cfg) |
568 | dwc->dev_state = DWC3_ADDRESS_STATE; | 575 | usb_gadget_set_state(&dwc->gadget, |
576 | USB_STATE_ADDRESS); | ||
569 | break; | 577 | break; |
570 | default: | 578 | default: |
571 | ret = -EINVAL; | 579 | ret = -EINVAL; |
@@ -620,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req) | |||
620 | static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | 628 | static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
621 | { | 629 | { |
622 | struct dwc3_ep *dep; | 630 | struct dwc3_ep *dep; |
631 | enum usb_device_state state = dwc->gadget.state; | ||
623 | u16 wLength; | 632 | u16 wLength; |
624 | u16 wValue; | 633 | u16 wValue; |
625 | 634 | ||
626 | if (dwc->dev_state == DWC3_DEFAULT_STATE) | 635 | if (state == USB_STATE_DEFAULT) |
627 | return -EINVAL; | 636 | return -EINVAL; |
628 | 637 | ||
629 | wValue = le16_to_cpu(ctrl->wValue); | 638 | wValue = le16_to_cpu(ctrl->wValue); |
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 82e160e96fca..2b6e7e001207 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -1425,8 +1425,10 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on) | |||
1425 | if (dwc->revision >= DWC3_REVISION_194A) | 1425 | if (dwc->revision >= DWC3_REVISION_194A) |
1426 | reg &= ~DWC3_DCTL_KEEP_CONNECT; | 1426 | reg &= ~DWC3_DCTL_KEEP_CONNECT; |
1427 | reg |= DWC3_DCTL_RUN_STOP; | 1427 | reg |= DWC3_DCTL_RUN_STOP; |
1428 | dwc->pullups_connected = true; | ||
1428 | } else { | 1429 | } else { |
1429 | reg &= ~DWC3_DCTL_RUN_STOP; | 1430 | reg &= ~DWC3_DCTL_RUN_STOP; |
1431 | dwc->pullups_connected = false; | ||
1430 | } | 1432 | } |
1431 | 1433 | ||
1432 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); | 1434 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
@@ -1469,6 +1471,33 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) | |||
1469 | return ret; | 1471 | return ret; |
1470 | } | 1472 | } |
1471 | 1473 | ||
1474 | static void dwc3_gadget_enable_irq(struct dwc3 *dwc) | ||
1475 | { | ||
1476 | u32 reg; | ||
1477 | |||
1478 | /* Enable all but Start and End of Frame IRQs */ | ||
1479 | reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN | | ||
1480 | DWC3_DEVTEN_EVNTOVERFLOWEN | | ||
1481 | DWC3_DEVTEN_CMDCMPLTEN | | ||
1482 | DWC3_DEVTEN_ERRTICERREN | | ||
1483 | DWC3_DEVTEN_WKUPEVTEN | | ||
1484 | DWC3_DEVTEN_ULSTCNGEN | | ||
1485 | DWC3_DEVTEN_CONNECTDONEEN | | ||
1486 | DWC3_DEVTEN_USBRSTEN | | ||
1487 | DWC3_DEVTEN_DISCONNEVTEN); | ||
1488 | |||
1489 | dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); | ||
1490 | } | ||
1491 | |||
1492 | static void dwc3_gadget_disable_irq(struct dwc3 *dwc) | ||
1493 | { | ||
1494 | /* mask all interrupts */ | ||
1495 | dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); | ||
1496 | } | ||
1497 | |||
1498 | static irqreturn_t dwc3_interrupt(int irq, void *_dwc); | ||
1499 | static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc); | ||
1500 | |||
1472 | static int dwc3_gadget_start(struct usb_gadget *g, | 1501 | static int dwc3_gadget_start(struct usb_gadget *g, |
1473 | struct usb_gadget_driver *driver) | 1502 | struct usb_gadget_driver *driver) |
1474 | { | 1503 | { |
@@ -1476,6 +1505,7 @@ static int dwc3_gadget_start(struct usb_gadget *g, | |||
1476 | struct dwc3_ep *dep; | 1505 | struct dwc3_ep *dep; |
1477 | unsigned long flags; | 1506 | unsigned long flags; |
1478 | int ret = 0; | 1507 | int ret = 0; |
1508 | int irq; | ||
1479 | u32 reg; | 1509 | u32 reg; |
1480 | 1510 | ||
1481 | spin_lock_irqsave(&dwc->lock, flags); | 1511 | spin_lock_irqsave(&dwc->lock, flags); |
@@ -1489,7 +1519,6 @@ static int dwc3_gadget_start(struct usb_gadget *g, | |||
1489 | } | 1519 | } |
1490 | 1520 | ||
1491 | dwc->gadget_driver = driver; | 1521 | dwc->gadget_driver = driver; |
1492 | dwc->gadget.dev.driver = &driver->driver; | ||
1493 | 1522 | ||
1494 | reg = dwc3_readl(dwc->regs, DWC3_DCFG); | 1523 | reg = dwc3_readl(dwc->regs, DWC3_DCFG); |
1495 | reg &= ~(DWC3_DCFG_SPEED_MASK); | 1524 | reg &= ~(DWC3_DCFG_SPEED_MASK); |
@@ -1536,6 +1565,17 @@ static int dwc3_gadget_start(struct usb_gadget *g, | |||
1536 | dwc->ep0state = EP0_SETUP_PHASE; | 1565 | dwc->ep0state = EP0_SETUP_PHASE; |
1537 | dwc3_ep0_out_start(dwc); | 1566 | dwc3_ep0_out_start(dwc); |
1538 | 1567 | ||
1568 | irq = platform_get_irq(to_platform_device(dwc->dev), 0); | ||
1569 | ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt, | ||
1570 | IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc); | ||
1571 | if (ret) { | ||
1572 | dev_err(dwc->dev, "failed to request irq #%d --> %d\n", | ||
1573 | irq, ret); | ||
1574 | goto err1; | ||
1575 | } | ||
1576 | |||
1577 | dwc3_gadget_enable_irq(dwc); | ||
1578 | |||
1539 | spin_unlock_irqrestore(&dwc->lock, flags); | 1579 | spin_unlock_irqrestore(&dwc->lock, flags); |
1540 | 1580 | ||
1541 | return 0; | 1581 | return 0; |
@@ -1554,14 +1594,18 @@ static int dwc3_gadget_stop(struct usb_gadget *g, | |||
1554 | { | 1594 | { |
1555 | struct dwc3 *dwc = gadget_to_dwc(g); | 1595 | struct dwc3 *dwc = gadget_to_dwc(g); |
1556 | unsigned long flags; | 1596 | unsigned long flags; |
1597 | int irq; | ||
1557 | 1598 | ||
1558 | spin_lock_irqsave(&dwc->lock, flags); | 1599 | spin_lock_irqsave(&dwc->lock, flags); |
1559 | 1600 | ||
1601 | dwc3_gadget_disable_irq(dwc); | ||
1602 | irq = platform_get_irq(to_platform_device(dwc->dev), 0); | ||
1603 | free_irq(irq, dwc); | ||
1604 | |||
1560 | __dwc3_gadget_ep_disable(dwc->eps[0]); | 1605 | __dwc3_gadget_ep_disable(dwc->eps[0]); |
1561 | __dwc3_gadget_ep_disable(dwc->eps[1]); | 1606 | __dwc3_gadget_ep_disable(dwc->eps[1]); |
1562 | 1607 | ||
1563 | dwc->gadget_driver = NULL; | 1608 | dwc->gadget_driver = NULL; |
1564 | dwc->gadget.dev.driver = NULL; | ||
1565 | 1609 | ||
1566 | spin_unlock_irqrestore(&dwc->lock, flags); | 1610 | spin_unlock_irqrestore(&dwc->lock, flags); |
1567 | 1611 | ||
@@ -1579,14 +1623,15 @@ static const struct usb_gadget_ops dwc3_gadget_ops = { | |||
1579 | 1623 | ||
1580 | /* -------------------------------------------------------------------------- */ | 1624 | /* -------------------------------------------------------------------------- */ |
1581 | 1625 | ||
1582 | static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) | 1626 | static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc, |
1627 | u8 num, u32 direction) | ||
1583 | { | 1628 | { |
1584 | struct dwc3_ep *dep; | 1629 | struct dwc3_ep *dep; |
1585 | u8 epnum; | 1630 | u8 i; |
1586 | 1631 | ||
1587 | INIT_LIST_HEAD(&dwc->gadget.ep_list); | 1632 | for (i = 0; i < num; i++) { |
1633 | u8 epnum = (i << 1) | (!!direction); | ||
1588 | 1634 | ||
1589 | for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { | ||
1590 | dep = kzalloc(sizeof(*dep), GFP_KERNEL); | 1635 | dep = kzalloc(sizeof(*dep), GFP_KERNEL); |
1591 | if (!dep) { | 1636 | if (!dep) { |
1592 | dev_err(dwc->dev, "can't allocate endpoint %d\n", | 1637 | dev_err(dwc->dev, "can't allocate endpoint %d\n", |
@@ -1600,6 +1645,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) | |||
1600 | 1645 | ||
1601 | snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, | 1646 | snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, |
1602 | (epnum & 1) ? "in" : "out"); | 1647 | (epnum & 1) ? "in" : "out"); |
1648 | |||
1603 | dep->endpoint.name = dep->name; | 1649 | dep->endpoint.name = dep->name; |
1604 | dep->direction = (epnum & 1); | 1650 | dep->direction = (epnum & 1); |
1605 | 1651 | ||
@@ -1630,6 +1676,27 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) | |||
1630 | return 0; | 1676 | return 0; |
1631 | } | 1677 | } |
1632 | 1678 | ||
1679 | static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) | ||
1680 | { | ||
1681 | int ret; | ||
1682 | |||
1683 | INIT_LIST_HEAD(&dwc->gadget.ep_list); | ||
1684 | |||
1685 | ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_out_eps, 0); | ||
1686 | if (ret < 0) { | ||
1687 | dev_vdbg(dwc->dev, "failed to allocate OUT endpoints\n"); | ||
1688 | return ret; | ||
1689 | } | ||
1690 | |||
1691 | ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_in_eps, 1); | ||
1692 | if (ret < 0) { | ||
1693 | dev_vdbg(dwc->dev, "failed to allocate IN endpoints\n"); | ||
1694 | return ret; | ||
1695 | } | ||
1696 | |||
1697 | return 0; | ||
1698 | } | ||
1699 | |||
1633 | static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) | 1700 | static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) |
1634 | { | 1701 | { |
1635 | struct dwc3_ep *dep; | 1702 | struct dwc3_ep *dep; |
@@ -1637,6 +1704,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) | |||
1637 | 1704 | ||
1638 | for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { | 1705 | for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { |
1639 | dep = dwc->eps[epnum]; | 1706 | dep = dwc->eps[epnum]; |
1707 | if (!dep) | ||
1708 | continue; | ||
1709 | |||
1640 | dwc3_free_trb_pool(dep); | 1710 | dwc3_free_trb_pool(dep); |
1641 | 1711 | ||
1642 | if (epnum != 0 && epnum != 1) | 1712 | if (epnum != 0 && epnum != 1) |
@@ -1646,12 +1716,8 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) | |||
1646 | } | 1716 | } |
1647 | } | 1717 | } |
1648 | 1718 | ||
1649 | static void dwc3_gadget_release(struct device *dev) | ||
1650 | { | ||
1651 | dev_dbg(dev, "%s\n", __func__); | ||
1652 | } | ||
1653 | |||
1654 | /* -------------------------------------------------------------------------- */ | 1719 | /* -------------------------------------------------------------------------- */ |
1720 | |||
1655 | static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, | 1721 | static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, |
1656 | struct dwc3_request *req, struct dwc3_trb *trb, | 1722 | struct dwc3_request *req, struct dwc3_trb *trb, |
1657 | const struct dwc3_event_depevt *event, int status) | 1723 | const struct dwc3_event_depevt *event, int status) |
@@ -1975,6 +2041,9 @@ static void dwc3_stop_active_transfers(struct dwc3 *dwc) | |||
1975 | struct dwc3_ep *dep; | 2041 | struct dwc3_ep *dep; |
1976 | 2042 | ||
1977 | dep = dwc->eps[epnum]; | 2043 | dep = dwc->eps[epnum]; |
2044 | if (!dep) | ||
2045 | continue; | ||
2046 | |||
1978 | if (!(dep->flags & DWC3_EP_ENABLED)) | 2047 | if (!(dep->flags & DWC3_EP_ENABLED)) |
1979 | continue; | 2048 | continue; |
1980 | 2049 | ||
@@ -1992,6 +2061,8 @@ static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) | |||
1992 | int ret; | 2061 | int ret; |
1993 | 2062 | ||
1994 | dep = dwc->eps[epnum]; | 2063 | dep = dwc->eps[epnum]; |
2064 | if (!dep) | ||
2065 | continue; | ||
1995 | 2066 | ||
1996 | if (!(dep->flags & DWC3_EP_STALL)) | 2067 | if (!(dep->flags & DWC3_EP_STALL)) |
1997 | continue; | 2068 | continue; |
@@ -2091,7 +2162,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) | |||
2091 | } | 2162 | } |
2092 | 2163 | ||
2093 | /* after reset -> Default State */ | 2164 | /* after reset -> Default State */ |
2094 | dwc->dev_state = DWC3_DEFAULT_STATE; | 2165 | usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); |
2095 | 2166 | ||
2096 | /* Recent versions support automatic phy suspend and don't need this */ | 2167 | /* Recent versions support automatic phy suspend and don't need this */ |
2097 | if (dwc->revision < DWC3_REVISION_194A) { | 2168 | if (dwc->revision < DWC3_REVISION_194A) { |
@@ -2277,6 +2348,34 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, | |||
2277 | unsigned int evtinfo) | 2348 | unsigned int evtinfo) |
2278 | { | 2349 | { |
2279 | enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; | 2350 | enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; |
2351 | unsigned int pwropt; | ||
2352 | |||
2353 | /* | ||
2354 | * WORKAROUND: DWC3 < 2.50a have an issue when configured without | ||
2355 | * Hibernation mode enabled which would show up when device detects | ||
2356 | * host-initiated U3 exit. | ||
2357 | * | ||
2358 | * In that case, device will generate a Link State Change Interrupt | ||
2359 | * from U3 to RESUME which is only necessary if Hibernation is | ||
2360 | * configured in. | ||
2361 | * | ||
2362 | * There are no functional changes due to such spurious event and we | ||
2363 | * just need to ignore it. | ||
2364 | * | ||
2365 | * Refers to: | ||
2366 | * | ||
2367 | * STAR#9000570034 RTL: SS Resume event generated in non-Hibernation | ||
2368 | * operational mode | ||
2369 | */ | ||
2370 | pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); | ||
2371 | if ((dwc->revision < DWC3_REVISION_250A) && | ||
2372 | (pwropt != DWC3_GHWPARAMS1_EN_PWROPT_HIB)) { | ||
2373 | if ((dwc->link_state == DWC3_LINK_STATE_U3) && | ||
2374 | (next == DWC3_LINK_STATE_RESUME)) { | ||
2375 | dev_vdbg(dwc->dev, "ignoring transition U3 -> Resume\n"); | ||
2376 | return; | ||
2377 | } | ||
2378 | } | ||
2280 | 2379 | ||
2281 | /* | 2380 | /* |
2282 | * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending | 2381 | * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending |
@@ -2387,40 +2486,73 @@ static void dwc3_process_event_entry(struct dwc3 *dwc, | |||
2387 | } | 2486 | } |
2388 | } | 2487 | } |
2389 | 2488 | ||
2489 | static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc) | ||
2490 | { | ||
2491 | struct dwc3 *dwc = _dwc; | ||
2492 | unsigned long flags; | ||
2493 | irqreturn_t ret = IRQ_NONE; | ||
2494 | int i; | ||
2495 | |||
2496 | spin_lock_irqsave(&dwc->lock, flags); | ||
2497 | |||
2498 | for (i = 0; i < dwc->num_event_buffers; i++) { | ||
2499 | struct dwc3_event_buffer *evt; | ||
2500 | int left; | ||
2501 | |||
2502 | evt = dwc->ev_buffs[i]; | ||
2503 | left = evt->count; | ||
2504 | |||
2505 | if (!(evt->flags & DWC3_EVENT_PENDING)) | ||
2506 | continue; | ||
2507 | |||
2508 | while (left > 0) { | ||
2509 | union dwc3_event event; | ||
2510 | |||
2511 | event.raw = *(u32 *) (evt->buf + evt->lpos); | ||
2512 | |||
2513 | dwc3_process_event_entry(dwc, &event); | ||
2514 | |||
2515 | /* | ||
2516 | * FIXME we wrap around correctly to the next entry as | ||
2517 | * almost all entries are 4 bytes in size. There is one | ||
2518 | * entry which has 12 bytes which is a regular entry | ||
2519 | * followed by 8 bytes data. ATM I don't know how | ||
2520 | * things are organized if we get next to the a | ||
2521 | * boundary so I worry about that once we try to handle | ||
2522 | * that. | ||
2523 | */ | ||
2524 | evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE; | ||
2525 | left -= 4; | ||
2526 | |||
2527 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(i), 4); | ||
2528 | } | ||
2529 | |||
2530 | evt->count = 0; | ||
2531 | evt->flags &= ~DWC3_EVENT_PENDING; | ||
2532 | ret = IRQ_HANDLED; | ||
2533 | } | ||
2534 | |||
2535 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
2536 | |||
2537 | return ret; | ||
2538 | } | ||
2539 | |||
2390 | static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) | 2540 | static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) |
2391 | { | 2541 | { |
2392 | struct dwc3_event_buffer *evt; | 2542 | struct dwc3_event_buffer *evt; |
2393 | int left; | ||
2394 | u32 count; | 2543 | u32 count; |
2395 | 2544 | ||
2545 | evt = dwc->ev_buffs[buf]; | ||
2546 | |||
2396 | count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf)); | 2547 | count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf)); |
2397 | count &= DWC3_GEVNTCOUNT_MASK; | 2548 | count &= DWC3_GEVNTCOUNT_MASK; |
2398 | if (!count) | 2549 | if (!count) |
2399 | return IRQ_NONE; | 2550 | return IRQ_NONE; |
2400 | 2551 | ||
2401 | evt = dwc->ev_buffs[buf]; | 2552 | evt->count = count; |
2402 | left = count; | 2553 | evt->flags |= DWC3_EVENT_PENDING; |
2403 | |||
2404 | while (left > 0) { | ||
2405 | union dwc3_event event; | ||
2406 | |||
2407 | event.raw = *(u32 *) (evt->buf + evt->lpos); | ||
2408 | 2554 | ||
2409 | dwc3_process_event_entry(dwc, &event); | 2555 | return IRQ_WAKE_THREAD; |
2410 | /* | ||
2411 | * XXX we wrap around correctly to the next entry as almost all | ||
2412 | * entries are 4 bytes in size. There is one entry which has 12 | ||
2413 | * bytes which is a regular entry followed by 8 bytes data. ATM | ||
2414 | * I don't know how things are organized if were get next to the | ||
2415 | * a boundary so I worry about that once we try to handle that. | ||
2416 | */ | ||
2417 | evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE; | ||
2418 | left -= 4; | ||
2419 | |||
2420 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4); | ||
2421 | } | ||
2422 | |||
2423 | return IRQ_HANDLED; | ||
2424 | } | 2556 | } |
2425 | 2557 | ||
2426 | static irqreturn_t dwc3_interrupt(int irq, void *_dwc) | 2558 | static irqreturn_t dwc3_interrupt(int irq, void *_dwc) |
@@ -2435,7 +2567,7 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc) | |||
2435 | irqreturn_t status; | 2567 | irqreturn_t status; |
2436 | 2568 | ||
2437 | status = dwc3_process_event_buf(dwc, i); | 2569 | status = dwc3_process_event_buf(dwc, i); |
2438 | if (status == IRQ_HANDLED) | 2570 | if (status == IRQ_WAKE_THREAD) |
2439 | ret = status; | 2571 | ret = status; |
2440 | } | 2572 | } |
2441 | 2573 | ||
@@ -2454,7 +2586,6 @@ int dwc3_gadget_init(struct dwc3 *dwc) | |||
2454 | { | 2586 | { |
2455 | u32 reg; | 2587 | u32 reg; |
2456 | int ret; | 2588 | int ret; |
2457 | int irq; | ||
2458 | 2589 | ||
2459 | dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), | 2590 | dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), |
2460 | &dwc->ctrl_req_addr, GFP_KERNEL); | 2591 | &dwc->ctrl_req_addr, GFP_KERNEL); |
@@ -2488,19 +2619,10 @@ int dwc3_gadget_init(struct dwc3 *dwc) | |||
2488 | goto err3; | 2619 | goto err3; |
2489 | } | 2620 | } |
2490 | 2621 | ||
2491 | dev_set_name(&dwc->gadget.dev, "gadget"); | ||
2492 | |||
2493 | dwc->gadget.ops = &dwc3_gadget_ops; | 2622 | dwc->gadget.ops = &dwc3_gadget_ops; |
2494 | dwc->gadget.max_speed = USB_SPEED_SUPER; | 2623 | dwc->gadget.max_speed = USB_SPEED_SUPER; |
2495 | dwc->gadget.speed = USB_SPEED_UNKNOWN; | 2624 | dwc->gadget.speed = USB_SPEED_UNKNOWN; |
2496 | dwc->gadget.dev.parent = dwc->dev; | ||
2497 | dwc->gadget.sg_supported = true; | 2625 | dwc->gadget.sg_supported = true; |
2498 | |||
2499 | dma_set_coherent_mask(&dwc->gadget.dev, dwc->dev->coherent_dma_mask); | ||
2500 | |||
2501 | dwc->gadget.dev.dma_parms = dwc->dev->dma_parms; | ||
2502 | dwc->gadget.dev.dma_mask = dwc->dev->dma_mask; | ||
2503 | dwc->gadget.dev.release = dwc3_gadget_release; | ||
2504 | dwc->gadget.name = "dwc3-gadget"; | 2626 | dwc->gadget.name = "dwc3-gadget"; |
2505 | 2627 | ||
2506 | /* | 2628 | /* |
@@ -2512,60 +2634,24 @@ int dwc3_gadget_init(struct dwc3 *dwc) | |||
2512 | if (ret) | 2634 | if (ret) |
2513 | goto err4; | 2635 | goto err4; |
2514 | 2636 | ||
2515 | irq = platform_get_irq(to_platform_device(dwc->dev), 0); | ||
2516 | |||
2517 | ret = request_irq(irq, dwc3_interrupt, IRQF_SHARED, | ||
2518 | "dwc3", dwc); | ||
2519 | if (ret) { | ||
2520 | dev_err(dwc->dev, "failed to request irq #%d --> %d\n", | ||
2521 | irq, ret); | ||
2522 | goto err5; | ||
2523 | } | ||
2524 | |||
2525 | reg = dwc3_readl(dwc->regs, DWC3_DCFG); | 2637 | reg = dwc3_readl(dwc->regs, DWC3_DCFG); |
2526 | reg |= DWC3_DCFG_LPM_CAP; | 2638 | reg |= DWC3_DCFG_LPM_CAP; |
2527 | dwc3_writel(dwc->regs, DWC3_DCFG, reg); | 2639 | dwc3_writel(dwc->regs, DWC3_DCFG, reg); |
2528 | 2640 | ||
2529 | /* Enable all but Start and End of Frame IRQs */ | 2641 | /* Enable USB2 LPM and automatic phy suspend only on recent versions */ |
2530 | reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN | | ||
2531 | DWC3_DEVTEN_EVNTOVERFLOWEN | | ||
2532 | DWC3_DEVTEN_CMDCMPLTEN | | ||
2533 | DWC3_DEVTEN_ERRTICERREN | | ||
2534 | DWC3_DEVTEN_WKUPEVTEN | | ||
2535 | DWC3_DEVTEN_ULSTCNGEN | | ||
2536 | DWC3_DEVTEN_CONNECTDONEEN | | ||
2537 | DWC3_DEVTEN_USBRSTEN | | ||
2538 | DWC3_DEVTEN_DISCONNEVTEN); | ||
2539 | dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); | ||
2540 | |||
2541 | /* automatic phy suspend only on recent versions */ | ||
2542 | if (dwc->revision >= DWC3_REVISION_194A) { | 2642 | if (dwc->revision >= DWC3_REVISION_194A) { |
2543 | dwc3_gadget_usb2_phy_suspend(dwc, false); | 2643 | dwc3_gadget_usb2_phy_suspend(dwc, false); |
2544 | dwc3_gadget_usb3_phy_suspend(dwc, false); | 2644 | dwc3_gadget_usb3_phy_suspend(dwc, false); |
2545 | } | 2645 | } |
2546 | 2646 | ||
2547 | ret = device_register(&dwc->gadget.dev); | ||
2548 | if (ret) { | ||
2549 | dev_err(dwc->dev, "failed to register gadget device\n"); | ||
2550 | put_device(&dwc->gadget.dev); | ||
2551 | goto err6; | ||
2552 | } | ||
2553 | |||
2554 | ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); | 2647 | ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); |
2555 | if (ret) { | 2648 | if (ret) { |
2556 | dev_err(dwc->dev, "failed to register udc\n"); | 2649 | dev_err(dwc->dev, "failed to register udc\n"); |
2557 | goto err7; | 2650 | goto err5; |
2558 | } | 2651 | } |
2559 | 2652 | ||
2560 | return 0; | 2653 | return 0; |
2561 | 2654 | ||
2562 | err7: | ||
2563 | device_unregister(&dwc->gadget.dev); | ||
2564 | |||
2565 | err6: | ||
2566 | dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); | ||
2567 | free_irq(irq, dwc); | ||
2568 | |||
2569 | err5: | 2655 | err5: |
2570 | dwc3_gadget_free_endpoints(dwc); | 2656 | dwc3_gadget_free_endpoints(dwc); |
2571 | 2657 | ||
@@ -2588,15 +2674,11 @@ err0: | |||
2588 | return ret; | 2674 | return ret; |
2589 | } | 2675 | } |
2590 | 2676 | ||
2677 | /* -------------------------------------------------------------------------- */ | ||
2678 | |||
2591 | void dwc3_gadget_exit(struct dwc3 *dwc) | 2679 | void dwc3_gadget_exit(struct dwc3 *dwc) |
2592 | { | 2680 | { |
2593 | int irq; | ||
2594 | |||
2595 | usb_del_gadget_udc(&dwc->gadget); | 2681 | usb_del_gadget_udc(&dwc->gadget); |
2596 | irq = platform_get_irq(to_platform_device(dwc->dev), 0); | ||
2597 | |||
2598 | dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); | ||
2599 | free_irq(irq, dwc); | ||
2600 | 2682 | ||
2601 | dwc3_gadget_free_endpoints(dwc); | 2683 | dwc3_gadget_free_endpoints(dwc); |
2602 | 2684 | ||
@@ -2610,6 +2692,63 @@ void dwc3_gadget_exit(struct dwc3 *dwc) | |||
2610 | 2692 | ||
2611 | dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), | 2693 | dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), |
2612 | dwc->ctrl_req, dwc->ctrl_req_addr); | 2694 | dwc->ctrl_req, dwc->ctrl_req_addr); |
2695 | } | ||
2613 | 2696 | ||
2614 | device_unregister(&dwc->gadget.dev); | 2697 | int dwc3_gadget_prepare(struct dwc3 *dwc) |
2698 | { | ||
2699 | if (dwc->pullups_connected) | ||
2700 | dwc3_gadget_disable_irq(dwc); | ||
2701 | |||
2702 | return 0; | ||
2703 | } | ||
2704 | |||
2705 | void dwc3_gadget_complete(struct dwc3 *dwc) | ||
2706 | { | ||
2707 | if (dwc->pullups_connected) { | ||
2708 | dwc3_gadget_enable_irq(dwc); | ||
2709 | dwc3_gadget_run_stop(dwc, true); | ||
2710 | } | ||
2711 | } | ||
2712 | |||
2713 | int dwc3_gadget_suspend(struct dwc3 *dwc) | ||
2714 | { | ||
2715 | __dwc3_gadget_ep_disable(dwc->eps[0]); | ||
2716 | __dwc3_gadget_ep_disable(dwc->eps[1]); | ||
2717 | |||
2718 | dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG); | ||
2719 | |||
2720 | return 0; | ||
2721 | } | ||
2722 | |||
2723 | int dwc3_gadget_resume(struct dwc3 *dwc) | ||
2724 | { | ||
2725 | struct dwc3_ep *dep; | ||
2726 | int ret; | ||
2727 | |||
2728 | /* Start with SuperSpeed Default */ | ||
2729 | dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); | ||
2730 | |||
2731 | dep = dwc->eps[0]; | ||
2732 | ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false); | ||
2733 | if (ret) | ||
2734 | goto err0; | ||
2735 | |||
2736 | dep = dwc->eps[1]; | ||
2737 | ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false); | ||
2738 | if (ret) | ||
2739 | goto err1; | ||
2740 | |||
2741 | /* begin to receive SETUP packets */ | ||
2742 | dwc->ep0state = EP0_SETUP_PHASE; | ||
2743 | dwc3_ep0_out_start(dwc); | ||
2744 | |||
2745 | dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg); | ||
2746 | |||
2747 | return 0; | ||
2748 | |||
2749 | err1: | ||
2750 | __dwc3_gadget_ep_disable(dwc->eps[0]); | ||
2751 | |||
2752 | err0: | ||
2753 | return ret; | ||
2615 | } | 2754 | } |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index c7525b1cad74..a61d981cbd15 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -196,7 +196,6 @@ config USB_OMAP | |||
196 | tristate "OMAP USB Device Controller" | 196 | tristate "OMAP USB Device Controller" |
197 | depends on ARCH_OMAP1 | 197 | depends on ARCH_OMAP1 |
198 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG | 198 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG |
199 | select USB_OTG_UTILS if ARCH_OMAP | ||
200 | help | 199 | help |
201 | Many Texas Instruments OMAP processors have flexible full | 200 | Many Texas Instruments OMAP processors have flexible full |
202 | speed USB device controllers, with support for up to 30 | 201 | speed USB device controllers, with support for up to 30 |
@@ -211,7 +210,6 @@ config USB_OMAP | |||
211 | config USB_PXA25X | 210 | config USB_PXA25X |
212 | tristate "PXA 25x or IXP 4xx" | 211 | tristate "PXA 25x or IXP 4xx" |
213 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX | 212 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX |
214 | select USB_OTG_UTILS | ||
215 | help | 213 | help |
216 | Intel's PXA 25x series XScale ARM-5TE processors include | 214 | Intel's PXA 25x series XScale ARM-5TE processors include |
217 | an integrated full speed USB 1.1 device controller. The | 215 | an integrated full speed USB 1.1 device controller. The |
@@ -259,8 +257,6 @@ config USB_RENESAS_USBHS_UDC | |||
259 | 257 | ||
260 | config USB_PXA27X | 258 | config USB_PXA27X |
261 | tristate "PXA 27x" | 259 | tristate "PXA 27x" |
262 | depends on ARCH_PXA && (PXA27x || PXA3xx) | ||
263 | select USB_OTG_UTILS | ||
264 | help | 260 | help |
265 | Intel's PXA 27x series XScale ARM v5TE processors include | 261 | Intel's PXA 27x series XScale ARM v5TE processors include |
266 | an integrated full speed USB 1.1 device controller. | 262 | an integrated full speed USB 1.1 device controller. |
@@ -329,9 +325,6 @@ config USB_MV_UDC | |||
329 | 325 | ||
330 | config USB_MV_U3D | 326 | config USB_MV_U3D |
331 | tristate "MARVELL PXA2128 USB 3.0 controller" | 327 | tristate "MARVELL PXA2128 USB 3.0 controller" |
332 | depends on CPU_MMP3 | ||
333 | select USB_GADGET_DUALSPEED | ||
334 | select USB_GADGET_SUPERSPEED | ||
335 | help | 328 | help |
336 | MARVELL PXA2128 Processor series include a super speed USB3.0 device | 329 | MARVELL PXA2128 Processor series include a super speed USB3.0 device |
337 | controller, which support super speed USB peripheral. | 330 | controller, which support super speed USB peripheral. |
@@ -501,6 +494,7 @@ endmenu | |||
501 | # composite based drivers | 494 | # composite based drivers |
502 | config USB_LIBCOMPOSITE | 495 | config USB_LIBCOMPOSITE |
503 | tristate | 496 | tristate |
497 | select CONFIGFS_FS | ||
504 | depends on USB_GADGET | 498 | depends on USB_GADGET |
505 | 499 | ||
506 | config USB_F_ACM | 500 | config USB_F_ACM |
@@ -512,6 +506,12 @@ config USB_F_SS_LB | |||
512 | config USB_U_SERIAL | 506 | config USB_U_SERIAL |
513 | tristate | 507 | tristate |
514 | 508 | ||
509 | config USB_F_SERIAL | ||
510 | tristate | ||
511 | |||
512 | config USB_F_OBEX | ||
513 | tristate | ||
514 | |||
515 | choice | 515 | choice |
516 | tristate "USB Gadget Drivers" | 516 | tristate "USB Gadget Drivers" |
517 | default USB_ETH | 517 | default USB_ETH |
@@ -766,6 +766,8 @@ config USB_G_SERIAL | |||
766 | depends on TTY | 766 | depends on TTY |
767 | select USB_U_SERIAL | 767 | select USB_U_SERIAL |
768 | select USB_F_ACM | 768 | select USB_F_ACM |
769 | select USB_F_SERIAL | ||
770 | select USB_F_OBEX | ||
769 | select USB_LIBCOMPOSITE | 771 | select USB_LIBCOMPOSITE |
770 | help | 772 | help |
771 | The Serial Gadget talks to the Linux-USB generic serial driver. | 773 | The Serial Gadget talks to the Linux-USB generic serial driver. |
@@ -839,6 +841,7 @@ config USB_G_NOKIA | |||
839 | depends on PHONET | 841 | depends on PHONET |
840 | select USB_LIBCOMPOSITE | 842 | select USB_LIBCOMPOSITE |
841 | select USB_U_SERIAL | 843 | select USB_U_SERIAL |
844 | select USB_F_ACM | ||
842 | help | 845 | help |
843 | The Nokia composite gadget provides support for acm, obex | 846 | The Nokia composite gadget provides support for acm, obex |
844 | and phonet in only one composite gadget driver. | 847 | and phonet in only one composite gadget driver. |
@@ -957,6 +960,7 @@ config USB_G_WEBCAM | |||
957 | tristate "USB Webcam Gadget" | 960 | tristate "USB Webcam Gadget" |
958 | depends on VIDEO_DEV | 961 | depends on VIDEO_DEV |
959 | select USB_LIBCOMPOSITE | 962 | select USB_LIBCOMPOSITE |
963 | select VIDEOBUF2_VMALLOC | ||
960 | help | 964 | help |
961 | The Webcam Gadget acts as a composite USB Audio and Video Class | 965 | The Webcam Gadget acts as a composite USB Audio and Video Class |
962 | device. It provides a userspace API to process UVC control requests | 966 | device. It provides a userspace API to process UVC control requests |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 82fb22511356..6afd16659e78 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -6,7 +6,7 @@ ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG | |||
6 | obj-$(CONFIG_USB_GADGET) += udc-core.o | 6 | obj-$(CONFIG_USB_GADGET) += udc-core.o |
7 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o | 7 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o |
8 | libcomposite-y := usbstring.o config.o epautoconf.o | 8 | libcomposite-y := usbstring.o config.o epautoconf.o |
9 | libcomposite-y += composite.o functions.o | 9 | libcomposite-y += composite.o functions.o configfs.o |
10 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | 10 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o |
11 | obj-$(CONFIG_USB_NET2272) += net2272.o | 11 | obj-$(CONFIG_USB_NET2272) += net2272.o |
12 | obj-$(CONFIG_USB_NET2280) += net2280.o | 12 | obj-$(CONFIG_USB_NET2280) += net2280.o |
@@ -36,10 +36,15 @@ obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | |||
36 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | 36 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o |
37 | 37 | ||
38 | # USB Functions | 38 | # USB Functions |
39 | obj-$(CONFIG_USB_F_ACM) += f_acm.o | 39 | usb_f_acm-y := f_acm.o |
40 | f_ss_lb-y := f_loopback.o f_sourcesink.o | 40 | obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o |
41 | obj-$(CONFIG_USB_F_SS_LB) += f_ss_lb.o | 41 | usb_f_ss_lb-y := f_loopback.o f_sourcesink.o |
42 | obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o | ||
42 | obj-$(CONFIG_USB_U_SERIAL) += u_serial.o | 43 | obj-$(CONFIG_USB_U_SERIAL) += u_serial.o |
44 | usb_f_serial-y := f_serial.o | ||
45 | obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o | ||
46 | usb_f_obex-y := f_obex.o | ||
47 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o | ||
43 | 48 | ||
44 | # | 49 | # |
45 | # USB gadget drivers | 50 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 8f2b0e391534..4b947bb50f62 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c | |||
@@ -109,7 +109,6 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | |||
109 | static struct fsg_common fsg_common; | 109 | static struct fsg_common fsg_common; |
110 | 110 | ||
111 | /*-------------------------------------------------------------------------*/ | 111 | /*-------------------------------------------------------------------------*/ |
112 | static unsigned char tty_line; | ||
113 | static struct usb_function *f_acm; | 112 | static struct usb_function *f_acm; |
114 | static struct usb_function_instance *f_acm_inst; | 113 | static struct usb_function_instance *f_acm_inst; |
115 | /* | 114 | /* |
@@ -117,7 +116,6 @@ static struct usb_function_instance *f_acm_inst; | |||
117 | */ | 116 | */ |
118 | static int __init acm_ms_do_config(struct usb_configuration *c) | 117 | static int __init acm_ms_do_config(struct usb_configuration *c) |
119 | { | 118 | { |
120 | struct f_serial_opts *opts; | ||
121 | int status; | 119 | int status; |
122 | 120 | ||
123 | if (gadget_is_otg(c->cdev->gadget)) { | 121 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -129,9 +127,6 @@ static int __init acm_ms_do_config(struct usb_configuration *c) | |||
129 | if (IS_ERR(f_acm_inst)) | 127 | if (IS_ERR(f_acm_inst)) |
130 | return PTR_ERR(f_acm_inst); | 128 | return PTR_ERR(f_acm_inst); |
131 | 129 | ||
132 | opts = container_of(f_acm_inst, struct f_serial_opts, func_inst); | ||
133 | opts->port_num = tty_line; | ||
134 | |||
135 | f_acm = usb_get_function(f_acm_inst); | 130 | f_acm = usb_get_function(f_acm_inst); |
136 | if (IS_ERR(f_acm)) { | 131 | if (IS_ERR(f_acm)) { |
137 | status = PTR_ERR(f_acm); | 132 | status = PTR_ERR(f_acm); |
@@ -171,16 +166,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev) | |||
171 | int status; | 166 | int status; |
172 | void *retp; | 167 | void *retp; |
173 | 168 | ||
174 | /* set up serial link layer */ | ||
175 | status = gserial_alloc_line(&tty_line); | ||
176 | if (status < 0) | ||
177 | return status; | ||
178 | |||
179 | /* set up mass storage function */ | 169 | /* set up mass storage function */ |
180 | retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); | 170 | retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); |
181 | if (IS_ERR(retp)) { | 171 | if (IS_ERR(retp)) { |
182 | status = PTR_ERR(retp); | 172 | status = PTR_ERR(retp); |
183 | goto fail0; | 173 | return PTR_ERR(retp); |
184 | } | 174 | } |
185 | 175 | ||
186 | /* | 176 | /* |
@@ -207,8 +197,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev) | |||
207 | /* error recovery */ | 197 | /* error recovery */ |
208 | fail1: | 198 | fail1: |
209 | fsg_common_put(&fsg_common); | 199 | fsg_common_put(&fsg_common); |
210 | fail0: | ||
211 | gserial_free_line(tty_line); | ||
212 | return status; | 200 | return status; |
213 | } | 201 | } |
214 | 202 | ||
@@ -216,7 +204,6 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) | |||
216 | { | 204 | { |
217 | usb_put_function(f_acm); | 205 | usb_put_function(f_acm); |
218 | usb_put_function_instance(f_acm_inst); | 206 | usb_put_function_instance(f_acm_inst); |
219 | gserial_free_line(tty_line); | ||
220 | return 0; | 207 | return 0; |
221 | } | 208 | } |
222 | 209 | ||
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 75973f33a4c8..f52dcfe8f545 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -1922,7 +1922,6 @@ static int amd5536_udc_start(struct usb_gadget *g, | |||
1922 | 1922 | ||
1923 | driver->driver.bus = NULL; | 1923 | driver->driver.bus = NULL; |
1924 | dev->driver = driver; | 1924 | dev->driver = driver; |
1925 | dev->gadget.dev.driver = &driver->driver; | ||
1926 | 1925 | ||
1927 | /* Some gadget drivers use both ep0 directions. | 1926 | /* Some gadget drivers use both ep0 directions. |
1928 | * NOTE: to gadget driver, ep0 is just one endpoint... | 1927 | * NOTE: to gadget driver, ep0 is just one endpoint... |
@@ -1973,7 +1972,6 @@ static int amd5536_udc_stop(struct usb_gadget *g, | |||
1973 | shutdown(dev, driver); | 1972 | shutdown(dev, driver); |
1974 | spin_unlock_irqrestore(&dev->lock, flags); | 1973 | spin_unlock_irqrestore(&dev->lock, flags); |
1975 | 1974 | ||
1976 | dev->gadget.dev.driver = NULL; | ||
1977 | dev->driver = NULL; | 1975 | dev->driver = NULL; |
1978 | 1976 | ||
1979 | /* set SD */ | 1977 | /* set SD */ |
@@ -3080,7 +3078,6 @@ static void udc_pci_remove(struct pci_dev *pdev) | |||
3080 | if (dev->active) | 3078 | if (dev->active) |
3081 | pci_disable_device(pdev); | 3079 | pci_disable_device(pdev); |
3082 | 3080 | ||
3083 | device_unregister(&dev->gadget.dev); | ||
3084 | pci_set_drvdata(pdev, NULL); | 3081 | pci_set_drvdata(pdev, NULL); |
3085 | 3082 | ||
3086 | udc_remove(dev); | 3083 | udc_remove(dev); |
@@ -3245,8 +3242,6 @@ static int udc_pci_probe( | |||
3245 | dev->phys_addr = resource; | 3242 | dev->phys_addr = resource; |
3246 | dev->irq = pdev->irq; | 3243 | dev->irq = pdev->irq; |
3247 | dev->pdev = pdev; | 3244 | dev->pdev = pdev; |
3248 | dev->gadget.dev.parent = &pdev->dev; | ||
3249 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
3250 | 3245 | ||
3251 | /* general probing */ | 3246 | /* general probing */ |
3252 | if (udc_probe(dev) == 0) | 3247 | if (udc_probe(dev) == 0) |
@@ -3273,7 +3268,6 @@ static int udc_probe(struct udc *dev) | |||
3273 | dev->gadget.ops = &udc_ops; | 3268 | dev->gadget.ops = &udc_ops; |
3274 | 3269 | ||
3275 | dev_set_name(&dev->gadget.dev, "gadget"); | 3270 | dev_set_name(&dev->gadget.dev, "gadget"); |
3276 | dev->gadget.dev.release = gadget_release; | ||
3277 | dev->gadget.name = name; | 3271 | dev->gadget.name = name; |
3278 | dev->gadget.max_speed = USB_SPEED_HIGH; | 3272 | dev->gadget.max_speed = USB_SPEED_HIGH; |
3279 | 3273 | ||
@@ -3297,17 +3291,11 @@ static int udc_probe(struct udc *dev) | |||
3297 | "driver version: %s(for Geode5536 B1)\n", tmp); | 3291 | "driver version: %s(for Geode5536 B1)\n", tmp); |
3298 | udc = dev; | 3292 | udc = dev; |
3299 | 3293 | ||
3300 | retval = usb_add_gadget_udc(&udc->pdev->dev, &dev->gadget); | 3294 | retval = usb_add_gadget_udc_release(&udc->pdev->dev, &dev->gadget, |
3295 | gadget_release); | ||
3301 | if (retval) | 3296 | if (retval) |
3302 | goto finished; | 3297 | goto finished; |
3303 | 3298 | ||
3304 | retval = device_register(&dev->gadget.dev); | ||
3305 | if (retval) { | ||
3306 | usb_del_gadget_udc(&dev->gadget); | ||
3307 | put_device(&dev->gadget.dev); | ||
3308 | goto finished; | ||
3309 | } | ||
3310 | |||
3311 | /* timer init */ | 3299 | /* timer init */ |
3312 | init_timer(&udc_timer); | 3300 | init_timer(&udc_timer); |
3313 | udc_timer.function = udc_timer_function; | 3301 | udc_timer.function = udc_timer_function; |
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h index f1bf32e6b8d8..6744d3b83109 100644 --- a/drivers/usb/gadget/amd5536udc.h +++ b/drivers/usb/gadget/amd5536udc.h | |||
@@ -472,7 +472,6 @@ struct udc_request { | |||
472 | 472 | ||
473 | /* flags */ | 473 | /* flags */ |
474 | unsigned dma_going : 1, | 474 | unsigned dma_going : 1, |
475 | dma_mapping : 1, | ||
476 | dma_done : 1; | 475 | dma_done : 1; |
477 | /* phys. address */ | 476 | /* phys. address */ |
478 | dma_addr_t td_phys; | 477 | dma_addr_t td_phys; |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 45dd2929a671..a690d64217f4 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -1631,7 +1631,6 @@ static int at91_start(struct usb_gadget *gadget, | |||
1631 | 1631 | ||
1632 | udc = container_of(gadget, struct at91_udc, gadget); | 1632 | udc = container_of(gadget, struct at91_udc, gadget); |
1633 | udc->driver = driver; | 1633 | udc->driver = driver; |
1634 | udc->gadget.dev.driver = &driver->driver; | ||
1635 | udc->gadget.dev.of_node = udc->pdev->dev.of_node; | 1634 | udc->gadget.dev.of_node = udc->pdev->dev.of_node; |
1636 | udc->enabled = 1; | 1635 | udc->enabled = 1; |
1637 | udc->selfpowered = 1; | 1636 | udc->selfpowered = 1; |
@@ -1652,7 +1651,6 @@ static int at91_stop(struct usb_gadget *gadget, | |||
1652 | at91_udp_write(udc, AT91_UDP_IDR, ~0); | 1651 | at91_udp_write(udc, AT91_UDP_IDR, ~0); |
1653 | spin_unlock_irqrestore(&udc->lock, flags); | 1652 | spin_unlock_irqrestore(&udc->lock, flags); |
1654 | 1653 | ||
1655 | udc->gadget.dev.driver = NULL; | ||
1656 | udc->driver = NULL; | 1654 | udc->driver = NULL; |
1657 | 1655 | ||
1658 | DBG("unbound from %s\n", driver->driver.name); | 1656 | DBG("unbound from %s\n", driver->driver.name); |
@@ -1780,13 +1778,7 @@ static int at91udc_probe(struct platform_device *pdev) | |||
1780 | DBG("clocks missing\n"); | 1778 | DBG("clocks missing\n"); |
1781 | retval = -ENODEV; | 1779 | retval = -ENODEV; |
1782 | /* NOTE: we "know" here that refcounts on these are NOPs */ | 1780 | /* NOTE: we "know" here that refcounts on these are NOPs */ |
1783 | goto fail0b; | 1781 | goto fail1; |
1784 | } | ||
1785 | |||
1786 | retval = device_register(&udc->gadget.dev); | ||
1787 | if (retval < 0) { | ||
1788 | put_device(&udc->gadget.dev); | ||
1789 | goto fail0b; | ||
1790 | } | 1782 | } |
1791 | 1783 | ||
1792 | /* don't do anything until we have both gadget driver and VBUS */ | 1784 | /* don't do anything until we have both gadget driver and VBUS */ |
@@ -1857,8 +1849,6 @@ fail3: | |||
1857 | fail2: | 1849 | fail2: |
1858 | free_irq(udc->udp_irq, udc); | 1850 | free_irq(udc->udp_irq, udc); |
1859 | fail1: | 1851 | fail1: |
1860 | device_unregister(&udc->gadget.dev); | ||
1861 | fail0b: | ||
1862 | iounmap(udc->udp_baseaddr); | 1852 | iounmap(udc->udp_baseaddr); |
1863 | fail0a: | 1853 | fail0a: |
1864 | if (cpu_is_at91rm9200()) | 1854 | if (cpu_is_at91rm9200()) |
@@ -1892,8 +1882,6 @@ static int __exit at91udc_remove(struct platform_device *pdev) | |||
1892 | gpio_free(udc->board.vbus_pin); | 1882 | gpio_free(udc->board.vbus_pin); |
1893 | } | 1883 | } |
1894 | free_irq(udc->udp_irq, udc); | 1884 | free_irq(udc->udp_irq, udc); |
1895 | device_unregister(&udc->gadget.dev); | ||
1896 | |||
1897 | iounmap(udc->udp_baseaddr); | 1885 | iounmap(udc->udp_baseaddr); |
1898 | 1886 | ||
1899 | if (cpu_is_at91rm9200()) | 1887 | if (cpu_is_at91rm9200()) |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index b66130c97269..f2a970f75bfa 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -489,13 +489,8 @@ request_complete(struct usba_ep *ep, struct usba_request *req, int status) | |||
489 | if (req->req.status == -EINPROGRESS) | 489 | if (req->req.status == -EINPROGRESS) |
490 | req->req.status = status; | 490 | req->req.status = status; |
491 | 491 | ||
492 | if (req->mapped) { | 492 | if (req->using_dma) |
493 | dma_unmap_single( | 493 | usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); |
494 | &udc->pdev->dev, req->req.dma, req->req.length, | ||
495 | ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
496 | req->req.dma = DMA_ADDR_INVALID; | ||
497 | req->mapped = 0; | ||
498 | } | ||
499 | 494 | ||
500 | DBG(DBG_GADGET | DBG_REQ, | 495 | DBG(DBG_GADGET | DBG_REQ, |
501 | "%s: req %p complete: status %d, actual %u\n", | 496 | "%s: req %p complete: status %d, actual %u\n", |
@@ -684,7 +679,6 @@ usba_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | |||
684 | return NULL; | 679 | return NULL; |
685 | 680 | ||
686 | INIT_LIST_HEAD(&req->queue); | 681 | INIT_LIST_HEAD(&req->queue); |
687 | req->req.dma = DMA_ADDR_INVALID; | ||
688 | 682 | ||
689 | return &req->req; | 683 | return &req->req; |
690 | } | 684 | } |
@@ -717,20 +711,11 @@ static int queue_dma(struct usba_udc *udc, struct usba_ep *ep, | |||
717 | return -EINVAL; | 711 | return -EINVAL; |
718 | } | 712 | } |
719 | 713 | ||
720 | req->using_dma = 1; | 714 | ret = usb_gadget_map_request(&udc->gadget, &req->req, ep->is_in); |
721 | 715 | if (ret) | |
722 | if (req->req.dma == DMA_ADDR_INVALID) { | 716 | return ret; |
723 | req->req.dma = dma_map_single( | ||
724 | &udc->pdev->dev, req->req.buf, req->req.length, | ||
725 | ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
726 | req->mapped = 1; | ||
727 | } else { | ||
728 | dma_sync_single_for_device( | ||
729 | &udc->pdev->dev, req->req.dma, req->req.length, | ||
730 | ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
731 | req->mapped = 0; | ||
732 | } | ||
733 | 717 | ||
718 | req->using_dma = 1; | ||
734 | req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length) | 719 | req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length) |
735 | | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE | 720 | | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE |
736 | | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE; | 721 | | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE; |
@@ -1799,7 +1784,6 @@ static int atmel_usba_start(struct usb_gadget *gadget, | |||
1799 | 1784 | ||
1800 | udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; | 1785 | udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; |
1801 | udc->driver = driver; | 1786 | udc->driver = driver; |
1802 | udc->gadget.dev.driver = &driver->driver; | ||
1803 | spin_unlock_irqrestore(&udc->lock, flags); | 1787 | spin_unlock_irqrestore(&udc->lock, flags); |
1804 | 1788 | ||
1805 | clk_enable(udc->pclk); | 1789 | clk_enable(udc->pclk); |
@@ -1841,7 +1825,6 @@ static int atmel_usba_stop(struct usb_gadget *gadget, | |||
1841 | toggle_bias(0); | 1825 | toggle_bias(0); |
1842 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | 1826 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); |
1843 | 1827 | ||
1844 | udc->gadget.dev.driver = NULL; | ||
1845 | udc->driver = NULL; | 1828 | udc->driver = NULL; |
1846 | 1829 | ||
1847 | clk_disable(udc->hclk); | 1830 | clk_disable(udc->hclk); |
@@ -1900,10 +1883,6 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
1900 | dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", | 1883 | dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", |
1901 | (unsigned long)fifo->start, udc->fifo); | 1884 | (unsigned long)fifo->start, udc->fifo); |
1902 | 1885 | ||
1903 | device_initialize(&udc->gadget.dev); | ||
1904 | udc->gadget.dev.parent = &pdev->dev; | ||
1905 | udc->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1906 | |||
1907 | platform_set_drvdata(pdev, udc); | 1886 | platform_set_drvdata(pdev, udc); |
1908 | 1887 | ||
1909 | /* Make sure we start from a clean slate */ | 1888 | /* Make sure we start from a clean slate */ |
@@ -1962,12 +1941,6 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
1962 | } | 1941 | } |
1963 | udc->irq = irq; | 1942 | udc->irq = irq; |
1964 | 1943 | ||
1965 | ret = device_add(&udc->gadget.dev); | ||
1966 | if (ret) { | ||
1967 | dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret); | ||
1968 | goto err_device_add; | ||
1969 | } | ||
1970 | |||
1971 | if (gpio_is_valid(pdata->vbus_pin)) { | 1944 | if (gpio_is_valid(pdata->vbus_pin)) { |
1972 | if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { | 1945 | if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { |
1973 | udc->vbus_pin = pdata->vbus_pin; | 1946 | udc->vbus_pin = pdata->vbus_pin; |
@@ -2007,9 +1980,6 @@ err_add_udc: | |||
2007 | gpio_free(udc->vbus_pin); | 1980 | gpio_free(udc->vbus_pin); |
2008 | } | 1981 | } |
2009 | 1982 | ||
2010 | device_unregister(&udc->gadget.dev); | ||
2011 | |||
2012 | err_device_add: | ||
2013 | free_irq(irq, udc); | 1983 | free_irq(irq, udc); |
2014 | err_request_irq: | 1984 | err_request_irq: |
2015 | kfree(usba_ep); | 1985 | kfree(usba_ep); |
@@ -2053,8 +2023,6 @@ static int __exit usba_udc_remove(struct platform_device *pdev) | |||
2053 | clk_put(udc->hclk); | 2023 | clk_put(udc->hclk); |
2054 | clk_put(udc->pclk); | 2024 | clk_put(udc->pclk); |
2055 | 2025 | ||
2056 | device_unregister(&udc->gadget.dev); | ||
2057 | |||
2058 | return 0; | 2026 | return 0; |
2059 | } | 2027 | } |
2060 | 2028 | ||
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h index 9791259cbda7..d65a61851d3d 100644 --- a/drivers/usb/gadget/atmel_usba_udc.h +++ b/drivers/usb/gadget/atmel_usba_udc.h | |||
@@ -216,12 +216,6 @@ | |||
216 | #define EP0_EPT_SIZE USBA_EPT_SIZE_64 | 216 | #define EP0_EPT_SIZE USBA_EPT_SIZE_64 |
217 | #define EP0_NR_BANKS 1 | 217 | #define EP0_NR_BANKS 1 |
218 | 218 | ||
219 | /* | ||
220 | * REVISIT: Try to eliminate this value. Can we rely on req->mapped to | ||
221 | * provide this information? | ||
222 | */ | ||
223 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
224 | |||
225 | #define FIFO_IOMEM_ID 0 | 219 | #define FIFO_IOMEM_ID 0 |
226 | #define CTRL_IOMEM_ID 1 | 220 | #define CTRL_IOMEM_ID 1 |
227 | 221 | ||
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c index 8cc8253f1100..6e6518264c42 100644 --- a/drivers/usb/gadget/bcm63xx_udc.c +++ b/drivers/usb/gadget/bcm63xx_udc.c | |||
@@ -1819,7 +1819,6 @@ static int bcm63xx_udc_start(struct usb_gadget *gadget, | |||
1819 | 1819 | ||
1820 | udc->driver = driver; | 1820 | udc->driver = driver; |
1821 | driver->driver.bus = NULL; | 1821 | driver->driver.bus = NULL; |
1822 | udc->gadget.dev.driver = &driver->driver; | ||
1823 | udc->gadget.dev.of_node = udc->dev->of_node; | 1822 | udc->gadget.dev.of_node = udc->dev->of_node; |
1824 | 1823 | ||
1825 | spin_unlock_irqrestore(&udc->lock, flags); | 1824 | spin_unlock_irqrestore(&udc->lock, flags); |
@@ -1841,7 +1840,6 @@ static int bcm63xx_udc_stop(struct usb_gadget *gadget, | |||
1841 | spin_lock_irqsave(&udc->lock, flags); | 1840 | spin_lock_irqsave(&udc->lock, flags); |
1842 | 1841 | ||
1843 | udc->driver = NULL; | 1842 | udc->driver = NULL; |
1844 | udc->gadget.dev.driver = NULL; | ||
1845 | 1843 | ||
1846 | /* | 1844 | /* |
1847 | * If we switch the PHY too abruptly after dropping D+, the host | 1845 | * If we switch the PHY too abruptly after dropping D+, the host |
@@ -2306,17 +2304,6 @@ static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc) | |||
2306 | ***********************************************************************/ | 2304 | ***********************************************************************/ |
2307 | 2305 | ||
2308 | /** | 2306 | /** |
2309 | * bcm63xx_udc_gadget_release - Called from device_release(). | ||
2310 | * @dev: Unused. | ||
2311 | * | ||
2312 | * We get a warning if this function doesn't exist, but it's empty because | ||
2313 | * we don't have to free any of the memory allocated with the devm_* APIs. | ||
2314 | */ | ||
2315 | static void bcm63xx_udc_gadget_release(struct device *dev) | ||
2316 | { | ||
2317 | } | ||
2318 | |||
2319 | /** | ||
2320 | * bcm63xx_udc_probe - Initialize a new instance of the UDC. | 2307 | * bcm63xx_udc_probe - Initialize a new instance of the UDC. |
2321 | * @pdev: Platform device struct from the bcm63xx BSP code. | 2308 | * @pdev: Platform device struct from the bcm63xx BSP code. |
2322 | * | 2309 | * |
@@ -2368,13 +2355,9 @@ static int bcm63xx_udc_probe(struct platform_device *pdev) | |||
2368 | 2355 | ||
2369 | spin_lock_init(&udc->lock); | 2356 | spin_lock_init(&udc->lock); |
2370 | INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); | 2357 | INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); |
2371 | dev_set_name(&udc->gadget.dev, "gadget"); | ||
2372 | 2358 | ||
2373 | udc->gadget.ops = &bcm63xx_udc_ops; | 2359 | udc->gadget.ops = &bcm63xx_udc_ops; |
2374 | udc->gadget.name = dev_name(dev); | 2360 | udc->gadget.name = dev_name(dev); |
2375 | udc->gadget.dev.parent = dev; | ||
2376 | udc->gadget.dev.release = bcm63xx_udc_gadget_release; | ||
2377 | udc->gadget.dev.dma_mask = dev->dma_mask; | ||
2378 | 2361 | ||
2379 | if (!pd->use_fullspeed && !use_fullspeed) | 2362 | if (!pd->use_fullspeed && !use_fullspeed) |
2380 | udc->gadget.max_speed = USB_SPEED_HIGH; | 2363 | udc->gadget.max_speed = USB_SPEED_HIGH; |
@@ -2414,17 +2397,12 @@ static int bcm63xx_udc_probe(struct platform_device *pdev) | |||
2414 | } | 2397 | } |
2415 | } | 2398 | } |
2416 | 2399 | ||
2417 | rc = device_register(&udc->gadget.dev); | ||
2418 | if (rc) | ||
2419 | goto out_uninit; | ||
2420 | |||
2421 | bcm63xx_udc_init_debugfs(udc); | 2400 | bcm63xx_udc_init_debugfs(udc); |
2422 | rc = usb_add_gadget_udc(dev, &udc->gadget); | 2401 | rc = usb_add_gadget_udc(dev, &udc->gadget); |
2423 | if (!rc) | 2402 | if (!rc) |
2424 | return 0; | 2403 | return 0; |
2425 | 2404 | ||
2426 | bcm63xx_udc_cleanup_debugfs(udc); | 2405 | bcm63xx_udc_cleanup_debugfs(udc); |
2427 | device_unregister(&udc->gadget.dev); | ||
2428 | out_uninit: | 2406 | out_uninit: |
2429 | bcm63xx_uninit_udc_hw(udc); | 2407 | bcm63xx_uninit_udc_hw(udc); |
2430 | return rc; | 2408 | return rc; |
@@ -2440,7 +2418,6 @@ static int bcm63xx_udc_remove(struct platform_device *pdev) | |||
2440 | 2418 | ||
2441 | bcm63xx_udc_cleanup_debugfs(udc); | 2419 | bcm63xx_udc_cleanup_debugfs(udc); |
2442 | usb_del_gadget_udc(&udc->gadget); | 2420 | usb_del_gadget_udc(&udc->gadget); |
2443 | device_unregister(&udc->gadget.dev); | ||
2444 | BUG_ON(udc->driver); | 2421 | BUG_ON(udc->driver); |
2445 | 2422 | ||
2446 | platform_set_drvdata(pdev, NULL); | 2423 | platform_set_drvdata(pdev, NULL); |
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index a7d6f7026757..c6ee6f1558c3 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c | |||
@@ -103,18 +103,16 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
103 | }; | 103 | }; |
104 | 104 | ||
105 | static u8 hostaddr[ETH_ALEN]; | 105 | static u8 hostaddr[ETH_ALEN]; |
106 | 106 | static struct eth_dev *the_dev; | |
107 | /*-------------------------------------------------------------------------*/ | 107 | /*-------------------------------------------------------------------------*/ |
108 | static struct usb_function *f_acm; | 108 | static struct usb_function *f_acm; |
109 | static struct usb_function_instance *fi_serial; | 109 | static struct usb_function_instance *fi_serial; |
110 | 110 | ||
111 | static unsigned char tty_line; | ||
112 | /* | 111 | /* |
113 | * We _always_ have both CDC ECM and CDC ACM functions. | 112 | * We _always_ have both CDC ECM and CDC ACM functions. |
114 | */ | 113 | */ |
115 | static int __init cdc_do_config(struct usb_configuration *c) | 114 | static int __init cdc_do_config(struct usb_configuration *c) |
116 | { | 115 | { |
117 | struct f_serial_opts *opts; | ||
118 | int status; | 116 | int status; |
119 | 117 | ||
120 | if (gadget_is_otg(c->cdev->gadget)) { | 118 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -122,7 +120,7 @@ static int __init cdc_do_config(struct usb_configuration *c) | |||
122 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 120 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
123 | } | 121 | } |
124 | 122 | ||
125 | status = ecm_bind_config(c, hostaddr); | 123 | status = ecm_bind_config(c, hostaddr, the_dev); |
126 | if (status < 0) | 124 | if (status < 0) |
127 | return status; | 125 | return status; |
128 | 126 | ||
@@ -130,9 +128,6 @@ static int __init cdc_do_config(struct usb_configuration *c) | |||
130 | if (IS_ERR(fi_serial)) | 128 | if (IS_ERR(fi_serial)) |
131 | return PTR_ERR(fi_serial); | 129 | return PTR_ERR(fi_serial); |
132 | 130 | ||
133 | opts = container_of(fi_serial, struct f_serial_opts, func_inst); | ||
134 | opts->port_num = tty_line; | ||
135 | |||
136 | f_acm = usb_get_function(fi_serial); | 131 | f_acm = usb_get_function(fi_serial); |
137 | if (IS_ERR(f_acm)) | 132 | if (IS_ERR(f_acm)) |
138 | goto err_func_acm; | 133 | goto err_func_acm; |
@@ -169,14 +164,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) | |||
169 | } | 164 | } |
170 | 165 | ||
171 | /* set up network link layer */ | 166 | /* set up network link layer */ |
172 | status = gether_setup(cdev->gadget, hostaddr); | 167 | the_dev = gether_setup(cdev->gadget, hostaddr); |
173 | if (status < 0) | 168 | if (IS_ERR(the_dev)) |
174 | return status; | 169 | return PTR_ERR(the_dev); |
175 | |||
176 | /* set up serial link layer */ | ||
177 | status = gserial_alloc_line(&tty_line); | ||
178 | if (status < 0) | ||
179 | goto fail0; | ||
180 | 170 | ||
181 | /* Allocate string descriptor numbers ... note that string | 171 | /* Allocate string descriptor numbers ... note that string |
182 | * contents can be overridden by the composite_dev glue. | 172 | * contents can be overridden by the composite_dev glue. |
@@ -200,9 +190,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) | |||
200 | return 0; | 190 | return 0; |
201 | 191 | ||
202 | fail1: | 192 | fail1: |
203 | gserial_free_line(tty_line); | 193 | gether_cleanup(the_dev); |
204 | fail0: | ||
205 | gether_cleanup(); | ||
206 | return status; | 194 | return status; |
207 | } | 195 | } |
208 | 196 | ||
@@ -210,8 +198,7 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev) | |||
210 | { | 198 | { |
211 | usb_put_function(f_acm); | 199 | usb_put_function(f_acm); |
212 | usb_put_function_instance(fi_serial); | 200 | usb_put_function_instance(fi_serial); |
213 | gserial_free_line(tty_line); | 201 | gether_cleanup(the_dev); |
214 | gether_cleanup(); | ||
215 | return 0; | 202 | return 0; |
216 | } | 203 | } |
217 | 204 | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index c0d62b278610..55f4df60f327 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -1637,6 +1637,7 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) | |||
1637 | kfree(cdev->req->buf); | 1637 | kfree(cdev->req->buf); |
1638 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); | 1638 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); |
1639 | } | 1639 | } |
1640 | cdev->next_string_id = 0; | ||
1640 | device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); | 1641 | device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); |
1641 | } | 1642 | } |
1642 | 1643 | ||
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c new file mode 100644 index 000000000000..a34633a898a1 --- /dev/null +++ b/drivers/usb/gadget/configfs.c | |||
@@ -0,0 +1,1003 @@ | |||
1 | #include <linux/configfs.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/slab.h> | ||
4 | #include <linux/device.h> | ||
5 | #include <linux/usb/composite.h> | ||
6 | #include <linux/usb/gadget_configfs.h> | ||
7 | |||
8 | int check_user_usb_string(const char *name, | ||
9 | struct usb_gadget_strings *stringtab_dev) | ||
10 | { | ||
11 | unsigned primary_lang; | ||
12 | unsigned sub_lang; | ||
13 | u16 num; | ||
14 | int ret; | ||
15 | |||
16 | ret = kstrtou16(name, 0, &num); | ||
17 | if (ret) | ||
18 | return ret; | ||
19 | |||
20 | primary_lang = num & 0x3ff; | ||
21 | sub_lang = num >> 10; | ||
22 | |||
23 | /* simple sanity check for valid langid */ | ||
24 | switch (primary_lang) { | ||
25 | case 0: | ||
26 | case 0x62 ... 0xfe: | ||
27 | case 0x100 ... 0x3ff: | ||
28 | return -EINVAL; | ||
29 | } | ||
30 | if (!sub_lang) | ||
31 | return -EINVAL; | ||
32 | |||
33 | stringtab_dev->language = num; | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | #define MAX_NAME_LEN 40 | ||
38 | #define MAX_USB_STRING_LANGS 2 | ||
39 | |||
40 | struct gadget_info { | ||
41 | struct config_group group; | ||
42 | struct config_group functions_group; | ||
43 | struct config_group configs_group; | ||
44 | struct config_group strings_group; | ||
45 | struct config_group *default_groups[4]; | ||
46 | |||
47 | struct mutex lock; | ||
48 | struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; | ||
49 | struct list_head string_list; | ||
50 | struct list_head available_func; | ||
51 | |||
52 | const char *udc_name; | ||
53 | #ifdef CONFIG_USB_OTG | ||
54 | struct usb_otg_descriptor otg; | ||
55 | #endif | ||
56 | struct usb_composite_driver composite; | ||
57 | struct usb_composite_dev cdev; | ||
58 | }; | ||
59 | |||
60 | struct config_usb_cfg { | ||
61 | struct config_group group; | ||
62 | struct config_group strings_group; | ||
63 | struct config_group *default_groups[2]; | ||
64 | struct list_head string_list; | ||
65 | struct usb_configuration c; | ||
66 | struct list_head func_list; | ||
67 | struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; | ||
68 | }; | ||
69 | |||
70 | struct gadget_strings { | ||
71 | struct usb_gadget_strings stringtab_dev; | ||
72 | struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX]; | ||
73 | char *manufacturer; | ||
74 | char *product; | ||
75 | char *serialnumber; | ||
76 | |||
77 | struct config_group group; | ||
78 | struct list_head list; | ||
79 | }; | ||
80 | |||
81 | struct gadget_config_name { | ||
82 | struct usb_gadget_strings stringtab_dev; | ||
83 | struct usb_string strings; | ||
84 | char *configuration; | ||
85 | |||
86 | struct config_group group; | ||
87 | struct list_head list; | ||
88 | }; | ||
89 | |||
90 | static int usb_string_copy(const char *s, char **s_copy) | ||
91 | { | ||
92 | int ret; | ||
93 | char *str; | ||
94 | char *copy = *s_copy; | ||
95 | ret = strlen(s); | ||
96 | if (ret > 126) | ||
97 | return -EOVERFLOW; | ||
98 | |||
99 | str = kstrdup(s, GFP_KERNEL); | ||
100 | if (!str) | ||
101 | return -ENOMEM; | ||
102 | if (str[ret - 1] == '\n') | ||
103 | str[ret - 1] = '\0'; | ||
104 | kfree(copy); | ||
105 | *s_copy = str; | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | CONFIGFS_ATTR_STRUCT(gadget_info); | ||
110 | CONFIGFS_ATTR_STRUCT(config_usb_cfg); | ||
111 | |||
112 | #define GI_DEVICE_DESC_ITEM_ATTR(name) \ | ||
113 | static struct gadget_info_attribute gadget_cdev_desc_##name = \ | ||
114 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ | ||
115 | gadget_dev_desc_##name##_show, \ | ||
116 | gadget_dev_desc_##name##_store) | ||
117 | |||
118 | #define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \ | ||
119 | static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ | ||
120 | char *page) \ | ||
121 | { \ | ||
122 | return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \ | ||
123 | } | ||
124 | |||
125 | #define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \ | ||
126 | static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ | ||
127 | char *page) \ | ||
128 | { \ | ||
129 | return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \ | ||
130 | } | ||
131 | |||
132 | |||
133 | #define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \ | ||
134 | static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ | ||
135 | const char *page, size_t len) \ | ||
136 | { \ | ||
137 | u8 val; \ | ||
138 | int ret; \ | ||
139 | ret = kstrtou8(page, 0, &val); \ | ||
140 | if (ret) \ | ||
141 | return ret; \ | ||
142 | gi->cdev.desc._name = val; \ | ||
143 | return len; \ | ||
144 | } | ||
145 | |||
146 | #define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \ | ||
147 | static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ | ||
148 | const char *page, size_t len) \ | ||
149 | { \ | ||
150 | u16 val; \ | ||
151 | int ret; \ | ||
152 | ret = kstrtou16(page, 0, &val); \ | ||
153 | if (ret) \ | ||
154 | return ret; \ | ||
155 | gi->cdev.desc._name = cpu_to_le16p(&val); \ | ||
156 | return len; \ | ||
157 | } | ||
158 | |||
159 | #define GI_DEVICE_DESC_SIMPLE_RW(_name, _type) \ | ||
160 | GI_DEVICE_DESC_SIMPLE_R_##_type(_name) \ | ||
161 | GI_DEVICE_DESC_SIMPLE_W_##_type(_name) | ||
162 | |||
163 | GI_DEVICE_DESC_SIMPLE_R_u16(bcdUSB); | ||
164 | GI_DEVICE_DESC_SIMPLE_RW(bDeviceClass, u8); | ||
165 | GI_DEVICE_DESC_SIMPLE_RW(bDeviceSubClass, u8); | ||
166 | GI_DEVICE_DESC_SIMPLE_RW(bDeviceProtocol, u8); | ||
167 | GI_DEVICE_DESC_SIMPLE_RW(bMaxPacketSize0, u8); | ||
168 | GI_DEVICE_DESC_SIMPLE_RW(idVendor, u16); | ||
169 | GI_DEVICE_DESC_SIMPLE_RW(idProduct, u16); | ||
170 | GI_DEVICE_DESC_SIMPLE_R_u16(bcdDevice); | ||
171 | |||
172 | static ssize_t is_valid_bcd(u16 bcd_val) | ||
173 | { | ||
174 | if ((bcd_val & 0xf) > 9) | ||
175 | return -EINVAL; | ||
176 | if (((bcd_val >> 4) & 0xf) > 9) | ||
177 | return -EINVAL; | ||
178 | if (((bcd_val >> 8) & 0xf) > 9) | ||
179 | return -EINVAL; | ||
180 | if (((bcd_val >> 12) & 0xf) > 9) | ||
181 | return -EINVAL; | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi, | ||
186 | const char *page, size_t len) | ||
187 | { | ||
188 | u16 bcdDevice; | ||
189 | int ret; | ||
190 | |||
191 | ret = kstrtou16(page, 0, &bcdDevice); | ||
192 | if (ret) | ||
193 | return ret; | ||
194 | ret = is_valid_bcd(bcdDevice); | ||
195 | if (ret) | ||
196 | return ret; | ||
197 | |||
198 | gi->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); | ||
199 | return len; | ||
200 | } | ||
201 | |||
202 | static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi, | ||
203 | const char *page, size_t len) | ||
204 | { | ||
205 | u16 bcdUSB; | ||
206 | int ret; | ||
207 | |||
208 | ret = kstrtou16(page, 0, &bcdUSB); | ||
209 | if (ret) | ||
210 | return ret; | ||
211 | ret = is_valid_bcd(bcdUSB); | ||
212 | if (ret) | ||
213 | return ret; | ||
214 | |||
215 | gi->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); | ||
216 | return len; | ||
217 | } | ||
218 | |||
219 | static ssize_t gadget_dev_desc_UDC_show(struct gadget_info *gi, char *page) | ||
220 | { | ||
221 | return sprintf(page, "%s\n", gi->udc_name ?: ""); | ||
222 | } | ||
223 | |||
224 | static int unregister_gadget(struct gadget_info *gi) | ||
225 | { | ||
226 | int ret; | ||
227 | |||
228 | if (!gi->udc_name) | ||
229 | return -ENODEV; | ||
230 | |||
231 | ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver); | ||
232 | if (ret) | ||
233 | return ret; | ||
234 | kfree(gi->udc_name); | ||
235 | gi->udc_name = NULL; | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static ssize_t gadget_dev_desc_UDC_store(struct gadget_info *gi, | ||
240 | const char *page, size_t len) | ||
241 | { | ||
242 | char *name; | ||
243 | int ret; | ||
244 | |||
245 | name = kstrdup(page, GFP_KERNEL); | ||
246 | if (!name) | ||
247 | return -ENOMEM; | ||
248 | if (name[len - 1] == '\n') | ||
249 | name[len - 1] = '\0'; | ||
250 | |||
251 | mutex_lock(&gi->lock); | ||
252 | |||
253 | if (!strlen(name)) { | ||
254 | ret = unregister_gadget(gi); | ||
255 | if (ret) | ||
256 | goto err; | ||
257 | } else { | ||
258 | if (gi->udc_name) { | ||
259 | ret = -EBUSY; | ||
260 | goto err; | ||
261 | } | ||
262 | ret = udc_attach_driver(name, &gi->composite.gadget_driver); | ||
263 | if (ret) | ||
264 | goto err; | ||
265 | gi->udc_name = name; | ||
266 | } | ||
267 | mutex_unlock(&gi->lock); | ||
268 | return len; | ||
269 | err: | ||
270 | kfree(name); | ||
271 | mutex_unlock(&gi->lock); | ||
272 | return ret; | ||
273 | } | ||
274 | |||
275 | GI_DEVICE_DESC_ITEM_ATTR(bDeviceClass); | ||
276 | GI_DEVICE_DESC_ITEM_ATTR(bDeviceSubClass); | ||
277 | GI_DEVICE_DESC_ITEM_ATTR(bDeviceProtocol); | ||
278 | GI_DEVICE_DESC_ITEM_ATTR(bMaxPacketSize0); | ||
279 | GI_DEVICE_DESC_ITEM_ATTR(idVendor); | ||
280 | GI_DEVICE_DESC_ITEM_ATTR(idProduct); | ||
281 | GI_DEVICE_DESC_ITEM_ATTR(bcdDevice); | ||
282 | GI_DEVICE_DESC_ITEM_ATTR(bcdUSB); | ||
283 | GI_DEVICE_DESC_ITEM_ATTR(UDC); | ||
284 | |||
285 | static struct configfs_attribute *gadget_root_attrs[] = { | ||
286 | &gadget_cdev_desc_bDeviceClass.attr, | ||
287 | &gadget_cdev_desc_bDeviceSubClass.attr, | ||
288 | &gadget_cdev_desc_bDeviceProtocol.attr, | ||
289 | &gadget_cdev_desc_bMaxPacketSize0.attr, | ||
290 | &gadget_cdev_desc_idVendor.attr, | ||
291 | &gadget_cdev_desc_idProduct.attr, | ||
292 | &gadget_cdev_desc_bcdDevice.attr, | ||
293 | &gadget_cdev_desc_bcdUSB.attr, | ||
294 | &gadget_cdev_desc_UDC.attr, | ||
295 | NULL, | ||
296 | }; | ||
297 | |||
298 | static inline struct gadget_info *to_gadget_info(struct config_item *item) | ||
299 | { | ||
300 | return container_of(to_config_group(item), struct gadget_info, group); | ||
301 | } | ||
302 | |||
303 | static inline struct gadget_strings *to_gadget_strings(struct config_item *item) | ||
304 | { | ||
305 | return container_of(to_config_group(item), struct gadget_strings, | ||
306 | group); | ||
307 | } | ||
308 | |||
309 | static inline struct gadget_config_name *to_gadget_config_name( | ||
310 | struct config_item *item) | ||
311 | { | ||
312 | return container_of(to_config_group(item), struct gadget_config_name, | ||
313 | group); | ||
314 | } | ||
315 | |||
316 | static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item) | ||
317 | { | ||
318 | return container_of(to_config_group(item), struct config_usb_cfg, | ||
319 | group); | ||
320 | } | ||
321 | |||
322 | static inline struct usb_function_instance *to_usb_function_instance( | ||
323 | struct config_item *item) | ||
324 | { | ||
325 | return container_of(to_config_group(item), | ||
326 | struct usb_function_instance, group); | ||
327 | } | ||
328 | |||
329 | static void gadget_info_attr_release(struct config_item *item) | ||
330 | { | ||
331 | struct gadget_info *gi = to_gadget_info(item); | ||
332 | |||
333 | WARN_ON(!list_empty(&gi->cdev.configs)); | ||
334 | WARN_ON(!list_empty(&gi->string_list)); | ||
335 | WARN_ON(!list_empty(&gi->available_func)); | ||
336 | kfree(gi->composite.gadget_driver.function); | ||
337 | kfree(gi); | ||
338 | } | ||
339 | |||
340 | CONFIGFS_ATTR_OPS(gadget_info); | ||
341 | |||
342 | static struct configfs_item_operations gadget_root_item_ops = { | ||
343 | .release = gadget_info_attr_release, | ||
344 | .show_attribute = gadget_info_attr_show, | ||
345 | .store_attribute = gadget_info_attr_store, | ||
346 | }; | ||
347 | |||
348 | static void gadget_config_attr_release(struct config_item *item) | ||
349 | { | ||
350 | struct config_usb_cfg *cfg = to_config_usb_cfg(item); | ||
351 | |||
352 | WARN_ON(!list_empty(&cfg->c.functions)); | ||
353 | list_del(&cfg->c.list); | ||
354 | kfree(cfg->c.label); | ||
355 | kfree(cfg); | ||
356 | } | ||
357 | |||
358 | static int config_usb_cfg_link( | ||
359 | struct config_item *usb_cfg_ci, | ||
360 | struct config_item *usb_func_ci) | ||
361 | { | ||
362 | struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci); | ||
363 | struct usb_composite_dev *cdev = cfg->c.cdev; | ||
364 | struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev); | ||
365 | |||
366 | struct config_group *group = to_config_group(usb_func_ci); | ||
367 | struct usb_function_instance *fi = container_of(group, | ||
368 | struct usb_function_instance, group); | ||
369 | struct usb_function_instance *a_fi; | ||
370 | struct usb_function *f; | ||
371 | int ret; | ||
372 | |||
373 | mutex_lock(&gi->lock); | ||
374 | /* | ||
375 | * Make sure this function is from within our _this_ gadget and not | ||
376 | * from another gadget or a random directory. | ||
377 | * Also a function instance can only be linked once. | ||
378 | */ | ||
379 | list_for_each_entry(a_fi, &gi->available_func, cfs_list) { | ||
380 | if (a_fi == fi) | ||
381 | break; | ||
382 | } | ||
383 | if (a_fi != fi) { | ||
384 | ret = -EINVAL; | ||
385 | goto out; | ||
386 | } | ||
387 | |||
388 | list_for_each_entry(f, &cfg->func_list, list) { | ||
389 | if (f->fi == fi) { | ||
390 | ret = -EEXIST; | ||
391 | goto out; | ||
392 | } | ||
393 | } | ||
394 | |||
395 | f = usb_get_function(fi); | ||
396 | if (IS_ERR(f)) { | ||
397 | ret = PTR_ERR(f); | ||
398 | goto out; | ||
399 | } | ||
400 | |||
401 | /* stash the function until we bind it to the gadget */ | ||
402 | list_add_tail(&f->list, &cfg->func_list); | ||
403 | ret = 0; | ||
404 | out: | ||
405 | mutex_unlock(&gi->lock); | ||
406 | return ret; | ||
407 | } | ||
408 | |||
409 | static int config_usb_cfg_unlink( | ||
410 | struct config_item *usb_cfg_ci, | ||
411 | struct config_item *usb_func_ci) | ||
412 | { | ||
413 | struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci); | ||
414 | struct usb_composite_dev *cdev = cfg->c.cdev; | ||
415 | struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev); | ||
416 | |||
417 | struct config_group *group = to_config_group(usb_func_ci); | ||
418 | struct usb_function_instance *fi = container_of(group, | ||
419 | struct usb_function_instance, group); | ||
420 | struct usb_function *f; | ||
421 | |||
422 | /* | ||
423 | * ideally I would like to forbid to unlink functions while a gadget is | ||
424 | * bound to an UDC. Since this isn't possible at the moment, we simply | ||
425 | * force an unbind, the function is available here and then we can | ||
426 | * remove the function. | ||
427 | */ | ||
428 | mutex_lock(&gi->lock); | ||
429 | if (gi->udc_name) | ||
430 | unregister_gadget(gi); | ||
431 | WARN_ON(gi->udc_name); | ||
432 | |||
433 | list_for_each_entry(f, &cfg->func_list, list) { | ||
434 | if (f->fi == fi) { | ||
435 | list_del(&f->list); | ||
436 | usb_put_function(f); | ||
437 | mutex_unlock(&gi->lock); | ||
438 | return 0; | ||
439 | } | ||
440 | } | ||
441 | mutex_unlock(&gi->lock); | ||
442 | __WARN_printf("Unable to locate function to unbind\n"); | ||
443 | return 0; | ||
444 | } | ||
445 | |||
446 | CONFIGFS_ATTR_OPS(config_usb_cfg); | ||
447 | |||
448 | static struct configfs_item_operations gadget_config_item_ops = { | ||
449 | .release = gadget_config_attr_release, | ||
450 | .show_attribute = config_usb_cfg_attr_show, | ||
451 | .store_attribute = config_usb_cfg_attr_store, | ||
452 | .allow_link = config_usb_cfg_link, | ||
453 | .drop_link = config_usb_cfg_unlink, | ||
454 | }; | ||
455 | |||
456 | |||
457 | static ssize_t gadget_config_desc_MaxPower_show(struct config_usb_cfg *cfg, | ||
458 | char *page) | ||
459 | { | ||
460 | return sprintf(page, "%u\n", cfg->c.MaxPower); | ||
461 | } | ||
462 | |||
463 | static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg, | ||
464 | const char *page, size_t len) | ||
465 | { | ||
466 | u16 val; | ||
467 | int ret; | ||
468 | ret = kstrtou16(page, 0, &val); | ||
469 | if (ret) | ||
470 | return ret; | ||
471 | if (DIV_ROUND_UP(val, 8) > 0xff) | ||
472 | return -ERANGE; | ||
473 | cfg->c.MaxPower = val; | ||
474 | return len; | ||
475 | } | ||
476 | |||
477 | static ssize_t gadget_config_desc_bmAttributes_show(struct config_usb_cfg *cfg, | ||
478 | char *page) | ||
479 | { | ||
480 | return sprintf(page, "0x%02x\n", cfg->c.bmAttributes); | ||
481 | } | ||
482 | |||
483 | static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg, | ||
484 | const char *page, size_t len) | ||
485 | { | ||
486 | u8 val; | ||
487 | int ret; | ||
488 | ret = kstrtou8(page, 0, &val); | ||
489 | if (ret) | ||
490 | return ret; | ||
491 | if (!(val & USB_CONFIG_ATT_ONE)) | ||
492 | return -EINVAL; | ||
493 | if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER | | ||
494 | USB_CONFIG_ATT_WAKEUP)) | ||
495 | return -EINVAL; | ||
496 | cfg->c.bmAttributes = val; | ||
497 | return len; | ||
498 | } | ||
499 | |||
500 | #define CFG_CONFIG_DESC_ITEM_ATTR(name) \ | ||
501 | static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \ | ||
502 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ | ||
503 | gadget_config_desc_##name##_show, \ | ||
504 | gadget_config_desc_##name##_store) | ||
505 | |||
506 | CFG_CONFIG_DESC_ITEM_ATTR(MaxPower); | ||
507 | CFG_CONFIG_DESC_ITEM_ATTR(bmAttributes); | ||
508 | |||
509 | static struct configfs_attribute *gadget_config_attrs[] = { | ||
510 | &gadget_usb_cfg_MaxPower.attr, | ||
511 | &gadget_usb_cfg_bmAttributes.attr, | ||
512 | NULL, | ||
513 | }; | ||
514 | |||
515 | static struct config_item_type gadget_config_type = { | ||
516 | .ct_item_ops = &gadget_config_item_ops, | ||
517 | .ct_attrs = gadget_config_attrs, | ||
518 | .ct_owner = THIS_MODULE, | ||
519 | }; | ||
520 | |||
521 | static struct config_item_type gadget_root_type = { | ||
522 | .ct_item_ops = &gadget_root_item_ops, | ||
523 | .ct_attrs = gadget_root_attrs, | ||
524 | .ct_owner = THIS_MODULE, | ||
525 | }; | ||
526 | |||
527 | static void composite_init_dev(struct usb_composite_dev *cdev) | ||
528 | { | ||
529 | spin_lock_init(&cdev->lock); | ||
530 | INIT_LIST_HEAD(&cdev->configs); | ||
531 | INIT_LIST_HEAD(&cdev->gstrings); | ||
532 | } | ||
533 | |||
534 | static struct config_group *function_make( | ||
535 | struct config_group *group, | ||
536 | const char *name) | ||
537 | { | ||
538 | struct gadget_info *gi; | ||
539 | struct usb_function_instance *fi; | ||
540 | char buf[MAX_NAME_LEN]; | ||
541 | char *func_name; | ||
542 | char *instance_name; | ||
543 | int ret; | ||
544 | |||
545 | ret = snprintf(buf, MAX_NAME_LEN, "%s", name); | ||
546 | if (ret >= MAX_NAME_LEN) | ||
547 | return ERR_PTR(-ENAMETOOLONG); | ||
548 | |||
549 | func_name = buf; | ||
550 | instance_name = strchr(func_name, '.'); | ||
551 | if (!instance_name) { | ||
552 | pr_err("Unable to locate . in FUNC.INSTANCE\n"); | ||
553 | return ERR_PTR(-EINVAL); | ||
554 | } | ||
555 | *instance_name = '\0'; | ||
556 | instance_name++; | ||
557 | |||
558 | fi = usb_get_function_instance(func_name); | ||
559 | if (IS_ERR(fi)) | ||
560 | return ERR_PTR(PTR_ERR(fi)); | ||
561 | |||
562 | ret = config_item_set_name(&fi->group.cg_item, name); | ||
563 | if (ret) { | ||
564 | usb_put_function_instance(fi); | ||
565 | return ERR_PTR(ret); | ||
566 | } | ||
567 | |||
568 | gi = container_of(group, struct gadget_info, functions_group); | ||
569 | |||
570 | mutex_lock(&gi->lock); | ||
571 | list_add_tail(&fi->cfs_list, &gi->available_func); | ||
572 | mutex_unlock(&gi->lock); | ||
573 | return &fi->group; | ||
574 | } | ||
575 | |||
576 | static void function_drop( | ||
577 | struct config_group *group, | ||
578 | struct config_item *item) | ||
579 | { | ||
580 | struct usb_function_instance *fi = to_usb_function_instance(item); | ||
581 | struct gadget_info *gi; | ||
582 | |||
583 | gi = container_of(group, struct gadget_info, functions_group); | ||
584 | |||
585 | mutex_lock(&gi->lock); | ||
586 | list_del(&fi->cfs_list); | ||
587 | mutex_unlock(&gi->lock); | ||
588 | config_item_put(item); | ||
589 | } | ||
590 | |||
591 | static struct configfs_group_operations functions_ops = { | ||
592 | .make_group = &function_make, | ||
593 | .drop_item = &function_drop, | ||
594 | }; | ||
595 | |||
596 | static struct config_item_type functions_type = { | ||
597 | .ct_group_ops = &functions_ops, | ||
598 | .ct_owner = THIS_MODULE, | ||
599 | }; | ||
600 | |||
601 | CONFIGFS_ATTR_STRUCT(gadget_config_name); | ||
602 | GS_STRINGS_RW(gadget_config_name, configuration); | ||
603 | |||
604 | static struct configfs_attribute *gadget_config_name_langid_attrs[] = { | ||
605 | &gadget_config_name_configuration.attr, | ||
606 | NULL, | ||
607 | }; | ||
608 | |||
609 | static void gadget_config_name_attr_release(struct config_item *item) | ||
610 | { | ||
611 | struct gadget_config_name *cn = to_gadget_config_name(item); | ||
612 | |||
613 | kfree(cn->configuration); | ||
614 | |||
615 | list_del(&cn->list); | ||
616 | kfree(cn); | ||
617 | } | ||
618 | |||
619 | USB_CONFIG_STRING_RW_OPS(gadget_config_name); | ||
620 | USB_CONFIG_STRINGS_LANG(gadget_config_name, config_usb_cfg); | ||
621 | |||
622 | static struct config_group *config_desc_make( | ||
623 | struct config_group *group, | ||
624 | const char *name) | ||
625 | { | ||
626 | struct gadget_info *gi; | ||
627 | struct config_usb_cfg *cfg; | ||
628 | char buf[MAX_NAME_LEN]; | ||
629 | char *num_str; | ||
630 | u8 num; | ||
631 | int ret; | ||
632 | |||
633 | gi = container_of(group, struct gadget_info, configs_group); | ||
634 | ret = snprintf(buf, MAX_NAME_LEN, "%s", name); | ||
635 | if (ret >= MAX_NAME_LEN) | ||
636 | return ERR_PTR(-ENAMETOOLONG); | ||
637 | |||
638 | num_str = strchr(buf, '.'); | ||
639 | if (!num_str) { | ||
640 | pr_err("Unable to locate . in name.bConfigurationValue\n"); | ||
641 | return ERR_PTR(-EINVAL); | ||
642 | } | ||
643 | |||
644 | *num_str = '\0'; | ||
645 | num_str++; | ||
646 | |||
647 | if (!strlen(buf)) | ||
648 | return ERR_PTR(-EINVAL); | ||
649 | |||
650 | ret = kstrtou8(num_str, 0, &num); | ||
651 | if (ret) | ||
652 | return ERR_PTR(ret); | ||
653 | |||
654 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); | ||
655 | if (!cfg) | ||
656 | return ERR_PTR(-ENOMEM); | ||
657 | cfg->c.label = kstrdup(buf, GFP_KERNEL); | ||
658 | if (!cfg->c.label) { | ||
659 | ret = -ENOMEM; | ||
660 | goto err; | ||
661 | } | ||
662 | cfg->c.bConfigurationValue = num; | ||
663 | cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW; | ||
664 | cfg->c.bmAttributes = USB_CONFIG_ATT_ONE; | ||
665 | INIT_LIST_HEAD(&cfg->string_list); | ||
666 | INIT_LIST_HEAD(&cfg->func_list); | ||
667 | |||
668 | cfg->group.default_groups = cfg->default_groups; | ||
669 | cfg->default_groups[0] = &cfg->strings_group; | ||
670 | |||
671 | config_group_init_type_name(&cfg->group, name, | ||
672 | &gadget_config_type); | ||
673 | config_group_init_type_name(&cfg->strings_group, "strings", | ||
674 | &gadget_config_name_strings_type); | ||
675 | |||
676 | ret = usb_add_config_only(&gi->cdev, &cfg->c); | ||
677 | if (ret) | ||
678 | goto err; | ||
679 | |||
680 | return &cfg->group; | ||
681 | err: | ||
682 | kfree(cfg->c.label); | ||
683 | kfree(cfg); | ||
684 | return ERR_PTR(ret); | ||
685 | } | ||
686 | |||
687 | static void config_desc_drop( | ||
688 | struct config_group *group, | ||
689 | struct config_item *item) | ||
690 | { | ||
691 | config_item_put(item); | ||
692 | } | ||
693 | |||
694 | static struct configfs_group_operations config_desc_ops = { | ||
695 | .make_group = &config_desc_make, | ||
696 | .drop_item = &config_desc_drop, | ||
697 | }; | ||
698 | |||
699 | static struct config_item_type config_desc_type = { | ||
700 | .ct_group_ops = &config_desc_ops, | ||
701 | .ct_owner = THIS_MODULE, | ||
702 | }; | ||
703 | |||
704 | CONFIGFS_ATTR_STRUCT(gadget_strings); | ||
705 | GS_STRINGS_RW(gadget_strings, manufacturer); | ||
706 | GS_STRINGS_RW(gadget_strings, product); | ||
707 | GS_STRINGS_RW(gadget_strings, serialnumber); | ||
708 | |||
709 | static struct configfs_attribute *gadget_strings_langid_attrs[] = { | ||
710 | &gadget_strings_manufacturer.attr, | ||
711 | &gadget_strings_product.attr, | ||
712 | &gadget_strings_serialnumber.attr, | ||
713 | NULL, | ||
714 | }; | ||
715 | |||
716 | static void gadget_strings_attr_release(struct config_item *item) | ||
717 | { | ||
718 | struct gadget_strings *gs = to_gadget_strings(item); | ||
719 | |||
720 | kfree(gs->manufacturer); | ||
721 | kfree(gs->product); | ||
722 | kfree(gs->serialnumber); | ||
723 | |||
724 | list_del(&gs->list); | ||
725 | kfree(gs); | ||
726 | } | ||
727 | |||
728 | USB_CONFIG_STRING_RW_OPS(gadget_strings); | ||
729 | USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info); | ||
730 | |||
731 | static int configfs_do_nothing(struct usb_composite_dev *cdev) | ||
732 | { | ||
733 | __WARN(); | ||
734 | return -EINVAL; | ||
735 | } | ||
736 | |||
737 | int composite_dev_prepare(struct usb_composite_driver *composite, | ||
738 | struct usb_composite_dev *dev); | ||
739 | |||
740 | static void purge_configs_funcs(struct gadget_info *gi) | ||
741 | { | ||
742 | struct usb_configuration *c; | ||
743 | |||
744 | list_for_each_entry(c, &gi->cdev.configs, list) { | ||
745 | struct usb_function *f, *tmp; | ||
746 | struct config_usb_cfg *cfg; | ||
747 | |||
748 | cfg = container_of(c, struct config_usb_cfg, c); | ||
749 | |||
750 | list_for_each_entry_safe(f, tmp, &c->functions, list) { | ||
751 | |||
752 | list_move_tail(&f->list, &cfg->func_list); | ||
753 | if (f->unbind) { | ||
754 | dev_err(&gi->cdev.gadget->dev, "unbind function" | ||
755 | " '%s'/%p\n", f->name, f); | ||
756 | f->unbind(c, f); | ||
757 | } | ||
758 | } | ||
759 | c->next_interface_id = 0; | ||
760 | c->superspeed = 0; | ||
761 | c->highspeed = 0; | ||
762 | c->fullspeed = 0; | ||
763 | } | ||
764 | } | ||
765 | |||
766 | static int configfs_composite_bind(struct usb_gadget *gadget, | ||
767 | struct usb_gadget_driver *gdriver) | ||
768 | { | ||
769 | struct usb_composite_driver *composite = to_cdriver(gdriver); | ||
770 | struct gadget_info *gi = container_of(composite, | ||
771 | struct gadget_info, composite); | ||
772 | struct usb_composite_dev *cdev = &gi->cdev; | ||
773 | struct usb_configuration *c; | ||
774 | struct usb_string *s; | ||
775 | unsigned i; | ||
776 | int ret; | ||
777 | |||
778 | /* the gi->lock is hold by the caller */ | ||
779 | cdev->gadget = gadget; | ||
780 | set_gadget_data(gadget, cdev); | ||
781 | ret = composite_dev_prepare(composite, cdev); | ||
782 | if (ret) | ||
783 | return ret; | ||
784 | /* and now the gadget bind */ | ||
785 | ret = -EINVAL; | ||
786 | |||
787 | if (list_empty(&gi->cdev.configs)) { | ||
788 | pr_err("Need atleast one configuration in %s.\n", | ||
789 | gi->composite.name); | ||
790 | goto err_comp_cleanup; | ||
791 | } | ||
792 | |||
793 | |||
794 | list_for_each_entry(c, &gi->cdev.configs, list) { | ||
795 | struct config_usb_cfg *cfg; | ||
796 | |||
797 | cfg = container_of(c, struct config_usb_cfg, c); | ||
798 | if (list_empty(&cfg->func_list)) { | ||
799 | pr_err("Config %s/%d of %s needs atleast one function.\n", | ||
800 | c->label, c->bConfigurationValue, | ||
801 | gi->composite.name); | ||
802 | goto err_comp_cleanup; | ||
803 | } | ||
804 | } | ||
805 | |||
806 | /* init all strings */ | ||
807 | if (!list_empty(&gi->string_list)) { | ||
808 | struct gadget_strings *gs; | ||
809 | |||
810 | i = 0; | ||
811 | list_for_each_entry(gs, &gi->string_list, list) { | ||
812 | |||
813 | gi->gstrings[i] = &gs->stringtab_dev; | ||
814 | gs->stringtab_dev.strings = gs->strings; | ||
815 | gs->strings[USB_GADGET_MANUFACTURER_IDX].s = | ||
816 | gs->manufacturer; | ||
817 | gs->strings[USB_GADGET_PRODUCT_IDX].s = gs->product; | ||
818 | gs->strings[USB_GADGET_SERIAL_IDX].s = gs->serialnumber; | ||
819 | i++; | ||
820 | } | ||
821 | gi->gstrings[i] = NULL; | ||
822 | s = usb_gstrings_attach(&gi->cdev, gi->gstrings, | ||
823 | USB_GADGET_FIRST_AVAIL_IDX); | ||
824 | if (IS_ERR(s)) | ||
825 | goto err_comp_cleanup; | ||
826 | |||
827 | gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id; | ||
828 | gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id; | ||
829 | gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id; | ||
830 | } | ||
831 | |||
832 | /* Go through all configs, attach all functions */ | ||
833 | list_for_each_entry(c, &gi->cdev.configs, list) { | ||
834 | struct config_usb_cfg *cfg; | ||
835 | struct usb_function *f; | ||
836 | struct usb_function *tmp; | ||
837 | struct gadget_config_name *cn; | ||
838 | |||
839 | cfg = container_of(c, struct config_usb_cfg, c); | ||
840 | if (!list_empty(&cfg->string_list)) { | ||
841 | i = 0; | ||
842 | list_for_each_entry(cn, &cfg->string_list, list) { | ||
843 | cfg->gstrings[i] = &cn->stringtab_dev; | ||
844 | cn->stringtab_dev.strings = &cn->strings; | ||
845 | cn->strings.s = cn->configuration; | ||
846 | i++; | ||
847 | } | ||
848 | cfg->gstrings[i] = NULL; | ||
849 | s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1); | ||
850 | if (IS_ERR(s)) | ||
851 | goto err_comp_cleanup; | ||
852 | c->iConfiguration = s[0].id; | ||
853 | } | ||
854 | |||
855 | list_for_each_entry_safe(f, tmp, &cfg->func_list, list) { | ||
856 | list_del(&f->list); | ||
857 | ret = usb_add_function(c, f); | ||
858 | if (ret) | ||
859 | goto err_purge_funcs; | ||
860 | } | ||
861 | usb_ep_autoconfig_reset(cdev->gadget); | ||
862 | } | ||
863 | usb_ep_autoconfig_reset(cdev->gadget); | ||
864 | return 0; | ||
865 | |||
866 | err_purge_funcs: | ||
867 | purge_configs_funcs(gi); | ||
868 | err_comp_cleanup: | ||
869 | composite_dev_cleanup(cdev); | ||
870 | return ret; | ||
871 | } | ||
872 | |||
873 | static void configfs_composite_unbind(struct usb_gadget *gadget) | ||
874 | { | ||
875 | struct usb_composite_dev *cdev; | ||
876 | struct gadget_info *gi; | ||
877 | |||
878 | /* the gi->lock is hold by the caller */ | ||
879 | |||
880 | cdev = get_gadget_data(gadget); | ||
881 | gi = container_of(cdev, struct gadget_info, cdev); | ||
882 | |||
883 | purge_configs_funcs(gi); | ||
884 | composite_dev_cleanup(cdev); | ||
885 | usb_ep_autoconfig_reset(cdev->gadget); | ||
886 | cdev->gadget = NULL; | ||
887 | set_gadget_data(gadget, NULL); | ||
888 | } | ||
889 | |||
890 | static const struct usb_gadget_driver configfs_driver_template = { | ||
891 | .bind = configfs_composite_bind, | ||
892 | .unbind = configfs_composite_unbind, | ||
893 | |||
894 | .setup = composite_setup, | ||
895 | .disconnect = composite_disconnect, | ||
896 | |||
897 | .max_speed = USB_SPEED_SUPER, | ||
898 | .driver = { | ||
899 | .owner = THIS_MODULE, | ||
900 | .name = "configfs-gadget", | ||
901 | }, | ||
902 | }; | ||
903 | |||
904 | static struct config_group *gadgets_make( | ||
905 | struct config_group *group, | ||
906 | const char *name) | ||
907 | { | ||
908 | struct gadget_info *gi; | ||
909 | |||
910 | gi = kzalloc(sizeof(*gi), GFP_KERNEL); | ||
911 | if (!gi) | ||
912 | return ERR_PTR(-ENOMEM); | ||
913 | |||
914 | gi->group.default_groups = gi->default_groups; | ||
915 | gi->group.default_groups[0] = &gi->functions_group; | ||
916 | gi->group.default_groups[1] = &gi->configs_group; | ||
917 | gi->group.default_groups[2] = &gi->strings_group; | ||
918 | |||
919 | config_group_init_type_name(&gi->functions_group, "functions", | ||
920 | &functions_type); | ||
921 | config_group_init_type_name(&gi->configs_group, "configs", | ||
922 | &config_desc_type); | ||
923 | config_group_init_type_name(&gi->strings_group, "strings", | ||
924 | &gadget_strings_strings_type); | ||
925 | |||
926 | gi->composite.bind = configfs_do_nothing; | ||
927 | gi->composite.unbind = configfs_do_nothing; | ||
928 | gi->composite.suspend = NULL; | ||
929 | gi->composite.resume = NULL; | ||
930 | gi->composite.max_speed = USB_SPEED_SUPER; | ||
931 | |||
932 | mutex_init(&gi->lock); | ||
933 | INIT_LIST_HEAD(&gi->string_list); | ||
934 | INIT_LIST_HEAD(&gi->available_func); | ||
935 | |||
936 | composite_init_dev(&gi->cdev); | ||
937 | gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE; | ||
938 | gi->cdev.desc.bDescriptorType = USB_DT_DEVICE; | ||
939 | gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice()); | ||
940 | |||
941 | gi->composite.gadget_driver = configfs_driver_template; | ||
942 | |||
943 | gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); | ||
944 | gi->composite.name = gi->composite.gadget_driver.function; | ||
945 | |||
946 | if (!gi->composite.gadget_driver.function) | ||
947 | goto err; | ||
948 | |||
949 | #ifdef CONFIG_USB_OTG | ||
950 | gi->otg.bLength = sizeof(struct usb_otg_descriptor); | ||
951 | gi->otg.bDescriptorType = USB_DT_OTG; | ||
952 | gi->otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP; | ||
953 | #endif | ||
954 | |||
955 | config_group_init_type_name(&gi->group, name, | ||
956 | &gadget_root_type); | ||
957 | return &gi->group; | ||
958 | err: | ||
959 | kfree(gi); | ||
960 | return ERR_PTR(-ENOMEM); | ||
961 | } | ||
962 | |||
963 | static void gadgets_drop(struct config_group *group, struct config_item *item) | ||
964 | { | ||
965 | config_item_put(item); | ||
966 | } | ||
967 | |||
968 | static struct configfs_group_operations gadgets_ops = { | ||
969 | .make_group = &gadgets_make, | ||
970 | .drop_item = &gadgets_drop, | ||
971 | }; | ||
972 | |||
973 | static struct config_item_type gadgets_type = { | ||
974 | .ct_group_ops = &gadgets_ops, | ||
975 | .ct_owner = THIS_MODULE, | ||
976 | }; | ||
977 | |||
978 | static struct configfs_subsystem gadget_subsys = { | ||
979 | .su_group = { | ||
980 | .cg_item = { | ||
981 | .ci_namebuf = "usb_gadget", | ||
982 | .ci_type = &gadgets_type, | ||
983 | }, | ||
984 | }, | ||
985 | .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex), | ||
986 | }; | ||
987 | |||
988 | static int __init gadget_cfs_init(void) | ||
989 | { | ||
990 | int ret; | ||
991 | |||
992 | config_group_init(&gadget_subsys.su_group); | ||
993 | |||
994 | ret = configfs_register_subsystem(&gadget_subsys); | ||
995 | return ret; | ||
996 | } | ||
997 | module_init(gadget_cfs_init); | ||
998 | |||
999 | static void __exit gadget_cfs_exit(void) | ||
1000 | { | ||
1001 | configfs_unregister_subsystem(&gadget_subsys); | ||
1002 | } | ||
1003 | module_exit(gadget_cfs_exit); | ||
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 8cf0c0f6fa1f..a792e322f4f1 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -912,7 +912,6 @@ static int dummy_udc_start(struct usb_gadget *g, | |||
912 | dum->devstatus = 0; | 912 | dum->devstatus = 0; |
913 | 913 | ||
914 | dum->driver = driver; | 914 | dum->driver = driver; |
915 | dum->gadget.dev.driver = &driver->driver; | ||
916 | dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n", | 915 | dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n", |
917 | driver->driver.name); | 916 | driver->driver.name); |
918 | return 0; | 917 | return 0; |
@@ -927,7 +926,6 @@ static int dummy_udc_stop(struct usb_gadget *g, | |||
927 | dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", | 926 | dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", |
928 | driver->driver.name); | 927 | driver->driver.name); |
929 | 928 | ||
930 | dum->gadget.dev.driver = NULL; | ||
931 | dum->driver = NULL; | 929 | dum->driver = NULL; |
932 | 930 | ||
933 | return 0; | 931 | return 0; |
@@ -937,11 +935,6 @@ static int dummy_udc_stop(struct usb_gadget *g, | |||
937 | 935 | ||
938 | /* The gadget structure is stored inside the hcd structure and will be | 936 | /* The gadget structure is stored inside the hcd structure and will be |
939 | * released along with it. */ | 937 | * released along with it. */ |
940 | static void dummy_gadget_release(struct device *dev) | ||
941 | { | ||
942 | return; | ||
943 | } | ||
944 | |||
945 | static void init_dummy_udc_hw(struct dummy *dum) | 938 | static void init_dummy_udc_hw(struct dummy *dum) |
946 | { | 939 | { |
947 | int i; | 940 | int i; |
@@ -984,15 +977,7 @@ static int dummy_udc_probe(struct platform_device *pdev) | |||
984 | dum->gadget.ops = &dummy_ops; | 977 | dum->gadget.ops = &dummy_ops; |
985 | dum->gadget.max_speed = USB_SPEED_SUPER; | 978 | dum->gadget.max_speed = USB_SPEED_SUPER; |
986 | 979 | ||
987 | dev_set_name(&dum->gadget.dev, "gadget"); | ||
988 | dum->gadget.dev.parent = &pdev->dev; | 980 | dum->gadget.dev.parent = &pdev->dev; |
989 | dum->gadget.dev.release = dummy_gadget_release; | ||
990 | rc = device_register(&dum->gadget.dev); | ||
991 | if (rc < 0) { | ||
992 | put_device(&dum->gadget.dev); | ||
993 | return rc; | ||
994 | } | ||
995 | |||
996 | init_dummy_udc_hw(dum); | 981 | init_dummy_udc_hw(dum); |
997 | 982 | ||
998 | rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget); | 983 | rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget); |
@@ -1008,7 +993,6 @@ static int dummy_udc_probe(struct platform_device *pdev) | |||
1008 | err_dev: | 993 | err_dev: |
1009 | usb_del_gadget_udc(&dum->gadget); | 994 | usb_del_gadget_udc(&dum->gadget); |
1010 | err_udc: | 995 | err_udc: |
1011 | device_unregister(&dum->gadget.dev); | ||
1012 | return rc; | 996 | return rc; |
1013 | } | 997 | } |
1014 | 998 | ||
@@ -1019,7 +1003,6 @@ static int dummy_udc_remove(struct platform_device *pdev) | |||
1019 | usb_del_gadget_udc(&dum->gadget); | 1003 | usb_del_gadget_udc(&dum->gadget); |
1020 | platform_set_drvdata(pdev, NULL); | 1004 | platform_set_drvdata(pdev, NULL); |
1021 | device_remove_file(&dum->gadget.dev, &dev_attr_function); | 1005 | device_remove_file(&dum->gadget.dev, &dev_attr_function); |
1022 | device_unregister(&dum->gadget.dev); | ||
1023 | return 0; | 1006 | return 0; |
1024 | } | 1007 | } |
1025 | 1008 | ||
@@ -1923,7 +1906,7 @@ done: | |||
1923 | } | 1906 | } |
1924 | 1907 | ||
1925 | /* usb 3.0 root hub device descriptor */ | 1908 | /* usb 3.0 root hub device descriptor */ |
1926 | struct { | 1909 | static struct { |
1927 | struct usb_bos_descriptor bos; | 1910 | struct usb_bos_descriptor bos; |
1928 | struct usb_ss_cap_descriptor ss_cap; | 1911 | struct usb_ss_cap_descriptor ss_cap; |
1929 | } __packed usb3_bos_desc = { | 1912 | } __packed usb3_bos_desc = { |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 18c3f423706e..56c8ecae9bc3 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -207,7 +207,7 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
207 | }; | 207 | }; |
208 | 208 | ||
209 | static u8 hostaddr[ETH_ALEN]; | 209 | static u8 hostaddr[ETH_ALEN]; |
210 | 210 | static struct eth_dev *the_dev; | |
211 | /*-------------------------------------------------------------------------*/ | 211 | /*-------------------------------------------------------------------------*/ |
212 | 212 | ||
213 | /* | 213 | /* |
@@ -224,7 +224,7 @@ static int __init rndis_do_config(struct usb_configuration *c) | |||
224 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 224 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
225 | } | 225 | } |
226 | 226 | ||
227 | return rndis_bind_config(c, hostaddr); | 227 | return rndis_bind_config(c, hostaddr, the_dev); |
228 | } | 228 | } |
229 | 229 | ||
230 | static struct usb_configuration rndis_config_driver = { | 230 | static struct usb_configuration rndis_config_driver = { |
@@ -257,11 +257,11 @@ static int __init eth_do_config(struct usb_configuration *c) | |||
257 | } | 257 | } |
258 | 258 | ||
259 | if (use_eem) | 259 | if (use_eem) |
260 | return eem_bind_config(c); | 260 | return eem_bind_config(c, the_dev); |
261 | else if (can_support_ecm(c->cdev->gadget)) | 261 | else if (can_support_ecm(c->cdev->gadget)) |
262 | return ecm_bind_config(c, hostaddr); | 262 | return ecm_bind_config(c, hostaddr, the_dev); |
263 | else | 263 | else |
264 | return geth_bind_config(c, hostaddr); | 264 | return geth_bind_config(c, hostaddr, the_dev); |
265 | } | 265 | } |
266 | 266 | ||
267 | static struct usb_configuration eth_config_driver = { | 267 | static struct usb_configuration eth_config_driver = { |
@@ -279,9 +279,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev) | |||
279 | int status; | 279 | int status; |
280 | 280 | ||
281 | /* set up network link layer */ | 281 | /* set up network link layer */ |
282 | status = gether_setup(cdev->gadget, hostaddr); | 282 | the_dev = gether_setup(cdev->gadget, hostaddr); |
283 | if (status < 0) | 283 | if (IS_ERR(the_dev)) |
284 | return status; | 284 | return PTR_ERR(the_dev); |
285 | 285 | ||
286 | /* set up main config label and device descriptor */ | 286 | /* set up main config label and device descriptor */ |
287 | if (use_eem) { | 287 | if (use_eem) { |
@@ -338,13 +338,13 @@ static int __init eth_bind(struct usb_composite_dev *cdev) | |||
338 | return 0; | 338 | return 0; |
339 | 339 | ||
340 | fail: | 340 | fail: |
341 | gether_cleanup(); | 341 | gether_cleanup(the_dev); |
342 | return status; | 342 | return status; |
343 | } | 343 | } |
344 | 344 | ||
345 | static int __exit eth_unbind(struct usb_composite_dev *cdev) | 345 | static int __exit eth_unbind(struct usb_composite_dev *cdev) |
346 | { | 346 | { |
347 | gether_cleanup(); | 347 | gether_cleanup(the_dev); |
348 | return 0; | 348 | return 0; |
349 | } | 349 | } |
350 | 350 | ||
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index 1ae180baa597..4b7e33e5d9c6 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c | |||
@@ -715,13 +715,31 @@ fail: | |||
715 | return status; | 715 | return status; |
716 | } | 716 | } |
717 | 717 | ||
718 | static struct f_acm *acm_alloc_basic_func(void) | 718 | static void acm_unbind(struct usb_configuration *c, struct usb_function *f) |
719 | { | ||
720 | struct f_acm *acm = func_to_acm(f); | ||
721 | |||
722 | acm_string_defs[0].id = 0; | ||
723 | usb_free_all_descriptors(f); | ||
724 | if (acm->notify_req) | ||
725 | gs_free_req(acm->notify, acm->notify_req); | ||
726 | } | ||
727 | |||
728 | static void acm_free_func(struct usb_function *f) | ||
729 | { | ||
730 | struct f_acm *acm = func_to_acm(f); | ||
731 | |||
732 | kfree(acm); | ||
733 | } | ||
734 | |||
735 | static struct usb_function *acm_alloc_func(struct usb_function_instance *fi) | ||
719 | { | 736 | { |
720 | struct f_acm *acm; | 737 | struct f_serial_opts *opts; |
738 | struct f_acm *acm; | ||
721 | 739 | ||
722 | acm = kzalloc(sizeof(*acm), GFP_KERNEL); | 740 | acm = kzalloc(sizeof(*acm), GFP_KERNEL); |
723 | if (!acm) | 741 | if (!acm) |
724 | return NULL; | 742 | return ERR_PTR(-ENOMEM); |
725 | 743 | ||
726 | spin_lock_init(&acm->lock); | 744 | spin_lock_init(&acm->lock); |
727 | 745 | ||
@@ -730,109 +748,100 @@ static struct f_acm *acm_alloc_basic_func(void) | |||
730 | acm->port.send_break = acm_send_break; | 748 | acm->port.send_break = acm_send_break; |
731 | 749 | ||
732 | acm->port.func.name = "acm"; | 750 | acm->port.func.name = "acm"; |
751 | acm->port.func.strings = acm_strings; | ||
733 | /* descriptors are per-instance copies */ | 752 | /* descriptors are per-instance copies */ |
734 | acm->port.func.bind = acm_bind; | 753 | acm->port.func.bind = acm_bind; |
735 | acm->port.func.set_alt = acm_set_alt; | 754 | acm->port.func.set_alt = acm_set_alt; |
736 | acm->port.func.setup = acm_setup; | 755 | acm->port.func.setup = acm_setup; |
737 | acm->port.func.disable = acm_disable; | 756 | acm->port.func.disable = acm_disable; |
738 | 757 | ||
739 | return acm; | 758 | opts = container_of(fi, struct f_serial_opts, func_inst); |
759 | acm->port_num = opts->port_num; | ||
760 | acm->port.func.unbind = acm_unbind; | ||
761 | acm->port.func.free_func = acm_free_func; | ||
762 | |||
763 | return &acm->port.func; | ||
740 | } | 764 | } |
741 | 765 | ||
742 | #ifdef USB_FACM_INCLUDED | 766 | static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) |
743 | static void | ||
744 | acm_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
745 | { | 767 | { |
746 | struct f_acm *acm = func_to_acm(f); | 768 | return container_of(to_config_group(item), struct f_serial_opts, |
747 | 769 | func_inst.group); | |
748 | usb_free_all_descriptors(f); | ||
749 | if (acm->notify_req) | ||
750 | gs_free_req(acm->notify, acm->notify_req); | ||
751 | kfree(acm); | ||
752 | } | 770 | } |
753 | 771 | ||
754 | /** | 772 | CONFIGFS_ATTR_STRUCT(f_serial_opts); |
755 | * acm_bind_config - add a CDC ACM function to a configuration | 773 | static ssize_t f_acm_attr_show(struct config_item *item, |
756 | * @c: the configuration to support the CDC ACM instance | 774 | struct configfs_attribute *attr, |
757 | * @port_num: /dev/ttyGS* port this interface will use | 775 | char *page) |
758 | * Context: single threaded during gadget setup | ||
759 | * | ||
760 | * Returns zero on success, else negative errno. | ||
761 | * | ||
762 | */ | ||
763 | int acm_bind_config(struct usb_configuration *c, u8 port_num) | ||
764 | { | 776 | { |
765 | struct f_acm *acm; | 777 | struct f_serial_opts *opts = to_f_serial_opts(item); |
766 | int status; | 778 | struct f_serial_opts_attribute *f_serial_opts_attr = |
767 | 779 | container_of(attr, struct f_serial_opts_attribute, attr); | |
768 | /* allocate and initialize one new instance */ | 780 | ssize_t ret = 0; |
769 | acm = acm_alloc_basic_func(); | 781 | |
770 | if (!acm) | 782 | if (f_serial_opts_attr->show) |
771 | return -ENOMEM; | 783 | ret = f_serial_opts_attr->show(opts, page); |
772 | 784 | return ret; | |
773 | acm->port_num = port_num; | ||
774 | acm->port.func.unbind = acm_old_unbind; | ||
775 | |||
776 | status = usb_add_function(c, &acm->port.func); | ||
777 | if (status) | ||
778 | kfree(acm); | ||
779 | return status; | ||
780 | } | 785 | } |
781 | 786 | ||
782 | #else | 787 | static void acm_attr_release(struct config_item *item) |
783 | |||
784 | static void acm_unbind(struct usb_configuration *c, struct usb_function *f) | ||
785 | { | 788 | { |
786 | struct f_acm *acm = func_to_acm(f); | 789 | struct f_serial_opts *opts = to_f_serial_opts(item); |
787 | 790 | ||
788 | acm_string_defs[0].id = 0; | 791 | usb_put_function_instance(&opts->func_inst); |
789 | usb_free_all_descriptors(f); | ||
790 | if (acm->notify_req) | ||
791 | gs_free_req(acm->notify, acm->notify_req); | ||
792 | } | 792 | } |
793 | 793 | ||
794 | static void acm_free_func(struct usb_function *f) | 794 | static struct configfs_item_operations acm_item_ops = { |
795 | { | 795 | .release = acm_attr_release, |
796 | struct f_acm *acm = func_to_acm(f); | 796 | .show_attribute = f_acm_attr_show, |
797 | }; | ||
797 | 798 | ||
798 | kfree(acm); | 799 | static ssize_t f_acm_port_num_show(struct f_serial_opts *opts, char *page) |
800 | { | ||
801 | return sprintf(page, "%u\n", opts->port_num); | ||
799 | } | 802 | } |
800 | 803 | ||
801 | static struct usb_function *acm_alloc_func(struct usb_function_instance *fi) | 804 | static struct f_serial_opts_attribute f_acm_port_num = |
802 | { | 805 | __CONFIGFS_ATTR_RO(port_num, f_acm_port_num_show); |
803 | struct f_serial_opts *opts; | ||
804 | struct f_acm *acm; | ||
805 | 806 | ||
806 | acm = acm_alloc_basic_func(); | ||
807 | if (!acm) | ||
808 | return ERR_PTR(-ENOMEM); | ||
809 | 807 | ||
810 | opts = container_of(fi, struct f_serial_opts, func_inst); | 808 | static struct configfs_attribute *acm_attrs[] = { |
811 | acm->port_num = opts->port_num; | 809 | &f_acm_port_num.attr, |
812 | acm->port.func.unbind = acm_unbind; | 810 | NULL, |
813 | acm->port.func.free_func = acm_free_func; | 811 | }; |
814 | 812 | ||
815 | return &acm->port.func; | 813 | static struct config_item_type acm_func_type = { |
816 | } | 814 | .ct_item_ops = &acm_item_ops, |
815 | .ct_attrs = acm_attrs, | ||
816 | .ct_owner = THIS_MODULE, | ||
817 | }; | ||
817 | 818 | ||
818 | static void acm_free_instance(struct usb_function_instance *fi) | 819 | static void acm_free_instance(struct usb_function_instance *fi) |
819 | { | 820 | { |
820 | struct f_serial_opts *opts; | 821 | struct f_serial_opts *opts; |
821 | 822 | ||
822 | opts = container_of(fi, struct f_serial_opts, func_inst); | 823 | opts = container_of(fi, struct f_serial_opts, func_inst); |
824 | gserial_free_line(opts->port_num); | ||
823 | kfree(opts); | 825 | kfree(opts); |
824 | } | 826 | } |
825 | 827 | ||
826 | static struct usb_function_instance *acm_alloc_instance(void) | 828 | static struct usb_function_instance *acm_alloc_instance(void) |
827 | { | 829 | { |
828 | struct f_serial_opts *opts; | 830 | struct f_serial_opts *opts; |
831 | int ret; | ||
829 | 832 | ||
830 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | 833 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); |
831 | if (!opts) | 834 | if (!opts) |
832 | return ERR_PTR(-ENOMEM); | 835 | return ERR_PTR(-ENOMEM); |
833 | opts->func_inst.free_func_inst = acm_free_instance; | 836 | opts->func_inst.free_func_inst = acm_free_instance; |
837 | ret = gserial_alloc_line(&opts->port_num); | ||
838 | if (ret) { | ||
839 | kfree(opts); | ||
840 | return ERR_PTR(ret); | ||
841 | } | ||
842 | config_group_init_type_name(&opts->func_inst.group, "", | ||
843 | &acm_func_type); | ||
834 | return &opts->func_inst; | 844 | return &opts->func_inst; |
835 | } | 845 | } |
836 | DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); | 846 | DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); |
837 | MODULE_LICENSE("GPL"); | 847 | MODULE_LICENSE("GPL"); |
838 | #endif | ||
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c index 83420a310fb7..d893d6929079 100644 --- a/drivers/usb/gadget/f_ecm.c +++ b/drivers/usb/gadget/f_ecm.c | |||
@@ -824,7 +824,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f) | |||
824 | * for calling @gether_cleanup() before module unload. | 824 | * for calling @gether_cleanup() before module unload. |
825 | */ | 825 | */ |
826 | int | 826 | int |
827 | ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | 827 | ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
828 | struct eth_dev *dev) | ||
828 | { | 829 | { |
829 | struct f_ecm *ecm; | 830 | struct f_ecm *ecm; |
830 | int status; | 831 | int status; |
@@ -852,6 +853,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | |||
852 | snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); | 853 | snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); |
853 | ecm_string_defs[1].s = ecm->ethaddr; | 854 | ecm_string_defs[1].s = ecm->ethaddr; |
854 | 855 | ||
856 | ecm->port.ioport = dev; | ||
855 | ecm->port.cdc_filter = DEFAULT_FILTER; | 857 | ecm->port.cdc_filter = DEFAULT_FILTER; |
856 | 858 | ||
857 | ecm->port.func.name = "cdc_ethernet"; | 859 | ecm->port.func.name = "cdc_ethernet"; |
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c index cf0ebee85563..f4e0bbef602a 100644 --- a/drivers/usb/gadget/f_eem.c +++ b/drivers/usb/gadget/f_eem.c | |||
@@ -528,7 +528,7 @@ error: | |||
528 | * Caller must have called @gether_setup(). Caller is also responsible | 528 | * Caller must have called @gether_setup(). Caller is also responsible |
529 | * for calling @gether_cleanup() before module unload. | 529 | * for calling @gether_cleanup() before module unload. |
530 | */ | 530 | */ |
531 | int __init eem_bind_config(struct usb_configuration *c) | 531 | int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev) |
532 | { | 532 | { |
533 | struct f_eem *eem; | 533 | struct f_eem *eem; |
534 | int status; | 534 | int status; |
@@ -549,6 +549,7 @@ int __init eem_bind_config(struct usb_configuration *c) | |||
549 | if (!eem) | 549 | if (!eem) |
550 | return -ENOMEM; | 550 | return -ENOMEM; |
551 | 551 | ||
552 | eem->port.ioport = dev; | ||
552 | eem->port.cdc_filter = DEFAULT_FILTER; | 553 | eem->port.cdc_filter = DEFAULT_FILTER; |
553 | 554 | ||
554 | eem->port.func.name = "cdc_eem"; | 555 | eem->port.func.name = "cdc_eem"; |
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c index 5e7557e23ecc..ee19bc8d0040 100644 --- a/drivers/usb/gadget/f_ncm.c +++ b/drivers/usb/gadget/f_ncm.c | |||
@@ -1287,7 +1287,8 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f) | |||
1287 | * Caller must have called @gether_setup(). Caller is also responsible | 1287 | * Caller must have called @gether_setup(). Caller is also responsible |
1288 | * for calling @gether_cleanup() before module unload. | 1288 | * for calling @gether_cleanup() before module unload. |
1289 | */ | 1289 | */ |
1290 | int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | 1290 | int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
1291 | struct eth_dev *dev) | ||
1291 | { | 1292 | { |
1292 | struct f_ncm *ncm; | 1293 | struct f_ncm *ncm; |
1293 | int status; | 1294 | int status; |
@@ -1321,6 +1322,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | |||
1321 | 1322 | ||
1322 | spin_lock_init(&ncm->lock); | 1323 | spin_lock_init(&ncm->lock); |
1323 | ncm_reset_values(ncm); | 1324 | ncm_reset_values(ncm); |
1325 | ncm->port.ioport = dev; | ||
1324 | ncm->port.is_fixed = true; | 1326 | ncm->port.is_fixed = true; |
1325 | 1327 | ||
1326 | ncm->port.func.name = "cdc_network"; | 1328 | ncm->port.func.name = "cdc_network"; |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index 36a004563b82..29a348a2a294 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -72,7 +72,7 @@ static struct usb_gadget_strings *obex_strings[] = { | |||
72 | 72 | ||
73 | /*-------------------------------------------------------------------------*/ | 73 | /*-------------------------------------------------------------------------*/ |
74 | 74 | ||
75 | static struct usb_interface_descriptor obex_control_intf __initdata = { | 75 | static struct usb_interface_descriptor obex_control_intf = { |
76 | .bLength = sizeof(obex_control_intf), | 76 | .bLength = sizeof(obex_control_intf), |
77 | .bDescriptorType = USB_DT_INTERFACE, | 77 | .bDescriptorType = USB_DT_INTERFACE, |
78 | .bInterfaceNumber = 0, | 78 | .bInterfaceNumber = 0, |
@@ -83,7 +83,7 @@ static struct usb_interface_descriptor obex_control_intf __initdata = { | |||
83 | .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX, | 83 | .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX, |
84 | }; | 84 | }; |
85 | 85 | ||
86 | static struct usb_interface_descriptor obex_data_nop_intf __initdata = { | 86 | static struct usb_interface_descriptor obex_data_nop_intf = { |
87 | .bLength = sizeof(obex_data_nop_intf), | 87 | .bLength = sizeof(obex_data_nop_intf), |
88 | .bDescriptorType = USB_DT_INTERFACE, | 88 | .bDescriptorType = USB_DT_INTERFACE, |
89 | .bInterfaceNumber = 1, | 89 | .bInterfaceNumber = 1, |
@@ -93,7 +93,7 @@ static struct usb_interface_descriptor obex_data_nop_intf __initdata = { | |||
93 | .bInterfaceClass = USB_CLASS_CDC_DATA, | 93 | .bInterfaceClass = USB_CLASS_CDC_DATA, |
94 | }; | 94 | }; |
95 | 95 | ||
96 | static struct usb_interface_descriptor obex_data_intf __initdata = { | 96 | static struct usb_interface_descriptor obex_data_intf = { |
97 | .bLength = sizeof(obex_data_intf), | 97 | .bLength = sizeof(obex_data_intf), |
98 | .bDescriptorType = USB_DT_INTERFACE, | 98 | .bDescriptorType = USB_DT_INTERFACE, |
99 | .bInterfaceNumber = 2, | 99 | .bInterfaceNumber = 2, |
@@ -103,14 +103,14 @@ static struct usb_interface_descriptor obex_data_intf __initdata = { | |||
103 | .bInterfaceClass = USB_CLASS_CDC_DATA, | 103 | .bInterfaceClass = USB_CLASS_CDC_DATA, |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = { | 106 | static struct usb_cdc_header_desc obex_cdc_header_desc = { |
107 | .bLength = sizeof(obex_cdc_header_desc), | 107 | .bLength = sizeof(obex_cdc_header_desc), |
108 | .bDescriptorType = USB_DT_CS_INTERFACE, | 108 | .bDescriptorType = USB_DT_CS_INTERFACE, |
109 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, | 109 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, |
110 | .bcdCDC = cpu_to_le16(0x0120), | 110 | .bcdCDC = cpu_to_le16(0x0120), |
111 | }; | 111 | }; |
112 | 112 | ||
113 | static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { | 113 | static struct usb_cdc_union_desc obex_cdc_union_desc = { |
114 | .bLength = sizeof(obex_cdc_union_desc), | 114 | .bLength = sizeof(obex_cdc_union_desc), |
115 | .bDescriptorType = USB_DT_CS_INTERFACE, | 115 | .bDescriptorType = USB_DT_CS_INTERFACE, |
116 | .bDescriptorSubType = USB_CDC_UNION_TYPE, | 116 | .bDescriptorSubType = USB_CDC_UNION_TYPE, |
@@ -118,7 +118,7 @@ static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { | |||
118 | .bSlaveInterface0 = 2, | 118 | .bSlaveInterface0 = 2, |
119 | }; | 119 | }; |
120 | 120 | ||
121 | static struct usb_cdc_obex_desc obex_desc __initdata = { | 121 | static struct usb_cdc_obex_desc obex_desc = { |
122 | .bLength = sizeof(obex_desc), | 122 | .bLength = sizeof(obex_desc), |
123 | .bDescriptorType = USB_DT_CS_INTERFACE, | 123 | .bDescriptorType = USB_DT_CS_INTERFACE, |
124 | .bDescriptorSubType = USB_CDC_OBEX_TYPE, | 124 | .bDescriptorSubType = USB_CDC_OBEX_TYPE, |
@@ -127,7 +127,7 @@ static struct usb_cdc_obex_desc obex_desc __initdata = { | |||
127 | 127 | ||
128 | /* High-Speed Support */ | 128 | /* High-Speed Support */ |
129 | 129 | ||
130 | static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = { | 130 | static struct usb_endpoint_descriptor obex_hs_ep_out_desc = { |
131 | .bLength = USB_DT_ENDPOINT_SIZE, | 131 | .bLength = USB_DT_ENDPOINT_SIZE, |
132 | .bDescriptorType = USB_DT_ENDPOINT, | 132 | .bDescriptorType = USB_DT_ENDPOINT, |
133 | 133 | ||
@@ -136,7 +136,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = { | |||
136 | .wMaxPacketSize = cpu_to_le16(512), | 136 | .wMaxPacketSize = cpu_to_le16(512), |
137 | }; | 137 | }; |
138 | 138 | ||
139 | static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { | 139 | static struct usb_endpoint_descriptor obex_hs_ep_in_desc = { |
140 | .bLength = USB_DT_ENDPOINT_SIZE, | 140 | .bLength = USB_DT_ENDPOINT_SIZE, |
141 | .bDescriptorType = USB_DT_ENDPOINT, | 141 | .bDescriptorType = USB_DT_ENDPOINT, |
142 | 142 | ||
@@ -145,7 +145,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { | |||
145 | .wMaxPacketSize = cpu_to_le16(512), | 145 | .wMaxPacketSize = cpu_to_le16(512), |
146 | }; | 146 | }; |
147 | 147 | ||
148 | static struct usb_descriptor_header *hs_function[] __initdata = { | 148 | static struct usb_descriptor_header *hs_function[] = { |
149 | (struct usb_descriptor_header *) &obex_control_intf, | 149 | (struct usb_descriptor_header *) &obex_control_intf, |
150 | (struct usb_descriptor_header *) &obex_cdc_header_desc, | 150 | (struct usb_descriptor_header *) &obex_cdc_header_desc, |
151 | (struct usb_descriptor_header *) &obex_desc, | 151 | (struct usb_descriptor_header *) &obex_desc, |
@@ -160,7 +160,7 @@ static struct usb_descriptor_header *hs_function[] __initdata = { | |||
160 | 160 | ||
161 | /* Full-Speed Support */ | 161 | /* Full-Speed Support */ |
162 | 162 | ||
163 | static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = { | 163 | static struct usb_endpoint_descriptor obex_fs_ep_in_desc = { |
164 | .bLength = USB_DT_ENDPOINT_SIZE, | 164 | .bLength = USB_DT_ENDPOINT_SIZE, |
165 | .bDescriptorType = USB_DT_ENDPOINT, | 165 | .bDescriptorType = USB_DT_ENDPOINT, |
166 | 166 | ||
@@ -168,7 +168,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = { | |||
168 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 168 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
169 | }; | 169 | }; |
170 | 170 | ||
171 | static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = { | 171 | static struct usb_endpoint_descriptor obex_fs_ep_out_desc = { |
172 | .bLength = USB_DT_ENDPOINT_SIZE, | 172 | .bLength = USB_DT_ENDPOINT_SIZE, |
173 | .bDescriptorType = USB_DT_ENDPOINT, | 173 | .bDescriptorType = USB_DT_ENDPOINT, |
174 | 174 | ||
@@ -176,7 +176,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = { | |||
176 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 176 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
177 | }; | 177 | }; |
178 | 178 | ||
179 | static struct usb_descriptor_header *fs_function[] __initdata = { | 179 | static struct usb_descriptor_header *fs_function[] = { |
180 | (struct usb_descriptor_header *) &obex_control_intf, | 180 | (struct usb_descriptor_header *) &obex_control_intf, |
181 | (struct usb_descriptor_header *) &obex_cdc_header_desc, | 181 | (struct usb_descriptor_header *) &obex_cdc_header_desc, |
182 | (struct usb_descriptor_header *) &obex_desc, | 182 | (struct usb_descriptor_header *) &obex_desc, |
@@ -290,14 +290,43 @@ static void obex_disconnect(struct gserial *g) | |||
290 | 290 | ||
291 | /*-------------------------------------------------------------------------*/ | 291 | /*-------------------------------------------------------------------------*/ |
292 | 292 | ||
293 | static int __init | 293 | /* Some controllers can't support CDC OBEX ... */ |
294 | obex_bind(struct usb_configuration *c, struct usb_function *f) | 294 | static inline bool can_support_obex(struct usb_configuration *c) |
295 | { | ||
296 | /* Since the first interface is a NOP, we can ignore the | ||
297 | * issue of multi-interface support on most controllers. | ||
298 | * | ||
299 | * Altsettings are mandatory, however... | ||
300 | */ | ||
301 | if (!gadget_supports_altsettings(c->cdev->gadget)) | ||
302 | return false; | ||
303 | |||
304 | /* everything else is *probably* fine ... */ | ||
305 | return true; | ||
306 | } | ||
307 | |||
308 | static int obex_bind(struct usb_configuration *c, struct usb_function *f) | ||
295 | { | 309 | { |
296 | struct usb_composite_dev *cdev = c->cdev; | 310 | struct usb_composite_dev *cdev = c->cdev; |
297 | struct f_obex *obex = func_to_obex(f); | 311 | struct f_obex *obex = func_to_obex(f); |
298 | int status; | 312 | int status; |
299 | struct usb_ep *ep; | 313 | struct usb_ep *ep; |
300 | 314 | ||
315 | if (!can_support_obex(c)) | ||
316 | return -EINVAL; | ||
317 | |||
318 | if (obex_string_defs[OBEX_CTRL_IDX].id == 0) { | ||
319 | status = usb_string_ids_tab(c->cdev, obex_string_defs); | ||
320 | if (status < 0) | ||
321 | return status; | ||
322 | obex_control_intf.iInterface = | ||
323 | obex_string_defs[OBEX_CTRL_IDX].id; | ||
324 | |||
325 | status = obex_string_defs[OBEX_DATA_IDX].id; | ||
326 | obex_data_nop_intf.iInterface = status; | ||
327 | obex_data_intf.iInterface = status; | ||
328 | } | ||
329 | |||
301 | /* allocate instance-specific interface IDs, and patch descriptors */ | 330 | /* allocate instance-specific interface IDs, and patch descriptors */ |
302 | 331 | ||
303 | status = usb_interface_id(c, f); | 332 | status = usb_interface_id(c, f); |
@@ -376,29 +405,16 @@ fail: | |||
376 | return status; | 405 | return status; |
377 | } | 406 | } |
378 | 407 | ||
408 | #ifdef USBF_OBEX_INCLUDED | ||
409 | |||
379 | static void | 410 | static void |
380 | obex_unbind(struct usb_configuration *c, struct usb_function *f) | 411 | obex_old_unbind(struct usb_configuration *c, struct usb_function *f) |
381 | { | 412 | { |
382 | obex_string_defs[OBEX_CTRL_IDX].id = 0; | 413 | obex_string_defs[OBEX_CTRL_IDX].id = 0; |
383 | usb_free_all_descriptors(f); | 414 | usb_free_all_descriptors(f); |
384 | kfree(func_to_obex(f)); | 415 | kfree(func_to_obex(f)); |
385 | } | 416 | } |
386 | 417 | ||
387 | /* Some controllers can't support CDC OBEX ... */ | ||
388 | static inline bool can_support_obex(struct usb_configuration *c) | ||
389 | { | ||
390 | /* Since the first interface is a NOP, we can ignore the | ||
391 | * issue of multi-interface support on most controllers. | ||
392 | * | ||
393 | * Altsettings are mandatory, however... | ||
394 | */ | ||
395 | if (!gadget_supports_altsettings(c->cdev->gadget)) | ||
396 | return false; | ||
397 | |||
398 | /* everything else is *probably* fine ... */ | ||
399 | return true; | ||
400 | } | ||
401 | |||
402 | /** | 418 | /** |
403 | * obex_bind_config - add a CDC OBEX function to a configuration | 419 | * obex_bind_config - add a CDC OBEX function to a configuration |
404 | * @c: the configuration to support the CDC OBEX instance | 420 | * @c: the configuration to support the CDC OBEX instance |
@@ -412,21 +428,6 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num) | |||
412 | struct f_obex *obex; | 428 | struct f_obex *obex; |
413 | int status; | 429 | int status; |
414 | 430 | ||
415 | if (!can_support_obex(c)) | ||
416 | return -EINVAL; | ||
417 | |||
418 | if (obex_string_defs[OBEX_CTRL_IDX].id == 0) { | ||
419 | status = usb_string_ids_tab(c->cdev, obex_string_defs); | ||
420 | if (status < 0) | ||
421 | return status; | ||
422 | obex_control_intf.iInterface = | ||
423 | obex_string_defs[OBEX_CTRL_IDX].id; | ||
424 | |||
425 | status = obex_string_defs[OBEX_DATA_IDX].id; | ||
426 | obex_data_nop_intf.iInterface = status; | ||
427 | obex_data_intf.iInterface = status; | ||
428 | } | ||
429 | |||
430 | /* allocate and initialize one new instance */ | 431 | /* allocate and initialize one new instance */ |
431 | obex = kzalloc(sizeof *obex, GFP_KERNEL); | 432 | obex = kzalloc(sizeof *obex, GFP_KERNEL); |
432 | if (!obex) | 433 | if (!obex) |
@@ -441,7 +442,7 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num) | |||
441 | obex->port.func.strings = obex_strings; | 442 | obex->port.func.strings = obex_strings; |
442 | /* descriptors are per-instance copies */ | 443 | /* descriptors are per-instance copies */ |
443 | obex->port.func.bind = obex_bind; | 444 | obex->port.func.bind = obex_bind; |
444 | obex->port.func.unbind = obex_unbind; | 445 | obex->port.func.unbind = obex_old_unbind; |
445 | obex->port.func.set_alt = obex_set_alt; | 446 | obex->port.func.set_alt = obex_set_alt; |
446 | obex->port.func.get_alt = obex_get_alt; | 447 | obex->port.func.get_alt = obex_get_alt; |
447 | obex->port.func.disable = obex_disable; | 448 | obex->port.func.disable = obex_disable; |
@@ -453,5 +454,138 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num) | |||
453 | return status; | 454 | return status; |
454 | } | 455 | } |
455 | 456 | ||
457 | #else | ||
458 | |||
459 | static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) | ||
460 | { | ||
461 | return container_of(to_config_group(item), struct f_serial_opts, | ||
462 | func_inst.group); | ||
463 | } | ||
464 | |||
465 | CONFIGFS_ATTR_STRUCT(f_serial_opts); | ||
466 | static ssize_t f_obex_attr_show(struct config_item *item, | ||
467 | struct configfs_attribute *attr, | ||
468 | char *page) | ||
469 | { | ||
470 | struct f_serial_opts *opts = to_f_serial_opts(item); | ||
471 | struct f_serial_opts_attribute *f_serial_opts_attr = | ||
472 | container_of(attr, struct f_serial_opts_attribute, attr); | ||
473 | ssize_t ret = 0; | ||
474 | |||
475 | if (f_serial_opts_attr->show) | ||
476 | ret = f_serial_opts_attr->show(opts, page); | ||
477 | |||
478 | return ret; | ||
479 | } | ||
480 | |||
481 | static void obex_attr_release(struct config_item *item) | ||
482 | { | ||
483 | struct f_serial_opts *opts = to_f_serial_opts(item); | ||
484 | |||
485 | usb_put_function_instance(&opts->func_inst); | ||
486 | } | ||
487 | |||
488 | static struct configfs_item_operations obex_item_ops = { | ||
489 | .release = obex_attr_release, | ||
490 | .show_attribute = f_obex_attr_show, | ||
491 | }; | ||
492 | |||
493 | static ssize_t f_obex_port_num_show(struct f_serial_opts *opts, char *page) | ||
494 | { | ||
495 | return sprintf(page, "%u\n", opts->port_num); | ||
496 | } | ||
497 | |||
498 | static struct f_serial_opts_attribute f_obex_port_num = | ||
499 | __CONFIGFS_ATTR_RO(port_num, f_obex_port_num_show); | ||
500 | |||
501 | static struct configfs_attribute *acm_attrs[] = { | ||
502 | &f_obex_port_num.attr, | ||
503 | NULL, | ||
504 | }; | ||
505 | |||
506 | static struct config_item_type obex_func_type = { | ||
507 | .ct_item_ops = &obex_item_ops, | ||
508 | .ct_attrs = acm_attrs, | ||
509 | .ct_owner = THIS_MODULE, | ||
510 | }; | ||
511 | |||
512 | static void obex_free_inst(struct usb_function_instance *f) | ||
513 | { | ||
514 | struct f_serial_opts *opts; | ||
515 | |||
516 | opts = container_of(f, struct f_serial_opts, func_inst); | ||
517 | gserial_free_line(opts->port_num); | ||
518 | kfree(opts); | ||
519 | } | ||
520 | |||
521 | static struct usb_function_instance *obex_alloc_inst(void) | ||
522 | { | ||
523 | struct f_serial_opts *opts; | ||
524 | int ret; | ||
525 | |||
526 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
527 | if (!opts) | ||
528 | return ERR_PTR(-ENOMEM); | ||
529 | |||
530 | opts->func_inst.free_func_inst = obex_free_inst; | ||
531 | ret = gserial_alloc_line(&opts->port_num); | ||
532 | if (ret) { | ||
533 | kfree(opts); | ||
534 | return ERR_PTR(ret); | ||
535 | } | ||
536 | config_group_init_type_name(&opts->func_inst.group, "", | ||
537 | &obex_func_type); | ||
538 | |||
539 | return &opts->func_inst; | ||
540 | } | ||
541 | |||
542 | static void obex_free(struct usb_function *f) | ||
543 | { | ||
544 | struct f_obex *obex; | ||
545 | |||
546 | obex = func_to_obex(f); | ||
547 | kfree(obex); | ||
548 | } | ||
549 | |||
550 | static void obex_unbind(struct usb_configuration *c, struct usb_function *f) | ||
551 | { | ||
552 | obex_string_defs[OBEX_CTRL_IDX].id = 0; | ||
553 | usb_free_all_descriptors(f); | ||
554 | } | ||
555 | |||
556 | struct usb_function *obex_alloc(struct usb_function_instance *fi) | ||
557 | { | ||
558 | struct f_obex *obex; | ||
559 | struct f_serial_opts *opts; | ||
560 | |||
561 | /* allocate and initialize one new instance */ | ||
562 | obex = kzalloc(sizeof(*obex), GFP_KERNEL); | ||
563 | if (!obex) | ||
564 | return ERR_PTR(-ENOMEM); | ||
565 | |||
566 | opts = container_of(fi, struct f_serial_opts, func_inst); | ||
567 | |||
568 | obex->port_num = opts->port_num; | ||
569 | |||
570 | obex->port.connect = obex_connect; | ||
571 | obex->port.disconnect = obex_disconnect; | ||
572 | |||
573 | obex->port.func.name = "obex"; | ||
574 | obex->port.func.strings = obex_strings; | ||
575 | /* descriptors are per-instance copies */ | ||
576 | obex->port.func.bind = obex_bind; | ||
577 | obex->port.func.unbind = obex_unbind; | ||
578 | obex->port.func.set_alt = obex_set_alt; | ||
579 | obex->port.func.get_alt = obex_get_alt; | ||
580 | obex->port.func.disable = obex_disable; | ||
581 | obex->port.func.free_func = obex_free; | ||
582 | |||
583 | return &obex->port.func; | ||
584 | } | ||
585 | |||
586 | DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc); | ||
587 | |||
588 | #endif | ||
589 | |||
456 | MODULE_AUTHOR("Felipe Balbi"); | 590 | MODULE_AUTHOR("Felipe Balbi"); |
457 | MODULE_LICENSE("GPL"); | 591 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index cc9c49c57c80..36e8c44d8e5e 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -813,7 +813,7 @@ static inline bool can_support_rndis(struct usb_configuration *c) | |||
813 | 813 | ||
814 | int | 814 | int |
815 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 815 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
816 | u32 vendorID, const char *manufacturer) | 816 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) |
817 | { | 817 | { |
818 | struct f_rndis *rndis; | 818 | struct f_rndis *rndis; |
819 | int status; | 819 | int status; |
@@ -846,6 +846,7 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | |||
846 | rndis->vendorID = vendorID; | 846 | rndis->vendorID = vendorID; |
847 | rndis->manufacturer = manufacturer; | 847 | rndis->manufacturer = manufacturer; |
848 | 848 | ||
849 | rndis->port.ioport = dev; | ||
849 | /* RNDIS activates when the host changes this filter */ | 850 | /* RNDIS activates when the host changes this filter */ |
850 | rndis->port.cdc_filter = 0; | 851 | rndis->port.cdc_filter = 0; |
851 | 852 | ||
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c index da33cfb3031d..981113c9924d 100644 --- a/drivers/usb/gadget/f_serial.c +++ b/drivers/usb/gadget/f_serial.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/module.h> | ||
15 | #include <linux/device.h> | 16 | #include <linux/device.h> |
16 | 17 | ||
17 | #include "u_serial.h" | 18 | #include "u_serial.h" |
@@ -42,7 +43,7 @@ static inline struct f_gser *func_to_gser(struct usb_function *f) | |||
42 | 43 | ||
43 | /* interface descriptor: */ | 44 | /* interface descriptor: */ |
44 | 45 | ||
45 | static struct usb_interface_descriptor gser_interface_desc __initdata = { | 46 | static struct usb_interface_descriptor gser_interface_desc = { |
46 | .bLength = USB_DT_INTERFACE_SIZE, | 47 | .bLength = USB_DT_INTERFACE_SIZE, |
47 | .bDescriptorType = USB_DT_INTERFACE, | 48 | .bDescriptorType = USB_DT_INTERFACE, |
48 | /* .bInterfaceNumber = DYNAMIC */ | 49 | /* .bInterfaceNumber = DYNAMIC */ |
@@ -55,21 +56,21 @@ static struct usb_interface_descriptor gser_interface_desc __initdata = { | |||
55 | 56 | ||
56 | /* full speed support: */ | 57 | /* full speed support: */ |
57 | 58 | ||
58 | static struct usb_endpoint_descriptor gser_fs_in_desc __initdata = { | 59 | static struct usb_endpoint_descriptor gser_fs_in_desc = { |
59 | .bLength = USB_DT_ENDPOINT_SIZE, | 60 | .bLength = USB_DT_ENDPOINT_SIZE, |
60 | .bDescriptorType = USB_DT_ENDPOINT, | 61 | .bDescriptorType = USB_DT_ENDPOINT, |
61 | .bEndpointAddress = USB_DIR_IN, | 62 | .bEndpointAddress = USB_DIR_IN, |
62 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 63 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
63 | }; | 64 | }; |
64 | 65 | ||
65 | static struct usb_endpoint_descriptor gser_fs_out_desc __initdata = { | 66 | static struct usb_endpoint_descriptor gser_fs_out_desc = { |
66 | .bLength = USB_DT_ENDPOINT_SIZE, | 67 | .bLength = USB_DT_ENDPOINT_SIZE, |
67 | .bDescriptorType = USB_DT_ENDPOINT, | 68 | .bDescriptorType = USB_DT_ENDPOINT, |
68 | .bEndpointAddress = USB_DIR_OUT, | 69 | .bEndpointAddress = USB_DIR_OUT, |
69 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 70 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
70 | }; | 71 | }; |
71 | 72 | ||
72 | static struct usb_descriptor_header *gser_fs_function[] __initdata = { | 73 | static struct usb_descriptor_header *gser_fs_function[] = { |
73 | (struct usb_descriptor_header *) &gser_interface_desc, | 74 | (struct usb_descriptor_header *) &gser_interface_desc, |
74 | (struct usb_descriptor_header *) &gser_fs_in_desc, | 75 | (struct usb_descriptor_header *) &gser_fs_in_desc, |
75 | (struct usb_descriptor_header *) &gser_fs_out_desc, | 76 | (struct usb_descriptor_header *) &gser_fs_out_desc, |
@@ -78,47 +79,47 @@ static struct usb_descriptor_header *gser_fs_function[] __initdata = { | |||
78 | 79 | ||
79 | /* high speed support: */ | 80 | /* high speed support: */ |
80 | 81 | ||
81 | static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = { | 82 | static struct usb_endpoint_descriptor gser_hs_in_desc = { |
82 | .bLength = USB_DT_ENDPOINT_SIZE, | 83 | .bLength = USB_DT_ENDPOINT_SIZE, |
83 | .bDescriptorType = USB_DT_ENDPOINT, | 84 | .bDescriptorType = USB_DT_ENDPOINT, |
84 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 85 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
85 | .wMaxPacketSize = cpu_to_le16(512), | 86 | .wMaxPacketSize = cpu_to_le16(512), |
86 | }; | 87 | }; |
87 | 88 | ||
88 | static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = { | 89 | static struct usb_endpoint_descriptor gser_hs_out_desc = { |
89 | .bLength = USB_DT_ENDPOINT_SIZE, | 90 | .bLength = USB_DT_ENDPOINT_SIZE, |
90 | .bDescriptorType = USB_DT_ENDPOINT, | 91 | .bDescriptorType = USB_DT_ENDPOINT, |
91 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 92 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
92 | .wMaxPacketSize = cpu_to_le16(512), | 93 | .wMaxPacketSize = cpu_to_le16(512), |
93 | }; | 94 | }; |
94 | 95 | ||
95 | static struct usb_descriptor_header *gser_hs_function[] __initdata = { | 96 | static struct usb_descriptor_header *gser_hs_function[] = { |
96 | (struct usb_descriptor_header *) &gser_interface_desc, | 97 | (struct usb_descriptor_header *) &gser_interface_desc, |
97 | (struct usb_descriptor_header *) &gser_hs_in_desc, | 98 | (struct usb_descriptor_header *) &gser_hs_in_desc, |
98 | (struct usb_descriptor_header *) &gser_hs_out_desc, | 99 | (struct usb_descriptor_header *) &gser_hs_out_desc, |
99 | NULL, | 100 | NULL, |
100 | }; | 101 | }; |
101 | 102 | ||
102 | static struct usb_endpoint_descriptor gser_ss_in_desc __initdata = { | 103 | static struct usb_endpoint_descriptor gser_ss_in_desc = { |
103 | .bLength = USB_DT_ENDPOINT_SIZE, | 104 | .bLength = USB_DT_ENDPOINT_SIZE, |
104 | .bDescriptorType = USB_DT_ENDPOINT, | 105 | .bDescriptorType = USB_DT_ENDPOINT, |
105 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 106 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
106 | .wMaxPacketSize = cpu_to_le16(1024), | 107 | .wMaxPacketSize = cpu_to_le16(1024), |
107 | }; | 108 | }; |
108 | 109 | ||
109 | static struct usb_endpoint_descriptor gser_ss_out_desc __initdata = { | 110 | static struct usb_endpoint_descriptor gser_ss_out_desc = { |
110 | .bLength = USB_DT_ENDPOINT_SIZE, | 111 | .bLength = USB_DT_ENDPOINT_SIZE, |
111 | .bDescriptorType = USB_DT_ENDPOINT, | 112 | .bDescriptorType = USB_DT_ENDPOINT, |
112 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 113 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
113 | .wMaxPacketSize = cpu_to_le16(1024), | 114 | .wMaxPacketSize = cpu_to_le16(1024), |
114 | }; | 115 | }; |
115 | 116 | ||
116 | static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc __initdata = { | 117 | static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc = { |
117 | .bLength = sizeof gser_ss_bulk_comp_desc, | 118 | .bLength = sizeof gser_ss_bulk_comp_desc, |
118 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 119 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
119 | }; | 120 | }; |
120 | 121 | ||
121 | static struct usb_descriptor_header *gser_ss_function[] __initdata = { | 122 | static struct usb_descriptor_header *gser_ss_function[] = { |
122 | (struct usb_descriptor_header *) &gser_interface_desc, | 123 | (struct usb_descriptor_header *) &gser_interface_desc, |
123 | (struct usb_descriptor_header *) &gser_ss_in_desc, | 124 | (struct usb_descriptor_header *) &gser_ss_in_desc, |
124 | (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, | 125 | (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, |
@@ -183,14 +184,25 @@ static void gser_disable(struct usb_function *f) | |||
183 | 184 | ||
184 | /* serial function driver setup/binding */ | 185 | /* serial function driver setup/binding */ |
185 | 186 | ||
186 | static int __init | 187 | static int gser_bind(struct usb_configuration *c, struct usb_function *f) |
187 | gser_bind(struct usb_configuration *c, struct usb_function *f) | ||
188 | { | 188 | { |
189 | struct usb_composite_dev *cdev = c->cdev; | 189 | struct usb_composite_dev *cdev = c->cdev; |
190 | struct f_gser *gser = func_to_gser(f); | 190 | struct f_gser *gser = func_to_gser(f); |
191 | int status; | 191 | int status; |
192 | struct usb_ep *ep; | 192 | struct usb_ep *ep; |
193 | 193 | ||
194 | /* REVISIT might want instance-specific strings to help | ||
195 | * distinguish instances ... | ||
196 | */ | ||
197 | |||
198 | /* maybe allocate device-global string ID */ | ||
199 | if (gser_string_defs[0].id == 0) { | ||
200 | status = usb_string_id(c->cdev); | ||
201 | if (status < 0) | ||
202 | return status; | ||
203 | gser_string_defs[0].id = status; | ||
204 | } | ||
205 | |||
194 | /* allocate instance-specific interface IDs */ | 206 | /* allocate instance-specific interface IDs */ |
195 | status = usb_interface_id(c, f); | 207 | status = usb_interface_id(c, f); |
196 | if (status < 0) | 208 | if (status < 0) |
@@ -246,44 +258,115 @@ fail: | |||
246 | return status; | 258 | return status; |
247 | } | 259 | } |
248 | 260 | ||
249 | static void | 261 | static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) |
250 | gser_unbind(struct usb_configuration *c, struct usb_function *f) | ||
251 | { | 262 | { |
252 | usb_free_all_descriptors(f); | 263 | return container_of(to_config_group(item), struct f_serial_opts, |
253 | kfree(func_to_gser(f)); | 264 | func_inst.group); |
254 | } | 265 | } |
255 | 266 | ||
256 | /** | 267 | CONFIGFS_ATTR_STRUCT(f_serial_opts); |
257 | * gser_bind_config - add a generic serial function to a configuration | 268 | static ssize_t f_serial_attr_show(struct config_item *item, |
258 | * @c: the configuration to support the serial instance | 269 | struct configfs_attribute *attr, |
259 | * @port_num: /dev/ttyGS* port this interface will use | 270 | char *page) |
260 | * Context: single threaded during gadget setup | ||
261 | * | ||
262 | * Returns zero on success, else negative errno. | ||
263 | */ | ||
264 | int __init gser_bind_config(struct usb_configuration *c, u8 port_num) | ||
265 | { | 271 | { |
266 | struct f_gser *gser; | 272 | struct f_serial_opts *opts = to_f_serial_opts(item); |
267 | int status; | 273 | struct f_serial_opts_attribute *f_serial_opts_attr = |
274 | container_of(attr, struct f_serial_opts_attribute, attr); | ||
275 | ssize_t ret = 0; | ||
268 | 276 | ||
269 | /* REVISIT might want instance-specific strings to help | 277 | if (f_serial_opts_attr->show) |
270 | * distinguish instances ... | 278 | ret = f_serial_opts_attr->show(opts, page); |
271 | */ | ||
272 | 279 | ||
273 | /* maybe allocate device-global string ID */ | 280 | return ret; |
274 | if (gser_string_defs[0].id == 0) { | 281 | } |
275 | status = usb_string_id(c->cdev); | 282 | |
276 | if (status < 0) | 283 | static void serial_attr_release(struct config_item *item) |
277 | return status; | 284 | { |
278 | gser_string_defs[0].id = status; | 285 | struct f_serial_opts *opts = to_f_serial_opts(item); |
286 | |||
287 | usb_put_function_instance(&opts->func_inst); | ||
288 | } | ||
289 | |||
290 | static struct configfs_item_operations serial_item_ops = { | ||
291 | .release = serial_attr_release, | ||
292 | .show_attribute = f_serial_attr_show, | ||
293 | }; | ||
294 | |||
295 | static ssize_t f_serial_port_num_show(struct f_serial_opts *opts, char *page) | ||
296 | { | ||
297 | return sprintf(page, "%u\n", opts->port_num); | ||
298 | } | ||
299 | |||
300 | static struct f_serial_opts_attribute f_serial_port_num = | ||
301 | __CONFIGFS_ATTR_RO(port_num, f_serial_port_num_show); | ||
302 | |||
303 | static struct configfs_attribute *acm_attrs[] = { | ||
304 | &f_serial_port_num.attr, | ||
305 | NULL, | ||
306 | }; | ||
307 | |||
308 | static struct config_item_type serial_func_type = { | ||
309 | .ct_item_ops = &serial_item_ops, | ||
310 | .ct_attrs = acm_attrs, | ||
311 | .ct_owner = THIS_MODULE, | ||
312 | }; | ||
313 | |||
314 | static void gser_free_inst(struct usb_function_instance *f) | ||
315 | { | ||
316 | struct f_serial_opts *opts; | ||
317 | |||
318 | opts = container_of(f, struct f_serial_opts, func_inst); | ||
319 | gserial_free_line(opts->port_num); | ||
320 | kfree(opts); | ||
321 | } | ||
322 | |||
323 | static struct usb_function_instance *gser_alloc_inst(void) | ||
324 | { | ||
325 | struct f_serial_opts *opts; | ||
326 | int ret; | ||
327 | |||
328 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
329 | if (!opts) | ||
330 | return ERR_PTR(-ENOMEM); | ||
331 | |||
332 | opts->func_inst.free_func_inst = gser_free_inst; | ||
333 | ret = gserial_alloc_line(&opts->port_num); | ||
334 | if (ret) { | ||
335 | kfree(opts); | ||
336 | return ERR_PTR(ret); | ||
279 | } | 337 | } |
338 | config_group_init_type_name(&opts->func_inst.group, "", | ||
339 | &serial_func_type); | ||
340 | |||
341 | return &opts->func_inst; | ||
342 | } | ||
343 | |||
344 | static void gser_free(struct usb_function *f) | ||
345 | { | ||
346 | struct f_gser *serial; | ||
347 | |||
348 | serial = func_to_gser(f); | ||
349 | kfree(serial); | ||
350 | } | ||
351 | |||
352 | static void gser_unbind(struct usb_configuration *c, struct usb_function *f) | ||
353 | { | ||
354 | usb_free_all_descriptors(f); | ||
355 | } | ||
356 | |||
357 | struct usb_function *gser_alloc(struct usb_function_instance *fi) | ||
358 | { | ||
359 | struct f_gser *gser; | ||
360 | struct f_serial_opts *opts; | ||
280 | 361 | ||
281 | /* allocate and initialize one new instance */ | 362 | /* allocate and initialize one new instance */ |
282 | gser = kzalloc(sizeof *gser, GFP_KERNEL); | 363 | gser = kzalloc(sizeof(*gser), GFP_KERNEL); |
283 | if (!gser) | 364 | if (!gser) |
284 | return -ENOMEM; | 365 | return ERR_PTR(-ENOMEM); |
285 | 366 | ||
286 | gser->port_num = port_num; | 367 | opts = container_of(fi, struct f_serial_opts, func_inst); |
368 | |||
369 | gser->port_num = opts->port_num; | ||
287 | 370 | ||
288 | gser->port.func.name = "gser"; | 371 | gser->port.func.name = "gser"; |
289 | gser->port.func.strings = gser_strings; | 372 | gser->port.func.strings = gser_strings; |
@@ -291,9 +374,12 @@ int __init gser_bind_config(struct usb_configuration *c, u8 port_num) | |||
291 | gser->port.func.unbind = gser_unbind; | 374 | gser->port.func.unbind = gser_unbind; |
292 | gser->port.func.set_alt = gser_set_alt; | 375 | gser->port.func.set_alt = gser_set_alt; |
293 | gser->port.func.disable = gser_disable; | 376 | gser->port.func.disable = gser_disable; |
377 | gser->port.func.free_func = gser_free; | ||
294 | 378 | ||
295 | status = usb_add_function(c, &gser->port.func); | 379 | return &gser->port.func; |
296 | if (status) | ||
297 | kfree(gser); | ||
298 | return status; | ||
299 | } | 380 | } |
381 | |||
382 | DECLARE_USB_FUNCTION_INIT(gser, gser_alloc_inst, gser_alloc); | ||
383 | MODULE_LICENSE("GPL"); | ||
384 | MODULE_AUTHOR("Al Borchers"); | ||
385 | MODULE_AUTHOR("David Brownell"); | ||
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index f172bd152fbb..185d6f5e4e4d 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -380,7 +380,8 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f) | |||
380 | * Caller must have called @gether_setup(). Caller is also responsible | 380 | * Caller must have called @gether_setup(). Caller is also responsible |
381 | * for calling @gether_cleanup() before module unload. | 381 | * for calling @gether_cleanup() before module unload. |
382 | */ | 382 | */ |
383 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | 383 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
384 | struct eth_dev *dev) | ||
384 | { | 385 | { |
385 | struct f_gether *geth; | 386 | struct f_gether *geth; |
386 | int status; | 387 | int status; |
@@ -406,6 +407,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | |||
406 | snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); | 407 | snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); |
407 | geth_string_defs[1].s = geth->ethaddr; | 408 | geth_string_defs[1].s = geth->ethaddr; |
408 | 409 | ||
410 | geth->port.ioport = dev; | ||
409 | geth->port.cdc_filter = DEFAULT_FILTER; | 411 | geth->port.cdc_filter = DEFAULT_FILTER; |
410 | 412 | ||
411 | geth->port.func.name = "cdc_subset"; | 413 | geth->port.func.name = "cdc_subset"; |
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c index 92efd6ec48af..38dcedddc52c 100644 --- a/drivers/usb/gadget/f_uvc.c +++ b/drivers/usb/gadget/f_uvc.c | |||
@@ -33,19 +33,15 @@ unsigned int uvc_gadget_trace_param; | |||
33 | /*-------------------------------------------------------------------------*/ | 33 | /*-------------------------------------------------------------------------*/ |
34 | 34 | ||
35 | /* module parameters specific to the Video streaming endpoint */ | 35 | /* module parameters specific to the Video streaming endpoint */ |
36 | static unsigned streaming_interval = 1; | 36 | static unsigned int streaming_interval = 1; |
37 | module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); | 37 | module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); |
38 | MODULE_PARM_DESC(streaming_interval, "1 - 16"); | 38 | MODULE_PARM_DESC(streaming_interval, "1 - 16"); |
39 | 39 | ||
40 | static unsigned streaming_maxpacket = 1024; | 40 | static unsigned int streaming_maxpacket = 1024; |
41 | module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); | 41 | module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); |
42 | MODULE_PARM_DESC(streaming_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); | 42 | MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)"); |
43 | 43 | ||
44 | static unsigned streaming_mult; | 44 | static unsigned int streaming_maxburst; |
45 | module_param(streaming_mult, uint, S_IRUGO|S_IWUSR); | ||
46 | MODULE_PARM_DESC(streaming_mult, "0 - 2 (hs/ss only)"); | ||
47 | |||
48 | static unsigned streaming_maxburst; | ||
49 | module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); | 45 | module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); |
50 | MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); | 46 | MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); |
51 | 47 | ||
@@ -55,13 +51,11 @@ MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); | |||
55 | 51 | ||
56 | /* string IDs are assigned dynamically */ | 52 | /* string IDs are assigned dynamically */ |
57 | 53 | ||
58 | #define UVC_STRING_ASSOCIATION_IDX 0 | 54 | #define UVC_STRING_CONTROL_IDX 0 |
59 | #define UVC_STRING_CONTROL_IDX 1 | 55 | #define UVC_STRING_STREAMING_IDX 1 |
60 | #define UVC_STRING_STREAMING_IDX 2 | ||
61 | 56 | ||
62 | static struct usb_string uvc_en_us_strings[] = { | 57 | static struct usb_string uvc_en_us_strings[] = { |
63 | [UVC_STRING_ASSOCIATION_IDX].s = "UVC Camera", | 58 | [UVC_STRING_CONTROL_IDX].s = "UVC Camera", |
64 | [UVC_STRING_CONTROL_IDX].s = "Video Control", | ||
65 | [UVC_STRING_STREAMING_IDX].s = "Video Streaming", | 59 | [UVC_STRING_STREAMING_IDX].s = "Video Streaming", |
66 | { } | 60 | { } |
67 | }; | 61 | }; |
@@ -79,7 +73,7 @@ static struct usb_gadget_strings *uvc_function_strings[] = { | |||
79 | #define UVC_INTF_VIDEO_CONTROL 0 | 73 | #define UVC_INTF_VIDEO_CONTROL 0 |
80 | #define UVC_INTF_VIDEO_STREAMING 1 | 74 | #define UVC_INTF_VIDEO_STREAMING 1 |
81 | 75 | ||
82 | #define STATUS_BYTECOUNT 16 /* 16 bytes status */ | 76 | #define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */ |
83 | 77 | ||
84 | static struct usb_interface_assoc_descriptor uvc_iad __initdata = { | 78 | static struct usb_interface_assoc_descriptor uvc_iad __initdata = { |
85 | .bLength = sizeof(uvc_iad), | 79 | .bLength = sizeof(uvc_iad), |
@@ -104,20 +98,29 @@ static struct usb_interface_descriptor uvc_control_intf __initdata = { | |||
104 | .iInterface = 0, | 98 | .iInterface = 0, |
105 | }; | 99 | }; |
106 | 100 | ||
107 | static struct usb_endpoint_descriptor uvc_fs_control_ep __initdata = { | 101 | static struct usb_endpoint_descriptor uvc_control_ep __initdata = { |
108 | .bLength = USB_DT_ENDPOINT_SIZE, | 102 | .bLength = USB_DT_ENDPOINT_SIZE, |
109 | .bDescriptorType = USB_DT_ENDPOINT, | 103 | .bDescriptorType = USB_DT_ENDPOINT, |
110 | .bEndpointAddress = USB_DIR_IN, | 104 | .bEndpointAddress = USB_DIR_IN, |
111 | .bmAttributes = USB_ENDPOINT_XFER_INT, | 105 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
112 | .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), | 106 | .wMaxPacketSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), |
113 | .bInterval = 8, | 107 | .bInterval = 8, |
114 | }; | 108 | }; |
115 | 109 | ||
110 | static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = { | ||
111 | .bLength = sizeof(uvc_ss_control_comp), | ||
112 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
113 | /* The following 3 values can be tweaked if necessary. */ | ||
114 | .bMaxBurst = 0, | ||
115 | .bmAttributes = 0, | ||
116 | .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), | ||
117 | }; | ||
118 | |||
116 | static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = { | 119 | static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = { |
117 | .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, | 120 | .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, |
118 | .bDescriptorType = USB_DT_CS_ENDPOINT, | 121 | .bDescriptorType = USB_DT_CS_ENDPOINT, |
119 | .bDescriptorSubType = UVC_EP_INTERRUPT, | 122 | .bDescriptorSubType = UVC_EP_INTERRUPT, |
120 | .wMaxTransferSize = cpu_to_le16(STATUS_BYTECOUNT), | 123 | .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), |
121 | }; | 124 | }; |
122 | 125 | ||
123 | static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { | 126 | static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { |
@@ -144,63 +147,53 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = { | |||
144 | .iInterface = 0, | 147 | .iInterface = 0, |
145 | }; | 148 | }; |
146 | 149 | ||
147 | static struct usb_endpoint_descriptor uvc_fs_streaming_ep = { | 150 | static struct usb_endpoint_descriptor uvc_fs_streaming_ep __initdata = { |
148 | .bLength = USB_DT_ENDPOINT_SIZE, | 151 | .bLength = USB_DT_ENDPOINT_SIZE, |
149 | .bDescriptorType = USB_DT_ENDPOINT, | 152 | .bDescriptorType = USB_DT_ENDPOINT, |
150 | .bEndpointAddress = USB_DIR_IN, | 153 | .bEndpointAddress = USB_DIR_IN, |
151 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | 154 | .bmAttributes = USB_ENDPOINT_SYNC_ASYNC |
152 | .wMaxPacketSize = cpu_to_le16(512), | 155 | | USB_ENDPOINT_XFER_ISOC, |
153 | .bInterval = 1, | 156 | /* The wMaxPacketSize and bInterval values will be initialized from |
157 | * module parameters. | ||
158 | */ | ||
159 | .wMaxPacketSize = 0, | ||
160 | .bInterval = 0, | ||
154 | }; | 161 | }; |
155 | 162 | ||
156 | static struct usb_endpoint_descriptor uvc_hs_streaming_ep = { | 163 | static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = { |
157 | .bLength = USB_DT_ENDPOINT_SIZE, | 164 | .bLength = USB_DT_ENDPOINT_SIZE, |
158 | .bDescriptorType = USB_DT_ENDPOINT, | 165 | .bDescriptorType = USB_DT_ENDPOINT, |
159 | .bEndpointAddress = USB_DIR_IN, | 166 | .bEndpointAddress = USB_DIR_IN, |
160 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | 167 | .bmAttributes = USB_ENDPOINT_SYNC_ASYNC |
161 | .wMaxPacketSize = cpu_to_le16(1024), | 168 | | USB_ENDPOINT_XFER_ISOC, |
162 | .bInterval = 1, | 169 | /* The wMaxPacketSize and bInterval values will be initialized from |
163 | }; | 170 | * module parameters. |
164 | 171 | */ | |
165 | /* super speed support */ | 172 | .wMaxPacketSize = 0, |
166 | static struct usb_endpoint_descriptor uvc_ss_control_ep __initdata = { | 173 | .bInterval = 0, |
167 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
168 | .bDescriptorType = USB_DT_ENDPOINT, | ||
169 | |||
170 | .bEndpointAddress = USB_DIR_IN, | ||
171 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
172 | .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), | ||
173 | .bInterval = 8, | ||
174 | }; | ||
175 | |||
176 | static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = { | ||
177 | .bLength = sizeof uvc_ss_control_comp, | ||
178 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
179 | |||
180 | /* the following 3 values can be tweaked if necessary */ | ||
181 | /* .bMaxBurst = 0, */ | ||
182 | /* .bmAttributes = 0, */ | ||
183 | .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT), | ||
184 | }; | 174 | }; |
185 | 175 | ||
186 | static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { | 176 | static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { |
187 | .bLength = USB_DT_ENDPOINT_SIZE, | 177 | .bLength = USB_DT_ENDPOINT_SIZE, |
188 | .bDescriptorType = USB_DT_ENDPOINT, | 178 | .bDescriptorType = USB_DT_ENDPOINT, |
189 | 179 | ||
190 | .bEndpointAddress = USB_DIR_IN, | 180 | .bEndpointAddress = USB_DIR_IN, |
191 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | 181 | .bmAttributes = USB_ENDPOINT_SYNC_ASYNC |
192 | .wMaxPacketSize = cpu_to_le16(1024), | 182 | | USB_ENDPOINT_XFER_ISOC, |
193 | .bInterval = 4, | 183 | /* The wMaxPacketSize and bInterval values will be initialized from |
184 | * module parameters. | ||
185 | */ | ||
186 | .wMaxPacketSize = 0, | ||
187 | .bInterval = 0, | ||
194 | }; | 188 | }; |
195 | 189 | ||
196 | static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = { | 190 | static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp __initdata = { |
197 | .bLength = sizeof uvc_ss_streaming_comp, | 191 | .bLength = sizeof(uvc_ss_streaming_comp), |
198 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 192 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
199 | 193 | /* The following 3 values can be tweaked if necessary. */ | |
200 | /* the following 3 values can be tweaked if necessary */ | 194 | .bMaxBurst = 0, |
201 | .bMaxBurst = 0, | 195 | .bmAttributes = 0, |
202 | .bmAttributes = 0, | 196 | .wBytesPerInterval = cpu_to_le16(1024), |
203 | .wBytesPerInterval = cpu_to_le16(1024), | ||
204 | }; | 197 | }; |
205 | 198 | ||
206 | static const struct usb_descriptor_header * const uvc_fs_streaming[] = { | 199 | static const struct usb_descriptor_header * const uvc_fs_streaming[] = { |
@@ -273,6 +266,13 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | |||
273 | return 0; | 266 | return 0; |
274 | } | 267 | } |
275 | 268 | ||
269 | void uvc_function_setup_continue(struct uvc_device *uvc) | ||
270 | { | ||
271 | struct usb_composite_dev *cdev = uvc->func.config->cdev; | ||
272 | |||
273 | usb_composite_setup_continue(cdev); | ||
274 | } | ||
275 | |||
276 | static int | 276 | static int |
277 | uvc_function_get_alt(struct usb_function *f, unsigned interface) | 277 | uvc_function_get_alt(struct usb_function *f, unsigned interface) |
278 | { | 278 | { |
@@ -335,7 +335,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) | |||
335 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 335 | v4l2_event_queue(uvc->vdev, &v4l2_event); |
336 | 336 | ||
337 | uvc->state = UVC_STATE_CONNECTED; | 337 | uvc->state = UVC_STATE_CONNECTED; |
338 | break; | 338 | return 0; |
339 | 339 | ||
340 | case 1: | 340 | case 1: |
341 | if (uvc->state != UVC_STATE_CONNECTED) | 341 | if (uvc->state != UVC_STATE_CONNECTED) |
@@ -352,15 +352,11 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) | |||
352 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 352 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
353 | v4l2_event.type = UVC_EVENT_STREAMON; | 353 | v4l2_event.type = UVC_EVENT_STREAMON; |
354 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 354 | v4l2_event_queue(uvc->vdev, &v4l2_event); |
355 | 355 | return USB_GADGET_DELAYED_STATUS; | |
356 | uvc->state = UVC_STATE_STREAMING; | ||
357 | break; | ||
358 | 356 | ||
359 | default: | 357 | default: |
360 | return -EINVAL; | 358 | return -EINVAL; |
361 | } | 359 | } |
362 | |||
363 | return 0; | ||
364 | } | 360 | } |
365 | 361 | ||
366 | static void | 362 | static void |
@@ -454,7 +450,6 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
454 | const struct uvc_descriptor_header * const *uvc_streaming_cls; | 450 | const struct uvc_descriptor_header * const *uvc_streaming_cls; |
455 | const struct usb_descriptor_header * const *uvc_streaming_std; | 451 | const struct usb_descriptor_header * const *uvc_streaming_std; |
456 | const struct usb_descriptor_header * const *src; | 452 | const struct usb_descriptor_header * const *src; |
457 | static struct usb_endpoint_descriptor *uvc_control_ep; | ||
458 | struct usb_descriptor_header **dst; | 453 | struct usb_descriptor_header **dst; |
459 | struct usb_descriptor_header **hdr; | 454 | struct usb_descriptor_header **hdr; |
460 | unsigned int control_size; | 455 | unsigned int control_size; |
@@ -468,14 +463,12 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
468 | uvc_control_desc = uvc->desc.ss_control; | 463 | uvc_control_desc = uvc->desc.ss_control; |
469 | uvc_streaming_cls = uvc->desc.ss_streaming; | 464 | uvc_streaming_cls = uvc->desc.ss_streaming; |
470 | uvc_streaming_std = uvc_ss_streaming; | 465 | uvc_streaming_std = uvc_ss_streaming; |
471 | uvc_control_ep = &uvc_ss_control_ep; | ||
472 | break; | 466 | break; |
473 | 467 | ||
474 | case USB_SPEED_HIGH: | 468 | case USB_SPEED_HIGH: |
475 | uvc_control_desc = uvc->desc.fs_control; | 469 | uvc_control_desc = uvc->desc.fs_control; |
476 | uvc_streaming_cls = uvc->desc.hs_streaming; | 470 | uvc_streaming_cls = uvc->desc.hs_streaming; |
477 | uvc_streaming_std = uvc_hs_streaming; | 471 | uvc_streaming_std = uvc_hs_streaming; |
478 | uvc_control_ep = &uvc_fs_control_ep; | ||
479 | break; | 472 | break; |
480 | 473 | ||
481 | case USB_SPEED_FULL: | 474 | case USB_SPEED_FULL: |
@@ -483,7 +476,6 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
483 | uvc_control_desc = uvc->desc.fs_control; | 476 | uvc_control_desc = uvc->desc.fs_control; |
484 | uvc_streaming_cls = uvc->desc.fs_streaming; | 477 | uvc_streaming_cls = uvc->desc.fs_streaming; |
485 | uvc_streaming_std = uvc_fs_streaming; | 478 | uvc_streaming_std = uvc_fs_streaming; |
486 | uvc_control_ep = &uvc_fs_control_ep; | ||
487 | break; | 479 | break; |
488 | } | 480 | } |
489 | 481 | ||
@@ -494,6 +486,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
494 | * Class-specific UVC control descriptors | 486 | * Class-specific UVC control descriptors |
495 | * uvc_control_ep | 487 | * uvc_control_ep |
496 | * uvc_control_cs_ep | 488 | * uvc_control_cs_ep |
489 | * uvc_ss_control_comp (for SS only) | ||
497 | * uvc_streaming_intf_alt0 | 490 | * uvc_streaming_intf_alt0 |
498 | * Class-specific UVC streaming descriptors | 491 | * Class-specific UVC streaming descriptors |
499 | * uvc_{fs|hs}_streaming | 492 | * uvc_{fs|hs}_streaming |
@@ -503,7 +496,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
503 | control_size = 0; | 496 | control_size = 0; |
504 | streaming_size = 0; | 497 | streaming_size = 0; |
505 | bytes = uvc_iad.bLength + uvc_control_intf.bLength | 498 | bytes = uvc_iad.bLength + uvc_control_intf.bLength |
506 | + uvc_control_ep->bLength + uvc_control_cs_ep.bLength | 499 | + uvc_control_ep.bLength + uvc_control_cs_ep.bLength |
507 | + uvc_streaming_intf_alt0.bLength; | 500 | + uvc_streaming_intf_alt0.bLength; |
508 | 501 | ||
509 | if (speed == USB_SPEED_SUPER) { | 502 | if (speed == USB_SPEED_SUPER) { |
@@ -514,13 +507,13 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
514 | } | 507 | } |
515 | 508 | ||
516 | for (src = (const struct usb_descriptor_header **)uvc_control_desc; | 509 | for (src = (const struct usb_descriptor_header **)uvc_control_desc; |
517 | *src; ++src) { | 510 | *src; ++src) { |
518 | control_size += (*src)->bLength; | 511 | control_size += (*src)->bLength; |
519 | bytes += (*src)->bLength; | 512 | bytes += (*src)->bLength; |
520 | n_desc++; | 513 | n_desc++; |
521 | } | 514 | } |
522 | for (src = (const struct usb_descriptor_header **)uvc_streaming_cls; | 515 | for (src = (const struct usb_descriptor_header **)uvc_streaming_cls; |
523 | *src; ++src) { | 516 | *src; ++src) { |
524 | streaming_size += (*src)->bLength; | 517 | streaming_size += (*src)->bLength; |
525 | bytes += (*src)->bLength; | 518 | bytes += (*src)->bLength; |
526 | n_desc++; | 519 | n_desc++; |
@@ -549,7 +542,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
549 | uvc_control_header->bInCollection = 1; | 542 | uvc_control_header->bInCollection = 1; |
550 | uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf; | 543 | uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf; |
551 | 544 | ||
552 | UVC_COPY_DESCRIPTOR(mem, dst, uvc_control_ep); | 545 | UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_ep); |
553 | if (speed == USB_SPEED_SUPER) | 546 | if (speed == USB_SPEED_SUPER) |
554 | UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp); | 547 | UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp); |
555 | 548 | ||
@@ -560,8 +553,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
560 | UVC_COPY_DESCRIPTORS(mem, dst, | 553 | UVC_COPY_DESCRIPTORS(mem, dst, |
561 | (const struct usb_descriptor_header**)uvc_streaming_cls); | 554 | (const struct usb_descriptor_header**)uvc_streaming_cls); |
562 | uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size); | 555 | uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size); |
563 | uvc_streaming_header->bEndpointAddress = | 556 | uvc_streaming_header->bEndpointAddress = uvc->video.ep->address; |
564 | uvc_fs_streaming_ep.bEndpointAddress; | ||
565 | 557 | ||
566 | UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std); | 558 | UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std); |
567 | 559 | ||
@@ -581,7 +573,7 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f) | |||
581 | uvc->control_ep->driver_data = NULL; | 573 | uvc->control_ep->driver_data = NULL; |
582 | uvc->video.ep->driver_data = NULL; | 574 | uvc->video.ep->driver_data = NULL; |
583 | 575 | ||
584 | uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id = 0; | 576 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = 0; |
585 | usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); | 577 | usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); |
586 | kfree(uvc->control_buf); | 578 | kfree(uvc->control_buf); |
587 | 579 | ||
@@ -595,31 +587,52 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
595 | { | 587 | { |
596 | struct usb_composite_dev *cdev = c->cdev; | 588 | struct usb_composite_dev *cdev = c->cdev; |
597 | struct uvc_device *uvc = to_uvc(f); | 589 | struct uvc_device *uvc = to_uvc(f); |
590 | unsigned int max_packet_mult; | ||
591 | unsigned int max_packet_size; | ||
598 | struct usb_ep *ep; | 592 | struct usb_ep *ep; |
599 | int ret = -EINVAL; | 593 | int ret = -EINVAL; |
600 | 594 | ||
601 | INFO(cdev, "uvc_function_bind\n"); | 595 | INFO(cdev, "uvc_function_bind\n"); |
602 | 596 | ||
603 | /* sanity check the streaming endpoint module parameters */ | 597 | /* Sanity check the streaming endpoint module parameters. |
604 | if (streaming_interval < 1) | ||
605 | streaming_interval = 1; | ||
606 | if (streaming_interval > 16) | ||
607 | streaming_interval = 16; | ||
608 | if (streaming_mult > 2) | ||
609 | streaming_mult = 2; | ||
610 | if (streaming_maxburst > 15) | ||
611 | streaming_maxburst = 15; | ||
612 | |||
613 | /* | ||
614 | * fill in the FS video streaming specific descriptors from the | ||
615 | * module parameters | ||
616 | */ | 598 | */ |
617 | uvc_fs_streaming_ep.wMaxPacketSize = streaming_maxpacket > 1023 ? | 599 | streaming_interval = clamp(streaming_interval, 1U, 16U); |
618 | 1023 : streaming_maxpacket; | 600 | streaming_maxpacket = clamp(streaming_maxpacket, 1U, 3072U); |
601 | streaming_maxburst = min(streaming_maxburst, 15U); | ||
602 | |||
603 | /* Fill in the FS/HS/SS Video Streaming specific descriptors from the | ||
604 | * module parameters. | ||
605 | * | ||
606 | * NOTE: We assume that the user knows what they are doing and won't | ||
607 | * give parameters that their UDC doesn't support. | ||
608 | */ | ||
609 | if (streaming_maxpacket <= 1024) { | ||
610 | max_packet_mult = 1; | ||
611 | max_packet_size = streaming_maxpacket; | ||
612 | } else if (streaming_maxpacket <= 2048) { | ||
613 | max_packet_mult = 2; | ||
614 | max_packet_size = streaming_maxpacket / 2; | ||
615 | } else { | ||
616 | max_packet_mult = 3; | ||
617 | max_packet_size = streaming_maxpacket / 3; | ||
618 | } | ||
619 | |||
620 | uvc_fs_streaming_ep.wMaxPacketSize = min(streaming_maxpacket, 1023U); | ||
619 | uvc_fs_streaming_ep.bInterval = streaming_interval; | 621 | uvc_fs_streaming_ep.bInterval = streaming_interval; |
620 | 622 | ||
623 | uvc_hs_streaming_ep.wMaxPacketSize = max_packet_size; | ||
624 | uvc_hs_streaming_ep.wMaxPacketSize |= ((max_packet_mult - 1) << 11); | ||
625 | uvc_hs_streaming_ep.bInterval = streaming_interval; | ||
626 | |||
627 | uvc_ss_streaming_ep.wMaxPacketSize = max_packet_size; | ||
628 | uvc_ss_streaming_ep.bInterval = streaming_interval; | ||
629 | uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1; | ||
630 | uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst; | ||
631 | uvc_ss_streaming_comp.wBytesPerInterval = | ||
632 | max_packet_size * max_packet_mult * streaming_maxburst; | ||
633 | |||
621 | /* Allocate endpoints. */ | 634 | /* Allocate endpoints. */ |
622 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_control_ep); | 635 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep); |
623 | if (!ep) { | 636 | if (!ep) { |
624 | INFO(cdev, "Unable to allocate control EP\n"); | 637 | INFO(cdev, "Unable to allocate control EP\n"); |
625 | goto error; | 638 | goto error; |
@@ -627,7 +640,14 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
627 | uvc->control_ep = ep; | 640 | uvc->control_ep = ep; |
628 | ep->driver_data = uvc; | 641 | ep->driver_data = uvc; |
629 | 642 | ||
630 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); | 643 | if (gadget_is_superspeed(c->cdev->gadget)) |
644 | ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep, | ||
645 | &uvc_ss_streaming_comp); | ||
646 | else if (gadget_is_dualspeed(cdev->gadget)) | ||
647 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_hs_streaming_ep); | ||
648 | else | ||
649 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); | ||
650 | |||
631 | if (!ep) { | 651 | if (!ep) { |
632 | INFO(cdev, "Unable to allocate streaming EP\n"); | 652 | INFO(cdev, "Unable to allocate streaming EP\n"); |
633 | goto error; | 653 | goto error; |
@@ -635,6 +655,10 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
635 | uvc->video.ep = ep; | 655 | uvc->video.ep = ep; |
636 | ep->driver_data = uvc; | 656 | ep->driver_data = uvc; |
637 | 657 | ||
658 | uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address; | ||
659 | uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; | ||
660 | uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address; | ||
661 | |||
638 | /* Allocate interface IDs. */ | 662 | /* Allocate interface IDs. */ |
639 | if ((ret = usb_interface_id(c, f)) < 0) | 663 | if ((ret = usb_interface_id(c, f)) < 0) |
640 | goto error; | 664 | goto error; |
@@ -648,37 +672,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
648 | uvc_streaming_intf_alt1.bInterfaceNumber = ret; | 672 | uvc_streaming_intf_alt1.bInterfaceNumber = ret; |
649 | uvc->streaming_intf = ret; | 673 | uvc->streaming_intf = ret; |
650 | 674 | ||
651 | /* sanity check the streaming endpoint module parameters */ | ||
652 | if (streaming_maxpacket > 1024) | ||
653 | streaming_maxpacket = 1024; | ||
654 | /* | ||
655 | * Fill in the HS descriptors from the module parameters for the Video | ||
656 | * Streaming endpoint. | ||
657 | * NOTE: We assume that the user knows what they are doing and won't | ||
658 | * give parameters that their UDC doesn't support. | ||
659 | */ | ||
660 | uvc_hs_streaming_ep.wMaxPacketSize = streaming_maxpacket; | ||
661 | uvc_hs_streaming_ep.wMaxPacketSize |= streaming_mult << 11; | ||
662 | uvc_hs_streaming_ep.bInterval = streaming_interval; | ||
663 | uvc_hs_streaming_ep.bEndpointAddress = | ||
664 | uvc_fs_streaming_ep.bEndpointAddress; | ||
665 | |||
666 | /* | ||
667 | * Fill in the SS descriptors from the module parameters for the Video | ||
668 | * Streaming endpoint. | ||
669 | * NOTE: We assume that the user knows what they are doing and won't | ||
670 | * give parameters that their UDC doesn't support. | ||
671 | */ | ||
672 | uvc_ss_streaming_ep.wMaxPacketSize = streaming_maxpacket; | ||
673 | uvc_ss_streaming_ep.bInterval = streaming_interval; | ||
674 | uvc_ss_streaming_comp.bmAttributes = streaming_mult; | ||
675 | uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst; | ||
676 | uvc_ss_streaming_comp.wBytesPerInterval = | ||
677 | streaming_maxpacket * (streaming_mult + 1) * | ||
678 | (streaming_maxburst + 1); | ||
679 | uvc_ss_streaming_ep.bEndpointAddress = | ||
680 | uvc_fs_streaming_ep.bEndpointAddress; | ||
681 | |||
682 | /* Copy descriptors */ | 675 | /* Copy descriptors */ |
683 | f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); | 676 | f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); |
684 | if (gadget_is_dualspeed(cdev->gadget)) | 677 | if (gadget_is_dualspeed(cdev->gadget)) |
@@ -775,23 +768,23 @@ uvc_bind_config(struct usb_configuration *c, | |||
775 | 768 | ||
776 | /* Validate the descriptors. */ | 769 | /* Validate the descriptors. */ |
777 | if (fs_control == NULL || fs_control[0] == NULL || | 770 | if (fs_control == NULL || fs_control[0] == NULL || |
778 | fs_control[0]->bDescriptorSubType != UVC_VC_HEADER) | 771 | fs_control[0]->bDescriptorSubType != UVC_VC_HEADER) |
779 | goto error; | 772 | goto error; |
780 | 773 | ||
781 | if (ss_control == NULL || ss_control[0] == NULL || | 774 | if (ss_control == NULL || ss_control[0] == NULL || |
782 | ss_control[0]->bDescriptorSubType != UVC_VC_HEADER) | 775 | ss_control[0]->bDescriptorSubType != UVC_VC_HEADER) |
783 | goto error; | 776 | goto error; |
784 | 777 | ||
785 | if (fs_streaming == NULL || fs_streaming[0] == NULL || | 778 | if (fs_streaming == NULL || fs_streaming[0] == NULL || |
786 | fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) | 779 | fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) |
787 | goto error; | 780 | goto error; |
788 | 781 | ||
789 | if (hs_streaming == NULL || hs_streaming[0] == NULL || | 782 | if (hs_streaming == NULL || hs_streaming[0] == NULL || |
790 | hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) | 783 | hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) |
791 | goto error; | 784 | goto error; |
792 | 785 | ||
793 | if (ss_streaming == NULL || ss_streaming[0] == NULL || | 786 | if (ss_streaming == NULL || ss_streaming[0] == NULL || |
794 | ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) | 787 | ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) |
795 | goto error; | 788 | goto error; |
796 | 789 | ||
797 | uvc->desc.fs_control = fs_control; | 790 | uvc->desc.fs_control = fs_control; |
@@ -800,13 +793,16 @@ uvc_bind_config(struct usb_configuration *c, | |||
800 | uvc->desc.hs_streaming = hs_streaming; | 793 | uvc->desc.hs_streaming = hs_streaming; |
801 | uvc->desc.ss_streaming = ss_streaming; | 794 | uvc->desc.ss_streaming = ss_streaming; |
802 | 795 | ||
803 | /* Allocate string descriptor numbers. */ | 796 | /* String descriptors are global, we only need to allocate string IDs |
804 | if (uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id == 0) { | 797 | * for the first UVC function. UVC functions beyond the first (if any) |
798 | * will reuse the same IDs. | ||
799 | */ | ||
800 | if (uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id == 0) { | ||
805 | ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings); | 801 | ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings); |
806 | if (ret) | 802 | if (ret) |
807 | goto error; | 803 | goto error; |
808 | uvc_iad.iFunction = | 804 | uvc_iad.iFunction = |
809 | uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id; | 805 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; |
810 | uvc_control_intf.iInterface = | 806 | uvc_control_intf.iInterface = |
811 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; | 807 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; |
812 | ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id; | 808 | ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id; |
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h index c3d258d30188..ec52752f7326 100644 --- a/drivers/usb/gadget/f_uvc.h +++ b/drivers/usb/gadget/f_uvc.h | |||
@@ -16,12 +16,12 @@ | |||
16 | #include <linux/usb/composite.h> | 16 | #include <linux/usb/composite.h> |
17 | #include <linux/usb/video.h> | 17 | #include <linux/usb/video.h> |
18 | 18 | ||
19 | extern int uvc_bind_config(struct usb_configuration *c, | 19 | int uvc_bind_config(struct usb_configuration *c, |
20 | const struct uvc_descriptor_header * const *fs_control, | 20 | const struct uvc_descriptor_header * const *fs_control, |
21 | const struct uvc_descriptor_header * const *hs_control, | 21 | const struct uvc_descriptor_header * const *hs_control, |
22 | const struct uvc_descriptor_header * const *fs_streaming, | 22 | const struct uvc_descriptor_header * const *fs_streaming, |
23 | const struct uvc_descriptor_header * const *hs_streaming, | 23 | const struct uvc_descriptor_header * const *hs_streaming, |
24 | const struct uvc_descriptor_header * const *ss_streaming); | 24 | const struct uvc_descriptor_header * const *ss_streaming); |
25 | 25 | ||
26 | #endif /* _F_UVC_H_ */ | 26 | #endif /* _F_UVC_H_ */ |
27 | 27 | ||
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index 034477ce77c6..9a7ee3347e4d 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -2296,7 +2296,6 @@ static int fsl_qe_start(struct usb_gadget *gadget, | |||
2296 | driver->driver.bus = NULL; | 2296 | driver->driver.bus = NULL; |
2297 | /* hook up the driver */ | 2297 | /* hook up the driver */ |
2298 | udc->driver = driver; | 2298 | udc->driver = driver; |
2299 | udc->gadget.dev.driver = &driver->driver; | ||
2300 | udc->gadget.speed = driver->max_speed; | 2299 | udc->gadget.speed = driver->max_speed; |
2301 | 2300 | ||
2302 | /* Enable IRQ reg and Set usbcmd reg EN bit */ | 2301 | /* Enable IRQ reg and Set usbcmd reg EN bit */ |
@@ -2338,7 +2337,6 @@ static int fsl_qe_stop(struct usb_gadget *gadget, | |||
2338 | nuke(loop_ep, -ESHUTDOWN); | 2337 | nuke(loop_ep, -ESHUTDOWN); |
2339 | spin_unlock_irqrestore(&udc->lock, flags); | 2338 | spin_unlock_irqrestore(&udc->lock, flags); |
2340 | 2339 | ||
2341 | udc->gadget.dev.driver = NULL; | ||
2342 | udc->driver = NULL; | 2340 | udc->driver = NULL; |
2343 | 2341 | ||
2344 | dev_info(udc->dev, "unregistered gadget driver '%s'\r\n", | 2342 | dev_info(udc->dev, "unregistered gadget driver '%s'\r\n", |
@@ -2523,12 +2521,6 @@ static int qe_udc_probe(struct platform_device *ofdev) | |||
2523 | 2521 | ||
2524 | /* name: Identifies the controller hardware type. */ | 2522 | /* name: Identifies the controller hardware type. */ |
2525 | udc->gadget.name = driver_name; | 2523 | udc->gadget.name = driver_name; |
2526 | |||
2527 | device_initialize(&udc->gadget.dev); | ||
2528 | |||
2529 | dev_set_name(&udc->gadget.dev, "gadget"); | ||
2530 | |||
2531 | udc->gadget.dev.release = qe_udc_release; | ||
2532 | udc->gadget.dev.parent = &ofdev->dev; | 2524 | udc->gadget.dev.parent = &ofdev->dev; |
2533 | 2525 | ||
2534 | /* initialize qe_ep struct */ | 2526 | /* initialize qe_ep struct */ |
@@ -2592,22 +2584,17 @@ static int qe_udc_probe(struct platform_device *ofdev) | |||
2592 | goto err5; | 2584 | goto err5; |
2593 | } | 2585 | } |
2594 | 2586 | ||
2595 | ret = device_add(&udc->gadget.dev); | 2587 | ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget, |
2588 | qe_udc_release); | ||
2596 | if (ret) | 2589 | if (ret) |
2597 | goto err6; | 2590 | goto err6; |
2598 | 2591 | ||
2599 | ret = usb_add_gadget_udc(&ofdev->dev, &udc->gadget); | ||
2600 | if (ret) | ||
2601 | goto err7; | ||
2602 | |||
2603 | dev_set_drvdata(&ofdev->dev, udc); | 2592 | dev_set_drvdata(&ofdev->dev, udc); |
2604 | dev_info(udc->dev, | 2593 | dev_info(udc->dev, |
2605 | "%s USB controller initialized as device\n", | 2594 | "%s USB controller initialized as device\n", |
2606 | (udc->soc_type == PORT_QE) ? "QE" : "CPM"); | 2595 | (udc->soc_type == PORT_QE) ? "QE" : "CPM"); |
2607 | return 0; | 2596 | return 0; |
2608 | 2597 | ||
2609 | err7: | ||
2610 | device_unregister(&udc->gadget.dev); | ||
2611 | err6: | 2598 | err6: |
2612 | free_irq(udc->usb_irq, udc); | 2599 | free_irq(udc->usb_irq, udc); |
2613 | err5: | 2600 | err5: |
@@ -2702,7 +2689,6 @@ static int qe_udc_remove(struct platform_device *ofdev) | |||
2702 | 2689 | ||
2703 | iounmap(udc->usb_regs); | 2690 | iounmap(udc->usb_regs); |
2704 | 2691 | ||
2705 | device_unregister(&udc->gadget.dev); | ||
2706 | /* wait for release() of gadget.dev to free udc */ | 2692 | /* wait for release() of gadget.dev to free udc */ |
2707 | wait_for_completion(&done); | 2693 | wait_for_completion(&done); |
2708 | 2694 | ||
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 04d5fef1440c..7c2a101d19ac 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -185,20 +185,7 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status) | |||
185 | dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma); | 185 | dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma); |
186 | } | 186 | } |
187 | 187 | ||
188 | if (req->mapped) { | 188 | usb_gadget_unmap_request(&ep->udc->gadget, &req->req, ep_is_in(ep)); |
189 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
190 | req->req.dma, req->req.length, | ||
191 | ep_is_in(ep) | ||
192 | ? DMA_TO_DEVICE | ||
193 | : DMA_FROM_DEVICE); | ||
194 | req->req.dma = DMA_ADDR_INVALID; | ||
195 | req->mapped = 0; | ||
196 | } else | ||
197 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, | ||
198 | req->req.dma, req->req.length, | ||
199 | ep_is_in(ep) | ||
200 | ? DMA_TO_DEVICE | ||
201 | : DMA_FROM_DEVICE); | ||
202 | 189 | ||
203 | if (status && (status != -ESHUTDOWN)) | 190 | if (status && (status != -ESHUTDOWN)) |
204 | VDBG("complete %s req %p stat %d len %u/%u", | 191 | VDBG("complete %s req %p stat %d len %u/%u", |
@@ -888,6 +875,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
888 | struct fsl_req *req = container_of(_req, struct fsl_req, req); | 875 | struct fsl_req *req = container_of(_req, struct fsl_req, req); |
889 | struct fsl_udc *udc; | 876 | struct fsl_udc *udc; |
890 | unsigned long flags; | 877 | unsigned long flags; |
878 | int ret; | ||
891 | 879 | ||
892 | /* catch various bogus parameters */ | 880 | /* catch various bogus parameters */ |
893 | if (!_req || !req->req.complete || !req->req.buf | 881 | if (!_req || !req->req.complete || !req->req.buf |
@@ -910,22 +898,9 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
910 | 898 | ||
911 | req->ep = ep; | 899 | req->ep = ep; |
912 | 900 | ||
913 | /* map virtual address to hardware */ | 901 | ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep)); |
914 | if (req->req.dma == DMA_ADDR_INVALID) { | 902 | if (ret) |
915 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | 903 | return ret; |
916 | req->req.buf, | ||
917 | req->req.length, ep_is_in(ep) | ||
918 | ? DMA_TO_DEVICE | ||
919 | : DMA_FROM_DEVICE); | ||
920 | req->mapped = 1; | ||
921 | } else { | ||
922 | dma_sync_single_for_device(ep->udc->gadget.dev.parent, | ||
923 | req->req.dma, req->req.length, | ||
924 | ep_is_in(ep) | ||
925 | ? DMA_TO_DEVICE | ||
926 | : DMA_FROM_DEVICE); | ||
927 | req->mapped = 0; | ||
928 | } | ||
929 | 904 | ||
930 | req->req.status = -EINPROGRESS; | 905 | req->req.status = -EINPROGRESS; |
931 | req->req.actual = 0; | 906 | req->req.actual = 0; |
@@ -1290,6 +1265,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction) | |||
1290 | { | 1265 | { |
1291 | struct fsl_req *req = udc->status_req; | 1266 | struct fsl_req *req = udc->status_req; |
1292 | struct fsl_ep *ep; | 1267 | struct fsl_ep *ep; |
1268 | int ret; | ||
1293 | 1269 | ||
1294 | if (direction == EP_DIR_IN) | 1270 | if (direction == EP_DIR_IN) |
1295 | udc->ep0_dir = USB_DIR_IN; | 1271 | udc->ep0_dir = USB_DIR_IN; |
@@ -1307,10 +1283,9 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction) | |||
1307 | req->req.complete = NULL; | 1283 | req->req.complete = NULL; |
1308 | req->dtd_count = 0; | 1284 | req->dtd_count = 0; |
1309 | 1285 | ||
1310 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | 1286 | ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep)); |
1311 | req->req.buf, req->req.length, | 1287 | if (ret) |
1312 | ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | 1288 | return ret; |
1313 | req->mapped = 1; | ||
1314 | 1289 | ||
1315 | if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0) | 1290 | if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0) |
1316 | fsl_queue_td(ep, req); | 1291 | fsl_queue_td(ep, req); |
@@ -1353,6 +1328,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value, | |||
1353 | u16 tmp = 0; /* Status, cpu endian */ | 1328 | u16 tmp = 0; /* Status, cpu endian */ |
1354 | struct fsl_req *req; | 1329 | struct fsl_req *req; |
1355 | struct fsl_ep *ep; | 1330 | struct fsl_ep *ep; |
1331 | int ret; | ||
1356 | 1332 | ||
1357 | ep = &udc->eps[0]; | 1333 | ep = &udc->eps[0]; |
1358 | 1334 | ||
@@ -1390,10 +1366,9 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value, | |||
1390 | req->req.complete = NULL; | 1366 | req->req.complete = NULL; |
1391 | req->dtd_count = 0; | 1367 | req->dtd_count = 0; |
1392 | 1368 | ||
1393 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | 1369 | ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep)); |
1394 | req->req.buf, req->req.length, | 1370 | if (ret) |
1395 | ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | 1371 | goto stall; |
1396 | req->mapped = 1; | ||
1397 | 1372 | ||
1398 | /* prime the data phase */ | 1373 | /* prime the data phase */ |
1399 | if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0)) | 1374 | if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0)) |
@@ -1964,7 +1939,6 @@ static int fsl_udc_start(struct usb_gadget *g, | |||
1964 | driver->driver.bus = NULL; | 1939 | driver->driver.bus = NULL; |
1965 | /* hook up the driver */ | 1940 | /* hook up the driver */ |
1966 | udc_controller->driver = driver; | 1941 | udc_controller->driver = driver; |
1967 | udc_controller->gadget.dev.driver = &driver->driver; | ||
1968 | spin_unlock_irqrestore(&udc_controller->lock, flags); | 1942 | spin_unlock_irqrestore(&udc_controller->lock, flags); |
1969 | 1943 | ||
1970 | if (!IS_ERR_OR_NULL(udc_controller->transceiver)) { | 1944 | if (!IS_ERR_OR_NULL(udc_controller->transceiver)) { |
@@ -1980,7 +1954,6 @@ static int fsl_udc_start(struct usb_gadget *g, | |||
1980 | if (retval < 0) { | 1954 | if (retval < 0) { |
1981 | ERR("can't bind to transceiver\n"); | 1955 | ERR("can't bind to transceiver\n"); |
1982 | driver->unbind(&udc_controller->gadget); | 1956 | driver->unbind(&udc_controller->gadget); |
1983 | udc_controller->gadget.dev.driver = 0; | ||
1984 | udc_controller->driver = 0; | 1957 | udc_controller->driver = 0; |
1985 | return retval; | 1958 | return retval; |
1986 | } | 1959 | } |
@@ -2023,7 +1996,6 @@ static int fsl_udc_stop(struct usb_gadget *g, | |||
2023 | nuke(loop_ep, -ESHUTDOWN); | 1996 | nuke(loop_ep, -ESHUTDOWN); |
2024 | spin_unlock_irqrestore(&udc_controller->lock, flags); | 1997 | spin_unlock_irqrestore(&udc_controller->lock, flags); |
2025 | 1998 | ||
2026 | udc_controller->gadget.dev.driver = NULL; | ||
2027 | udc_controller->driver = NULL; | 1999 | udc_controller->driver = NULL; |
2028 | 2000 | ||
2029 | return 0; | 2001 | return 0; |
@@ -2521,12 +2493,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2521 | 2493 | ||
2522 | /* Setup gadget.dev and register with kernel */ | 2494 | /* Setup gadget.dev and register with kernel */ |
2523 | dev_set_name(&udc_controller->gadget.dev, "gadget"); | 2495 | dev_set_name(&udc_controller->gadget.dev, "gadget"); |
2524 | udc_controller->gadget.dev.release = fsl_udc_release; | ||
2525 | udc_controller->gadget.dev.parent = &pdev->dev; | ||
2526 | udc_controller->gadget.dev.of_node = pdev->dev.of_node; | 2496 | udc_controller->gadget.dev.of_node = pdev->dev.of_node; |
2527 | ret = device_register(&udc_controller->gadget.dev); | ||
2528 | if (ret < 0) | ||
2529 | goto err_free_irq; | ||
2530 | 2497 | ||
2531 | if (!IS_ERR_OR_NULL(udc_controller->transceiver)) | 2498 | if (!IS_ERR_OR_NULL(udc_controller->transceiver)) |
2532 | udc_controller->gadget.is_otg = 1; | 2499 | udc_controller->gadget.is_otg = 1; |
@@ -2559,10 +2526,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2559 | DTD_ALIGNMENT, UDC_DMA_BOUNDARY); | 2526 | DTD_ALIGNMENT, UDC_DMA_BOUNDARY); |
2560 | if (udc_controller->td_pool == NULL) { | 2527 | if (udc_controller->td_pool == NULL) { |
2561 | ret = -ENOMEM; | 2528 | ret = -ENOMEM; |
2562 | goto err_unregister; | 2529 | goto err_free_irq; |
2563 | } | 2530 | } |
2564 | 2531 | ||
2565 | ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget); | 2532 | ret = usb_add_gadget_udc_release(&pdev->dev, &udc_controller->gadget, |
2533 | fsl_udc_release); | ||
2566 | if (ret) | 2534 | if (ret) |
2567 | goto err_del_udc; | 2535 | goto err_del_udc; |
2568 | 2536 | ||
@@ -2571,8 +2539,6 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2571 | 2539 | ||
2572 | err_del_udc: | 2540 | err_del_udc: |
2573 | dma_pool_destroy(udc_controller->td_pool); | 2541 | dma_pool_destroy(udc_controller->td_pool); |
2574 | err_unregister: | ||
2575 | device_unregister(&udc_controller->gadget.dev); | ||
2576 | err_free_irq: | 2542 | err_free_irq: |
2577 | free_irq(udc_controller->irq, udc_controller); | 2543 | free_irq(udc_controller->irq, udc_controller); |
2578 | err_iounmap: | 2544 | err_iounmap: |
@@ -2622,7 +2588,6 @@ static int __exit fsl_udc_remove(struct platform_device *pdev) | |||
2622 | if (pdata->operating_mode == FSL_USB2_DR_DEVICE) | 2588 | if (pdata->operating_mode == FSL_USB2_DR_DEVICE) |
2623 | release_mem_region(res->start, resource_size(res)); | 2589 | release_mem_region(res->start, resource_size(res)); |
2624 | 2590 | ||
2625 | device_unregister(&udc_controller->gadget.dev); | ||
2626 | /* free udc --wait for the release() finished */ | 2591 | /* free udc --wait for the release() finished */ |
2627 | wait_for_completion(&done); | 2592 | wait_for_completion(&done); |
2628 | 2593 | ||
@@ -2747,21 +2712,7 @@ static struct platform_driver udc_driver = { | |||
2747 | }, | 2712 | }, |
2748 | }; | 2713 | }; |
2749 | 2714 | ||
2750 | static int __init udc_init(void) | 2715 | module_platform_driver_probe(udc_driver, fsl_udc_probe); |
2751 | { | ||
2752 | printk(KERN_INFO "%s (%s)\n", driver_desc, DRIVER_VERSION); | ||
2753 | return platform_driver_probe(&udc_driver, fsl_udc_probe); | ||
2754 | } | ||
2755 | |||
2756 | module_init(udc_init); | ||
2757 | |||
2758 | static void __exit udc_exit(void) | ||
2759 | { | ||
2760 | platform_driver_unregister(&udc_driver); | ||
2761 | printk(KERN_WARNING "%s unregistered\n", driver_desc); | ||
2762 | } | ||
2763 | |||
2764 | module_exit(udc_exit); | ||
2765 | 2716 | ||
2766 | MODULE_DESCRIPTION(DRIVER_DESC); | 2717 | MODULE_DESCRIPTION(DRIVER_DESC); |
2767 | MODULE_AUTHOR(DRIVER_AUTHOR); | 2718 | MODULE_AUTHOR(DRIVER_AUTHOR); |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index 066cb89376de..cec8871b77f9 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -394,7 +394,7 @@ static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep) | |||
394 | 394 | ||
395 | if (reg & FUSB300_EPSET0_STL) { | 395 | if (reg & FUSB300_EPSET0_STL) { |
396 | printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep); | 396 | printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep); |
397 | reg &= ~FUSB300_EPSET0_STL; | 397 | reg |= FUSB300_EPSET0_STL_CLR; |
398 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); | 398 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); |
399 | } | 399 | } |
400 | } | 400 | } |
@@ -930,33 +930,33 @@ static void fusb300_wait_idma_finished(struct fusb300_ep *ep) | |||
930 | 930 | ||
931 | fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0, | 931 | fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0, |
932 | FUSB300_IGR0_EPn_PRD_INT(ep->epnum)); | 932 | FUSB300_IGR0_EPn_PRD_INT(ep->epnum)); |
933 | return; | ||
934 | |||
933 | IDMA_RESET: | 935 | IDMA_RESET: |
934 | fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0, | 936 | reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGER0); |
935 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); | 937 | reg &= ~FUSB300_IGER0_EEPn_PRD_INT(ep->epnum); |
938 | iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_IGER0); | ||
936 | } | 939 | } |
937 | 940 | ||
938 | static void fusb300_set_idma(struct fusb300_ep *ep, | 941 | static void fusb300_set_idma(struct fusb300_ep *ep, |
939 | struct fusb300_request *req) | 942 | struct fusb300_request *req) |
940 | { | 943 | { |
941 | dma_addr_t d; | 944 | int ret; |
942 | |||
943 | d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE); | ||
944 | 945 | ||
945 | if (dma_mapping_error(NULL, d)) { | 946 | ret = usb_gadget_map_request(&ep->fusb300->gadget, |
946 | printk(KERN_DEBUG "dma_mapping_error\n"); | 947 | &req->req, DMA_TO_DEVICE); |
948 | if (ret) | ||
947 | return; | 949 | return; |
948 | } | ||
949 | |||
950 | dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE); | ||
951 | 950 | ||
952 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, | 951 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, |
953 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); | 952 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); |
954 | 953 | ||
955 | fusb300_fill_idma_prdtbl(ep, d, req->req.length); | 954 | fusb300_fill_idma_prdtbl(ep, req->req.dma, req->req.length); |
956 | /* check idma is done */ | 955 | /* check idma is done */ |
957 | fusb300_wait_idma_finished(ep); | 956 | fusb300_wait_idma_finished(ep); |
958 | 957 | ||
959 | dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE); | 958 | usb_gadget_unmap_request(&ep->fusb300->gadget, |
959 | &req->req, DMA_TO_DEVICE); | ||
960 | } | 960 | } |
961 | 961 | ||
962 | static void in_ep_fifo_handler(struct fusb300_ep *ep) | 962 | static void in_ep_fifo_handler(struct fusb300_ep *ep) |
@@ -1316,7 +1316,6 @@ static int fusb300_udc_start(struct usb_gadget *g, | |||
1316 | /* hook up the driver */ | 1316 | /* hook up the driver */ |
1317 | driver->driver.bus = NULL; | 1317 | driver->driver.bus = NULL; |
1318 | fusb300->driver = driver; | 1318 | fusb300->driver = driver; |
1319 | fusb300->gadget.dev.driver = &driver->driver; | ||
1320 | 1319 | ||
1321 | return 0; | 1320 | return 0; |
1322 | } | 1321 | } |
@@ -1327,7 +1326,6 @@ static int fusb300_udc_stop(struct usb_gadget *g, | |||
1327 | struct fusb300 *fusb300 = to_fusb300(g); | 1326 | struct fusb300 *fusb300 = to_fusb300(g); |
1328 | 1327 | ||
1329 | driver->unbind(&fusb300->gadget); | 1328 | driver->unbind(&fusb300->gadget); |
1330 | fusb300->gadget.dev.driver = NULL; | ||
1331 | 1329 | ||
1332 | init_controller(fusb300); | 1330 | init_controller(fusb300); |
1333 | fusb300->driver = NULL; | 1331 | fusb300->driver = NULL; |
@@ -1422,14 +1420,7 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1422 | 1420 | ||
1423 | fusb300->gadget.ops = &fusb300_gadget_ops; | 1421 | fusb300->gadget.ops = &fusb300_gadget_ops; |
1424 | 1422 | ||
1425 | device_initialize(&fusb300->gadget.dev); | ||
1426 | |||
1427 | dev_set_name(&fusb300->gadget.dev, "gadget"); | ||
1428 | |||
1429 | fusb300->gadget.max_speed = USB_SPEED_HIGH; | 1423 | fusb300->gadget.max_speed = USB_SPEED_HIGH; |
1430 | fusb300->gadget.dev.parent = &pdev->dev; | ||
1431 | fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1432 | fusb300->gadget.dev.release = pdev->dev.release; | ||
1433 | fusb300->gadget.name = udc_name; | 1424 | fusb300->gadget.name = udc_name; |
1434 | fusb300->reg = reg; | 1425 | fusb300->reg = reg; |
1435 | 1426 | ||
@@ -1478,19 +1469,10 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1478 | if (ret) | 1469 | if (ret) |
1479 | goto err_add_udc; | 1470 | goto err_add_udc; |
1480 | 1471 | ||
1481 | ret = device_add(&fusb300->gadget.dev); | ||
1482 | if (ret) { | ||
1483 | pr_err("device_add error (%d)\n", ret); | ||
1484 | goto err_add_device; | ||
1485 | } | ||
1486 | |||
1487 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | 1472 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); |
1488 | 1473 | ||
1489 | return 0; | 1474 | return 0; |
1490 | 1475 | ||
1491 | err_add_device: | ||
1492 | usb_del_gadget_udc(&fusb300->gadget); | ||
1493 | |||
1494 | err_add_udc: | 1476 | err_add_udc: |
1495 | fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); | 1477 | fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); |
1496 | 1478 | ||
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h index 6ba444ae8dd5..ae811d8d38b4 100644 --- a/drivers/usb/gadget/fusb300_udc.h +++ b/drivers/usb/gadget/fusb300_udc.h | |||
@@ -111,8 +111,8 @@ | |||
111 | /* | 111 | /* |
112 | * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 ) | 112 | * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 ) |
113 | * */ | 113 | * */ |
114 | #define FUSB300_EPSET0_STL_CLR (1 << 3) | ||
114 | #define FUSB300_EPSET0_CLRSEQNUM (1 << 2) | 115 | #define FUSB300_EPSET0_CLRSEQNUM (1 << 2) |
115 | #define FUSB300_EPSET0_EPn_TX0BYTE (1 << 1) | ||
116 | #define FUSB300_EPSET0_STL (1 << 0) | 116 | #define FUSB300_EPSET0_STL (1 << 0) |
117 | 117 | ||
118 | /* | 118 | /* |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 3b343b23e4b0..787a78e92aa2 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #define pr_fmt(fmt) "g_ffs: " fmt | 13 | #define pr_fmt(fmt) "g_ffs: " fmt |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | |||
17 | /* | 16 | /* |
18 | * kbuild is not very cooperative with respect to linking separately | 17 | * kbuild is not very cooperative with respect to linking separately |
19 | * compiled library objects into one module. So for now we won't use | 18 | * compiled library objects into one module. So for now we won't use |
@@ -38,13 +37,16 @@ | |||
38 | # include "u_ether.c" | 37 | # include "u_ether.c" |
39 | 38 | ||
40 | static u8 gfs_hostaddr[ETH_ALEN]; | 39 | static u8 gfs_hostaddr[ETH_ALEN]; |
40 | static struct eth_dev *the_dev; | ||
41 | # ifdef CONFIG_USB_FUNCTIONFS_ETH | 41 | # ifdef CONFIG_USB_FUNCTIONFS_ETH |
42 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 42 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
43 | struct eth_dev *dev); | ||
43 | # endif | 44 | # endif |
44 | #else | 45 | #else |
45 | # define gether_cleanup() do { } while (0) | 46 | # define the_dev NULL |
46 | # define gether_setup(gadget, hostaddr) ((int)0) | 47 | # define gether_cleanup(dev) do { } while (0) |
47 | # define gfs_hostaddr NULL | 48 | # define gfs_hostaddr NULL |
49 | struct eth_dev; | ||
48 | #endif | 50 | #endif |
49 | 51 | ||
50 | #include "f_fs.c" | 52 | #include "f_fs.c" |
@@ -137,7 +139,8 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { | |||
137 | 139 | ||
138 | struct gfs_configuration { | 140 | struct gfs_configuration { |
139 | struct usb_configuration c; | 141 | struct usb_configuration c; |
140 | int (*eth)(struct usb_configuration *c, u8 *ethaddr); | 142 | int (*eth)(struct usb_configuration *c, u8 *ethaddr, |
143 | struct eth_dev *dev); | ||
141 | } gfs_configurations[] = { | 144 | } gfs_configurations[] = { |
142 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 145 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
143 | { | 146 | { |
@@ -346,10 +349,13 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
346 | 349 | ||
347 | if (missing_funcs) | 350 | if (missing_funcs) |
348 | return -ENODEV; | 351 | return -ENODEV; |
349 | 352 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | |
350 | ret = gether_setup(cdev->gadget, gfs_hostaddr); | 353 | the_dev = gether_setup(cdev->gadget, gfs_hostaddr); |
351 | if (unlikely(ret < 0)) | 354 | #endif |
355 | if (IS_ERR(the_dev)) { | ||
356 | ret = PTR_ERR(the_dev); | ||
352 | goto error_quick; | 357 | goto error_quick; |
358 | } | ||
353 | gfs_ether_setup = true; | 359 | gfs_ether_setup = true; |
354 | 360 | ||
355 | ret = usb_string_ids_tab(cdev, gfs_strings); | 361 | ret = usb_string_ids_tab(cdev, gfs_strings); |
@@ -386,7 +392,7 @@ error_unbind: | |||
386 | for (i = 0; i < func_num; i++) | 392 | for (i = 0; i < func_num; i++) |
387 | functionfs_unbind(ffs_tab[i].ffs_data); | 393 | functionfs_unbind(ffs_tab[i].ffs_data); |
388 | error: | 394 | error: |
389 | gether_cleanup(); | 395 | gether_cleanup(the_dev); |
390 | error_quick: | 396 | error_quick: |
391 | gfs_ether_setup = false; | 397 | gfs_ether_setup = false; |
392 | return ret; | 398 | return ret; |
@@ -410,7 +416,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev) | |||
410 | * do...? | 416 | * do...? |
411 | */ | 417 | */ |
412 | if (gfs_ether_setup) | 418 | if (gfs_ether_setup) |
413 | gether_cleanup(); | 419 | gether_cleanup(the_dev); |
414 | gfs_ether_setup = false; | 420 | gfs_ether_setup = false; |
415 | 421 | ||
416 | for (i = func_num; i--; ) | 422 | for (i = func_num; i--; ) |
@@ -440,7 +446,7 @@ static int gfs_do_config(struct usb_configuration *c) | |||
440 | } | 446 | } |
441 | 447 | ||
442 | if (gc->eth) { | 448 | if (gc->eth) { |
443 | ret = gc->eth(c, gfs_hostaddr); | 449 | ret = gc->eth(c, gfs_hostaddr, the_dev); |
444 | if (unlikely(ret < 0)) | 450 | if (unlikely(ret < 0)) |
445 | return ret; | 451 | return ret; |
446 | } | 452 | } |
@@ -469,11 +475,12 @@ static int gfs_do_config(struct usb_configuration *c) | |||
469 | 475 | ||
470 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 476 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
471 | 477 | ||
472 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | 478 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
479 | struct eth_dev *dev) | ||
473 | { | 480 | { |
474 | return can_support_ecm(c->cdev->gadget) | 481 | return can_support_ecm(c->cdev->gadget) |
475 | ? ecm_bind_config(c, ethaddr) | 482 | ? ecm_bind_config(c, ethaddr, dev) |
476 | : geth_bind_config(c, ethaddr); | 483 | : geth_bind_config(c, ethaddr, dev); |
477 | } | 484 | } |
478 | 485 | ||
479 | #endif | 486 | #endif |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index 85742d4c67df..991aba390d9d 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -51,8 +51,6 @@ | |||
51 | #define DRIVER_DESC "TC86C001 USB Device Controller" | 51 | #define DRIVER_DESC "TC86C001 USB Device Controller" |
52 | #define DRIVER_VERSION "30-Oct 2003" | 52 | #define DRIVER_VERSION "30-Oct 2003" |
53 | 53 | ||
54 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
55 | |||
56 | static const char driver_name [] = "goku_udc"; | 54 | static const char driver_name [] = "goku_udc"; |
57 | static const char driver_desc [] = DRIVER_DESC; | 55 | static const char driver_desc [] = DRIVER_DESC; |
58 | 56 | ||
@@ -275,7 +273,6 @@ goku_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | |||
275 | if (!req) | 273 | if (!req) |
276 | return NULL; | 274 | return NULL; |
277 | 275 | ||
278 | req->req.dma = DMA_ADDR_INVALID; | ||
279 | INIT_LIST_HEAD(&req->queue); | 276 | INIT_LIST_HEAD(&req->queue); |
280 | return &req->req; | 277 | return &req->req; |
281 | } | 278 | } |
@@ -1354,7 +1351,6 @@ static int goku_udc_start(struct usb_gadget *g, | |||
1354 | /* hook up the driver */ | 1351 | /* hook up the driver */ |
1355 | driver->driver.bus = NULL; | 1352 | driver->driver.bus = NULL; |
1356 | dev->driver = driver; | 1353 | dev->driver = driver; |
1357 | dev->gadget.dev.driver = &driver->driver; | ||
1358 | 1354 | ||
1359 | /* | 1355 | /* |
1360 | * then enable host detection and ep0; and we're ready | 1356 | * then enable host detection and ep0; and we're ready |
@@ -1394,7 +1390,6 @@ static int goku_udc_stop(struct usb_gadget *g, | |||
1394 | dev->driver = NULL; | 1390 | dev->driver = NULL; |
1395 | stop_activity(dev, driver); | 1391 | stop_activity(dev, driver); |
1396 | spin_unlock_irqrestore(&dev->lock, flags); | 1392 | spin_unlock_irqrestore(&dev->lock, flags); |
1397 | dev->gadget.dev.driver = NULL; | ||
1398 | 1393 | ||
1399 | return 0; | 1394 | return 0; |
1400 | } | 1395 | } |
@@ -1716,8 +1711,6 @@ static void goku_remove(struct pci_dev *pdev) | |||
1716 | pci_resource_len (pdev, 0)); | 1711 | pci_resource_len (pdev, 0)); |
1717 | if (dev->enabled) | 1712 | if (dev->enabled) |
1718 | pci_disable_device(pdev); | 1713 | pci_disable_device(pdev); |
1719 | if (dev->registered) | ||
1720 | device_unregister(&dev->gadget.dev); | ||
1721 | 1714 | ||
1722 | pci_set_drvdata(pdev, NULL); | 1715 | pci_set_drvdata(pdev, NULL); |
1723 | dev->regs = NULL; | 1716 | dev->regs = NULL; |
@@ -1756,10 +1749,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1756 | dev->gadget.max_speed = USB_SPEED_FULL; | 1749 | dev->gadget.max_speed = USB_SPEED_FULL; |
1757 | 1750 | ||
1758 | /* the "gadget" abstracts/virtualizes the controller */ | 1751 | /* the "gadget" abstracts/virtualizes the controller */ |
1759 | dev_set_name(&dev->gadget.dev, "gadget"); | ||
1760 | dev->gadget.dev.parent = &pdev->dev; | ||
1761 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1762 | dev->gadget.dev.release = gadget_release; | ||
1763 | dev->gadget.name = driver_name; | 1752 | dev->gadget.name = driver_name; |
1764 | 1753 | ||
1765 | /* now all the pci goodies ... */ | 1754 | /* now all the pci goodies ... */ |
@@ -1810,13 +1799,8 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1810 | create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); | 1799 | create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); |
1811 | #endif | 1800 | #endif |
1812 | 1801 | ||
1813 | retval = device_register(&dev->gadget.dev); | 1802 | retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, |
1814 | if (retval) { | 1803 | gadget_release); |
1815 | put_device(&dev->gadget.dev); | ||
1816 | goto err; | ||
1817 | } | ||
1818 | dev->registered = 1; | ||
1819 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | ||
1820 | if (retval) | 1804 | if (retval) |
1821 | goto err; | 1805 | goto err; |
1822 | 1806 | ||
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h index b4470d2b1d86..86d2adafe149 100644 --- a/drivers/usb/gadget/goku_udc.h +++ b/drivers/usb/gadget/goku_udc.h | |||
@@ -250,8 +250,7 @@ struct goku_udc { | |||
250 | got_region:1, | 250 | got_region:1, |
251 | req_config:1, | 251 | req_config:1, |
252 | configured:1, | 252 | configured:1, |
253 | enabled:1, | 253 | enabled:1; |
254 | registered:1; | ||
255 | 254 | ||
256 | /* pci state used to access those endpoints */ | 255 | /* pci state used to access those endpoints */ |
257 | struct pci_dev *pdev; | 256 | struct pci_dev *pdev; |
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c index 5bd930d779b9..b5cebd6b0d7a 100644 --- a/drivers/usb/gadget/imx_udc.c +++ b/drivers/usb/gadget/imx_udc.c | |||
@@ -1338,7 +1338,6 @@ static int imx_udc_start(struct usb_gadget *gadget, | |||
1338 | imx_usb = container_of(gadget, struct imx_udc_struct, gadget); | 1338 | imx_usb = container_of(gadget, struct imx_udc_struct, gadget); |
1339 | /* first hook up the driver ... */ | 1339 | /* first hook up the driver ... */ |
1340 | imx_usb->driver = driver; | 1340 | imx_usb->driver = driver; |
1341 | imx_usb->gadget.dev.driver = &driver->driver; | ||
1342 | 1341 | ||
1343 | D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", | 1342 | D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", |
1344 | __func__, driver->driver.name); | 1343 | __func__, driver->driver.name); |
@@ -1358,7 +1357,6 @@ static int imx_udc_stop(struct usb_gadget *gadget, | |||
1358 | imx_udc_disable(imx_usb); | 1357 | imx_udc_disable(imx_usb); |
1359 | del_timer(&imx_usb->timer); | 1358 | del_timer(&imx_usb->timer); |
1360 | 1359 | ||
1361 | imx_usb->gadget.dev.driver = NULL; | ||
1362 | imx_usb->driver = NULL; | 1360 | imx_usb->driver = NULL; |
1363 | 1361 | ||
1364 | D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n", | 1362 | D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n", |
@@ -1461,15 +1459,6 @@ static int __init imx_udc_probe(struct platform_device *pdev) | |||
1461 | imx_usb->clk = clk; | 1459 | imx_usb->clk = clk; |
1462 | imx_usb->dev = &pdev->dev; | 1460 | imx_usb->dev = &pdev->dev; |
1463 | 1461 | ||
1464 | device_initialize(&imx_usb->gadget.dev); | ||
1465 | |||
1466 | imx_usb->gadget.dev.parent = &pdev->dev; | ||
1467 | imx_usb->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1468 | |||
1469 | ret = device_add(&imx_usb->gadget.dev); | ||
1470 | if (retval) | ||
1471 | goto fail4; | ||
1472 | |||
1473 | platform_set_drvdata(pdev, imx_usb); | 1462 | platform_set_drvdata(pdev, imx_usb); |
1474 | 1463 | ||
1475 | usb_init_data(imx_usb); | 1464 | usb_init_data(imx_usb); |
@@ -1481,11 +1470,9 @@ static int __init imx_udc_probe(struct platform_device *pdev) | |||
1481 | 1470 | ||
1482 | ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget); | 1471 | ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget); |
1483 | if (ret) | 1472 | if (ret) |
1484 | goto fail5; | 1473 | goto fail4; |
1485 | 1474 | ||
1486 | return 0; | 1475 | return 0; |
1487 | fail5: | ||
1488 | device_unregister(&imx_usb->gadget.dev); | ||
1489 | fail4: | 1476 | fail4: |
1490 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) | 1477 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) |
1491 | free_irq(imx_usb->usbd_int[i], imx_usb); | 1478 | free_irq(imx_usb->usbd_int[i], imx_usb); |
@@ -1509,7 +1496,6 @@ static int __exit imx_udc_remove(struct platform_device *pdev) | |||
1509 | int i; | 1496 | int i; |
1510 | 1497 | ||
1511 | usb_del_gadget_udc(&imx_usb->gadget); | 1498 | usb_del_gadget_udc(&imx_usb->gadget); |
1512 | device_unregister(&imx_usb->gadget.dev); | ||
1513 | imx_udc_disable(imx_usb); | 1499 | imx_udc_disable(imx_usb); |
1514 | del_timer(&imx_usb->timer); | 1500 | del_timer(&imx_usb->timer); |
1515 | 1501 | ||
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c index aa04089d6899..b943d8cdfbf7 100644 --- a/drivers/usb/gadget/lpc32xx_udc.c +++ b/drivers/usb/gadget/lpc32xx_udc.c | |||
@@ -1469,23 +1469,7 @@ static void done(struct lpc32xx_ep *ep, struct lpc32xx_request *req, int status) | |||
1469 | status = req->req.status; | 1469 | status = req->req.status; |
1470 | 1470 | ||
1471 | if (ep->lep) { | 1471 | if (ep->lep) { |
1472 | enum dma_data_direction direction; | 1472 | usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); |
1473 | |||
1474 | if (ep->is_in) | ||
1475 | direction = DMA_TO_DEVICE; | ||
1476 | else | ||
1477 | direction = DMA_FROM_DEVICE; | ||
1478 | |||
1479 | if (req->mapped) { | ||
1480 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
1481 | req->req.dma, req->req.length, | ||
1482 | direction); | ||
1483 | req->req.dma = 0; | ||
1484 | req->mapped = 0; | ||
1485 | } else | ||
1486 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, | ||
1487 | req->req.dma, req->req.length, | ||
1488 | direction); | ||
1489 | 1473 | ||
1490 | /* Free DDs */ | 1474 | /* Free DDs */ |
1491 | udc_dd_free(udc, req->dd_desc_ptr); | 1475 | udc_dd_free(udc, req->dd_desc_ptr); |
@@ -1841,26 +1825,11 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep, | |||
1841 | } | 1825 | } |
1842 | 1826 | ||
1843 | if (ep->lep) { | 1827 | if (ep->lep) { |
1844 | enum dma_data_direction direction; | ||
1845 | struct lpc32xx_usbd_dd_gad *dd; | 1828 | struct lpc32xx_usbd_dd_gad *dd; |
1846 | 1829 | ||
1847 | /* Map DMA pointer */ | 1830 | status = usb_gadget_map_request(&udc->gadget, _req, ep->is_in); |
1848 | if (ep->is_in) | 1831 | if (status) |
1849 | direction = DMA_TO_DEVICE; | 1832 | return status; |
1850 | else | ||
1851 | direction = DMA_FROM_DEVICE; | ||
1852 | |||
1853 | if (req->req.dma == 0) { | ||
1854 | req->req.dma = dma_map_single( | ||
1855 | ep->udc->gadget.dev.parent, | ||
1856 | req->req.buf, req->req.length, direction); | ||
1857 | req->mapped = 1; | ||
1858 | } else { | ||
1859 | dma_sync_single_for_device( | ||
1860 | ep->udc->gadget.dev.parent, req->req.dma, | ||
1861 | req->req.length, direction); | ||
1862 | req->mapped = 0; | ||
1863 | } | ||
1864 | 1833 | ||
1865 | /* For the request, build a list of DDs */ | 1834 | /* For the request, build a list of DDs */ |
1866 | dd = udc_dd_alloc(udc); | 1835 | dd = udc_dd_alloc(udc); |
@@ -2977,7 +2946,6 @@ static int lpc32xx_start(struct usb_gadget *gadget, | |||
2977 | } | 2946 | } |
2978 | 2947 | ||
2979 | udc->driver = driver; | 2948 | udc->driver = driver; |
2980 | udc->gadget.dev.driver = &driver->driver; | ||
2981 | udc->gadget.dev.of_node = udc->dev->of_node; | 2949 | udc->gadget.dev.of_node = udc->dev->of_node; |
2982 | udc->enabled = 1; | 2950 | udc->enabled = 1; |
2983 | udc->selfpowered = 1; | 2951 | udc->selfpowered = 1; |
@@ -3026,7 +2994,6 @@ static int lpc32xx_stop(struct usb_gadget *gadget, | |||
3026 | } | 2994 | } |
3027 | 2995 | ||
3028 | udc->enabled = 0; | 2996 | udc->enabled = 0; |
3029 | udc->gadget.dev.driver = NULL; | ||
3030 | udc->driver = NULL; | 2997 | udc->driver = NULL; |
3031 | 2998 | ||
3032 | return 0; | 2999 | return 0; |
@@ -3248,12 +3215,6 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev) | |||
3248 | udc_disable(udc); | 3215 | udc_disable(udc); |
3249 | udc_reinit(udc); | 3216 | udc_reinit(udc); |
3250 | 3217 | ||
3251 | retval = device_register(&udc->gadget.dev); | ||
3252 | if (retval < 0) { | ||
3253 | dev_err(udc->dev, "Device registration failure\n"); | ||
3254 | goto dev_register_fail; | ||
3255 | } | ||
3256 | |||
3257 | /* Request IRQs - low and high priority USB device IRQs are routed to | 3218 | /* Request IRQs - low and high priority USB device IRQs are routed to |
3258 | * the same handler, while the DMA interrupt is routed elsewhere */ | 3219 | * the same handler, while the DMA interrupt is routed elsewhere */ |
3259 | retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq, | 3220 | retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq, |
@@ -3320,8 +3281,6 @@ irq_dev_fail: | |||
3320 | irq_hp_fail: | 3281 | irq_hp_fail: |
3321 | free_irq(udc->udp_irq[IRQ_USB_LP], udc); | 3282 | free_irq(udc->udp_irq[IRQ_USB_LP], udc); |
3322 | irq_lp_fail: | 3283 | irq_lp_fail: |
3323 | device_unregister(&udc->gadget.dev); | ||
3324 | dev_register_fail: | ||
3325 | dma_pool_destroy(udc->dd_cache); | 3284 | dma_pool_destroy(udc->dd_cache); |
3326 | dma_alloc_fail: | 3285 | dma_alloc_fail: |
3327 | dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, | 3286 | dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, |
@@ -3376,8 +3335,6 @@ static int lpc32xx_udc_remove(struct platform_device *pdev) | |||
3376 | free_irq(udc->udp_irq[IRQ_USB_HP], udc); | 3335 | free_irq(udc->udp_irq[IRQ_USB_HP], udc); |
3377 | free_irq(udc->udp_irq[IRQ_USB_LP], udc); | 3336 | free_irq(udc->udp_irq[IRQ_USB_LP], udc); |
3378 | 3337 | ||
3379 | device_unregister(&udc->gadget.dev); | ||
3380 | |||
3381 | clk_disable(udc->usb_otg_clk); | 3338 | clk_disable(udc->usb_otg_clk); |
3382 | clk_put(udc->usb_otg_clk); | 3339 | clk_put(udc->usb_otg_clk); |
3383 | clk_disable(udc->usb_slv_clk); | 3340 | clk_disable(udc->usb_slv_clk); |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index c1b8c2dd808d..866ef0999247 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -1471,7 +1471,6 @@ static int m66592_udc_start(struct usb_gadget *g, | |||
1471 | /* hook up the driver */ | 1471 | /* hook up the driver */ |
1472 | driver->driver.bus = NULL; | 1472 | driver->driver.bus = NULL; |
1473 | m66592->driver = driver; | 1473 | m66592->driver = driver; |
1474 | m66592->gadget.dev.driver = &driver->driver; | ||
1475 | 1474 | ||
1476 | m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); | 1475 | m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); |
1477 | if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) { | 1476 | if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) { |
@@ -1494,7 +1493,6 @@ static int m66592_udc_stop(struct usb_gadget *g, | |||
1494 | m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); | 1493 | m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); |
1495 | 1494 | ||
1496 | driver->unbind(&m66592->gadget); | 1495 | driver->unbind(&m66592->gadget); |
1497 | m66592->gadget.dev.driver = NULL; | ||
1498 | 1496 | ||
1499 | init_controller(m66592); | 1497 | init_controller(m66592); |
1500 | disable_controller(m66592); | 1498 | disable_controller(m66592); |
@@ -1538,7 +1536,6 @@ static int __exit m66592_remove(struct platform_device *pdev) | |||
1538 | struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); | 1536 | struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); |
1539 | 1537 | ||
1540 | usb_del_gadget_udc(&m66592->gadget); | 1538 | usb_del_gadget_udc(&m66592->gadget); |
1541 | device_del(&m66592->gadget.dev); | ||
1542 | 1539 | ||
1543 | del_timer_sync(&m66592->timer); | 1540 | del_timer_sync(&m66592->timer); |
1544 | iounmap(m66592->reg); | 1541 | iounmap(m66592->reg); |
@@ -1608,12 +1605,7 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1608 | dev_set_drvdata(&pdev->dev, m66592); | 1605 | dev_set_drvdata(&pdev->dev, m66592); |
1609 | 1606 | ||
1610 | m66592->gadget.ops = &m66592_gadget_ops; | 1607 | m66592->gadget.ops = &m66592_gadget_ops; |
1611 | device_initialize(&m66592->gadget.dev); | ||
1612 | dev_set_name(&m66592->gadget.dev, "gadget"); | ||
1613 | m66592->gadget.max_speed = USB_SPEED_HIGH; | 1608 | m66592->gadget.max_speed = USB_SPEED_HIGH; |
1614 | m66592->gadget.dev.parent = &pdev->dev; | ||
1615 | m66592->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1616 | m66592->gadget.dev.release = pdev->dev.release; | ||
1617 | m66592->gadget.name = udc_name; | 1609 | m66592->gadget.name = udc_name; |
1618 | 1610 | ||
1619 | init_timer(&m66592->timer); | 1611 | init_timer(&m66592->timer); |
@@ -1674,12 +1666,6 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1674 | 1666 | ||
1675 | init_controller(m66592); | 1667 | init_controller(m66592); |
1676 | 1668 | ||
1677 | ret = device_add(&m66592->gadget.dev); | ||
1678 | if (ret) { | ||
1679 | pr_err("device_add error (%d)\n", ret); | ||
1680 | goto err_device_add; | ||
1681 | } | ||
1682 | |||
1683 | ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); | 1669 | ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); |
1684 | if (ret) | 1670 | if (ret) |
1685 | goto err_add_udc; | 1671 | goto err_add_udc; |
@@ -1688,9 +1674,6 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1688 | return 0; | 1674 | return 0; |
1689 | 1675 | ||
1690 | err_add_udc: | 1676 | err_add_udc: |
1691 | device_del(&m66592->gadget.dev); | ||
1692 | |||
1693 | err_device_add: | ||
1694 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); | 1677 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); |
1695 | 1678 | ||
1696 | clean_up3: | 1679 | clean_up3: |
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 20bbbf917fc2..a74ebefc7682 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -135,8 +135,8 @@ static struct fsg_common fsg_common; | |||
135 | 135 | ||
136 | static u8 hostaddr[ETH_ALEN]; | 136 | static u8 hostaddr[ETH_ALEN]; |
137 | 137 | ||
138 | static unsigned char tty_line; | ||
139 | static struct usb_function_instance *fi_acm; | 138 | static struct usb_function_instance *fi_acm; |
139 | static struct eth_dev *the_dev; | ||
140 | 140 | ||
141 | /********** RNDIS **********/ | 141 | /********** RNDIS **********/ |
142 | 142 | ||
@@ -152,7 +152,7 @@ static __init int rndis_do_config(struct usb_configuration *c) | |||
152 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 152 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
153 | } | 153 | } |
154 | 154 | ||
155 | ret = rndis_bind_config(c, hostaddr); | 155 | ret = rndis_bind_config(c, hostaddr, the_dev); |
156 | if (ret < 0) | 156 | if (ret < 0) |
157 | return ret; | 157 | return ret; |
158 | 158 | ||
@@ -214,7 +214,7 @@ static __init int cdc_do_config(struct usb_configuration *c) | |||
214 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 214 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
215 | } | 215 | } |
216 | 216 | ||
217 | ret = ecm_bind_config(c, hostaddr); | 217 | ret = ecm_bind_config(c, hostaddr, the_dev); |
218 | if (ret < 0) | 218 | if (ret < 0) |
219 | return ret; | 219 | return ret; |
220 | 220 | ||
@@ -269,7 +269,6 @@ static int cdc_config_register(struct usb_composite_dev *cdev) | |||
269 | static int __ref multi_bind(struct usb_composite_dev *cdev) | 269 | static int __ref multi_bind(struct usb_composite_dev *cdev) |
270 | { | 270 | { |
271 | struct usb_gadget *gadget = cdev->gadget; | 271 | struct usb_gadget *gadget = cdev->gadget; |
272 | struct f_serial_opts *opts; | ||
273 | int status; | 272 | int status; |
274 | 273 | ||
275 | if (!can_support_ecm(cdev->gadget)) { | 274 | if (!can_support_ecm(cdev->gadget)) { |
@@ -279,24 +278,17 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) | |||
279 | } | 278 | } |
280 | 279 | ||
281 | /* set up network link layer */ | 280 | /* set up network link layer */ |
282 | status = gether_setup(cdev->gadget, hostaddr); | 281 | the_dev = gether_setup(cdev->gadget, hostaddr); |
283 | if (status < 0) | 282 | if (IS_ERR(the_dev)) |
284 | return status; | 283 | return PTR_ERR(the_dev); |
285 | 284 | ||
286 | /* set up serial link layer */ | 285 | /* set up serial link layer */ |
287 | status = gserial_alloc_line(&tty_line); | ||
288 | if (status < 0) | ||
289 | goto fail0; | ||
290 | |||
291 | fi_acm = usb_get_function_instance("acm"); | 286 | fi_acm = usb_get_function_instance("acm"); |
292 | if (IS_ERR(fi_acm)) { | 287 | if (IS_ERR(fi_acm)) { |
293 | status = PTR_ERR(fi_acm); | 288 | status = PTR_ERR(fi_acm); |
294 | goto fail0dot5; | 289 | goto fail0; |
295 | } | 290 | } |
296 | 291 | ||
297 | opts = container_of(fi_acm, struct f_serial_opts, func_inst); | ||
298 | opts->port_num = tty_line; | ||
299 | |||
300 | /* set up mass storage function */ | 292 | /* set up mass storage function */ |
301 | { | 293 | { |
302 | void *retp; | 294 | void *retp; |
@@ -334,10 +326,8 @@ fail2: | |||
334 | fsg_common_put(&fsg_common); | 326 | fsg_common_put(&fsg_common); |
335 | fail1: | 327 | fail1: |
336 | usb_put_function_instance(fi_acm); | 328 | usb_put_function_instance(fi_acm); |
337 | fail0dot5: | ||
338 | gserial_free_line(tty_line); | ||
339 | fail0: | 329 | fail0: |
340 | gether_cleanup(); | 330 | gether_cleanup(the_dev); |
341 | return status; | 331 | return status; |
342 | } | 332 | } |
343 | 333 | ||
@@ -350,8 +340,7 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev) | |||
350 | usb_put_function(f_acm_rndis); | 340 | usb_put_function(f_acm_rndis); |
351 | #endif | 341 | #endif |
352 | usb_put_function_instance(fi_acm); | 342 | usb_put_function_instance(fi_acm); |
353 | gserial_free_line(tty_line); | 343 | gether_cleanup(the_dev); |
354 | gether_cleanup(); | ||
355 | return 0; | 344 | return 0; |
356 | } | 345 | } |
357 | 346 | ||
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c index b5cea273c957..58288e9cf728 100644 --- a/drivers/usb/gadget/mv_u3d_core.c +++ b/drivers/usb/gadget/mv_u3d_core.c | |||
@@ -30,9 +30,6 @@ | |||
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/platform_data/mv_usb.h> | 31 | #include <linux/platform_data/mv_usb.h> |
32 | #include <linux/clk.h> | 32 | #include <linux/clk.h> |
33 | #include <asm/system.h> | ||
34 | #include <asm/unaligned.h> | ||
35 | #include <asm/byteorder.h> | ||
36 | 33 | ||
37 | #include "mv_u3d.h" | 34 | #include "mv_u3d.h" |
38 | 35 | ||
@@ -125,7 +122,7 @@ static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index, | |||
125 | struct mv_u3d_trb *curr_trb; | 122 | struct mv_u3d_trb *curr_trb; |
126 | dma_addr_t cur_deq_lo; | 123 | dma_addr_t cur_deq_lo; |
127 | struct mv_u3d_ep_context *curr_ep_context; | 124 | struct mv_u3d_ep_context *curr_ep_context; |
128 | int trb_complete, actual, remaining_length; | 125 | int trb_complete, actual, remaining_length = 0; |
129 | int direction, ep_num; | 126 | int direction, ep_num; |
130 | int retval = 0; | 127 | int retval = 0; |
131 | u32 tmp, status, length; | 128 | u32 tmp, status, length; |
@@ -189,6 +186,8 @@ static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index, | |||
189 | */ | 186 | */ |
190 | static | 187 | static |
191 | void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status) | 188 | void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status) |
189 | __releases(&ep->udc->lock) | ||
190 | __acquires(&ep->udc->lock) | ||
192 | { | 191 | { |
193 | struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d; | 192 | struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d; |
194 | 193 | ||
@@ -812,19 +811,19 @@ mv_u3d_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
812 | return 0; | 811 | return 0; |
813 | } | 812 | } |
814 | 813 | ||
815 | dev_dbg(u3d->dev, "%s: %s, req: 0x%x\n", | 814 | dev_dbg(u3d->dev, "%s: %s, req: 0x%p\n", |
816 | __func__, _ep->name, (u32)req); | 815 | __func__, _ep->name, req); |
817 | 816 | ||
818 | /* catch various bogus parameters */ | 817 | /* catch various bogus parameters */ |
819 | if (!req->req.complete || !req->req.buf | 818 | if (!req->req.complete || !req->req.buf |
820 | || !list_empty(&req->queue)) { | 819 | || !list_empty(&req->queue)) { |
821 | dev_err(u3d->dev, | 820 | dev_err(u3d->dev, |
822 | "%s, bad params, _req: 0x%x," | 821 | "%s, bad params, _req: 0x%p," |
823 | "req->req.complete: 0x%x, req->req.buf: 0x%x," | 822 | "req->req.complete: 0x%p, req->req.buf: 0x%p," |
824 | "list_empty: 0x%x\n", | 823 | "list_empty: 0x%x\n", |
825 | __func__, (u32)_req, | 824 | __func__, _req, |
826 | (u32)req->req.complete, (u32)req->req.buf, | 825 | req->req.complete, req->req.buf, |
827 | (u32)list_empty(&req->queue)); | 826 | list_empty(&req->queue)); |
828 | return -EINVAL; | 827 | return -EINVAL; |
829 | } | 828 | } |
830 | if (unlikely(!ep->ep.desc)) { | 829 | if (unlikely(!ep->ep.desc)) { |
@@ -905,7 +904,7 @@ static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
905 | struct mv_u3d_req, queue); | 904 | struct mv_u3d_req, queue); |
906 | 905 | ||
907 | /* Point first TRB of next request to the EP context. */ | 906 | /* Point first TRB of next request to the EP context. */ |
908 | iowrite32((u32) next_req->trb_head, | 907 | iowrite32((unsigned long) next_req->trb_head, |
909 | &ep_context->trb_addr_lo); | 908 | &ep_context->trb_addr_lo); |
910 | } else { | 909 | } else { |
911 | struct mv_u3d_ep_context *ep_context; | 910 | struct mv_u3d_ep_context *ep_context; |
@@ -1264,7 +1263,6 @@ static int mv_u3d_start(struct usb_gadget *g, | |||
1264 | /* hook up the driver ... */ | 1263 | /* hook up the driver ... */ |
1265 | driver->driver.bus = NULL; | 1264 | driver->driver.bus = NULL; |
1266 | u3d->driver = driver; | 1265 | u3d->driver = driver; |
1267 | u3d->gadget.dev.driver = &driver->driver; | ||
1268 | 1266 | ||
1269 | u3d->ep0_dir = USB_DIR_OUT; | 1267 | u3d->ep0_dir = USB_DIR_OUT; |
1270 | 1268 | ||
@@ -1302,7 +1300,6 @@ static int mv_u3d_stop(struct usb_gadget *g, | |||
1302 | 1300 | ||
1303 | spin_unlock_irqrestore(&u3d->lock, flags); | 1301 | spin_unlock_irqrestore(&u3d->lock, flags); |
1304 | 1302 | ||
1305 | u3d->gadget.dev.driver = NULL; | ||
1306 | u3d->driver = NULL; | 1303 | u3d->driver = NULL; |
1307 | 1304 | ||
1308 | return 0; | 1305 | return 0; |
@@ -1525,6 +1522,8 @@ static int mv_u3d_is_set_configuration(struct usb_ctrlrequest *setup) | |||
1525 | 1522 | ||
1526 | static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num, | 1523 | static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num, |
1527 | struct usb_ctrlrequest *setup) | 1524 | struct usb_ctrlrequest *setup) |
1525 | __releases(&u3c->lock) | ||
1526 | __acquires(&u3c->lock) | ||
1528 | { | 1527 | { |
1529 | bool delegate = false; | 1528 | bool delegate = false; |
1530 | 1529 | ||
@@ -1758,11 +1757,6 @@ static irqreturn_t mv_u3d_irq(int irq, void *dev) | |||
1758 | return IRQ_HANDLED; | 1757 | return IRQ_HANDLED; |
1759 | } | 1758 | } |
1760 | 1759 | ||
1761 | static void mv_u3d_gadget_release(struct device *dev) | ||
1762 | { | ||
1763 | dev_dbg(dev, "%s\n", __func__); | ||
1764 | } | ||
1765 | |||
1766 | static int mv_u3d_remove(struct platform_device *dev) | 1760 | static int mv_u3d_remove(struct platform_device *dev) |
1767 | { | 1761 | { |
1768 | struct mv_u3d *u3d = platform_get_drvdata(dev); | 1762 | struct mv_u3d *u3d = platform_get_drvdata(dev); |
@@ -1792,8 +1786,6 @@ static int mv_u3d_remove(struct platform_device *dev) | |||
1792 | 1786 | ||
1793 | clk_put(u3d->clk); | 1787 | clk_put(u3d->clk); |
1794 | 1788 | ||
1795 | device_unregister(&u3d->gadget.dev); | ||
1796 | |||
1797 | platform_set_drvdata(dev, NULL); | 1789 | platform_set_drvdata(dev, NULL); |
1798 | 1790 | ||
1799 | kfree(u3d); | 1791 | kfree(u3d); |
@@ -1829,7 +1821,7 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1829 | u3d->dev = &dev->dev; | 1821 | u3d->dev = &dev->dev; |
1830 | u3d->vbus = pdata->vbus; | 1822 | u3d->vbus = pdata->vbus; |
1831 | 1823 | ||
1832 | u3d->clk = clk_get(&dev->dev, pdata->clkname[0]); | 1824 | u3d->clk = clk_get(&dev->dev, NULL); |
1833 | if (IS_ERR(u3d->clk)) { | 1825 | if (IS_ERR(u3d->clk)) { |
1834 | retval = PTR_ERR(u3d->clk); | 1826 | retval = PTR_ERR(u3d->clk); |
1835 | goto err_get_clk; | 1827 | goto err_get_clk; |
@@ -1849,8 +1841,9 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1849 | retval = -EBUSY; | 1841 | retval = -EBUSY; |
1850 | goto err_map_cap_regs; | 1842 | goto err_map_cap_regs; |
1851 | } else { | 1843 | } else { |
1852 | dev_dbg(&dev->dev, "cap_regs address: 0x%x/0x%x\n", | 1844 | dev_dbg(&dev->dev, "cap_regs address: 0x%lx/0x%lx\n", |
1853 | (unsigned int)r->start, (unsigned int)u3d->cap_regs); | 1845 | (unsigned long) r->start, |
1846 | (unsigned long) u3d->cap_regs); | ||
1854 | } | 1847 | } |
1855 | 1848 | ||
1856 | /* we will access controller register, so enable the u3d controller */ | 1849 | /* we will access controller register, so enable the u3d controller */ |
@@ -1864,10 +1857,10 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1864 | } | 1857 | } |
1865 | } | 1858 | } |
1866 | 1859 | ||
1867 | u3d->op_regs = (struct mv_u3d_op_regs __iomem *)((u32)u3d->cap_regs | 1860 | u3d->op_regs = (struct mv_u3d_op_regs __iomem *)(u3d->cap_regs |
1868 | + MV_U3D_USB3_OP_REGS_OFFSET); | 1861 | + MV_U3D_USB3_OP_REGS_OFFSET); |
1869 | 1862 | ||
1870 | u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)((u32)u3d->cap_regs | 1863 | u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)(u3d->cap_regs |
1871 | + ioread32(&u3d->cap_regs->vuoff)); | 1864 | + ioread32(&u3d->cap_regs->vuoff)); |
1872 | 1865 | ||
1873 | u3d->max_eps = 16; | 1866 | u3d->max_eps = 16; |
@@ -1957,16 +1950,8 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1957 | u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */ | 1950 | u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */ |
1958 | 1951 | ||
1959 | /* the "gadget" abstracts/virtualizes the controller */ | 1952 | /* the "gadget" abstracts/virtualizes the controller */ |
1960 | dev_set_name(&u3d->gadget.dev, "gadget"); | ||
1961 | u3d->gadget.dev.parent = &dev->dev; | ||
1962 | u3d->gadget.dev.dma_mask = dev->dev.dma_mask; | ||
1963 | u3d->gadget.dev.release = mv_u3d_gadget_release; | ||
1964 | u3d->gadget.name = driver_name; /* gadget name */ | 1953 | u3d->gadget.name = driver_name; /* gadget name */ |
1965 | 1954 | ||
1966 | retval = device_register(&u3d->gadget.dev); | ||
1967 | if (retval) | ||
1968 | goto err_register_gadget_device; | ||
1969 | |||
1970 | mv_u3d_eps_init(u3d); | 1955 | mv_u3d_eps_init(u3d); |
1971 | 1956 | ||
1972 | /* external vbus detection */ | 1957 | /* external vbus detection */ |
@@ -1991,8 +1976,6 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1991 | return 0; | 1976 | return 0; |
1992 | 1977 | ||
1993 | err_unregister: | 1978 | err_unregister: |
1994 | device_unregister(&u3d->gadget.dev); | ||
1995 | err_register_gadget_device: | ||
1996 | free_irq(u3d->irq, &dev->dev); | 1979 | free_irq(u3d->irq, &dev->dev); |
1997 | err_request_irq: | 1980 | err_request_irq: |
1998 | err_get_irq: | 1981 | err_get_irq: |
@@ -2021,7 +2004,7 @@ err_pdata: | |||
2021 | return retval; | 2004 | return retval; |
2022 | } | 2005 | } |
2023 | 2006 | ||
2024 | #ifdef CONFIG_PM | 2007 | #ifdef CONFIG_PM_SLEEP |
2025 | static int mv_u3d_suspend(struct device *dev) | 2008 | static int mv_u3d_suspend(struct device *dev) |
2026 | { | 2009 | { |
2027 | struct mv_u3d *u3d = dev_get_drvdata(dev); | 2010 | struct mv_u3d *u3d = dev_get_drvdata(dev); |
@@ -2064,10 +2047,10 @@ static int mv_u3d_resume(struct device *dev) | |||
2064 | 2047 | ||
2065 | return 0; | 2048 | return 0; |
2066 | } | 2049 | } |
2067 | |||
2068 | SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume); | ||
2069 | #endif | 2050 | #endif |
2070 | 2051 | ||
2052 | static SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume); | ||
2053 | |||
2071 | static void mv_u3d_shutdown(struct platform_device *dev) | 2054 | static void mv_u3d_shutdown(struct platform_device *dev) |
2072 | { | 2055 | { |
2073 | struct mv_u3d *u3d = dev_get_drvdata(&dev->dev); | 2056 | struct mv_u3d *u3d = dev_get_drvdata(&dev->dev); |
@@ -2080,14 +2063,12 @@ static void mv_u3d_shutdown(struct platform_device *dev) | |||
2080 | 2063 | ||
2081 | static struct platform_driver mv_u3d_driver = { | 2064 | static struct platform_driver mv_u3d_driver = { |
2082 | .probe = mv_u3d_probe, | 2065 | .probe = mv_u3d_probe, |
2083 | .remove = __exit_p(mv_u3d_remove), | 2066 | .remove = mv_u3d_remove, |
2084 | .shutdown = mv_u3d_shutdown, | 2067 | .shutdown = mv_u3d_shutdown, |
2085 | .driver = { | 2068 | .driver = { |
2086 | .owner = THIS_MODULE, | 2069 | .owner = THIS_MODULE, |
2087 | .name = "mv-u3d", | 2070 | .name = "mv-u3d", |
2088 | #ifdef CONFIG_PM | ||
2089 | .pm = &mv_u3d_pm_ops, | 2071 | .pm = &mv_u3d_pm_ops, |
2090 | #endif | ||
2091 | }, | 2072 | }, |
2092 | }; | 2073 | }; |
2093 | 2074 | ||
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h index 9073436d8b24..be77f207dbaf 100644 --- a/drivers/usb/gadget/mv_udc.h +++ b/drivers/usb/gadget/mv_udc.h | |||
@@ -222,8 +222,7 @@ struct mv_udc { | |||
222 | struct mv_usb_platform_data *pdata; | 222 | struct mv_usb_platform_data *pdata; |
223 | 223 | ||
224 | /* some SOC has mutiple clock sources for USB*/ | 224 | /* some SOC has mutiple clock sources for USB*/ |
225 | unsigned int clknum; | 225 | struct clk *clk; |
226 | struct clk *clk[0]; | ||
227 | }; | 226 | }; |
228 | 227 | ||
229 | /* endpoint data structure */ | 228 | /* endpoint data structure */ |
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c index c8cf959057fe..c2a57023e467 100644 --- a/drivers/usb/gadget/mv_udc_core.c +++ b/drivers/usb/gadget/mv_udc_core.c | |||
@@ -212,6 +212,8 @@ static int process_ep_req(struct mv_udc *udc, int index, | |||
212 | * request is still in progress. | 212 | * request is still in progress. |
213 | */ | 213 | */ |
214 | static void done(struct mv_ep *ep, struct mv_req *req, int status) | 214 | static void done(struct mv_ep *ep, struct mv_req *req, int status) |
215 | __releases(&ep->udc->lock) | ||
216 | __acquires(&ep->udc->lock) | ||
215 | { | 217 | { |
216 | struct mv_udc *udc = NULL; | 218 | struct mv_udc *udc = NULL; |
217 | unsigned char stopped = ep->stopped; | 219 | unsigned char stopped = ep->stopped; |
@@ -237,18 +239,7 @@ static void done(struct mv_ep *ep, struct mv_req *req, int status) | |||
237 | dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma); | 239 | dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma); |
238 | } | 240 | } |
239 | 241 | ||
240 | if (req->mapped) { | 242 | usb_gadget_unmap_request(&udc->gadget, &req->req, ep_dir(ep)); |
241 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
242 | req->req.dma, req->req.length, | ||
243 | ((ep_dir(ep) == EP_DIR_IN) ? | ||
244 | DMA_TO_DEVICE : DMA_FROM_DEVICE)); | ||
245 | req->req.dma = DMA_ADDR_INVALID; | ||
246 | req->mapped = 0; | ||
247 | } else | ||
248 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, | ||
249 | req->req.dma, req->req.length, | ||
250 | ((ep_dir(ep) == EP_DIR_IN) ? | ||
251 | DMA_TO_DEVICE : DMA_FROM_DEVICE)); | ||
252 | 243 | ||
253 | if (status && (status != -ESHUTDOWN)) | 244 | if (status && (status != -ESHUTDOWN)) |
254 | dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u", | 245 | dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u", |
@@ -732,21 +723,9 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
732 | req->ep = ep; | 723 | req->ep = ep; |
733 | 724 | ||
734 | /* map virtual address to hardware */ | 725 | /* map virtual address to hardware */ |
735 | if (req->req.dma == DMA_ADDR_INVALID) { | 726 | retval = usb_gadget_map_request(&udc->gadget, _req, ep_dir(ep)); |
736 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | 727 | if (retval) |
737 | req->req.buf, | 728 | return retval; |
738 | req->req.length, ep_dir(ep) | ||
739 | ? DMA_TO_DEVICE | ||
740 | : DMA_FROM_DEVICE); | ||
741 | req->mapped = 1; | ||
742 | } else { | ||
743 | dma_sync_single_for_device(ep->udc->gadget.dev.parent, | ||
744 | req->req.dma, req->req.length, | ||
745 | ep_dir(ep) | ||
746 | ? DMA_TO_DEVICE | ||
747 | : DMA_FROM_DEVICE); | ||
748 | req->mapped = 0; | ||
749 | } | ||
750 | 729 | ||
751 | req->req.status = -EINPROGRESS; | 730 | req->req.status = -EINPROGRESS; |
752 | req->req.actual = 0; | 731 | req->req.actual = 0; |
@@ -780,18 +759,7 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
780 | return 0; | 759 | return 0; |
781 | 760 | ||
782 | err_unmap_dma: | 761 | err_unmap_dma: |
783 | if (req->mapped) { | 762 | usb_gadget_unmap_request(&udc->gadget, _req, ep_dir(ep)); |
784 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
785 | req->req.dma, req->req.length, | ||
786 | ((ep_dir(ep) == EP_DIR_IN) ? | ||
787 | DMA_TO_DEVICE : DMA_FROM_DEVICE)); | ||
788 | req->req.dma = DMA_ADDR_INVALID; | ||
789 | req->mapped = 0; | ||
790 | } else | ||
791 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, | ||
792 | req->req.dma, req->req.length, | ||
793 | ((ep_dir(ep) == EP_DIR_IN) ? | ||
794 | DMA_TO_DEVICE : DMA_FROM_DEVICE)); | ||
795 | 763 | ||
796 | return retval; | 764 | return retval; |
797 | } | 765 | } |
@@ -1006,18 +974,12 @@ static struct usb_ep_ops mv_ep_ops = { | |||
1006 | 974 | ||
1007 | static void udc_clock_enable(struct mv_udc *udc) | 975 | static void udc_clock_enable(struct mv_udc *udc) |
1008 | { | 976 | { |
1009 | unsigned int i; | 977 | clk_prepare_enable(udc->clk); |
1010 | |||
1011 | for (i = 0; i < udc->clknum; i++) | ||
1012 | clk_prepare_enable(udc->clk[i]); | ||
1013 | } | 978 | } |
1014 | 979 | ||
1015 | static void udc_clock_disable(struct mv_udc *udc) | 980 | static void udc_clock_disable(struct mv_udc *udc) |
1016 | { | 981 | { |
1017 | unsigned int i; | 982 | clk_disable_unprepare(udc->clk); |
1018 | |||
1019 | for (i = 0; i < udc->clknum; i++) | ||
1020 | clk_disable_unprepare(udc->clk[i]); | ||
1021 | } | 983 | } |
1022 | 984 | ||
1023 | static void udc_stop(struct mv_udc *udc) | 985 | static void udc_stop(struct mv_udc *udc) |
@@ -1386,7 +1348,6 @@ static int mv_udc_start(struct usb_gadget *gadget, | |||
1386 | /* hook up the driver ... */ | 1348 | /* hook up the driver ... */ |
1387 | driver->driver.bus = NULL; | 1349 | driver->driver.bus = NULL; |
1388 | udc->driver = driver; | 1350 | udc->driver = driver; |
1389 | udc->gadget.dev.driver = &driver->driver; | ||
1390 | 1351 | ||
1391 | udc->usb_state = USB_STATE_ATTACHED; | 1352 | udc->usb_state = USB_STATE_ATTACHED; |
1392 | udc->ep0_state = WAIT_FOR_SETUP; | 1353 | udc->ep0_state = WAIT_FOR_SETUP; |
@@ -1401,7 +1362,6 @@ static int mv_udc_start(struct usb_gadget *gadget, | |||
1401 | dev_err(&udc->dev->dev, | 1362 | dev_err(&udc->dev->dev, |
1402 | "unable to register peripheral to otg\n"); | 1363 | "unable to register peripheral to otg\n"); |
1403 | udc->driver = NULL; | 1364 | udc->driver = NULL; |
1404 | udc->gadget.dev.driver = NULL; | ||
1405 | return retval; | 1365 | return retval; |
1406 | } | 1366 | } |
1407 | } | 1367 | } |
@@ -1437,7 +1397,6 @@ static int mv_udc_stop(struct usb_gadget *gadget, | |||
1437 | spin_unlock_irqrestore(&udc->lock, flags); | 1397 | spin_unlock_irqrestore(&udc->lock, flags); |
1438 | 1398 | ||
1439 | /* unbind gadget driver */ | 1399 | /* unbind gadget driver */ |
1440 | udc->gadget.dev.driver = NULL; | ||
1441 | udc->driver = NULL; | 1400 | udc->driver = NULL; |
1442 | 1401 | ||
1443 | return 0; | 1402 | return 0; |
@@ -1528,14 +1487,7 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) | |||
1528 | 1487 | ||
1529 | return 0; | 1488 | return 0; |
1530 | out: | 1489 | out: |
1531 | if (req->mapped) { | 1490 | usb_gadget_unmap_request(&udc->gadget, &req->req, ep_dir(ep)); |
1532 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
1533 | req->req.dma, req->req.length, | ||
1534 | ((ep_dir(ep) == EP_DIR_IN) ? | ||
1535 | DMA_TO_DEVICE : DMA_FROM_DEVICE)); | ||
1536 | req->req.dma = DMA_ADDR_INVALID; | ||
1537 | req->mapped = 0; | ||
1538 | } | ||
1539 | 1491 | ||
1540 | return retval; | 1492 | return retval; |
1541 | } | 1493 | } |
@@ -1695,6 +1647,8 @@ out: | |||
1695 | 1647 | ||
1696 | static void handle_setup_packet(struct mv_udc *udc, u8 ep_num, | 1648 | static void handle_setup_packet(struct mv_udc *udc, u8 ep_num, |
1697 | struct usb_ctrlrequest *setup) | 1649 | struct usb_ctrlrequest *setup) |
1650 | __releases(&ep->udc->lock) | ||
1651 | __acquires(&ep->udc->lock) | ||
1698 | { | 1652 | { |
1699 | bool delegate = false; | 1653 | bool delegate = false; |
1700 | 1654 | ||
@@ -1891,7 +1845,7 @@ static void irq_process_tr_complete(struct mv_udc *udc) | |||
1891 | } | 1845 | } |
1892 | } | 1846 | } |
1893 | 1847 | ||
1894 | void irq_process_reset(struct mv_udc *udc) | 1848 | static void irq_process_reset(struct mv_udc *udc) |
1895 | { | 1849 | { |
1896 | u32 tmp; | 1850 | u32 tmp; |
1897 | unsigned int loops; | 1851 | unsigned int loops; |
@@ -2138,8 +2092,6 @@ static int mv_udc_remove(struct platform_device *pdev) | |||
2138 | 2092 | ||
2139 | mv_udc_disable(udc); | 2093 | mv_udc_disable(udc); |
2140 | 2094 | ||
2141 | device_unregister(&udc->gadget.dev); | ||
2142 | |||
2143 | /* free dev, wait for the release() finished */ | 2095 | /* free dev, wait for the release() finished */ |
2144 | wait_for_completion(udc->done); | 2096 | wait_for_completion(udc->done); |
2145 | 2097 | ||
@@ -2151,7 +2103,6 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2151 | struct mv_usb_platform_data *pdata = pdev->dev.platform_data; | 2103 | struct mv_usb_platform_data *pdata = pdev->dev.platform_data; |
2152 | struct mv_udc *udc; | 2104 | struct mv_udc *udc; |
2153 | int retval = 0; | 2105 | int retval = 0; |
2154 | int clk_i = 0; | ||
2155 | struct resource *r; | 2106 | struct resource *r; |
2156 | size_t size; | 2107 | size_t size; |
2157 | 2108 | ||
@@ -2160,8 +2111,7 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2160 | return -ENODEV; | 2111 | return -ENODEV; |
2161 | } | 2112 | } |
2162 | 2113 | ||
2163 | size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum; | 2114 | udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); |
2164 | udc = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); | ||
2165 | if (udc == NULL) { | 2115 | if (udc == NULL) { |
2166 | dev_err(&pdev->dev, "failed to allocate memory for udc\n"); | 2116 | dev_err(&pdev->dev, "failed to allocate memory for udc\n"); |
2167 | return -ENOMEM; | 2117 | return -ENOMEM; |
@@ -2173,26 +2123,24 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2173 | 2123 | ||
2174 | udc->dev = pdev; | 2124 | udc->dev = pdev; |
2175 | 2125 | ||
2176 | #ifdef CONFIG_USB_OTG_UTILS | ||
2177 | if (pdata->mode == MV_USB_MODE_OTG) { | 2126 | if (pdata->mode == MV_USB_MODE_OTG) { |
2178 | udc->transceiver = devm_usb_get_phy(&pdev->dev, | 2127 | udc->transceiver = devm_usb_get_phy(&pdev->dev, |
2179 | USB_PHY_TYPE_USB2); | 2128 | USB_PHY_TYPE_USB2); |
2180 | if (IS_ERR_OR_NULL(udc->transceiver)) { | 2129 | if (IS_ERR(udc->transceiver)) { |
2130 | retval = PTR_ERR(udc->transceiver); | ||
2131 | |||
2132 | if (retval == -ENXIO) | ||
2133 | return retval; | ||
2134 | |||
2181 | udc->transceiver = NULL; | 2135 | udc->transceiver = NULL; |
2182 | return -ENODEV; | 2136 | return -EPROBE_DEFER; |
2183 | } | 2137 | } |
2184 | } | 2138 | } |
2185 | #endif | ||
2186 | 2139 | ||
2187 | udc->clknum = pdata->clknum; | 2140 | /* udc only have one sysclk. */ |
2188 | for (clk_i = 0; clk_i < udc->clknum; clk_i++) { | 2141 | udc->clk = devm_clk_get(&pdev->dev, NULL); |
2189 | udc->clk[clk_i] = devm_clk_get(&pdev->dev, | 2142 | if (IS_ERR(udc->clk)) |
2190 | pdata->clkname[clk_i]); | 2143 | return PTR_ERR(udc->clk); |
2191 | if (IS_ERR(udc->clk[clk_i])) { | ||
2192 | retval = PTR_ERR(udc->clk[clk_i]); | ||
2193 | return retval; | ||
2194 | } | ||
2195 | } | ||
2196 | 2144 | ||
2197 | r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); | 2145 | r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); |
2198 | if (r == NULL) { | 2146 | if (r == NULL) { |
@@ -2311,16 +2259,8 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2311 | udc->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */ | 2259 | udc->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */ |
2312 | 2260 | ||
2313 | /* the "gadget" abstracts/virtualizes the controller */ | 2261 | /* the "gadget" abstracts/virtualizes the controller */ |
2314 | dev_set_name(&udc->gadget.dev, "gadget"); | ||
2315 | udc->gadget.dev.parent = &pdev->dev; | ||
2316 | udc->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
2317 | udc->gadget.dev.release = gadget_release; | ||
2318 | udc->gadget.name = driver_name; /* gadget name */ | 2262 | udc->gadget.name = driver_name; /* gadget name */ |
2319 | 2263 | ||
2320 | retval = device_register(&udc->gadget.dev); | ||
2321 | if (retval) | ||
2322 | goto err_destroy_dma; | ||
2323 | |||
2324 | eps_init(udc); | 2264 | eps_init(udc); |
2325 | 2265 | ||
2326 | /* VBUS detect: we can disable/enable clock on demand.*/ | 2266 | /* VBUS detect: we can disable/enable clock on demand.*/ |
@@ -2342,7 +2282,7 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2342 | if (!udc->qwork) { | 2282 | if (!udc->qwork) { |
2343 | dev_err(&pdev->dev, "cannot create workqueue\n"); | 2283 | dev_err(&pdev->dev, "cannot create workqueue\n"); |
2344 | retval = -ENOMEM; | 2284 | retval = -ENOMEM; |
2345 | goto err_unregister; | 2285 | goto err_destroy_dma; |
2346 | } | 2286 | } |
2347 | 2287 | ||
2348 | INIT_WORK(&udc->vbus_work, mv_udc_vbus_work); | 2288 | INIT_WORK(&udc->vbus_work, mv_udc_vbus_work); |
@@ -2358,7 +2298,8 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2358 | else | 2298 | else |
2359 | udc->vbus_active = 1; | 2299 | udc->vbus_active = 1; |
2360 | 2300 | ||
2361 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2301 | retval = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, |
2302 | gadget_release); | ||
2362 | if (retval) | 2303 | if (retval) |
2363 | goto err_create_workqueue; | 2304 | goto err_create_workqueue; |
2364 | 2305 | ||
@@ -2370,8 +2311,6 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2370 | 2311 | ||
2371 | err_create_workqueue: | 2312 | err_create_workqueue: |
2372 | destroy_workqueue(udc->qwork); | 2313 | destroy_workqueue(udc->qwork); |
2373 | err_unregister: | ||
2374 | device_unregister(&udc->gadget.dev); | ||
2375 | err_destroy_dma: | 2314 | err_destroy_dma: |
2376 | dma_pool_destroy(udc->dtd_pool); | 2315 | dma_pool_destroy(udc->dtd_pool); |
2377 | err_free_dma: | 2316 | err_free_dma: |
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index a22ad9af0565..3b02fd4649ce 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c | |||
@@ -111,6 +111,7 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
111 | NULL, | 111 | NULL, |
112 | }; | 112 | }; |
113 | 113 | ||
114 | struct eth_dev *the_dev; | ||
114 | static u8 hostaddr[ETH_ALEN]; | 115 | static u8 hostaddr[ETH_ALEN]; |
115 | 116 | ||
116 | /*-------------------------------------------------------------------------*/ | 117 | /*-------------------------------------------------------------------------*/ |
@@ -124,7 +125,7 @@ static int __init ncm_do_config(struct usb_configuration *c) | |||
124 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 125 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
125 | } | 126 | } |
126 | 127 | ||
127 | return ncm_bind_config(c, hostaddr); | 128 | return ncm_bind_config(c, hostaddr, the_dev); |
128 | } | 129 | } |
129 | 130 | ||
130 | static struct usb_configuration ncm_config_driver = { | 131 | static struct usb_configuration ncm_config_driver = { |
@@ -143,9 +144,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) | |||
143 | int status; | 144 | int status; |
144 | 145 | ||
145 | /* set up network link layer */ | 146 | /* set up network link layer */ |
146 | status = gether_setup(cdev->gadget, hostaddr); | 147 | the_dev = gether_setup(cdev->gadget, hostaddr); |
147 | if (status < 0) | 148 | if (IS_ERR(the_dev)) |
148 | return status; | 149 | return PTR_ERR(the_dev); |
149 | 150 | ||
150 | /* Allocate string descriptor numbers ... note that string | 151 | /* Allocate string descriptor numbers ... note that string |
151 | * contents can be overridden by the composite_dev glue. | 152 | * contents can be overridden by the composite_dev glue. |
@@ -168,13 +169,13 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) | |||
168 | return 0; | 169 | return 0; |
169 | 170 | ||
170 | fail: | 171 | fail: |
171 | gether_cleanup(); | 172 | gether_cleanup(the_dev); |
172 | return status; | 173 | return status; |
173 | } | 174 | } |
174 | 175 | ||
175 | static int __exit gncm_unbind(struct usb_composite_dev *cdev) | 176 | static int __exit gncm_unbind(struct usb_composite_dev *cdev) |
176 | { | 177 | { |
177 | gether_cleanup(); | 178 | gether_cleanup(the_dev); |
178 | return 0; | 179 | return 0; |
179 | } | 180 | } |
180 | 181 | ||
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c index 32524b631959..f1e50a3e322d 100644 --- a/drivers/usb/gadget/net2272.c +++ b/drivers/usb/gadget/net2272.c | |||
@@ -58,7 +58,6 @@ static const char * const ep_name[] = { | |||
58 | "ep-a", "ep-b", "ep-c", | 58 | "ep-a", "ep-b", "ep-c", |
59 | }; | 59 | }; |
60 | 60 | ||
61 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
62 | #ifdef CONFIG_USB_NET2272_DMA | 61 | #ifdef CONFIG_USB_NET2272_DMA |
63 | /* | 62 | /* |
64 | * use_dma: the NET2272 can use an external DMA controller. | 63 | * use_dma: the NET2272 can use an external DMA controller. |
@@ -341,7 +340,6 @@ net2272_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | |||
341 | if (!req) | 340 | if (!req) |
342 | return NULL; | 341 | return NULL; |
343 | 342 | ||
344 | req->req.dma = DMA_ADDR_INVALID; | ||
345 | INIT_LIST_HEAD(&req->queue); | 343 | INIT_LIST_HEAD(&req->queue); |
346 | 344 | ||
347 | return &req->req; | 345 | return &req->req; |
@@ -913,7 +911,7 @@ net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
913 | } | 911 | } |
914 | } | 912 | } |
915 | } | 913 | } |
916 | if (likely(req != 0)) | 914 | if (likely(req)) |
917 | list_add_tail(&req->queue, &ep->queue); | 915 | list_add_tail(&req->queue, &ep->queue); |
918 | 916 | ||
919 | if (likely(!list_empty(&ep->queue))) | 917 | if (likely(!list_empty(&ep->queue))) |
@@ -1467,7 +1465,6 @@ static int net2272_start(struct usb_gadget *_gadget, | |||
1467 | dev->softconnect = 1; | 1465 | dev->softconnect = 1; |
1468 | driver->driver.bus = NULL; | 1466 | driver->driver.bus = NULL; |
1469 | dev->driver = driver; | 1467 | dev->driver = driver; |
1470 | dev->gadget.dev.driver = &driver->driver; | ||
1471 | 1468 | ||
1472 | /* ... then enable host detection and ep0; and we're ready | 1469 | /* ... then enable host detection and ep0; and we're ready |
1473 | * for set_configuration as well as eventual disconnect. | 1470 | * for set_configuration as well as eventual disconnect. |
@@ -1517,7 +1514,6 @@ static int net2272_stop(struct usb_gadget *_gadget, | |||
1517 | stop_activity(dev, driver); | 1514 | stop_activity(dev, driver); |
1518 | spin_unlock_irqrestore(&dev->lock, flags); | 1515 | spin_unlock_irqrestore(&dev->lock, flags); |
1519 | 1516 | ||
1520 | dev->gadget.dev.driver = NULL; | ||
1521 | dev->driver = NULL; | 1517 | dev->driver = NULL; |
1522 | 1518 | ||
1523 | dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); | 1519 | dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); |
@@ -1549,7 +1545,7 @@ net2272_handle_dma(struct net2272_ep *ep) | |||
1549 | | (ep->dev->dma_eot_polarity << EOT_POLARITY) | 1545 | | (ep->dev->dma_eot_polarity << EOT_POLARITY) |
1550 | | (ep->dev->dma_dack_polarity << DACK_POLARITY) | 1546 | | (ep->dev->dma_dack_polarity << DACK_POLARITY) |
1551 | | (ep->dev->dma_dreq_polarity << DREQ_POLARITY) | 1547 | | (ep->dev->dma_dreq_polarity << DREQ_POLARITY) |
1552 | | ((ep->dma >> 1) << DMA_ENDPOINT_SELECT)); | 1548 | | (ep->dma << DMA_ENDPOINT_SELECT)); |
1553 | 1549 | ||
1554 | ep->dev->dma_busy = 0; | 1550 | ep->dev->dma_busy = 0; |
1555 | 1551 | ||
@@ -1622,7 +1618,7 @@ net2272_handle_ep(struct net2272_ep *ep) | |||
1622 | ep->irqs++; | 1618 | ep->irqs++; |
1623 | 1619 | ||
1624 | dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n", | 1620 | dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n", |
1625 | ep->ep.name, stat0, stat1, req ? &req->req : 0); | 1621 | ep->ep.name, stat0, stat1, req ? &req->req : NULL); |
1626 | 1622 | ||
1627 | net2272_ep_write(ep, EP_STAT0, stat0 & | 1623 | net2272_ep_write(ep, EP_STAT0, stat0 & |
1628 | ~((1 << NAK_OUT_PACKETS) | 1624 | ~((1 << NAK_OUT_PACKETS) |
@@ -2216,7 +2212,6 @@ net2272_remove(struct net2272 *dev) | |||
2216 | free_irq(dev->irq, dev); | 2212 | free_irq(dev->irq, dev); |
2217 | iounmap(dev->base_addr); | 2213 | iounmap(dev->base_addr); |
2218 | 2214 | ||
2219 | device_unregister(&dev->gadget.dev); | ||
2220 | device_remove_file(dev->dev, &dev_attr_registers); | 2215 | device_remove_file(dev->dev, &dev_attr_registers); |
2221 | 2216 | ||
2222 | dev_info(dev->dev, "unbind\n"); | 2217 | dev_info(dev->dev, "unbind\n"); |
@@ -2243,10 +2238,6 @@ static struct net2272 *net2272_probe_init(struct device *dev, unsigned int irq) | |||
2243 | ret->gadget.max_speed = USB_SPEED_HIGH; | 2238 | ret->gadget.max_speed = USB_SPEED_HIGH; |
2244 | 2239 | ||
2245 | /* the "gadget" abstracts/virtualizes the controller */ | 2240 | /* the "gadget" abstracts/virtualizes the controller */ |
2246 | dev_set_name(&ret->gadget.dev, "gadget"); | ||
2247 | ret->gadget.dev.parent = dev; | ||
2248 | ret->gadget.dev.dma_mask = dev->dma_mask; | ||
2249 | ret->gadget.dev.release = net2272_gadget_release; | ||
2250 | ret->gadget.name = driver_name; | 2241 | ret->gadget.name = driver_name; |
2251 | 2242 | ||
2252 | return ret; | 2243 | return ret; |
@@ -2282,14 +2273,12 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags) | |||
2282 | dma_mode_string()); | 2273 | dma_mode_string()); |
2283 | dev_info(dev->dev, "version: %s\n", driver_vers); | 2274 | dev_info(dev->dev, "version: %s\n", driver_vers); |
2284 | 2275 | ||
2285 | ret = device_register(&dev->gadget.dev); | ||
2286 | if (ret) | ||
2287 | goto err_irq; | ||
2288 | ret = device_create_file(dev->dev, &dev_attr_registers); | 2276 | ret = device_create_file(dev->dev, &dev_attr_registers); |
2289 | if (ret) | 2277 | if (ret) |
2290 | goto err_dev_reg; | 2278 | goto err_irq; |
2291 | 2279 | ||
2292 | ret = usb_add_gadget_udc(dev->dev, &dev->gadget); | 2280 | ret = usb_add_gadget_udc_release(dev->dev, &dev->gadget, |
2281 | net2272_gadget_release); | ||
2293 | if (ret) | 2282 | if (ret) |
2294 | goto err_add_udc; | 2283 | goto err_add_udc; |
2295 | 2284 | ||
@@ -2297,8 +2286,6 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags) | |||
2297 | 2286 | ||
2298 | err_add_udc: | 2287 | err_add_udc: |
2299 | device_remove_file(dev->dev, &dev_attr_registers); | 2288 | device_remove_file(dev->dev, &dev_attr_registers); |
2300 | err_dev_reg: | ||
2301 | device_unregister(&dev->gadget.dev); | ||
2302 | err_irq: | 2289 | err_irq: |
2303 | free_irq(dev->irq, dev); | 2290 | free_irq(dev->irq, dev); |
2304 | err: | 2291 | err: |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index 3bd0f992fb49..fbd006ab31d3 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -65,7 +65,6 @@ | |||
65 | #define DRIVER_DESC "PLX NET228x USB Peripheral Controller" | 65 | #define DRIVER_DESC "PLX NET228x USB Peripheral Controller" |
66 | #define DRIVER_VERSION "2005 Sept 27" | 66 | #define DRIVER_VERSION "2005 Sept 27" |
67 | 67 | ||
68 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
69 | #define EP_DONTUSE 13 /* nonzero */ | 68 | #define EP_DONTUSE 13 /* nonzero */ |
70 | 69 | ||
71 | #define USE_RDK_LEDS /* GPIO pins control three LEDs */ | 70 | #define USE_RDK_LEDS /* GPIO pins control three LEDs */ |
@@ -406,7 +405,6 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags) | |||
406 | if (!req) | 405 | if (!req) |
407 | return NULL; | 406 | return NULL; |
408 | 407 | ||
409 | req->req.dma = DMA_ADDR_INVALID; | ||
410 | INIT_LIST_HEAD (&req->queue); | 408 | INIT_LIST_HEAD (&req->queue); |
411 | 409 | ||
412 | /* this dma descriptor may be swapped with the previous dummy */ | 410 | /* this dma descriptor may be swapped with the previous dummy */ |
@@ -420,7 +418,6 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags) | |||
420 | return NULL; | 418 | return NULL; |
421 | } | 419 | } |
422 | td->dmacount = 0; /* not VALID */ | 420 | td->dmacount = 0; /* not VALID */ |
423 | td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID); | ||
424 | td->dmadesc = td->dmaaddr; | 421 | td->dmadesc = td->dmaaddr; |
425 | req->td = td; | 422 | req->td = td; |
426 | } | 423 | } |
@@ -1896,7 +1893,6 @@ static int net2280_start(struct usb_gadget *_gadget, | |||
1896 | dev->softconnect = 1; | 1893 | dev->softconnect = 1; |
1897 | driver->driver.bus = NULL; | 1894 | driver->driver.bus = NULL; |
1898 | dev->driver = driver; | 1895 | dev->driver = driver; |
1899 | dev->gadget.dev.driver = &driver->driver; | ||
1900 | 1896 | ||
1901 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); | 1897 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); |
1902 | if (retval) goto err_unbind; | 1898 | if (retval) goto err_unbind; |
@@ -1924,7 +1920,6 @@ static int net2280_start(struct usb_gadget *_gadget, | |||
1924 | err_func: | 1920 | err_func: |
1925 | device_remove_file (&dev->pdev->dev, &dev_attr_function); | 1921 | device_remove_file (&dev->pdev->dev, &dev_attr_function); |
1926 | err_unbind: | 1922 | err_unbind: |
1927 | dev->gadget.dev.driver = NULL; | ||
1928 | dev->driver = NULL; | 1923 | dev->driver = NULL; |
1929 | return retval; | 1924 | return retval; |
1930 | } | 1925 | } |
@@ -1967,7 +1962,6 @@ static int net2280_stop(struct usb_gadget *_gadget, | |||
1967 | stop_activity (dev, driver); | 1962 | stop_activity (dev, driver); |
1968 | spin_unlock_irqrestore (&dev->lock, flags); | 1963 | spin_unlock_irqrestore (&dev->lock, flags); |
1969 | 1964 | ||
1970 | dev->gadget.dev.driver = NULL; | ||
1971 | dev->driver = NULL; | 1965 | dev->driver = NULL; |
1972 | 1966 | ||
1973 | net2280_led_active (dev, 0); | 1967 | net2280_led_active (dev, 0); |
@@ -2072,7 +2066,7 @@ static void handle_ep_small (struct net2280_ep *ep) | |||
2072 | return; | 2066 | return; |
2073 | 2067 | ||
2074 | /* manual DMA queue advance after short OUT */ | 2068 | /* manual DMA queue advance after short OUT */ |
2075 | if (likely (ep->dma != 0)) { | 2069 | if (likely (ep->dma)) { |
2076 | if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) { | 2070 | if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) { |
2077 | u32 count; | 2071 | u32 count; |
2078 | int stopped = ep->stopped; | 2072 | int stopped = ep->stopped; |
@@ -2330,7 +2324,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2330 | /* hw handles device and interface status */ | 2324 | /* hw handles device and interface status */ |
2331 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) | 2325 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) |
2332 | goto delegate; | 2326 | goto delegate; |
2333 | if ((e = get_ep_by_addr (dev, w_index)) == 0 | 2327 | if ((e = get_ep_by_addr (dev, w_index)) == NULL |
2334 | || w_length > 2) | 2328 | || w_length > 2) |
2335 | goto do_stall; | 2329 | goto do_stall; |
2336 | 2330 | ||
@@ -2358,7 +2352,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2358 | if (w_value != USB_ENDPOINT_HALT | 2352 | if (w_value != USB_ENDPOINT_HALT |
2359 | || w_length != 0) | 2353 | || w_length != 0) |
2360 | goto do_stall; | 2354 | goto do_stall; |
2361 | if ((e = get_ep_by_addr (dev, w_index)) == 0) | 2355 | if ((e = get_ep_by_addr (dev, w_index)) == NULL) |
2362 | goto do_stall; | 2356 | goto do_stall; |
2363 | if (e->wedged) { | 2357 | if (e->wedged) { |
2364 | VDEBUG(dev, "%s wedged, halt not cleared\n", | 2358 | VDEBUG(dev, "%s wedged, halt not cleared\n", |
@@ -2380,7 +2374,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2380 | if (w_value != USB_ENDPOINT_HALT | 2374 | if (w_value != USB_ENDPOINT_HALT |
2381 | || w_length != 0) | 2375 | || w_length != 0) |
2382 | goto do_stall; | 2376 | goto do_stall; |
2383 | if ((e = get_ep_by_addr (dev, w_index)) == 0) | 2377 | if ((e = get_ep_by_addr (dev, w_index)) == NULL) |
2384 | goto do_stall; | 2378 | goto do_stall; |
2385 | if (e->ep.name == ep0name) | 2379 | if (e->ep.name == ep0name) |
2386 | goto do_stall; | 2380 | goto do_stall; |
@@ -2685,7 +2679,6 @@ static void net2280_remove (struct pci_dev *pdev) | |||
2685 | pci_resource_len (pdev, 0)); | 2679 | pci_resource_len (pdev, 0)); |
2686 | if (dev->enabled) | 2680 | if (dev->enabled) |
2687 | pci_disable_device (pdev); | 2681 | pci_disable_device (pdev); |
2688 | device_unregister (&dev->gadget.dev); | ||
2689 | device_remove_file (&pdev->dev, &dev_attr_registers); | 2682 | device_remove_file (&pdev->dev, &dev_attr_registers); |
2690 | pci_set_drvdata (pdev, NULL); | 2683 | pci_set_drvdata (pdev, NULL); |
2691 | 2684 | ||
@@ -2717,10 +2710,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2717 | dev->gadget.max_speed = USB_SPEED_HIGH; | 2710 | dev->gadget.max_speed = USB_SPEED_HIGH; |
2718 | 2711 | ||
2719 | /* the "gadget" abstracts/virtualizes the controller */ | 2712 | /* the "gadget" abstracts/virtualizes the controller */ |
2720 | dev_set_name(&dev->gadget.dev, "gadget"); | ||
2721 | dev->gadget.dev.parent = &pdev->dev; | ||
2722 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
2723 | dev->gadget.dev.release = gadget_release; | ||
2724 | dev->gadget.name = driver_name; | 2713 | dev->gadget.name = driver_name; |
2725 | 2714 | ||
2726 | /* now all the pci goodies ... */ | 2715 | /* now all the pci goodies ... */ |
@@ -2802,7 +2791,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2802 | goto done; | 2791 | goto done; |
2803 | } | 2792 | } |
2804 | td->dmacount = 0; /* not VALID */ | 2793 | td->dmacount = 0; /* not VALID */ |
2805 | td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID); | ||
2806 | td->dmadesc = td->dmaaddr; | 2794 | td->dmadesc = td->dmaaddr; |
2807 | dev->ep [i].dummy = td; | 2795 | dev->ep [i].dummy = td; |
2808 | } | 2796 | } |
@@ -2829,12 +2817,11 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2829 | use_dma | 2817 | use_dma |
2830 | ? (use_dma_chaining ? "chaining" : "enabled") | 2818 | ? (use_dma_chaining ? "chaining" : "enabled") |
2831 | : "disabled"); | 2819 | : "disabled"); |
2832 | retval = device_register (&dev->gadget.dev); | ||
2833 | if (retval) goto done; | ||
2834 | retval = device_create_file (&pdev->dev, &dev_attr_registers); | 2820 | retval = device_create_file (&pdev->dev, &dev_attr_registers); |
2835 | if (retval) goto done; | 2821 | if (retval) goto done; |
2836 | 2822 | ||
2837 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | 2823 | retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, |
2824 | gadget_release); | ||
2838 | if (retval) | 2825 | if (retval) |
2839 | goto done; | 2826 | goto done; |
2840 | return 0; | 2827 | return 0; |
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index def37403989a..3b344b41a167 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c | |||
@@ -37,11 +37,9 @@ | |||
37 | * the runtime footprint, and giving us at least some parts of what | 37 | * the runtime footprint, and giving us at least some parts of what |
38 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | 38 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
39 | */ | 39 | */ |
40 | #define USB_FACM_INCLUDED | 40 | #define USBF_OBEX_INCLUDED |
41 | #include "f_acm.c" | ||
42 | #include "f_ecm.c" | 41 | #include "f_ecm.c" |
43 | #include "f_obex.c" | 42 | #include "f_obex.c" |
44 | #include "f_serial.c" | ||
45 | #include "f_phonet.c" | 43 | #include "f_phonet.c" |
46 | #include "u_ether.c" | 44 | #include "u_ether.c" |
47 | 45 | ||
@@ -98,20 +96,40 @@ MODULE_AUTHOR("Felipe Balbi"); | |||
98 | MODULE_LICENSE("GPL"); | 96 | MODULE_LICENSE("GPL"); |
99 | 97 | ||
100 | /*-------------------------------------------------------------------------*/ | 98 | /*-------------------------------------------------------------------------*/ |
101 | 99 | static struct usb_function *f_acm_cfg1; | |
100 | static struct usb_function *f_acm_cfg2; | ||
102 | static u8 hostaddr[ETH_ALEN]; | 101 | static u8 hostaddr[ETH_ALEN]; |
102 | static struct eth_dev *the_dev; | ||
103 | 103 | ||
104 | enum { | 104 | enum { |
105 | TTY_PORT_OBEX0, | 105 | TTY_PORT_OBEX0, |
106 | TTY_PORT_OBEX1, | 106 | TTY_PORT_OBEX1, |
107 | TTY_PORT_ACM, | ||
108 | TTY_PORTS_MAX, | 107 | TTY_PORTS_MAX, |
109 | }; | 108 | }; |
110 | 109 | ||
111 | static unsigned char tty_lines[TTY_PORTS_MAX]; | 110 | static unsigned char tty_lines[TTY_PORTS_MAX]; |
112 | 111 | ||
112 | static struct usb_configuration nokia_config_500ma_driver = { | ||
113 | .label = "Bus Powered", | ||
114 | .bConfigurationValue = 1, | ||
115 | /* .iConfiguration = DYNAMIC */ | ||
116 | .bmAttributes = USB_CONFIG_ATT_ONE, | ||
117 | .MaxPower = 500, | ||
118 | }; | ||
119 | |||
120 | static struct usb_configuration nokia_config_100ma_driver = { | ||
121 | .label = "Self Powered", | ||
122 | .bConfigurationValue = 2, | ||
123 | /* .iConfiguration = DYNAMIC */ | ||
124 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | ||
125 | .MaxPower = 100, | ||
126 | }; | ||
127 | |||
128 | static struct usb_function_instance *fi_acm; | ||
129 | |||
113 | static int __init nokia_bind_config(struct usb_configuration *c) | 130 | static int __init nokia_bind_config(struct usb_configuration *c) |
114 | { | 131 | { |
132 | struct usb_function *f_acm; | ||
115 | int status = 0; | 133 | int status = 0; |
116 | 134 | ||
117 | status = phonet_bind_config(c); | 135 | status = phonet_bind_config(c); |
@@ -126,33 +144,32 @@ static int __init nokia_bind_config(struct usb_configuration *c) | |||
126 | if (status) | 144 | if (status) |
127 | printk(KERN_DEBUG "could not bind obex config %d\n", 0); | 145 | printk(KERN_DEBUG "could not bind obex config %d\n", 0); |
128 | 146 | ||
129 | status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]); | 147 | f_acm = usb_get_function(fi_acm); |
130 | if (status) | 148 | if (IS_ERR(f_acm)) |
131 | printk(KERN_DEBUG "could not bind acm config\n"); | 149 | return PTR_ERR(f_acm); |
132 | 150 | ||
133 | status = ecm_bind_config(c, hostaddr); | 151 | status = usb_add_function(c, f_acm); |
134 | if (status) | 152 | if (status) |
135 | printk(KERN_DEBUG "could not bind ecm config\n"); | 153 | goto err_conf; |
154 | |||
155 | status = ecm_bind_config(c, hostaddr, the_dev); | ||
156 | if (status) { | ||
157 | pr_debug("could not bind ecm config %d\n", status); | ||
158 | goto err_ecm; | ||
159 | } | ||
160 | if (c == &nokia_config_500ma_driver) | ||
161 | f_acm_cfg1 = f_acm; | ||
162 | else | ||
163 | f_acm_cfg2 = f_acm; | ||
136 | 164 | ||
137 | return status; | 165 | return status; |
166 | err_ecm: | ||
167 | usb_remove_function(c, f_acm); | ||
168 | err_conf: | ||
169 | usb_put_function(f_acm); | ||
170 | return status; | ||
138 | } | 171 | } |
139 | 172 | ||
140 | static struct usb_configuration nokia_config_500ma_driver = { | ||
141 | .label = "Bus Powered", | ||
142 | .bConfigurationValue = 1, | ||
143 | /* .iConfiguration = DYNAMIC */ | ||
144 | .bmAttributes = USB_CONFIG_ATT_ONE, | ||
145 | .MaxPower = 500, | ||
146 | }; | ||
147 | |||
148 | static struct usb_configuration nokia_config_100ma_driver = { | ||
149 | .label = "Self Powered", | ||
150 | .bConfigurationValue = 2, | ||
151 | /* .iConfiguration = DYNAMIC */ | ||
152 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | ||
153 | .MaxPower = 100, | ||
154 | }; | ||
155 | |||
156 | static int __init nokia_bind(struct usb_composite_dev *cdev) | 173 | static int __init nokia_bind(struct usb_composite_dev *cdev) |
157 | { | 174 | { |
158 | struct usb_gadget *gadget = cdev->gadget; | 175 | struct usb_gadget *gadget = cdev->gadget; |
@@ -169,9 +186,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev) | |||
169 | goto err_ether; | 186 | goto err_ether; |
170 | } | 187 | } |
171 | 188 | ||
172 | status = gether_setup(cdev->gadget, hostaddr); | 189 | the_dev = gether_setup(cdev->gadget, hostaddr); |
173 | if (status < 0) | 190 | if (IS_ERR(the_dev)) { |
191 | status = PTR_ERR(the_dev); | ||
174 | goto err_ether; | 192 | goto err_ether; |
193 | } | ||
175 | 194 | ||
176 | status = usb_string_ids_tab(cdev, strings_dev); | 195 | status = usb_string_ids_tab(cdev, strings_dev); |
177 | if (status < 0) | 196 | if (status < 0) |
@@ -185,24 +204,32 @@ static int __init nokia_bind(struct usb_composite_dev *cdev) | |||
185 | if (!gadget_supports_altsettings(gadget)) | 204 | if (!gadget_supports_altsettings(gadget)) |
186 | goto err_usb; | 205 | goto err_usb; |
187 | 206 | ||
207 | fi_acm = usb_get_function_instance("acm"); | ||
208 | if (IS_ERR(fi_acm)) | ||
209 | goto err_usb; | ||
210 | |||
188 | /* finally register the configuration */ | 211 | /* finally register the configuration */ |
189 | status = usb_add_config(cdev, &nokia_config_500ma_driver, | 212 | status = usb_add_config(cdev, &nokia_config_500ma_driver, |
190 | nokia_bind_config); | 213 | nokia_bind_config); |
191 | if (status < 0) | 214 | if (status < 0) |
192 | goto err_usb; | 215 | goto err_acm_inst; |
193 | 216 | ||
194 | status = usb_add_config(cdev, &nokia_config_100ma_driver, | 217 | status = usb_add_config(cdev, &nokia_config_100ma_driver, |
195 | nokia_bind_config); | 218 | nokia_bind_config); |
196 | if (status < 0) | 219 | if (status < 0) |
197 | goto err_usb; | 220 | goto err_put_cfg1; |
198 | 221 | ||
199 | usb_composite_overwrite_options(cdev, &coverwrite); | 222 | usb_composite_overwrite_options(cdev, &coverwrite); |
200 | dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); | 223 | dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); |
201 | 224 | ||
202 | return 0; | 225 | return 0; |
203 | 226 | ||
227 | err_put_cfg1: | ||
228 | usb_put_function(f_acm_cfg1); | ||
229 | err_acm_inst: | ||
230 | usb_put_function_instance(fi_acm); | ||
204 | err_usb: | 231 | err_usb: |
205 | gether_cleanup(); | 232 | gether_cleanup(the_dev); |
206 | err_ether: | 233 | err_ether: |
207 | cur_line--; | 234 | cur_line--; |
208 | while (cur_line >= 0) | 235 | while (cur_line >= 0) |
@@ -217,12 +244,15 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev) | |||
217 | { | 244 | { |
218 | int i; | 245 | int i; |
219 | 246 | ||
247 | usb_put_function(f_acm_cfg1); | ||
248 | usb_put_function(f_acm_cfg2); | ||
249 | usb_put_function_instance(fi_acm); | ||
220 | gphonet_cleanup(); | 250 | gphonet_cleanup(); |
221 | 251 | ||
222 | for (i = 0; i < TTY_PORTS_MAX; i++) | 252 | for (i = 0; i < TTY_PORTS_MAX; i++) |
223 | gserial_free_line(tty_lines[i]); | 253 | gserial_free_line(tty_lines[i]); |
224 | 254 | ||
225 | gether_cleanup(); | 255 | gether_cleanup(the_dev); |
226 | 256 | ||
227 | return 0; | 257 | return 0; |
228 | } | 258 | } |
@@ -247,4 +277,3 @@ static void __exit nokia_cleanup(void) | |||
247 | usb_composite_unregister(&nokia_driver); | 277 | usb_composite_unregister(&nokia_driver); |
248 | } | 278 | } |
249 | module_exit(nokia_cleanup); | 279 | module_exit(nokia_cleanup); |
250 | |||
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index f8445653577f..b8ed74a823cb 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -2067,7 +2067,6 @@ static int omap_udc_start(struct usb_gadget *g, | |||
2067 | /* hook up the driver */ | 2067 | /* hook up the driver */ |
2068 | driver->driver.bus = NULL; | 2068 | driver->driver.bus = NULL; |
2069 | udc->driver = driver; | 2069 | udc->driver = driver; |
2070 | udc->gadget.dev.driver = &driver->driver; | ||
2071 | spin_unlock_irqrestore(&udc->lock, flags); | 2070 | spin_unlock_irqrestore(&udc->lock, flags); |
2072 | 2071 | ||
2073 | if (udc->dc_clk != NULL) | 2072 | if (udc->dc_clk != NULL) |
@@ -2083,7 +2082,6 @@ static int omap_udc_start(struct usb_gadget *g, | |||
2083 | ERR("can't bind to transceiver\n"); | 2082 | ERR("can't bind to transceiver\n"); |
2084 | if (driver->unbind) { | 2083 | if (driver->unbind) { |
2085 | driver->unbind(&udc->gadget); | 2084 | driver->unbind(&udc->gadget); |
2086 | udc->gadget.dev.driver = NULL; | ||
2087 | udc->driver = NULL; | 2085 | udc->driver = NULL; |
2088 | } | 2086 | } |
2089 | goto done; | 2087 | goto done; |
@@ -2129,7 +2127,6 @@ static int omap_udc_stop(struct usb_gadget *g, | |||
2129 | udc_quiesce(udc); | 2127 | udc_quiesce(udc); |
2130 | spin_unlock_irqrestore(&udc->lock, flags); | 2128 | spin_unlock_irqrestore(&udc->lock, flags); |
2131 | 2129 | ||
2132 | udc->gadget.dev.driver = NULL; | ||
2133 | udc->driver = NULL; | 2130 | udc->driver = NULL; |
2134 | 2131 | ||
2135 | if (udc->dc_clk != NULL) | 2132 | if (udc->dc_clk != NULL) |
@@ -2631,14 +2628,6 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv) | |||
2631 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 2628 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
2632 | udc->gadget.max_speed = USB_SPEED_FULL; | 2629 | udc->gadget.max_speed = USB_SPEED_FULL; |
2633 | udc->gadget.name = driver_name; | 2630 | udc->gadget.name = driver_name; |
2634 | |||
2635 | device_initialize(&udc->gadget.dev); | ||
2636 | dev_set_name(&udc->gadget.dev, "gadget"); | ||
2637 | udc->gadget.dev.release = omap_udc_release; | ||
2638 | udc->gadget.dev.parent = &odev->dev; | ||
2639 | if (use_dma) | ||
2640 | udc->gadget.dev.dma_mask = odev->dev.dma_mask; | ||
2641 | |||
2642 | udc->transceiver = xceiv; | 2631 | udc->transceiver = xceiv; |
2643 | 2632 | ||
2644 | /* ep0 is special; put it right after the SETUP buffer */ | 2633 | /* ep0 is special; put it right after the SETUP buffer */ |
@@ -2912,14 +2901,13 @@ bad_on_1710: | |||
2912 | } | 2901 | } |
2913 | 2902 | ||
2914 | create_proc_file(); | 2903 | create_proc_file(); |
2915 | status = device_add(&udc->gadget.dev); | 2904 | status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, |
2905 | omap_udc_release); | ||
2916 | if (status) | 2906 | if (status) |
2917 | goto cleanup4; | 2907 | goto cleanup4; |
2918 | 2908 | ||
2919 | status = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2909 | return 0; |
2920 | if (!status) | 2910 | |
2921 | return status; | ||
2922 | /* If fail, fall through */ | ||
2923 | cleanup4: | 2911 | cleanup4: |
2924 | remove_proc_file(); | 2912 | remove_proc_file(); |
2925 | 2913 | ||
@@ -2990,7 +2978,6 @@ static int omap_udc_remove(struct platform_device *pdev) | |||
2990 | release_mem_region(pdev->resource[0].start, | 2978 | release_mem_region(pdev->resource[0].start, |
2991 | pdev->resource[0].end - pdev->resource[0].start + 1); | 2979 | pdev->resource[0].end - pdev->resource[0].start + 1); |
2992 | 2980 | ||
2993 | device_unregister(&udc->gadget.dev); | ||
2994 | wait_for_completion(&done); | 2981 | wait_for_completion(&done); |
2995 | 2982 | ||
2996 | return 0; | 2983 | return 0; |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index a787a8ef672b..24174e1d1564 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -358,7 +358,6 @@ struct pch_udc_dev { | |||
358 | prot_stall:1, | 358 | prot_stall:1, |
359 | irq_registered:1, | 359 | irq_registered:1, |
360 | mem_region:1, | 360 | mem_region:1, |
361 | registered:1, | ||
362 | suspended:1, | 361 | suspended:1, |
363 | connected:1, | 362 | connected:1, |
364 | vbus_session:1, | 363 | vbus_session:1, |
@@ -1441,6 +1440,8 @@ static void pch_vbus_gpio_free(struct pch_udc_dev *dev) | |||
1441 | */ | 1440 | */ |
1442 | static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, | 1441 | static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, |
1443 | int status) | 1442 | int status) |
1443 | __releases(&dev->lock) | ||
1444 | __acquires(&dev->lock) | ||
1444 | { | 1445 | { |
1445 | struct pch_udc_dev *dev; | 1446 | struct pch_udc_dev *dev; |
1446 | unsigned halted = ep->halted; | 1447 | unsigned halted = ep->halted; |
@@ -2382,6 +2383,8 @@ static void pch_udc_svc_control_in(struct pch_udc_dev *dev) | |||
2382 | * @dev: Reference to the device structure | 2383 | * @dev: Reference to the device structure |
2383 | */ | 2384 | */ |
2384 | static void pch_udc_svc_control_out(struct pch_udc_dev *dev) | 2385 | static void pch_udc_svc_control_out(struct pch_udc_dev *dev) |
2386 | __releases(&dev->lock) | ||
2387 | __acquires(&dev->lock) | ||
2385 | { | 2388 | { |
2386 | u32 stat; | 2389 | u32 stat; |
2387 | int setup_supported; | 2390 | int setup_supported; |
@@ -2989,7 +2992,6 @@ static int pch_udc_start(struct usb_gadget *g, | |||
2989 | 2992 | ||
2990 | driver->driver.bus = NULL; | 2993 | driver->driver.bus = NULL; |
2991 | dev->driver = driver; | 2994 | dev->driver = driver; |
2992 | dev->gadget.dev.driver = &driver->driver; | ||
2993 | 2995 | ||
2994 | /* get ready for ep0 traffic */ | 2996 | /* get ready for ep0 traffic */ |
2995 | pch_udc_setup_ep0(dev); | 2997 | pch_udc_setup_ep0(dev); |
@@ -3010,7 +3012,6 @@ static int pch_udc_stop(struct usb_gadget *g, | |||
3010 | pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); | 3012 | pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); |
3011 | 3013 | ||
3012 | /* Assures that there are no pending requests with this driver */ | 3014 | /* Assures that there are no pending requests with this driver */ |
3013 | dev->gadget.dev.driver = NULL; | ||
3014 | dev->driver = NULL; | 3015 | dev->driver = NULL; |
3015 | dev->connected = 0; | 3016 | dev->connected = 0; |
3016 | 3017 | ||
@@ -3078,8 +3079,6 @@ static void pch_udc_remove(struct pci_dev *pdev) | |||
3078 | pci_resource_len(pdev, PCH_UDC_PCI_BAR)); | 3079 | pci_resource_len(pdev, PCH_UDC_PCI_BAR)); |
3079 | if (dev->active) | 3080 | if (dev->active) |
3080 | pci_disable_device(pdev); | 3081 | pci_disable_device(pdev); |
3081 | if (dev->registered) | ||
3082 | device_unregister(&dev->gadget.dev); | ||
3083 | kfree(dev); | 3082 | kfree(dev); |
3084 | pci_set_drvdata(pdev, NULL); | 3083 | pci_set_drvdata(pdev, NULL); |
3085 | } | 3084 | } |
@@ -3196,21 +3195,13 @@ static int pch_udc_probe(struct pci_dev *pdev, | |||
3196 | if (retval) | 3195 | if (retval) |
3197 | goto finished; | 3196 | goto finished; |
3198 | 3197 | ||
3199 | dev_set_name(&dev->gadget.dev, "gadget"); | ||
3200 | dev->gadget.dev.parent = &pdev->dev; | ||
3201 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
3202 | dev->gadget.dev.release = gadget_release; | ||
3203 | dev->gadget.name = KBUILD_MODNAME; | 3198 | dev->gadget.name = KBUILD_MODNAME; |
3204 | dev->gadget.max_speed = USB_SPEED_HIGH; | 3199 | dev->gadget.max_speed = USB_SPEED_HIGH; |
3205 | 3200 | ||
3206 | retval = device_register(&dev->gadget.dev); | ||
3207 | if (retval) | ||
3208 | goto finished; | ||
3209 | dev->registered = 1; | ||
3210 | |||
3211 | /* Put the device in disconnected state till a driver is bound */ | 3201 | /* Put the device in disconnected state till a driver is bound */ |
3212 | pch_udc_set_disconnect(dev); | 3202 | pch_udc_set_disconnect(dev); |
3213 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | 3203 | retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, |
3204 | gadget_release); | ||
3214 | if (retval) | 3205 | if (retval) |
3215 | goto finished; | 3206 | goto finished; |
3216 | return 0; | 3207 | return 0; |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index d0f37484b6b0..ef47495dec8f 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -1263,7 +1263,6 @@ static int pxa25x_udc_start(struct usb_gadget *g, | |||
1263 | 1263 | ||
1264 | /* first hook up the driver ... */ | 1264 | /* first hook up the driver ... */ |
1265 | dev->driver = driver; | 1265 | dev->driver = driver; |
1266 | dev->gadget.dev.driver = &driver->driver; | ||
1267 | dev->pullup = 1; | 1266 | dev->pullup = 1; |
1268 | 1267 | ||
1269 | /* ... then enable host detection and ep0; and we're ready | 1268 | /* ... then enable host detection and ep0; and we're ready |
@@ -1325,7 +1324,6 @@ static int pxa25x_udc_stop(struct usb_gadget*g, | |||
1325 | if (!IS_ERR_OR_NULL(dev->transceiver)) | 1324 | if (!IS_ERR_OR_NULL(dev->transceiver)) |
1326 | (void) otg_set_peripheral(dev->transceiver->otg, NULL); | 1325 | (void) otg_set_peripheral(dev->transceiver->otg, NULL); |
1327 | 1326 | ||
1328 | dev->gadget.dev.driver = NULL; | ||
1329 | dev->driver = NULL; | 1327 | dev->driver = NULL; |
1330 | 1328 | ||
1331 | dump_state(dev); | 1329 | dump_state(dev); |
@@ -2138,17 +2136,6 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2138 | dev->timer.function = udc_watchdog; | 2136 | dev->timer.function = udc_watchdog; |
2139 | dev->timer.data = (unsigned long) dev; | 2137 | dev->timer.data = (unsigned long) dev; |
2140 | 2138 | ||
2141 | device_initialize(&dev->gadget.dev); | ||
2142 | dev->gadget.dev.parent = &pdev->dev; | ||
2143 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
2144 | |||
2145 | retval = device_add(&dev->gadget.dev); | ||
2146 | if (retval) { | ||
2147 | dev->driver = NULL; | ||
2148 | dev->gadget.dev.driver = NULL; | ||
2149 | goto err_device_add; | ||
2150 | } | ||
2151 | |||
2152 | the_controller = dev; | 2139 | the_controller = dev; |
2153 | platform_set_drvdata(pdev, dev); | 2140 | platform_set_drvdata(pdev, dev); |
2154 | 2141 | ||
@@ -2199,8 +2186,6 @@ lubbock_fail0: | |||
2199 | free_irq(irq, dev); | 2186 | free_irq(irq, dev); |
2200 | #endif | 2187 | #endif |
2201 | err_irq1: | 2188 | err_irq1: |
2202 | device_unregister(&dev->gadget.dev); | ||
2203 | err_device_add: | ||
2204 | if (gpio_is_valid(dev->mach->gpio_pullup)) | 2189 | if (gpio_is_valid(dev->mach->gpio_pullup)) |
2205 | gpio_free(dev->mach->gpio_pullup); | 2190 | gpio_free(dev->mach->gpio_pullup); |
2206 | err_gpio_pullup: | 2191 | err_gpio_pullup: |
@@ -2226,7 +2211,6 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev) | |||
2226 | return -EBUSY; | 2211 | return -EBUSY; |
2227 | 2212 | ||
2228 | usb_del_gadget_udc(&dev->gadget); | 2213 | usb_del_gadget_udc(&dev->gadget); |
2229 | device_unregister(&dev->gadget.dev); | ||
2230 | dev->pullup = 0; | 2214 | dev->pullup = 0; |
2231 | pullup(dev); | 2215 | pullup(dev); |
2232 | 2216 | ||
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 2fc867652ef5..6b4c7d95853f 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -24,14 +24,12 @@ | |||
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/prefetch.h> | 26 | #include <linux/prefetch.h> |
27 | 27 | #include <linux/byteorder/generic.h> | |
28 | #include <asm/byteorder.h> | 28 | #include <linux/platform_data/pxa2xx_udc.h> |
29 | #include <mach/hardware.h> | ||
30 | 29 | ||
31 | #include <linux/usb.h> | 30 | #include <linux/usb.h> |
32 | #include <linux/usb/ch9.h> | 31 | #include <linux/usb/ch9.h> |
33 | #include <linux/usb/gadget.h> | 32 | #include <linux/usb/gadget.h> |
34 | #include <mach/udc.h> | ||
35 | 33 | ||
36 | #include "pxa27x_udc.h" | 34 | #include "pxa27x_udc.h" |
37 | 35 | ||
@@ -611,7 +609,7 @@ static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in) | |||
611 | * | 609 | * |
612 | * Find the physical pxa27x ep, and setup its UDCCR | 610 | * Find the physical pxa27x ep, and setup its UDCCR |
613 | */ | 611 | */ |
614 | static __init void pxa_ep_setup(struct pxa_ep *ep) | 612 | static void pxa_ep_setup(struct pxa_ep *ep) |
615 | { | 613 | { |
616 | u32 new_udccr; | 614 | u32 new_udccr; |
617 | 615 | ||
@@ -633,7 +631,7 @@ static __init void pxa_ep_setup(struct pxa_ep *ep) | |||
633 | * | 631 | * |
634 | * Setup all pxa physical endpoints, except ep0 | 632 | * Setup all pxa physical endpoints, except ep0 |
635 | */ | 633 | */ |
636 | static __init void pxa_eps_setup(struct pxa_udc *dev) | 634 | static void pxa_eps_setup(struct pxa_udc *dev) |
637 | { | 635 | { |
638 | unsigned int i; | 636 | unsigned int i; |
639 | 637 | ||
@@ -1718,7 +1716,7 @@ static void udc_disable(struct pxa_udc *udc) | |||
1718 | * Initializes gadget endpoint list, endpoints locks. No action is taken | 1716 | * Initializes gadget endpoint list, endpoints locks. No action is taken |
1719 | * on the hardware. | 1717 | * on the hardware. |
1720 | */ | 1718 | */ |
1721 | static __init void udc_init_data(struct pxa_udc *dev) | 1719 | static void udc_init_data(struct pxa_udc *dev) |
1722 | { | 1720 | { |
1723 | int i; | 1721 | int i; |
1724 | struct pxa_ep *ep; | 1722 | struct pxa_ep *ep; |
@@ -1811,7 +1809,6 @@ static int pxa27x_udc_start(struct usb_gadget *g, | |||
1811 | 1809 | ||
1812 | /* first hook up the driver ... */ | 1810 | /* first hook up the driver ... */ |
1813 | udc->driver = driver; | 1811 | udc->driver = driver; |
1814 | udc->gadget.dev.driver = &driver->driver; | ||
1815 | dplus_pullup(udc, 1); | 1812 | dplus_pullup(udc, 1); |
1816 | 1813 | ||
1817 | if (!IS_ERR_OR_NULL(udc->transceiver)) { | 1814 | if (!IS_ERR_OR_NULL(udc->transceiver)) { |
@@ -1829,7 +1826,6 @@ static int pxa27x_udc_start(struct usb_gadget *g, | |||
1829 | 1826 | ||
1830 | fail: | 1827 | fail: |
1831 | udc->driver = NULL; | 1828 | udc->driver = NULL; |
1832 | udc->gadget.dev.driver = NULL; | ||
1833 | return retval; | 1829 | return retval; |
1834 | } | 1830 | } |
1835 | 1831 | ||
@@ -1871,7 +1867,6 @@ static int pxa27x_udc_stop(struct usb_gadget *g, | |||
1871 | 1867 | ||
1872 | udc->driver = NULL; | 1868 | udc->driver = NULL; |
1873 | 1869 | ||
1874 | |||
1875 | if (!IS_ERR_OR_NULL(udc->transceiver)) | 1870 | if (!IS_ERR_OR_NULL(udc->transceiver)) |
1876 | return otg_set_peripheral(udc->transceiver->otg, NULL); | 1871 | return otg_set_peripheral(udc->transceiver->otg, NULL); |
1877 | return 0; | 1872 | return 0; |
@@ -2413,7 +2408,7 @@ static struct pxa_udc memory = { | |||
2413 | * Perform basic init : allocates udc clock, creates sysfs files, requests | 2408 | * Perform basic init : allocates udc clock, creates sysfs files, requests |
2414 | * irq. | 2409 | * irq. |
2415 | */ | 2410 | */ |
2416 | static int __init pxa_udc_probe(struct platform_device *pdev) | 2411 | static int pxa_udc_probe(struct platform_device *pdev) |
2417 | { | 2412 | { |
2418 | struct resource *regs; | 2413 | struct resource *regs; |
2419 | struct pxa_udc *udc = &memory; | 2414 | struct pxa_udc *udc = &memory; |
@@ -2456,9 +2451,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2456 | goto err_map; | 2451 | goto err_map; |
2457 | } | 2452 | } |
2458 | 2453 | ||
2459 | device_initialize(&udc->gadget.dev); | ||
2460 | udc->gadget.dev.parent = &pdev->dev; | ||
2461 | udc->gadget.dev.dma_mask = NULL; | ||
2462 | udc->vbus_sensed = 0; | 2454 | udc->vbus_sensed = 0; |
2463 | 2455 | ||
2464 | the_controller = udc; | 2456 | the_controller = udc; |
@@ -2475,12 +2467,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2475 | goto err_irq; | 2467 | goto err_irq; |
2476 | } | 2468 | } |
2477 | 2469 | ||
2478 | retval = device_add(&udc->gadget.dev); | ||
2479 | if (retval) { | ||
2480 | dev_err(udc->dev, "device_add error %d\n", retval); | ||
2481 | goto err_dev_add; | ||
2482 | } | ||
2483 | |||
2484 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2470 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); |
2485 | if (retval) | 2471 | if (retval) |
2486 | goto err_add_udc; | 2472 | goto err_add_udc; |
@@ -2490,8 +2476,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2490 | return 0; | 2476 | return 0; |
2491 | 2477 | ||
2492 | err_add_udc: | 2478 | err_add_udc: |
2493 | device_unregister(&udc->gadget.dev); | ||
2494 | err_dev_add: | ||
2495 | free_irq(udc->irq, udc); | 2479 | free_irq(udc->irq, udc); |
2496 | err_irq: | 2480 | err_irq: |
2497 | iounmap(udc->regs); | 2481 | iounmap(udc->regs); |
@@ -2506,13 +2490,12 @@ err_clk: | |||
2506 | * pxa_udc_remove - removes the udc device driver | 2490 | * pxa_udc_remove - removes the udc device driver |
2507 | * @_dev: platform device | 2491 | * @_dev: platform device |
2508 | */ | 2492 | */ |
2509 | static int __exit pxa_udc_remove(struct platform_device *_dev) | 2493 | static int pxa_udc_remove(struct platform_device *_dev) |
2510 | { | 2494 | { |
2511 | struct pxa_udc *udc = platform_get_drvdata(_dev); | 2495 | struct pxa_udc *udc = platform_get_drvdata(_dev); |
2512 | int gpio = udc->mach->gpio_pullup; | 2496 | int gpio = udc->mach->gpio_pullup; |
2513 | 2497 | ||
2514 | usb_del_gadget_udc(&udc->gadget); | 2498 | usb_del_gadget_udc(&udc->gadget); |
2515 | device_del(&udc->gadget.dev); | ||
2516 | usb_gadget_unregister_driver(udc->driver); | 2499 | usb_gadget_unregister_driver(udc->driver); |
2517 | free_irq(udc->irq, udc); | 2500 | free_irq(udc->irq, udc); |
2518 | pxa_cleanup_debugfs(udc); | 2501 | pxa_cleanup_debugfs(udc); |
@@ -2625,7 +2608,8 @@ static struct platform_driver udc_driver = { | |||
2625 | .name = "pxa27x-udc", | 2608 | .name = "pxa27x-udc", |
2626 | .owner = THIS_MODULE, | 2609 | .owner = THIS_MODULE, |
2627 | }, | 2610 | }, |
2628 | .remove = __exit_p(pxa_udc_remove), | 2611 | .probe = pxa_udc_probe, |
2612 | .remove = pxa_udc_remove, | ||
2629 | .shutdown = pxa_udc_shutdown, | 2613 | .shutdown = pxa_udc_shutdown, |
2630 | #ifdef CONFIG_PM | 2614 | #ifdef CONFIG_PM |
2631 | .suspend = pxa_udc_suspend, | 2615 | .suspend = pxa_udc_suspend, |
@@ -2633,22 +2617,7 @@ static struct platform_driver udc_driver = { | |||
2633 | #endif | 2617 | #endif |
2634 | }; | 2618 | }; |
2635 | 2619 | ||
2636 | static int __init udc_init(void) | 2620 | module_platform_driver(udc_driver); |
2637 | { | ||
2638 | if (!cpu_is_pxa27x() && !cpu_is_pxa3xx()) | ||
2639 | return -ENODEV; | ||
2640 | |||
2641 | printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION); | ||
2642 | return platform_driver_probe(&udc_driver, pxa_udc_probe); | ||
2643 | } | ||
2644 | module_init(udc_init); | ||
2645 | |||
2646 | |||
2647 | static void __exit udc_exit(void) | ||
2648 | { | ||
2649 | platform_driver_unregister(&udc_driver); | ||
2650 | } | ||
2651 | module_exit(udc_exit); | ||
2652 | 2621 | ||
2653 | MODULE_DESCRIPTION(DRIVER_DESC); | 2622 | MODULE_DESCRIPTION(DRIVER_DESC); |
2654 | MODULE_AUTHOR("Robert Jarzmik"); | 2623 | MODULE_AUTHOR("Robert Jarzmik"); |
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index f46a1b77ce3e..0b742d171843 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -1837,7 +1837,6 @@ static int __exit r8a66597_remove(struct platform_device *pdev) | |||
1837 | clk_put(r8a66597->clk); | 1837 | clk_put(r8a66597->clk); |
1838 | } | 1838 | } |
1839 | 1839 | ||
1840 | device_unregister(&r8a66597->gadget.dev); | ||
1841 | kfree(r8a66597); | 1840 | kfree(r8a66597); |
1842 | return 0; | 1841 | return 0; |
1843 | } | 1842 | } |
@@ -1915,17 +1914,8 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1915 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; | 1914 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; |
1916 | 1915 | ||
1917 | r8a66597->gadget.ops = &r8a66597_gadget_ops; | 1916 | r8a66597->gadget.ops = &r8a66597_gadget_ops; |
1918 | dev_set_name(&r8a66597->gadget.dev, "gadget"); | ||
1919 | r8a66597->gadget.max_speed = USB_SPEED_HIGH; | 1917 | r8a66597->gadget.max_speed = USB_SPEED_HIGH; |
1920 | r8a66597->gadget.dev.parent = &pdev->dev; | ||
1921 | r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1922 | r8a66597->gadget.dev.release = pdev->dev.release; | ||
1923 | r8a66597->gadget.name = udc_name; | 1918 | r8a66597->gadget.name = udc_name; |
1924 | ret = device_register(&r8a66597->gadget.dev); | ||
1925 | if (ret < 0) { | ||
1926 | dev_err(&pdev->dev, "device_register failed\n"); | ||
1927 | goto clean_up; | ||
1928 | } | ||
1929 | 1919 | ||
1930 | init_timer(&r8a66597->timer); | 1920 | init_timer(&r8a66597->timer); |
1931 | r8a66597->timer.function = r8a66597_timer; | 1921 | r8a66597->timer.function = r8a66597_timer; |
@@ -1939,7 +1929,7 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1939 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", | 1929 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", |
1940 | clk_name); | 1930 | clk_name); |
1941 | ret = PTR_ERR(r8a66597->clk); | 1931 | ret = PTR_ERR(r8a66597->clk); |
1942 | goto clean_up_dev; | 1932 | goto clean_up; |
1943 | } | 1933 | } |
1944 | clk_enable(r8a66597->clk); | 1934 | clk_enable(r8a66597->clk); |
1945 | } | 1935 | } |
@@ -2007,8 +1997,6 @@ clean_up2: | |||
2007 | clk_disable(r8a66597->clk); | 1997 | clk_disable(r8a66597->clk); |
2008 | clk_put(r8a66597->clk); | 1998 | clk_put(r8a66597->clk); |
2009 | } | 1999 | } |
2010 | clean_up_dev: | ||
2011 | device_unregister(&r8a66597->gadget.dev); | ||
2012 | clean_up: | 2000 | clean_up: |
2013 | if (r8a66597) { | 2001 | if (r8a66597) { |
2014 | if (r8a66597->sudmac_reg) | 2002 | if (r8a66597->sudmac_reg) |
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index c26564f29a2c..a3cdc32115d5 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -39,8 +39,6 @@ | |||
39 | 39 | ||
40 | #include "s3c-hsotg.h" | 40 | #include "s3c-hsotg.h" |
41 | 41 | ||
42 | #define DMA_ADDR_INVALID (~((dma_addr_t)0)) | ||
43 | |||
44 | static const char * const s3c_hsotg_supply_names[] = { | 42 | static const char * const s3c_hsotg_supply_names[] = { |
45 | "vusb_d", /* digital USB supply, 1.2V */ | 43 | "vusb_d", /* digital USB supply, 1.2V */ |
46 | "vusb_a", /* analog USB supply, 1.1V */ | 44 | "vusb_a", /* analog USB supply, 1.1V */ |
@@ -405,7 +403,6 @@ static struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep, | |||
405 | 403 | ||
406 | INIT_LIST_HEAD(&req->queue); | 404 | INIT_LIST_HEAD(&req->queue); |
407 | 405 | ||
408 | req->req.dma = DMA_ADDR_INVALID; | ||
409 | return &req->req; | 406 | return &req->req; |
410 | } | 407 | } |
411 | 408 | ||
@@ -435,24 +432,12 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | |||
435 | struct s3c_hsotg_req *hs_req) | 432 | struct s3c_hsotg_req *hs_req) |
436 | { | 433 | { |
437 | struct usb_request *req = &hs_req->req; | 434 | struct usb_request *req = &hs_req->req; |
438 | enum dma_data_direction dir; | ||
439 | |||
440 | dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE; | ||
441 | 435 | ||
442 | /* ignore this if we're not moving any data */ | 436 | /* ignore this if we're not moving any data */ |
443 | if (hs_req->req.length == 0) | 437 | if (hs_req->req.length == 0) |
444 | return; | 438 | return; |
445 | 439 | ||
446 | if (hs_req->mapped) { | 440 | usb_gadget_unmap_request(&hsotg->gadget, hs_req, hs_ep->dir_in); |
447 | /* we mapped this, so unmap and remove the dma */ | ||
448 | |||
449 | dma_unmap_single(hsotg->dev, req->dma, req->length, dir); | ||
450 | |||
451 | req->dma = DMA_ADDR_INVALID; | ||
452 | hs_req->mapped = 0; | ||
453 | } else { | ||
454 | dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir); | ||
455 | } | ||
456 | } | 441 | } |
457 | 442 | ||
458 | /** | 443 | /** |
@@ -852,37 +837,16 @@ static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, | |||
852 | struct s3c_hsotg_ep *hs_ep, | 837 | struct s3c_hsotg_ep *hs_ep, |
853 | struct usb_request *req) | 838 | struct usb_request *req) |
854 | { | 839 | { |
855 | enum dma_data_direction dir; | ||
856 | struct s3c_hsotg_req *hs_req = our_req(req); | 840 | struct s3c_hsotg_req *hs_req = our_req(req); |
857 | 841 | int ret; | |
858 | dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE; | ||
859 | 842 | ||
860 | /* if the length is zero, ignore the DMA data */ | 843 | /* if the length is zero, ignore the DMA data */ |
861 | if (hs_req->req.length == 0) | 844 | if (hs_req->req.length == 0) |
862 | return 0; | 845 | return 0; |
863 | 846 | ||
864 | if (req->dma == DMA_ADDR_INVALID) { | 847 | ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); |
865 | dma_addr_t dma; | 848 | if (ret) |
866 | 849 | goto dma_error; | |
867 | dma = dma_map_single(hsotg->dev, req->buf, req->length, dir); | ||
868 | |||
869 | if (unlikely(dma_mapping_error(hsotg->dev, dma))) | ||
870 | goto dma_error; | ||
871 | |||
872 | if (dma & 3) { | ||
873 | dev_err(hsotg->dev, "%s: unaligned dma buffer\n", | ||
874 | __func__); | ||
875 | |||
876 | dma_unmap_single(hsotg->dev, dma, req->length, dir); | ||
877 | return -EINVAL; | ||
878 | } | ||
879 | |||
880 | hs_req->mapped = 1; | ||
881 | req->dma = dma; | ||
882 | } else { | ||
883 | dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir); | ||
884 | hs_req->mapped = 0; | ||
885 | } | ||
886 | 850 | ||
887 | return 0; | 851 | return 0; |
888 | 852 | ||
@@ -2961,9 +2925,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | |||
2961 | 2925 | ||
2962 | driver->driver.bus = NULL; | 2926 | driver->driver.bus = NULL; |
2963 | hsotg->driver = driver; | 2927 | hsotg->driver = driver; |
2964 | hsotg->gadget.dev.driver = &driver->driver; | ||
2965 | hsotg->gadget.dev.of_node = hsotg->dev->of_node; | 2928 | hsotg->gadget.dev.of_node = hsotg->dev->of_node; |
2966 | hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask; | ||
2967 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 2929 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
2968 | 2930 | ||
2969 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), | 2931 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
@@ -2979,7 +2941,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | |||
2979 | 2941 | ||
2980 | err: | 2942 | err: |
2981 | hsotg->driver = NULL; | 2943 | hsotg->driver = NULL; |
2982 | hsotg->gadget.dev.driver = NULL; | ||
2983 | return ret; | 2944 | return ret; |
2984 | } | 2945 | } |
2985 | 2946 | ||
@@ -3014,7 +2975,6 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | |||
3014 | 2975 | ||
3015 | hsotg->driver = NULL; | 2976 | hsotg->driver = NULL; |
3016 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 2977 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
3017 | hsotg->gadget.dev.driver = NULL; | ||
3018 | 2978 | ||
3019 | spin_unlock_irqrestore(&hsotg->lock, flags); | 2979 | spin_unlock_irqrestore(&hsotg->lock, flags); |
3020 | 2980 | ||
@@ -3484,16 +3444,6 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | |||
3484 | } | 3444 | } |
3485 | 3445 | ||
3486 | /** | 3446 | /** |
3487 | * s3c_hsotg_release - release callback for hsotg device | ||
3488 | * @dev: Device to for which release is called | ||
3489 | * | ||
3490 | * Nothing to do as the resource is allocated using devm_ API. | ||
3491 | */ | ||
3492 | static void s3c_hsotg_release(struct device *dev) | ||
3493 | { | ||
3494 | } | ||
3495 | |||
3496 | /** | ||
3497 | * s3c_hsotg_probe - probe function for hsotg driver | 3447 | * s3c_hsotg_probe - probe function for hsotg driver |
3498 | * @pdev: The platform information for the driver | 3448 | * @pdev: The platform information for the driver |
3499 | */ | 3449 | */ |
@@ -3517,7 +3467,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3517 | } | 3467 | } |
3518 | 3468 | ||
3519 | phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | 3469 | phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
3520 | if (IS_ERR_OR_NULL(phy)) { | 3470 | if (IS_ERR(phy)) { |
3521 | /* Fallback for pdata */ | 3471 | /* Fallback for pdata */ |
3522 | plat = pdev->dev.platform_data; | 3472 | plat = pdev->dev.platform_data; |
3523 | if (!plat) { | 3473 | if (!plat) { |
@@ -3567,18 +3517,10 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3567 | 3517 | ||
3568 | dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); | 3518 | dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); |
3569 | 3519 | ||
3570 | device_initialize(&hsotg->gadget.dev); | ||
3571 | |||
3572 | dev_set_name(&hsotg->gadget.dev, "gadget"); | ||
3573 | |||
3574 | hsotg->gadget.max_speed = USB_SPEED_HIGH; | 3520 | hsotg->gadget.max_speed = USB_SPEED_HIGH; |
3575 | hsotg->gadget.ops = &s3c_hsotg_gadget_ops; | 3521 | hsotg->gadget.ops = &s3c_hsotg_gadget_ops; |
3576 | hsotg->gadget.name = dev_name(dev); | 3522 | hsotg->gadget.name = dev_name(dev); |
3577 | 3523 | ||
3578 | hsotg->gadget.dev.parent = dev; | ||
3579 | hsotg->gadget.dev.dma_mask = dev->dma_mask; | ||
3580 | hsotg->gadget.dev.release = s3c_hsotg_release; | ||
3581 | |||
3582 | /* reset the system */ | 3524 | /* reset the system */ |
3583 | 3525 | ||
3584 | clk_prepare_enable(hsotg->clk); | 3526 | clk_prepare_enable(hsotg->clk); |
@@ -3658,12 +3600,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3658 | 3600 | ||
3659 | s3c_hsotg_phy_disable(hsotg); | 3601 | s3c_hsotg_phy_disable(hsotg); |
3660 | 3602 | ||
3661 | ret = device_add(&hsotg->gadget.dev); | ||
3662 | if (ret) { | ||
3663 | put_device(&hsotg->gadget.dev); | ||
3664 | goto err_ep_mem; | ||
3665 | } | ||
3666 | |||
3667 | ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); | 3603 | ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); |
3668 | if (ret) | 3604 | if (ret) |
3669 | goto err_ep_mem; | 3605 | goto err_ep_mem; |
@@ -3702,10 +3638,8 @@ static int s3c_hsotg_remove(struct platform_device *pdev) | |||
3702 | } | 3638 | } |
3703 | 3639 | ||
3704 | s3c_hsotg_phy_disable(hsotg); | 3640 | s3c_hsotg_phy_disable(hsotg); |
3705 | |||
3706 | clk_disable_unprepare(hsotg->clk); | 3641 | clk_disable_unprepare(hsotg->clk); |
3707 | 3642 | ||
3708 | device_unregister(&hsotg->gadget.dev); | ||
3709 | return 0; | 3643 | return 0; |
3710 | } | 3644 | } |
3711 | 3645 | ||
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index 458965a1b138..b1f0771fbd3d 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -283,7 +283,6 @@ static void s3c_hsudc_nuke_ep(struct s3c_hsudc_ep *hsep, int status) | |||
283 | /** | 283 | /** |
284 | * s3c_hsudc_stop_activity - Stop activity on all endpoints. | 284 | * s3c_hsudc_stop_activity - Stop activity on all endpoints. |
285 | * @hsudc: Device controller for which EP activity is to be stopped. | 285 | * @hsudc: Device controller for which EP activity is to be stopped. |
286 | * @driver: Reference to the gadget driver which is currently active. | ||
287 | * | 286 | * |
288 | * All the endpoints are stopped and any pending transfer requests if any on | 287 | * All the endpoints are stopped and any pending transfer requests if any on |
289 | * the endpoint are terminated. | 288 | * the endpoint are terminated. |
@@ -1154,7 +1153,6 @@ static int s3c_hsudc_start(struct usb_gadget *gadget, | |||
1154 | return -EBUSY; | 1153 | return -EBUSY; |
1155 | 1154 | ||
1156 | hsudc->driver = driver; | 1155 | hsudc->driver = driver; |
1157 | hsudc->gadget.dev.driver = &driver->driver; | ||
1158 | 1156 | ||
1159 | ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies), | 1157 | ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies), |
1160 | hsudc->supplies); | 1158 | hsudc->supplies); |
@@ -1190,7 +1188,6 @@ err_otg: | |||
1190 | regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); | 1188 | regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); |
1191 | err_supplies: | 1189 | err_supplies: |
1192 | hsudc->driver = NULL; | 1190 | hsudc->driver = NULL; |
1193 | hsudc->gadget.dev.driver = NULL; | ||
1194 | return ret; | 1191 | return ret; |
1195 | } | 1192 | } |
1196 | 1193 | ||
@@ -1208,7 +1205,6 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget, | |||
1208 | 1205 | ||
1209 | spin_lock_irqsave(&hsudc->lock, flags); | 1206 | spin_lock_irqsave(&hsudc->lock, flags); |
1210 | hsudc->driver = NULL; | 1207 | hsudc->driver = NULL; |
1211 | hsudc->gadget.dev.driver = NULL; | ||
1212 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; | 1208 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; |
1213 | s3c_hsudc_uninit_phy(); | 1209 | s3c_hsudc_uninit_phy(); |
1214 | 1210 | ||
@@ -1303,15 +1299,10 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1303 | 1299 | ||
1304 | spin_lock_init(&hsudc->lock); | 1300 | spin_lock_init(&hsudc->lock); |
1305 | 1301 | ||
1306 | dev_set_name(&hsudc->gadget.dev, "gadget"); | ||
1307 | |||
1308 | hsudc->gadget.max_speed = USB_SPEED_HIGH; | 1302 | hsudc->gadget.max_speed = USB_SPEED_HIGH; |
1309 | hsudc->gadget.ops = &s3c_hsudc_gadget_ops; | 1303 | hsudc->gadget.ops = &s3c_hsudc_gadget_ops; |
1310 | hsudc->gadget.name = dev_name(dev); | 1304 | hsudc->gadget.name = dev_name(dev); |
1311 | hsudc->gadget.dev.parent = dev; | ||
1312 | hsudc->gadget.dev.dma_mask = dev->dma_mask; | ||
1313 | hsudc->gadget.ep0 = &hsudc->ep[0].ep; | 1305 | hsudc->gadget.ep0 = &hsudc->ep[0].ep; |
1314 | |||
1315 | hsudc->gadget.is_otg = 0; | 1306 | hsudc->gadget.is_otg = 0; |
1316 | hsudc->gadget.is_a_peripheral = 0; | 1307 | hsudc->gadget.is_a_peripheral = 0; |
1317 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; | 1308 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; |
@@ -1345,12 +1336,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1345 | disable_irq(hsudc->irq); | 1336 | disable_irq(hsudc->irq); |
1346 | local_irq_enable(); | 1337 | local_irq_enable(); |
1347 | 1338 | ||
1348 | ret = device_register(&hsudc->gadget.dev); | ||
1349 | if (ret) { | ||
1350 | put_device(&hsudc->gadget.dev); | ||
1351 | goto err_add_device; | ||
1352 | } | ||
1353 | |||
1354 | ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget); | 1339 | ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget); |
1355 | if (ret) | 1340 | if (ret) |
1356 | goto err_add_udc; | 1341 | goto err_add_udc; |
@@ -1359,7 +1344,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1359 | 1344 | ||
1360 | return 0; | 1345 | return 0; |
1361 | err_add_udc: | 1346 | err_add_udc: |
1362 | device_unregister(&hsudc->gadget.dev); | ||
1363 | err_add_device: | 1347 | err_add_device: |
1364 | clk_disable(hsudc->uclk); | 1348 | clk_disable(hsudc->uclk); |
1365 | err_res: | 1349 | err_res: |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index 08f89652533b..d0e75e1b3ccb 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1674,7 +1674,6 @@ static int s3c2410_udc_start(struct usb_gadget *g, | |||
1674 | 1674 | ||
1675 | /* Hook the driver */ | 1675 | /* Hook the driver */ |
1676 | udc->driver = driver; | 1676 | udc->driver = driver; |
1677 | udc->gadget.dev.driver = &driver->driver; | ||
1678 | 1677 | ||
1679 | /* Enable udc */ | 1678 | /* Enable udc */ |
1680 | s3c2410_udc_enable(udc); | 1679 | s3c2410_udc_enable(udc); |
@@ -1824,17 +1823,6 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1824 | goto err_mem; | 1823 | goto err_mem; |
1825 | } | 1824 | } |
1826 | 1825 | ||
1827 | device_initialize(&udc->gadget.dev); | ||
1828 | udc->gadget.dev.parent = &pdev->dev; | ||
1829 | udc->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1830 | |||
1831 | /* Bind the driver */ | ||
1832 | retval = device_add(&udc->gadget.dev); | ||
1833 | if (retval) { | ||
1834 | dev_err(&udc->gadget.dev, "Error in device_add() : %d\n", retval); | ||
1835 | goto err_device_add; | ||
1836 | } | ||
1837 | |||
1838 | the_controller = udc; | 1826 | the_controller = udc; |
1839 | platform_set_drvdata(pdev, udc); | 1827 | platform_set_drvdata(pdev, udc); |
1840 | 1828 | ||
@@ -1923,8 +1911,6 @@ err_gpio_claim: | |||
1923 | err_int: | 1911 | err_int: |
1924 | free_irq(IRQ_USBD, udc); | 1912 | free_irq(IRQ_USBD, udc); |
1925 | err_map: | 1913 | err_map: |
1926 | device_unregister(&udc->gadget.dev); | ||
1927 | err_device_add: | ||
1928 | iounmap(base_addr); | 1914 | iounmap(base_addr); |
1929 | err_mem: | 1915 | err_mem: |
1930 | release_mem_region(rsrc_start, rsrc_len); | 1916 | release_mem_region(rsrc_start, rsrc_len); |
@@ -1946,7 +1932,6 @@ static int s3c2410_udc_remove(struct platform_device *pdev) | |||
1946 | return -EBUSY; | 1932 | return -EBUSY; |
1947 | 1933 | ||
1948 | usb_del_gadget_udc(&udc->gadget); | 1934 | usb_del_gadget_udc(&udc->gadget); |
1949 | device_unregister(&udc->gadget.dev); | ||
1950 | debugfs_remove(udc->regs_info); | 1935 | debugfs_remove(udc->regs_info); |
1951 | 1936 | ||
1952 | if (udc_info && !udc_info->udc_command && | 1937 | if (udc_info && !udc_info->udc_command && |
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 68d7bb06ebcb..1f5f978d35d5 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/device.h> | 14 | #include <linux/device.h> |
15 | #include <linux/module.h> | ||
15 | #include <linux/tty.h> | 16 | #include <linux/tty.h> |
16 | #include <linux/tty_flip.h> | 17 | #include <linux/tty_flip.h> |
17 | 18 | ||
@@ -28,18 +29,6 @@ | |||
28 | #define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR | 29 | #define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR |
29 | 30 | ||
30 | /*-------------------------------------------------------------------------*/ | 31 | /*-------------------------------------------------------------------------*/ |
31 | |||
32 | /* | ||
33 | * Kbuild is not very cooperative with respect to linking separately | ||
34 | * compiled library objects into one module. So for now we won't use | ||
35 | * separate compilation ... ensuring init/exit sections work to shrink | ||
36 | * the runtime footprint, and giving us at least some parts of what | ||
37 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
38 | */ | ||
39 | #include "f_obex.c" | ||
40 | #include "f_serial.c" | ||
41 | |||
42 | /*-------------------------------------------------------------------------*/ | ||
43 | USB_GADGET_COMPOSITE_OPTIONS(); | 32 | USB_GADGET_COMPOSITE_OPTIONS(); |
44 | 33 | ||
45 | /* Thanks to NetChip Technologies for donating this product ID. | 34 | /* Thanks to NetChip Technologies for donating this product ID. |
@@ -126,27 +115,6 @@ module_param(n_ports, uint, 0); | |||
126 | MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); | 115 | MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); |
127 | 116 | ||
128 | /*-------------------------------------------------------------------------*/ | 117 | /*-------------------------------------------------------------------------*/ |
129 | static unsigned char tty_lines[MAX_U_SERIAL_PORTS]; | ||
130 | |||
131 | static int __init serial_bind_obex_config(struct usb_configuration *c) | ||
132 | { | ||
133 | unsigned i; | ||
134 | int status = 0; | ||
135 | |||
136 | for (i = 0; i < n_ports && status == 0; i++) | ||
137 | status = obex_bind_config(c, tty_lines[i]); | ||
138 | return status; | ||
139 | } | ||
140 | |||
141 | static int __init serial_bind_gser_config(struct usb_configuration *c) | ||
142 | { | ||
143 | unsigned i; | ||
144 | int status = 0; | ||
145 | |||
146 | for (i = 0; i < n_ports && status == 0; i++) | ||
147 | status = gser_bind_config(c, tty_lines[i]); | ||
148 | return status; | ||
149 | } | ||
150 | 118 | ||
151 | static struct usb_configuration serial_config_driver = { | 119 | static struct usb_configuration serial_config_driver = { |
152 | /* .label = f(use_acm) */ | 120 | /* .label = f(use_acm) */ |
@@ -169,15 +137,12 @@ static int serial_register_ports(struct usb_composite_dev *cdev, | |||
169 | goto out; | 137 | goto out; |
170 | 138 | ||
171 | for (i = 0; i < n_ports; i++) { | 139 | for (i = 0; i < n_ports; i++) { |
172 | struct f_serial_opts *opts; | ||
173 | 140 | ||
174 | fi_serial[i] = usb_get_function_instance(f_name); | 141 | fi_serial[i] = usb_get_function_instance(f_name); |
175 | if (IS_ERR(fi_serial[i])) { | 142 | if (IS_ERR(fi_serial[i])) { |
176 | ret = PTR_ERR(fi_serial[i]); | 143 | ret = PTR_ERR(fi_serial[i]); |
177 | goto fail; | 144 | goto fail; |
178 | } | 145 | } |
179 | opts = container_of(fi_serial[i], struct f_serial_opts, func_inst); | ||
180 | opts->port_num = tty_lines[i]; | ||
181 | 146 | ||
182 | f_serial[i] = usb_get_function(fi_serial[i]); | 147 | f_serial[i] = usb_get_function(fi_serial[i]); |
183 | if (IS_ERR(f_serial[i])) { | 148 | if (IS_ERR(f_serial[i])) { |
@@ -212,13 +177,6 @@ out: | |||
212 | static int __init gs_bind(struct usb_composite_dev *cdev) | 177 | static int __init gs_bind(struct usb_composite_dev *cdev) |
213 | { | 178 | { |
214 | int status; | 179 | int status; |
215 | int cur_line; | ||
216 | |||
217 | for (cur_line = 0; cur_line < n_ports; cur_line++) { | ||
218 | status = gserial_alloc_line(&tty_lines[cur_line]); | ||
219 | if (status) | ||
220 | goto fail; | ||
221 | } | ||
222 | 180 | ||
223 | /* Allocate string descriptor numbers ... note that string | 181 | /* Allocate string descriptor numbers ... note that string |
224 | * contents can be overridden by the composite_dev glue. | 182 | * contents can be overridden by the composite_dev glue. |
@@ -243,11 +201,12 @@ static int __init gs_bind(struct usb_composite_dev *cdev) | |||
243 | "acm"); | 201 | "acm"); |
244 | usb_ep_autoconfig_reset(cdev->gadget); | 202 | usb_ep_autoconfig_reset(cdev->gadget); |
245 | } else if (use_obex) | 203 | } else if (use_obex) |
246 | status = usb_add_config(cdev, &serial_config_driver, | 204 | status = serial_register_ports(cdev, &serial_config_driver, |
247 | serial_bind_obex_config); | 205 | "obex"); |
248 | else | 206 | else { |
249 | status = usb_add_config(cdev, &serial_config_driver, | 207 | status = serial_register_ports(cdev, &serial_config_driver, |
250 | serial_bind_gser_config); | 208 | "gser"); |
209 | } | ||
251 | if (status < 0) | 210 | if (status < 0) |
252 | goto fail; | 211 | goto fail; |
253 | 212 | ||
@@ -257,9 +216,6 @@ static int __init gs_bind(struct usb_composite_dev *cdev) | |||
257 | return 0; | 216 | return 0; |
258 | 217 | ||
259 | fail: | 218 | fail: |
260 | cur_line--; | ||
261 | while (cur_line >= 0) | ||
262 | gserial_free_line(tty_lines[cur_line--]); | ||
263 | return status; | 219 | return status; |
264 | } | 220 | } |
265 | 221 | ||
@@ -270,7 +226,6 @@ static int gs_unbind(struct usb_composite_dev *cdev) | |||
270 | for (i = 0; i < n_ports; i++) { | 226 | for (i = 0; i < n_ports; i++) { |
271 | usb_put_function(f_serial[i]); | 227 | usb_put_function(f_serial[i]); |
272 | usb_put_function_instance(fi_serial[i]); | 228 | usb_put_function_instance(fi_serial[i]); |
273 | gserial_free_line(tty_lines[i]); | ||
274 | } | 229 | } |
275 | return 0; | 230 | return 0; |
276 | } | 231 | } |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index a0aa721d8b21..4b76124ce96b 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -50,7 +50,6 @@ | |||
50 | 50 | ||
51 | struct eth_dev { | 51 | struct eth_dev { |
52 | /* lock is held while accessing port_usb | 52 | /* lock is held while accessing port_usb |
53 | * or updating its backlink port_usb->ioport | ||
54 | */ | 53 | */ |
55 | spinlock_t lock; | 54 | spinlock_t lock; |
56 | struct gether *port_usb; | 55 | struct gether *port_usb; |
@@ -729,8 +728,6 @@ static int get_ether_addr(const char *str, u8 *dev_addr) | |||
729 | return 1; | 728 | return 1; |
730 | } | 729 | } |
731 | 730 | ||
732 | static struct eth_dev *the_dev; | ||
733 | |||
734 | static const struct net_device_ops eth_netdev_ops = { | 731 | static const struct net_device_ops eth_netdev_ops = { |
735 | .ndo_open = eth_open, | 732 | .ndo_open = eth_open, |
736 | .ndo_stop = eth_stop, | 733 | .ndo_stop = eth_stop, |
@@ -758,19 +755,16 @@ static struct device_type gadget_type = { | |||
758 | * | 755 | * |
759 | * Returns negative errno, or zero on success | 756 | * Returns negative errno, or zero on success |
760 | */ | 757 | */ |
761 | int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | 758 | struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], |
762 | const char *netname) | 759 | const char *netname) |
763 | { | 760 | { |
764 | struct eth_dev *dev; | 761 | struct eth_dev *dev; |
765 | struct net_device *net; | 762 | struct net_device *net; |
766 | int status; | 763 | int status; |
767 | 764 | ||
768 | if (the_dev) | ||
769 | return -EBUSY; | ||
770 | |||
771 | net = alloc_etherdev(sizeof *dev); | 765 | net = alloc_etherdev(sizeof *dev); |
772 | if (!net) | 766 | if (!net) |
773 | return -ENOMEM; | 767 | return ERR_PTR(-ENOMEM); |
774 | 768 | ||
775 | dev = netdev_priv(net); | 769 | dev = netdev_priv(net); |
776 | spin_lock_init(&dev->lock); | 770 | spin_lock_init(&dev->lock); |
@@ -807,12 +801,11 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
807 | if (status < 0) { | 801 | if (status < 0) { |
808 | dev_dbg(&g->dev, "register_netdev failed, %d\n", status); | 802 | dev_dbg(&g->dev, "register_netdev failed, %d\n", status); |
809 | free_netdev(net); | 803 | free_netdev(net); |
804 | dev = ERR_PTR(status); | ||
810 | } else { | 805 | } else { |
811 | INFO(dev, "MAC %pM\n", net->dev_addr); | 806 | INFO(dev, "MAC %pM\n", net->dev_addr); |
812 | INFO(dev, "HOST MAC %pM\n", dev->host_mac); | 807 | INFO(dev, "HOST MAC %pM\n", dev->host_mac); |
813 | 808 | ||
814 | the_dev = dev; | ||
815 | |||
816 | /* two kinds of host-initiated state changes: | 809 | /* two kinds of host-initiated state changes: |
817 | * - iff DATA transfer is active, carrier is "on" | 810 | * - iff DATA transfer is active, carrier is "on" |
818 | * - tx queueing enabled if open *and* carrier is "on" | 811 | * - tx queueing enabled if open *and* carrier is "on" |
@@ -820,7 +813,7 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
820 | netif_carrier_off(net); | 813 | netif_carrier_off(net); |
821 | } | 814 | } |
822 | 815 | ||
823 | return status; | 816 | return dev; |
824 | } | 817 | } |
825 | 818 | ||
826 | /** | 819 | /** |
@@ -829,19 +822,16 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
829 | * | 822 | * |
830 | * This is called to free all resources allocated by @gether_setup(). | 823 | * This is called to free all resources allocated by @gether_setup(). |
831 | */ | 824 | */ |
832 | void gether_cleanup(void) | 825 | void gether_cleanup(struct eth_dev *dev) |
833 | { | 826 | { |
834 | if (!the_dev) | 827 | if (!dev) |
835 | return; | 828 | return; |
836 | 829 | ||
837 | unregister_netdev(the_dev->net); | 830 | unregister_netdev(dev->net); |
838 | flush_work(&the_dev->work); | 831 | flush_work(&dev->work); |
839 | free_netdev(the_dev->net); | 832 | free_netdev(dev->net); |
840 | |||
841 | the_dev = NULL; | ||
842 | } | 833 | } |
843 | 834 | ||
844 | |||
845 | /** | 835 | /** |
846 | * gether_connect - notify network layer that USB link is active | 836 | * gether_connect - notify network layer that USB link is active |
847 | * @link: the USB link, set up with endpoints, descriptors matching | 837 | * @link: the USB link, set up with endpoints, descriptors matching |
@@ -860,7 +850,7 @@ void gether_cleanup(void) | |||
860 | */ | 850 | */ |
861 | struct net_device *gether_connect(struct gether *link) | 851 | struct net_device *gether_connect(struct gether *link) |
862 | { | 852 | { |
863 | struct eth_dev *dev = the_dev; | 853 | struct eth_dev *dev = link->ioport; |
864 | int result = 0; | 854 | int result = 0; |
865 | 855 | ||
866 | if (!dev) | 856 | if (!dev) |
@@ -895,7 +885,6 @@ struct net_device *gether_connect(struct gether *link) | |||
895 | 885 | ||
896 | spin_lock(&dev->lock); | 886 | spin_lock(&dev->lock); |
897 | dev->port_usb = link; | 887 | dev->port_usb = link; |
898 | link->ioport = dev; | ||
899 | if (netif_running(dev->net)) { | 888 | if (netif_running(dev->net)) { |
900 | if (link->open) | 889 | if (link->open) |
901 | link->open(link); | 890 | link->open(link); |
@@ -989,6 +978,5 @@ void gether_disconnect(struct gether *link) | |||
989 | 978 | ||
990 | spin_lock(&dev->lock); | 979 | spin_lock(&dev->lock); |
991 | dev->port_usb = NULL; | 980 | dev->port_usb = NULL; |
992 | link->ioport = NULL; | ||
993 | spin_unlock(&dev->lock); | 981 | spin_unlock(&dev->lock); |
994 | } | 982 | } |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 6f4a1623d854..02522338a708 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "gadget_chips.h" | 22 | #include "gadget_chips.h" |
23 | 23 | ||
24 | struct eth_dev; | ||
24 | 25 | ||
25 | /* | 26 | /* |
26 | * This represents the USB side of an "ethernet" link, managed by a USB | 27 | * This represents the USB side of an "ethernet" link, managed by a USB |
@@ -70,7 +71,7 @@ struct gether { | |||
70 | |USB_CDC_PACKET_TYPE_DIRECTED) | 71 | |USB_CDC_PACKET_TYPE_DIRECTED) |
71 | 72 | ||
72 | /* variant of gether_setup that allows customizing network device name */ | 73 | /* variant of gether_setup that allows customizing network device name */ |
73 | int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | 74 | struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], |
74 | const char *netname); | 75 | const char *netname); |
75 | 76 | ||
76 | /* netdev setup/teardown as directed by the gadget driver */ | 77 | /* netdev setup/teardown as directed by the gadget driver */ |
@@ -86,12 +87,13 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
86 | * | 87 | * |
87 | * Returns negative errno, or zero on success | 88 | * Returns negative errno, or zero on success |
88 | */ | 89 | */ |
89 | static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | 90 | static inline struct eth_dev *gether_setup(struct usb_gadget *g, |
91 | u8 ethaddr[ETH_ALEN]) | ||
90 | { | 92 | { |
91 | return gether_setup_name(g, ethaddr, "usb"); | 93 | return gether_setup_name(g, ethaddr, "usb"); |
92 | } | 94 | } |
93 | 95 | ||
94 | void gether_cleanup(void); | 96 | void gether_cleanup(struct eth_dev *dev); |
95 | 97 | ||
96 | /* connect/disconnect is handled by individual functions */ | 98 | /* connect/disconnect is handled by individual functions */ |
97 | struct net_device *gether_connect(struct gether *); | 99 | struct net_device *gether_connect(struct gether *); |
@@ -111,21 +113,24 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) | |||
111 | } | 113 | } |
112 | 114 | ||
113 | /* each configuration may bind one instance of an ethernet link */ | 115 | /* each configuration may bind one instance of an ethernet link */ |
114 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 116 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
115 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 117 | struct eth_dev *dev); |
116 | int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 118 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
117 | int eem_bind_config(struct usb_configuration *c); | 119 | struct eth_dev *dev); |
120 | int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
121 | struct eth_dev *dev); | ||
122 | int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev); | ||
118 | 123 | ||
119 | #ifdef USB_ETH_RNDIS | 124 | #ifdef USB_ETH_RNDIS |
120 | 125 | ||
121 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 126 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
122 | u32 vendorID, const char *manufacturer); | 127 | u32 vendorID, const char *manufacturer, struct eth_dev *dev); |
123 | 128 | ||
124 | #else | 129 | #else |
125 | 130 | ||
126 | static inline int | 131 | static inline int |
127 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 132 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
128 | u32 vendorID, const char *manufacturer) | 133 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) |
129 | { | 134 | { |
130 | return 0; | 135 | return 0; |
131 | } | 136 | } |
@@ -145,9 +150,9 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | |||
145 | * for calling @gether_cleanup() before module unload. | 150 | * for calling @gether_cleanup() before module unload. |
146 | */ | 151 | */ |
147 | static inline int rndis_bind_config(struct usb_configuration *c, | 152 | static inline int rndis_bind_config(struct usb_configuration *c, |
148 | u8 ethaddr[ETH_ALEN]) | 153 | u8 ethaddr[ETH_ALEN], struct eth_dev *dev) |
149 | { | 154 | { |
150 | return rndis_bind_config_vendor(c, ethaddr, 0, NULL); | 155 | return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev); |
151 | } | 156 | } |
152 | 157 | ||
153 | 158 | ||
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h index 66ce73a00509..c20210c0babd 100644 --- a/drivers/usb/gadget/u_serial.h +++ b/drivers/usb/gadget/u_serial.h | |||
@@ -65,7 +65,6 @@ int gserial_connect(struct gserial *, u8 port_num); | |||
65 | void gserial_disconnect(struct gserial *); | 65 | void gserial_disconnect(struct gserial *); |
66 | 66 | ||
67 | /* functions are bound to configurations by a config or gadget driver */ | 67 | /* functions are bound to configurations by a config or gadget driver */ |
68 | int acm_bind_config(struct usb_configuration *c, u8 port_num); | ||
69 | int gser_bind_config(struct usb_configuration *c, u8 port_num); | 68 | int gser_bind_config(struct usb_configuration *c, u8 port_num); |
70 | int obex_bind_config(struct usb_configuration *c, u8 port_num); | 69 | int obex_bind_config(struct usb_configuration *c, u8 port_num); |
71 | 70 | ||
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index f8f62c3ed65e..ffd8fa541101 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -101,6 +101,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); | |||
101 | 101 | ||
102 | /* ------------------------------------------------------------------------- */ | 102 | /* ------------------------------------------------------------------------- */ |
103 | 103 | ||
104 | void usb_gadget_set_state(struct usb_gadget *gadget, | ||
105 | enum usb_device_state state) | ||
106 | { | ||
107 | gadget->state = state; | ||
108 | sysfs_notify(&gadget->dev.kobj, NULL, "status"); | ||
109 | } | ||
110 | EXPORT_SYMBOL_GPL(usb_gadget_set_state); | ||
111 | |||
112 | /* ------------------------------------------------------------------------- */ | ||
113 | |||
104 | /** | 114 | /** |
105 | * usb_gadget_udc_start - tells usb device controller to start up | 115 | * usb_gadget_udc_start - tells usb device controller to start up |
106 | * @gadget: The gadget we want to get started | 116 | * @gadget: The gadget we want to get started |
@@ -156,15 +166,23 @@ static void usb_udc_release(struct device *dev) | |||
156 | } | 166 | } |
157 | 167 | ||
158 | static const struct attribute_group *usb_udc_attr_groups[]; | 168 | static const struct attribute_group *usb_udc_attr_groups[]; |
169 | |||
170 | static void usb_udc_nop_release(struct device *dev) | ||
171 | { | ||
172 | dev_vdbg(dev, "%s\n", __func__); | ||
173 | } | ||
174 | |||
159 | /** | 175 | /** |
160 | * usb_add_gadget_udc - adds a new gadget to the udc class driver list | 176 | * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list |
161 | * @parent: the parent device to this udc. Usually the controller | 177 | * @parent: the parent device to this udc. Usually the controller driver's |
162 | * driver's device. | 178 | * device. |
163 | * @gadget: the gadget to be added to the list | 179 | * @gadget: the gadget to be added to the list. |
180 | * @release: a gadget release function. | ||
164 | * | 181 | * |
165 | * Returns zero on success, negative errno otherwise. | 182 | * Returns zero on success, negative errno otherwise. |
166 | */ | 183 | */ |
167 | int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | 184 | int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, |
185 | void (*release)(struct device *dev)) | ||
168 | { | 186 | { |
169 | struct usb_udc *udc; | 187 | struct usb_udc *udc; |
170 | int ret = -ENOMEM; | 188 | int ret = -ENOMEM; |
@@ -173,6 +191,22 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | |||
173 | if (!udc) | 191 | if (!udc) |
174 | goto err1; | 192 | goto err1; |
175 | 193 | ||
194 | dev_set_name(&gadget->dev, "gadget"); | ||
195 | gadget->dev.parent = parent; | ||
196 | |||
197 | dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask); | ||
198 | gadget->dev.dma_parms = parent->dma_parms; | ||
199 | gadget->dev.dma_mask = parent->dma_mask; | ||
200 | |||
201 | if (release) | ||
202 | gadget->dev.release = release; | ||
203 | else | ||
204 | gadget->dev.release = usb_udc_nop_release; | ||
205 | |||
206 | ret = device_register(&gadget->dev); | ||
207 | if (ret) | ||
208 | goto err2; | ||
209 | |||
176 | device_initialize(&udc->dev); | 210 | device_initialize(&udc->dev); |
177 | udc->dev.release = usb_udc_release; | 211 | udc->dev.release = usb_udc_release; |
178 | udc->dev.class = udc_class; | 212 | udc->dev.class = udc_class; |
@@ -180,7 +214,7 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | |||
180 | udc->dev.parent = parent; | 214 | udc->dev.parent = parent; |
181 | ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); | 215 | ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); |
182 | if (ret) | 216 | if (ret) |
183 | goto err2; | 217 | goto err3; |
184 | 218 | ||
185 | udc->gadget = gadget; | 219 | udc->gadget = gadget; |
186 | 220 | ||
@@ -189,21 +223,42 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | |||
189 | 223 | ||
190 | ret = device_add(&udc->dev); | 224 | ret = device_add(&udc->dev); |
191 | if (ret) | 225 | if (ret) |
192 | goto err3; | 226 | goto err4; |
227 | |||
228 | usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); | ||
193 | 229 | ||
194 | mutex_unlock(&udc_lock); | 230 | mutex_unlock(&udc_lock); |
195 | 231 | ||
196 | return 0; | 232 | return 0; |
197 | err3: | 233 | |
234 | err4: | ||
198 | list_del(&udc->list); | 235 | list_del(&udc->list); |
199 | mutex_unlock(&udc_lock); | 236 | mutex_unlock(&udc_lock); |
200 | 237 | ||
201 | err2: | 238 | err3: |
202 | put_device(&udc->dev); | 239 | put_device(&udc->dev); |
203 | 240 | ||
241 | err2: | ||
242 | put_device(&gadget->dev); | ||
243 | kfree(udc); | ||
244 | |||
204 | err1: | 245 | err1: |
205 | return ret; | 246 | return ret; |
206 | } | 247 | } |
248 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); | ||
249 | |||
250 | /** | ||
251 | * usb_add_gadget_udc - adds a new gadget to the udc class driver list | ||
252 | * @parent: the parent device to this udc. Usually the controller | ||
253 | * driver's device. | ||
254 | * @gadget: the gadget to be added to the list | ||
255 | * | ||
256 | * Returns zero on success, negative errno otherwise. | ||
257 | */ | ||
258 | int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | ||
259 | { | ||
260 | return usb_add_gadget_udc_release(parent, gadget, NULL); | ||
261 | } | ||
207 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc); | 262 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc); |
208 | 263 | ||
209 | static void usb_gadget_remove_driver(struct usb_udc *udc) | 264 | static void usb_gadget_remove_driver(struct usb_udc *udc) |
@@ -220,6 +275,7 @@ static void usb_gadget_remove_driver(struct usb_udc *udc) | |||
220 | 275 | ||
221 | udc->driver = NULL; | 276 | udc->driver = NULL; |
222 | udc->dev.driver = NULL; | 277 | udc->dev.driver = NULL; |
278 | udc->gadget->dev.driver = NULL; | ||
223 | } | 279 | } |
224 | 280 | ||
225 | /** | 281 | /** |
@@ -254,6 +310,7 @@ found: | |||
254 | 310 | ||
255 | kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); | 311 | kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); |
256 | device_unregister(&udc->dev); | 312 | device_unregister(&udc->dev); |
313 | device_unregister(&gadget->dev); | ||
257 | } | 314 | } |
258 | EXPORT_SYMBOL_GPL(usb_del_gadget_udc); | 315 | EXPORT_SYMBOL_GPL(usb_del_gadget_udc); |
259 | 316 | ||
@@ -268,6 +325,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri | |||
268 | 325 | ||
269 | udc->driver = driver; | 326 | udc->driver = driver; |
270 | udc->dev.driver = &driver->driver; | 327 | udc->dev.driver = &driver->driver; |
328 | udc->gadget->dev.driver = &driver->driver; | ||
271 | 329 | ||
272 | ret = driver->bind(udc->gadget, driver); | 330 | ret = driver->bind(udc->gadget, driver); |
273 | if (ret) | 331 | if (ret) |
@@ -286,6 +344,7 @@ err1: | |||
286 | udc->driver->function, ret); | 344 | udc->driver->function, ret); |
287 | udc->driver = NULL; | 345 | udc->driver = NULL; |
288 | udc->dev.driver = NULL; | 346 | udc->dev.driver = NULL; |
347 | udc->gadget->dev.driver = NULL; | ||
289 | return ret; | 348 | return ret; |
290 | } | 349 | } |
291 | 350 | ||
@@ -395,6 +454,16 @@ static ssize_t usb_udc_softconn_store(struct device *dev, | |||
395 | } | 454 | } |
396 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); | 455 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); |
397 | 456 | ||
457 | static ssize_t usb_gadget_state_show(struct device *dev, | ||
458 | struct device_attribute *attr, char *buf) | ||
459 | { | ||
460 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); | ||
461 | struct usb_gadget *gadget = udc->gadget; | ||
462 | |||
463 | return sprintf(buf, "%s\n", usb_state_string(gadget->state)); | ||
464 | } | ||
465 | static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL); | ||
466 | |||
398 | #define USB_UDC_SPEED_ATTR(name, param) \ | 467 | #define USB_UDC_SPEED_ATTR(name, param) \ |
399 | ssize_t usb_udc_##param##_show(struct device *dev, \ | 468 | ssize_t usb_udc_##param##_show(struct device *dev, \ |
400 | struct device_attribute *attr, char *buf) \ | 469 | struct device_attribute *attr, char *buf) \ |
@@ -403,7 +472,7 @@ ssize_t usb_udc_##param##_show(struct device *dev, \ | |||
403 | return snprintf(buf, PAGE_SIZE, "%s\n", \ | 472 | return snprintf(buf, PAGE_SIZE, "%s\n", \ |
404 | usb_speed_string(udc->gadget->param)); \ | 473 | usb_speed_string(udc->gadget->param)); \ |
405 | } \ | 474 | } \ |
406 | static DEVICE_ATTR(name, S_IRUSR, usb_udc_##param##_show, NULL) | 475 | static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL) |
407 | 476 | ||
408 | static USB_UDC_SPEED_ATTR(current_speed, speed); | 477 | static USB_UDC_SPEED_ATTR(current_speed, speed); |
409 | static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); | 478 | static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); |
@@ -428,6 +497,7 @@ static USB_UDC_ATTR(a_alt_hnp_support); | |||
428 | static struct attribute *usb_udc_attrs[] = { | 497 | static struct attribute *usb_udc_attrs[] = { |
429 | &dev_attr_srp.attr, | 498 | &dev_attr_srp.attr, |
430 | &dev_attr_soft_connect.attr, | 499 | &dev_attr_soft_connect.attr, |
500 | &dev_attr_state.attr, | ||
431 | &dev_attr_current_speed.attr, | 501 | &dev_attr_current_speed.attr, |
432 | &dev_attr_maximum_speed.attr, | 502 | &dev_attr_maximum_speed.attr, |
433 | 503 | ||
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h index 93b0c1191115..817e9e19cecf 100644 --- a/drivers/usb/gadget/uvc.h +++ b/drivers/usb/gadget/uvc.h | |||
@@ -98,8 +98,6 @@ extern unsigned int uvc_gadget_trace_param; | |||
98 | #define DRIVER_VERSION "0.1.0" | 98 | #define DRIVER_VERSION "0.1.0" |
99 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) | 99 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) |
100 | 100 | ||
101 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
102 | |||
103 | #define UVC_NUM_REQUESTS 4 | 101 | #define UVC_NUM_REQUESTS 4 |
104 | #define UVC_MAX_REQUEST_SIZE 64 | 102 | #define UVC_MAX_REQUEST_SIZE 64 |
105 | #define UVC_MAX_EVENTS 4 | 103 | #define UVC_MAX_EVENTS 4 |
@@ -190,6 +188,7 @@ struct uvc_file_handle | |||
190 | * Functions | 188 | * Functions |
191 | */ | 189 | */ |
192 | 190 | ||
191 | extern void uvc_function_setup_continue(struct uvc_device *uvc); | ||
193 | extern void uvc_endpoint_stream(struct uvc_device *dev); | 192 | extern void uvc_endpoint_stream(struct uvc_device *dev); |
194 | 193 | ||
195 | extern void uvc_function_connect(struct uvc_device *uvc); | 194 | extern void uvc_function_connect(struct uvc_device *uvc); |
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c index 104ae9c81251..7ce27e35550b 100644 --- a/drivers/usb/gadget/uvc_queue.c +++ b/drivers/usb/gadget/uvc_queue.c | |||
@@ -10,6 +10,7 @@ | |||
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/atomic.h> | ||
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
14 | #include <linux/mm.h> | 15 | #include <linux/mm.h> |
15 | #include <linux/list.h> | 16 | #include <linux/list.h> |
@@ -18,7 +19,8 @@ | |||
18 | #include <linux/videodev2.h> | 19 | #include <linux/videodev2.h> |
19 | #include <linux/vmalloc.h> | 20 | #include <linux/vmalloc.h> |
20 | #include <linux/wait.h> | 21 | #include <linux/wait.h> |
21 | #include <linux/atomic.h> | 22 | |
23 | #include <media/videobuf2-vmalloc.h> | ||
22 | 24 | ||
23 | #include "uvc.h" | 25 | #include "uvc.h" |
24 | 26 | ||
@@ -28,330 +30,175 @@ | |||
28 | * Video queues is initialized by uvc_queue_init(). The function performs | 30 | * Video queues is initialized by uvc_queue_init(). The function performs |
29 | * basic initialization of the uvc_video_queue struct and never fails. | 31 | * basic initialization of the uvc_video_queue struct and never fails. |
30 | * | 32 | * |
31 | * Video buffer allocation and freeing are performed by uvc_alloc_buffers and | 33 | * Video buffers are managed by videobuf2. The driver uses a mutex to protect |
32 | * uvc_free_buffers respectively. The former acquires the video queue lock, | 34 | * the videobuf2 queue operations by serializing calls to videobuf2 and a |
33 | * while the later must be called with the lock held (so that allocation can | 35 | * spinlock to protect the IRQ queue that holds the buffers to be processed by |
34 | * free previously allocated buffers). Trying to free buffers that are mapped | 36 | * the driver. |
35 | * to user space will return -EBUSY. | ||
36 | * | ||
37 | * Video buffers are managed using two queues. However, unlike most USB video | ||
38 | * drivers that use an in queue and an out queue, we use a main queue to hold | ||
39 | * all queued buffers (both 'empty' and 'done' buffers), and an irq queue to | ||
40 | * hold empty buffers. This design (copied from video-buf) minimizes locking | ||
41 | * in interrupt, as only one queue is shared between interrupt and user | ||
42 | * contexts. | ||
43 | * | ||
44 | * Use cases | ||
45 | * --------- | ||
46 | * | ||
47 | * Unless stated otherwise, all operations that modify the irq buffers queue | ||
48 | * are protected by the irq spinlock. | ||
49 | * | ||
50 | * 1. The user queues the buffers, starts streaming and dequeues a buffer. | ||
51 | * | ||
52 | * The buffers are added to the main and irq queues. Both operations are | ||
53 | * protected by the queue lock, and the later is protected by the irq | ||
54 | * spinlock as well. | ||
55 | * | ||
56 | * The completion handler fetches a buffer from the irq queue and fills it | ||
57 | * with video data. If no buffer is available (irq queue empty), the handler | ||
58 | * returns immediately. | ||
59 | * | ||
60 | * When the buffer is full, the completion handler removes it from the irq | ||
61 | * queue, marks it as ready (UVC_BUF_STATE_DONE) and wakes its wait queue. | ||
62 | * At that point, any process waiting on the buffer will be woken up. If a | ||
63 | * process tries to dequeue a buffer after it has been marked ready, the | ||
64 | * dequeing will succeed immediately. | ||
65 | * | ||
66 | * 2. Buffers are queued, user is waiting on a buffer and the device gets | ||
67 | * disconnected. | ||
68 | * | ||
69 | * When the device is disconnected, the kernel calls the completion handler | ||
70 | * with an appropriate status code. The handler marks all buffers in the | ||
71 | * irq queue as being erroneous (UVC_BUF_STATE_ERROR) and wakes them up so | ||
72 | * that any process waiting on a buffer gets woken up. | ||
73 | * | ||
74 | * Waking up up the first buffer on the irq list is not enough, as the | ||
75 | * process waiting on the buffer might restart the dequeue operation | ||
76 | * immediately. | ||
77 | * | ||
78 | */ | 37 | */ |
79 | 38 | ||
80 | static void | 39 | /* ----------------------------------------------------------------------------- |
81 | uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | 40 | * videobuf2 queue operations |
82 | { | ||
83 | mutex_init(&queue->mutex); | ||
84 | spin_lock_init(&queue->irqlock); | ||
85 | INIT_LIST_HEAD(&queue->mainqueue); | ||
86 | INIT_LIST_HEAD(&queue->irqqueue); | ||
87 | queue->type = type; | ||
88 | } | ||
89 | |||
90 | /* | ||
91 | * Free the video buffers. | ||
92 | * | ||
93 | * This function must be called with the queue lock held. | ||
94 | */ | 41 | */ |
95 | static int uvc_free_buffers(struct uvc_video_queue *queue) | 42 | |
43 | static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, | ||
44 | unsigned int *nbuffers, unsigned int *nplanes, | ||
45 | unsigned int sizes[], void *alloc_ctxs[]) | ||
96 | { | 46 | { |
97 | unsigned int i; | 47 | struct uvc_video_queue *queue = vb2_get_drv_priv(vq); |
48 | struct uvc_video *video = container_of(queue, struct uvc_video, queue); | ||
98 | 49 | ||
99 | for (i = 0; i < queue->count; ++i) { | 50 | if (*nbuffers > UVC_MAX_VIDEO_BUFFERS) |
100 | if (queue->buffer[i].vma_use_count != 0) | 51 | *nbuffers = UVC_MAX_VIDEO_BUFFERS; |
101 | return -EBUSY; | ||
102 | } | ||
103 | 52 | ||
104 | if (queue->count) { | 53 | *nplanes = 1; |
105 | vfree(queue->mem); | 54 | |
106 | queue->count = 0; | 55 | sizes[0] = video->imagesize; |
107 | } | ||
108 | 56 | ||
109 | return 0; | 57 | return 0; |
110 | } | 58 | } |
111 | 59 | ||
112 | /* | 60 | static int uvc_buffer_prepare(struct vb2_buffer *vb) |
113 | * Allocate the video buffers. | ||
114 | * | ||
115 | * Pages are reserved to make sure they will not be swapped, as they will be | ||
116 | * filled in the URB completion handler. | ||
117 | * | ||
118 | * Buffers will be individually mapped, so they must all be page aligned. | ||
119 | */ | ||
120 | static int | ||
121 | uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, | ||
122 | unsigned int buflength) | ||
123 | { | 61 | { |
124 | unsigned int bufsize = PAGE_ALIGN(buflength); | 62 | struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); |
125 | unsigned int i; | 63 | struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); |
126 | void *mem = NULL; | ||
127 | int ret; | ||
128 | 64 | ||
129 | if (nbuffers > UVC_MAX_VIDEO_BUFFERS) | 65 | if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT && |
130 | nbuffers = UVC_MAX_VIDEO_BUFFERS; | 66 | vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) { |
67 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n"); | ||
68 | return -EINVAL; | ||
69 | } | ||
131 | 70 | ||
132 | mutex_lock(&queue->mutex); | 71 | if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED)) |
72 | return -ENODEV; | ||
133 | 73 | ||
134 | if ((ret = uvc_free_buffers(queue)) < 0) | 74 | buf->state = UVC_BUF_STATE_QUEUED; |
135 | goto done; | 75 | buf->mem = vb2_plane_vaddr(vb, 0); |
76 | buf->length = vb2_plane_size(vb, 0); | ||
77 | if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
78 | buf->bytesused = 0; | ||
79 | else | ||
80 | buf->bytesused = vb2_get_plane_payload(vb, 0); | ||
136 | 81 | ||
137 | /* Bail out if no buffers should be allocated. */ | 82 | return 0; |
138 | if (nbuffers == 0) | 83 | } |
139 | goto done; | ||
140 | 84 | ||
141 | /* Decrement the number of buffers until allocation succeeds. */ | 85 | static void uvc_buffer_queue(struct vb2_buffer *vb) |
142 | for (; nbuffers > 0; --nbuffers) { | 86 | { |
143 | mem = vmalloc_32(nbuffers * bufsize); | 87 | struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); |
144 | if (mem != NULL) | 88 | struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); |
145 | break; | 89 | unsigned long flags; |
146 | } | ||
147 | 90 | ||
148 | if (mem == NULL) { | 91 | spin_lock_irqsave(&queue->irqlock, flags); |
149 | ret = -ENOMEM; | ||
150 | goto done; | ||
151 | } | ||
152 | 92 | ||
153 | for (i = 0; i < nbuffers; ++i) { | 93 | if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) { |
154 | memset(&queue->buffer[i], 0, sizeof queue->buffer[i]); | 94 | list_add_tail(&buf->queue, &queue->irqqueue); |
155 | queue->buffer[i].buf.index = i; | 95 | } else { |
156 | queue->buffer[i].buf.m.offset = i * bufsize; | 96 | /* If the device is disconnected return the buffer to userspace |
157 | queue->buffer[i].buf.length = buflength; | 97 | * directly. The next QBUF call will fail with -ENODEV. |
158 | queue->buffer[i].buf.type = queue->type; | 98 | */ |
159 | queue->buffer[i].buf.sequence = 0; | 99 | buf->state = UVC_BUF_STATE_ERROR; |
160 | queue->buffer[i].buf.field = V4L2_FIELD_NONE; | 100 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR); |
161 | queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP; | ||
162 | queue->buffer[i].buf.flags = 0; | ||
163 | init_waitqueue_head(&queue->buffer[i].wait); | ||
164 | } | 101 | } |
165 | 102 | ||
166 | queue->mem = mem; | 103 | spin_unlock_irqrestore(&queue->irqlock, flags); |
167 | queue->count = nbuffers; | ||
168 | queue->buf_size = bufsize; | ||
169 | ret = nbuffers; | ||
170 | |||
171 | done: | ||
172 | mutex_unlock(&queue->mutex); | ||
173 | return ret; | ||
174 | } | 104 | } |
175 | 105 | ||
176 | static void __uvc_query_buffer(struct uvc_buffer *buf, | 106 | static struct vb2_ops uvc_queue_qops = { |
177 | struct v4l2_buffer *v4l2_buf) | 107 | .queue_setup = uvc_queue_setup, |
178 | { | 108 | .buf_prepare = uvc_buffer_prepare, |
179 | memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf); | 109 | .buf_queue = uvc_buffer_queue, |
180 | 110 | }; | |
181 | if (buf->vma_use_count) | ||
182 | v4l2_buf->flags |= V4L2_BUF_FLAG_MAPPED; | ||
183 | |||
184 | switch (buf->state) { | ||
185 | case UVC_BUF_STATE_ERROR: | ||
186 | case UVC_BUF_STATE_DONE: | ||
187 | v4l2_buf->flags |= V4L2_BUF_FLAG_DONE; | ||
188 | break; | ||
189 | case UVC_BUF_STATE_QUEUED: | ||
190 | case UVC_BUF_STATE_ACTIVE: | ||
191 | v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED; | ||
192 | break; | ||
193 | case UVC_BUF_STATE_IDLE: | ||
194 | default: | ||
195 | break; | ||
196 | } | ||
197 | } | ||
198 | 111 | ||
199 | static int | 112 | static int uvc_queue_init(struct uvc_video_queue *queue, |
200 | uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) | 113 | enum v4l2_buf_type type) |
201 | { | 114 | { |
202 | int ret = 0; | 115 | int ret; |
203 | 116 | ||
204 | mutex_lock(&queue->mutex); | 117 | queue->queue.type = type; |
205 | if (v4l2_buf->index >= queue->count) { | 118 | queue->queue.io_modes = VB2_MMAP | VB2_USERPTR; |
206 | ret = -EINVAL; | 119 | queue->queue.drv_priv = queue; |
207 | goto done; | 120 | queue->queue.buf_struct_size = sizeof(struct uvc_buffer); |
208 | } | 121 | queue->queue.ops = &uvc_queue_qops; |
122 | queue->queue.mem_ops = &vb2_vmalloc_memops; | ||
123 | ret = vb2_queue_init(&queue->queue); | ||
124 | if (ret) | ||
125 | return ret; | ||
126 | |||
127 | mutex_init(&queue->mutex); | ||
128 | spin_lock_init(&queue->irqlock); | ||
129 | INIT_LIST_HEAD(&queue->irqqueue); | ||
130 | queue->flags = 0; | ||
209 | 131 | ||
210 | __uvc_query_buffer(&queue->buffer[v4l2_buf->index], v4l2_buf); | 132 | return 0; |
133 | } | ||
211 | 134 | ||
212 | done: | 135 | /* |
136 | * Free the video buffers. | ||
137 | */ | ||
138 | static void uvc_free_buffers(struct uvc_video_queue *queue) | ||
139 | { | ||
140 | mutex_lock(&queue->mutex); | ||
141 | vb2_queue_release(&queue->queue); | ||
213 | mutex_unlock(&queue->mutex); | 142 | mutex_unlock(&queue->mutex); |
214 | return ret; | ||
215 | } | 143 | } |
216 | 144 | ||
217 | /* | 145 | /* |
218 | * Queue a video buffer. Attempting to queue a buffer that has already been | 146 | * Allocate the video buffers. |
219 | * queued will return -EINVAL. | ||
220 | */ | 147 | */ |
221 | static int | 148 | static int uvc_alloc_buffers(struct uvc_video_queue *queue, |
222 | uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) | 149 | struct v4l2_requestbuffers *rb) |
223 | { | 150 | { |
224 | struct uvc_buffer *buf; | 151 | int ret; |
225 | unsigned long flags; | ||
226 | int ret = 0; | ||
227 | 152 | ||
228 | uvc_trace(UVC_TRACE_CAPTURE, "Queuing buffer %u.\n", v4l2_buf->index); | 153 | mutex_lock(&queue->mutex); |
154 | ret = vb2_reqbufs(&queue->queue, rb); | ||
155 | mutex_unlock(&queue->mutex); | ||
229 | 156 | ||
230 | if (v4l2_buf->type != queue->type || | 157 | return ret ? ret : rb->count; |
231 | v4l2_buf->memory != V4L2_MEMORY_MMAP) { | 158 | } |
232 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) " | ||
233 | "and/or memory (%u).\n", v4l2_buf->type, | ||
234 | v4l2_buf->memory); | ||
235 | return -EINVAL; | ||
236 | } | ||
237 | 159 | ||
238 | mutex_lock(&queue->mutex); | 160 | static int uvc_query_buffer(struct uvc_video_queue *queue, |
239 | if (v4l2_buf->index >= queue->count) { | 161 | struct v4l2_buffer *buf) |
240 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Out of range index.\n"); | 162 | { |
241 | ret = -EINVAL; | 163 | int ret; |
242 | goto done; | ||
243 | } | ||
244 | 164 | ||
245 | buf = &queue->buffer[v4l2_buf->index]; | 165 | mutex_lock(&queue->mutex); |
246 | if (buf->state != UVC_BUF_STATE_IDLE) { | 166 | ret = vb2_querybuf(&queue->queue, buf); |
247 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state " | 167 | mutex_unlock(&queue->mutex); |
248 | "(%u).\n", buf->state); | ||
249 | ret = -EINVAL; | ||
250 | goto done; | ||
251 | } | ||
252 | 168 | ||
253 | if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && | 169 | return ret; |
254 | v4l2_buf->bytesused > buf->buf.length) { | 170 | } |
255 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n"); | ||
256 | ret = -EINVAL; | ||
257 | goto done; | ||
258 | } | ||
259 | 171 | ||
260 | if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) | 172 | static int uvc_queue_buffer(struct uvc_video_queue *queue, |
261 | buf->buf.bytesused = 0; | 173 | struct v4l2_buffer *buf) |
262 | else | 174 | { |
263 | buf->buf.bytesused = v4l2_buf->bytesused; | 175 | unsigned long flags; |
176 | int ret; | ||
264 | 177 | ||
178 | mutex_lock(&queue->mutex); | ||
179 | ret = vb2_qbuf(&queue->queue, buf); | ||
265 | spin_lock_irqsave(&queue->irqlock, flags); | 180 | spin_lock_irqsave(&queue->irqlock, flags); |
266 | if (queue->flags & UVC_QUEUE_DISCONNECTED) { | ||
267 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
268 | ret = -ENODEV; | ||
269 | goto done; | ||
270 | } | ||
271 | buf->state = UVC_BUF_STATE_QUEUED; | ||
272 | |||
273 | ret = (queue->flags & UVC_QUEUE_PAUSED) != 0; | 181 | ret = (queue->flags & UVC_QUEUE_PAUSED) != 0; |
274 | queue->flags &= ~UVC_QUEUE_PAUSED; | 182 | queue->flags &= ~UVC_QUEUE_PAUSED; |
275 | |||
276 | list_add_tail(&buf->stream, &queue->mainqueue); | ||
277 | list_add_tail(&buf->queue, &queue->irqqueue); | ||
278 | spin_unlock_irqrestore(&queue->irqlock, flags); | 183 | spin_unlock_irqrestore(&queue->irqlock, flags); |
279 | |||
280 | done: | ||
281 | mutex_unlock(&queue->mutex); | 184 | mutex_unlock(&queue->mutex); |
282 | return ret; | ||
283 | } | ||
284 | 185 | ||
285 | static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking) | 186 | return ret; |
286 | { | ||
287 | if (nonblocking) { | ||
288 | return (buf->state != UVC_BUF_STATE_QUEUED && | ||
289 | buf->state != UVC_BUF_STATE_ACTIVE) | ||
290 | ? 0 : -EAGAIN; | ||
291 | } | ||
292 | |||
293 | return wait_event_interruptible(buf->wait, | ||
294 | buf->state != UVC_BUF_STATE_QUEUED && | ||
295 | buf->state != UVC_BUF_STATE_ACTIVE); | ||
296 | } | 187 | } |
297 | 188 | ||
298 | /* | 189 | /* |
299 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is | 190 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is |
300 | * available. | 191 | * available. |
301 | */ | 192 | */ |
302 | static int | 193 | static int uvc_dequeue_buffer(struct uvc_video_queue *queue, |
303 | uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf, | 194 | struct v4l2_buffer *buf, int nonblocking) |
304 | int nonblocking) | ||
305 | { | 195 | { |
306 | struct uvc_buffer *buf; | 196 | int ret; |
307 | int ret = 0; | ||
308 | |||
309 | if (v4l2_buf->type != queue->type || | ||
310 | v4l2_buf->memory != V4L2_MEMORY_MMAP) { | ||
311 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) " | ||
312 | "and/or memory (%u).\n", v4l2_buf->type, | ||
313 | v4l2_buf->memory); | ||
314 | return -EINVAL; | ||
315 | } | ||
316 | 197 | ||
317 | mutex_lock(&queue->mutex); | 198 | mutex_lock(&queue->mutex); |
318 | if (list_empty(&queue->mainqueue)) { | 199 | ret = vb2_dqbuf(&queue->queue, buf, nonblocking); |
319 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Empty buffer queue.\n"); | ||
320 | ret = -EINVAL; | ||
321 | goto done; | ||
322 | } | ||
323 | |||
324 | buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream); | ||
325 | if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0) | ||
326 | goto done; | ||
327 | |||
328 | uvc_trace(UVC_TRACE_CAPTURE, "Dequeuing buffer %u (%u, %u bytes).\n", | ||
329 | buf->buf.index, buf->state, buf->buf.bytesused); | ||
330 | |||
331 | switch (buf->state) { | ||
332 | case UVC_BUF_STATE_ERROR: | ||
333 | uvc_trace(UVC_TRACE_CAPTURE, "[W] Corrupted data " | ||
334 | "(transmission error).\n"); | ||
335 | ret = -EIO; | ||
336 | case UVC_BUF_STATE_DONE: | ||
337 | buf->state = UVC_BUF_STATE_IDLE; | ||
338 | break; | ||
339 | |||
340 | case UVC_BUF_STATE_IDLE: | ||
341 | case UVC_BUF_STATE_QUEUED: | ||
342 | case UVC_BUF_STATE_ACTIVE: | ||
343 | default: | ||
344 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state %u " | ||
345 | "(driver bug?).\n", buf->state); | ||
346 | ret = -EINVAL; | ||
347 | goto done; | ||
348 | } | ||
349 | |||
350 | list_del(&buf->stream); | ||
351 | __uvc_query_buffer(buf, v4l2_buf); | ||
352 | |||
353 | done: | ||
354 | mutex_unlock(&queue->mutex); | 200 | mutex_unlock(&queue->mutex); |
201 | |||
355 | return ret; | 202 | return ret; |
356 | } | 203 | } |
357 | 204 | ||
@@ -361,105 +208,47 @@ done: | |||
361 | * This function implements video queue polling and is intended to be used by | 208 | * This function implements video queue polling and is intended to be used by |
362 | * the device poll handler. | 209 | * the device poll handler. |
363 | */ | 210 | */ |
364 | static unsigned int | 211 | static unsigned int uvc_queue_poll(struct uvc_video_queue *queue, |
365 | uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, | 212 | struct file *file, poll_table *wait) |
366 | poll_table *wait) | ||
367 | { | 213 | { |
368 | struct uvc_buffer *buf; | 214 | unsigned int ret; |
369 | unsigned int mask = 0; | ||
370 | 215 | ||
371 | mutex_lock(&queue->mutex); | 216 | mutex_lock(&queue->mutex); |
372 | if (list_empty(&queue->mainqueue)) | 217 | ret = vb2_poll(&queue->queue, file, wait); |
373 | goto done; | ||
374 | |||
375 | buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream); | ||
376 | |||
377 | poll_wait(file, &buf->wait, wait); | ||
378 | if (buf->state == UVC_BUF_STATE_DONE || | ||
379 | buf->state == UVC_BUF_STATE_ERROR) | ||
380 | mask |= POLLOUT | POLLWRNORM; | ||
381 | |||
382 | done: | ||
383 | mutex_unlock(&queue->mutex); | 218 | mutex_unlock(&queue->mutex); |
384 | return mask; | ||
385 | } | ||
386 | 219 | ||
387 | /* | 220 | return ret; |
388 | * VMA operations. | ||
389 | */ | ||
390 | static void uvc_vm_open(struct vm_area_struct *vma) | ||
391 | { | ||
392 | struct uvc_buffer *buffer = vma->vm_private_data; | ||
393 | buffer->vma_use_count++; | ||
394 | } | 221 | } |
395 | 222 | ||
396 | static void uvc_vm_close(struct vm_area_struct *vma) | 223 | static int uvc_queue_mmap(struct uvc_video_queue *queue, |
224 | struct vm_area_struct *vma) | ||
397 | { | 225 | { |
398 | struct uvc_buffer *buffer = vma->vm_private_data; | 226 | int ret; |
399 | buffer->vma_use_count--; | ||
400 | } | ||
401 | 227 | ||
402 | static struct vm_operations_struct uvc_vm_ops = { | 228 | mutex_lock(&queue->mutex); |
403 | .open = uvc_vm_open, | 229 | ret = vb2_mmap(&queue->queue, vma); |
404 | .close = uvc_vm_close, | 230 | mutex_unlock(&queue->mutex); |
405 | }; | 231 | |
232 | return ret; | ||
233 | } | ||
406 | 234 | ||
235 | #ifndef CONFIG_MMU | ||
407 | /* | 236 | /* |
408 | * Memory-map a buffer. | 237 | * Get unmapped area. |
409 | * | 238 | * |
410 | * This function implements video buffer memory mapping and is intended to be | 239 | * NO-MMU arch need this function to make mmap() work correctly. |
411 | * used by the device mmap handler. | ||
412 | */ | 240 | */ |
413 | static int | 241 | static unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, |
414 | uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) | 242 | unsigned long pgoff) |
415 | { | 243 | { |
416 | struct uvc_buffer *uninitialized_var(buffer); | 244 | unsigned long ret; |
417 | struct page *page; | ||
418 | unsigned long addr, start, size; | ||
419 | unsigned int i; | ||
420 | int ret = 0; | ||
421 | |||
422 | start = vma->vm_start; | ||
423 | size = vma->vm_end - vma->vm_start; | ||
424 | 245 | ||
425 | mutex_lock(&queue->mutex); | 246 | mutex_lock(&queue->mutex); |
426 | 247 | ret = vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0); | |
427 | for (i = 0; i < queue->count; ++i) { | ||
428 | buffer = &queue->buffer[i]; | ||
429 | if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) | ||
430 | break; | ||
431 | } | ||
432 | |||
433 | if (i == queue->count || size != queue->buf_size) { | ||
434 | ret = -EINVAL; | ||
435 | goto done; | ||
436 | } | ||
437 | |||
438 | /* | ||
439 | * VM_IO marks the area as being an mmaped region for I/O to a | ||
440 | * device. It also prevents the region from being core dumped. | ||
441 | */ | ||
442 | vma->vm_flags |= VM_IO; | ||
443 | |||
444 | addr = (unsigned long)queue->mem + buffer->buf.m.offset; | ||
445 | while (size > 0) { | ||
446 | page = vmalloc_to_page((void *)addr); | ||
447 | if ((ret = vm_insert_page(vma, start, page)) < 0) | ||
448 | goto done; | ||
449 | |||
450 | start += PAGE_SIZE; | ||
451 | addr += PAGE_SIZE; | ||
452 | size -= PAGE_SIZE; | ||
453 | } | ||
454 | |||
455 | vma->vm_ops = &uvc_vm_ops; | ||
456 | vma->vm_private_data = buffer; | ||
457 | uvc_vm_open(vma); | ||
458 | |||
459 | done: | ||
460 | mutex_unlock(&queue->mutex); | 248 | mutex_unlock(&queue->mutex); |
461 | return ret; | 249 | return ret; |
462 | } | 250 | } |
251 | #endif | ||
463 | 252 | ||
464 | /* | 253 | /* |
465 | * Cancel the video buffers queue. | 254 | * Cancel the video buffers queue. |
@@ -484,7 +273,7 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | |||
484 | queue); | 273 | queue); |
485 | list_del(&buf->queue); | 274 | list_del(&buf->queue); |
486 | buf->state = UVC_BUF_STATE_ERROR; | 275 | buf->state = UVC_BUF_STATE_ERROR; |
487 | wake_up(&buf->wait); | 276 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR); |
488 | } | 277 | } |
489 | /* This must be protected by the irqlock spinlock to avoid race | 278 | /* This must be protected by the irqlock spinlock to avoid race |
490 | * conditions between uvc_queue_buffer and the disconnection event that | 279 | * conditions between uvc_queue_buffer and the disconnection event that |
@@ -516,26 +305,33 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | |||
516 | */ | 305 | */ |
517 | static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) | 306 | static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) |
518 | { | 307 | { |
519 | unsigned int i; | 308 | unsigned long flags; |
520 | int ret = 0; | 309 | int ret = 0; |
521 | 310 | ||
522 | mutex_lock(&queue->mutex); | 311 | mutex_lock(&queue->mutex); |
523 | if (enable) { | 312 | if (enable) { |
524 | if (uvc_queue_streaming(queue)) { | 313 | ret = vb2_streamon(&queue->queue, queue->queue.type); |
525 | ret = -EBUSY; | 314 | if (ret < 0) |
526 | goto done; | 315 | goto done; |
527 | } | 316 | |
528 | queue->sequence = 0; | 317 | queue->sequence = 0; |
529 | queue->flags |= UVC_QUEUE_STREAMING; | ||
530 | queue->buf_used = 0; | 318 | queue->buf_used = 0; |
531 | } else { | 319 | } else { |
532 | uvc_queue_cancel(queue, 0); | 320 | ret = vb2_streamoff(&queue->queue, queue->queue.type); |
533 | INIT_LIST_HEAD(&queue->mainqueue); | 321 | if (ret < 0) |
322 | goto done; | ||
534 | 323 | ||
535 | for (i = 0; i < queue->count; ++i) | 324 | spin_lock_irqsave(&queue->irqlock, flags); |
536 | queue->buffer[i].state = UVC_BUF_STATE_IDLE; | 325 | INIT_LIST_HEAD(&queue->irqqueue); |
537 | 326 | ||
538 | queue->flags &= ~UVC_QUEUE_STREAMING; | 327 | /* |
328 | * FIXME: We need to clear the DISCONNECTED flag to ensure that | ||
329 | * applications will be able to queue buffers for the next | ||
330 | * streaming run. However, clearing it here doesn't guarantee | ||
331 | * that the device will be reconnected in the meantime. | ||
332 | */ | ||
333 | queue->flags &= ~UVC_QUEUE_DISCONNECTED; | ||
334 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
539 | } | 335 | } |
540 | 336 | ||
541 | done: | 337 | done: |
@@ -544,15 +340,15 @@ done: | |||
544 | } | 340 | } |
545 | 341 | ||
546 | /* called with &queue_irqlock held.. */ | 342 | /* called with &queue_irqlock held.. */ |
547 | static struct uvc_buffer * | 343 | static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, |
548 | uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) | 344 | struct uvc_buffer *buf) |
549 | { | 345 | { |
550 | struct uvc_buffer *nextbuf; | 346 | struct uvc_buffer *nextbuf; |
551 | 347 | ||
552 | if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && | 348 | if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && |
553 | buf->buf.length != buf->buf.bytesused) { | 349 | buf->length != buf->bytesused) { |
554 | buf->state = UVC_BUF_STATE_QUEUED; | 350 | buf->state = UVC_BUF_STATE_QUEUED; |
555 | buf->buf.bytesused = 0; | 351 | vb2_set_plane_payload(&buf->buf, 0, 0); |
556 | return buf; | 352 | return buf; |
557 | } | 353 | } |
558 | 354 | ||
@@ -563,10 +359,18 @@ uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) | |||
563 | else | 359 | else |
564 | nextbuf = NULL; | 360 | nextbuf = NULL; |
565 | 361 | ||
566 | buf->buf.sequence = queue->sequence++; | 362 | /* |
567 | do_gettimeofday(&buf->buf.timestamp); | 363 | * FIXME: with videobuf2, the sequence number or timestamp fields |
364 | * are valid only for video capture devices and the UVC gadget usually | ||
365 | * is a video output device. Keeping these until the specs are clear on | ||
366 | * this aspect. | ||
367 | */ | ||
368 | buf->buf.v4l2_buf.sequence = queue->sequence++; | ||
369 | do_gettimeofday(&buf->buf.v4l2_buf.timestamp); | ||
370 | |||
371 | vb2_set_plane_payload(&buf->buf, 0, buf->bytesused); | ||
372 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE); | ||
568 | 373 | ||
569 | wake_up(&buf->wait); | ||
570 | return nextbuf; | 374 | return nextbuf; |
571 | } | 375 | } |
572 | 376 | ||
diff --git a/drivers/usb/gadget/uvc_queue.h b/drivers/usb/gadget/uvc_queue.h index 1812a8ecc5d0..8e76ce982f1e 100644 --- a/drivers/usb/gadget/uvc_queue.h +++ b/drivers/usb/gadget/uvc_queue.h | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <linux/kernel.h> | 6 | #include <linux/kernel.h> |
7 | #include <linux/poll.h> | 7 | #include <linux/poll.h> |
8 | #include <linux/videodev2.h> | 8 | #include <linux/videodev2.h> |
9 | #include <media/videobuf2-core.h> | ||
9 | 10 | ||
10 | /* Maximum frame size in bytes, for sanity checking. */ | 11 | /* Maximum frame size in bytes, for sanity checking. */ |
11 | #define UVC_MAX_FRAME_SIZE (16*1024*1024) | 12 | #define UVC_MAX_FRAME_SIZE (16*1024*1024) |
@@ -25,42 +26,35 @@ enum uvc_buffer_state { | |||
25 | }; | 26 | }; |
26 | 27 | ||
27 | struct uvc_buffer { | 28 | struct uvc_buffer { |
28 | unsigned long vma_use_count; | 29 | struct vb2_buffer buf; |
29 | struct list_head stream; | ||
30 | |||
31 | /* Touched by interrupt handler. */ | ||
32 | struct v4l2_buffer buf; | ||
33 | struct list_head queue; | 30 | struct list_head queue; |
34 | wait_queue_head_t wait; | 31 | |
35 | enum uvc_buffer_state state; | 32 | enum uvc_buffer_state state; |
33 | void *mem; | ||
34 | unsigned int length; | ||
35 | unsigned int bytesused; | ||
36 | }; | 36 | }; |
37 | 37 | ||
38 | #define UVC_QUEUE_STREAMING (1 << 0) | 38 | #define UVC_QUEUE_DISCONNECTED (1 << 0) |
39 | #define UVC_QUEUE_DISCONNECTED (1 << 1) | 39 | #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1) |
40 | #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2) | 40 | #define UVC_QUEUE_PAUSED (1 << 2) |
41 | #define UVC_QUEUE_PAUSED (1 << 3) | ||
42 | 41 | ||
43 | struct uvc_video_queue { | 42 | struct uvc_video_queue { |
44 | enum v4l2_buf_type type; | 43 | struct vb2_queue queue; |
44 | struct mutex mutex; /* Protects queue */ | ||
45 | 45 | ||
46 | void *mem; | ||
47 | unsigned int flags; | 46 | unsigned int flags; |
48 | __u32 sequence; | 47 | __u32 sequence; |
49 | 48 | ||
50 | unsigned int count; | ||
51 | unsigned int buf_size; | ||
52 | unsigned int buf_used; | 49 | unsigned int buf_used; |
53 | struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS]; | ||
54 | struct mutex mutex; /* protects buffers and mainqueue */ | ||
55 | spinlock_t irqlock; /* protects irqqueue */ | ||
56 | 50 | ||
57 | struct list_head mainqueue; | 51 | spinlock_t irqlock; /* Protects flags and irqqueue */ |
58 | struct list_head irqqueue; | 52 | struct list_head irqqueue; |
59 | }; | 53 | }; |
60 | 54 | ||
61 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) | 55 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
62 | { | 56 | { |
63 | return queue->flags & UVC_QUEUE_STREAMING; | 57 | return vb2_is_streaming(&queue->queue); |
64 | } | 58 | } |
65 | 59 | ||
66 | #endif /* __KERNEL__ */ | 60 | #endif /* __KERNEL__ */ |
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c index 2ca9386d655b..ad48e81155e2 100644 --- a/drivers/usb/gadget/uvc_v4l2.c +++ b/drivers/usb/gadget/uvc_v4l2.c | |||
@@ -41,9 +41,8 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data) | |||
41 | 41 | ||
42 | req->length = min_t(unsigned int, uvc->event_length, data->length); | 42 | req->length = min_t(unsigned int, uvc->event_length, data->length); |
43 | req->zero = data->length < uvc->event_length; | 43 | req->zero = data->length < uvc->event_length; |
44 | req->dma = DMA_ADDR_INVALID; | ||
45 | 44 | ||
46 | memcpy(req->buf, data->data, data->length); | 45 | memcpy(req->buf, data->data, req->length); |
47 | 46 | ||
48 | return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL); | 47 | return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL); |
49 | } | 48 | } |
@@ -148,16 +147,13 @@ uvc_v4l2_release(struct file *file) | |||
148 | uvc_function_disconnect(uvc); | 147 | uvc_function_disconnect(uvc); |
149 | 148 | ||
150 | uvc_video_enable(video, 0); | 149 | uvc_video_enable(video, 0); |
151 | mutex_lock(&video->queue.mutex); | 150 | uvc_free_buffers(&video->queue); |
152 | if (uvc_free_buffers(&video->queue) < 0) | ||
153 | printk(KERN_ERR "uvc_v4l2_release: Unable to free " | ||
154 | "buffers.\n"); | ||
155 | mutex_unlock(&video->queue.mutex); | ||
156 | 151 | ||
157 | file->private_data = NULL; | 152 | file->private_data = NULL; |
158 | v4l2_fh_del(&handle->vfh); | 153 | v4l2_fh_del(&handle->vfh); |
159 | v4l2_fh_exit(&handle->vfh); | 154 | v4l2_fh_exit(&handle->vfh); |
160 | kfree(handle); | 155 | kfree(handle); |
156 | |||
161 | return 0; | 157 | return 0; |
162 | } | 158 | } |
163 | 159 | ||
@@ -178,9 +174,9 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
178 | struct v4l2_capability *cap = arg; | 174 | struct v4l2_capability *cap = arg; |
179 | 175 | ||
180 | memset(cap, 0, sizeof *cap); | 176 | memset(cap, 0, sizeof *cap); |
181 | strncpy(cap->driver, "g_uvc", sizeof(cap->driver)); | 177 | strlcpy(cap->driver, "g_uvc", sizeof(cap->driver)); |
182 | strncpy(cap->card, cdev->gadget->name, sizeof(cap->card)); | 178 | strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card)); |
183 | strncpy(cap->bus_info, dev_name(&cdev->gadget->dev), | 179 | strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev), |
184 | sizeof cap->bus_info); | 180 | sizeof cap->bus_info); |
185 | cap->version = DRIVER_VERSION_NUMBER; | 181 | cap->version = DRIVER_VERSION_NUMBER; |
186 | cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; | 182 | cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; |
@@ -192,7 +188,7 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
192 | { | 188 | { |
193 | struct v4l2_format *fmt = arg; | 189 | struct v4l2_format *fmt = arg; |
194 | 190 | ||
195 | if (fmt->type != video->queue.type) | 191 | if (fmt->type != video->queue.queue.type) |
196 | return -EINVAL; | 192 | return -EINVAL; |
197 | 193 | ||
198 | return uvc_v4l2_get_format(video, fmt); | 194 | return uvc_v4l2_get_format(video, fmt); |
@@ -202,7 +198,7 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
202 | { | 198 | { |
203 | struct v4l2_format *fmt = arg; | 199 | struct v4l2_format *fmt = arg; |
204 | 200 | ||
205 | if (fmt->type != video->queue.type) | 201 | if (fmt->type != video->queue.queue.type) |
206 | return -EINVAL; | 202 | return -EINVAL; |
207 | 203 | ||
208 | return uvc_v4l2_set_format(video, fmt); | 204 | return uvc_v4l2_set_format(video, fmt); |
@@ -213,16 +209,13 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
213 | { | 209 | { |
214 | struct v4l2_requestbuffers *rb = arg; | 210 | struct v4l2_requestbuffers *rb = arg; |
215 | 211 | ||
216 | if (rb->type != video->queue.type || | 212 | if (rb->type != video->queue.queue.type) |
217 | rb->memory != V4L2_MEMORY_MMAP) | ||
218 | return -EINVAL; | 213 | return -EINVAL; |
219 | 214 | ||
220 | ret = uvc_alloc_buffers(&video->queue, rb->count, | 215 | ret = uvc_alloc_buffers(&video->queue, rb); |
221 | video->imagesize); | ||
222 | if (ret < 0) | 216 | if (ret < 0) |
223 | return ret; | 217 | return ret; |
224 | 218 | ||
225 | rb->count = ret; | ||
226 | ret = 0; | 219 | ret = 0; |
227 | break; | 220 | break; |
228 | } | 221 | } |
@@ -231,9 +224,6 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
231 | { | 224 | { |
232 | struct v4l2_buffer *buf = arg; | 225 | struct v4l2_buffer *buf = arg; |
233 | 226 | ||
234 | if (buf->type != video->queue.type) | ||
235 | return -EINVAL; | ||
236 | |||
237 | return uvc_query_buffer(&video->queue, buf); | 227 | return uvc_query_buffer(&video->queue, buf); |
238 | } | 228 | } |
239 | 229 | ||
@@ -251,24 +241,36 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
251 | { | 241 | { |
252 | int *type = arg; | 242 | int *type = arg; |
253 | 243 | ||
254 | if (*type != video->queue.type) | 244 | if (*type != video->queue.queue.type) |
255 | return -EINVAL; | 245 | return -EINVAL; |
256 | 246 | ||
257 | return uvc_video_enable(video, 1); | 247 | /* Enable UVC video. */ |
248 | ret = uvc_video_enable(video, 1); | ||
249 | if (ret < 0) | ||
250 | return ret; | ||
251 | |||
252 | /* | ||
253 | * Complete the alternate setting selection setup phase now that | ||
254 | * userspace is ready to provide video frames. | ||
255 | */ | ||
256 | uvc_function_setup_continue(uvc); | ||
257 | uvc->state = UVC_STATE_STREAMING; | ||
258 | |||
259 | return 0; | ||
258 | } | 260 | } |
259 | 261 | ||
260 | case VIDIOC_STREAMOFF: | 262 | case VIDIOC_STREAMOFF: |
261 | { | 263 | { |
262 | int *type = arg; | 264 | int *type = arg; |
263 | 265 | ||
264 | if (*type != video->queue.type) | 266 | if (*type != video->queue.queue.type) |
265 | return -EINVAL; | 267 | return -EINVAL; |
266 | 268 | ||
267 | return uvc_video_enable(video, 0); | 269 | return uvc_video_enable(video, 0); |
268 | } | 270 | } |
269 | 271 | ||
270 | /* Events */ | 272 | /* Events */ |
271 | case VIDIOC_DQEVENT: | 273 | case VIDIOC_DQEVENT: |
272 | { | 274 | { |
273 | struct v4l2_event *event = arg; | 275 | struct v4l2_event *event = arg; |
274 | 276 | ||
@@ -333,17 +335,21 @@ uvc_v4l2_poll(struct file *file, poll_table *wait) | |||
333 | { | 335 | { |
334 | struct video_device *vdev = video_devdata(file); | 336 | struct video_device *vdev = video_devdata(file); |
335 | struct uvc_device *uvc = video_get_drvdata(vdev); | 337 | struct uvc_device *uvc = video_get_drvdata(vdev); |
336 | struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data); | ||
337 | unsigned int mask = 0; | ||
338 | 338 | ||
339 | poll_wait(file, &handle->vfh.wait, wait); | 339 | return uvc_queue_poll(&uvc->video.queue, file, wait); |
340 | if (v4l2_event_pending(&handle->vfh)) | 340 | } |
341 | mask |= POLLPRI; | ||
342 | 341 | ||
343 | mask |= uvc_queue_poll(&uvc->video.queue, file, wait); | 342 | #ifndef CONFIG_MMU |
343 | static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, | ||
344 | unsigned long addr, unsigned long len, unsigned long pgoff, | ||
345 | unsigned long flags) | ||
346 | { | ||
347 | struct video_device *vdev = video_devdata(file); | ||
348 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
344 | 349 | ||
345 | return mask; | 350 | return uvc_queue_get_unmapped_area(&uvc->video.queue, pgoff); |
346 | } | 351 | } |
352 | #endif | ||
347 | 353 | ||
348 | static struct v4l2_file_operations uvc_v4l2_fops = { | 354 | static struct v4l2_file_operations uvc_v4l2_fops = { |
349 | .owner = THIS_MODULE, | 355 | .owner = THIS_MODULE, |
@@ -352,5 +358,8 @@ static struct v4l2_file_operations uvc_v4l2_fops = { | |||
352 | .ioctl = uvc_v4l2_ioctl, | 358 | .ioctl = uvc_v4l2_ioctl, |
353 | .mmap = uvc_v4l2_mmap, | 359 | .mmap = uvc_v4l2_mmap, |
354 | .poll = uvc_v4l2_poll, | 360 | .poll = uvc_v4l2_poll, |
361 | #ifndef CONFIG_MMU | ||
362 | .get_unmapped_area = uvc_v4l2_get_unmapped_area, | ||
363 | #endif | ||
355 | }; | 364 | }; |
356 | 365 | ||
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c index b0e53a8ea4f7..71e896d4c5ae 100644 --- a/drivers/usb/gadget/uvc_video.c +++ b/drivers/usb/gadget/uvc_video.c | |||
@@ -32,7 +32,7 @@ uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf, | |||
32 | data[0] = 2; | 32 | data[0] = 2; |
33 | data[1] = UVC_STREAM_EOH | video->fid; | 33 | data[1] = UVC_STREAM_EOH | video->fid; |
34 | 34 | ||
35 | if (buf->buf.bytesused - video->queue.buf_used <= len - 2) | 35 | if (buf->bytesused - video->queue.buf_used <= len - 2) |
36 | data[1] |= UVC_STREAM_EOF; | 36 | data[1] |= UVC_STREAM_EOF; |
37 | 37 | ||
38 | return 2; | 38 | return 2; |
@@ -47,8 +47,8 @@ uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf, | |||
47 | void *mem; | 47 | void *mem; |
48 | 48 | ||
49 | /* Copy video data to the USB buffer. */ | 49 | /* Copy video data to the USB buffer. */ |
50 | mem = queue->mem + buf->buf.m.offset + queue->buf_used; | 50 | mem = buf->mem + queue->buf_used; |
51 | nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used); | 51 | nbytes = min((unsigned int)len, buf->bytesused - queue->buf_used); |
52 | 52 | ||
53 | memcpy(data, mem, nbytes); | 53 | memcpy(data, mem, nbytes); |
54 | queue->buf_used += nbytes; | 54 | queue->buf_used += nbytes; |
@@ -82,7 +82,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video, | |||
82 | req->length = video->req_size - len; | 82 | req->length = video->req_size - len; |
83 | req->zero = video->payload_size == video->max_payload_size; | 83 | req->zero = video->payload_size == video->max_payload_size; |
84 | 84 | ||
85 | if (buf->buf.bytesused == video->queue.buf_used) { | 85 | if (buf->bytesused == video->queue.buf_used) { |
86 | video->queue.buf_used = 0; | 86 | video->queue.buf_used = 0; |
87 | buf->state = UVC_BUF_STATE_DONE; | 87 | buf->state = UVC_BUF_STATE_DONE; |
88 | uvc_queue_next_buffer(&video->queue, buf); | 88 | uvc_queue_next_buffer(&video->queue, buf); |
@@ -92,7 +92,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video, | |||
92 | } | 92 | } |
93 | 93 | ||
94 | if (video->payload_size == video->max_payload_size || | 94 | if (video->payload_size == video->max_payload_size || |
95 | buf->buf.bytesused == video->queue.buf_used) | 95 | buf->bytesused == video->queue.buf_used) |
96 | video->payload_size = 0; | 96 | video->payload_size = 0; |
97 | } | 97 | } |
98 | 98 | ||
@@ -115,7 +115,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video, | |||
115 | 115 | ||
116 | req->length = video->req_size - len; | 116 | req->length = video->req_size - len; |
117 | 117 | ||
118 | if (buf->buf.bytesused == video->queue.buf_used) { | 118 | if (buf->bytesused == video->queue.buf_used) { |
119 | video->queue.buf_used = 0; | 119 | video->queue.buf_used = 0; |
120 | buf->state = UVC_BUF_STATE_DONE; | 120 | buf->state = UVC_BUF_STATE_DONE; |
121 | uvc_queue_next_buffer(&video->queue, buf); | 121 | uvc_queue_next_buffer(&video->queue, buf); |
@@ -161,6 +161,7 @@ static void | |||
161 | uvc_video_complete(struct usb_ep *ep, struct usb_request *req) | 161 | uvc_video_complete(struct usb_ep *ep, struct usb_request *req) |
162 | { | 162 | { |
163 | struct uvc_video *video = req->context; | 163 | struct uvc_video *video = req->context; |
164 | struct uvc_video_queue *queue = &video->queue; | ||
164 | struct uvc_buffer *buf; | 165 | struct uvc_buffer *buf; |
165 | unsigned long flags; | 166 | unsigned long flags; |
166 | int ret; | 167 | int ret; |
@@ -169,13 +170,15 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) | |||
169 | case 0: | 170 | case 0: |
170 | break; | 171 | break; |
171 | 172 | ||
172 | case -ESHUTDOWN: | 173 | case -ESHUTDOWN: /* disconnect from host. */ |
173 | printk(KERN_INFO "VS request cancelled.\n"); | 174 | printk(KERN_INFO "VS request cancelled.\n"); |
175 | uvc_queue_cancel(queue, 1); | ||
174 | goto requeue; | 176 | goto requeue; |
175 | 177 | ||
176 | default: | 178 | default: |
177 | printk(KERN_INFO "VS request completed with status %d.\n", | 179 | printk(KERN_INFO "VS request completed with status %d.\n", |
178 | req->status); | 180 | req->status); |
181 | uvc_queue_cancel(queue, 0); | ||
179 | goto requeue; | 182 | goto requeue; |
180 | } | 183 | } |
181 | 184 | ||
@@ -229,13 +232,18 @@ uvc_video_free_requests(struct uvc_video *video) | |||
229 | static int | 232 | static int |
230 | uvc_video_alloc_requests(struct uvc_video *video) | 233 | uvc_video_alloc_requests(struct uvc_video *video) |
231 | { | 234 | { |
235 | unsigned int req_size; | ||
232 | unsigned int i; | 236 | unsigned int i; |
233 | int ret = -ENOMEM; | 237 | int ret = -ENOMEM; |
234 | 238 | ||
235 | BUG_ON(video->req_size); | 239 | BUG_ON(video->req_size); |
236 | 240 | ||
241 | req_size = video->ep->maxpacket | ||
242 | * max_t(unsigned int, video->ep->maxburst, 1) | ||
243 | * (video->ep->mult + 1); | ||
244 | |||
237 | for (i = 0; i < UVC_NUM_REQUESTS; ++i) { | 245 | for (i = 0; i < UVC_NUM_REQUESTS; ++i) { |
238 | video->req_buffer[i] = kmalloc(video->ep->maxpacket, GFP_KERNEL); | 246 | video->req_buffer[i] = kmalloc(req_size, GFP_KERNEL); |
239 | if (video->req_buffer[i] == NULL) | 247 | if (video->req_buffer[i] == NULL) |
240 | goto error; | 248 | goto error; |
241 | 249 | ||
@@ -245,14 +253,14 @@ uvc_video_alloc_requests(struct uvc_video *video) | |||
245 | 253 | ||
246 | video->req[i]->buf = video->req_buffer[i]; | 254 | video->req[i]->buf = video->req_buffer[i]; |
247 | video->req[i]->length = 0; | 255 | video->req[i]->length = 0; |
248 | video->req[i]->dma = DMA_ADDR_INVALID; | ||
249 | video->req[i]->complete = uvc_video_complete; | 256 | video->req[i]->complete = uvc_video_complete; |
250 | video->req[i]->context = video; | 257 | video->req[i]->context = video; |
251 | 258 | ||
252 | list_add_tail(&video->req[i]->list, &video->req_free); | 259 | list_add_tail(&video->req[i]->list, &video->req_free); |
253 | } | 260 | } |
254 | 261 | ||
255 | video->req_size = video->ep->maxpacket; | 262 | video->req_size = req_size; |
263 | |||
256 | return 0; | 264 | return 0; |
257 | 265 | ||
258 | error: | 266 | error: |
@@ -309,7 +317,8 @@ uvc_video_pump(struct uvc_video *video) | |||
309 | video->encode(req, video, buf); | 317 | video->encode(req, video, buf); |
310 | 318 | ||
311 | /* Queue the USB request */ | 319 | /* Queue the USB request */ |
312 | if ((ret = usb_ep_queue(video->ep, req, GFP_KERNEL)) < 0) { | 320 | ret = usb_ep_queue(video->ep, req, GFP_ATOMIC); |
321 | if (ret < 0) { | ||
313 | printk(KERN_INFO "Failed to queue request (%d)\n", ret); | 322 | printk(KERN_INFO "Failed to queue request (%d)\n", ret); |
314 | usb_ep_set_halt(video->ep); | 323 | usb_ep_set_halt(video->ep); |
315 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 324 | spin_unlock_irqrestore(&video->queue.irqlock, flags); |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 2f682219e257..f7af0984743b 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -180,6 +180,7 @@ config USB_EHCI_TEGRA | |||
180 | boolean "NVIDIA Tegra HCD support" | 180 | boolean "NVIDIA Tegra HCD support" |
181 | depends on USB_EHCI_HCD && ARCH_TEGRA | 181 | depends on USB_EHCI_HCD && ARCH_TEGRA |
182 | select USB_EHCI_ROOT_HUB_TT | 182 | select USB_EHCI_ROOT_HUB_TT |
183 | select USB_PHY | ||
183 | help | 184 | help |
184 | This driver enables support for the internal USB Host Controllers | 185 | This driver enables support for the internal USB Host Controllers |
185 | found in NVIDIA Tegra SoCs. The controllers are EHCI compliant. | 186 | found in NVIDIA Tegra SoCs. The controllers are EHCI compliant. |
@@ -301,7 +302,6 @@ config USB_OHCI_HCD | |||
301 | tristate "OHCI HCD support" | 302 | tristate "OHCI HCD support" |
302 | depends on USB && USB_ARCH_HAS_OHCI | 303 | depends on USB && USB_ARCH_HAS_OHCI |
303 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 | 304 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 |
304 | select USB_OTG_UTILS if ARCH_OMAP | ||
305 | depends on USB_ISP1301 || !ARCH_LPC32XX | 305 | depends on USB_ISP1301 || !ARCH_LPC32XX |
306 | ---help--- | 306 | ---help--- |
307 | The Open Host Controller Interface (OHCI) is a standard for accessing | 307 | The Open Host Controller Interface (OHCI) is a standard for accessing |
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c index 88a49c87e748..ebf410311957 100644 --- a/drivers/usb/host/ehci-msm.c +++ b/drivers/usb/host/ehci-msm.c | |||
@@ -145,7 +145,7 @@ static int ehci_msm_probe(struct platform_device *pdev) | |||
145 | * management. | 145 | * management. |
146 | */ | 146 | */ |
147 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 147 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
148 | if (IS_ERR_OR_NULL(phy)) { | 148 | if (IS_ERR(phy)) { |
149 | dev_err(&pdev->dev, "unable to find transceiver\n"); | 149 | dev_err(&pdev->dev, "unable to find transceiver\n"); |
150 | ret = -ENODEV; | 150 | ret = -ENODEV; |
151 | goto put_hcd; | 151 | goto put_hcd; |
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c index 5cd9f96ed92d..402062973f03 100644 --- a/drivers/usb/host/ehci-mv.c +++ b/drivers/usb/host/ehci-mv.c | |||
@@ -33,25 +33,17 @@ struct ehci_hcd_mv { | |||
33 | 33 | ||
34 | struct mv_usb_platform_data *pdata; | 34 | struct mv_usb_platform_data *pdata; |
35 | 35 | ||
36 | /* clock source and total clock number */ | 36 | struct clk *clk; |
37 | unsigned int clknum; | ||
38 | struct clk *clk[0]; | ||
39 | }; | 37 | }; |
40 | 38 | ||
41 | static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv) | 39 | static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv) |
42 | { | 40 | { |
43 | unsigned int i; | 41 | clk_prepare_enable(ehci_mv->clk); |
44 | |||
45 | for (i = 0; i < ehci_mv->clknum; i++) | ||
46 | clk_prepare_enable(ehci_mv->clk[i]); | ||
47 | } | 42 | } |
48 | 43 | ||
49 | static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv) | 44 | static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv) |
50 | { | 45 | { |
51 | unsigned int i; | 46 | clk_disable_unprepare(ehci_mv->clk); |
52 | |||
53 | for (i = 0; i < ehci_mv->clknum; i++) | ||
54 | clk_disable_unprepare(ehci_mv->clk[i]); | ||
55 | } | 47 | } |
56 | 48 | ||
57 | static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) | 49 | static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) |
@@ -144,9 +136,8 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
144 | struct ehci_hcd *ehci; | 136 | struct ehci_hcd *ehci; |
145 | struct ehci_hcd_mv *ehci_mv; | 137 | struct ehci_hcd_mv *ehci_mv; |
146 | struct resource *r; | 138 | struct resource *r; |
147 | int clk_i, retval = -ENODEV; | 139 | int retval = -ENODEV; |
148 | u32 offset; | 140 | u32 offset; |
149 | size_t size; | ||
150 | 141 | ||
151 | if (!pdata) { | 142 | if (!pdata) { |
152 | dev_err(&pdev->dev, "missing platform_data\n"); | 143 | dev_err(&pdev->dev, "missing platform_data\n"); |
@@ -160,8 +151,7 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
160 | if (!hcd) | 151 | if (!hcd) |
161 | return -ENOMEM; | 152 | return -ENOMEM; |
162 | 153 | ||
163 | size = sizeof(*ehci_mv) + sizeof(struct clk *) * pdata->clknum; | 154 | ehci_mv = devm_kzalloc(&pdev->dev, sizeof(*ehci_mv), GFP_KERNEL); |
164 | ehci_mv = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); | ||
165 | if (ehci_mv == NULL) { | 155 | if (ehci_mv == NULL) { |
166 | dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); | 156 | dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); |
167 | retval = -ENOMEM; | 157 | retval = -ENOMEM; |
@@ -172,16 +162,11 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
172 | ehci_mv->pdata = pdata; | 162 | ehci_mv->pdata = pdata; |
173 | ehci_mv->hcd = hcd; | 163 | ehci_mv->hcd = hcd; |
174 | 164 | ||
175 | ehci_mv->clknum = pdata->clknum; | 165 | ehci_mv->clk = devm_clk_get(&pdev->dev, NULL); |
176 | for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) { | 166 | if (IS_ERR(ehci_mv->clk)) { |
177 | ehci_mv->clk[clk_i] = | 167 | dev_err(&pdev->dev, "error getting clock\n"); |
178 | devm_clk_get(&pdev->dev, pdata->clkname[clk_i]); | 168 | retval = PTR_ERR(ehci_mv->clk); |
179 | if (IS_ERR(ehci_mv->clk[clk_i])) { | 169 | goto err_clear_drvdata; |
180 | dev_err(&pdev->dev, "error get clck \"%s\"\n", | ||
181 | pdata->clkname[clk_i]); | ||
182 | retval = PTR_ERR(ehci_mv->clk[clk_i]); | ||
183 | goto err_clear_drvdata; | ||
184 | } | ||
185 | } | 170 | } |
186 | 171 | ||
187 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs"); | 172 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs"); |
@@ -240,12 +225,16 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
240 | 225 | ||
241 | ehci_mv->mode = pdata->mode; | 226 | ehci_mv->mode = pdata->mode; |
242 | if (ehci_mv->mode == MV_USB_MODE_OTG) { | 227 | if (ehci_mv->mode == MV_USB_MODE_OTG) { |
243 | #ifdef CONFIG_USB_OTG_UTILS | ||
244 | ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 228 | ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
245 | if (IS_ERR_OR_NULL(ehci_mv->otg)) { | 229 | if (IS_ERR(ehci_mv->otg)) { |
246 | dev_err(&pdev->dev, | 230 | retval = PTR_ERR(ehci_mv->otg); |
247 | "unable to find transceiver\n"); | 231 | |
248 | retval = -ENODEV; | 232 | if (retval == -ENXIO) |
233 | dev_info(&pdev->dev, "MV_USB_MODE_OTG " | ||
234 | "must have CONFIG_USB_PHY enabled\n"); | ||
235 | else | ||
236 | dev_err(&pdev->dev, | ||
237 | "unable to find transceiver\n"); | ||
249 | goto err_disable_clk; | 238 | goto err_disable_clk; |
250 | } | 239 | } |
251 | 240 | ||
@@ -258,11 +247,6 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
258 | } | 247 | } |
259 | /* otg will enable clock before use as host */ | 248 | /* otg will enable clock before use as host */ |
260 | mv_ehci_disable(ehci_mv); | 249 | mv_ehci_disable(ehci_mv); |
261 | #else | ||
262 | dev_info(&pdev->dev, "MV_USB_MODE_OTG " | ||
263 | "must have CONFIG_USB_OTG_UTILS enabled\n"); | ||
264 | goto err_disable_clk; | ||
265 | #endif | ||
266 | } else { | 250 | } else { |
267 | if (pdata->set_vbus) | 251 | if (pdata->set_vbus) |
268 | pdata->set_vbus(1); | 252 | pdata->set_vbus(1); |
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c index 738490e6d429..43a2a16732f5 100644 --- a/drivers/usb/host/ehci-s5p.c +++ b/drivers/usb/host/ehci-s5p.c | |||
@@ -140,7 +140,7 @@ static int s5p_ehci_probe(struct platform_device *pdev) | |||
140 | return -ENOMEM; | 140 | return -ENOMEM; |
141 | 141 | ||
142 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 142 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
143 | if (IS_ERR_OR_NULL(phy)) { | 143 | if (IS_ERR(phy)) { |
144 | /* Fallback to pdata */ | 144 | /* Fallback to pdata */ |
145 | if (!pdata) { | 145 | if (!pdata) { |
146 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | 146 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); |
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 4f3cfb83f862..ed201ae879cb 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -773,16 +773,14 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
773 | goto fail_phy; | 773 | goto fail_phy; |
774 | } | 774 | } |
775 | 775 | ||
776 | #ifdef CONFIG_USB_OTG_UTILS | ||
777 | if (pdata->operating_mode == TEGRA_USB_OTG) { | 776 | if (pdata->operating_mode == TEGRA_USB_OTG) { |
778 | tegra->transceiver = | 777 | tegra->transceiver = |
779 | devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 778 | devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
780 | if (!IS_ERR_OR_NULL(tegra->transceiver)) | 779 | if (!IS_ERR(tegra->transceiver)) |
781 | otg_set_host(tegra->transceiver->otg, &hcd->self); | 780 | otg_set_host(tegra->transceiver->otg, &hcd->self); |
782 | } else { | 781 | } else { |
783 | tegra->transceiver = ERR_PTR(-ENODEV); | 782 | tegra->transceiver = ERR_PTR(-ENODEV); |
784 | } | 783 | } |
785 | #endif | ||
786 | 784 | ||
787 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | 785 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
788 | if (err) { | 786 | if (err) { |
@@ -801,10 +799,8 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
801 | return err; | 799 | return err; |
802 | 800 | ||
803 | fail: | 801 | fail: |
804 | #ifdef CONFIG_USB_OTG_UTILS | 802 | if (!IS_ERR(tegra->transceiver)) |
805 | if (!IS_ERR_OR_NULL(tegra->transceiver)) | ||
806 | otg_set_host(tegra->transceiver->otg, NULL); | 803 | otg_set_host(tegra->transceiver->otg, NULL); |
807 | #endif | ||
808 | fail_phy: | 804 | fail_phy: |
809 | usb_phy_shutdown(hcd->phy); | 805 | usb_phy_shutdown(hcd->phy); |
810 | fail_io: | 806 | fail_io: |
@@ -823,10 +819,8 @@ static int tegra_ehci_remove(struct platform_device *pdev) | |||
823 | pm_runtime_disable(&pdev->dev); | 819 | pm_runtime_disable(&pdev->dev); |
824 | pm_runtime_put_noidle(&pdev->dev); | 820 | pm_runtime_put_noidle(&pdev->dev); |
825 | 821 | ||
826 | #ifdef CONFIG_USB_OTG_UTILS | 822 | if (!IS_ERR(tegra->transceiver)) |
827 | if (!IS_ERR_OR_NULL(tegra->transceiver)) | ||
828 | otg_set_host(tegra->transceiver->otg, NULL); | 823 | otg_set_host(tegra->transceiver->otg, NULL); |
829 | #endif | ||
830 | 824 | ||
831 | usb_phy_shutdown(hcd->phy); | 825 | usb_phy_shutdown(hcd->phy); |
832 | usb_remove_hcd(hcd); | 826 | usb_remove_hcd(hcd); |
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index e3b7e85120e4..4b469e050208 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c | |||
@@ -128,7 +128,7 @@ static int exynos_ohci_probe(struct platform_device *pdev) | |||
128 | return -ENOMEM; | 128 | return -ENOMEM; |
129 | 129 | ||
130 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 130 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
131 | if (IS_ERR_OR_NULL(phy)) { | 131 | if (IS_ERR(phy)) { |
132 | /* Fallback to pdata */ | 132 | /* Fallback to pdata */ |
133 | if (!pdata) { | 133 | if (!pdata) { |
134 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | 134 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); |
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 05e51432dd2f..47442d35b6fc 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig | |||
@@ -7,7 +7,6 @@ | |||
7 | config USB_MUSB_HDRC | 7 | config USB_MUSB_HDRC |
8 | tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' | 8 | tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' |
9 | depends on USB && USB_GADGET | 9 | depends on USB && USB_GADGET |
10 | select USB_OTG_UTILS | ||
11 | help | 10 | help |
12 | Say Y here if your system has a dual role high speed USB | 11 | Say Y here if your system has a dual role high speed USB |
13 | controller based on the Mentor Graphics silicon IP. Then | 12 | controller based on the Mentor Graphics silicon IP. Then |
@@ -34,10 +33,12 @@ choice | |||
34 | config USB_MUSB_DAVINCI | 33 | config USB_MUSB_DAVINCI |
35 | tristate "DaVinci" | 34 | tristate "DaVinci" |
36 | depends on ARCH_DAVINCI_DMx | 35 | depends on ARCH_DAVINCI_DMx |
36 | depends on BROKEN | ||
37 | 37 | ||
38 | config USB_MUSB_DA8XX | 38 | config USB_MUSB_DA8XX |
39 | tristate "DA8xx/OMAP-L1x" | 39 | tristate "DA8xx/OMAP-L1x" |
40 | depends on ARCH_DAVINCI_DA8XX | 40 | depends on ARCH_DAVINCI_DA8XX |
41 | depends on BROKEN | ||
41 | 42 | ||
42 | config USB_MUSB_TUSB6010 | 43 | config USB_MUSB_TUSB6010 |
43 | tristate "TUSB6010" | 44 | tristate "TUSB6010" |
@@ -53,7 +54,6 @@ config USB_MUSB_AM35X | |||
53 | 54 | ||
54 | config USB_MUSB_DSPS | 55 | config USB_MUSB_DSPS |
55 | tristate "TI DSPS platforms" | 56 | tristate "TI DSPS platforms" |
56 | depends on SOC_TI81XX || SOC_AM33XX | ||
57 | 57 | ||
58 | config USB_MUSB_BLACKFIN | 58 | config USB_MUSB_BLACKFIN |
59 | tristate "Blackfin" | 59 | tristate "Blackfin" |
@@ -61,12 +61,12 @@ config USB_MUSB_BLACKFIN | |||
61 | 61 | ||
62 | config USB_MUSB_UX500 | 62 | config USB_MUSB_UX500 |
63 | tristate "U8500 and U5500" | 63 | tristate "U8500 and U5500" |
64 | depends on (ARCH_U8500 && AB8500_USB) | ||
65 | 64 | ||
66 | endchoice | 65 | endchoice |
67 | 66 | ||
68 | choice | 67 | choice |
69 | prompt 'MUSB DMA mode' | 68 | prompt 'MUSB DMA mode' |
69 | default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM | ||
70 | default USB_UX500_DMA if USB_MUSB_UX500 | 70 | default USB_UX500_DMA if USB_MUSB_UX500 |
71 | default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN | 71 | default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN |
72 | default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI | 72 | default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI |
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c index 59eea219034a..2231850c0625 100644 --- a/drivers/usb/musb/am35x.c +++ b/drivers/usb/musb/am35x.c | |||
@@ -149,7 +149,7 @@ static void otg_timer(unsigned long _musb) | |||
149 | */ | 149 | */ |
150 | devctl = musb_readb(mregs, MUSB_DEVCTL); | 150 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
151 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 151 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, |
152 | otg_state_string(musb->xceiv->state)); | 152 | usb_otg_state_string(musb->xceiv->state)); |
153 | 153 | ||
154 | spin_lock_irqsave(&musb->lock, flags); | 154 | spin_lock_irqsave(&musb->lock, flags); |
155 | switch (musb->xceiv->state) { | 155 | switch (musb->xceiv->state) { |
@@ -195,7 +195,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
195 | if (musb->is_active || (musb->a_wait_bcon == 0 && | 195 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
196 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 196 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { |
197 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 197 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
198 | otg_state_string(musb->xceiv->state)); | 198 | usb_otg_state_string(musb->xceiv->state)); |
199 | del_timer(&otg_workaround); | 199 | del_timer(&otg_workaround); |
200 | last_timer = jiffies; | 200 | last_timer = jiffies; |
201 | return; | 201 | return; |
@@ -208,7 +208,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
208 | last_timer = timeout; | 208 | last_timer = timeout; |
209 | 209 | ||
210 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 210 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", |
211 | otg_state_string(musb->xceiv->state), | 211 | usb_otg_state_string(musb->xceiv->state), |
212 | jiffies_to_msecs(timeout - jiffies)); | 212 | jiffies_to_msecs(timeout - jiffies)); |
213 | mod_timer(&otg_workaround, timeout); | 213 | mod_timer(&otg_workaround, timeout); |
214 | } | 214 | } |
@@ -298,7 +298,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci) | |||
298 | /* NOTE: this must complete power-on within 100 ms. */ | 298 | /* NOTE: this must complete power-on within 100 ms. */ |
299 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 299 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
300 | drvvbus ? "on" : "off", | 300 | drvvbus ? "on" : "off", |
301 | otg_state_string(musb->xceiv->state), | 301 | usb_otg_state_string(musb->xceiv->state), |
302 | err ? " ERROR" : "", | 302 | err ? " ERROR" : "", |
303 | devctl); | 303 | devctl); |
304 | ret = IRQ_HANDLED; | 304 | ret = IRQ_HANDLED; |
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c index dbb31b30c7fa..5e63b160db0c 100644 --- a/drivers/usb/musb/blackfin.c +++ b/drivers/usb/musb/blackfin.c | |||
@@ -280,13 +280,13 @@ static void musb_conn_timer_handler(unsigned long _musb) | |||
280 | break; | 280 | break; |
281 | default: | 281 | default: |
282 | dev_dbg(musb->controller, "%s state not handled\n", | 282 | dev_dbg(musb->controller, "%s state not handled\n", |
283 | otg_state_string(musb->xceiv->state)); | 283 | usb_otg_state_string(musb->xceiv->state)); |
284 | break; | 284 | break; |
285 | } | 285 | } |
286 | spin_unlock_irqrestore(&musb->lock, flags); | 286 | spin_unlock_irqrestore(&musb->lock, flags); |
287 | 287 | ||
288 | dev_dbg(musb->controller, "state is %s\n", | 288 | dev_dbg(musb->controller, "state is %s\n", |
289 | otg_state_string(musb->xceiv->state)); | 289 | usb_otg_state_string(musb->xceiv->state)); |
290 | } | 290 | } |
291 | 291 | ||
292 | static void bfin_musb_enable(struct musb *musb) | 292 | static void bfin_musb_enable(struct musb *musb) |
@@ -307,7 +307,7 @@ static void bfin_musb_set_vbus(struct musb *musb, int is_on) | |||
307 | 307 | ||
308 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " | 308 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
309 | /* otg %3x conf %08x prcm %08x */ "\n", | 309 | /* otg %3x conf %08x prcm %08x */ "\n", |
310 | otg_state_string(musb->xceiv->state), | 310 | usb_otg_state_string(musb->xceiv->state), |
311 | musb_readb(musb->mregs, MUSB_DEVCTL)); | 311 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
312 | } | 312 | } |
313 | 313 | ||
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c index f522000e8f06..9db211ee15b5 100644 --- a/drivers/usb/musb/cppi_dma.c +++ b/drivers/usb/musb/cppi_dma.c | |||
@@ -435,7 +435,6 @@ cppi_rndis_update(struct cppi_channel *c, int is_rx, | |||
435 | } | 435 | } |
436 | } | 436 | } |
437 | 437 | ||
438 | #ifdef CONFIG_USB_MUSB_DEBUG | ||
439 | static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) | 438 | static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) |
440 | { | 439 | { |
441 | pr_debug("RXBD/%s %08x: " | 440 | pr_debug("RXBD/%s %08x: " |
@@ -444,21 +443,16 @@ static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) | |||
444 | bd->hw_next, bd->hw_bufp, bd->hw_off_len, | 443 | bd->hw_next, bd->hw_bufp, bd->hw_off_len, |
445 | bd->hw_options); | 444 | bd->hw_options); |
446 | } | 445 | } |
447 | #endif | ||
448 | 446 | ||
449 | static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx) | 447 | static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx) |
450 | { | 448 | { |
451 | #ifdef CONFIG_USB_MUSB_DEBUG | ||
452 | struct cppi_descriptor *bd; | 449 | struct cppi_descriptor *bd; |
453 | 450 | ||
454 | if (!_dbg_level(level)) | ||
455 | return; | ||
456 | cppi_dump_rx(level, rx, tag); | 451 | cppi_dump_rx(level, rx, tag); |
457 | if (rx->last_processed) | 452 | if (rx->last_processed) |
458 | cppi_dump_rxbd("last", rx->last_processed); | 453 | cppi_dump_rxbd("last", rx->last_processed); |
459 | for (bd = rx->head; bd; bd = bd->next) | 454 | for (bd = rx->head; bd; bd = bd->next) |
460 | cppi_dump_rxbd("active", bd); | 455 | cppi_dump_rxbd("active", bd); |
461 | #endif | ||
462 | } | 456 | } |
463 | 457 | ||
464 | 458 | ||
@@ -784,6 +778,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket) | |||
784 | void __iomem *tibase = musb->ctrl_base; | 778 | void __iomem *tibase = musb->ctrl_base; |
785 | int is_rndis = 0; | 779 | int is_rndis = 0; |
786 | struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram; | 780 | struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram; |
781 | struct cppi_descriptor *d; | ||
787 | 782 | ||
788 | if (onepacket) { | 783 | if (onepacket) { |
789 | /* almost every USB driver, host or peripheral side */ | 784 | /* almost every USB driver, host or peripheral side */ |
@@ -897,14 +892,8 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket) | |||
897 | bd->hw_options |= CPPI_SOP_SET; | 892 | bd->hw_options |= CPPI_SOP_SET; |
898 | tail->hw_options |= CPPI_EOP_SET; | 893 | tail->hw_options |= CPPI_EOP_SET; |
899 | 894 | ||
900 | #ifdef CONFIG_USB_MUSB_DEBUG | 895 | for (d = rx->head; d; d = d->next) |
901 | if (_dbg_level(5)) { | 896 | cppi_dump_rxbd("S", d); |
902 | struct cppi_descriptor *d; | ||
903 | |||
904 | for (d = rx->head; d; d = d->next) | ||
905 | cppi_dump_rxbd("S", d); | ||
906 | } | ||
907 | #endif | ||
908 | 897 | ||
909 | /* in case the preceding transfer left some state... */ | 898 | /* in case the preceding transfer left some state... */ |
910 | tail = rx->last_processed; | 899 | tail = rx->last_processed; |
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index 41613a2b35e8..b903b744a224 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c | |||
@@ -198,7 +198,7 @@ static void otg_timer(unsigned long _musb) | |||
198 | */ | 198 | */ |
199 | devctl = musb_readb(mregs, MUSB_DEVCTL); | 199 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
200 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 200 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, |
201 | otg_state_string(musb->xceiv->state)); | 201 | usb_otg_state_string(musb->xceiv->state)); |
202 | 202 | ||
203 | spin_lock_irqsave(&musb->lock, flags); | 203 | spin_lock_irqsave(&musb->lock, flags); |
204 | switch (musb->xceiv->state) { | 204 | switch (musb->xceiv->state) { |
@@ -267,7 +267,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
267 | if (musb->is_active || (musb->a_wait_bcon == 0 && | 267 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
268 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 268 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { |
269 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 269 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
270 | otg_state_string(musb->xceiv->state)); | 270 | usb_otg_state_string(musb->xceiv->state)); |
271 | del_timer(&otg_workaround); | 271 | del_timer(&otg_workaround); |
272 | last_timer = jiffies; | 272 | last_timer = jiffies; |
273 | return; | 273 | return; |
@@ -280,7 +280,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
280 | last_timer = timeout; | 280 | last_timer = timeout; |
281 | 281 | ||
282 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 282 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", |
283 | otg_state_string(musb->xceiv->state), | 283 | usb_otg_state_string(musb->xceiv->state), |
284 | jiffies_to_msecs(timeout - jiffies)); | 284 | jiffies_to_msecs(timeout - jiffies)); |
285 | mod_timer(&otg_workaround, timeout); | 285 | mod_timer(&otg_workaround, timeout); |
286 | } | 286 | } |
@@ -360,7 +360,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci) | |||
360 | 360 | ||
361 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 361 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
362 | drvvbus ? "on" : "off", | 362 | drvvbus ? "on" : "off", |
363 | otg_state_string(musb->xceiv->state), | 363 | usb_otg_state_string(musb->xceiv->state), |
364 | err ? " ERROR" : "", | 364 | err ? " ERROR" : "", |
365 | devctl); | 365 | devctl); |
366 | ret = IRQ_HANDLED; | 366 | ret = IRQ_HANDLED; |
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c index e040d9103735..bea6cc35471c 100644 --- a/drivers/usb/musb/davinci.c +++ b/drivers/usb/musb/davinci.c | |||
@@ -215,7 +215,7 @@ static void otg_timer(unsigned long _musb) | |||
215 | */ | 215 | */ |
216 | devctl = musb_readb(mregs, MUSB_DEVCTL); | 216 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
217 | dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, | 217 | dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, |
218 | otg_state_string(musb->xceiv->state)); | 218 | usb_otg_state_string(musb->xceiv->state)); |
219 | 219 | ||
220 | spin_lock_irqsave(&musb->lock, flags); | 220 | spin_lock_irqsave(&musb->lock, flags); |
221 | switch (musb->xceiv->state) { | 221 | switch (musb->xceiv->state) { |
@@ -349,7 +349,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci) | |||
349 | davinci_musb_source_power(musb, drvvbus, 0); | 349 | davinci_musb_source_power(musb, drvvbus, 0); |
350 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 350 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
351 | drvvbus ? "on" : "off", | 351 | drvvbus ? "on" : "off", |
352 | otg_state_string(musb->xceiv->state), | 352 | usb_otg_state_string(musb->xceiv->state), |
353 | err ? " ERROR" : "", | 353 | err ? " ERROR" : "", |
354 | devctl); | 354 | devctl); |
355 | retval = IRQ_HANDLED; | 355 | retval = IRQ_HANDLED; |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index daec6e0f7e38..37a261a6bb6a 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -372,13 +372,13 @@ static void musb_otg_timer_func(unsigned long data) | |||
372 | case OTG_STATE_A_SUSPEND: | 372 | case OTG_STATE_A_SUSPEND: |
373 | case OTG_STATE_A_WAIT_BCON: | 373 | case OTG_STATE_A_WAIT_BCON: |
374 | dev_dbg(musb->controller, "HNP: %s timeout\n", | 374 | dev_dbg(musb->controller, "HNP: %s timeout\n", |
375 | otg_state_string(musb->xceiv->state)); | 375 | usb_otg_state_string(musb->xceiv->state)); |
376 | musb_platform_set_vbus(musb, 0); | 376 | musb_platform_set_vbus(musb, 0); |
377 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 377 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; |
378 | break; | 378 | break; |
379 | default: | 379 | default: |
380 | dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", | 380 | dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", |
381 | otg_state_string(musb->xceiv->state)); | 381 | usb_otg_state_string(musb->xceiv->state)); |
382 | } | 382 | } |
383 | musb->ignore_disconnect = 0; | 383 | musb->ignore_disconnect = 0; |
384 | spin_unlock_irqrestore(&musb->lock, flags); | 384 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -393,13 +393,14 @@ void musb_hnp_stop(struct musb *musb) | |||
393 | void __iomem *mbase = musb->mregs; | 393 | void __iomem *mbase = musb->mregs; |
394 | u8 reg; | 394 | u8 reg; |
395 | 395 | ||
396 | dev_dbg(musb->controller, "HNP: stop from %s\n", otg_state_string(musb->xceiv->state)); | 396 | dev_dbg(musb->controller, "HNP: stop from %s\n", |
397 | usb_otg_state_string(musb->xceiv->state)); | ||
397 | 398 | ||
398 | switch (musb->xceiv->state) { | 399 | switch (musb->xceiv->state) { |
399 | case OTG_STATE_A_PERIPHERAL: | 400 | case OTG_STATE_A_PERIPHERAL: |
400 | musb_g_disconnect(musb); | 401 | musb_g_disconnect(musb); |
401 | dev_dbg(musb->controller, "HNP: back to %s\n", | 402 | dev_dbg(musb->controller, "HNP: back to %s\n", |
402 | otg_state_string(musb->xceiv->state)); | 403 | usb_otg_state_string(musb->xceiv->state)); |
403 | break; | 404 | break; |
404 | case OTG_STATE_B_HOST: | 405 | case OTG_STATE_B_HOST: |
405 | dev_dbg(musb->controller, "HNP: Disabling HR\n"); | 406 | dev_dbg(musb->controller, "HNP: Disabling HR\n"); |
@@ -413,7 +414,7 @@ void musb_hnp_stop(struct musb *musb) | |||
413 | break; | 414 | break; |
414 | default: | 415 | default: |
415 | dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", | 416 | dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", |
416 | otg_state_string(musb->xceiv->state)); | 417 | usb_otg_state_string(musb->xceiv->state)); |
417 | } | 418 | } |
418 | 419 | ||
419 | /* | 420 | /* |
@@ -451,7 +452,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
451 | */ | 452 | */ |
452 | if (int_usb & MUSB_INTR_RESUME) { | 453 | if (int_usb & MUSB_INTR_RESUME) { |
453 | handled = IRQ_HANDLED; | 454 | handled = IRQ_HANDLED; |
454 | dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state)); | 455 | dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->state)); |
455 | 456 | ||
456 | if (devctl & MUSB_DEVCTL_HM) { | 457 | if (devctl & MUSB_DEVCTL_HM) { |
457 | void __iomem *mbase = musb->mregs; | 458 | void __iomem *mbase = musb->mregs; |
@@ -493,7 +494,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
493 | default: | 494 | default: |
494 | WARNING("bogus %s RESUME (%s)\n", | 495 | WARNING("bogus %s RESUME (%s)\n", |
495 | "host", | 496 | "host", |
496 | otg_state_string(musb->xceiv->state)); | 497 | usb_otg_state_string(musb->xceiv->state)); |
497 | } | 498 | } |
498 | } else { | 499 | } else { |
499 | switch (musb->xceiv->state) { | 500 | switch (musb->xceiv->state) { |
@@ -522,7 +523,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
522 | default: | 523 | default: |
523 | WARNING("bogus %s RESUME (%s)\n", | 524 | WARNING("bogus %s RESUME (%s)\n", |
524 | "peripheral", | 525 | "peripheral", |
525 | otg_state_string(musb->xceiv->state)); | 526 | usb_otg_state_string(musb->xceiv->state)); |
526 | } | 527 | } |
527 | } | 528 | } |
528 | } | 529 | } |
@@ -538,7 +539,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
538 | } | 539 | } |
539 | 540 | ||
540 | dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", | 541 | dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", |
541 | otg_state_string(musb->xceiv->state)); | 542 | usb_otg_state_string(musb->xceiv->state)); |
542 | 543 | ||
543 | /* IRQ arrives from ID pin sense or (later, if VBUS power | 544 | /* IRQ arrives from ID pin sense or (later, if VBUS power |
544 | * is removed) SRP. responses are time critical: | 545 | * is removed) SRP. responses are time critical: |
@@ -602,8 +603,9 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
602 | break; | 603 | break; |
603 | } | 604 | } |
604 | 605 | ||
605 | dev_dbg(musb->controller, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", | 606 | dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller, |
606 | otg_state_string(musb->xceiv->state), | 607 | "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", |
608 | usb_otg_state_string(musb->xceiv->state), | ||
607 | devctl, | 609 | devctl, |
608 | ({ char *s; | 610 | ({ char *s; |
609 | switch (devctl & MUSB_DEVCTL_VBUS) { | 611 | switch (devctl & MUSB_DEVCTL_VBUS) { |
@@ -628,7 +630,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
628 | 630 | ||
629 | if (int_usb & MUSB_INTR_SUSPEND) { | 631 | if (int_usb & MUSB_INTR_SUSPEND) { |
630 | dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", | 632 | dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", |
631 | otg_state_string(musb->xceiv->state), devctl); | 633 | usb_otg_state_string(musb->xceiv->state), devctl); |
632 | handled = IRQ_HANDLED; | 634 | handled = IRQ_HANDLED; |
633 | 635 | ||
634 | switch (musb->xceiv->state) { | 636 | switch (musb->xceiv->state) { |
@@ -745,12 +747,12 @@ b_host: | |||
745 | usb_hcd_resume_root_hub(hcd); | 747 | usb_hcd_resume_root_hub(hcd); |
746 | 748 | ||
747 | dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", | 749 | dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", |
748 | otg_state_string(musb->xceiv->state), devctl); | 750 | usb_otg_state_string(musb->xceiv->state), devctl); |
749 | } | 751 | } |
750 | 752 | ||
751 | if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { | 753 | if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { |
752 | dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", | 754 | dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", |
753 | otg_state_string(musb->xceiv->state), | 755 | usb_otg_state_string(musb->xceiv->state), |
754 | MUSB_MODE(musb), devctl); | 756 | MUSB_MODE(musb), devctl); |
755 | handled = IRQ_HANDLED; | 757 | handled = IRQ_HANDLED; |
756 | 758 | ||
@@ -787,7 +789,7 @@ b_host: | |||
787 | break; | 789 | break; |
788 | default: | 790 | default: |
789 | WARNING("unhandled DISCONNECT transition (%s)\n", | 791 | WARNING("unhandled DISCONNECT transition (%s)\n", |
790 | otg_state_string(musb->xceiv->state)); | 792 | usb_otg_state_string(musb->xceiv->state)); |
791 | break; | 793 | break; |
792 | } | 794 | } |
793 | } | 795 | } |
@@ -813,7 +815,7 @@ b_host: | |||
813 | } | 815 | } |
814 | } else { | 816 | } else { |
815 | dev_dbg(musb->controller, "BUS RESET as %s\n", | 817 | dev_dbg(musb->controller, "BUS RESET as %s\n", |
816 | otg_state_string(musb->xceiv->state)); | 818 | usb_otg_state_string(musb->xceiv->state)); |
817 | switch (musb->xceiv->state) { | 819 | switch (musb->xceiv->state) { |
818 | case OTG_STATE_A_SUSPEND: | 820 | case OTG_STATE_A_SUSPEND: |
819 | /* We need to ignore disconnect on suspend | 821 | /* We need to ignore disconnect on suspend |
@@ -826,7 +828,7 @@ b_host: | |||
826 | case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ | 828 | case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ |
827 | /* never use invalid T(a_wait_bcon) */ | 829 | /* never use invalid T(a_wait_bcon) */ |
828 | dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", | 830 | dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", |
829 | otg_state_string(musb->xceiv->state), | 831 | usb_otg_state_string(musb->xceiv->state), |
830 | TA_WAIT_BCON(musb)); | 832 | TA_WAIT_BCON(musb)); |
831 | mod_timer(&musb->otg_timer, jiffies | 833 | mod_timer(&musb->otg_timer, jiffies |
832 | + msecs_to_jiffies(TA_WAIT_BCON(musb))); | 834 | + msecs_to_jiffies(TA_WAIT_BCON(musb))); |
@@ -838,7 +840,7 @@ b_host: | |||
838 | break; | 840 | break; |
839 | case OTG_STATE_B_WAIT_ACON: | 841 | case OTG_STATE_B_WAIT_ACON: |
840 | dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", | 842 | dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", |
841 | otg_state_string(musb->xceiv->state)); | 843 | usb_otg_state_string(musb->xceiv->state)); |
842 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 844 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; |
843 | musb_g_reset(musb); | 845 | musb_g_reset(musb); |
844 | break; | 846 | break; |
@@ -850,7 +852,7 @@ b_host: | |||
850 | break; | 852 | break; |
851 | default: | 853 | default: |
852 | dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", | 854 | dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", |
853 | otg_state_string(musb->xceiv->state)); | 855 | usb_otg_state_string(musb->xceiv->state)); |
854 | } | 856 | } |
855 | } | 857 | } |
856 | } | 858 | } |
@@ -1632,7 +1634,7 @@ musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
1632 | int ret = -EINVAL; | 1634 | int ret = -EINVAL; |
1633 | 1635 | ||
1634 | spin_lock_irqsave(&musb->lock, flags); | 1636 | spin_lock_irqsave(&musb->lock, flags); |
1635 | ret = sprintf(buf, "%s\n", otg_state_string(musb->xceiv->state)); | 1637 | ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->state)); |
1636 | spin_unlock_irqrestore(&musb->lock, flags); | 1638 | spin_unlock_irqrestore(&musb->lock, flags); |
1637 | 1639 | ||
1638 | return ret; | 1640 | return ret; |
@@ -1951,9 +1953,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1951 | musb_write_ulpi_buscontrol(musb->mregs, busctl); | 1953 | musb_write_ulpi_buscontrol(musb->mregs, busctl); |
1952 | } | 1954 | } |
1953 | 1955 | ||
1954 | MUSB_DEV_MODE(musb); | 1956 | if (musb->xceiv->otg->default_a) { |
1955 | musb->xceiv->otg->default_a = 0; | 1957 | MUSB_HST_MODE(musb); |
1956 | musb->xceiv->state = OTG_STATE_B_IDLE; | 1958 | musb->xceiv->state = OTG_STATE_A_IDLE; |
1959 | } else { | ||
1960 | MUSB_DEV_MODE(musb); | ||
1961 | musb->xceiv->state = OTG_STATE_B_IDLE; | ||
1962 | } | ||
1957 | 1963 | ||
1958 | status = musb_gadget_setup(musb); | 1964 | status = musb_gadget_setup(musb); |
1959 | 1965 | ||
@@ -2008,7 +2014,6 @@ static int musb_probe(struct platform_device *pdev) | |||
2008 | { | 2014 | { |
2009 | struct device *dev = &pdev->dev; | 2015 | struct device *dev = &pdev->dev; |
2010 | int irq = platform_get_irq_byname(pdev, "mc"); | 2016 | int irq = platform_get_irq_byname(pdev, "mc"); |
2011 | int status; | ||
2012 | struct resource *iomem; | 2017 | struct resource *iomem; |
2013 | void __iomem *base; | 2018 | void __iomem *base; |
2014 | 2019 | ||
@@ -2016,24 +2021,17 @@ static int musb_probe(struct platform_device *pdev) | |||
2016 | if (!iomem || irq <= 0) | 2021 | if (!iomem || irq <= 0) |
2017 | return -ENODEV; | 2022 | return -ENODEV; |
2018 | 2023 | ||
2019 | base = ioremap(iomem->start, resource_size(iomem)); | 2024 | base = devm_ioremap_resource(dev, iomem); |
2020 | if (!base) { | 2025 | if (IS_ERR(base)) |
2021 | dev_err(dev, "ioremap failed\n"); | 2026 | return PTR_ERR(base); |
2022 | return -ENOMEM; | ||
2023 | } | ||
2024 | 2027 | ||
2025 | status = musb_init_controller(dev, irq, base); | 2028 | return musb_init_controller(dev, irq, base); |
2026 | if (status < 0) | ||
2027 | iounmap(base); | ||
2028 | |||
2029 | return status; | ||
2030 | } | 2029 | } |
2031 | 2030 | ||
2032 | static int musb_remove(struct platform_device *pdev) | 2031 | static int musb_remove(struct platform_device *pdev) |
2033 | { | 2032 | { |
2034 | struct device *dev = &pdev->dev; | 2033 | struct device *dev = &pdev->dev; |
2035 | struct musb *musb = dev_to_musb(dev); | 2034 | struct musb *musb = dev_to_musb(dev); |
2036 | void __iomem *ctrl_base = musb->ctrl_base; | ||
2037 | 2035 | ||
2038 | /* this gets called on rmmod. | 2036 | /* this gets called on rmmod. |
2039 | * - Host mode: host may still be active | 2037 | * - Host mode: host may still be active |
@@ -2044,7 +2042,6 @@ static int musb_remove(struct platform_device *pdev) | |||
2044 | musb_shutdown(pdev); | 2042 | musb_shutdown(pdev); |
2045 | 2043 | ||
2046 | musb_free(musb); | 2044 | musb_free(musb); |
2047 | iounmap(ctrl_base); | ||
2048 | device_init_wakeup(dev, 0); | 2045 | device_init_wakeup(dev, 0); |
2049 | #ifndef CONFIG_MUSB_PIO_ONLY | 2046 | #ifndef CONFIG_MUSB_PIO_ONLY |
2050 | dma_set_mask(dev, *dev->parent->dma_mask); | 2047 | dma_set_mask(dev, *dev->parent->dma_mask); |
@@ -2293,8 +2290,6 @@ static int __init musb_init(void) | |||
2293 | if (usb_disabled()) | 2290 | if (usb_disabled()) |
2294 | return 0; | 2291 | return 0; |
2295 | 2292 | ||
2296 | pr_info("%s: version " MUSB_VERSION ", ?dma?, otg (peripheral+host)\n", | ||
2297 | musb_driver_name); | ||
2298 | return platform_driver_register(&musb_driver); | 2293 | return platform_driver_register(&musb_driver); |
2299 | } | 2294 | } |
2300 | module_init(musb_init); | 2295 | module_init(musb_init); |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 6bb89715b637..3a18e44e9391 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | #include <linux/usb/nop-usb-xceiv.h> | 39 | #include <linux/usb/nop-usb-xceiv.h> |
40 | #include <linux/platform_data/usb-omap.h> | 40 | #include <linux/platform_data/usb-omap.h> |
41 | #include <linux/sizes.h> | ||
41 | 42 | ||
42 | #include <linux/of.h> | 43 | #include <linux/of.h> |
43 | #include <linux/of_device.h> | 44 | #include <linux/of_device.h> |
@@ -224,7 +225,7 @@ static void otg_timer(unsigned long _musb) | |||
224 | */ | 225 | */ |
225 | devctl = dsps_readb(mregs, MUSB_DEVCTL); | 226 | devctl = dsps_readb(mregs, MUSB_DEVCTL); |
226 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 227 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, |
227 | otg_state_string(musb->xceiv->state)); | 228 | usb_otg_state_string(musb->xceiv->state)); |
228 | 229 | ||
229 | spin_lock_irqsave(&musb->lock, flags); | 230 | spin_lock_irqsave(&musb->lock, flags); |
230 | switch (musb->xceiv->state) { | 231 | switch (musb->xceiv->state) { |
@@ -273,7 +274,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
273 | if (musb->is_active || (musb->a_wait_bcon == 0 && | 274 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
274 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 275 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { |
275 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 276 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
276 | otg_state_string(musb->xceiv->state)); | 277 | usb_otg_state_string(musb->xceiv->state)); |
277 | del_timer(&glue->timer[pdev->id]); | 278 | del_timer(&glue->timer[pdev->id]); |
278 | glue->last_timer[pdev->id] = jiffies; | 279 | glue->last_timer[pdev->id] = jiffies; |
279 | return; | 280 | return; |
@@ -288,7 +289,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
288 | glue->last_timer[pdev->id] = timeout; | 289 | glue->last_timer[pdev->id] = timeout; |
289 | 290 | ||
290 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 291 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", |
291 | otg_state_string(musb->xceiv->state), | 292 | usb_otg_state_string(musb->xceiv->state), |
292 | jiffies_to_msecs(timeout - jiffies)); | 293 | jiffies_to_msecs(timeout - jiffies)); |
293 | mod_timer(&glue->timer[pdev->id], timeout); | 294 | mod_timer(&glue->timer[pdev->id], timeout); |
294 | } | 295 | } |
@@ -334,7 +335,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
334 | * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. | 335 | * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. |
335 | * Also, DRVVBUS pulses for SRP (but not at 5V) ... | 336 | * Also, DRVVBUS pulses for SRP (but not at 5V) ... |
336 | */ | 337 | */ |
337 | if (usbintr & MUSB_INTR_BABBLE) | 338 | if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) |
338 | pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); | 339 | pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); |
339 | 340 | ||
340 | if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { | 341 | if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { |
@@ -377,7 +378,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
377 | /* NOTE: this must complete power-on within 100 ms. */ | 378 | /* NOTE: this must complete power-on within 100 ms. */ |
378 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 379 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
379 | drvvbus ? "on" : "off", | 380 | drvvbus ? "on" : "off", |
380 | otg_state_string(musb->xceiv->state), | 381 | usb_otg_state_string(musb->xceiv->state), |
381 | err ? " ERROR" : "", | 382 | err ? " ERROR" : "", |
382 | devctl); | 383 | devctl); |
383 | ret = IRQ_HANDLED; | 384 | ret = IRQ_HANDLED; |
@@ -596,14 +597,13 @@ err0: | |||
596 | 597 | ||
597 | static int dsps_probe(struct platform_device *pdev) | 598 | static int dsps_probe(struct platform_device *pdev) |
598 | { | 599 | { |
599 | struct device_node *np = pdev->dev.of_node; | ||
600 | const struct of_device_id *match; | 600 | const struct of_device_id *match; |
601 | const struct dsps_musb_wrapper *wrp; | 601 | const struct dsps_musb_wrapper *wrp; |
602 | struct dsps_glue *glue; | 602 | struct dsps_glue *glue; |
603 | struct resource *iomem; | 603 | struct resource *iomem; |
604 | int ret, i; | 604 | int ret, i; |
605 | 605 | ||
606 | match = of_match_node(musb_dsps_of_match, np); | 606 | match = of_match_node(musb_dsps_of_match, pdev->dev.of_node); |
607 | if (!match) { | 607 | if (!match) { |
608 | dev_err(&pdev->dev, "fail to get matching of_match struct\n"); | 608 | dev_err(&pdev->dev, "fail to get matching of_match struct\n"); |
609 | ret = -EINVAL; | 609 | ret = -EINVAL; |
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 83eddedcd9be..ba7092349fa9 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -46,48 +46,6 @@ | |||
46 | #include "musb_core.h" | 46 | #include "musb_core.h" |
47 | 47 | ||
48 | 48 | ||
49 | /* MUSB PERIPHERAL status 3-mar-2006: | ||
50 | * | ||
51 | * - EP0 seems solid. It passes both USBCV and usbtest control cases. | ||
52 | * Minor glitches: | ||
53 | * | ||
54 | * + remote wakeup to Linux hosts work, but saw USBCV failures; | ||
55 | * in one test run (operator error?) | ||
56 | * + endpoint halt tests -- in both usbtest and usbcv -- seem | ||
57 | * to break when dma is enabled ... is something wrongly | ||
58 | * clearing SENDSTALL? | ||
59 | * | ||
60 | * - Mass storage behaved ok when last tested. Network traffic patterns | ||
61 | * (with lots of short transfers etc) need retesting; they turn up the | ||
62 | * worst cases of the DMA, since short packets are typical but are not | ||
63 | * required. | ||
64 | * | ||
65 | * - TX/IN | ||
66 | * + both pio and dma behave in with network and g_zero tests | ||
67 | * + no cppi throughput issues other than no-hw-queueing | ||
68 | * + failed with FLAT_REG (DaVinci) | ||
69 | * + seems to behave with double buffering, PIO -and- CPPI | ||
70 | * + with gadgetfs + AIO, requests got lost? | ||
71 | * | ||
72 | * - RX/OUT | ||
73 | * + both pio and dma behave in with network and g_zero tests | ||
74 | * + dma is slow in typical case (short_not_ok is clear) | ||
75 | * + double buffering ok with PIO | ||
76 | * + double buffering *FAILS* with CPPI, wrong data bytes sometimes | ||
77 | * + request lossage observed with gadgetfs | ||
78 | * | ||
79 | * - ISO not tested ... might work, but only weakly isochronous | ||
80 | * | ||
81 | * - Gadget driver disabling of softconnect during bind() is ignored; so | ||
82 | * drivers can't hold off host requests until userspace is ready. | ||
83 | * (Workaround: they can turn it off later.) | ||
84 | * | ||
85 | * - PORTABILITY (assumes PIO works): | ||
86 | * + DaVinci, basically works with cppi dma | ||
87 | * + OMAP 2430, ditto with mentor dma | ||
88 | * + TUSB 6010, platform-specific dma in the works | ||
89 | */ | ||
90 | |||
91 | /* ----------------------------------------------------------------------- */ | 49 | /* ----------------------------------------------------------------------- */ |
92 | 50 | ||
93 | #define is_buffer_mapped(req) (is_dma_capable() && \ | 51 | #define is_buffer_mapped(req) (is_dma_capable() && \ |
@@ -280,41 +238,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep) | |||
280 | return ep->packet_sz; | 238 | return ep->packet_sz; |
281 | } | 239 | } |
282 | 240 | ||
283 | |||
284 | #ifdef CONFIG_USB_INVENTRA_DMA | ||
285 | |||
286 | /* Peripheral tx (IN) using Mentor DMA works as follows: | ||
287 | Only mode 0 is used for transfers <= wPktSize, | ||
288 | mode 1 is used for larger transfers, | ||
289 | |||
290 | One of the following happens: | ||
291 | - Host sends IN token which causes an endpoint interrupt | ||
292 | -> TxAvail | ||
293 | -> if DMA is currently busy, exit. | ||
294 | -> if queue is non-empty, txstate(). | ||
295 | |||
296 | - Request is queued by the gadget driver. | ||
297 | -> if queue was previously empty, txstate() | ||
298 | |||
299 | txstate() | ||
300 | -> start | ||
301 | /\ -> setup DMA | ||
302 | | (data is transferred to the FIFO, then sent out when | ||
303 | | IN token(s) are recd from Host. | ||
304 | | -> DMA interrupt on completion | ||
305 | | calls TxAvail. | ||
306 | | -> stop DMA, ~DMAENAB, | ||
307 | | -> set TxPktRdy for last short pkt or zlp | ||
308 | | -> Complete Request | ||
309 | | -> Continue next request (call txstate) | ||
310 | |___________________________________| | ||
311 | |||
312 | * Non-Mentor DMA engines can of course work differently, such as by | ||
313 | * upleveling from irq-per-packet to irq-per-buffer. | ||
314 | */ | ||
315 | |||
316 | #endif | ||
317 | |||
318 | /* | 241 | /* |
319 | * An endpoint is transmitting data. This can be called either from | 242 | * An endpoint is transmitting data. This can be called either from |
320 | * the IRQ routine or from ep.queue() to kickstart a request on an | 243 | * the IRQ routine or from ep.queue() to kickstart a request on an |
@@ -621,37 +544,6 @@ void musb_g_tx(struct musb *musb, u8 epnum) | |||
621 | 544 | ||
622 | /* ------------------------------------------------------------ */ | 545 | /* ------------------------------------------------------------ */ |
623 | 546 | ||
624 | #ifdef CONFIG_USB_INVENTRA_DMA | ||
625 | |||
626 | /* Peripheral rx (OUT) using Mentor DMA works as follows: | ||
627 | - Only mode 0 is used. | ||
628 | |||
629 | - Request is queued by the gadget class driver. | ||
630 | -> if queue was previously empty, rxstate() | ||
631 | |||
632 | - Host sends OUT token which causes an endpoint interrupt | ||
633 | /\ -> RxReady | ||
634 | | -> if request queued, call rxstate | ||
635 | | /\ -> setup DMA | ||
636 | | | -> DMA interrupt on completion | ||
637 | | | -> RxReady | ||
638 | | | -> stop DMA | ||
639 | | | -> ack the read | ||
640 | | | -> if data recd = max expected | ||
641 | | | by the request, or host | ||
642 | | | sent a short packet, | ||
643 | | | complete the request, | ||
644 | | | and start the next one. | ||
645 | | |_____________________________________| | ||
646 | | else just wait for the host | ||
647 | | to send the next OUT token. | ||
648 | |__________________________________________________| | ||
649 | |||
650 | * Non-Mentor DMA engines can of course work differently. | ||
651 | */ | ||
652 | |||
653 | #endif | ||
654 | |||
655 | /* | 547 | /* |
656 | * Context: controller locked, IRQs blocked, endpoint selected | 548 | * Context: controller locked, IRQs blocked, endpoint selected |
657 | */ | 549 | */ |
@@ -740,7 +632,7 @@ static void rxstate(struct musb *musb, struct musb_request *req) | |||
740 | struct dma_controller *c; | 632 | struct dma_controller *c; |
741 | struct dma_channel *channel; | 633 | struct dma_channel *channel; |
742 | int use_dma = 0; | 634 | int use_dma = 0; |
743 | int transfer_size; | 635 | unsigned int transfer_size; |
744 | 636 | ||
745 | c = musb->dma_controller; | 637 | c = musb->dma_controller; |
746 | channel = musb_ep->dma; | 638 | channel = musb_ep->dma; |
@@ -782,10 +674,11 @@ static void rxstate(struct musb *musb, struct musb_request *req) | |||
782 | csr | MUSB_RXCSR_DMAMODE); | 674 | csr | MUSB_RXCSR_DMAMODE); |
783 | musb_writew(epio, MUSB_RXCSR, csr); | 675 | musb_writew(epio, MUSB_RXCSR, csr); |
784 | 676 | ||
785 | transfer_size = min(request->length - request->actual, | 677 | transfer_size = min_t(unsigned int, |
678 | request->length - | ||
679 | request->actual, | ||
786 | channel->max_len); | 680 | channel->max_len); |
787 | musb_ep->dma->desired_mode = 1; | 681 | musb_ep->dma->desired_mode = 1; |
788 | |||
789 | } else { | 682 | } else { |
790 | if (!musb_ep->hb_mult && | 683 | if (!musb_ep->hb_mult && |
791 | musb_ep->hw_ep->rx_double_buffered) | 684 | musb_ep->hw_ep->rx_double_buffered) |
@@ -815,7 +708,7 @@ static void rxstate(struct musb *musb, struct musb_request *req) | |||
815 | 708 | ||
816 | struct dma_controller *c; | 709 | struct dma_controller *c; |
817 | struct dma_channel *channel; | 710 | struct dma_channel *channel; |
818 | int transfer_size = 0; | 711 | unsigned int transfer_size = 0; |
819 | 712 | ||
820 | c = musb->dma_controller; | 713 | c = musb->dma_controller; |
821 | channel = musb_ep->dma; | 714 | channel = musb_ep->dma; |
@@ -824,11 +717,13 @@ static void rxstate(struct musb *musb, struct musb_request *req) | |||
824 | if (fifo_count < musb_ep->packet_sz) | 717 | if (fifo_count < musb_ep->packet_sz) |
825 | transfer_size = fifo_count; | 718 | transfer_size = fifo_count; |
826 | else if (request->short_not_ok) | 719 | else if (request->short_not_ok) |
827 | transfer_size = min(request->length - | 720 | transfer_size = min_t(unsigned int, |
721 | request->length - | ||
828 | request->actual, | 722 | request->actual, |
829 | channel->max_len); | 723 | channel->max_len); |
830 | else | 724 | else |
831 | transfer_size = min(request->length - | 725 | transfer_size = min_t(unsigned int, |
726 | request->length - | ||
832 | request->actual, | 727 | request->actual, |
833 | (unsigned)fifo_count); | 728 | (unsigned)fifo_count); |
834 | 729 | ||
@@ -1681,7 +1576,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) | |||
1681 | goto done; | 1576 | goto done; |
1682 | default: | 1577 | default: |
1683 | dev_dbg(musb->controller, "Unhandled wake: %s\n", | 1578 | dev_dbg(musb->controller, "Unhandled wake: %s\n", |
1684 | otg_state_string(musb->xceiv->state)); | 1579 | usb_otg_state_string(musb->xceiv->state)); |
1685 | goto done; | 1580 | goto done; |
1686 | } | 1581 | } |
1687 | 1582 | ||
@@ -1801,13 +1696,6 @@ static const struct usb_gadget_ops musb_gadget_operations = { | |||
1801 | * all peripheral ports are external... | 1696 | * all peripheral ports are external... |
1802 | */ | 1697 | */ |
1803 | 1698 | ||
1804 | static void musb_gadget_release(struct device *dev) | ||
1805 | { | ||
1806 | /* kref_put(WHAT) */ | ||
1807 | dev_dbg(dev, "%s\n", __func__); | ||
1808 | } | ||
1809 | |||
1810 | |||
1811 | static void | 1699 | static void |
1812 | init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) | 1700 | init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) |
1813 | { | 1701 | { |
@@ -1892,12 +1780,7 @@ int musb_gadget_setup(struct musb *musb) | |||
1892 | musb->g.speed = USB_SPEED_UNKNOWN; | 1780 | musb->g.speed = USB_SPEED_UNKNOWN; |
1893 | 1781 | ||
1894 | /* this "gadget" abstracts/virtualizes the controller */ | 1782 | /* this "gadget" abstracts/virtualizes the controller */ |
1895 | dev_set_name(&musb->g.dev, "gadget"); | ||
1896 | musb->g.dev.parent = musb->controller; | ||
1897 | musb->g.dev.dma_mask = musb->controller->dma_mask; | ||
1898 | musb->g.dev.release = musb_gadget_release; | ||
1899 | musb->g.name = musb_driver_name; | 1783 | musb->g.name = musb_driver_name; |
1900 | |||
1901 | musb->g.is_otg = 1; | 1784 | musb->g.is_otg = 1; |
1902 | 1785 | ||
1903 | musb_g_init_endpoints(musb); | 1786 | musb_g_init_endpoints(musb); |
@@ -1905,11 +1788,6 @@ int musb_gadget_setup(struct musb *musb) | |||
1905 | musb->is_active = 0; | 1788 | musb->is_active = 0; |
1906 | musb_platform_try_idle(musb, 0); | 1789 | musb_platform_try_idle(musb, 0); |
1907 | 1790 | ||
1908 | status = device_register(&musb->g.dev); | ||
1909 | if (status != 0) { | ||
1910 | put_device(&musb->g.dev); | ||
1911 | return status; | ||
1912 | } | ||
1913 | status = usb_add_gadget_udc(musb->controller, &musb->g); | 1791 | status = usb_add_gadget_udc(musb->controller, &musb->g); |
1914 | if (status) | 1792 | if (status) |
1915 | goto err; | 1793 | goto err; |
@@ -1924,8 +1802,6 @@ err: | |||
1924 | void musb_gadget_cleanup(struct musb *musb) | 1802 | void musb_gadget_cleanup(struct musb *musb) |
1925 | { | 1803 | { |
1926 | usb_del_gadget_udc(&musb->g); | 1804 | usb_del_gadget_udc(&musb->g); |
1927 | if (musb->g.dev.parent) | ||
1928 | device_unregister(&musb->g.dev); | ||
1929 | } | 1805 | } |
1930 | 1806 | ||
1931 | /* | 1807 | /* |
@@ -1977,9 +1853,8 @@ static int musb_gadget_start(struct usb_gadget *g, | |||
1977 | goto err; | 1853 | goto err; |
1978 | } | 1854 | } |
1979 | 1855 | ||
1980 | if ((musb->xceiv->last_event == USB_EVENT_ID) | 1856 | if (musb->xceiv->last_event == USB_EVENT_ID) |
1981 | && otg->set_vbus) | 1857 | musb_platform_set_vbus(musb, 1); |
1982 | otg_set_vbus(otg, 1); | ||
1983 | 1858 | ||
1984 | hcd->self.uses_pio_for_control = 1; | 1859 | hcd->self.uses_pio_for_control = 1; |
1985 | 1860 | ||
@@ -2063,6 +1938,7 @@ static int musb_gadget_stop(struct usb_gadget *g, | |||
2063 | dev_dbg(musb->controller, "unregistering driver %s\n", driver->function); | 1938 | dev_dbg(musb->controller, "unregistering driver %s\n", driver->function); |
2064 | 1939 | ||
2065 | musb->is_active = 0; | 1940 | musb->is_active = 0; |
1941 | musb->gadget_driver = NULL; | ||
2066 | musb_platform_try_idle(musb, 0); | 1942 | musb_platform_try_idle(musb, 0); |
2067 | spin_unlock_irqrestore(&musb->lock, flags); | 1943 | spin_unlock_irqrestore(&musb->lock, flags); |
2068 | 1944 | ||
@@ -2099,7 +1975,7 @@ void musb_g_resume(struct musb *musb) | |||
2099 | break; | 1975 | break; |
2100 | default: | 1976 | default: |
2101 | WARNING("unhandled RESUME transition (%s)\n", | 1977 | WARNING("unhandled RESUME transition (%s)\n", |
2102 | otg_state_string(musb->xceiv->state)); | 1978 | usb_otg_state_string(musb->xceiv->state)); |
2103 | } | 1979 | } |
2104 | } | 1980 | } |
2105 | 1981 | ||
@@ -2129,7 +2005,7 @@ void musb_g_suspend(struct musb *musb) | |||
2129 | * A_PERIPHERAL may need care too | 2005 | * A_PERIPHERAL may need care too |
2130 | */ | 2006 | */ |
2131 | WARNING("unhandled SUSPEND transition (%s)\n", | 2007 | WARNING("unhandled SUSPEND transition (%s)\n", |
2132 | otg_state_string(musb->xceiv->state)); | 2008 | usb_otg_state_string(musb->xceiv->state)); |
2133 | } | 2009 | } |
2134 | } | 2010 | } |
2135 | 2011 | ||
@@ -2163,7 +2039,7 @@ void musb_g_disconnect(struct musb *musb) | |||
2163 | switch (musb->xceiv->state) { | 2039 | switch (musb->xceiv->state) { |
2164 | default: | 2040 | default: |
2165 | dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", | 2041 | dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", |
2166 | otg_state_string(musb->xceiv->state)); | 2042 | usb_otg_state_string(musb->xceiv->state)); |
2167 | musb->xceiv->state = OTG_STATE_A_IDLE; | 2043 | musb->xceiv->state = OTG_STATE_A_IDLE; |
2168 | MUSB_HST_MODE(musb); | 2044 | MUSB_HST_MODE(musb); |
2169 | break; | 2045 | break; |
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c index c9c1ac4e075f..2af45a0c8930 100644 --- a/drivers/usb/musb/musb_gadget_ep0.c +++ b/drivers/usb/musb/musb_gadget_ep0.c | |||
@@ -505,8 +505,10 @@ static void ep0_rxstate(struct musb *musb) | |||
505 | req->status = -EOVERFLOW; | 505 | req->status = -EOVERFLOW; |
506 | count = len; | 506 | count = len; |
507 | } | 507 | } |
508 | musb_read_fifo(&musb->endpoints[0], count, buf); | 508 | if (count > 0) { |
509 | req->actual += count; | 509 | musb_read_fifo(&musb->endpoints[0], count, buf); |
510 | req->actual += count; | ||
511 | } | ||
510 | csr = MUSB_CSR0_P_SVDRXPKTRDY; | 512 | csr = MUSB_CSR0_P_SVDRXPKTRDY; |
511 | if (count < 64 || req->actual == req->length) { | 513 | if (count < 64 || req->actual == req->length) { |
512 | musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; | 514 | musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; |
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index 1ce1fcf3f3e7..8914dec49f01 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c | |||
@@ -2453,7 +2453,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) | |||
2453 | 2453 | ||
2454 | if (musb->is_active) { | 2454 | if (musb->is_active) { |
2455 | WARNING("trying to suspend as %s while active\n", | 2455 | WARNING("trying to suspend as %s while active\n", |
2456 | otg_state_string(musb->xceiv->state)); | 2456 | usb_otg_state_string(musb->xceiv->state)); |
2457 | return -EBUSY; | 2457 | return -EBUSY; |
2458 | } else | 2458 | } else |
2459 | return 0; | 2459 | return 0; |
@@ -2465,6 +2465,118 @@ static int musb_bus_resume(struct usb_hcd *hcd) | |||
2465 | return 0; | 2465 | return 0; |
2466 | } | 2466 | } |
2467 | 2467 | ||
2468 | |||
2469 | #ifndef CONFIG_MUSB_PIO_ONLY | ||
2470 | |||
2471 | #define MUSB_USB_DMA_ALIGN 4 | ||
2472 | |||
2473 | struct musb_temp_buffer { | ||
2474 | void *kmalloc_ptr; | ||
2475 | void *old_xfer_buffer; | ||
2476 | u8 data[0]; | ||
2477 | }; | ||
2478 | |||
2479 | static void musb_free_temp_buffer(struct urb *urb) | ||
2480 | { | ||
2481 | enum dma_data_direction dir; | ||
2482 | struct musb_temp_buffer *temp; | ||
2483 | |||
2484 | if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER)) | ||
2485 | return; | ||
2486 | |||
2487 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | ||
2488 | |||
2489 | temp = container_of(urb->transfer_buffer, struct musb_temp_buffer, | ||
2490 | data); | ||
2491 | |||
2492 | if (dir == DMA_FROM_DEVICE) { | ||
2493 | memcpy(temp->old_xfer_buffer, temp->data, | ||
2494 | urb->transfer_buffer_length); | ||
2495 | } | ||
2496 | urb->transfer_buffer = temp->old_xfer_buffer; | ||
2497 | kfree(temp->kmalloc_ptr); | ||
2498 | |||
2499 | urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER; | ||
2500 | } | ||
2501 | |||
2502 | static int musb_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags) | ||
2503 | { | ||
2504 | enum dma_data_direction dir; | ||
2505 | struct musb_temp_buffer *temp; | ||
2506 | void *kmalloc_ptr; | ||
2507 | size_t kmalloc_size; | ||
2508 | |||
2509 | if (urb->num_sgs || urb->sg || | ||
2510 | urb->transfer_buffer_length == 0 || | ||
2511 | !((uintptr_t)urb->transfer_buffer & (MUSB_USB_DMA_ALIGN - 1))) | ||
2512 | return 0; | ||
2513 | |||
2514 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | ||
2515 | |||
2516 | /* Allocate a buffer with enough padding for alignment */ | ||
2517 | kmalloc_size = urb->transfer_buffer_length + | ||
2518 | sizeof(struct musb_temp_buffer) + MUSB_USB_DMA_ALIGN - 1; | ||
2519 | |||
2520 | kmalloc_ptr = kmalloc(kmalloc_size, mem_flags); | ||
2521 | if (!kmalloc_ptr) | ||
2522 | return -ENOMEM; | ||
2523 | |||
2524 | /* Position our struct temp_buffer such that data is aligned */ | ||
2525 | temp = PTR_ALIGN(kmalloc_ptr, MUSB_USB_DMA_ALIGN); | ||
2526 | |||
2527 | |||
2528 | temp->kmalloc_ptr = kmalloc_ptr; | ||
2529 | temp->old_xfer_buffer = urb->transfer_buffer; | ||
2530 | if (dir == DMA_TO_DEVICE) | ||
2531 | memcpy(temp->data, urb->transfer_buffer, | ||
2532 | urb->transfer_buffer_length); | ||
2533 | urb->transfer_buffer = temp->data; | ||
2534 | |||
2535 | urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER; | ||
2536 | |||
2537 | return 0; | ||
2538 | } | ||
2539 | |||
2540 | static int musb_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | ||
2541 | gfp_t mem_flags) | ||
2542 | { | ||
2543 | struct musb *musb = hcd_to_musb(hcd); | ||
2544 | int ret; | ||
2545 | |||
2546 | /* | ||
2547 | * The DMA engine in RTL1.8 and above cannot handle | ||
2548 | * DMA addresses that are not aligned to a 4 byte boundary. | ||
2549 | * For such engine implemented (un)map_urb_for_dma hooks. | ||
2550 | * Do not use these hooks for RTL<1.8 | ||
2551 | */ | ||
2552 | if (musb->hwvers < MUSB_HWVERS_1800) | ||
2553 | return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); | ||
2554 | |||
2555 | ret = musb_alloc_temp_buffer(urb, mem_flags); | ||
2556 | if (ret) | ||
2557 | return ret; | ||
2558 | |||
2559 | ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); | ||
2560 | if (ret) | ||
2561 | musb_free_temp_buffer(urb); | ||
2562 | |||
2563 | return ret; | ||
2564 | } | ||
2565 | |||
2566 | static void musb_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
2567 | { | ||
2568 | struct musb *musb = hcd_to_musb(hcd); | ||
2569 | |||
2570 | usb_hcd_unmap_urb_for_dma(hcd, urb); | ||
2571 | |||
2572 | /* Do not use this hook for RTL<1.8 (see description above) */ | ||
2573 | if (musb->hwvers < MUSB_HWVERS_1800) | ||
2574 | return; | ||
2575 | |||
2576 | musb_free_temp_buffer(urb); | ||
2577 | } | ||
2578 | #endif /* !CONFIG_MUSB_PIO_ONLY */ | ||
2579 | |||
2468 | const struct hc_driver musb_hc_driver = { | 2580 | const struct hc_driver musb_hc_driver = { |
2469 | .description = "musb-hcd", | 2581 | .description = "musb-hcd", |
2470 | .product_desc = "MUSB HDRC host driver", | 2582 | .product_desc = "MUSB HDRC host driver", |
@@ -2484,6 +2596,11 @@ const struct hc_driver musb_hc_driver = { | |||
2484 | .urb_dequeue = musb_urb_dequeue, | 2596 | .urb_dequeue = musb_urb_dequeue, |
2485 | .endpoint_disable = musb_h_disable, | 2597 | .endpoint_disable = musb_h_disable, |
2486 | 2598 | ||
2599 | #ifndef CONFIG_MUSB_PIO_ONLY | ||
2600 | .map_urb_for_dma = musb_map_urb_for_dma, | ||
2601 | .unmap_urb_for_dma = musb_unmap_urb_for_dma, | ||
2602 | #endif | ||
2603 | |||
2487 | .hub_status_data = musb_hub_status_data, | 2604 | .hub_status_data = musb_hub_status_data, |
2488 | .hub_control = musb_hub_control, | 2605 | .hub_control = musb_hub_control, |
2489 | .bus_suspend = musb_bus_suspend, | 2606 | .bus_suspend = musb_bus_suspend, |
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index f70579154ded..ef7d11045f56 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c | |||
@@ -95,7 +95,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend) | |||
95 | break; | 95 | break; |
96 | default: | 96 | default: |
97 | dev_dbg(musb->controller, "bogus rh suspend? %s\n", | 97 | dev_dbg(musb->controller, "bogus rh suspend? %s\n", |
98 | otg_state_string(musb->xceiv->state)); | 98 | usb_otg_state_string(musb->xceiv->state)); |
99 | } | 99 | } |
100 | } else if (power & MUSB_POWER_SUSPENDM) { | 100 | } else if (power & MUSB_POWER_SUSPENDM) { |
101 | power &= ~MUSB_POWER_SUSPENDM; | 101 | power &= ~MUSB_POWER_SUSPENDM; |
@@ -203,7 +203,7 @@ void musb_root_disconnect(struct musb *musb) | |||
203 | break; | 203 | break; |
204 | default: | 204 | default: |
205 | dev_dbg(musb->controller, "host disconnect (%s)\n", | 205 | dev_dbg(musb->controller, "host disconnect (%s)\n", |
206 | otg_state_string(musb->xceiv->state)); | 206 | usb_otg_state_string(musb->xceiv->state)); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 1a42a458f2c4..3551f1a30c65 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c | |||
@@ -117,7 +117,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
117 | if (musb->is_active || ((musb->a_wait_bcon == 0) | 117 | if (musb->is_active || ((musb->a_wait_bcon == 0) |
118 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { | 118 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { |
119 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 119 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
120 | otg_state_string(musb->xceiv->state)); | 120 | usb_otg_state_string(musb->xceiv->state)); |
121 | del_timer(&musb_idle_timer); | 121 | del_timer(&musb_idle_timer); |
122 | last_timer = jiffies; | 122 | last_timer = jiffies; |
123 | return; | 123 | return; |
@@ -134,7 +134,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
134 | last_timer = timeout; | 134 | last_timer = timeout; |
135 | 135 | ||
136 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", | 136 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", |
137 | otg_state_string(musb->xceiv->state), | 137 | usb_otg_state_string(musb->xceiv->state), |
138 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); | 138 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); |
139 | mod_timer(&musb_idle_timer, timeout); | 139 | mod_timer(&musb_idle_timer, timeout); |
140 | } | 140 | } |
@@ -174,8 +174,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | if (otg->set_vbus) | 177 | otg_set_vbus(otg, 1); |
178 | otg_set_vbus(otg, 1); | ||
179 | } else { | 178 | } else { |
180 | musb->is_active = 1; | 179 | musb->is_active = 1; |
181 | otg->default_a = 1; | 180 | otg->default_a = 1; |
@@ -200,7 +199,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
200 | 199 | ||
201 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " | 200 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
202 | /* otg %3x conf %08x prcm %08x */ "\n", | 201 | /* otg %3x conf %08x prcm %08x */ "\n", |
203 | otg_state_string(musb->xceiv->state), | 202 | usb_otg_state_string(musb->xceiv->state), |
204 | musb_readb(musb->mregs, MUSB_DEVCTL)); | 203 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
205 | } | 204 | } |
206 | 205 | ||
@@ -292,14 +291,14 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue) | |||
292 | 291 | ||
293 | musb->xceiv->last_event = USB_EVENT_NONE; | 292 | musb->xceiv->last_event = USB_EVENT_NONE; |
294 | if (musb->gadget_driver) { | 293 | if (musb->gadget_driver) { |
294 | omap2430_musb_set_vbus(musb, 0); | ||
295 | pm_runtime_mark_last_busy(dev); | 295 | pm_runtime_mark_last_busy(dev); |
296 | pm_runtime_put_autosuspend(dev); | 296 | pm_runtime_put_autosuspend(dev); |
297 | } | 297 | } |
298 | 298 | ||
299 | if (data->interface_type == MUSB_INTERFACE_UTMI) { | 299 | if (data->interface_type == MUSB_INTERFACE_UTMI) |
300 | if (musb->xceiv->otg->set_vbus) | 300 | otg_set_vbus(musb->xceiv->otg, 0); |
301 | otg_set_vbus(musb->xceiv->otg, 0); | 301 | |
302 | } | ||
303 | omap_control_usb_set_mode(glue->control_otghs, | 302 | omap_control_usb_set_mode(glue->control_otghs, |
304 | USB_MODE_DISCONNECT); | 303 | USB_MODE_DISCONNECT); |
305 | break; | 304 | break; |
@@ -355,7 +354,12 @@ static int omap2430_musb_init(struct musb *musb) | |||
355 | else | 354 | else |
356 | musb->xceiv = devm_usb_get_phy_dev(dev, 0); | 355 | musb->xceiv = devm_usb_get_phy_dev(dev, 0); |
357 | 356 | ||
358 | if (IS_ERR_OR_NULL(musb->xceiv)) { | 357 | if (IS_ERR(musb->xceiv)) { |
358 | status = PTR_ERR(musb->xceiv); | ||
359 | |||
360 | if (status == -ENXIO) | ||
361 | return status; | ||
362 | |||
359 | pr_err("HS USB OTG: no transceiver configured\n"); | 363 | pr_err("HS USB OTG: no transceiver configured\n"); |
360 | return -EPROBE_DEFER; | 364 | return -EPROBE_DEFER; |
361 | } | 365 | } |
@@ -393,6 +397,8 @@ static int omap2430_musb_init(struct musb *musb) | |||
393 | if (glue->status != OMAP_MUSB_UNKNOWN) | 397 | if (glue->status != OMAP_MUSB_UNKNOWN) |
394 | omap_musb_set_mailbox(glue); | 398 | omap_musb_set_mailbox(glue); |
395 | 399 | ||
400 | usb_phy_init(musb->xceiv); | ||
401 | |||
396 | pm_runtime_put_noidle(musb->controller); | 402 | pm_runtime_put_noidle(musb->controller); |
397 | return 0; | 403 | return 0; |
398 | 404 | ||
@@ -526,10 +532,10 @@ static int omap2430_probe(struct platform_device *pdev) | |||
526 | } | 532 | } |
527 | 533 | ||
528 | of_property_read_u32(np, "mode", (u32 *)&pdata->mode); | 534 | of_property_read_u32(np, "mode", (u32 *)&pdata->mode); |
529 | of_property_read_u32(np, "interface_type", | 535 | of_property_read_u32(np, "interface-type", |
530 | (u32 *)&data->interface_type); | 536 | (u32 *)&data->interface_type); |
531 | of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps); | 537 | of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps); |
532 | of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits); | 538 | of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); |
533 | of_property_read_u32(np, "power", (u32 *)&pdata->power); | 539 | of_property_read_u32(np, "power", (u32 *)&pdata->power); |
534 | config->multipoint = of_property_read_bool(np, "multipoint"); | 540 | config->multipoint = of_property_read_bool(np, "multipoint"); |
535 | pdata->has_mailbox = of_property_read_bool(np, | 541 | pdata->has_mailbox = of_property_read_bool(np, |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index 464bd23cccda..7369ba33c94f 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -423,7 +423,7 @@ static void musb_do_idle(unsigned long _musb) | |||
423 | && (musb->idle_timeout == 0 | 423 | && (musb->idle_timeout == 0 |
424 | || time_after(jiffies, musb->idle_timeout))) { | 424 | || time_after(jiffies, musb->idle_timeout))) { |
425 | dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", | 425 | dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", |
426 | otg_state_string(musb->xceiv->state)); | 426 | usb_otg_state_string(musb->xceiv->state)); |
427 | } | 427 | } |
428 | /* FALLTHROUGH */ | 428 | /* FALLTHROUGH */ |
429 | case OTG_STATE_A_IDLE: | 429 | case OTG_STATE_A_IDLE: |
@@ -478,7 +478,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
478 | if (musb->is_active || ((musb->a_wait_bcon == 0) | 478 | if (musb->is_active || ((musb->a_wait_bcon == 0) |
479 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { | 479 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { |
480 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 480 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
481 | otg_state_string(musb->xceiv->state)); | 481 | usb_otg_state_string(musb->xceiv->state)); |
482 | del_timer(&musb_idle_timer); | 482 | del_timer(&musb_idle_timer); |
483 | last_timer = jiffies; | 483 | last_timer = jiffies; |
484 | return; | 484 | return; |
@@ -495,7 +495,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
495 | last_timer = timeout; | 495 | last_timer = timeout; |
496 | 496 | ||
497 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", | 497 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", |
498 | otg_state_string(musb->xceiv->state), | 498 | usb_otg_state_string(musb->xceiv->state), |
499 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); | 499 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); |
500 | mod_timer(&musb_idle_timer, timeout); | 500 | mod_timer(&musb_idle_timer, timeout); |
501 | } | 501 | } |
@@ -571,7 +571,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on) | |||
571 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 571 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
572 | 572 | ||
573 | dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", | 573 | dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", |
574 | otg_state_string(musb->xceiv->state), | 574 | usb_otg_state_string(musb->xceiv->state), |
575 | musb_readb(musb->mregs, MUSB_DEVCTL), | 575 | musb_readb(musb->mregs, MUSB_DEVCTL), |
576 | musb_readl(tbase, TUSB_DEV_OTG_STAT), | 576 | musb_readl(tbase, TUSB_DEV_OTG_STAT), |
577 | conf, prcm); | 577 | conf, prcm); |
@@ -678,13 +678,13 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) | |||
678 | musb->is_active = 0; | 678 | musb->is_active = 0; |
679 | } | 679 | } |
680 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", | 680 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", |
681 | otg_state_string(musb->xceiv->state), otg_stat); | 681 | usb_otg_state_string(musb->xceiv->state), otg_stat); |
682 | idle_timeout = jiffies + (1 * HZ); | 682 | idle_timeout = jiffies + (1 * HZ); |
683 | schedule_work(&musb->irq_work); | 683 | schedule_work(&musb->irq_work); |
684 | 684 | ||
685 | } else /* A-dev state machine */ { | 685 | } else /* A-dev state machine */ { |
686 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", | 686 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", |
687 | otg_state_string(musb->xceiv->state), otg_stat); | 687 | usb_otg_state_string(musb->xceiv->state), otg_stat); |
688 | 688 | ||
689 | switch (musb->xceiv->state) { | 689 | switch (musb->xceiv->state) { |
690 | case OTG_STATE_A_IDLE: | 690 | case OTG_STATE_A_IDLE: |
@@ -733,7 +733,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) | |||
733 | u8 devctl; | 733 | u8 devctl; |
734 | 734 | ||
735 | dev_dbg(musb->controller, "%s timer, %03x\n", | 735 | dev_dbg(musb->controller, "%s timer, %03x\n", |
736 | otg_state_string(musb->xceiv->state), otg_stat); | 736 | usb_otg_state_string(musb->xceiv->state), otg_stat); |
737 | 737 | ||
738 | switch (musb->xceiv->state) { | 738 | switch (musb->xceiv->state) { |
739 | case OTG_STATE_A_WAIT_VRISE: | 739 | case OTG_STATE_A_WAIT_VRISE: |
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c index 13a392913769..2c80004e0a83 100644 --- a/drivers/usb/musb/ux500.c +++ b/drivers/usb/musb/ux500.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/err.h> | 26 | #include <linux/err.h> |
27 | #include <linux/io.h> | 27 | #include <linux/io.h> |
28 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
29 | #include <linux/usb/musb-ux500.h> | ||
29 | 30 | ||
30 | #include "musb_core.h" | 31 | #include "musb_core.h" |
31 | 32 | ||
@@ -36,6 +37,98 @@ struct ux500_glue { | |||
36 | }; | 37 | }; |
37 | #define glue_to_musb(g) platform_get_drvdata(g->musb) | 38 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
38 | 39 | ||
40 | static void ux500_musb_set_vbus(struct musb *musb, int is_on) | ||
41 | { | ||
42 | u8 devctl; | ||
43 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | ||
44 | /* HDRC controls CPEN, but beware current surges during device | ||
45 | * connect. They can trigger transient overcurrent conditions | ||
46 | * that must be ignored. | ||
47 | */ | ||
48 | |||
49 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | ||
50 | |||
51 | if (is_on) { | ||
52 | if (musb->xceiv->state == OTG_STATE_A_IDLE) { | ||
53 | /* start the session */ | ||
54 | devctl |= MUSB_DEVCTL_SESSION; | ||
55 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | ||
56 | /* | ||
57 | * Wait for the musb to set as A device to enable the | ||
58 | * VBUS | ||
59 | */ | ||
60 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { | ||
61 | |||
62 | if (time_after(jiffies, timeout)) { | ||
63 | dev_err(musb->controller, | ||
64 | "configured as A device timeout"); | ||
65 | break; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | } else { | ||
70 | musb->is_active = 1; | ||
71 | musb->xceiv->otg->default_a = 1; | ||
72 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | ||
73 | devctl |= MUSB_DEVCTL_SESSION; | ||
74 | MUSB_HST_MODE(musb); | ||
75 | } | ||
76 | } else { | ||
77 | musb->is_active = 0; | ||
78 | |||
79 | /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping | ||
80 | * right to B_IDLE... | ||
81 | */ | ||
82 | musb->xceiv->otg->default_a = 0; | ||
83 | devctl &= ~MUSB_DEVCTL_SESSION; | ||
84 | MUSB_DEV_MODE(musb); | ||
85 | } | ||
86 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | ||
87 | |||
88 | /* | ||
89 | * Devctl values will be updated after vbus goes below | ||
90 | * session_valid. The time taken depends on the capacitance | ||
91 | * on VBUS line. The max discharge time can be upto 1 sec | ||
92 | * as per the spec. Typically on our platform, it is 200ms | ||
93 | */ | ||
94 | if (!is_on) | ||
95 | mdelay(200); | ||
96 | |||
97 | dev_dbg(musb->controller, "VBUS %s, devctl %02x\n", | ||
98 | usb_otg_state_string(musb->xceiv->state), | ||
99 | musb_readb(musb->mregs, MUSB_DEVCTL)); | ||
100 | } | ||
101 | |||
102 | static int musb_otg_notifications(struct notifier_block *nb, | ||
103 | unsigned long event, void *unused) | ||
104 | { | ||
105 | struct musb *musb = container_of(nb, struct musb, nb); | ||
106 | |||
107 | dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n", | ||
108 | event, usb_otg_state_string(musb->xceiv->state)); | ||
109 | |||
110 | switch (event) { | ||
111 | case UX500_MUSB_ID: | ||
112 | dev_dbg(musb->controller, "ID GND\n"); | ||
113 | ux500_musb_set_vbus(musb, 1); | ||
114 | break; | ||
115 | case UX500_MUSB_VBUS: | ||
116 | dev_dbg(musb->controller, "VBUS Connect\n"); | ||
117 | break; | ||
118 | case UX500_MUSB_NONE: | ||
119 | dev_dbg(musb->controller, "VBUS Disconnect\n"); | ||
120 | if (is_host_active(musb)) | ||
121 | ux500_musb_set_vbus(musb, 0); | ||
122 | else | ||
123 | musb->xceiv->state = OTG_STATE_B_IDLE; | ||
124 | break; | ||
125 | default: | ||
126 | dev_dbg(musb->controller, "ID float\n"); | ||
127 | return NOTIFY_DONE; | ||
128 | } | ||
129 | return NOTIFY_OK; | ||
130 | } | ||
131 | |||
39 | static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) | 132 | static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) |
40 | { | 133 | { |
41 | unsigned long flags; | 134 | unsigned long flags; |
@@ -58,12 +151,21 @@ static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) | |||
58 | 151 | ||
59 | static int ux500_musb_init(struct musb *musb) | 152 | static int ux500_musb_init(struct musb *musb) |
60 | { | 153 | { |
154 | int status; | ||
155 | |||
61 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 156 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
62 | if (IS_ERR_OR_NULL(musb->xceiv)) { | 157 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
63 | pr_err("HS USB OTG: no transceiver configured\n"); | 158 | pr_err("HS USB OTG: no transceiver configured\n"); |
64 | return -EPROBE_DEFER; | 159 | return -EPROBE_DEFER; |
65 | } | 160 | } |
66 | 161 | ||
162 | musb->nb.notifier_call = musb_otg_notifications; | ||
163 | status = usb_register_notifier(musb->xceiv, &musb->nb); | ||
164 | if (status < 0) { | ||
165 | dev_dbg(musb->controller, "notification register failed\n"); | ||
166 | return status; | ||
167 | } | ||
168 | |||
67 | musb->isr = ux500_musb_interrupt; | 169 | musb->isr = ux500_musb_interrupt; |
68 | 170 | ||
69 | return 0; | 171 | return 0; |
@@ -71,6 +173,8 @@ static int ux500_musb_init(struct musb *musb) | |||
71 | 173 | ||
72 | static int ux500_musb_exit(struct musb *musb) | 174 | static int ux500_musb_exit(struct musb *musb) |
73 | { | 175 | { |
176 | usb_unregister_notifier(musb->xceiv, &musb->nb); | ||
177 | |||
74 | usb_put_phy(musb->xceiv); | 178 | usb_put_phy(musb->xceiv); |
75 | 179 | ||
76 | return 0; | 180 | return 0; |
@@ -79,6 +183,8 @@ static int ux500_musb_exit(struct musb *musb) | |||
79 | static const struct musb_platform_ops ux500_ops = { | 183 | static const struct musb_platform_ops ux500_ops = { |
80 | .init = ux500_musb_init, | 184 | .init = ux500_musb_init, |
81 | .exit = ux500_musb_exit, | 185 | .exit = ux500_musb_exit, |
186 | |||
187 | .set_vbus = ux500_musb_set_vbus, | ||
82 | }; | 188 | }; |
83 | 189 | ||
84 | static int ux500_probe(struct platform_device *pdev) | 190 | static int ux500_probe(struct platform_device *pdev) |
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c index 039e567dd3b6..338120641145 100644 --- a/drivers/usb/musb/ux500_dma.c +++ b/drivers/usb/musb/ux500_dma.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * drivers/usb/musb/ux500_dma.c | 2 | * drivers/usb/musb/ux500_dma.c |
3 | * | 3 | * |
4 | * U8500 and U5500 DMA support code | 4 | * U8500 DMA support code |
5 | * | 5 | * |
6 | * Copyright (C) 2009 STMicroelectronics | 6 | * Copyright (C) 2009 STMicroelectronics |
7 | * Copyright (C) 2011 ST-Ericsson SA | 7 | * Copyright (C) 2011 ST-Ericsson SA |
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/dma-mapping.h> | 30 | #include <linux/dma-mapping.h> |
31 | #include <linux/dmaengine.h> | 31 | #include <linux/dmaengine.h> |
32 | #include <linux/pfn.h> | 32 | #include <linux/pfn.h> |
33 | #include <linux/sizes.h> | ||
33 | #include <linux/platform_data/usb-musb-ux500.h> | 34 | #include <linux/platform_data/usb-musb-ux500.h> |
34 | #include "musb_core.h" | 35 | #include "musb_core.h" |
35 | 36 | ||
@@ -56,7 +57,7 @@ struct ux500_dma_controller { | |||
56 | }; | 57 | }; |
57 | 58 | ||
58 | /* Work function invoked from DMA callback to handle rx transfers. */ | 59 | /* Work function invoked from DMA callback to handle rx transfers. */ |
59 | void ux500_dma_callback(void *private_data) | 60 | static void ux500_dma_callback(void *private_data) |
60 | { | 61 | { |
61 | struct dma_channel *channel = private_data; | 62 | struct dma_channel *channel = private_data; |
62 | struct ux500_dma_channel *ux500_channel = channel->private_data; | 63 | struct ux500_dma_channel *ux500_channel = channel->private_data; |
@@ -93,8 +94,9 @@ static bool ux500_configure_channel(struct dma_channel *channel, | |||
93 | struct musb *musb = ux500_channel->controller->private_data; | 94 | struct musb *musb = ux500_channel->controller->private_data; |
94 | 95 | ||
95 | dev_dbg(musb->controller, | 96 | dev_dbg(musb->controller, |
96 | "packet_sz=%d, mode=%d, dma_addr=0x%x, len=%d is_tx=%d\n", | 97 | "packet_sz=%d, mode=%d, dma_addr=0x%llu, len=%d is_tx=%d\n", |
97 | packet_sz, mode, dma_addr, len, ux500_channel->is_tx); | 98 | packet_sz, mode, (unsigned long long) dma_addr, |
99 | len, ux500_channel->is_tx); | ||
98 | 100 | ||
99 | ux500_channel->cur_len = len; | 101 | ux500_channel->cur_len = len; |
100 | 102 | ||
@@ -191,7 +193,7 @@ static int ux500_dma_is_compatible(struct dma_channel *channel, | |||
191 | u16 maxpacket, void *buf, u32 length) | 193 | u16 maxpacket, void *buf, u32 length) |
192 | { | 194 | { |
193 | if ((maxpacket & 0x3) || | 195 | if ((maxpacket & 0x3) || |
194 | ((int)buf & 0x3) || | 196 | ((unsigned long int) buf & 0x3) || |
195 | (length < 512) || | 197 | (length < 512) || |
196 | (length & 0x3)) | 198 | (length & 0x3)) |
197 | return false; | 199 | return false; |
@@ -372,12 +374,17 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba | |||
372 | 374 | ||
373 | controller = kzalloc(sizeof(*controller), GFP_KERNEL); | 375 | controller = kzalloc(sizeof(*controller), GFP_KERNEL); |
374 | if (!controller) | 376 | if (!controller) |
375 | return NULL; | 377 | goto kzalloc_fail; |
376 | 378 | ||
377 | controller->private_data = musb; | 379 | controller->private_data = musb; |
378 | 380 | ||
379 | /* Save physical address for DMA controller. */ | 381 | /* Save physical address for DMA controller. */ |
380 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 382 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
383 | if (!iomem) { | ||
384 | dev_err(musb->controller, "no memory resource defined\n"); | ||
385 | goto plat_get_fail; | ||
386 | } | ||
387 | |||
381 | controller->phy_base = (dma_addr_t) iomem->start; | 388 | controller->phy_base = (dma_addr_t) iomem->start; |
382 | 389 | ||
383 | controller->controller.start = ux500_dma_controller_start; | 390 | controller->controller.start = ux500_dma_controller_start; |
@@ -389,4 +396,9 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba | |||
389 | controller->controller.is_compatible = ux500_dma_is_compatible; | 396 | controller->controller.is_compatible = ux500_dma_is_compatible; |
390 | 397 | ||
391 | return &controller->controller; | 398 | return &controller->controller; |
399 | |||
400 | plat_get_fail: | ||
401 | kfree(controller); | ||
402 | kzalloc_fail: | ||
403 | return NULL; | ||
392 | } | 404 | } |
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig deleted file mode 100644 index 37962c99ff1e..000000000000 --- a/drivers/usb/otg/Kconfig +++ /dev/null | |||
@@ -1,141 +0,0 @@ | |||
1 | # | ||
2 | # USB OTG infrastructure may be needed for peripheral-only, host-only, | ||
3 | # or OTG-capable configurations when OTG transceivers or controllers | ||
4 | # are used. | ||
5 | # | ||
6 | |||
7 | comment "OTG and related infrastructure" | ||
8 | |||
9 | config USB_OTG_UTILS | ||
10 | bool | ||
11 | help | ||
12 | Select this to make sure the build includes objects from | ||
13 | the OTG infrastructure directory. | ||
14 | |||
15 | if USB || USB_GADGET | ||
16 | |||
17 | # | ||
18 | # USB Transceiver Drivers | ||
19 | # | ||
20 | config USB_GPIO_VBUS | ||
21 | tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" | ||
22 | depends on GENERIC_GPIO | ||
23 | select USB_OTG_UTILS | ||
24 | help | ||
25 | Provides simple GPIO VBUS sensing for controllers with an | ||
26 | internal transceiver via the usb_phy interface, and | ||
27 | optionally control of a D+ pullup GPIO as well as a VBUS | ||
28 | current limit regulator. | ||
29 | |||
30 | config ISP1301_OMAP | ||
31 | tristate "Philips ISP1301 with OMAP OTG" | ||
32 | depends on I2C && ARCH_OMAP_OTG | ||
33 | select USB_OTG_UTILS | ||
34 | help | ||
35 | If you say yes here you get support for the Philips ISP1301 | ||
36 | USB-On-The-Go transceiver working with the OMAP OTG controller. | ||
37 | The ISP1301 is a full speed USB transceiver which is used in | ||
38 | products including H2, H3, and H4 development boards for Texas | ||
39 | Instruments OMAP processors. | ||
40 | |||
41 | This driver can also be built as a module. If so, the module | ||
42 | will be called isp1301_omap. | ||
43 | |||
44 | config USB_ULPI | ||
45 | bool "Generic ULPI Transceiver Driver" | ||
46 | depends on ARM | ||
47 | select USB_OTG_UTILS | ||
48 | help | ||
49 | Enable this to support ULPI connected USB OTG transceivers which | ||
50 | are likely found on embedded boards. | ||
51 | |||
52 | config USB_ULPI_VIEWPORT | ||
53 | bool | ||
54 | depends on USB_ULPI | ||
55 | help | ||
56 | Provides read/write operations to the ULPI phy register set for | ||
57 | controllers with a viewport register (e.g. Chipidea/ARC controllers). | ||
58 | |||
59 | config TWL4030_USB | ||
60 | tristate "TWL4030 USB Transceiver Driver" | ||
61 | depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS | ||
62 | select USB_OTG_UTILS | ||
63 | help | ||
64 | Enable this to support the USB OTG transceiver on TWL4030 | ||
65 | family chips (including the TWL5030 and TPS659x0 devices). | ||
66 | This transceiver supports high and full speed devices plus, | ||
67 | in host mode, low speed. | ||
68 | |||
69 | config TWL6030_USB | ||
70 | tristate "TWL6030 USB Transceiver Driver" | ||
71 | depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS | ||
72 | select USB_OTG_UTILS | ||
73 | help | ||
74 | Enable this to support the USB OTG transceiver on TWL6030 | ||
75 | family chips. This TWL6030 transceiver has the VBUS and ID GND | ||
76 | and OTG SRP events capabilities. For all other transceiver functionality | ||
77 | UTMI PHY is embedded in OMAP4430. The internal PHY configurations APIs | ||
78 | are hooked to this driver through platform_data structure. | ||
79 | The definition of internal PHY APIs are in the mach-omap2 layer. | ||
80 | |||
81 | config NOP_USB_XCEIV | ||
82 | tristate "NOP USB Transceiver Driver" | ||
83 | select USB_OTG_UTILS | ||
84 | help | ||
85 | This driver is to be used by all the usb transceiver which are either | ||
86 | built-in with usb ip or which are autonomous and doesn't require any | ||
87 | phy programming such as ISP1x04 etc. | ||
88 | |||
89 | config USB_MSM_OTG | ||
90 | tristate "OTG support for Qualcomm on-chip USB controller" | ||
91 | depends on (USB || USB_GADGET) && ARCH_MSM | ||
92 | select USB_OTG_UTILS | ||
93 | help | ||
94 | Enable this to support the USB OTG transceiver on MSM chips. It | ||
95 | handles PHY initialization, clock management, and workarounds | ||
96 | required after resetting the hardware and power management. | ||
97 | This driver is required even for peripheral only or host only | ||
98 | mode configurations. | ||
99 | This driver is not supported on boards like trout which | ||
100 | has an external PHY. | ||
101 | |||
102 | config AB8500_USB | ||
103 | tristate "AB8500 USB Transceiver Driver" | ||
104 | depends on AB8500_CORE | ||
105 | select USB_OTG_UTILS | ||
106 | help | ||
107 | Enable this to support the USB OTG transceiver in AB8500 chip. | ||
108 | This transceiver supports high and full speed devices plus, | ||
109 | in host mode, low speed. | ||
110 | |||
111 | config FSL_USB2_OTG | ||
112 | bool "Freescale USB OTG Transceiver Driver" | ||
113 | depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_SUSPEND | ||
114 | select USB_OTG | ||
115 | select USB_OTG_UTILS | ||
116 | help | ||
117 | Enable this to support Freescale USB OTG transceiver. | ||
118 | |||
119 | config USB_MXS_PHY | ||
120 | tristate "Freescale MXS USB PHY support" | ||
121 | depends on ARCH_MXC || ARCH_MXS | ||
122 | select STMP_DEVICE | ||
123 | select USB_OTG_UTILS | ||
124 | help | ||
125 | Enable this to support the Freescale MXS USB PHY. | ||
126 | |||
127 | MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. | ||
128 | |||
129 | config USB_MV_OTG | ||
130 | tristate "Marvell USB OTG support" | ||
131 | depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND | ||
132 | select USB_OTG | ||
133 | select USB_OTG_UTILS | ||
134 | help | ||
135 | Say Y here if you want to build Marvell USB OTG transciever | ||
136 | driver in kernel (including PXA and MMP series). This driver | ||
137 | implements role switch between EHCI host driver and gadget driver. | ||
138 | |||
139 | To compile this driver as a module, choose M here. | ||
140 | |||
141 | endif # USB || OTG | ||
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile deleted file mode 100644 index a844b8d35d14..000000000000 --- a/drivers/usb/otg/Makefile +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | # | ||
2 | # OTG infrastructure and transceiver drivers | ||
3 | # | ||
4 | |||
5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | ||
6 | ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG | ||
7 | |||
8 | # infrastructure | ||
9 | obj-$(CONFIG_USB_OTG_UTILS) += otg.o | ||
10 | |||
11 | # transceiver drivers | ||
12 | obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o | ||
13 | obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o | ||
14 | obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o | ||
15 | obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o | ||
16 | obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o | ||
17 | obj-$(CONFIG_USB_ULPI) += ulpi.o | ||
18 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi_viewport.o | ||
19 | obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o | ||
20 | obj-$(CONFIG_AB8500_USB) += ab8500-usb.o | ||
21 | fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o | ||
22 | obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o | ||
23 | obj-$(CONFIG_USB_MXS_PHY) += mxs-phy.o | ||
24 | obj-$(CONFIG_USB_MV_OTG) += mv_otg.o | ||
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c deleted file mode 100644 index 2d86f26a0183..000000000000 --- a/drivers/usb/otg/ab8500-usb.c +++ /dev/null | |||
@@ -1,596 +0,0 @@ | |||
1 | /* | ||
2 | * drivers/usb/otg/ab8500_usb.c | ||
3 | * | ||
4 | * USB transceiver driver for AB8500 chip | ||
5 | * | ||
6 | * Copyright (C) 2010 ST-Ericsson AB | ||
7 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/module.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/usb/otg.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/notifier.h> | ||
30 | #include <linux/interrupt.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/mfd/abx500.h> | ||
33 | #include <linux/mfd/abx500/ab8500.h> | ||
34 | |||
35 | #define AB8500_MAIN_WD_CTRL_REG 0x01 | ||
36 | #define AB8500_USB_LINE_STAT_REG 0x80 | ||
37 | #define AB8500_USB_PHY_CTRL_REG 0x8A | ||
38 | |||
39 | #define AB8500_BIT_OTG_STAT_ID (1 << 0) | ||
40 | #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0) | ||
41 | #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1) | ||
42 | #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0) | ||
43 | #define AB8500_BIT_WD_CTRL_KICK (1 << 1) | ||
44 | |||
45 | #define AB8500_V1x_LINK_STAT_WAIT (HZ/10) | ||
46 | #define AB8500_WD_KICK_DELAY_US 100 /* usec */ | ||
47 | #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */ | ||
48 | #define AB8500_WD_V10_DISABLE_DELAY_MS 100 /* ms */ | ||
49 | |||
50 | /* Usb line status register */ | ||
51 | enum ab8500_usb_link_status { | ||
52 | USB_LINK_NOT_CONFIGURED = 0, | ||
53 | USB_LINK_STD_HOST_NC, | ||
54 | USB_LINK_STD_HOST_C_NS, | ||
55 | USB_LINK_STD_HOST_C_S, | ||
56 | USB_LINK_HOST_CHG_NM, | ||
57 | USB_LINK_HOST_CHG_HS, | ||
58 | USB_LINK_HOST_CHG_HS_CHIRP, | ||
59 | USB_LINK_DEDICATED_CHG, | ||
60 | USB_LINK_ACA_RID_A, | ||
61 | USB_LINK_ACA_RID_B, | ||
62 | USB_LINK_ACA_RID_C_NM, | ||
63 | USB_LINK_ACA_RID_C_HS, | ||
64 | USB_LINK_ACA_RID_C_HS_CHIRP, | ||
65 | USB_LINK_HM_IDGND, | ||
66 | USB_LINK_RESERVED, | ||
67 | USB_LINK_NOT_VALID_LINK | ||
68 | }; | ||
69 | |||
70 | struct ab8500_usb { | ||
71 | struct usb_phy phy; | ||
72 | struct device *dev; | ||
73 | int irq_num_id_rise; | ||
74 | int irq_num_id_fall; | ||
75 | int irq_num_vbus_rise; | ||
76 | int irq_num_vbus_fall; | ||
77 | int irq_num_link_status; | ||
78 | unsigned vbus_draw; | ||
79 | struct delayed_work dwork; | ||
80 | struct work_struct phy_dis_work; | ||
81 | unsigned long link_status_wait; | ||
82 | int rev; | ||
83 | }; | ||
84 | |||
85 | static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x) | ||
86 | { | ||
87 | return container_of(x, struct ab8500_usb, phy); | ||
88 | } | ||
89 | |||
90 | static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) | ||
91 | { | ||
92 | abx500_set_register_interruptible(ab->dev, | ||
93 | AB8500_SYS_CTRL2_BLOCK, | ||
94 | AB8500_MAIN_WD_CTRL_REG, | ||
95 | AB8500_BIT_WD_CTRL_ENABLE); | ||
96 | |||
97 | udelay(AB8500_WD_KICK_DELAY_US); | ||
98 | |||
99 | abx500_set_register_interruptible(ab->dev, | ||
100 | AB8500_SYS_CTRL2_BLOCK, | ||
101 | AB8500_MAIN_WD_CTRL_REG, | ||
102 | (AB8500_BIT_WD_CTRL_ENABLE | ||
103 | | AB8500_BIT_WD_CTRL_KICK)); | ||
104 | |||
105 | if (ab->rev > 0x10) /* v1.1 v2.0 */ | ||
106 | udelay(AB8500_WD_V11_DISABLE_DELAY_US); | ||
107 | else /* v1.0 */ | ||
108 | msleep(AB8500_WD_V10_DISABLE_DELAY_MS); | ||
109 | |||
110 | abx500_set_register_interruptible(ab->dev, | ||
111 | AB8500_SYS_CTRL2_BLOCK, | ||
112 | AB8500_MAIN_WD_CTRL_REG, | ||
113 | 0); | ||
114 | } | ||
115 | |||
116 | static void ab8500_usb_phy_ctrl(struct ab8500_usb *ab, bool sel_host, | ||
117 | bool enable) | ||
118 | { | ||
119 | u8 ctrl_reg; | ||
120 | abx500_get_register_interruptible(ab->dev, | ||
121 | AB8500_USB, | ||
122 | AB8500_USB_PHY_CTRL_REG, | ||
123 | &ctrl_reg); | ||
124 | if (sel_host) { | ||
125 | if (enable) | ||
126 | ctrl_reg |= AB8500_BIT_PHY_CTRL_HOST_EN; | ||
127 | else | ||
128 | ctrl_reg &= ~AB8500_BIT_PHY_CTRL_HOST_EN; | ||
129 | } else { | ||
130 | if (enable) | ||
131 | ctrl_reg |= AB8500_BIT_PHY_CTRL_DEVICE_EN; | ||
132 | else | ||
133 | ctrl_reg &= ~AB8500_BIT_PHY_CTRL_DEVICE_EN; | ||
134 | } | ||
135 | |||
136 | abx500_set_register_interruptible(ab->dev, | ||
137 | AB8500_USB, | ||
138 | AB8500_USB_PHY_CTRL_REG, | ||
139 | ctrl_reg); | ||
140 | |||
141 | /* Needed to enable the phy.*/ | ||
142 | if (enable) | ||
143 | ab8500_usb_wd_workaround(ab); | ||
144 | } | ||
145 | |||
146 | #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_ctrl(ab, true, true) | ||
147 | #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_ctrl(ab, true, false) | ||
148 | #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_ctrl(ab, false, true) | ||
149 | #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_ctrl(ab, false, false) | ||
150 | |||
151 | static int ab8500_usb_link_status_update(struct ab8500_usb *ab) | ||
152 | { | ||
153 | u8 reg; | ||
154 | enum ab8500_usb_link_status lsts; | ||
155 | void *v = NULL; | ||
156 | enum usb_phy_events event; | ||
157 | |||
158 | abx500_get_register_interruptible(ab->dev, | ||
159 | AB8500_USB, | ||
160 | AB8500_USB_LINE_STAT_REG, | ||
161 | ®); | ||
162 | |||
163 | lsts = (reg >> 3) & 0x0F; | ||
164 | |||
165 | switch (lsts) { | ||
166 | case USB_LINK_NOT_CONFIGURED: | ||
167 | case USB_LINK_RESERVED: | ||
168 | case USB_LINK_NOT_VALID_LINK: | ||
169 | /* TODO: Disable regulators. */ | ||
170 | ab8500_usb_host_phy_dis(ab); | ||
171 | ab8500_usb_peri_phy_dis(ab); | ||
172 | ab->phy.state = OTG_STATE_B_IDLE; | ||
173 | ab->phy.otg->default_a = false; | ||
174 | ab->vbus_draw = 0; | ||
175 | event = USB_EVENT_NONE; | ||
176 | break; | ||
177 | |||
178 | case USB_LINK_STD_HOST_NC: | ||
179 | case USB_LINK_STD_HOST_C_NS: | ||
180 | case USB_LINK_STD_HOST_C_S: | ||
181 | case USB_LINK_HOST_CHG_NM: | ||
182 | case USB_LINK_HOST_CHG_HS: | ||
183 | case USB_LINK_HOST_CHG_HS_CHIRP: | ||
184 | if (ab->phy.otg->gadget) { | ||
185 | /* TODO: Enable regulators. */ | ||
186 | ab8500_usb_peri_phy_en(ab); | ||
187 | v = ab->phy.otg->gadget; | ||
188 | } | ||
189 | event = USB_EVENT_VBUS; | ||
190 | break; | ||
191 | |||
192 | case USB_LINK_HM_IDGND: | ||
193 | if (ab->phy.otg->host) { | ||
194 | /* TODO: Enable regulators. */ | ||
195 | ab8500_usb_host_phy_en(ab); | ||
196 | v = ab->phy.otg->host; | ||
197 | } | ||
198 | ab->phy.state = OTG_STATE_A_IDLE; | ||
199 | ab->phy.otg->default_a = true; | ||
200 | event = USB_EVENT_ID; | ||
201 | break; | ||
202 | |||
203 | case USB_LINK_ACA_RID_A: | ||
204 | case USB_LINK_ACA_RID_B: | ||
205 | /* TODO */ | ||
206 | case USB_LINK_ACA_RID_C_NM: | ||
207 | case USB_LINK_ACA_RID_C_HS: | ||
208 | case USB_LINK_ACA_RID_C_HS_CHIRP: | ||
209 | case USB_LINK_DEDICATED_CHG: | ||
210 | /* TODO: vbus_draw */ | ||
211 | event = USB_EVENT_CHARGER; | ||
212 | break; | ||
213 | } | ||
214 | |||
215 | atomic_notifier_call_chain(&ab->phy.notifier, event, v); | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | static void ab8500_usb_delayed_work(struct work_struct *work) | ||
221 | { | ||
222 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, | ||
223 | dwork.work); | ||
224 | |||
225 | ab8500_usb_link_status_update(ab); | ||
226 | } | ||
227 | |||
228 | static irqreturn_t ab8500_usb_v1x_common_irq(int irq, void *data) | ||
229 | { | ||
230 | struct ab8500_usb *ab = (struct ab8500_usb *) data; | ||
231 | |||
232 | /* Wait for link status to become stable. */ | ||
233 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); | ||
234 | |||
235 | return IRQ_HANDLED; | ||
236 | } | ||
237 | |||
238 | static irqreturn_t ab8500_usb_v1x_vbus_fall_irq(int irq, void *data) | ||
239 | { | ||
240 | struct ab8500_usb *ab = (struct ab8500_usb *) data; | ||
241 | |||
242 | /* Link status will not be updated till phy is disabled. */ | ||
243 | ab8500_usb_peri_phy_dis(ab); | ||
244 | |||
245 | /* Wait for link status to become stable. */ | ||
246 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); | ||
247 | |||
248 | return IRQ_HANDLED; | ||
249 | } | ||
250 | |||
251 | static irqreturn_t ab8500_usb_v20_irq(int irq, void *data) | ||
252 | { | ||
253 | struct ab8500_usb *ab = (struct ab8500_usb *) data; | ||
254 | |||
255 | ab8500_usb_link_status_update(ab); | ||
256 | |||
257 | return IRQ_HANDLED; | ||
258 | } | ||
259 | |||
260 | static void ab8500_usb_phy_disable_work(struct work_struct *work) | ||
261 | { | ||
262 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, | ||
263 | phy_dis_work); | ||
264 | |||
265 | if (!ab->phy.otg->host) | ||
266 | ab8500_usb_host_phy_dis(ab); | ||
267 | |||
268 | if (!ab->phy.otg->gadget) | ||
269 | ab8500_usb_peri_phy_dis(ab); | ||
270 | } | ||
271 | |||
272 | static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA) | ||
273 | { | ||
274 | struct ab8500_usb *ab; | ||
275 | |||
276 | if (!phy) | ||
277 | return -ENODEV; | ||
278 | |||
279 | ab = phy_to_ab(phy); | ||
280 | |||
281 | ab->vbus_draw = mA; | ||
282 | |||
283 | if (mA) | ||
284 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
285 | USB_EVENT_ENUMERATED, ab->phy.otg->gadget); | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | /* TODO: Implement some way for charging or other drivers to read | ||
290 | * ab->vbus_draw. | ||
291 | */ | ||
292 | |||
293 | static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend) | ||
294 | { | ||
295 | /* TODO */ | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static int ab8500_usb_set_peripheral(struct usb_otg *otg, | ||
300 | struct usb_gadget *gadget) | ||
301 | { | ||
302 | struct ab8500_usb *ab; | ||
303 | |||
304 | if (!otg) | ||
305 | return -ENODEV; | ||
306 | |||
307 | ab = phy_to_ab(otg->phy); | ||
308 | |||
309 | /* Some drivers call this function in atomic context. | ||
310 | * Do not update ab8500 registers directly till this | ||
311 | * is fixed. | ||
312 | */ | ||
313 | |||
314 | if (!gadget) { | ||
315 | /* TODO: Disable regulators. */ | ||
316 | otg->gadget = NULL; | ||
317 | schedule_work(&ab->phy_dis_work); | ||
318 | } else { | ||
319 | otg->gadget = gadget; | ||
320 | otg->phy->state = OTG_STATE_B_IDLE; | ||
321 | |||
322 | /* Phy will not be enabled if cable is already | ||
323 | * plugged-in. Schedule to enable phy. | ||
324 | * Use same delay to avoid any race condition. | ||
325 | */ | ||
326 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); | ||
327 | } | ||
328 | |||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | ||
333 | { | ||
334 | struct ab8500_usb *ab; | ||
335 | |||
336 | if (!otg) | ||
337 | return -ENODEV; | ||
338 | |||
339 | ab = phy_to_ab(otg->phy); | ||
340 | |||
341 | /* Some drivers call this function in atomic context. | ||
342 | * Do not update ab8500 registers directly till this | ||
343 | * is fixed. | ||
344 | */ | ||
345 | |||
346 | if (!host) { | ||
347 | /* TODO: Disable regulators. */ | ||
348 | otg->host = NULL; | ||
349 | schedule_work(&ab->phy_dis_work); | ||
350 | } else { | ||
351 | otg->host = host; | ||
352 | /* Phy will not be enabled if cable is already | ||
353 | * plugged-in. Schedule to enable phy. | ||
354 | * Use same delay to avoid any race condition. | ||
355 | */ | ||
356 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); | ||
357 | } | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static void ab8500_usb_irq_free(struct ab8500_usb *ab) | ||
363 | { | ||
364 | if (ab->rev < 0x20) { | ||
365 | free_irq(ab->irq_num_id_rise, ab); | ||
366 | free_irq(ab->irq_num_id_fall, ab); | ||
367 | free_irq(ab->irq_num_vbus_rise, ab); | ||
368 | free_irq(ab->irq_num_vbus_fall, ab); | ||
369 | } else { | ||
370 | free_irq(ab->irq_num_link_status, ab); | ||
371 | } | ||
372 | } | ||
373 | |||
374 | static int ab8500_usb_v1x_res_setup(struct platform_device *pdev, | ||
375 | struct ab8500_usb *ab) | ||
376 | { | ||
377 | int err; | ||
378 | |||
379 | ab->irq_num_id_rise = platform_get_irq_byname(pdev, "ID_WAKEUP_R"); | ||
380 | if (ab->irq_num_id_rise < 0) { | ||
381 | dev_err(&pdev->dev, "ID rise irq not found\n"); | ||
382 | return ab->irq_num_id_rise; | ||
383 | } | ||
384 | err = request_threaded_irq(ab->irq_num_id_rise, NULL, | ||
385 | ab8500_usb_v1x_common_irq, | ||
386 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
387 | "usb-id-rise", ab); | ||
388 | if (err < 0) { | ||
389 | dev_err(ab->dev, "request_irq failed for ID rise irq\n"); | ||
390 | goto fail0; | ||
391 | } | ||
392 | |||
393 | ab->irq_num_id_fall = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); | ||
394 | if (ab->irq_num_id_fall < 0) { | ||
395 | dev_err(&pdev->dev, "ID fall irq not found\n"); | ||
396 | return ab->irq_num_id_fall; | ||
397 | } | ||
398 | err = request_threaded_irq(ab->irq_num_id_fall, NULL, | ||
399 | ab8500_usb_v1x_common_irq, | ||
400 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
401 | "usb-id-fall", ab); | ||
402 | if (err < 0) { | ||
403 | dev_err(ab->dev, "request_irq failed for ID fall irq\n"); | ||
404 | goto fail1; | ||
405 | } | ||
406 | |||
407 | ab->irq_num_vbus_rise = platform_get_irq_byname(pdev, "VBUS_DET_R"); | ||
408 | if (ab->irq_num_vbus_rise < 0) { | ||
409 | dev_err(&pdev->dev, "VBUS rise irq not found\n"); | ||
410 | return ab->irq_num_vbus_rise; | ||
411 | } | ||
412 | err = request_threaded_irq(ab->irq_num_vbus_rise, NULL, | ||
413 | ab8500_usb_v1x_common_irq, | ||
414 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
415 | "usb-vbus-rise", ab); | ||
416 | if (err < 0) { | ||
417 | dev_err(ab->dev, "request_irq failed for Vbus rise irq\n"); | ||
418 | goto fail2; | ||
419 | } | ||
420 | |||
421 | ab->irq_num_vbus_fall = platform_get_irq_byname(pdev, "VBUS_DET_F"); | ||
422 | if (ab->irq_num_vbus_fall < 0) { | ||
423 | dev_err(&pdev->dev, "VBUS fall irq not found\n"); | ||
424 | return ab->irq_num_vbus_fall; | ||
425 | } | ||
426 | err = request_threaded_irq(ab->irq_num_vbus_fall, NULL, | ||
427 | ab8500_usb_v1x_vbus_fall_irq, | ||
428 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
429 | "usb-vbus-fall", ab); | ||
430 | if (err < 0) { | ||
431 | dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); | ||
432 | goto fail3; | ||
433 | } | ||
434 | |||
435 | return 0; | ||
436 | fail3: | ||
437 | free_irq(ab->irq_num_vbus_rise, ab); | ||
438 | fail2: | ||
439 | free_irq(ab->irq_num_id_fall, ab); | ||
440 | fail1: | ||
441 | free_irq(ab->irq_num_id_rise, ab); | ||
442 | fail0: | ||
443 | return err; | ||
444 | } | ||
445 | |||
446 | static int ab8500_usb_v2_res_setup(struct platform_device *pdev, | ||
447 | struct ab8500_usb *ab) | ||
448 | { | ||
449 | int err; | ||
450 | |||
451 | ab->irq_num_link_status = platform_get_irq_byname(pdev, | ||
452 | "USB_LINK_STATUS"); | ||
453 | if (ab->irq_num_link_status < 0) { | ||
454 | dev_err(&pdev->dev, "Link status irq not found\n"); | ||
455 | return ab->irq_num_link_status; | ||
456 | } | ||
457 | |||
458 | err = request_threaded_irq(ab->irq_num_link_status, NULL, | ||
459 | ab8500_usb_v20_irq, | ||
460 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
461 | "usb-link-status", ab); | ||
462 | if (err < 0) { | ||
463 | dev_err(ab->dev, | ||
464 | "request_irq failed for link status irq\n"); | ||
465 | return err; | ||
466 | } | ||
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static int ab8500_usb_probe(struct platform_device *pdev) | ||
472 | { | ||
473 | struct ab8500_usb *ab; | ||
474 | struct usb_otg *otg; | ||
475 | int err; | ||
476 | int rev; | ||
477 | |||
478 | rev = abx500_get_chip_id(&pdev->dev); | ||
479 | if (rev < 0) { | ||
480 | dev_err(&pdev->dev, "Chip id read failed\n"); | ||
481 | return rev; | ||
482 | } else if (rev < 0x10) { | ||
483 | dev_err(&pdev->dev, "Unsupported AB8500 chip\n"); | ||
484 | return -ENODEV; | ||
485 | } | ||
486 | |||
487 | ab = kzalloc(sizeof *ab, GFP_KERNEL); | ||
488 | if (!ab) | ||
489 | return -ENOMEM; | ||
490 | |||
491 | otg = kzalloc(sizeof *otg, GFP_KERNEL); | ||
492 | if (!otg) { | ||
493 | kfree(ab); | ||
494 | return -ENOMEM; | ||
495 | } | ||
496 | |||
497 | ab->dev = &pdev->dev; | ||
498 | ab->rev = rev; | ||
499 | ab->phy.dev = ab->dev; | ||
500 | ab->phy.otg = otg; | ||
501 | ab->phy.label = "ab8500"; | ||
502 | ab->phy.set_suspend = ab8500_usb_set_suspend; | ||
503 | ab->phy.set_power = ab8500_usb_set_power; | ||
504 | ab->phy.state = OTG_STATE_UNDEFINED; | ||
505 | |||
506 | otg->phy = &ab->phy; | ||
507 | otg->set_host = ab8500_usb_set_host; | ||
508 | otg->set_peripheral = ab8500_usb_set_peripheral; | ||
509 | |||
510 | platform_set_drvdata(pdev, ab); | ||
511 | |||
512 | ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); | ||
513 | |||
514 | /* v1: Wait for link status to become stable. | ||
515 | * all: Updates form set_host and set_peripheral as they are atomic. | ||
516 | */ | ||
517 | INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work); | ||
518 | |||
519 | /* all: Disable phy when called from set_host and set_peripheral */ | ||
520 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); | ||
521 | |||
522 | if (ab->rev < 0x20) { | ||
523 | err = ab8500_usb_v1x_res_setup(pdev, ab); | ||
524 | ab->link_status_wait = AB8500_V1x_LINK_STAT_WAIT; | ||
525 | } else { | ||
526 | err = ab8500_usb_v2_res_setup(pdev, ab); | ||
527 | } | ||
528 | |||
529 | if (err < 0) | ||
530 | goto fail0; | ||
531 | |||
532 | err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2); | ||
533 | if (err) { | ||
534 | dev_err(&pdev->dev, "Can't register transceiver\n"); | ||
535 | goto fail1; | ||
536 | } | ||
537 | |||
538 | dev_info(&pdev->dev, "AB8500 usb driver initialized\n"); | ||
539 | |||
540 | return 0; | ||
541 | fail1: | ||
542 | ab8500_usb_irq_free(ab); | ||
543 | fail0: | ||
544 | kfree(otg); | ||
545 | kfree(ab); | ||
546 | return err; | ||
547 | } | ||
548 | |||
549 | static int ab8500_usb_remove(struct platform_device *pdev) | ||
550 | { | ||
551 | struct ab8500_usb *ab = platform_get_drvdata(pdev); | ||
552 | |||
553 | ab8500_usb_irq_free(ab); | ||
554 | |||
555 | cancel_delayed_work_sync(&ab->dwork); | ||
556 | |||
557 | cancel_work_sync(&ab->phy_dis_work); | ||
558 | |||
559 | usb_remove_phy(&ab->phy); | ||
560 | |||
561 | ab8500_usb_host_phy_dis(ab); | ||
562 | ab8500_usb_peri_phy_dis(ab); | ||
563 | |||
564 | platform_set_drvdata(pdev, NULL); | ||
565 | |||
566 | kfree(ab->phy.otg); | ||
567 | kfree(ab); | ||
568 | |||
569 | return 0; | ||
570 | } | ||
571 | |||
572 | static struct platform_driver ab8500_usb_driver = { | ||
573 | .probe = ab8500_usb_probe, | ||
574 | .remove = ab8500_usb_remove, | ||
575 | .driver = { | ||
576 | .name = "ab8500-usb", | ||
577 | .owner = THIS_MODULE, | ||
578 | }, | ||
579 | }; | ||
580 | |||
581 | static int __init ab8500_usb_init(void) | ||
582 | { | ||
583 | return platform_driver_register(&ab8500_usb_driver); | ||
584 | } | ||
585 | subsys_initcall(ab8500_usb_init); | ||
586 | |||
587 | static void __exit ab8500_usb_exit(void) | ||
588 | { | ||
589 | platform_driver_unregister(&ab8500_usb_driver); | ||
590 | } | ||
591 | module_exit(ab8500_usb_exit); | ||
592 | |||
593 | MODULE_ALIAS("platform:ab8500_usb"); | ||
594 | MODULE_AUTHOR("ST-Ericsson AB"); | ||
595 | MODULE_DESCRIPTION("AB8500 usb transceiver driver"); | ||
596 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 90549382eba5..3a7fec957ca7 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig | |||
@@ -1,13 +1,74 @@ | |||
1 | # | 1 | # |
2 | # Physical Layer USB driver configuration | 2 | # Physical Layer USB driver configuration |
3 | # | 3 | # |
4 | comment "USB Physical Layer drivers" | 4 | menuconfig USB_PHY |
5 | depends on USB || USB_GADGET | 5 | tristate "USB Physical Layer drivers" |
6 | help | ||
7 | USB controllers (those which are host, device or DRD) need a | ||
8 | device to handle the physical layer signalling, commonly called | ||
9 | a PHY. | ||
10 | |||
11 | The following drivers add support for such PHY devices. | ||
12 | |||
13 | if USB_PHY | ||
14 | |||
15 | # | ||
16 | # USB Transceiver Drivers | ||
17 | # | ||
18 | config AB8500_USB | ||
19 | tristate "AB8500 USB Transceiver Driver" | ||
20 | depends on AB8500_CORE | ||
21 | help | ||
22 | Enable this to support the USB OTG transceiver in AB8500 chip. | ||
23 | This transceiver supports high and full speed devices plus, | ||
24 | in host mode, low speed. | ||
25 | |||
26 | config FSL_USB2_OTG | ||
27 | bool "Freescale USB OTG Transceiver Driver" | ||
28 | depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_SUSPEND | ||
29 | select USB_OTG | ||
30 | help | ||
31 | Enable this to support Freescale USB OTG transceiver. | ||
32 | |||
33 | config ISP1301_OMAP | ||
34 | tristate "Philips ISP1301 with OMAP OTG" | ||
35 | depends on I2C && ARCH_OMAP_OTG | ||
36 | help | ||
37 | If you say yes here you get support for the Philips ISP1301 | ||
38 | USB-On-The-Go transceiver working with the OMAP OTG controller. | ||
39 | The ISP1301 is a full speed USB transceiver which is used in | ||
40 | products including H2, H3, and H4 development boards for Texas | ||
41 | Instruments OMAP processors. | ||
42 | |||
43 | This driver can also be built as a module. If so, the module | ||
44 | will be called isp1301_omap. | ||
45 | |||
46 | config MV_U3D_PHY | ||
47 | bool "Marvell USB 3.0 PHY controller Driver" | ||
48 | depends on CPU_MMP3 | ||
49 | help | ||
50 | Enable this to support Marvell USB 3.0 phy controller for Marvell | ||
51 | SoC. | ||
52 | |||
53 | config NOP_USB_XCEIV | ||
54 | tristate "NOP USB Transceiver Driver" | ||
55 | help | ||
56 | This driver is to be used by all the usb transceiver which are either | ||
57 | built-in with usb ip or which are autonomous and doesn't require any | ||
58 | phy programming such as ISP1x04 etc. | ||
59 | |||
60 | config OMAP_CONTROL_USB | ||
61 | tristate "OMAP CONTROL USB Driver" | ||
62 | help | ||
63 | Enable this to add support for the USB part present in the control | ||
64 | module. This driver has API to power on the USB2 PHY and to write to | ||
65 | the mailbox. The mailbox is present only in omap4 and the register to | ||
66 | power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an | ||
67 | additional register to power on USB3 PHY. | ||
6 | 68 | ||
7 | config OMAP_USB2 | 69 | config OMAP_USB2 |
8 | tristate "OMAP USB2 PHY Driver" | 70 | tristate "OMAP USB2 PHY Driver" |
9 | depends on ARCH_OMAP2PLUS | 71 | depends on ARCH_OMAP2PLUS |
10 | select USB_OTG_UTILS | ||
11 | select OMAP_CONTROL_USB | 72 | select OMAP_CONTROL_USB |
12 | help | 73 | help |
13 | Enable this to support the transceiver that is part of SOC. This | 74 | Enable this to support the transceiver that is part of SOC. This |
@@ -17,7 +78,6 @@ config OMAP_USB2 | |||
17 | 78 | ||
18 | config OMAP_USB3 | 79 | config OMAP_USB3 |
19 | tristate "OMAP USB3 PHY Driver" | 80 | tristate "OMAP USB3 PHY Driver" |
20 | select USB_OTG_UTILS | ||
21 | select OMAP_CONTROL_USB | 81 | select OMAP_CONTROL_USB |
22 | help | 82 | help |
23 | Enable this to support the USB3 PHY that is part of SOC. This | 83 | Enable this to support the USB3 PHY that is part of SOC. This |
@@ -25,14 +85,55 @@ config OMAP_USB3 | |||
25 | This driver interacts with the "OMAP Control USB Driver" to power | 85 | This driver interacts with the "OMAP Control USB Driver" to power |
26 | on/off the PHY. | 86 | on/off the PHY. |
27 | 87 | ||
28 | config OMAP_CONTROL_USB | 88 | config SAMSUNG_USBPHY |
29 | tristate "OMAP CONTROL USB Driver" | 89 | tristate "Samsung USB PHY Driver" |
30 | help | 90 | help |
31 | Enable this to add support for the USB part present in the control | 91 | Enable this to support Samsung USB phy helper driver for Samsung SoCs. |
32 | module. This driver has API to power on the USB2 PHY and to write to | 92 | This driver provides common interface to interact, for Samsung USB 2.0 PHY |
33 | the mailbox. The mailbox is present only in omap4 and the register to | 93 | driver and later for Samsung USB 3.0 PHY driver. |
34 | power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an | 94 | |
35 | additional register to power on USB3 PHY. | 95 | config SAMSUNG_USB2PHY |
96 | tristate "Samsung USB 2.0 PHY controller Driver" | ||
97 | select SAMSUNG_USBPHY | ||
98 | help | ||
99 | Enable this to support Samsung USB 2.0 (High Speed) PHY controller | ||
100 | driver for Samsung SoCs. | ||
101 | |||
102 | config SAMSUNG_USB3PHY | ||
103 | tristate "Samsung USB 3.0 PHY controller Driver" | ||
104 | select SAMSUNG_USBPHY | ||
105 | help | ||
106 | Enable this to support Samsung USB 3.0 (Super Speed) phy controller | ||
107 | for samsung SoCs. | ||
108 | |||
109 | config TWL4030_USB | ||
110 | tristate "TWL4030 USB Transceiver Driver" | ||
111 | depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS | ||
112 | help | ||
113 | Enable this to support the USB OTG transceiver on TWL4030 | ||
114 | family chips (including the TWL5030 and TPS659x0 devices). | ||
115 | This transceiver supports high and full speed devices plus, | ||
116 | in host mode, low speed. | ||
117 | |||
118 | config TWL6030_USB | ||
119 | tristate "TWL6030 USB Transceiver Driver" | ||
120 | depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS | ||
121 | help | ||
122 | Enable this to support the USB OTG transceiver on TWL6030 | ||
123 | family chips. This TWL6030 transceiver has the VBUS and ID GND | ||
124 | and OTG SRP events capabilities. For all other transceiver functionality | ||
125 | UTMI PHY is embedded in OMAP4430. The internal PHY configurations APIs | ||
126 | are hooked to this driver through platform_data structure. | ||
127 | The definition of internal PHY APIs are in the mach-omap2 layer. | ||
128 | |||
129 | config USB_GPIO_VBUS | ||
130 | tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" | ||
131 | depends on GENERIC_GPIO | ||
132 | help | ||
133 | Provides simple GPIO VBUS sensing for controllers with an | ||
134 | internal transceiver via the usb_phy interface, and | ||
135 | optionally control of a D+ pullup GPIO as well as a VBUS | ||
136 | current limit regulator. | ||
36 | 137 | ||
37 | config USB_ISP1301 | 138 | config USB_ISP1301 |
38 | tristate "NXP ISP1301 USB transceiver support" | 139 | tristate "NXP ISP1301 USB transceiver support" |
@@ -47,18 +148,41 @@ config USB_ISP1301 | |||
47 | To compile this driver as a module, choose M here: the | 148 | To compile this driver as a module, choose M here: the |
48 | module will be called isp1301. | 149 | module will be called isp1301. |
49 | 150 | ||
50 | config MV_U3D_PHY | 151 | config USB_MSM_OTG |
51 | bool "Marvell USB 3.0 PHY controller Driver" | 152 | tristate "OTG support for Qualcomm on-chip USB controller" |
52 | depends on USB_MV_U3D | 153 | depends on (USB || USB_GADGET) && ARCH_MSM |
53 | select USB_OTG_UTILS | ||
54 | help | 154 | help |
55 | Enable this to support Marvell USB 3.0 phy controller for Marvell | 155 | Enable this to support the USB OTG transceiver on MSM chips. It |
56 | SoC. | 156 | handles PHY initialization, clock management, and workarounds |
157 | required after resetting the hardware and power management. | ||
158 | This driver is required even for peripheral only or host only | ||
159 | mode configurations. | ||
160 | This driver is not supported on boards like trout which | ||
161 | has an external PHY. | ||
162 | |||
163 | config USB_MV_OTG | ||
164 | tristate "Marvell USB OTG support" | ||
165 | depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND | ||
166 | select USB_OTG | ||
167 | help | ||
168 | Say Y here if you want to build Marvell USB OTG transciever | ||
169 | driver in kernel (including PXA and MMP series). This driver | ||
170 | implements role switch between EHCI host driver and gadget driver. | ||
171 | |||
172 | To compile this driver as a module, choose M here. | ||
173 | |||
174 | config USB_MXS_PHY | ||
175 | tristate "Freescale MXS USB PHY support" | ||
176 | depends on ARCH_MXC || ARCH_MXS | ||
177 | select STMP_DEVICE | ||
178 | help | ||
179 | Enable this to support the Freescale MXS USB PHY. | ||
180 | |||
181 | MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. | ||
57 | 182 | ||
58 | config USB_RCAR_PHY | 183 | config USB_RCAR_PHY |
59 | tristate "Renesas R-Car USB phy support" | 184 | tristate "Renesas R-Car USB phy support" |
60 | depends on USB || USB_GADGET | 185 | depends on USB || USB_GADGET |
61 | select USB_OTG_UTILS | ||
62 | help | 186 | help |
63 | Say Y here to add support for the Renesas R-Car USB phy driver. | 187 | Say Y here to add support for the Renesas R-Car USB phy driver. |
64 | This chip is typically used as USB phy for USB host, gadget. | 188 | This chip is typically used as USB phy for USB host, gadget. |
@@ -67,10 +191,18 @@ config USB_RCAR_PHY | |||
67 | To compile this driver as a module, choose M here: the | 191 | To compile this driver as a module, choose M here: the |
68 | module will be called rcar-phy. | 192 | module will be called rcar-phy. |
69 | 193 | ||
70 | config SAMSUNG_USBPHY | 194 | config USB_ULPI |
71 | bool "Samsung USB PHY controller Driver" | 195 | bool "Generic ULPI Transceiver Driver" |
72 | depends on USB_S3C_HSOTG || USB_EHCI_S5P || USB_OHCI_EXYNOS | 196 | depends on ARM |
73 | select USB_OTG_UTILS | 197 | help |
198 | Enable this to support ULPI connected USB OTG transceivers which | ||
199 | are likely found on embedded boards. | ||
200 | |||
201 | config USB_ULPI_VIEWPORT | ||
202 | bool | ||
203 | depends on USB_ULPI | ||
74 | help | 204 | help |
75 | Enable this to support Samsung USB phy controller for samsung | 205 | Provides read/write operations to the ULPI phy register set for |
76 | SoCs. | 206 | controllers with a viewport register (e.g. Chipidea/ARC controllers). |
207 | |||
208 | endif # USB_PHY | ||
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index b13faa193e0c..33863c09f3dc 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile | |||
@@ -4,11 +4,30 @@ | |||
4 | 4 | ||
5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | 5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG |
6 | 6 | ||
7 | obj-$(CONFIG_OMAP_USB2) += omap-usb2.o | 7 | obj-$(CONFIG_USB_PHY) += phy.o |
8 | obj-$(CONFIG_OMAP_USB3) += omap-usb3.o | 8 | |
9 | obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o | 9 | # transceiver drivers, keep the list sorted |
10 | obj-$(CONFIG_USB_ISP1301) += isp1301.o | 10 | |
11 | obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o | 11 | obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o |
12 | obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o | 12 | phy-fsl-usb2-objs := phy-fsl-usb.o phy-fsm-usb.o |
13 | obj-$(CONFIG_USB_RCAR_PHY) += rcar-phy.o | 13 | obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o |
14 | obj-$(CONFIG_SAMSUNG_USBPHY) += samsung-usbphy.o | 14 | obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301.omap.o |
15 | obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o | ||
16 | obj-$(CONFIG_NOP_USB_XCEIV) += phy-nop.o | ||
17 | obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o | ||
18 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o | ||
19 | obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o | ||
20 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o | ||
21 | obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o | ||
22 | obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o | ||
23 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o | ||
24 | obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o | ||
25 | obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o | ||
26 | obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o | ||
27 | obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o | ||
28 | obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o | ||
29 | obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o | ||
30 | obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o | ||
31 | obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o | ||
32 | obj-$(CONFIG_USB_ULPI) += phy-ulpi.o | ||
33 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o | ||
diff --git a/drivers/usb/phy/isp1301.c b/drivers/usb/phy/isp1301.c deleted file mode 100644 index 18dbf7e37607..000000000000 --- a/drivers/usb/phy/isp1301.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* | ||
2 | * NXP ISP1301 USB transceiver driver | ||
3 | * | ||
4 | * Copyright (C) 2012 Roland Stigge | ||
5 | * | ||
6 | * Author: Roland Stigge <stigge@antcom.de> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/i2c.h> | ||
15 | |||
16 | #define DRV_NAME "isp1301" | ||
17 | |||
18 | static const struct i2c_device_id isp1301_id[] = { | ||
19 | { "isp1301", 0 }, | ||
20 | { } | ||
21 | }; | ||
22 | |||
23 | static struct i2c_client *isp1301_i2c_client; | ||
24 | |||
25 | static int isp1301_probe(struct i2c_client *client, | ||
26 | const struct i2c_device_id *i2c_id) | ||
27 | { | ||
28 | isp1301_i2c_client = client; | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | static int isp1301_remove(struct i2c_client *client) | ||
33 | { | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | static struct i2c_driver isp1301_driver = { | ||
38 | .driver = { | ||
39 | .name = DRV_NAME, | ||
40 | }, | ||
41 | .probe = isp1301_probe, | ||
42 | .remove = isp1301_remove, | ||
43 | .id_table = isp1301_id, | ||
44 | }; | ||
45 | |||
46 | module_i2c_driver(isp1301_driver); | ||
47 | |||
48 | static int match(struct device *dev, void *data) | ||
49 | { | ||
50 | struct device_node *node = (struct device_node *)data; | ||
51 | return (dev->of_node == node) && | ||
52 | (dev->driver == &isp1301_driver.driver); | ||
53 | } | ||
54 | |||
55 | struct i2c_client *isp1301_get_client(struct device_node *node) | ||
56 | { | ||
57 | if (node) { /* reference of ISP1301 I2C node via DT */ | ||
58 | struct device *dev = bus_find_device(&i2c_bus_type, NULL, | ||
59 | node, match); | ||
60 | if (!dev) | ||
61 | return NULL; | ||
62 | return to_i2c_client(dev); | ||
63 | } else { /* non-DT: only one ISP1301 chip supported */ | ||
64 | return isp1301_i2c_client; | ||
65 | } | ||
66 | } | ||
67 | EXPORT_SYMBOL_GPL(isp1301_get_client); | ||
68 | |||
69 | MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); | ||
70 | MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver"); | ||
71 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c new file mode 100644 index 000000000000..4acef26a2ef5 --- /dev/null +++ b/drivers/usb/phy/phy-ab8500-usb.c | |||
@@ -0,0 +1,924 @@ | |||
1 | /* | ||
2 | * drivers/usb/otg/ab8500_usb.c | ||
3 | * | ||
4 | * USB transceiver driver for AB8500 chip | ||
5 | * | ||
6 | * Copyright (C) 2010 ST-Ericsson AB | ||
7 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/module.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/usb/otg.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/notifier.h> | ||
30 | #include <linux/interrupt.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/mfd/abx500.h> | ||
33 | #include <linux/mfd/abx500/ab8500.h> | ||
34 | #include <linux/usb/musb-ux500.h> | ||
35 | #include <linux/regulator/consumer.h> | ||
36 | #include <linux/pinctrl/consumer.h> | ||
37 | |||
38 | /* Bank AB8500_SYS_CTRL2_BLOCK */ | ||
39 | #define AB8500_MAIN_WD_CTRL_REG 0x01 | ||
40 | |||
41 | /* Bank AB8500_USB */ | ||
42 | #define AB8500_USB_LINE_STAT_REG 0x80 | ||
43 | #define AB8505_USB_LINE_STAT_REG 0x94 | ||
44 | #define AB8500_USB_PHY_CTRL_REG 0x8A | ||
45 | |||
46 | /* Bank AB8500_DEVELOPMENT */ | ||
47 | #define AB8500_BANK12_ACCESS 0x00 | ||
48 | |||
49 | /* Bank AB8500_DEBUG */ | ||
50 | #define AB8500_USB_PHY_TUNE1 0x05 | ||
51 | #define AB8500_USB_PHY_TUNE2 0x06 | ||
52 | #define AB8500_USB_PHY_TUNE3 0x07 | ||
53 | |||
54 | #define AB8500_BIT_OTG_STAT_ID (1 << 0) | ||
55 | #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0) | ||
56 | #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1) | ||
57 | #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0) | ||
58 | #define AB8500_BIT_WD_CTRL_KICK (1 << 1) | ||
59 | |||
60 | #define AB8500_WD_KICK_DELAY_US 100 /* usec */ | ||
61 | #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */ | ||
62 | #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */ | ||
63 | |||
64 | /* Usb line status register */ | ||
65 | enum ab8500_usb_link_status { | ||
66 | USB_LINK_NOT_CONFIGURED_8500 = 0, | ||
67 | USB_LINK_STD_HOST_NC_8500, | ||
68 | USB_LINK_STD_HOST_C_NS_8500, | ||
69 | USB_LINK_STD_HOST_C_S_8500, | ||
70 | USB_LINK_HOST_CHG_NM_8500, | ||
71 | USB_LINK_HOST_CHG_HS_8500, | ||
72 | USB_LINK_HOST_CHG_HS_CHIRP_8500, | ||
73 | USB_LINK_DEDICATED_CHG_8500, | ||
74 | USB_LINK_ACA_RID_A_8500, | ||
75 | USB_LINK_ACA_RID_B_8500, | ||
76 | USB_LINK_ACA_RID_C_NM_8500, | ||
77 | USB_LINK_ACA_RID_C_HS_8500, | ||
78 | USB_LINK_ACA_RID_C_HS_CHIRP_8500, | ||
79 | USB_LINK_HM_IDGND_8500, | ||
80 | USB_LINK_RESERVED_8500, | ||
81 | USB_LINK_NOT_VALID_LINK_8500, | ||
82 | }; | ||
83 | |||
84 | enum ab8505_usb_link_status { | ||
85 | USB_LINK_NOT_CONFIGURED_8505 = 0, | ||
86 | USB_LINK_STD_HOST_NC_8505, | ||
87 | USB_LINK_STD_HOST_C_NS_8505, | ||
88 | USB_LINK_STD_HOST_C_S_8505, | ||
89 | USB_LINK_CDP_8505, | ||
90 | USB_LINK_RESERVED0_8505, | ||
91 | USB_LINK_RESERVED1_8505, | ||
92 | USB_LINK_DEDICATED_CHG_8505, | ||
93 | USB_LINK_ACA_RID_A_8505, | ||
94 | USB_LINK_ACA_RID_B_8505, | ||
95 | USB_LINK_ACA_RID_C_NM_8505, | ||
96 | USB_LINK_RESERVED2_8505, | ||
97 | USB_LINK_RESERVED3_8505, | ||
98 | USB_LINK_HM_IDGND_8505, | ||
99 | USB_LINK_CHARGERPORT_NOT_OK_8505, | ||
100 | USB_LINK_CHARGER_DM_HIGH_8505, | ||
101 | USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505, | ||
102 | USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505, | ||
103 | USB_LINK_STD_UPSTREAM_8505, | ||
104 | USB_LINK_CHARGER_SE1_8505, | ||
105 | USB_LINK_CARKIT_CHGR_1_8505, | ||
106 | USB_LINK_CARKIT_CHGR_2_8505, | ||
107 | USB_LINK_ACA_DOCK_CHGR_8505, | ||
108 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505, | ||
109 | USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505, | ||
110 | USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505, | ||
111 | USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505, | ||
112 | USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505, | ||
113 | }; | ||
114 | |||
115 | enum ab8500_usb_mode { | ||
116 | USB_IDLE = 0, | ||
117 | USB_PERIPHERAL, | ||
118 | USB_HOST, | ||
119 | USB_DEDICATED_CHG | ||
120 | }; | ||
121 | |||
122 | struct ab8500_usb { | ||
123 | struct usb_phy phy; | ||
124 | struct device *dev; | ||
125 | struct ab8500 *ab8500; | ||
126 | unsigned vbus_draw; | ||
127 | struct work_struct phy_dis_work; | ||
128 | enum ab8500_usb_mode mode; | ||
129 | struct regulator *v_ape; | ||
130 | struct regulator *v_musb; | ||
131 | struct regulator *v_ulpi; | ||
132 | int saved_v_ulpi; | ||
133 | int previous_link_status_state; | ||
134 | struct pinctrl *pinctrl; | ||
135 | struct pinctrl_state *pins_sleep; | ||
136 | }; | ||
137 | |||
138 | static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x) | ||
139 | { | ||
140 | return container_of(x, struct ab8500_usb, phy); | ||
141 | } | ||
142 | |||
143 | static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) | ||
144 | { | ||
145 | abx500_set_register_interruptible(ab->dev, | ||
146 | AB8500_SYS_CTRL2_BLOCK, | ||
147 | AB8500_MAIN_WD_CTRL_REG, | ||
148 | AB8500_BIT_WD_CTRL_ENABLE); | ||
149 | |||
150 | udelay(AB8500_WD_KICK_DELAY_US); | ||
151 | |||
152 | abx500_set_register_interruptible(ab->dev, | ||
153 | AB8500_SYS_CTRL2_BLOCK, | ||
154 | AB8500_MAIN_WD_CTRL_REG, | ||
155 | (AB8500_BIT_WD_CTRL_ENABLE | ||
156 | | AB8500_BIT_WD_CTRL_KICK)); | ||
157 | |||
158 | udelay(AB8500_WD_V11_DISABLE_DELAY_US); | ||
159 | |||
160 | abx500_set_register_interruptible(ab->dev, | ||
161 | AB8500_SYS_CTRL2_BLOCK, | ||
162 | AB8500_MAIN_WD_CTRL_REG, | ||
163 | 0); | ||
164 | } | ||
165 | |||
166 | static void ab8500_usb_regulator_enable(struct ab8500_usb *ab) | ||
167 | { | ||
168 | int ret, volt; | ||
169 | |||
170 | ret = regulator_enable(ab->v_ape); | ||
171 | if (ret) | ||
172 | dev_err(ab->dev, "Failed to enable v-ape\n"); | ||
173 | |||
174 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { | ||
175 | ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi); | ||
176 | if (ab->saved_v_ulpi < 0) | ||
177 | dev_err(ab->dev, "Failed to get v_ulpi voltage\n"); | ||
178 | |||
179 | ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000); | ||
180 | if (ret < 0) | ||
181 | dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n", | ||
182 | ret); | ||
183 | |||
184 | ret = regulator_set_optimum_mode(ab->v_ulpi, 28000); | ||
185 | if (ret < 0) | ||
186 | dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", | ||
187 | ret); | ||
188 | } | ||
189 | |||
190 | ret = regulator_enable(ab->v_ulpi); | ||
191 | if (ret) | ||
192 | dev_err(ab->dev, "Failed to enable vddulpivio18\n"); | ||
193 | |||
194 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { | ||
195 | volt = regulator_get_voltage(ab->v_ulpi); | ||
196 | if ((volt != 1300000) && (volt != 1350000)) | ||
197 | dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n", | ||
198 | volt); | ||
199 | } | ||
200 | |||
201 | ret = regulator_enable(ab->v_musb); | ||
202 | if (ret) | ||
203 | dev_err(ab->dev, "Failed to enable musb_1v8\n"); | ||
204 | } | ||
205 | |||
206 | static void ab8500_usb_regulator_disable(struct ab8500_usb *ab) | ||
207 | { | ||
208 | int ret; | ||
209 | |||
210 | regulator_disable(ab->v_musb); | ||
211 | |||
212 | regulator_disable(ab->v_ulpi); | ||
213 | |||
214 | /* USB is not the only consumer of Vintcore, restore old settings */ | ||
215 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { | ||
216 | if (ab->saved_v_ulpi > 0) { | ||
217 | ret = regulator_set_voltage(ab->v_ulpi, | ||
218 | ab->saved_v_ulpi, ab->saved_v_ulpi); | ||
219 | if (ret < 0) | ||
220 | dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n", | ||
221 | ab->saved_v_ulpi, ret); | ||
222 | } | ||
223 | |||
224 | ret = regulator_set_optimum_mode(ab->v_ulpi, 0); | ||
225 | if (ret < 0) | ||
226 | dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", | ||
227 | ret); | ||
228 | } | ||
229 | |||
230 | regulator_disable(ab->v_ape); | ||
231 | } | ||
232 | |||
233 | static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit) | ||
234 | { | ||
235 | /* Workaround for v2.0 bug # 31952 */ | ||
236 | if (is_ab8500_2p0(ab->ab8500)) { | ||
237 | abx500_mask_and_set_register_interruptible(ab->dev, | ||
238 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, | ||
239 | bit, bit); | ||
240 | udelay(AB8500_V20_31952_DISABLE_DELAY_US); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host) | ||
245 | { | ||
246 | u8 bit; | ||
247 | bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : | ||
248 | AB8500_BIT_PHY_CTRL_DEVICE_EN; | ||
249 | |||
250 | /* mux and configure USB pins to DEFAULT state */ | ||
251 | ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT); | ||
252 | if (IS_ERR(ab->pinctrl)) | ||
253 | dev_err(ab->dev, "could not get/set default pinstate\n"); | ||
254 | |||
255 | ab8500_usb_regulator_enable(ab); | ||
256 | |||
257 | abx500_mask_and_set_register_interruptible(ab->dev, | ||
258 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, | ||
259 | bit, bit); | ||
260 | } | ||
261 | |||
262 | static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host) | ||
263 | { | ||
264 | u8 bit; | ||
265 | bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : | ||
266 | AB8500_BIT_PHY_CTRL_DEVICE_EN; | ||
267 | |||
268 | ab8500_usb_wd_linkstatus(ab, bit); | ||
269 | |||
270 | abx500_mask_and_set_register_interruptible(ab->dev, | ||
271 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, | ||
272 | bit, 0); | ||
273 | |||
274 | /* Needed to disable the phy.*/ | ||
275 | ab8500_usb_wd_workaround(ab); | ||
276 | |||
277 | ab8500_usb_regulator_disable(ab); | ||
278 | |||
279 | if (!IS_ERR(ab->pinctrl)) { | ||
280 | /* configure USB pins to SLEEP state */ | ||
281 | ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl, | ||
282 | PINCTRL_STATE_SLEEP); | ||
283 | |||
284 | if (IS_ERR(ab->pins_sleep)) | ||
285 | dev_dbg(ab->dev, "could not get sleep pinstate\n"); | ||
286 | else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep)) | ||
287 | dev_err(ab->dev, "could not set pins to sleep state\n"); | ||
288 | |||
289 | /* as USB pins are shared with idddet, release them to allow | ||
290 | * iddet to request them | ||
291 | */ | ||
292 | pinctrl_put(ab->pinctrl); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true) | ||
297 | #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true) | ||
298 | #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false) | ||
299 | #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false) | ||
300 | |||
301 | static int ab8505_usb_link_status_update(struct ab8500_usb *ab, | ||
302 | enum ab8505_usb_link_status lsts) | ||
303 | { | ||
304 | enum ux500_musb_vbus_id_status event = 0; | ||
305 | |||
306 | dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts); | ||
307 | |||
308 | /* | ||
309 | * Spurious link_status interrupts are seen at the time of | ||
310 | * disconnection of a device in RIDA state | ||
311 | */ | ||
312 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 && | ||
313 | (lsts == USB_LINK_STD_HOST_NC_8505)) | ||
314 | return 0; | ||
315 | |||
316 | ab->previous_link_status_state = lsts; | ||
317 | |||
318 | switch (lsts) { | ||
319 | case USB_LINK_ACA_RID_B_8505: | ||
320 | event = UX500_MUSB_RIDB; | ||
321 | case USB_LINK_NOT_CONFIGURED_8505: | ||
322 | case USB_LINK_RESERVED0_8505: | ||
323 | case USB_LINK_RESERVED1_8505: | ||
324 | case USB_LINK_RESERVED2_8505: | ||
325 | case USB_LINK_RESERVED3_8505: | ||
326 | ab->mode = USB_IDLE; | ||
327 | ab->phy.otg->default_a = false; | ||
328 | ab->vbus_draw = 0; | ||
329 | if (event != UX500_MUSB_RIDB) | ||
330 | event = UX500_MUSB_NONE; | ||
331 | /* | ||
332 | * Fallback to default B_IDLE as nothing | ||
333 | * is connected | ||
334 | */ | ||
335 | ab->phy.state = OTG_STATE_B_IDLE; | ||
336 | break; | ||
337 | |||
338 | case USB_LINK_ACA_RID_C_NM_8505: | ||
339 | event = UX500_MUSB_RIDC; | ||
340 | case USB_LINK_STD_HOST_NC_8505: | ||
341 | case USB_LINK_STD_HOST_C_NS_8505: | ||
342 | case USB_LINK_STD_HOST_C_S_8505: | ||
343 | case USB_LINK_CDP_8505: | ||
344 | if (ab->mode == USB_IDLE) { | ||
345 | ab->mode = USB_PERIPHERAL; | ||
346 | ab8500_usb_peri_phy_en(ab); | ||
347 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
348 | UX500_MUSB_PREPARE, &ab->vbus_draw); | ||
349 | } | ||
350 | if (event != UX500_MUSB_RIDC) | ||
351 | event = UX500_MUSB_VBUS; | ||
352 | break; | ||
353 | |||
354 | case USB_LINK_ACA_RID_A_8505: | ||
355 | case USB_LINK_ACA_DOCK_CHGR_8505: | ||
356 | event = UX500_MUSB_RIDA; | ||
357 | case USB_LINK_HM_IDGND_8505: | ||
358 | if (ab->mode == USB_IDLE) { | ||
359 | ab->mode = USB_HOST; | ||
360 | ab8500_usb_host_phy_en(ab); | ||
361 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
362 | UX500_MUSB_PREPARE, &ab->vbus_draw); | ||
363 | } | ||
364 | ab->phy.otg->default_a = true; | ||
365 | if (event != UX500_MUSB_RIDA) | ||
366 | event = UX500_MUSB_ID; | ||
367 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
368 | event, &ab->vbus_draw); | ||
369 | break; | ||
370 | |||
371 | case USB_LINK_DEDICATED_CHG_8505: | ||
372 | ab->mode = USB_DEDICATED_CHG; | ||
373 | event = UX500_MUSB_CHARGER; | ||
374 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
375 | event, &ab->vbus_draw); | ||
376 | break; | ||
377 | |||
378 | default: | ||
379 | break; | ||
380 | } | ||
381 | |||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | static int ab8500_usb_link_status_update(struct ab8500_usb *ab, | ||
386 | enum ab8500_usb_link_status lsts) | ||
387 | { | ||
388 | enum ux500_musb_vbus_id_status event = 0; | ||
389 | |||
390 | dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts); | ||
391 | |||
392 | /* | ||
393 | * Spurious link_status interrupts are seen in case of a | ||
394 | * disconnection of a device in IDGND and RIDA stage | ||
395 | */ | ||
396 | if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 && | ||
397 | (lsts == USB_LINK_STD_HOST_C_NS_8500 || | ||
398 | lsts == USB_LINK_STD_HOST_NC_8500)) | ||
399 | return 0; | ||
400 | |||
401 | if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 && | ||
402 | lsts == USB_LINK_STD_HOST_NC_8500) | ||
403 | return 0; | ||
404 | |||
405 | ab->previous_link_status_state = lsts; | ||
406 | |||
407 | switch (lsts) { | ||
408 | case USB_LINK_ACA_RID_B_8500: | ||
409 | event = UX500_MUSB_RIDB; | ||
410 | case USB_LINK_NOT_CONFIGURED_8500: | ||
411 | case USB_LINK_NOT_VALID_LINK_8500: | ||
412 | ab->mode = USB_IDLE; | ||
413 | ab->phy.otg->default_a = false; | ||
414 | ab->vbus_draw = 0; | ||
415 | if (event != UX500_MUSB_RIDB) | ||
416 | event = UX500_MUSB_NONE; | ||
417 | /* Fallback to default B_IDLE as nothing is connected */ | ||
418 | ab->phy.state = OTG_STATE_B_IDLE; | ||
419 | break; | ||
420 | |||
421 | case USB_LINK_ACA_RID_C_NM_8500: | ||
422 | case USB_LINK_ACA_RID_C_HS_8500: | ||
423 | case USB_LINK_ACA_RID_C_HS_CHIRP_8500: | ||
424 | event = UX500_MUSB_RIDC; | ||
425 | case USB_LINK_STD_HOST_NC_8500: | ||
426 | case USB_LINK_STD_HOST_C_NS_8500: | ||
427 | case USB_LINK_STD_HOST_C_S_8500: | ||
428 | case USB_LINK_HOST_CHG_NM_8500: | ||
429 | case USB_LINK_HOST_CHG_HS_8500: | ||
430 | case USB_LINK_HOST_CHG_HS_CHIRP_8500: | ||
431 | if (ab->mode == USB_IDLE) { | ||
432 | ab->mode = USB_PERIPHERAL; | ||
433 | ab8500_usb_peri_phy_en(ab); | ||
434 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
435 | UX500_MUSB_PREPARE, &ab->vbus_draw); | ||
436 | } | ||
437 | if (event != UX500_MUSB_RIDC) | ||
438 | event = UX500_MUSB_VBUS; | ||
439 | break; | ||
440 | |||
441 | case USB_LINK_ACA_RID_A_8500: | ||
442 | event = UX500_MUSB_RIDA; | ||
443 | case USB_LINK_HM_IDGND_8500: | ||
444 | if (ab->mode == USB_IDLE) { | ||
445 | ab->mode = USB_HOST; | ||
446 | ab8500_usb_host_phy_en(ab); | ||
447 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
448 | UX500_MUSB_PREPARE, &ab->vbus_draw); | ||
449 | } | ||
450 | ab->phy.otg->default_a = true; | ||
451 | if (event != UX500_MUSB_RIDA) | ||
452 | event = UX500_MUSB_ID; | ||
453 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
454 | event, &ab->vbus_draw); | ||
455 | break; | ||
456 | |||
457 | case USB_LINK_DEDICATED_CHG_8500: | ||
458 | ab->mode = USB_DEDICATED_CHG; | ||
459 | event = UX500_MUSB_CHARGER; | ||
460 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
461 | event, &ab->vbus_draw); | ||
462 | break; | ||
463 | |||
464 | case USB_LINK_RESERVED_8500: | ||
465 | break; | ||
466 | } | ||
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | /* | ||
472 | * Connection Sequence: | ||
473 | * 1. Link Status Interrupt | ||
474 | * 2. Enable AB clock | ||
475 | * 3. Enable AB regulators | ||
476 | * 4. Enable USB phy | ||
477 | * 5. Reset the musb controller | ||
478 | * 6. Switch the ULPI GPIO pins to fucntion mode | ||
479 | * 7. Enable the musb Peripheral5 clock | ||
480 | * 8. Restore MUSB context | ||
481 | */ | ||
482 | static int abx500_usb_link_status_update(struct ab8500_usb *ab) | ||
483 | { | ||
484 | u8 reg; | ||
485 | int ret = 0; | ||
486 | |||
487 | if (is_ab8500(ab->ab8500)) { | ||
488 | enum ab8500_usb_link_status lsts; | ||
489 | |||
490 | abx500_get_register_interruptible(ab->dev, | ||
491 | AB8500_USB, AB8500_USB_LINE_STAT_REG, ®); | ||
492 | lsts = (reg >> 3) & 0x0F; | ||
493 | ret = ab8500_usb_link_status_update(ab, lsts); | ||
494 | } else if (is_ab8505(ab->ab8500)) { | ||
495 | enum ab8505_usb_link_status lsts; | ||
496 | |||
497 | abx500_get_register_interruptible(ab->dev, | ||
498 | AB8500_USB, AB8505_USB_LINE_STAT_REG, ®); | ||
499 | lsts = (reg >> 3) & 0x1F; | ||
500 | ret = ab8505_usb_link_status_update(ab, lsts); | ||
501 | } | ||
502 | |||
503 | return ret; | ||
504 | } | ||
505 | |||
506 | /* | ||
507 | * Disconnection Sequence: | ||
508 | * 1. Disconect Interrupt | ||
509 | * 2. Disable regulators | ||
510 | * 3. Disable AB clock | ||
511 | * 4. Disable the Phy | ||
512 | * 5. Link Status Interrupt | ||
513 | * 6. Disable Musb Clock | ||
514 | */ | ||
515 | static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data) | ||
516 | { | ||
517 | struct ab8500_usb *ab = (struct ab8500_usb *) data; | ||
518 | enum usb_phy_events event = UX500_MUSB_NONE; | ||
519 | |||
520 | /* Link status will not be updated till phy is disabled. */ | ||
521 | if (ab->mode == USB_HOST) { | ||
522 | ab->phy.otg->default_a = false; | ||
523 | ab->vbus_draw = 0; | ||
524 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
525 | event, &ab->vbus_draw); | ||
526 | ab8500_usb_host_phy_dis(ab); | ||
527 | ab->mode = USB_IDLE; | ||
528 | } | ||
529 | |||
530 | if (ab->mode == USB_PERIPHERAL) { | ||
531 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
532 | event, &ab->vbus_draw); | ||
533 | ab8500_usb_peri_phy_dis(ab); | ||
534 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
535 | UX500_MUSB_CLEAN, &ab->vbus_draw); | ||
536 | ab->mode = USB_IDLE; | ||
537 | ab->phy.otg->default_a = false; | ||
538 | ab->vbus_draw = 0; | ||
539 | } | ||
540 | |||
541 | if (is_ab8500_2p0(ab->ab8500)) { | ||
542 | if (ab->mode == USB_DEDICATED_CHG) { | ||
543 | ab8500_usb_wd_linkstatus(ab, | ||
544 | AB8500_BIT_PHY_CTRL_DEVICE_EN); | ||
545 | abx500_mask_and_set_register_interruptible(ab->dev, | ||
546 | AB8500_USB, AB8500_USB_PHY_CTRL_REG, | ||
547 | AB8500_BIT_PHY_CTRL_DEVICE_EN, 0); | ||
548 | } | ||
549 | } | ||
550 | |||
551 | return IRQ_HANDLED; | ||
552 | } | ||
553 | |||
554 | static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data) | ||
555 | { | ||
556 | struct ab8500_usb *ab = (struct ab8500_usb *) data; | ||
557 | |||
558 | abx500_usb_link_status_update(ab); | ||
559 | |||
560 | return IRQ_HANDLED; | ||
561 | } | ||
562 | |||
563 | static void ab8500_usb_phy_disable_work(struct work_struct *work) | ||
564 | { | ||
565 | struct ab8500_usb *ab = container_of(work, struct ab8500_usb, | ||
566 | phy_dis_work); | ||
567 | |||
568 | if (!ab->phy.otg->host) | ||
569 | ab8500_usb_host_phy_dis(ab); | ||
570 | |||
571 | if (!ab->phy.otg->gadget) | ||
572 | ab8500_usb_peri_phy_dis(ab); | ||
573 | } | ||
574 | |||
575 | static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA) | ||
576 | { | ||
577 | /* | ||
578 | * AB8500 V2 has eye diagram issues when drawing more than 100mA from | ||
579 | * VBUS. Set charging current to 100mA in case of standard host | ||
580 | */ | ||
581 | if (is_ab8500_2p0_or_earlier(ab->ab8500)) | ||
582 | if (mA > 100) | ||
583 | mA = 100; | ||
584 | |||
585 | return mA; | ||
586 | } | ||
587 | |||
588 | static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA) | ||
589 | { | ||
590 | struct ab8500_usb *ab; | ||
591 | |||
592 | if (!phy) | ||
593 | return -ENODEV; | ||
594 | |||
595 | ab = phy_to_ab(phy); | ||
596 | |||
597 | mA = ab8500_eyediagram_workaroud(ab, mA); | ||
598 | |||
599 | ab->vbus_draw = mA; | ||
600 | |||
601 | atomic_notifier_call_chain(&ab->phy.notifier, | ||
602 | UX500_MUSB_VBUS, &ab->vbus_draw); | ||
603 | |||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend) | ||
608 | { | ||
609 | /* TODO */ | ||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | static int ab8500_usb_set_peripheral(struct usb_otg *otg, | ||
614 | struct usb_gadget *gadget) | ||
615 | { | ||
616 | struct ab8500_usb *ab; | ||
617 | |||
618 | if (!otg) | ||
619 | return -ENODEV; | ||
620 | |||
621 | ab = phy_to_ab(otg->phy); | ||
622 | |||
623 | ab->phy.otg->gadget = gadget; | ||
624 | |||
625 | /* Some drivers call this function in atomic context. | ||
626 | * Do not update ab8500 registers directly till this | ||
627 | * is fixed. | ||
628 | */ | ||
629 | |||
630 | if ((ab->mode != USB_IDLE) && (!gadget)) { | ||
631 | ab->mode = USB_IDLE; | ||
632 | schedule_work(&ab->phy_dis_work); | ||
633 | } | ||
634 | |||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | ||
639 | { | ||
640 | struct ab8500_usb *ab; | ||
641 | |||
642 | if (!otg) | ||
643 | return -ENODEV; | ||
644 | |||
645 | ab = phy_to_ab(otg->phy); | ||
646 | |||
647 | ab->phy.otg->host = host; | ||
648 | |||
649 | /* Some drivers call this function in atomic context. | ||
650 | * Do not update ab8500 registers directly till this | ||
651 | * is fixed. | ||
652 | */ | ||
653 | |||
654 | if ((ab->mode != USB_IDLE) && (!host)) { | ||
655 | ab->mode = USB_IDLE; | ||
656 | schedule_work(&ab->phy_dis_work); | ||
657 | } | ||
658 | |||
659 | return 0; | ||
660 | } | ||
661 | |||
662 | static int ab8500_usb_regulator_get(struct ab8500_usb *ab) | ||
663 | { | ||
664 | int err; | ||
665 | |||
666 | ab->v_ape = devm_regulator_get(ab->dev, "v-ape"); | ||
667 | if (IS_ERR(ab->v_ape)) { | ||
668 | dev_err(ab->dev, "Could not get v-ape supply\n"); | ||
669 | err = PTR_ERR(ab->v_ape); | ||
670 | return err; | ||
671 | } | ||
672 | |||
673 | ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18"); | ||
674 | if (IS_ERR(ab->v_ulpi)) { | ||
675 | dev_err(ab->dev, "Could not get vddulpivio18 supply\n"); | ||
676 | err = PTR_ERR(ab->v_ulpi); | ||
677 | return err; | ||
678 | } | ||
679 | |||
680 | ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8"); | ||
681 | if (IS_ERR(ab->v_musb)) { | ||
682 | dev_err(ab->dev, "Could not get musb_1v8 supply\n"); | ||
683 | err = PTR_ERR(ab->v_musb); | ||
684 | return err; | ||
685 | } | ||
686 | |||
687 | return 0; | ||
688 | } | ||
689 | |||
690 | static int ab8500_usb_irq_setup(struct platform_device *pdev, | ||
691 | struct ab8500_usb *ab) | ||
692 | { | ||
693 | int err; | ||
694 | int irq; | ||
695 | |||
696 | irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS"); | ||
697 | if (irq < 0) { | ||
698 | dev_err(&pdev->dev, "Link status irq not found\n"); | ||
699 | return irq; | ||
700 | } | ||
701 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, | ||
702 | ab8500_usb_link_status_irq, | ||
703 | IRQF_NO_SUSPEND | IRQF_SHARED, "usb-link-status", ab); | ||
704 | if (err < 0) { | ||
705 | dev_err(ab->dev, "request_irq failed for link status irq\n"); | ||
706 | return err; | ||
707 | } | ||
708 | |||
709 | irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); | ||
710 | if (irq < 0) { | ||
711 | dev_err(&pdev->dev, "ID fall irq not found\n"); | ||
712 | return irq; | ||
713 | } | ||
714 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, | ||
715 | ab8500_usb_disconnect_irq, | ||
716 | IRQF_NO_SUSPEND | IRQF_SHARED, "usb-id-fall", ab); | ||
717 | if (err < 0) { | ||
718 | dev_err(ab->dev, "request_irq failed for ID fall irq\n"); | ||
719 | return err; | ||
720 | } | ||
721 | |||
722 | irq = platform_get_irq_byname(pdev, "VBUS_DET_F"); | ||
723 | if (irq < 0) { | ||
724 | dev_err(&pdev->dev, "VBUS fall irq not found\n"); | ||
725 | return irq; | ||
726 | } | ||
727 | err = devm_request_threaded_irq(&pdev->dev, irq, NULL, | ||
728 | ab8500_usb_disconnect_irq, | ||
729 | IRQF_NO_SUSPEND | IRQF_SHARED, "usb-vbus-fall", ab); | ||
730 | if (err < 0) { | ||
731 | dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); | ||
732 | return err; | ||
733 | } | ||
734 | |||
735 | return 0; | ||
736 | } | ||
737 | |||
738 | static int ab8500_usb_probe(struct platform_device *pdev) | ||
739 | { | ||
740 | struct ab8500_usb *ab; | ||
741 | struct ab8500 *ab8500; | ||
742 | struct usb_otg *otg; | ||
743 | int err; | ||
744 | int rev; | ||
745 | |||
746 | ab8500 = dev_get_drvdata(pdev->dev.parent); | ||
747 | rev = abx500_get_chip_id(&pdev->dev); | ||
748 | |||
749 | if (is_ab8500_1p1_or_earlier(ab8500)) { | ||
750 | dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev); | ||
751 | return -ENODEV; | ||
752 | } | ||
753 | |||
754 | ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL); | ||
755 | if (!ab) | ||
756 | return -ENOMEM; | ||
757 | |||
758 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); | ||
759 | if (!otg) | ||
760 | return -ENOMEM; | ||
761 | |||
762 | ab->dev = &pdev->dev; | ||
763 | ab->ab8500 = ab8500; | ||
764 | ab->phy.dev = ab->dev; | ||
765 | ab->phy.otg = otg; | ||
766 | ab->phy.label = "ab8500"; | ||
767 | ab->phy.set_suspend = ab8500_usb_set_suspend; | ||
768 | ab->phy.set_power = ab8500_usb_set_power; | ||
769 | ab->phy.state = OTG_STATE_UNDEFINED; | ||
770 | |||
771 | otg->phy = &ab->phy; | ||
772 | otg->set_host = ab8500_usb_set_host; | ||
773 | otg->set_peripheral = ab8500_usb_set_peripheral; | ||
774 | |||
775 | platform_set_drvdata(pdev, ab); | ||
776 | |||
777 | ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); | ||
778 | |||
779 | /* all: Disable phy when called from set_host and set_peripheral */ | ||
780 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); | ||
781 | |||
782 | err = ab8500_usb_regulator_get(ab); | ||
783 | if (err) | ||
784 | return err; | ||
785 | |||
786 | err = ab8500_usb_irq_setup(pdev, ab); | ||
787 | if (err < 0) | ||
788 | return err; | ||
789 | |||
790 | err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2); | ||
791 | if (err) { | ||
792 | dev_err(&pdev->dev, "Can't register transceiver\n"); | ||
793 | return err; | ||
794 | } | ||
795 | |||
796 | /* Phy tuning values for AB8500 */ | ||
797 | if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { | ||
798 | /* Enable the PBT/Bank 0x12 access */ | ||
799 | err = abx500_set_register_interruptible(ab->dev, | ||
800 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); | ||
801 | if (err < 0) | ||
802 | dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", | ||
803 | err); | ||
804 | |||
805 | err = abx500_set_register_interruptible(ab->dev, | ||
806 | AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8); | ||
807 | if (err < 0) | ||
808 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", | ||
809 | err); | ||
810 | |||
811 | err = abx500_set_register_interruptible(ab->dev, | ||
812 | AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00); | ||
813 | if (err < 0) | ||
814 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", | ||
815 | err); | ||
816 | |||
817 | err = abx500_set_register_interruptible(ab->dev, | ||
818 | AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78); | ||
819 | if (err < 0) | ||
820 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", | ||
821 | err); | ||
822 | |||
823 | /* Switch to normal mode/disable Bank 0x12 access */ | ||
824 | err = abx500_set_register_interruptible(ab->dev, | ||
825 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00); | ||
826 | if (err < 0) | ||
827 | dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", | ||
828 | err); | ||
829 | } | ||
830 | |||
831 | /* Phy tuning values for AB8505 */ | ||
832 | if (is_ab8505(ab->ab8500)) { | ||
833 | /* Enable the PBT/Bank 0x12 access */ | ||
834 | err = abx500_mask_and_set_register_interruptible(ab->dev, | ||
835 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, | ||
836 | 0x01, 0x01); | ||
837 | if (err < 0) | ||
838 | dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", | ||
839 | err); | ||
840 | |||
841 | err = abx500_mask_and_set_register_interruptible(ab->dev, | ||
842 | AB8500_DEBUG, AB8500_USB_PHY_TUNE1, | ||
843 | 0xC8, 0xC8); | ||
844 | if (err < 0) | ||
845 | dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", | ||
846 | err); | ||
847 | |||
848 | err = abx500_mask_and_set_register_interruptible(ab->dev, | ||
849 | AB8500_DEBUG, AB8500_USB_PHY_TUNE2, | ||
850 | 0x60, 0x60); | ||
851 | if (err < 0) | ||
852 | dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", | ||
853 | err); | ||
854 | |||
855 | err = abx500_mask_and_set_register_interruptible(ab->dev, | ||
856 | AB8500_DEBUG, AB8500_USB_PHY_TUNE3, | ||
857 | 0xFC, 0x80); | ||
858 | |||
859 | if (err < 0) | ||
860 | dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", | ||
861 | err); | ||
862 | |||
863 | /* Switch to normal mode/disable Bank 0x12 access */ | ||
864 | err = abx500_mask_and_set_register_interruptible(ab->dev, | ||
865 | AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, | ||
866 | 0x00, 0x00); | ||
867 | if (err < 0) | ||
868 | dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", | ||
869 | err); | ||
870 | } | ||
871 | |||
872 | /* Needed to enable ID detection. */ | ||
873 | ab8500_usb_wd_workaround(ab); | ||
874 | |||
875 | abx500_usb_link_status_update(ab); | ||
876 | |||
877 | dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev); | ||
878 | |||
879 | return 0; | ||
880 | } | ||
881 | |||
882 | static int ab8500_usb_remove(struct platform_device *pdev) | ||
883 | { | ||
884 | struct ab8500_usb *ab = platform_get_drvdata(pdev); | ||
885 | |||
886 | cancel_work_sync(&ab->phy_dis_work); | ||
887 | |||
888 | usb_remove_phy(&ab->phy); | ||
889 | |||
890 | if (ab->mode == USB_HOST) | ||
891 | ab8500_usb_host_phy_dis(ab); | ||
892 | else if (ab->mode == USB_PERIPHERAL) | ||
893 | ab8500_usb_peri_phy_dis(ab); | ||
894 | |||
895 | platform_set_drvdata(pdev, NULL); | ||
896 | |||
897 | return 0; | ||
898 | } | ||
899 | |||
900 | static struct platform_driver ab8500_usb_driver = { | ||
901 | .probe = ab8500_usb_probe, | ||
902 | .remove = ab8500_usb_remove, | ||
903 | .driver = { | ||
904 | .name = "ab8500-usb", | ||
905 | .owner = THIS_MODULE, | ||
906 | }, | ||
907 | }; | ||
908 | |||
909 | static int __init ab8500_usb_init(void) | ||
910 | { | ||
911 | return platform_driver_register(&ab8500_usb_driver); | ||
912 | } | ||
913 | subsys_initcall(ab8500_usb_init); | ||
914 | |||
915 | static void __exit ab8500_usb_exit(void) | ||
916 | { | ||
917 | platform_driver_unregister(&ab8500_usb_driver); | ||
918 | } | ||
919 | module_exit(ab8500_usb_exit); | ||
920 | |||
921 | MODULE_ALIAS("platform:ab8500_usb"); | ||
922 | MODULE_AUTHOR("ST-Ericsson AB"); | ||
923 | MODULE_DESCRIPTION("AB8500 usb transceiver driver"); | ||
924 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/phy/phy-fsl-usb.c index d16adb41eb21..97b9308507c3 100644 --- a/drivers/usb/otg/fsl_otg.c +++ b/drivers/usb/phy/phy-fsl-usb.c | |||
@@ -43,7 +43,7 @@ | |||
43 | 43 | ||
44 | #include <asm/unaligned.h> | 44 | #include <asm/unaligned.h> |
45 | 45 | ||
46 | #include "fsl_otg.h" | 46 | #include "phy-fsl-usb.h" |
47 | 47 | ||
48 | #define DRIVER_VERSION "Rev. 1.55" | 48 | #define DRIVER_VERSION "Rev. 1.55" |
49 | #define DRIVER_AUTHOR "Jerry Huang/Li Yang" | 49 | #define DRIVER_AUTHOR "Jerry Huang/Li Yang" |
@@ -361,28 +361,18 @@ int fsl_otg_init_timers(struct otg_fsm *fsm) | |||
361 | void fsl_otg_uninit_timers(void) | 361 | void fsl_otg_uninit_timers(void) |
362 | { | 362 | { |
363 | /* FSM used timers */ | 363 | /* FSM used timers */ |
364 | if (a_wait_vrise_tmr != NULL) | 364 | kfree(a_wait_vrise_tmr); |
365 | kfree(a_wait_vrise_tmr); | 365 | kfree(a_wait_bcon_tmr); |
366 | if (a_wait_bcon_tmr != NULL) | 366 | kfree(a_aidl_bdis_tmr); |
367 | kfree(a_wait_bcon_tmr); | 367 | kfree(b_ase0_brst_tmr); |
368 | if (a_aidl_bdis_tmr != NULL) | 368 | kfree(b_se0_srp_tmr); |
369 | kfree(a_aidl_bdis_tmr); | 369 | kfree(b_srp_fail_tmr); |
370 | if (b_ase0_brst_tmr != NULL) | 370 | kfree(a_wait_enum_tmr); |
371 | kfree(b_ase0_brst_tmr); | ||
372 | if (b_se0_srp_tmr != NULL) | ||
373 | kfree(b_se0_srp_tmr); | ||
374 | if (b_srp_fail_tmr != NULL) | ||
375 | kfree(b_srp_fail_tmr); | ||
376 | if (a_wait_enum_tmr != NULL) | ||
377 | kfree(a_wait_enum_tmr); | ||
378 | 371 | ||
379 | /* device driver used timers */ | 372 | /* device driver used timers */ |
380 | if (b_srp_wait_tmr != NULL) | 373 | kfree(b_srp_wait_tmr); |
381 | kfree(b_srp_wait_tmr); | 374 | kfree(b_data_pulse_tmr); |
382 | if (b_data_pulse_tmr != NULL) | 375 | kfree(b_vbus_pulse_tmr); |
383 | kfree(b_data_pulse_tmr); | ||
384 | if (b_vbus_pulse_tmr != NULL) | ||
385 | kfree(b_vbus_pulse_tmr); | ||
386 | } | 376 | } |
387 | 377 | ||
388 | /* Add timer to timer list */ | 378 | /* Add timer to timer list */ |
@@ -1002,7 +992,7 @@ static int show_fsl_usb2_otg_state(struct device *dev, | |||
1002 | /* State */ | 992 | /* State */ |
1003 | t = scnprintf(next, size, | 993 | t = scnprintf(next, size, |
1004 | "OTG state: %s\n\n", | 994 | "OTG state: %s\n\n", |
1005 | otg_state_string(fsl_otg_dev->phy.state)); | 995 | usb_otg_state_string(fsl_otg_dev->phy.state)); |
1006 | size -= t; | 996 | size -= t; |
1007 | next += t; | 997 | next += t; |
1008 | 998 | ||
diff --git a/drivers/usb/otg/fsl_otg.h b/drivers/usb/phy/phy-fsl-usb.h index ca266280895d..ca266280895d 100644 --- a/drivers/usb/otg/fsl_otg.h +++ b/drivers/usb/phy/phy-fsl-usb.h | |||
diff --git a/drivers/usb/otg/otg_fsm.c b/drivers/usb/phy/phy-fsm-usb.c index ade131a8ae5e..c520b3548e7c 100644 --- a/drivers/usb/otg/otg_fsm.c +++ b/drivers/usb/phy/phy-fsm-usb.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include <linux/usb/gadget.h> | 29 | #include <linux/usb/gadget.h> |
30 | #include <linux/usb/otg.h> | 30 | #include <linux/usb/otg.h> |
31 | 31 | ||
32 | #include "otg_fsm.h" | 32 | #include "phy-otg-fsm.h" |
33 | 33 | ||
34 | /* Change USB protocol when there is a protocol change */ | 34 | /* Change USB protocol when there is a protocol change */ |
35 | static int otg_set_protocol(struct otg_fsm *fsm, int protocol) | 35 | static int otg_set_protocol(struct otg_fsm *fsm, int protocol) |
@@ -119,7 +119,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
119 | state_changed = 1; | 119 | state_changed = 1; |
120 | if (fsm->otg->phy->state == new_state) | 120 | if (fsm->otg->phy->state == new_state) |
121 | return 0; | 121 | return 0; |
122 | VDBG("Set state: %s\n", otg_state_string(new_state)); | 122 | VDBG("Set state: %s\n", usb_otg_state_string(new_state)); |
123 | otg_leave_state(fsm, fsm->otg->phy->state); | 123 | otg_leave_state(fsm, fsm->otg->phy->state); |
124 | switch (new_state) { | 124 | switch (new_state) { |
125 | case OTG_STATE_B_IDLE: | 125 | case OTG_STATE_B_IDLE: |
diff --git a/drivers/usb/otg/otg_fsm.h b/drivers/usb/phy/phy-fsm-usb.h index c30a2e1d9e46..c30a2e1d9e46 100644 --- a/drivers/usb/otg/otg_fsm.h +++ b/drivers/usb/phy/phy-fsm-usb.h | |||
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/phy/phy-gpio-vbus-usb.c index a7d4ac591982..4c76074e518d 100644 --- a/drivers/usb/otg/gpio_vbus.c +++ b/drivers/usb/phy/phy-gpio-vbus-usb.c | |||
@@ -61,6 +61,7 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA) | |||
61 | { | 61 | { |
62 | struct regulator *vbus_draw = gpio_vbus->vbus_draw; | 62 | struct regulator *vbus_draw = gpio_vbus->vbus_draw; |
63 | int enabled; | 63 | int enabled; |
64 | int ret; | ||
64 | 65 | ||
65 | if (!vbus_draw) | 66 | if (!vbus_draw) |
66 | return; | 67 | return; |
@@ -69,12 +70,16 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA) | |||
69 | if (mA) { | 70 | if (mA) { |
70 | regulator_set_current_limit(vbus_draw, 0, 1000 * mA); | 71 | regulator_set_current_limit(vbus_draw, 0, 1000 * mA); |
71 | if (!enabled) { | 72 | if (!enabled) { |
72 | regulator_enable(vbus_draw); | 73 | ret = regulator_enable(vbus_draw); |
74 | if (ret < 0) | ||
75 | return; | ||
73 | gpio_vbus->vbus_draw_enabled = 1; | 76 | gpio_vbus->vbus_draw_enabled = 1; |
74 | } | 77 | } |
75 | } else { | 78 | } else { |
76 | if (enabled) { | 79 | if (enabled) { |
77 | regulator_disable(vbus_draw); | 80 | ret = regulator_disable(vbus_draw); |
81 | if (ret < 0) | ||
82 | return; | ||
78 | gpio_vbus->vbus_draw_enabled = 0; | 83 | gpio_vbus->vbus_draw_enabled = 0; |
79 | } | 84 | } |
80 | } | 85 | } |
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/phy/phy-isp1301-omap.c index 8b9de9581319..ae481afcb3ec 100644 --- a/drivers/usb/otg/isp1301_omap.c +++ b/drivers/usb/phy/phy-isp1301-omap.c | |||
@@ -236,7 +236,7 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) | |||
236 | 236 | ||
237 | static inline const char *state_name(struct isp1301 *isp) | 237 | static inline const char *state_name(struct isp1301 *isp) |
238 | { | 238 | { |
239 | return otg_state_string(isp->phy.state); | 239 | return usb_otg_state_string(isp->phy.state); |
240 | } | 240 | } |
241 | 241 | ||
242 | /*-------------------------------------------------------------------------*/ | 242 | /*-------------------------------------------------------------------------*/ |
@@ -481,7 +481,7 @@ static void check_state(struct isp1301 *isp, const char *tag) | |||
481 | if (isp->phy.state == state && !extra) | 481 | if (isp->phy.state == state && !extra) |
482 | return; | 482 | return; |
483 | pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, | 483 | pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, |
484 | otg_state_string(state), fsm, state_name(isp), | 484 | usb_otg_state_string(state), fsm, state_name(isp), |
485 | omap_readl(OTG_CTRL)); | 485 | omap_readl(OTG_CTRL)); |
486 | } | 486 | } |
487 | 487 | ||
@@ -1077,7 +1077,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
1077 | 1077 | ||
1078 | if (state != isp->phy.state) | 1078 | if (state != isp->phy.state) |
1079 | pr_debug(" isp, %s -> %s\n", | 1079 | pr_debug(" isp, %s -> %s\n", |
1080 | otg_state_string(state), state_name(isp)); | 1080 | usb_otg_state_string(state), state_name(isp)); |
1081 | 1081 | ||
1082 | #ifdef CONFIG_USB_OTG | 1082 | #ifdef CONFIG_USB_OTG |
1083 | /* update the OTG controller state to match the isp1301; may | 1083 | /* update the OTG controller state to match the isp1301; may |
diff --git a/drivers/usb/phy/phy-isp1301.c b/drivers/usb/phy/phy-isp1301.c new file mode 100644 index 000000000000..225ae6c97eeb --- /dev/null +++ b/drivers/usb/phy/phy-isp1301.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * NXP ISP1301 USB transceiver driver | ||
3 | * | ||
4 | * Copyright (C) 2012 Roland Stigge | ||
5 | * | ||
6 | * Author: Roland Stigge <stigge@antcom.de> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/mutex.h> | ||
15 | #include <linux/i2c.h> | ||
16 | #include <linux/usb/phy.h> | ||
17 | #include <linux/usb/isp1301.h> | ||
18 | |||
19 | #define DRV_NAME "isp1301" | ||
20 | |||
21 | struct isp1301 { | ||
22 | struct usb_phy phy; | ||
23 | struct mutex mutex; | ||
24 | |||
25 | struct i2c_client *client; | ||
26 | }; | ||
27 | |||
28 | #define phy_to_isp(p) (container_of((p), struct isp1301, phy)) | ||
29 | |||
30 | static const struct i2c_device_id isp1301_id[] = { | ||
31 | { "isp1301", 0 }, | ||
32 | { } | ||
33 | }; | ||
34 | |||
35 | static struct i2c_client *isp1301_i2c_client; | ||
36 | |||
37 | static int __isp1301_write(struct isp1301 *isp, u8 reg, u8 value, u8 clear) | ||
38 | { | ||
39 | return i2c_smbus_write_byte_data(isp->client, reg | clear, value); | ||
40 | } | ||
41 | |||
42 | static int isp1301_write(struct isp1301 *isp, u8 reg, u8 value) | ||
43 | { | ||
44 | return __isp1301_write(isp, reg, value, 0); | ||
45 | } | ||
46 | |||
47 | static int isp1301_clear(struct isp1301 *isp, u8 reg, u8 value) | ||
48 | { | ||
49 | return __isp1301_write(isp, reg, value, ISP1301_I2C_REG_CLEAR_ADDR); | ||
50 | } | ||
51 | |||
52 | static int isp1301_phy_init(struct usb_phy *phy) | ||
53 | { | ||
54 | struct isp1301 *isp = phy_to_isp(phy); | ||
55 | |||
56 | /* Disable transparent UART mode first */ | ||
57 | isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_UART_EN); | ||
58 | isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, ~MC1_SPEED_REG); | ||
59 | isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG); | ||
60 | isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_2, ~0); | ||
61 | isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_PSW_EN | ||
62 | | MC2_SPD_SUSP_CTRL)); | ||
63 | |||
64 | isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, ~0); | ||
65 | isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0); | ||
66 | isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLDOWN | ||
67 | | OTG1_DP_PULLDOWN)); | ||
68 | isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLUP | ||
69 | | OTG1_DP_PULLUP)); | ||
70 | |||
71 | /* mask all interrupts */ | ||
72 | isp1301_clear(isp, ISP1301_I2C_INTERRUPT_LATCH, ~0); | ||
73 | isp1301_clear(isp, ISP1301_I2C_INTERRUPT_FALLING, ~0); | ||
74 | isp1301_clear(isp, ISP1301_I2C_INTERRUPT_RISING, ~0); | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | static int isp1301_phy_set_vbus(struct usb_phy *phy, int on) | ||
80 | { | ||
81 | struct isp1301 *isp = phy_to_isp(phy); | ||
82 | |||
83 | if (on) | ||
84 | isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV); | ||
85 | else | ||
86 | isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static int isp1301_probe(struct i2c_client *client, | ||
92 | const struct i2c_device_id *i2c_id) | ||
93 | { | ||
94 | struct isp1301 *isp; | ||
95 | struct usb_phy *phy; | ||
96 | |||
97 | isp = devm_kzalloc(&client->dev, sizeof(*isp), GFP_KERNEL); | ||
98 | if (!isp) | ||
99 | return -ENOMEM; | ||
100 | |||
101 | isp->client = client; | ||
102 | mutex_init(&isp->mutex); | ||
103 | |||
104 | phy = &isp->phy; | ||
105 | phy->label = DRV_NAME; | ||
106 | phy->init = isp1301_phy_init; | ||
107 | phy->set_vbus = isp1301_phy_set_vbus; | ||
108 | phy->type = USB_PHY_TYPE_USB2; | ||
109 | |||
110 | i2c_set_clientdata(client, isp); | ||
111 | usb_add_phy_dev(phy); | ||
112 | |||
113 | isp1301_i2c_client = client; | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | static int isp1301_remove(struct i2c_client *client) | ||
119 | { | ||
120 | struct isp1301 *isp = i2c_get_clientdata(client); | ||
121 | |||
122 | usb_remove_phy(&isp->phy); | ||
123 | isp1301_i2c_client = NULL; | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | static struct i2c_driver isp1301_driver = { | ||
129 | .driver = { | ||
130 | .name = DRV_NAME, | ||
131 | }, | ||
132 | .probe = isp1301_probe, | ||
133 | .remove = isp1301_remove, | ||
134 | .id_table = isp1301_id, | ||
135 | }; | ||
136 | |||
137 | module_i2c_driver(isp1301_driver); | ||
138 | |||
139 | static int match(struct device *dev, void *data) | ||
140 | { | ||
141 | struct device_node *node = (struct device_node *)data; | ||
142 | return (dev->of_node == node) && | ||
143 | (dev->driver == &isp1301_driver.driver); | ||
144 | } | ||
145 | |||
146 | struct i2c_client *isp1301_get_client(struct device_node *node) | ||
147 | { | ||
148 | if (node) { /* reference of ISP1301 I2C node via DT */ | ||
149 | struct device *dev = bus_find_device(&i2c_bus_type, NULL, | ||
150 | node, match); | ||
151 | if (!dev) | ||
152 | return NULL; | ||
153 | return to_i2c_client(dev); | ||
154 | } else { /* non-DT: only one ISP1301 chip supported */ | ||
155 | return isp1301_i2c_client; | ||
156 | } | ||
157 | } | ||
158 | EXPORT_SYMBOL_GPL(isp1301_get_client); | ||
159 | |||
160 | MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); | ||
161 | MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver"); | ||
162 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/phy/phy-msm-usb.c index 749fbf41fb6f..749fbf41fb6f 100644 --- a/drivers/usb/otg/msm_otg.c +++ b/drivers/usb/phy/phy-msm-usb.c | |||
diff --git a/drivers/usb/phy/mv_u3d_phy.c b/drivers/usb/phy/phy-mv-u3d-usb.c index bafd67f1f134..f7838a43347c 100644 --- a/drivers/usb/phy/mv_u3d_phy.c +++ b/drivers/usb/phy/phy-mv-u3d-usb.c | |||
@@ -15,7 +15,7 @@ | |||
15 | #include <linux/usb/otg.h> | 15 | #include <linux/usb/otg.h> |
16 | #include <linux/platform_data/mv_usb.h> | 16 | #include <linux/platform_data/mv_usb.h> |
17 | 17 | ||
18 | #include "mv_u3d_phy.h" | 18 | #include "phy-mv-u3d-usb.h" |
19 | 19 | ||
20 | /* | 20 | /* |
21 | * struct mv_u3d_phy - transceiver driver state | 21 | * struct mv_u3d_phy - transceiver driver state |
diff --git a/drivers/usb/phy/mv_u3d_phy.h b/drivers/usb/phy/phy-mv-u3d-usb.h index 2a658cb9a527..2a658cb9a527 100644 --- a/drivers/usb/phy/mv_u3d_phy.h +++ b/drivers/usb/phy/phy-mv-u3d-usb.h | |||
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/phy/phy-mv-usb.c index b6a9be31133b..c987bbe27851 100644 --- a/drivers/usb/otg/mv_otg.c +++ b/drivers/usb/phy/phy-mv-usb.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <linux/usb/hcd.h> | 27 | #include <linux/usb/hcd.h> |
28 | #include <linux/platform_data/mv_usb.h> | 28 | #include <linux/platform_data/mv_usb.h> |
29 | 29 | ||
30 | #include "mv_otg.h" | 30 | #include "phy-mv-usb.h" |
31 | 31 | ||
32 | #define DRIVER_DESC "Marvell USB OTG transceiver driver" | 32 | #define DRIVER_DESC "Marvell USB OTG transceiver driver" |
33 | #define DRIVER_VERSION "Jan 20, 2010" | 33 | #define DRIVER_VERSION "Jan 20, 2010" |
@@ -237,18 +237,12 @@ static void mv_otg_start_periphrals(struct mv_otg *mvotg, int on) | |||
237 | 237 | ||
238 | static void otg_clock_enable(struct mv_otg *mvotg) | 238 | static void otg_clock_enable(struct mv_otg *mvotg) |
239 | { | 239 | { |
240 | unsigned int i; | 240 | clk_prepare_enable(mvotg->clk); |
241 | |||
242 | for (i = 0; i < mvotg->clknum; i++) | ||
243 | clk_prepare_enable(mvotg->clk[i]); | ||
244 | } | 241 | } |
245 | 242 | ||
246 | static void otg_clock_disable(struct mv_otg *mvotg) | 243 | static void otg_clock_disable(struct mv_otg *mvotg) |
247 | { | 244 | { |
248 | unsigned int i; | 245 | clk_disable_unprepare(mvotg->clk); |
249 | |||
250 | for (i = 0; i < mvotg->clknum; i++) | ||
251 | clk_disable_unprepare(mvotg->clk[i]); | ||
252 | } | 246 | } |
253 | 247 | ||
254 | static int mv_otg_enable_internal(struct mv_otg *mvotg) | 248 | static int mv_otg_enable_internal(struct mv_otg *mvotg) |
@@ -684,16 +678,14 @@ static int mv_otg_probe(struct platform_device *pdev) | |||
684 | struct mv_otg *mvotg; | 678 | struct mv_otg *mvotg; |
685 | struct usb_otg *otg; | 679 | struct usb_otg *otg; |
686 | struct resource *r; | 680 | struct resource *r; |
687 | int retval = 0, clk_i, i; | 681 | int retval = 0, i; |
688 | size_t size; | ||
689 | 682 | ||
690 | if (pdata == NULL) { | 683 | if (pdata == NULL) { |
691 | dev_err(&pdev->dev, "failed to get platform data\n"); | 684 | dev_err(&pdev->dev, "failed to get platform data\n"); |
692 | return -ENODEV; | 685 | return -ENODEV; |
693 | } | 686 | } |
694 | 687 | ||
695 | size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; | 688 | mvotg = devm_kzalloc(&pdev->dev, sizeof(*mvotg), GFP_KERNEL); |
696 | mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); | ||
697 | if (!mvotg) { | 689 | if (!mvotg) { |
698 | dev_err(&pdev->dev, "failed to allocate memory!\n"); | 690 | dev_err(&pdev->dev, "failed to allocate memory!\n"); |
699 | return -ENOMEM; | 691 | return -ENOMEM; |
@@ -708,15 +700,9 @@ static int mv_otg_probe(struct platform_device *pdev) | |||
708 | mvotg->pdev = pdev; | 700 | mvotg->pdev = pdev; |
709 | mvotg->pdata = pdata; | 701 | mvotg->pdata = pdata; |
710 | 702 | ||
711 | mvotg->clknum = pdata->clknum; | 703 | mvotg->clk = devm_clk_get(&pdev->dev, NULL); |
712 | for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { | 704 | if (IS_ERR(mvotg->clk)) |
713 | mvotg->clk[clk_i] = devm_clk_get(&pdev->dev, | 705 | return PTR_ERR(mvotg->clk); |
714 | pdata->clkname[clk_i]); | ||
715 | if (IS_ERR(mvotg->clk[clk_i])) { | ||
716 | retval = PTR_ERR(mvotg->clk[clk_i]); | ||
717 | return retval; | ||
718 | } | ||
719 | } | ||
720 | 706 | ||
721 | mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); | 707 | mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); |
722 | if (!mvotg->qwork) { | 708 | if (!mvotg->qwork) { |
diff --git a/drivers/usb/otg/mv_otg.h b/drivers/usb/phy/phy-mv-usb.h index 8a9e351b36ba..551da6eb0ba8 100644 --- a/drivers/usb/otg/mv_otg.h +++ b/drivers/usb/phy/phy-mv-usb.h | |||
@@ -158,8 +158,7 @@ struct mv_otg { | |||
158 | 158 | ||
159 | unsigned int active; | 159 | unsigned int active; |
160 | unsigned int clock_gating; | 160 | unsigned int clock_gating; |
161 | unsigned int clknum; | 161 | struct clk *clk; |
162 | struct clk *clk[0]; | ||
163 | }; | 162 | }; |
164 | 163 | ||
165 | #endif | 164 | #endif |
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/phy/phy-mxs-usb.c index b0d9f119c749..9d4381e64d51 100644 --- a/drivers/usb/otg/mxs-phy.c +++ b/drivers/usb/phy/phy-mxs-usb.c | |||
@@ -48,12 +48,12 @@ static void mxs_phy_hw_init(struct mxs_phy *mxs_phy) | |||
48 | stmp_reset_block(base + HW_USBPHY_CTRL); | 48 | stmp_reset_block(base + HW_USBPHY_CTRL); |
49 | 49 | ||
50 | /* Power up the PHY */ | 50 | /* Power up the PHY */ |
51 | writel_relaxed(0, base + HW_USBPHY_PWD); | 51 | writel(0, base + HW_USBPHY_PWD); |
52 | 52 | ||
53 | /* enable FS/LS device */ | 53 | /* enable FS/LS device */ |
54 | writel_relaxed(BM_USBPHY_CTRL_ENUTMILEVEL2 | | 54 | writel(BM_USBPHY_CTRL_ENUTMILEVEL2 | |
55 | BM_USBPHY_CTRL_ENUTMILEVEL3, | 55 | BM_USBPHY_CTRL_ENUTMILEVEL3, |
56 | base + HW_USBPHY_CTRL_SET); | 56 | base + HW_USBPHY_CTRL_SET); |
57 | } | 57 | } |
58 | 58 | ||
59 | static int mxs_phy_init(struct usb_phy *phy) | 59 | static int mxs_phy_init(struct usb_phy *phy) |
@@ -70,8 +70,8 @@ static void mxs_phy_shutdown(struct usb_phy *phy) | |||
70 | { | 70 | { |
71 | struct mxs_phy *mxs_phy = to_mxs_phy(phy); | 71 | struct mxs_phy *mxs_phy = to_mxs_phy(phy); |
72 | 72 | ||
73 | writel_relaxed(BM_USBPHY_CTRL_CLKGATE, | 73 | writel(BM_USBPHY_CTRL_CLKGATE, |
74 | phy->io_priv + HW_USBPHY_CTRL_SET); | 74 | phy->io_priv + HW_USBPHY_CTRL_SET); |
75 | 75 | ||
76 | clk_disable_unprepare(mxs_phy->clk); | 76 | clk_disable_unprepare(mxs_phy->clk); |
77 | } | 77 | } |
@@ -81,15 +81,15 @@ static int mxs_phy_suspend(struct usb_phy *x, int suspend) | |||
81 | struct mxs_phy *mxs_phy = to_mxs_phy(x); | 81 | struct mxs_phy *mxs_phy = to_mxs_phy(x); |
82 | 82 | ||
83 | if (suspend) { | 83 | if (suspend) { |
84 | writel_relaxed(0xffffffff, x->io_priv + HW_USBPHY_PWD); | 84 | writel(0xffffffff, x->io_priv + HW_USBPHY_PWD); |
85 | writel_relaxed(BM_USBPHY_CTRL_CLKGATE, | 85 | writel(BM_USBPHY_CTRL_CLKGATE, |
86 | x->io_priv + HW_USBPHY_CTRL_SET); | 86 | x->io_priv + HW_USBPHY_CTRL_SET); |
87 | clk_disable_unprepare(mxs_phy->clk); | 87 | clk_disable_unprepare(mxs_phy->clk); |
88 | } else { | 88 | } else { |
89 | clk_prepare_enable(mxs_phy->clk); | 89 | clk_prepare_enable(mxs_phy->clk); |
90 | writel_relaxed(BM_USBPHY_CTRL_CLKGATE, | 90 | writel(BM_USBPHY_CTRL_CLKGATE, |
91 | x->io_priv + HW_USBPHY_CTRL_CLR); | 91 | x->io_priv + HW_USBPHY_CTRL_CLR); |
92 | writel_relaxed(0, x->io_priv + HW_USBPHY_PWD); | 92 | writel(0, x->io_priv + HW_USBPHY_PWD); |
93 | } | 93 | } |
94 | 94 | ||
95 | return 0; | 95 | return 0; |
@@ -102,8 +102,8 @@ static int mxs_phy_on_connect(struct usb_phy *phy, | |||
102 | (speed == USB_SPEED_HIGH) ? "high" : "non-high"); | 102 | (speed == USB_SPEED_HIGH) ? "high" : "non-high"); |
103 | 103 | ||
104 | if (speed == USB_SPEED_HIGH) | 104 | if (speed == USB_SPEED_HIGH) |
105 | writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, | 105 | writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, |
106 | phy->io_priv + HW_USBPHY_CTRL_SET); | 106 | phy->io_priv + HW_USBPHY_CTRL_SET); |
107 | 107 | ||
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
@@ -115,8 +115,8 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy, | |||
115 | (speed == USB_SPEED_HIGH) ? "high" : "non-high"); | 115 | (speed == USB_SPEED_HIGH) ? "high" : "non-high"); |
116 | 116 | ||
117 | if (speed == USB_SPEED_HIGH) | 117 | if (speed == USB_SPEED_HIGH) |
118 | writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, | 118 | writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, |
119 | phy->io_priv + HW_USBPHY_CTRL_CLR); | 119 | phy->io_priv + HW_USBPHY_CTRL_CLR); |
120 | 120 | ||
121 | return 0; | 121 | return 0; |
122 | } | 122 | } |
@@ -127,6 +127,7 @@ static int mxs_phy_probe(struct platform_device *pdev) | |||
127 | void __iomem *base; | 127 | void __iomem *base; |
128 | struct clk *clk; | 128 | struct clk *clk; |
129 | struct mxs_phy *mxs_phy; | 129 | struct mxs_phy *mxs_phy; |
130 | int ret; | ||
130 | 131 | ||
131 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 132 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
132 | if (!res) { | 133 | if (!res) { |
@@ -166,11 +167,19 @@ static int mxs_phy_probe(struct platform_device *pdev) | |||
166 | 167 | ||
167 | platform_set_drvdata(pdev, &mxs_phy->phy); | 168 | platform_set_drvdata(pdev, &mxs_phy->phy); |
168 | 169 | ||
170 | ret = usb_add_phy_dev(&mxs_phy->phy); | ||
171 | if (ret) | ||
172 | return ret; | ||
173 | |||
169 | return 0; | 174 | return 0; |
170 | } | 175 | } |
171 | 176 | ||
172 | static int mxs_phy_remove(struct platform_device *pdev) | 177 | static int mxs_phy_remove(struct platform_device *pdev) |
173 | { | 178 | { |
179 | struct mxs_phy *mxs_phy = platform_get_drvdata(pdev); | ||
180 | |||
181 | usb_remove_phy(&mxs_phy->phy); | ||
182 | |||
174 | platform_set_drvdata(pdev, NULL); | 183 | platform_set_drvdata(pdev, NULL); |
175 | 184 | ||
176 | return 0; | 185 | return 0; |
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/phy/phy-nop.c index a3ce24b94a73..2b10cc969bbb 100644 --- a/drivers/usb/otg/nop-usb-xceiv.c +++ b/drivers/usb/phy/phy-nop.c | |||
@@ -32,10 +32,16 @@ | |||
32 | #include <linux/usb/otg.h> | 32 | #include <linux/usb/otg.h> |
33 | #include <linux/usb/nop-usb-xceiv.h> | 33 | #include <linux/usb/nop-usb-xceiv.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/clk.h> | ||
36 | #include <linux/regulator/consumer.h> | ||
37 | #include <linux/of.h> | ||
35 | 38 | ||
36 | struct nop_usb_xceiv { | 39 | struct nop_usb_xceiv { |
37 | struct usb_phy phy; | 40 | struct usb_phy phy; |
38 | struct device *dev; | 41 | struct device *dev; |
42 | struct clk *clk; | ||
43 | struct regulator *vcc; | ||
44 | struct regulator *reset; | ||
39 | }; | 45 | }; |
40 | 46 | ||
41 | static struct platform_device *pd; | 47 | static struct platform_device *pd; |
@@ -64,6 +70,46 @@ static int nop_set_suspend(struct usb_phy *x, int suspend) | |||
64 | return 0; | 70 | return 0; |
65 | } | 71 | } |
66 | 72 | ||
73 | static int nop_init(struct usb_phy *phy) | ||
74 | { | ||
75 | struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev); | ||
76 | |||
77 | if (!IS_ERR(nop->vcc)) { | ||
78 | if (regulator_enable(nop->vcc)) | ||
79 | dev_err(phy->dev, "Failed to enable power\n"); | ||
80 | } | ||
81 | |||
82 | if (!IS_ERR(nop->clk)) | ||
83 | clk_enable(nop->clk); | ||
84 | |||
85 | if (!IS_ERR(nop->reset)) { | ||
86 | /* De-assert RESET */ | ||
87 | if (regulator_enable(nop->reset)) | ||
88 | dev_err(phy->dev, "Failed to de-assert reset\n"); | ||
89 | } | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | static void nop_shutdown(struct usb_phy *phy) | ||
95 | { | ||
96 | struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev); | ||
97 | |||
98 | if (!IS_ERR(nop->reset)) { | ||
99 | /* Assert RESET */ | ||
100 | if (regulator_disable(nop->reset)) | ||
101 | dev_err(phy->dev, "Failed to assert reset\n"); | ||
102 | } | ||
103 | |||
104 | if (!IS_ERR(nop->clk)) | ||
105 | clk_disable(nop->clk); | ||
106 | |||
107 | if (!IS_ERR(nop->vcc)) { | ||
108 | if (regulator_disable(nop->vcc)) | ||
109 | dev_err(phy->dev, "Failed to disable power\n"); | ||
110 | } | ||
111 | } | ||
112 | |||
67 | static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) | 113 | static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) |
68 | { | 114 | { |
69 | if (!otg) | 115 | if (!otg) |
@@ -95,39 +141,96 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
95 | 141 | ||
96 | static int nop_usb_xceiv_probe(struct platform_device *pdev) | 142 | static int nop_usb_xceiv_probe(struct platform_device *pdev) |
97 | { | 143 | { |
144 | struct device *dev = &pdev->dev; | ||
98 | struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data; | 145 | struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data; |
99 | struct nop_usb_xceiv *nop; | 146 | struct nop_usb_xceiv *nop; |
100 | enum usb_phy_type type = USB_PHY_TYPE_USB2; | 147 | enum usb_phy_type type = USB_PHY_TYPE_USB2; |
101 | int err; | 148 | int err; |
149 | u32 clk_rate = 0; | ||
150 | bool needs_vcc = false; | ||
151 | bool needs_reset = false; | ||
102 | 152 | ||
103 | nop = kzalloc(sizeof *nop, GFP_KERNEL); | 153 | nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL); |
104 | if (!nop) | 154 | if (!nop) |
105 | return -ENOMEM; | 155 | return -ENOMEM; |
106 | 156 | ||
107 | nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL); | 157 | nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg), |
108 | if (!nop->phy.otg) { | 158 | GFP_KERNEL); |
109 | kfree(nop); | 159 | if (!nop->phy.otg) |
110 | return -ENOMEM; | 160 | return -ENOMEM; |
111 | } | ||
112 | 161 | ||
113 | if (pdata) | 162 | if (dev->of_node) { |
163 | struct device_node *node = dev->of_node; | ||
164 | |||
165 | if (of_property_read_u32(node, "clock-frequency", &clk_rate)) | ||
166 | clk_rate = 0; | ||
167 | |||
168 | needs_vcc = of_property_read_bool(node, "vcc-supply"); | ||
169 | needs_reset = of_property_read_bool(node, "reset-supply"); | ||
170 | |||
171 | } else if (pdata) { | ||
114 | type = pdata->type; | 172 | type = pdata->type; |
173 | clk_rate = pdata->clk_rate; | ||
174 | needs_vcc = pdata->needs_vcc; | ||
175 | needs_reset = pdata->needs_reset; | ||
176 | } | ||
177 | |||
178 | nop->clk = devm_clk_get(&pdev->dev, "main_clk"); | ||
179 | if (IS_ERR(nop->clk)) { | ||
180 | dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n", | ||
181 | PTR_ERR(nop->clk)); | ||
182 | } | ||
183 | |||
184 | if (!IS_ERR(nop->clk) && clk_rate) { | ||
185 | err = clk_set_rate(nop->clk, clk_rate); | ||
186 | if (err) { | ||
187 | dev_err(&pdev->dev, "Error setting clock rate\n"); | ||
188 | return err; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | if (!IS_ERR(nop->clk)) { | ||
193 | err = clk_prepare(nop->clk); | ||
194 | if (err) { | ||
195 | dev_err(&pdev->dev, "Error preparing clock\n"); | ||
196 | return err; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | nop->vcc = devm_regulator_get(&pdev->dev, "vcc"); | ||
201 | if (IS_ERR(nop->vcc)) { | ||
202 | dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n", | ||
203 | PTR_ERR(nop->vcc)); | ||
204 | if (needs_vcc) | ||
205 | return -EPROBE_DEFER; | ||
206 | } | ||
207 | |||
208 | nop->reset = devm_regulator_get(&pdev->dev, "reset"); | ||
209 | if (IS_ERR(nop->reset)) { | ||
210 | dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n", | ||
211 | PTR_ERR(nop->reset)); | ||
212 | if (needs_reset) | ||
213 | return -EPROBE_DEFER; | ||
214 | } | ||
115 | 215 | ||
116 | nop->dev = &pdev->dev; | 216 | nop->dev = &pdev->dev; |
117 | nop->phy.dev = nop->dev; | 217 | nop->phy.dev = nop->dev; |
118 | nop->phy.label = "nop-xceiv"; | 218 | nop->phy.label = "nop-xceiv"; |
119 | nop->phy.set_suspend = nop_set_suspend; | 219 | nop->phy.set_suspend = nop_set_suspend; |
220 | nop->phy.init = nop_init; | ||
221 | nop->phy.shutdown = nop_shutdown; | ||
120 | nop->phy.state = OTG_STATE_UNDEFINED; | 222 | nop->phy.state = OTG_STATE_UNDEFINED; |
223 | nop->phy.type = type; | ||
121 | 224 | ||
122 | nop->phy.otg->phy = &nop->phy; | 225 | nop->phy.otg->phy = &nop->phy; |
123 | nop->phy.otg->set_host = nop_set_host; | 226 | nop->phy.otg->set_host = nop_set_host; |
124 | nop->phy.otg->set_peripheral = nop_set_peripheral; | 227 | nop->phy.otg->set_peripheral = nop_set_peripheral; |
125 | 228 | ||
126 | err = usb_add_phy(&nop->phy, type); | 229 | err = usb_add_phy_dev(&nop->phy); |
127 | if (err) { | 230 | if (err) { |
128 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", | 231 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", |
129 | err); | 232 | err); |
130 | goto exit; | 233 | goto err_add; |
131 | } | 234 | } |
132 | 235 | ||
133 | platform_set_drvdata(pdev, nop); | 236 | platform_set_drvdata(pdev, nop); |
@@ -135,9 +238,10 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev) | |||
135 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); | 238 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); |
136 | 239 | ||
137 | return 0; | 240 | return 0; |
138 | exit: | 241 | |
139 | kfree(nop->phy.otg); | 242 | err_add: |
140 | kfree(nop); | 243 | if (!IS_ERR(nop->clk)) |
244 | clk_unprepare(nop->clk); | ||
141 | return err; | 245 | return err; |
142 | } | 246 | } |
143 | 247 | ||
@@ -145,21 +249,30 @@ static int nop_usb_xceiv_remove(struct platform_device *pdev) | |||
145 | { | 249 | { |
146 | struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); | 250 | struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); |
147 | 251 | ||
252 | if (!IS_ERR(nop->clk)) | ||
253 | clk_unprepare(nop->clk); | ||
254 | |||
148 | usb_remove_phy(&nop->phy); | 255 | usb_remove_phy(&nop->phy); |
149 | 256 | ||
150 | platform_set_drvdata(pdev, NULL); | 257 | platform_set_drvdata(pdev, NULL); |
151 | kfree(nop->phy.otg); | ||
152 | kfree(nop); | ||
153 | 258 | ||
154 | return 0; | 259 | return 0; |
155 | } | 260 | } |
156 | 261 | ||
262 | static const struct of_device_id nop_xceiv_dt_ids[] = { | ||
263 | { .compatible = "usb-nop-xceiv" }, | ||
264 | { } | ||
265 | }; | ||
266 | |||
267 | MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids); | ||
268 | |||
157 | static struct platform_driver nop_usb_xceiv_driver = { | 269 | static struct platform_driver nop_usb_xceiv_driver = { |
158 | .probe = nop_usb_xceiv_probe, | 270 | .probe = nop_usb_xceiv_probe, |
159 | .remove = nop_usb_xceiv_remove, | 271 | .remove = nop_usb_xceiv_remove, |
160 | .driver = { | 272 | .driver = { |
161 | .name = "nop_usb_xceiv", | 273 | .name = "nop_usb_xceiv", |
162 | .owner = THIS_MODULE, | 274 | .owner = THIS_MODULE, |
275 | .of_match_table = of_match_ptr(nop_xceiv_dt_ids), | ||
163 | }, | 276 | }, |
164 | }; | 277 | }; |
165 | 278 | ||
diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/phy-omap-control.c index 1419ceda9759..1419ceda9759 100644 --- a/drivers/usb/phy/omap-control-usb.c +++ b/drivers/usb/phy/phy-omap-control.c | |||
diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/phy-omap-usb2.c index 844ab68f08d0..844ab68f08d0 100644 --- a/drivers/usb/phy/omap-usb2.c +++ b/drivers/usb/phy/phy-omap-usb2.c | |||
diff --git a/drivers/usb/phy/omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c index a6e60b1e102e..a6e60b1e102e 100644 --- a/drivers/usb/phy/omap-usb3.c +++ b/drivers/usb/phy/phy-omap-usb3.c | |||
diff --git a/drivers/usb/phy/rcar-phy.c b/drivers/usb/phy/phy-rcar-usb.c index a35681b0c501..a35681b0c501 100644 --- a/drivers/usb/phy/rcar-phy.c +++ b/drivers/usb/phy/phy-rcar-usb.c | |||
diff --git a/drivers/usb/phy/phy-samsung-usb.c b/drivers/usb/phy/phy-samsung-usb.c new file mode 100644 index 000000000000..7b118ee5f5e4 --- /dev/null +++ b/drivers/usb/phy/phy-samsung-usb.c | |||
@@ -0,0 +1,236 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb.c | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Praveen Paneri <p.paneri@samsung.com> | ||
7 | * | ||
8 | * Samsung USB-PHY helper driver with common function calls; | ||
9 | * interacts with Samsung USB 2.0 PHY controller driver and later | ||
10 | * with Samsung USB 3.0 PHY driver. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License version 2 as | ||
14 | * published by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/clk.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/of.h> | ||
29 | #include <linux/of_address.h> | ||
30 | #include <linux/usb/samsung_usb_phy.h> | ||
31 | |||
32 | #include "phy-samsung-usb.h" | ||
33 | |||
34 | int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy) | ||
35 | { | ||
36 | struct device_node *usbphy_sys; | ||
37 | |||
38 | /* Getting node for system controller interface for usb-phy */ | ||
39 | usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys"); | ||
40 | if (!usbphy_sys) { | ||
41 | dev_err(sphy->dev, "No sys-controller interface for usb-phy\n"); | ||
42 | return -ENODEV; | ||
43 | } | ||
44 | |||
45 | sphy->pmuregs = of_iomap(usbphy_sys, 0); | ||
46 | |||
47 | if (sphy->pmuregs == NULL) { | ||
48 | dev_err(sphy->dev, "Can't get usb-phy pmu control register\n"); | ||
49 | goto err0; | ||
50 | } | ||
51 | |||
52 | sphy->sysreg = of_iomap(usbphy_sys, 1); | ||
53 | |||
54 | /* | ||
55 | * Not returning error code here, since this situation is not fatal. | ||
56 | * Few SoCs may not have this switch available | ||
57 | */ | ||
58 | if (sphy->sysreg == NULL) | ||
59 | dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n"); | ||
60 | |||
61 | of_node_put(usbphy_sys); | ||
62 | |||
63 | return 0; | ||
64 | |||
65 | err0: | ||
66 | of_node_put(usbphy_sys); | ||
67 | return -ENXIO; | ||
68 | } | ||
69 | EXPORT_SYMBOL_GPL(samsung_usbphy_parse_dt); | ||
70 | |||
71 | /* | ||
72 | * Set isolation here for phy. | ||
73 | * Here 'on = true' would mean USB PHY block is isolated, hence | ||
74 | * de-activated and vice-versa. | ||
75 | */ | ||
76 | void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on) | ||
77 | { | ||
78 | void __iomem *reg = NULL; | ||
79 | u32 reg_val; | ||
80 | u32 en_mask = 0; | ||
81 | |||
82 | if (!sphy->pmuregs) { | ||
83 | dev_warn(sphy->dev, "Can't set pmu isolation\n"); | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | switch (sphy->drv_data->cpu_type) { | ||
88 | case TYPE_S3C64XX: | ||
89 | /* | ||
90 | * Do nothing: We will add here once S3C64xx goes for DT support | ||
91 | */ | ||
92 | break; | ||
93 | case TYPE_EXYNOS4210: | ||
94 | /* | ||
95 | * Fall through since exynos4210 and exynos5250 have similar | ||
96 | * register architecture: two separate registers for host and | ||
97 | * device phy control with enable bit at position 0. | ||
98 | */ | ||
99 | case TYPE_EXYNOS5250: | ||
100 | if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { | ||
101 | reg = sphy->pmuregs + | ||
102 | sphy->drv_data->devphy_reg_offset; | ||
103 | en_mask = sphy->drv_data->devphy_en_mask; | ||
104 | } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { | ||
105 | reg = sphy->pmuregs + | ||
106 | sphy->drv_data->hostphy_reg_offset; | ||
107 | en_mask = sphy->drv_data->hostphy_en_mask; | ||
108 | } | ||
109 | break; | ||
110 | default: | ||
111 | dev_err(sphy->dev, "Invalid SoC type\n"); | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | reg_val = readl(reg); | ||
116 | |||
117 | if (on) | ||
118 | reg_val &= ~en_mask; | ||
119 | else | ||
120 | reg_val |= en_mask; | ||
121 | |||
122 | writel(reg_val, reg); | ||
123 | } | ||
124 | EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation); | ||
125 | |||
126 | /* | ||
127 | * Configure the mode of working of usb-phy here: HOST/DEVICE. | ||
128 | */ | ||
129 | void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy) | ||
130 | { | ||
131 | u32 reg; | ||
132 | |||
133 | if (!sphy->sysreg) { | ||
134 | dev_warn(sphy->dev, "Can't configure specified phy mode\n"); | ||
135 | return; | ||
136 | } | ||
137 | |||
138 | reg = readl(sphy->sysreg); | ||
139 | |||
140 | if (sphy->phy_type == USB_PHY_TYPE_DEVICE) | ||
141 | reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK; | ||
142 | else if (sphy->phy_type == USB_PHY_TYPE_HOST) | ||
143 | reg |= EXYNOS_USB20PHY_CFG_HOST_LINK; | ||
144 | |||
145 | writel(reg, sphy->sysreg); | ||
146 | } | ||
147 | EXPORT_SYMBOL_GPL(samsung_usbphy_cfg_sel); | ||
148 | |||
149 | /* | ||
150 | * PHYs are different for USB Device and USB Host. | ||
151 | * This make sure that correct PHY type is selected before | ||
152 | * any operation on PHY. | ||
153 | */ | ||
154 | int samsung_usbphy_set_type(struct usb_phy *phy, | ||
155 | enum samsung_usb_phy_type phy_type) | ||
156 | { | ||
157 | struct samsung_usbphy *sphy = phy_to_sphy(phy); | ||
158 | |||
159 | sphy->phy_type = phy_type; | ||
160 | |||
161 | return 0; | ||
162 | } | ||
163 | EXPORT_SYMBOL_GPL(samsung_usbphy_set_type); | ||
164 | |||
165 | /* | ||
166 | * Returns reference clock frequency selection value | ||
167 | */ | ||
168 | int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy) | ||
169 | { | ||
170 | struct clk *ref_clk; | ||
171 | int refclk_freq = 0; | ||
172 | |||
173 | /* | ||
174 | * In exynos5250 USB host and device PHY use | ||
175 | * external crystal clock XXTI | ||
176 | */ | ||
177 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
178 | ref_clk = devm_clk_get(sphy->dev, "ext_xtal"); | ||
179 | else | ||
180 | ref_clk = devm_clk_get(sphy->dev, "xusbxti"); | ||
181 | if (IS_ERR(ref_clk)) { | ||
182 | dev_err(sphy->dev, "Failed to get reference clock\n"); | ||
183 | return PTR_ERR(ref_clk); | ||
184 | } | ||
185 | |||
186 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) { | ||
187 | /* set clock frequency for PLL */ | ||
188 | switch (clk_get_rate(ref_clk)) { | ||
189 | case 9600 * KHZ: | ||
190 | refclk_freq = FSEL_CLKSEL_9600K; | ||
191 | break; | ||
192 | case 10 * MHZ: | ||
193 | refclk_freq = FSEL_CLKSEL_10M; | ||
194 | break; | ||
195 | case 12 * MHZ: | ||
196 | refclk_freq = FSEL_CLKSEL_12M; | ||
197 | break; | ||
198 | case 19200 * KHZ: | ||
199 | refclk_freq = FSEL_CLKSEL_19200K; | ||
200 | break; | ||
201 | case 20 * MHZ: | ||
202 | refclk_freq = FSEL_CLKSEL_20M; | ||
203 | break; | ||
204 | case 50 * MHZ: | ||
205 | refclk_freq = FSEL_CLKSEL_50M; | ||
206 | break; | ||
207 | case 24 * MHZ: | ||
208 | default: | ||
209 | /* default reference clock */ | ||
210 | refclk_freq = FSEL_CLKSEL_24M; | ||
211 | break; | ||
212 | } | ||
213 | } else { | ||
214 | switch (clk_get_rate(ref_clk)) { | ||
215 | case 12 * MHZ: | ||
216 | refclk_freq = PHYCLK_CLKSEL_12M; | ||
217 | break; | ||
218 | case 24 * MHZ: | ||
219 | refclk_freq = PHYCLK_CLKSEL_24M; | ||
220 | break; | ||
221 | case 48 * MHZ: | ||
222 | refclk_freq = PHYCLK_CLKSEL_48M; | ||
223 | break; | ||
224 | default: | ||
225 | if (sphy->drv_data->cpu_type == TYPE_S3C64XX) | ||
226 | refclk_freq = PHYCLK_CLKSEL_48M; | ||
227 | else | ||
228 | refclk_freq = PHYCLK_CLKSEL_24M; | ||
229 | break; | ||
230 | } | ||
231 | } | ||
232 | clk_put(ref_clk); | ||
233 | |||
234 | return refclk_freq; | ||
235 | } | ||
236 | EXPORT_SYMBOL_GPL(samsung_usbphy_get_refclk_freq); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb.h b/drivers/usb/phy/phy-samsung-usb.h new file mode 100644 index 000000000000..70a9cae5e37f --- /dev/null +++ b/drivers/usb/phy/phy-samsung-usb.h | |||
@@ -0,0 +1,327 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb.h | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Samsung USB-PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and | ||
7 | * OHCI-EXYNOS controllers. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | */ | ||
18 | |||
19 | #include <linux/usb/phy.h> | ||
20 | |||
21 | /* Register definitions */ | ||
22 | |||
23 | #define SAMSUNG_PHYPWR (0x00) | ||
24 | |||
25 | #define PHYPWR_NORMAL_MASK (0x19 << 0) | ||
26 | #define PHYPWR_OTG_DISABLE (0x1 << 4) | ||
27 | #define PHYPWR_ANALOG_POWERDOWN (0x1 << 3) | ||
28 | #define PHYPWR_FORCE_SUSPEND (0x1 << 1) | ||
29 | /* For Exynos4 */ | ||
30 | #define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0) | ||
31 | #define PHYPWR_SLEEP_PHY0 (0x1 << 5) | ||
32 | |||
33 | #define SAMSUNG_PHYCLK (0x04) | ||
34 | |||
35 | #define PHYCLK_MODE_USB11 (0x1 << 6) | ||
36 | #define PHYCLK_EXT_OSC (0x1 << 5) | ||
37 | #define PHYCLK_COMMON_ON_N (0x1 << 4) | ||
38 | #define PHYCLK_ID_PULL (0x1 << 2) | ||
39 | #define PHYCLK_CLKSEL_MASK (0x3 << 0) | ||
40 | #define PHYCLK_CLKSEL_48M (0x0 << 0) | ||
41 | #define PHYCLK_CLKSEL_12M (0x2 << 0) | ||
42 | #define PHYCLK_CLKSEL_24M (0x3 << 0) | ||
43 | |||
44 | #define SAMSUNG_RSTCON (0x08) | ||
45 | |||
46 | #define RSTCON_PHYLINK_SWRST (0x1 << 2) | ||
47 | #define RSTCON_HLINK_SWRST (0x1 << 1) | ||
48 | #define RSTCON_SWRST (0x1 << 0) | ||
49 | |||
50 | /* EXYNOS5 */ | ||
51 | #define EXYNOS5_PHY_HOST_CTRL0 (0x00) | ||
52 | |||
53 | #define HOST_CTRL0_PHYSWRSTALL (0x1 << 31) | ||
54 | |||
55 | #define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19) | ||
56 | #define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19) | ||
57 | #define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19) | ||
58 | #define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19) | ||
59 | |||
60 | #define HOST_CTRL0_FSEL_MASK (0x7 << 16) | ||
61 | #define HOST_CTRL0_FSEL(_x) ((_x) << 16) | ||
62 | |||
63 | #define FSEL_CLKSEL_50M (0x7) | ||
64 | #define FSEL_CLKSEL_24M (0x5) | ||
65 | #define FSEL_CLKSEL_20M (0x4) | ||
66 | #define FSEL_CLKSEL_19200K (0x3) | ||
67 | #define FSEL_CLKSEL_12M (0x2) | ||
68 | #define FSEL_CLKSEL_10M (0x1) | ||
69 | #define FSEL_CLKSEL_9600K (0x0) | ||
70 | |||
71 | #define HOST_CTRL0_TESTBURNIN (0x1 << 11) | ||
72 | #define HOST_CTRL0_RETENABLE (0x1 << 10) | ||
73 | #define HOST_CTRL0_COMMONON_N (0x1 << 9) | ||
74 | #define HOST_CTRL0_SIDDQ (0x1 << 6) | ||
75 | #define HOST_CTRL0_FORCESLEEP (0x1 << 5) | ||
76 | #define HOST_CTRL0_FORCESUSPEND (0x1 << 4) | ||
77 | #define HOST_CTRL0_WORDINTERFACE (0x1 << 3) | ||
78 | #define HOST_CTRL0_UTMISWRST (0x1 << 2) | ||
79 | #define HOST_CTRL0_LINKSWRST (0x1 << 1) | ||
80 | #define HOST_CTRL0_PHYSWRST (0x1 << 0) | ||
81 | |||
82 | #define EXYNOS5_PHY_HOST_TUNE0 (0x04) | ||
83 | |||
84 | #define EXYNOS5_PHY_HSIC_CTRL1 (0x10) | ||
85 | |||
86 | #define EXYNOS5_PHY_HSIC_TUNE1 (0x14) | ||
87 | |||
88 | #define EXYNOS5_PHY_HSIC_CTRL2 (0x20) | ||
89 | |||
90 | #define EXYNOS5_PHY_HSIC_TUNE2 (0x24) | ||
91 | |||
92 | #define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23) | ||
93 | #define HSIC_CTRL_REFCLKSEL (0x2 << 23) | ||
94 | |||
95 | #define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16) | ||
96 | #define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16) | ||
97 | #define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16) | ||
98 | #define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16) | ||
99 | #define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16) | ||
100 | #define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16) | ||
101 | #define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16) | ||
102 | |||
103 | #define HSIC_CTRL_SIDDQ (0x1 << 6) | ||
104 | #define HSIC_CTRL_FORCESLEEP (0x1 << 5) | ||
105 | #define HSIC_CTRL_FORCESUSPEND (0x1 << 4) | ||
106 | #define HSIC_CTRL_WORDINTERFACE (0x1 << 3) | ||
107 | #define HSIC_CTRL_UTMISWRST (0x1 << 2) | ||
108 | #define HSIC_CTRL_PHYSWRST (0x1 << 0) | ||
109 | |||
110 | #define EXYNOS5_PHY_HOST_EHCICTRL (0x30) | ||
111 | |||
112 | #define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29) | ||
113 | #define HOST_EHCICTRL_ENAINCR4 (0x1 << 28) | ||
114 | #define HOST_EHCICTRL_ENAINCR8 (0x1 << 27) | ||
115 | #define HOST_EHCICTRL_ENAINCR16 (0x1 << 26) | ||
116 | |||
117 | #define EXYNOS5_PHY_HOST_OHCICTRL (0x34) | ||
118 | |||
119 | #define HOST_OHCICTRL_SUSPLGCY (0x1 << 3) | ||
120 | #define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2) | ||
121 | #define HOST_OHCICTRL_CNTSEL (0x1 << 1) | ||
122 | #define HOST_OHCICTRL_CLKCKTRST (0x1 << 0) | ||
123 | |||
124 | #define EXYNOS5_PHY_OTG_SYS (0x38) | ||
125 | |||
126 | #define OTG_SYS_PHYLINK_SWRESET (0x1 << 14) | ||
127 | #define OTG_SYS_LINKSWRST_UOTG (0x1 << 13) | ||
128 | #define OTG_SYS_PHY0_SWRST (0x1 << 12) | ||
129 | |||
130 | #define OTG_SYS_REFCLKSEL_MASK (0x3 << 9) | ||
131 | #define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9) | ||
132 | #define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9) | ||
133 | #define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9) | ||
134 | |||
135 | #define OTG_SYS_IDPULLUP_UOTG (0x1 << 8) | ||
136 | #define OTG_SYS_COMMON_ON (0x1 << 7) | ||
137 | |||
138 | #define OTG_SYS_FSEL_MASK (0x7 << 4) | ||
139 | #define OTG_SYS_FSEL(_x) ((_x) << 4) | ||
140 | |||
141 | #define OTG_SYS_FORCESLEEP (0x1 << 3) | ||
142 | #define OTG_SYS_OTGDISABLE (0x1 << 2) | ||
143 | #define OTG_SYS_SIDDQ_UOTG (0x1 << 1) | ||
144 | #define OTG_SYS_FORCESUSPEND (0x1 << 0) | ||
145 | |||
146 | #define EXYNOS5_PHY_OTG_TUNE (0x40) | ||
147 | |||
148 | /* EXYNOS5: USB 3.0 DRD */ | ||
149 | #define EXYNOS5_DRD_LINKSYSTEM (0x04) | ||
150 | |||
151 | #define LINKSYSTEM_FLADJ_MASK (0x3f << 1) | ||
152 | #define LINKSYSTEM_FLADJ(_x) ((_x) << 1) | ||
153 | #define LINKSYSTEM_XHCI_VERSION_CONTROL (0x1 << 27) | ||
154 | |||
155 | #define EXYNOS5_DRD_PHYUTMI (0x08) | ||
156 | |||
157 | #define PHYUTMI_OTGDISABLE (0x1 << 6) | ||
158 | #define PHYUTMI_FORCESUSPEND (0x1 << 1) | ||
159 | #define PHYUTMI_FORCESLEEP (0x1 << 0) | ||
160 | |||
161 | #define EXYNOS5_DRD_PHYPIPE (0x0c) | ||
162 | |||
163 | #define EXYNOS5_DRD_PHYCLKRST (0x10) | ||
164 | |||
165 | #define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23) | ||
166 | #define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23) | ||
167 | |||
168 | #define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21) | ||
169 | #define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21) | ||
170 | |||
171 | #define PHYCLKRST_SSC_EN (0x1 << 20) | ||
172 | #define PHYCLKRST_REF_SSP_EN (0x1 << 19) | ||
173 | #define PHYCLKRST_REF_CLKDIV2 (0x1 << 18) | ||
174 | |||
175 | #define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11) | ||
176 | #define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11) | ||
177 | #define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x02 << 11) | ||
178 | #define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11) | ||
179 | #define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11) | ||
180 | #define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11) | ||
181 | |||
182 | #define PHYCLKRST_FSEL_MASK (0x3f << 5) | ||
183 | #define PHYCLKRST_FSEL(_x) ((_x) << 5) | ||
184 | #define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5) | ||
185 | #define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5) | ||
186 | #define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5) | ||
187 | #define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5) | ||
188 | |||
189 | #define PHYCLKRST_RETENABLEN (0x1 << 4) | ||
190 | |||
191 | #define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2) | ||
192 | #define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2) | ||
193 | #define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2) | ||
194 | |||
195 | #define PHYCLKRST_PORTRESET (0x1 << 1) | ||
196 | #define PHYCLKRST_COMMONONN (0x1 << 0) | ||
197 | |||
198 | #define EXYNOS5_DRD_PHYREG0 (0x14) | ||
199 | #define EXYNOS5_DRD_PHYREG1 (0x18) | ||
200 | |||
201 | #define EXYNOS5_DRD_PHYPARAM0 (0x1c) | ||
202 | |||
203 | #define PHYPARAM0_REF_USE_PAD (0x1 << 31) | ||
204 | #define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26) | ||
205 | #define PHYPARAM0_REF_LOSLEVEL (0x9 << 26) | ||
206 | |||
207 | #define EXYNOS5_DRD_PHYPARAM1 (0x20) | ||
208 | |||
209 | #define PHYPARAM1_PCS_TXDEEMPH_MASK (0x1f << 0) | ||
210 | #define PHYPARAM1_PCS_TXDEEMPH (0x1c) | ||
211 | |||
212 | #define EXYNOS5_DRD_PHYTERM (0x24) | ||
213 | |||
214 | #define EXYNOS5_DRD_PHYTEST (0x28) | ||
215 | |||
216 | #define PHYTEST_POWERDOWN_SSP (0x1 << 3) | ||
217 | #define PHYTEST_POWERDOWN_HSP (0x1 << 2) | ||
218 | |||
219 | #define EXYNOS5_DRD_PHYADP (0x2c) | ||
220 | |||
221 | #define EXYNOS5_DRD_PHYBATCHG (0x30) | ||
222 | |||
223 | #define PHYBATCHG_UTMI_CLKSEL (0x1 << 2) | ||
224 | |||
225 | #define EXYNOS5_DRD_PHYRESUME (0x34) | ||
226 | #define EXYNOS5_DRD_LINKPORT (0x44) | ||
227 | |||
228 | #ifndef MHZ | ||
229 | #define MHZ (1000*1000) | ||
230 | #endif | ||
231 | |||
232 | #ifndef KHZ | ||
233 | #define KHZ (1000) | ||
234 | #endif | ||
235 | |||
236 | #define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4) | ||
237 | #define S3C64XX_USBPHY_ENABLE (0x1 << 16) | ||
238 | #define EXYNOS_USBPHY_ENABLE (0x1 << 0) | ||
239 | #define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0) | ||
240 | |||
241 | enum samsung_cpu_type { | ||
242 | TYPE_S3C64XX, | ||
243 | TYPE_EXYNOS4210, | ||
244 | TYPE_EXYNOS5250, | ||
245 | }; | ||
246 | |||
247 | /* | ||
248 | * struct samsung_usbphy_drvdata - driver data for various SoC variants | ||
249 | * @cpu_type: machine identifier | ||
250 | * @devphy_en_mask: device phy enable mask for PHY CONTROL register | ||
251 | * @hostphy_en_mask: host phy enable mask for PHY CONTROL register | ||
252 | * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from | ||
253 | * mapped address of system controller. | ||
254 | * @hostphy_reg_offset: offset to HOST PHY CONTROL register from | ||
255 | * mapped address of system controller. | ||
256 | * | ||
257 | * Here we have a separate mask for device type phy. | ||
258 | * Having different masks for host and device type phy helps | ||
259 | * in setting independent masks in case of SoCs like S5PV210, | ||
260 | * in which PHY0 and PHY1 enable bits belong to same register | ||
261 | * placed at position 0 and 1 respectively. | ||
262 | * Although for newer SoCs like exynos these bits belong to | ||
263 | * different registers altogether placed at position 0. | ||
264 | */ | ||
265 | struct samsung_usbphy_drvdata { | ||
266 | int cpu_type; | ||
267 | int devphy_en_mask; | ||
268 | int hostphy_en_mask; | ||
269 | u32 devphy_reg_offset; | ||
270 | u32 hostphy_reg_offset; | ||
271 | }; | ||
272 | |||
273 | /* | ||
274 | * struct samsung_usbphy - transceiver driver state | ||
275 | * @phy: transceiver structure | ||
276 | * @plat: platform data | ||
277 | * @dev: The parent device supplied to the probe function | ||
278 | * @clk: usb phy clock | ||
279 | * @regs: usb phy controller registers memory base | ||
280 | * @pmuregs: USB device PHY_CONTROL register memory base | ||
281 | * @sysreg: USB2.0 PHY_CFG register memory base | ||
282 | * @ref_clk_freq: reference clock frequency selection | ||
283 | * @drv_data: driver data available for different SoCs | ||
284 | * @phy_type: Samsung SoCs specific phy types: #HOST | ||
285 | * #DEVICE | ||
286 | * @phy_usage: usage count for phy | ||
287 | * @lock: lock for phy operations | ||
288 | */ | ||
289 | struct samsung_usbphy { | ||
290 | struct usb_phy phy; | ||
291 | struct samsung_usbphy_data *plat; | ||
292 | struct device *dev; | ||
293 | struct clk *clk; | ||
294 | void __iomem *regs; | ||
295 | void __iomem *pmuregs; | ||
296 | void __iomem *sysreg; | ||
297 | int ref_clk_freq; | ||
298 | const struct samsung_usbphy_drvdata *drv_data; | ||
299 | enum samsung_usb_phy_type phy_type; | ||
300 | atomic_t phy_usage; | ||
301 | spinlock_t lock; | ||
302 | }; | ||
303 | |||
304 | #define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy) | ||
305 | |||
306 | static const struct of_device_id samsung_usbphy_dt_match[]; | ||
307 | |||
308 | static inline const struct samsung_usbphy_drvdata | ||
309 | *samsung_usbphy_get_driver_data(struct platform_device *pdev) | ||
310 | { | ||
311 | if (pdev->dev.of_node) { | ||
312 | const struct of_device_id *match; | ||
313 | match = of_match_node(samsung_usbphy_dt_match, | ||
314 | pdev->dev.of_node); | ||
315 | return match->data; | ||
316 | } | ||
317 | |||
318 | return (struct samsung_usbphy_drvdata *) | ||
319 | platform_get_device_id(pdev)->driver_data; | ||
320 | } | ||
321 | |||
322 | extern int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy); | ||
323 | extern void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on); | ||
324 | extern void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy); | ||
325 | extern int samsung_usbphy_set_type(struct usb_phy *phy, | ||
326 | enum samsung_usb_phy_type phy_type); | ||
327 | extern int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c new file mode 100644 index 000000000000..45ffe036dacc --- /dev/null +++ b/drivers/usb/phy/phy-samsung-usb2.c | |||
@@ -0,0 +1,509 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb2.c | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Praveen Paneri <p.paneri@samsung.com> | ||
7 | * | ||
8 | * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and | ||
9 | * OHCI-EXYNOS controllers. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/clk.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/of.h> | ||
29 | #include <linux/usb/otg.h> | ||
30 | #include <linux/usb/samsung_usb_phy.h> | ||
31 | #include <linux/platform_data/samsung-usbphy.h> | ||
32 | |||
33 | #include "phy-samsung-usb.h" | ||
34 | |||
35 | static int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host) | ||
36 | { | ||
37 | if (!otg) | ||
38 | return -ENODEV; | ||
39 | |||
40 | if (!otg->host) | ||
41 | otg->host = host; | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static bool exynos5_phyhost_is_on(void __iomem *regs) | ||
47 | { | ||
48 | u32 reg; | ||
49 | |||
50 | reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
51 | |||
52 | return !(reg & HOST_CTRL0_SIDDQ); | ||
53 | } | ||
54 | |||
55 | static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy) | ||
56 | { | ||
57 | void __iomem *regs = sphy->regs; | ||
58 | u32 phyclk = sphy->ref_clk_freq; | ||
59 | u32 phyhost; | ||
60 | u32 phyotg; | ||
61 | u32 phyhsic; | ||
62 | u32 ehcictrl; | ||
63 | u32 ohcictrl; | ||
64 | |||
65 | /* | ||
66 | * phy_usage helps in keeping usage count for phy | ||
67 | * so that the first consumer enabling the phy is also | ||
68 | * the last consumer to disable it. | ||
69 | */ | ||
70 | |||
71 | atomic_inc(&sphy->phy_usage); | ||
72 | |||
73 | if (exynos5_phyhost_is_on(regs)) { | ||
74 | dev_info(sphy->dev, "Already power on PHY\n"); | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | /* Host configuration */ | ||
79 | phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
80 | |||
81 | /* phy reference clock configuration */ | ||
82 | phyhost &= ~HOST_CTRL0_FSEL_MASK; | ||
83 | phyhost |= HOST_CTRL0_FSEL(phyclk); | ||
84 | |||
85 | /* host phy reset */ | ||
86 | phyhost &= ~(HOST_CTRL0_PHYSWRST | | ||
87 | HOST_CTRL0_PHYSWRSTALL | | ||
88 | HOST_CTRL0_SIDDQ | | ||
89 | /* Enable normal mode of operation */ | ||
90 | HOST_CTRL0_FORCESUSPEND | | ||
91 | HOST_CTRL0_FORCESLEEP); | ||
92 | |||
93 | /* Link reset */ | ||
94 | phyhost |= (HOST_CTRL0_LINKSWRST | | ||
95 | HOST_CTRL0_UTMISWRST | | ||
96 | /* COMMON Block configuration during suspend */ | ||
97 | HOST_CTRL0_COMMONON_N); | ||
98 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
99 | udelay(10); | ||
100 | phyhost &= ~(HOST_CTRL0_LINKSWRST | | ||
101 | HOST_CTRL0_UTMISWRST); | ||
102 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
103 | |||
104 | /* OTG configuration */ | ||
105 | phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); | ||
106 | |||
107 | /* phy reference clock configuration */ | ||
108 | phyotg &= ~OTG_SYS_FSEL_MASK; | ||
109 | phyotg |= OTG_SYS_FSEL(phyclk); | ||
110 | |||
111 | /* Enable normal mode of operation */ | ||
112 | phyotg &= ~(OTG_SYS_FORCESUSPEND | | ||
113 | OTG_SYS_SIDDQ_UOTG | | ||
114 | OTG_SYS_FORCESLEEP | | ||
115 | OTG_SYS_REFCLKSEL_MASK | | ||
116 | /* COMMON Block configuration during suspend */ | ||
117 | OTG_SYS_COMMON_ON); | ||
118 | |||
119 | /* OTG phy & link reset */ | ||
120 | phyotg |= (OTG_SYS_PHY0_SWRST | | ||
121 | OTG_SYS_LINKSWRST_UOTG | | ||
122 | OTG_SYS_PHYLINK_SWRESET | | ||
123 | OTG_SYS_OTGDISABLE | | ||
124 | /* Set phy refclk */ | ||
125 | OTG_SYS_REFCLKSEL_CLKCORE); | ||
126 | |||
127 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
128 | udelay(10); | ||
129 | phyotg &= ~(OTG_SYS_PHY0_SWRST | | ||
130 | OTG_SYS_LINKSWRST_UOTG | | ||
131 | OTG_SYS_PHYLINK_SWRESET); | ||
132 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
133 | |||
134 | /* HSIC phy configuration */ | ||
135 | phyhsic = (HSIC_CTRL_REFCLKDIV_12 | | ||
136 | HSIC_CTRL_REFCLKSEL | | ||
137 | HSIC_CTRL_PHYSWRST); | ||
138 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
139 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
140 | udelay(10); | ||
141 | phyhsic &= ~HSIC_CTRL_PHYSWRST; | ||
142 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
143 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
144 | |||
145 | udelay(80); | ||
146 | |||
147 | /* enable EHCI DMA burst */ | ||
148 | ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL); | ||
149 | ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN | | ||
150 | HOST_EHCICTRL_ENAINCR4 | | ||
151 | HOST_EHCICTRL_ENAINCR8 | | ||
152 | HOST_EHCICTRL_ENAINCR16); | ||
153 | writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL); | ||
154 | |||
155 | /* set ohci_suspend_on_n */ | ||
156 | ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL); | ||
157 | ohcictrl |= HOST_OHCICTRL_SUSPLGCY; | ||
158 | writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL); | ||
159 | } | ||
160 | |||
161 | static void samsung_usb2phy_enable(struct samsung_usbphy *sphy) | ||
162 | { | ||
163 | void __iomem *regs = sphy->regs; | ||
164 | u32 phypwr; | ||
165 | u32 phyclk; | ||
166 | u32 rstcon; | ||
167 | |||
168 | /* set clock frequency for PLL */ | ||
169 | phyclk = sphy->ref_clk_freq; | ||
170 | phypwr = readl(regs + SAMSUNG_PHYPWR); | ||
171 | rstcon = readl(regs + SAMSUNG_RSTCON); | ||
172 | |||
173 | switch (sphy->drv_data->cpu_type) { | ||
174 | case TYPE_S3C64XX: | ||
175 | phyclk &= ~PHYCLK_COMMON_ON_N; | ||
176 | phypwr &= ~PHYPWR_NORMAL_MASK; | ||
177 | rstcon |= RSTCON_SWRST; | ||
178 | break; | ||
179 | case TYPE_EXYNOS4210: | ||
180 | phypwr &= ~PHYPWR_NORMAL_MASK_PHY0; | ||
181 | rstcon |= RSTCON_SWRST; | ||
182 | default: | ||
183 | break; | ||
184 | } | ||
185 | |||
186 | writel(phyclk, regs + SAMSUNG_PHYCLK); | ||
187 | /* Configure PHY0 for normal operation*/ | ||
188 | writel(phypwr, regs + SAMSUNG_PHYPWR); | ||
189 | /* reset all ports of PHY and Link */ | ||
190 | writel(rstcon, regs + SAMSUNG_RSTCON); | ||
191 | udelay(10); | ||
192 | rstcon &= ~RSTCON_SWRST; | ||
193 | writel(rstcon, regs + SAMSUNG_RSTCON); | ||
194 | } | ||
195 | |||
196 | static void samsung_exynos5_usb2phy_disable(struct samsung_usbphy *sphy) | ||
197 | { | ||
198 | void __iomem *regs = sphy->regs; | ||
199 | u32 phyhost; | ||
200 | u32 phyotg; | ||
201 | u32 phyhsic; | ||
202 | |||
203 | if (atomic_dec_return(&sphy->phy_usage) > 0) { | ||
204 | dev_info(sphy->dev, "still being used\n"); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | phyhsic = (HSIC_CTRL_REFCLKDIV_12 | | ||
209 | HSIC_CTRL_REFCLKSEL | | ||
210 | HSIC_CTRL_SIDDQ | | ||
211 | HSIC_CTRL_FORCESLEEP | | ||
212 | HSIC_CTRL_FORCESUSPEND); | ||
213 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
214 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
215 | |||
216 | phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
217 | phyhost |= (HOST_CTRL0_SIDDQ | | ||
218 | HOST_CTRL0_FORCESUSPEND | | ||
219 | HOST_CTRL0_FORCESLEEP | | ||
220 | HOST_CTRL0_PHYSWRST | | ||
221 | HOST_CTRL0_PHYSWRSTALL); | ||
222 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
223 | |||
224 | phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); | ||
225 | phyotg |= (OTG_SYS_FORCESUSPEND | | ||
226 | OTG_SYS_SIDDQ_UOTG | | ||
227 | OTG_SYS_FORCESLEEP); | ||
228 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
229 | } | ||
230 | |||
231 | static void samsung_usb2phy_disable(struct samsung_usbphy *sphy) | ||
232 | { | ||
233 | void __iomem *regs = sphy->regs; | ||
234 | u32 phypwr; | ||
235 | |||
236 | phypwr = readl(regs + SAMSUNG_PHYPWR); | ||
237 | |||
238 | switch (sphy->drv_data->cpu_type) { | ||
239 | case TYPE_S3C64XX: | ||
240 | phypwr |= PHYPWR_NORMAL_MASK; | ||
241 | break; | ||
242 | case TYPE_EXYNOS4210: | ||
243 | phypwr |= PHYPWR_NORMAL_MASK_PHY0; | ||
244 | default: | ||
245 | break; | ||
246 | } | ||
247 | |||
248 | /* Disable analog and otg block power */ | ||
249 | writel(phypwr, regs + SAMSUNG_PHYPWR); | ||
250 | } | ||
251 | |||
252 | /* | ||
253 | * The function passed to the usb driver for phy initialization | ||
254 | */ | ||
255 | static int samsung_usb2phy_init(struct usb_phy *phy) | ||
256 | { | ||
257 | struct samsung_usbphy *sphy; | ||
258 | struct usb_bus *host = NULL; | ||
259 | unsigned long flags; | ||
260 | int ret = 0; | ||
261 | |||
262 | sphy = phy_to_sphy(phy); | ||
263 | |||
264 | host = phy->otg->host; | ||
265 | |||
266 | /* Enable the phy clock */ | ||
267 | ret = clk_prepare_enable(sphy->clk); | ||
268 | if (ret) { | ||
269 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
270 | return ret; | ||
271 | } | ||
272 | |||
273 | spin_lock_irqsave(&sphy->lock, flags); | ||
274 | |||
275 | if (host) { | ||
276 | /* setting default phy-type for USB 2.0 */ | ||
277 | if (!strstr(dev_name(host->controller), "ehci") || | ||
278 | !strstr(dev_name(host->controller), "ohci")) | ||
279 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); | ||
280 | } else { | ||
281 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
282 | } | ||
283 | |||
284 | /* Disable phy isolation */ | ||
285 | if (sphy->plat && sphy->plat->pmu_isolation) | ||
286 | sphy->plat->pmu_isolation(false); | ||
287 | else | ||
288 | samsung_usbphy_set_isolation(sphy, false); | ||
289 | |||
290 | /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */ | ||
291 | samsung_usbphy_cfg_sel(sphy); | ||
292 | |||
293 | /* Initialize usb phy registers */ | ||
294 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
295 | samsung_exynos5_usb2phy_enable(sphy); | ||
296 | else | ||
297 | samsung_usb2phy_enable(sphy); | ||
298 | |||
299 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
300 | |||
301 | /* Disable the phy clock */ | ||
302 | clk_disable_unprepare(sphy->clk); | ||
303 | |||
304 | return ret; | ||
305 | } | ||
306 | |||
307 | /* | ||
308 | * The function passed to the usb driver for phy shutdown | ||
309 | */ | ||
310 | static void samsung_usb2phy_shutdown(struct usb_phy *phy) | ||
311 | { | ||
312 | struct samsung_usbphy *sphy; | ||
313 | struct usb_bus *host = NULL; | ||
314 | unsigned long flags; | ||
315 | |||
316 | sphy = phy_to_sphy(phy); | ||
317 | |||
318 | host = phy->otg->host; | ||
319 | |||
320 | if (clk_prepare_enable(sphy->clk)) { | ||
321 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
322 | return; | ||
323 | } | ||
324 | |||
325 | spin_lock_irqsave(&sphy->lock, flags); | ||
326 | |||
327 | if (host) { | ||
328 | /* setting default phy-type for USB 2.0 */ | ||
329 | if (!strstr(dev_name(host->controller), "ehci") || | ||
330 | !strstr(dev_name(host->controller), "ohci")) | ||
331 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); | ||
332 | } else { | ||
333 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
334 | } | ||
335 | |||
336 | /* De-initialize usb phy registers */ | ||
337 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
338 | samsung_exynos5_usb2phy_disable(sphy); | ||
339 | else | ||
340 | samsung_usb2phy_disable(sphy); | ||
341 | |||
342 | /* Enable phy isolation */ | ||
343 | if (sphy->plat && sphy->plat->pmu_isolation) | ||
344 | sphy->plat->pmu_isolation(true); | ||
345 | else | ||
346 | samsung_usbphy_set_isolation(sphy, true); | ||
347 | |||
348 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
349 | |||
350 | clk_disable_unprepare(sphy->clk); | ||
351 | } | ||
352 | |||
353 | static int samsung_usb2phy_probe(struct platform_device *pdev) | ||
354 | { | ||
355 | struct samsung_usbphy *sphy; | ||
356 | struct usb_otg *otg; | ||
357 | struct samsung_usbphy_data *pdata = pdev->dev.platform_data; | ||
358 | const struct samsung_usbphy_drvdata *drv_data; | ||
359 | struct device *dev = &pdev->dev; | ||
360 | struct resource *phy_mem; | ||
361 | void __iomem *phy_base; | ||
362 | struct clk *clk; | ||
363 | int ret; | ||
364 | |||
365 | phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
366 | if (!phy_mem) { | ||
367 | dev_err(dev, "%s: missing mem resource\n", __func__); | ||
368 | return -ENODEV; | ||
369 | } | ||
370 | |||
371 | phy_base = devm_ioremap_resource(dev, phy_mem); | ||
372 | if (IS_ERR(phy_base)) | ||
373 | return PTR_ERR(phy_base); | ||
374 | |||
375 | sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); | ||
376 | if (!sphy) | ||
377 | return -ENOMEM; | ||
378 | |||
379 | otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL); | ||
380 | if (!otg) | ||
381 | return -ENOMEM; | ||
382 | |||
383 | drv_data = samsung_usbphy_get_driver_data(pdev); | ||
384 | |||
385 | if (drv_data->cpu_type == TYPE_EXYNOS5250) | ||
386 | clk = devm_clk_get(dev, "usbhost"); | ||
387 | else | ||
388 | clk = devm_clk_get(dev, "otg"); | ||
389 | |||
390 | if (IS_ERR(clk)) { | ||
391 | dev_err(dev, "Failed to get otg clock\n"); | ||
392 | return PTR_ERR(clk); | ||
393 | } | ||
394 | |||
395 | sphy->dev = dev; | ||
396 | |||
397 | if (dev->of_node) { | ||
398 | ret = samsung_usbphy_parse_dt(sphy); | ||
399 | if (ret < 0) | ||
400 | return ret; | ||
401 | } else { | ||
402 | if (!pdata) { | ||
403 | dev_err(dev, "no platform data specified\n"); | ||
404 | return -EINVAL; | ||
405 | } | ||
406 | } | ||
407 | |||
408 | sphy->plat = pdata; | ||
409 | sphy->regs = phy_base; | ||
410 | sphy->clk = clk; | ||
411 | sphy->drv_data = drv_data; | ||
412 | sphy->phy.dev = sphy->dev; | ||
413 | sphy->phy.label = "samsung-usb2phy"; | ||
414 | sphy->phy.init = samsung_usb2phy_init; | ||
415 | sphy->phy.shutdown = samsung_usb2phy_shutdown; | ||
416 | sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); | ||
417 | |||
418 | sphy->phy.otg = otg; | ||
419 | sphy->phy.otg->phy = &sphy->phy; | ||
420 | sphy->phy.otg->set_host = samsung_usbphy_set_host; | ||
421 | |||
422 | spin_lock_init(&sphy->lock); | ||
423 | |||
424 | platform_set_drvdata(pdev, sphy); | ||
425 | |||
426 | return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2); | ||
427 | } | ||
428 | |||
429 | static int samsung_usb2phy_remove(struct platform_device *pdev) | ||
430 | { | ||
431 | struct samsung_usbphy *sphy = platform_get_drvdata(pdev); | ||
432 | |||
433 | usb_remove_phy(&sphy->phy); | ||
434 | |||
435 | if (sphy->pmuregs) | ||
436 | iounmap(sphy->pmuregs); | ||
437 | if (sphy->sysreg) | ||
438 | iounmap(sphy->sysreg); | ||
439 | |||
440 | return 0; | ||
441 | } | ||
442 | |||
443 | static const struct samsung_usbphy_drvdata usb2phy_s3c64xx = { | ||
444 | .cpu_type = TYPE_S3C64XX, | ||
445 | .devphy_en_mask = S3C64XX_USBPHY_ENABLE, | ||
446 | }; | ||
447 | |||
448 | static const struct samsung_usbphy_drvdata usb2phy_exynos4 = { | ||
449 | .cpu_type = TYPE_EXYNOS4210, | ||
450 | .devphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
451 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
452 | }; | ||
453 | |||
454 | static struct samsung_usbphy_drvdata usb2phy_exynos5 = { | ||
455 | .cpu_type = TYPE_EXYNOS5250, | ||
456 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
457 | .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET, | ||
458 | }; | ||
459 | |||
460 | #ifdef CONFIG_OF | ||
461 | static const struct of_device_id samsung_usbphy_dt_match[] = { | ||
462 | { | ||
463 | .compatible = "samsung,s3c64xx-usb2phy", | ||
464 | .data = &usb2phy_s3c64xx, | ||
465 | }, { | ||
466 | .compatible = "samsung,exynos4210-usb2phy", | ||
467 | .data = &usb2phy_exynos4, | ||
468 | }, { | ||
469 | .compatible = "samsung,exynos5250-usb2phy", | ||
470 | .data = &usb2phy_exynos5 | ||
471 | }, | ||
472 | {}, | ||
473 | }; | ||
474 | MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); | ||
475 | #endif | ||
476 | |||
477 | static struct platform_device_id samsung_usbphy_driver_ids[] = { | ||
478 | { | ||
479 | .name = "s3c64xx-usb2phy", | ||
480 | .driver_data = (unsigned long)&usb2phy_s3c64xx, | ||
481 | }, { | ||
482 | .name = "exynos4210-usb2phy", | ||
483 | .driver_data = (unsigned long)&usb2phy_exynos4, | ||
484 | }, { | ||
485 | .name = "exynos5250-usb2phy", | ||
486 | .driver_data = (unsigned long)&usb2phy_exynos5, | ||
487 | }, | ||
488 | {}, | ||
489 | }; | ||
490 | |||
491 | MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); | ||
492 | |||
493 | static struct platform_driver samsung_usb2phy_driver = { | ||
494 | .probe = samsung_usb2phy_probe, | ||
495 | .remove = samsung_usb2phy_remove, | ||
496 | .id_table = samsung_usbphy_driver_ids, | ||
497 | .driver = { | ||
498 | .name = "samsung-usb2phy", | ||
499 | .owner = THIS_MODULE, | ||
500 | .of_match_table = of_match_ptr(samsung_usbphy_dt_match), | ||
501 | }, | ||
502 | }; | ||
503 | |||
504 | module_platform_driver(samsung_usb2phy_driver); | ||
505 | |||
506 | MODULE_DESCRIPTION("Samsung USB 2.0 phy controller"); | ||
507 | MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>"); | ||
508 | MODULE_LICENSE("GPL"); | ||
509 | MODULE_ALIAS("platform:samsung-usb2phy"); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c new file mode 100644 index 000000000000..133f3d0c554f --- /dev/null +++ b/drivers/usb/phy/phy-samsung-usb3.c | |||
@@ -0,0 +1,347 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb3.c | ||
2 | * | ||
3 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Vivek Gautam <gautam.vivek@samsung.com> | ||
7 | * | ||
8 | * Samsung USB 3.0 PHY transceiver; talks to DWC3 controller. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/clk.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/err.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/of.h> | ||
27 | #include <linux/usb/samsung_usb_phy.h> | ||
28 | #include <linux/platform_data/samsung-usbphy.h> | ||
29 | |||
30 | #include "phy-samsung-usb.h" | ||
31 | |||
32 | /* | ||
33 | * Sets the phy clk as EXTREFCLK (XXTI) which is internal clock from clock core. | ||
34 | */ | ||
35 | static u32 samsung_usb3phy_set_refclk(struct samsung_usbphy *sphy) | ||
36 | { | ||
37 | u32 reg; | ||
38 | u32 refclk; | ||
39 | |||
40 | refclk = sphy->ref_clk_freq; | ||
41 | |||
42 | reg = PHYCLKRST_REFCLKSEL_EXT_REFCLK | | ||
43 | PHYCLKRST_FSEL(refclk); | ||
44 | |||
45 | switch (refclk) { | ||
46 | case FSEL_CLKSEL_50M: | ||
47 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF | | ||
48 | PHYCLKRST_SSC_REFCLKSEL(0x00)); | ||
49 | break; | ||
50 | case FSEL_CLKSEL_20M: | ||
51 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF | | ||
52 | PHYCLKRST_SSC_REFCLKSEL(0x00)); | ||
53 | break; | ||
54 | case FSEL_CLKSEL_19200K: | ||
55 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF | | ||
56 | PHYCLKRST_SSC_REFCLKSEL(0x88)); | ||
57 | break; | ||
58 | case FSEL_CLKSEL_24M: | ||
59 | default: | ||
60 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF | | ||
61 | PHYCLKRST_SSC_REFCLKSEL(0x88)); | ||
62 | break; | ||
63 | } | ||
64 | |||
65 | return reg; | ||
66 | } | ||
67 | |||
68 | static int samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy) | ||
69 | { | ||
70 | void __iomem *regs = sphy->regs; | ||
71 | u32 phyparam0; | ||
72 | u32 phyparam1; | ||
73 | u32 linksystem; | ||
74 | u32 phybatchg; | ||
75 | u32 phytest; | ||
76 | u32 phyclkrst; | ||
77 | |||
78 | /* Reset USB 3.0 PHY */ | ||
79 | writel(0x0, regs + EXYNOS5_DRD_PHYREG0); | ||
80 | |||
81 | phyparam0 = readl(regs + EXYNOS5_DRD_PHYPARAM0); | ||
82 | /* Select PHY CLK source */ | ||
83 | phyparam0 &= ~PHYPARAM0_REF_USE_PAD; | ||
84 | /* Set Loss-of-Signal Detector sensitivity */ | ||
85 | phyparam0 &= ~PHYPARAM0_REF_LOSLEVEL_MASK; | ||
86 | phyparam0 |= PHYPARAM0_REF_LOSLEVEL; | ||
87 | writel(phyparam0, regs + EXYNOS5_DRD_PHYPARAM0); | ||
88 | |||
89 | writel(0x0, regs + EXYNOS5_DRD_PHYRESUME); | ||
90 | |||
91 | /* | ||
92 | * Setting the Frame length Adj value[6:1] to default 0x20 | ||
93 | * See xHCI 1.0 spec, 5.2.4 | ||
94 | */ | ||
95 | linksystem = LINKSYSTEM_XHCI_VERSION_CONTROL | | ||
96 | LINKSYSTEM_FLADJ(0x20); | ||
97 | writel(linksystem, regs + EXYNOS5_DRD_LINKSYSTEM); | ||
98 | |||
99 | phyparam1 = readl(regs + EXYNOS5_DRD_PHYPARAM1); | ||
100 | /* Set Tx De-Emphasis level */ | ||
101 | phyparam1 &= ~PHYPARAM1_PCS_TXDEEMPH_MASK; | ||
102 | phyparam1 |= PHYPARAM1_PCS_TXDEEMPH; | ||
103 | writel(phyparam1, regs + EXYNOS5_DRD_PHYPARAM1); | ||
104 | |||
105 | phybatchg = readl(regs + EXYNOS5_DRD_PHYBATCHG); | ||
106 | phybatchg |= PHYBATCHG_UTMI_CLKSEL; | ||
107 | writel(phybatchg, regs + EXYNOS5_DRD_PHYBATCHG); | ||
108 | |||
109 | /* PHYTEST POWERDOWN Control */ | ||
110 | phytest = readl(regs + EXYNOS5_DRD_PHYTEST); | ||
111 | phytest &= ~(PHYTEST_POWERDOWN_SSP | | ||
112 | PHYTEST_POWERDOWN_HSP); | ||
113 | writel(phytest, regs + EXYNOS5_DRD_PHYTEST); | ||
114 | |||
115 | /* UTMI Power Control */ | ||
116 | writel(PHYUTMI_OTGDISABLE, regs + EXYNOS5_DRD_PHYUTMI); | ||
117 | |||
118 | phyclkrst = samsung_usb3phy_set_refclk(sphy); | ||
119 | |||
120 | phyclkrst |= PHYCLKRST_PORTRESET | | ||
121 | /* Digital power supply in normal operating mode */ | ||
122 | PHYCLKRST_RETENABLEN | | ||
123 | /* Enable ref clock for SS function */ | ||
124 | PHYCLKRST_REF_SSP_EN | | ||
125 | /* Enable spread spectrum */ | ||
126 | PHYCLKRST_SSC_EN | | ||
127 | /* Power down HS Bias and PLL blocks in suspend mode */ | ||
128 | PHYCLKRST_COMMONONN; | ||
129 | |||
130 | writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); | ||
131 | |||
132 | udelay(10); | ||
133 | |||
134 | phyclkrst &= ~(PHYCLKRST_PORTRESET); | ||
135 | writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); | ||
136 | |||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static void samsung_exynos5_usb3phy_disable(struct samsung_usbphy *sphy) | ||
141 | { | ||
142 | u32 phyutmi; | ||
143 | u32 phyclkrst; | ||
144 | u32 phytest; | ||
145 | void __iomem *regs = sphy->regs; | ||
146 | |||
147 | phyutmi = PHYUTMI_OTGDISABLE | | ||
148 | PHYUTMI_FORCESUSPEND | | ||
149 | PHYUTMI_FORCESLEEP; | ||
150 | writel(phyutmi, regs + EXYNOS5_DRD_PHYUTMI); | ||
151 | |||
152 | /* Resetting the PHYCLKRST enable bits to reduce leakage current */ | ||
153 | phyclkrst = readl(regs + EXYNOS5_DRD_PHYCLKRST); | ||
154 | phyclkrst &= ~(PHYCLKRST_REF_SSP_EN | | ||
155 | PHYCLKRST_SSC_EN | | ||
156 | PHYCLKRST_COMMONONN); | ||
157 | writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); | ||
158 | |||
159 | /* Control PHYTEST to remove leakage current */ | ||
160 | phytest = readl(regs + EXYNOS5_DRD_PHYTEST); | ||
161 | phytest |= (PHYTEST_POWERDOWN_SSP | | ||
162 | PHYTEST_POWERDOWN_HSP); | ||
163 | writel(phytest, regs + EXYNOS5_DRD_PHYTEST); | ||
164 | } | ||
165 | |||
166 | static int samsung_usb3phy_init(struct usb_phy *phy) | ||
167 | { | ||
168 | struct samsung_usbphy *sphy; | ||
169 | unsigned long flags; | ||
170 | int ret = 0; | ||
171 | |||
172 | sphy = phy_to_sphy(phy); | ||
173 | |||
174 | /* Enable the phy clock */ | ||
175 | ret = clk_prepare_enable(sphy->clk); | ||
176 | if (ret) { | ||
177 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
178 | return ret; | ||
179 | } | ||
180 | |||
181 | spin_lock_irqsave(&sphy->lock, flags); | ||
182 | |||
183 | /* setting default phy-type for USB 3.0 */ | ||
184 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
185 | |||
186 | /* Disable phy isolation */ | ||
187 | samsung_usbphy_set_isolation(sphy, false); | ||
188 | |||
189 | /* Initialize usb phy registers */ | ||
190 | samsung_exynos5_usb3phy_enable(sphy); | ||
191 | |||
192 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
193 | |||
194 | /* Disable the phy clock */ | ||
195 | clk_disable_unprepare(sphy->clk); | ||
196 | |||
197 | return ret; | ||
198 | } | ||
199 | |||
200 | /* | ||
201 | * The function passed to the usb driver for phy shutdown | ||
202 | */ | ||
203 | static void samsung_usb3phy_shutdown(struct usb_phy *phy) | ||
204 | { | ||
205 | struct samsung_usbphy *sphy; | ||
206 | unsigned long flags; | ||
207 | |||
208 | sphy = phy_to_sphy(phy); | ||
209 | |||
210 | if (clk_prepare_enable(sphy->clk)) { | ||
211 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
212 | return; | ||
213 | } | ||
214 | |||
215 | spin_lock_irqsave(&sphy->lock, flags); | ||
216 | |||
217 | /* setting default phy-type for USB 3.0 */ | ||
218 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
219 | |||
220 | /* De-initialize usb phy registers */ | ||
221 | samsung_exynos5_usb3phy_disable(sphy); | ||
222 | |||
223 | /* Enable phy isolation */ | ||
224 | samsung_usbphy_set_isolation(sphy, true); | ||
225 | |||
226 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
227 | |||
228 | clk_disable_unprepare(sphy->clk); | ||
229 | } | ||
230 | |||
231 | static int samsung_usb3phy_probe(struct platform_device *pdev) | ||
232 | { | ||
233 | struct samsung_usbphy *sphy; | ||
234 | struct samsung_usbphy_data *pdata = pdev->dev.platform_data; | ||
235 | struct device *dev = &pdev->dev; | ||
236 | struct resource *phy_mem; | ||
237 | void __iomem *phy_base; | ||
238 | struct clk *clk; | ||
239 | int ret; | ||
240 | |||
241 | phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
242 | if (!phy_mem) { | ||
243 | dev_err(dev, "%s: missing mem resource\n", __func__); | ||
244 | return -ENODEV; | ||
245 | } | ||
246 | |||
247 | phy_base = devm_ioremap_resource(dev, phy_mem); | ||
248 | if (IS_ERR(phy_base)) | ||
249 | return PTR_ERR(phy_base); | ||
250 | |||
251 | sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); | ||
252 | if (!sphy) | ||
253 | return -ENOMEM; | ||
254 | |||
255 | clk = devm_clk_get(dev, "usbdrd30"); | ||
256 | if (IS_ERR(clk)) { | ||
257 | dev_err(dev, "Failed to get device clock\n"); | ||
258 | return PTR_ERR(clk); | ||
259 | } | ||
260 | |||
261 | sphy->dev = dev; | ||
262 | |||
263 | if (dev->of_node) { | ||
264 | ret = samsung_usbphy_parse_dt(sphy); | ||
265 | if (ret < 0) | ||
266 | return ret; | ||
267 | } else { | ||
268 | if (!pdata) { | ||
269 | dev_err(dev, "no platform data specified\n"); | ||
270 | return -EINVAL; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | sphy->plat = pdata; | ||
275 | sphy->regs = phy_base; | ||
276 | sphy->clk = clk; | ||
277 | sphy->phy.dev = sphy->dev; | ||
278 | sphy->phy.label = "samsung-usb3phy"; | ||
279 | sphy->phy.init = samsung_usb3phy_init; | ||
280 | sphy->phy.shutdown = samsung_usb3phy_shutdown; | ||
281 | sphy->drv_data = samsung_usbphy_get_driver_data(pdev); | ||
282 | sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); | ||
283 | |||
284 | spin_lock_init(&sphy->lock); | ||
285 | |||
286 | platform_set_drvdata(pdev, sphy); | ||
287 | |||
288 | return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB3); | ||
289 | } | ||
290 | |||
291 | static int samsung_usb3phy_remove(struct platform_device *pdev) | ||
292 | { | ||
293 | struct samsung_usbphy *sphy = platform_get_drvdata(pdev); | ||
294 | |||
295 | usb_remove_phy(&sphy->phy); | ||
296 | |||
297 | if (sphy->pmuregs) | ||
298 | iounmap(sphy->pmuregs); | ||
299 | if (sphy->sysreg) | ||
300 | iounmap(sphy->sysreg); | ||
301 | |||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | static struct samsung_usbphy_drvdata usb3phy_exynos5 = { | ||
306 | .cpu_type = TYPE_EXYNOS5250, | ||
307 | .devphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
308 | }; | ||
309 | |||
310 | #ifdef CONFIG_OF | ||
311 | static const struct of_device_id samsung_usbphy_dt_match[] = { | ||
312 | { | ||
313 | .compatible = "samsung,exynos5250-usb3phy", | ||
314 | .data = &usb3phy_exynos5 | ||
315 | }, | ||
316 | {}, | ||
317 | }; | ||
318 | MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); | ||
319 | #endif | ||
320 | |||
321 | static struct platform_device_id samsung_usbphy_driver_ids[] = { | ||
322 | { | ||
323 | .name = "exynos5250-usb3phy", | ||
324 | .driver_data = (unsigned long)&usb3phy_exynos5, | ||
325 | }, | ||
326 | {}, | ||
327 | }; | ||
328 | |||
329 | MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); | ||
330 | |||
331 | static struct platform_driver samsung_usb3phy_driver = { | ||
332 | .probe = samsung_usb3phy_probe, | ||
333 | .remove = samsung_usb3phy_remove, | ||
334 | .id_table = samsung_usbphy_driver_ids, | ||
335 | .driver = { | ||
336 | .name = "samsung-usb3phy", | ||
337 | .owner = THIS_MODULE, | ||
338 | .of_match_table = of_match_ptr(samsung_usbphy_dt_match), | ||
339 | }, | ||
340 | }; | ||
341 | |||
342 | module_platform_driver(samsung_usb3phy_driver); | ||
343 | |||
344 | MODULE_DESCRIPTION("Samsung USB 3.0 phy controller"); | ||
345 | MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>"); | ||
346 | MODULE_LICENSE("GPL"); | ||
347 | MODULE_ALIAS("platform:samsung-usb3phy"); | ||
diff --git a/drivers/usb/phy/tegra_usb_phy.c b/drivers/usb/phy/phy-tegra-usb.c index 5487d38481af..5487d38481af 100644 --- a/drivers/usb/phy/tegra_usb_phy.c +++ b/drivers/usb/phy/phy-tegra-usb.c | |||
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c index 24d573a134b1..8f78d2d40722 100644 --- a/drivers/usb/otg/twl4030-usb.c +++ b/drivers/usb/phy/phy-twl4030-usb.c | |||
@@ -163,6 +163,8 @@ struct twl4030_usb { | |||
163 | bool vbus_supplied; | 163 | bool vbus_supplied; |
164 | u8 asleep; | 164 | u8 asleep; |
165 | bool irq_enabled; | 165 | bool irq_enabled; |
166 | |||
167 | struct delayed_work id_workaround_work; | ||
166 | }; | 168 | }; |
167 | 169 | ||
168 | /* internal define on top of container_of */ | 170 | /* internal define on top of container_of */ |
@@ -246,6 +248,25 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) | |||
246 | 248 | ||
247 | /*-------------------------------------------------------------------------*/ | 249 | /*-------------------------------------------------------------------------*/ |
248 | 250 | ||
251 | static bool twl4030_is_driving_vbus(struct twl4030_usb *twl) | ||
252 | { | ||
253 | int ret; | ||
254 | |||
255 | ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS); | ||
256 | if (ret < 0 || !(ret & PHY_DPLL_CLK)) | ||
257 | /* | ||
258 | * if clocks are off, registers are not updated, | ||
259 | * but we can assume we don't drive VBUS in this case | ||
260 | */ | ||
261 | return false; | ||
262 | |||
263 | ret = twl4030_usb_read(twl, ULPI_OTG_CTRL); | ||
264 | if (ret < 0) | ||
265 | return false; | ||
266 | |||
267 | return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false; | ||
268 | } | ||
269 | |||
249 | static enum omap_musb_vbus_id_status | 270 | static enum omap_musb_vbus_id_status |
250 | twl4030_usb_linkstat(struct twl4030_usb *twl) | 271 | twl4030_usb_linkstat(struct twl4030_usb *twl) |
251 | { | 272 | { |
@@ -268,13 +289,19 @@ static enum omap_musb_vbus_id_status | |||
268 | if (status < 0) | 289 | if (status < 0) |
269 | dev_err(twl->dev, "USB link status err %d\n", status); | 290 | dev_err(twl->dev, "USB link status err %d\n", status); |
270 | else if (status & (BIT(7) | BIT(2))) { | 291 | else if (status & (BIT(7) | BIT(2))) { |
271 | if (status & (BIT(7))) | 292 | if (status & BIT(7)) { |
272 | twl->vbus_supplied = true; | 293 | if (twl4030_is_driving_vbus(twl)) |
294 | status &= ~BIT(7); | ||
295 | else | ||
296 | twl->vbus_supplied = true; | ||
297 | } | ||
273 | 298 | ||
274 | if (status & BIT(2)) | 299 | if (status & BIT(2)) |
275 | linkstat = OMAP_MUSB_ID_GROUND; | 300 | linkstat = OMAP_MUSB_ID_GROUND; |
276 | else | 301 | else if (status & BIT(7)) |
277 | linkstat = OMAP_MUSB_VBUS_VALID; | 302 | linkstat = OMAP_MUSB_VBUS_VALID; |
303 | else | ||
304 | linkstat = OMAP_MUSB_VBUS_OFF; | ||
278 | } else { | 305 | } else { |
279 | if (twl->linkstat != OMAP_MUSB_UNKNOWN) | 306 | if (twl->linkstat != OMAP_MUSB_UNKNOWN) |
280 | linkstat = OMAP_MUSB_VBUS_OFF; | 307 | linkstat = OMAP_MUSB_VBUS_OFF; |
@@ -287,10 +314,6 @@ static enum omap_musb_vbus_id_status | |||
287 | * are registered, and that both are active... | 314 | * are registered, and that both are active... |
288 | */ | 315 | */ |
289 | 316 | ||
290 | spin_lock_irq(&twl->lock); | ||
291 | twl->linkstat = linkstat; | ||
292 | spin_unlock_irq(&twl->lock); | ||
293 | |||
294 | return linkstat; | 317 | return linkstat; |
295 | } | 318 | } |
296 | 319 | ||
@@ -361,9 +384,17 @@ static void __twl4030_phy_power(struct twl4030_usb *twl, int on) | |||
361 | 384 | ||
362 | static void twl4030_phy_power(struct twl4030_usb *twl, int on) | 385 | static void twl4030_phy_power(struct twl4030_usb *twl, int on) |
363 | { | 386 | { |
387 | int ret; | ||
388 | |||
364 | if (on) { | 389 | if (on) { |
365 | regulator_enable(twl->usb3v1); | 390 | ret = regulator_enable(twl->usb3v1); |
366 | regulator_enable(twl->usb1v8); | 391 | if (ret) |
392 | dev_err(twl->dev, "Failed to enable usb3v1\n"); | ||
393 | |||
394 | ret = regulator_enable(twl->usb1v8); | ||
395 | if (ret) | ||
396 | dev_err(twl->dev, "Failed to enable usb1v8\n"); | ||
397 | |||
367 | /* | 398 | /* |
368 | * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP | 399 | * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP |
369 | * in twl4030) resets the VUSB_DEDICATED2 register. This reset | 400 | * in twl4030) resets the VUSB_DEDICATED2 register. This reset |
@@ -372,7 +403,11 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on) | |||
372 | * is re-activated. This ensures that VUSB3V1 is really active. | 403 | * is re-activated. This ensures that VUSB3V1 is really active. |
373 | */ | 404 | */ |
374 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); | 405 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); |
375 | regulator_enable(twl->usb1v5); | 406 | |
407 | ret = regulator_enable(twl->usb1v5); | ||
408 | if (ret) | ||
409 | dev_err(twl->dev, "Failed to enable usb1v5\n"); | ||
410 | |||
376 | __twl4030_phy_power(twl, 1); | 411 | __twl4030_phy_power(twl, 1); |
377 | twl4030_usb_write(twl, PHY_CLK_CTRL, | 412 | twl4030_usb_write(twl, PHY_CLK_CTRL, |
378 | twl4030_usb_read(twl, PHY_CLK_CTRL) | | 413 | twl4030_usb_read(twl, PHY_CLK_CTRL) | |
@@ -412,6 +447,16 @@ static void twl4030_phy_resume(struct twl4030_usb *twl) | |||
412 | __twl4030_phy_resume(twl); | 447 | __twl4030_phy_resume(twl); |
413 | twl->asleep = 0; | 448 | twl->asleep = 0; |
414 | dev_dbg(twl->dev, "%s\n", __func__); | 449 | dev_dbg(twl->dev, "%s\n", __func__); |
450 | |||
451 | /* | ||
452 | * XXX When VBUS gets driven after musb goes to A mode, | ||
453 | * ID_PRES related interrupts no longer arrive, why? | ||
454 | * Register itself is updated fine though, so we must poll. | ||
455 | */ | ||
456 | if (twl->linkstat == OMAP_MUSB_ID_GROUND) { | ||
457 | cancel_delayed_work(&twl->id_workaround_work); | ||
458 | schedule_delayed_work(&twl->id_workaround_work, HZ); | ||
459 | } | ||
415 | } | 460 | } |
416 | 461 | ||
417 | static int twl4030_usb_ldo_init(struct twl4030_usb *twl) | 462 | static int twl4030_usb_ldo_init(struct twl4030_usb *twl) |
@@ -432,7 +477,7 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl) | |||
432 | /* Initialize 3.1V regulator */ | 477 | /* Initialize 3.1V regulator */ |
433 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP); | 478 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP); |
434 | 479 | ||
435 | twl->usb3v1 = regulator_get(twl->dev, "usb3v1"); | 480 | twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1"); |
436 | if (IS_ERR(twl->usb3v1)) | 481 | if (IS_ERR(twl->usb3v1)) |
437 | return -ENODEV; | 482 | return -ENODEV; |
438 | 483 | ||
@@ -441,18 +486,18 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl) | |||
441 | /* Initialize 1.5V regulator */ | 486 | /* Initialize 1.5V regulator */ |
442 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP); | 487 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP); |
443 | 488 | ||
444 | twl->usb1v5 = regulator_get(twl->dev, "usb1v5"); | 489 | twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5"); |
445 | if (IS_ERR(twl->usb1v5)) | 490 | if (IS_ERR(twl->usb1v5)) |
446 | goto fail1; | 491 | return -ENODEV; |
447 | 492 | ||
448 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); | 493 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); |
449 | 494 | ||
450 | /* Initialize 1.8V regulator */ | 495 | /* Initialize 1.8V regulator */ |
451 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP); | 496 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP); |
452 | 497 | ||
453 | twl->usb1v8 = regulator_get(twl->dev, "usb1v8"); | 498 | twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8"); |
454 | if (IS_ERR(twl->usb1v8)) | 499 | if (IS_ERR(twl->usb1v8)) |
455 | goto fail2; | 500 | return -ENODEV; |
456 | 501 | ||
457 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); | 502 | twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); |
458 | 503 | ||
@@ -461,14 +506,6 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl) | |||
461 | TWL4030_PM_MASTER_PROTECT_KEY); | 506 | TWL4030_PM_MASTER_PROTECT_KEY); |
462 | 507 | ||
463 | return 0; | 508 | return 0; |
464 | |||
465 | fail2: | ||
466 | regulator_put(twl->usb1v5); | ||
467 | twl->usb1v5 = NULL; | ||
468 | fail1: | ||
469 | regulator_put(twl->usb3v1); | ||
470 | twl->usb3v1 = NULL; | ||
471 | return -ENODEV; | ||
472 | } | 509 | } |
473 | 510 | ||
474 | static ssize_t twl4030_usb_vbus_show(struct device *dev, | 511 | static ssize_t twl4030_usb_vbus_show(struct device *dev, |
@@ -491,9 +528,18 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) | |||
491 | { | 528 | { |
492 | struct twl4030_usb *twl = _twl; | 529 | struct twl4030_usb *twl = _twl; |
493 | enum omap_musb_vbus_id_status status; | 530 | enum omap_musb_vbus_id_status status; |
531 | bool status_changed = false; | ||
494 | 532 | ||
495 | status = twl4030_usb_linkstat(twl); | 533 | status = twl4030_usb_linkstat(twl); |
496 | if (status > 0) { | 534 | |
535 | spin_lock_irq(&twl->lock); | ||
536 | if (status >= 0 && status != twl->linkstat) { | ||
537 | twl->linkstat = status; | ||
538 | status_changed = true; | ||
539 | } | ||
540 | spin_unlock_irq(&twl->lock); | ||
541 | |||
542 | if (status_changed) { | ||
497 | /* FIXME add a set_power() method so that B-devices can | 543 | /* FIXME add a set_power() method so that B-devices can |
498 | * configure the charger appropriately. It's not always | 544 | * configure the charger appropriately. It's not always |
499 | * correct to consume VBUS power, and how much current to | 545 | * correct to consume VBUS power, and how much current to |
@@ -505,37 +551,62 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) | |||
505 | * USB_LINK_VBUS state. musb_hdrc won't care until it | 551 | * USB_LINK_VBUS state. musb_hdrc won't care until it |
506 | * starts to handle softconnect right. | 552 | * starts to handle softconnect right. |
507 | */ | 553 | */ |
508 | if (status == OMAP_MUSB_VBUS_OFF || | 554 | omap_musb_mailbox(status); |
509 | status == OMAP_MUSB_ID_FLOAT) | ||
510 | twl4030_phy_suspend(twl, 0); | ||
511 | else | ||
512 | twl4030_phy_resume(twl); | ||
513 | |||
514 | omap_musb_mailbox(twl->linkstat); | ||
515 | } | 555 | } |
516 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | 556 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); |
517 | 557 | ||
518 | return IRQ_HANDLED; | 558 | return IRQ_HANDLED; |
519 | } | 559 | } |
520 | 560 | ||
521 | static void twl4030_usb_phy_init(struct twl4030_usb *twl) | 561 | static void twl4030_id_workaround_work(struct work_struct *work) |
522 | { | 562 | { |
563 | struct twl4030_usb *twl = container_of(work, struct twl4030_usb, | ||
564 | id_workaround_work.work); | ||
523 | enum omap_musb_vbus_id_status status; | 565 | enum omap_musb_vbus_id_status status; |
566 | bool status_changed = false; | ||
524 | 567 | ||
525 | status = twl4030_usb_linkstat(twl); | 568 | status = twl4030_usb_linkstat(twl); |
526 | if (status > 0) { | ||
527 | if (status == OMAP_MUSB_VBUS_OFF || | ||
528 | status == OMAP_MUSB_ID_FLOAT) { | ||
529 | __twl4030_phy_power(twl, 0); | ||
530 | twl->asleep = 1; | ||
531 | } else { | ||
532 | __twl4030_phy_resume(twl); | ||
533 | twl->asleep = 0; | ||
534 | } | ||
535 | 569 | ||
536 | omap_musb_mailbox(twl->linkstat); | 570 | spin_lock_irq(&twl->lock); |
571 | if (status >= 0 && status != twl->linkstat) { | ||
572 | twl->linkstat = status; | ||
573 | status_changed = true; | ||
574 | } | ||
575 | spin_unlock_irq(&twl->lock); | ||
576 | |||
577 | if (status_changed) { | ||
578 | dev_dbg(twl->dev, "handle missing status change to %d\n", | ||
579 | status); | ||
580 | omap_musb_mailbox(status); | ||
537 | } | 581 | } |
582 | |||
583 | /* don't schedule during sleep - irq works right then */ | ||
584 | if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) { | ||
585 | cancel_delayed_work(&twl->id_workaround_work); | ||
586 | schedule_delayed_work(&twl->id_workaround_work, HZ); | ||
587 | } | ||
588 | } | ||
589 | |||
590 | static int twl4030_usb_phy_init(struct usb_phy *phy) | ||
591 | { | ||
592 | struct twl4030_usb *twl = phy_to_twl(phy); | ||
593 | enum omap_musb_vbus_id_status status; | ||
594 | |||
595 | /* | ||
596 | * Start in sleep state, we'll get called through set_suspend() | ||
597 | * callback when musb is runtime resumed and it's time to start. | ||
598 | */ | ||
599 | __twl4030_phy_power(twl, 0); | ||
600 | twl->asleep = 1; | ||
601 | |||
602 | status = twl4030_usb_linkstat(twl); | ||
603 | twl->linkstat = status; | ||
604 | |||
605 | if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) | ||
606 | omap_musb_mailbox(twl->linkstat); | ||
607 | |||
538 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | 608 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); |
609 | return 0; | ||
539 | } | 610 | } |
540 | 611 | ||
541 | static int twl4030_set_suspend(struct usb_phy *x, int suspend) | 612 | static int twl4030_set_suspend(struct usb_phy *x, int suspend) |
@@ -612,6 +683,7 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
612 | twl->phy.otg = otg; | 683 | twl->phy.otg = otg; |
613 | twl->phy.type = USB_PHY_TYPE_USB2; | 684 | twl->phy.type = USB_PHY_TYPE_USB2; |
614 | twl->phy.set_suspend = twl4030_set_suspend; | 685 | twl->phy.set_suspend = twl4030_set_suspend; |
686 | twl->phy.init = twl4030_usb_phy_init; | ||
615 | 687 | ||
616 | otg->phy = &twl->phy; | 688 | otg->phy = &twl->phy; |
617 | otg->set_host = twl4030_set_host; | 689 | otg->set_host = twl4030_set_host; |
@@ -620,6 +692,8 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
620 | /* init spinlock for workqueue */ | 692 | /* init spinlock for workqueue */ |
621 | spin_lock_init(&twl->lock); | 693 | spin_lock_init(&twl->lock); |
622 | 694 | ||
695 | INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work); | ||
696 | |||
623 | err = twl4030_usb_ldo_init(twl); | 697 | err = twl4030_usb_ldo_init(twl); |
624 | if (err) { | 698 | if (err) { |
625 | dev_err(&pdev->dev, "ldo init failed\n"); | 699 | dev_err(&pdev->dev, "ldo init failed\n"); |
@@ -640,20 +714,15 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
640 | * need both handles, otherwise just one suffices. | 714 | * need both handles, otherwise just one suffices. |
641 | */ | 715 | */ |
642 | twl->irq_enabled = true; | 716 | twl->irq_enabled = true; |
643 | status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq, | 717 | status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, |
644 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | | 718 | twl4030_usb_irq, IRQF_TRIGGER_FALLING | |
645 | IRQF_ONESHOT, "twl4030_usb", twl); | 719 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl); |
646 | if (status < 0) { | 720 | if (status < 0) { |
647 | dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", | 721 | dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", |
648 | twl->irq, status); | 722 | twl->irq, status); |
649 | return status; | 723 | return status; |
650 | } | 724 | } |
651 | 725 | ||
652 | /* Power down phy or make it work according to | ||
653 | * current link state. | ||
654 | */ | ||
655 | twl4030_usb_phy_init(twl); | ||
656 | |||
657 | dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); | 726 | dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); |
658 | return 0; | 727 | return 0; |
659 | } | 728 | } |
@@ -663,7 +732,7 @@ static int twl4030_usb_remove(struct platform_device *pdev) | |||
663 | struct twl4030_usb *twl = platform_get_drvdata(pdev); | 732 | struct twl4030_usb *twl = platform_get_drvdata(pdev); |
664 | int val; | 733 | int val; |
665 | 734 | ||
666 | free_irq(twl->irq, twl); | 735 | cancel_delayed_work(&twl->id_workaround_work); |
667 | device_remove_file(twl->dev, &dev_attr_vbus); | 736 | device_remove_file(twl->dev, &dev_attr_vbus); |
668 | 737 | ||
669 | /* set transceiver mode to power on defaults */ | 738 | /* set transceiver mode to power on defaults */ |
@@ -685,9 +754,6 @@ static int twl4030_usb_remove(struct platform_device *pdev) | |||
685 | 754 | ||
686 | if (!twl->asleep) | 755 | if (!twl->asleep) |
687 | twl4030_phy_power(twl, 0); | 756 | twl4030_phy_power(twl, 0); |
688 | regulator_put(twl->usb1v5); | ||
689 | regulator_put(twl->usb1v8); | ||
690 | regulator_put(twl->usb3v1); | ||
691 | 757 | ||
692 | return 0; | 758 | return 0; |
693 | } | 759 | } |
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c index 7f3c5b0e3f66..9de7ada90a8b 100644 --- a/drivers/usb/otg/twl6030-usb.c +++ b/drivers/usb/phy/phy-twl6030-usb.c | |||
@@ -211,6 +211,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl) | |||
211 | struct twl6030_usb *twl = _twl; | 211 | struct twl6030_usb *twl = _twl; |
212 | enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; | 212 | enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; |
213 | u8 vbus_state, hw_state; | 213 | u8 vbus_state, hw_state; |
214 | int ret; | ||
214 | 215 | ||
215 | hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); | 216 | hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); |
216 | 217 | ||
@@ -218,7 +219,10 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl) | |||
218 | CONTROLLER_STAT1); | 219 | CONTROLLER_STAT1); |
219 | if (!(hw_state & STS_USB_ID)) { | 220 | if (!(hw_state & STS_USB_ID)) { |
220 | if (vbus_state & VBUS_DET) { | 221 | if (vbus_state & VBUS_DET) { |
221 | regulator_enable(twl->usb3v3); | 222 | ret = regulator_enable(twl->usb3v3); |
223 | if (ret) | ||
224 | dev_err(twl->dev, "Failed to enable usb3v3\n"); | ||
225 | |||
222 | twl->asleep = 1; | 226 | twl->asleep = 1; |
223 | status = OMAP_MUSB_VBUS_VALID; | 227 | status = OMAP_MUSB_VBUS_VALID; |
224 | twl->linkstat = status; | 228 | twl->linkstat = status; |
@@ -245,12 +249,15 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) | |||
245 | struct twl6030_usb *twl = _twl; | 249 | struct twl6030_usb *twl = _twl; |
246 | enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; | 250 | enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; |
247 | u8 hw_state; | 251 | u8 hw_state; |
252 | int ret; | ||
248 | 253 | ||
249 | hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); | 254 | hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); |
250 | 255 | ||
251 | if (hw_state & STS_USB_ID) { | 256 | if (hw_state & STS_USB_ID) { |
257 | ret = regulator_enable(twl->usb3v3); | ||
258 | if (ret) | ||
259 | dev_err(twl->dev, "Failed to enable usb3v3\n"); | ||
252 | 260 | ||
253 | regulator_enable(twl->usb3v3); | ||
254 | twl->asleep = 1; | 261 | twl->asleep = 1; |
255 | twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); | 262 | twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); |
256 | twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); | 263 | twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); |
diff --git a/drivers/usb/otg/ulpi_viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c index c5ba7e5423fc..c5ba7e5423fc 100644 --- a/drivers/usb/otg/ulpi_viewport.c +++ b/drivers/usb/phy/phy-ulpi-viewport.c | |||
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/phy/phy-ulpi.c index 217339dd7a90..217339dd7a90 100644 --- a/drivers/usb/otg/ulpi.c +++ b/drivers/usb/phy/phy-ulpi.c | |||
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/phy/phy.c index 2bd03d261a50..f52c006417ff 100644 --- a/drivers/usb/otg/otg.c +++ b/drivers/usb/phy/phy.c | |||
@@ -1,14 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | * otg.c -- USB OTG utility code | 2 | * phy.c -- USB phy handling |
3 | * | 3 | * |
4 | * Copyright (C) 2004 Texas Instruments | 4 | * Copyright (C) 2004-2013 Texas Instruments |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | */ | 10 | */ |
11 | |||
12 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
13 | #include <linux/export.h> | 12 | #include <linux/export.h> |
14 | #include <linux/err.h> | 13 | #include <linux/err.h> |
@@ -17,7 +16,7 @@ | |||
17 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
18 | #include <linux/of.h> | 17 | #include <linux/of.h> |
19 | 18 | ||
20 | #include <linux/usb/otg.h> | 19 | #include <linux/usb/phy.h> |
21 | 20 | ||
22 | static LIST_HEAD(phy_list); | 21 | static LIST_HEAD(phy_list); |
23 | static LIST_HEAD(phy_bind_list); | 22 | static LIST_HEAD(phy_bind_list); |
@@ -110,7 +109,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type) | |||
110 | 109 | ||
111 | return phy; | 110 | return phy; |
112 | } | 111 | } |
113 | EXPORT_SYMBOL(devm_usb_get_phy); | 112 | EXPORT_SYMBOL_GPL(devm_usb_get_phy); |
114 | 113 | ||
115 | /** | 114 | /** |
116 | * usb_get_phy - find the USB PHY | 115 | * usb_get_phy - find the USB PHY |
@@ -143,7 +142,7 @@ err0: | |||
143 | 142 | ||
144 | return phy; | 143 | return phy; |
145 | } | 144 | } |
146 | EXPORT_SYMBOL(usb_get_phy); | 145 | EXPORT_SYMBOL_GPL(usb_get_phy); |
147 | 146 | ||
148 | /** | 147 | /** |
149 | * devm_usb_get_phy_by_phandle - find the USB PHY by phandle | 148 | * devm_usb_get_phy_by_phandle - find the USB PHY by phandle |
@@ -207,7 +206,7 @@ err0: | |||
207 | 206 | ||
208 | return phy; | 207 | return phy; |
209 | } | 208 | } |
210 | EXPORT_SYMBOL(devm_usb_get_phy_by_phandle); | 209 | EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_phandle); |
211 | 210 | ||
212 | /** | 211 | /** |
213 | * usb_get_phy_dev - find the USB PHY | 212 | * usb_get_phy_dev - find the USB PHY |
@@ -240,7 +239,7 @@ err0: | |||
240 | 239 | ||
241 | return phy; | 240 | return phy; |
242 | } | 241 | } |
243 | EXPORT_SYMBOL(usb_get_phy_dev); | 242 | EXPORT_SYMBOL_GPL(usb_get_phy_dev); |
244 | 243 | ||
245 | /** | 244 | /** |
246 | * devm_usb_get_phy_dev - find the USB PHY using device ptr and index | 245 | * devm_usb_get_phy_dev - find the USB PHY using device ptr and index |
@@ -270,7 +269,7 @@ struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index) | |||
270 | 269 | ||
271 | return phy; | 270 | return phy; |
272 | } | 271 | } |
273 | EXPORT_SYMBOL(devm_usb_get_phy_dev); | 272 | EXPORT_SYMBOL_GPL(devm_usb_get_phy_dev); |
274 | 273 | ||
275 | /** | 274 | /** |
276 | * devm_usb_put_phy - release the USB PHY | 275 | * devm_usb_put_phy - release the USB PHY |
@@ -289,7 +288,7 @@ void devm_usb_put_phy(struct device *dev, struct usb_phy *phy) | |||
289 | r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy); | 288 | r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy); |
290 | dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); | 289 | dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); |
291 | } | 290 | } |
292 | EXPORT_SYMBOL(devm_usb_put_phy); | 291 | EXPORT_SYMBOL_GPL(devm_usb_put_phy); |
293 | 292 | ||
294 | /** | 293 | /** |
295 | * usb_put_phy - release the USB PHY | 294 | * usb_put_phy - release the USB PHY |
@@ -308,7 +307,7 @@ void usb_put_phy(struct usb_phy *x) | |||
308 | module_put(owner); | 307 | module_put(owner); |
309 | } | 308 | } |
310 | } | 309 | } |
311 | EXPORT_SYMBOL(usb_put_phy); | 310 | EXPORT_SYMBOL_GPL(usb_put_phy); |
312 | 311 | ||
313 | /** | 312 | /** |
314 | * usb_add_phy - declare the USB PHY | 313 | * usb_add_phy - declare the USB PHY |
@@ -348,7 +347,7 @@ out: | |||
348 | spin_unlock_irqrestore(&phy_lock, flags); | 347 | spin_unlock_irqrestore(&phy_lock, flags); |
349 | return ret; | 348 | return ret; |
350 | } | 349 | } |
351 | EXPORT_SYMBOL(usb_add_phy); | 350 | EXPORT_SYMBOL_GPL(usb_add_phy); |
352 | 351 | ||
353 | /** | 352 | /** |
354 | * usb_add_phy_dev - declare the USB PHY | 353 | * usb_add_phy_dev - declare the USB PHY |
@@ -378,7 +377,7 @@ int usb_add_phy_dev(struct usb_phy *x) | |||
378 | spin_unlock_irqrestore(&phy_lock, flags); | 377 | spin_unlock_irqrestore(&phy_lock, flags); |
379 | return 0; | 378 | return 0; |
380 | } | 379 | } |
381 | EXPORT_SYMBOL(usb_add_phy_dev); | 380 | EXPORT_SYMBOL_GPL(usb_add_phy_dev); |
382 | 381 | ||
383 | /** | 382 | /** |
384 | * usb_remove_phy - remove the OTG PHY | 383 | * usb_remove_phy - remove the OTG PHY |
@@ -400,7 +399,7 @@ void usb_remove_phy(struct usb_phy *x) | |||
400 | } | 399 | } |
401 | spin_unlock_irqrestore(&phy_lock, flags); | 400 | spin_unlock_irqrestore(&phy_lock, flags); |
402 | } | 401 | } |
403 | EXPORT_SYMBOL(usb_remove_phy); | 402 | EXPORT_SYMBOL_GPL(usb_remove_phy); |
404 | 403 | ||
405 | /** | 404 | /** |
406 | * usb_bind_phy - bind the phy and the controller that uses the phy | 405 | * usb_bind_phy - bind the phy and the controller that uses the phy |
@@ -437,38 +436,3 @@ int __init usb_bind_phy(const char *dev_name, u8 index, | |||
437 | return 0; | 436 | return 0; |
438 | } | 437 | } |
439 | EXPORT_SYMBOL_GPL(usb_bind_phy); | 438 | EXPORT_SYMBOL_GPL(usb_bind_phy); |
440 | |||
441 | const char *otg_state_string(enum usb_otg_state state) | ||
442 | { | ||
443 | switch (state) { | ||
444 | case OTG_STATE_A_IDLE: | ||
445 | return "a_idle"; | ||
446 | case OTG_STATE_A_WAIT_VRISE: | ||
447 | return "a_wait_vrise"; | ||
448 | case OTG_STATE_A_WAIT_BCON: | ||
449 | return "a_wait_bcon"; | ||
450 | case OTG_STATE_A_HOST: | ||
451 | return "a_host"; | ||
452 | case OTG_STATE_A_SUSPEND: | ||
453 | return "a_suspend"; | ||
454 | case OTG_STATE_A_PERIPHERAL: | ||
455 | return "a_peripheral"; | ||
456 | case OTG_STATE_A_WAIT_VFALL: | ||
457 | return "a_wait_vfall"; | ||
458 | case OTG_STATE_A_VBUS_ERR: | ||
459 | return "a_vbus_err"; | ||
460 | case OTG_STATE_B_IDLE: | ||
461 | return "b_idle"; | ||
462 | case OTG_STATE_B_SRP_INIT: | ||
463 | return "b_srp_init"; | ||
464 | case OTG_STATE_B_PERIPHERAL: | ||
465 | return "b_peripheral"; | ||
466 | case OTG_STATE_B_WAIT_ACON: | ||
467 | return "b_wait_acon"; | ||
468 | case OTG_STATE_B_HOST: | ||
469 | return "b_host"; | ||
470 | default: | ||
471 | return "UNDEFINED"; | ||
472 | } | ||
473 | } | ||
474 | EXPORT_SYMBOL(otg_state_string); | ||
diff --git a/drivers/usb/phy/samsung-usbphy.c b/drivers/usb/phy/samsung-usbphy.c deleted file mode 100644 index 967101ec15fd..000000000000 --- a/drivers/usb/phy/samsung-usbphy.c +++ /dev/null | |||
@@ -1,928 +0,0 @@ | |||
1 | /* linux/drivers/usb/phy/samsung-usbphy.c | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Praveen Paneri <p.paneri@samsung.com> | ||
7 | * | ||
8 | * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and | ||
9 | * OHCI-EXYNOS controllers. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/clk.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/of.h> | ||
29 | #include <linux/of_address.h> | ||
30 | #include <linux/usb/otg.h> | ||
31 | #include <linux/usb/samsung_usb_phy.h> | ||
32 | #include <linux/platform_data/samsung-usbphy.h> | ||
33 | |||
34 | /* Register definitions */ | ||
35 | |||
36 | #define SAMSUNG_PHYPWR (0x00) | ||
37 | |||
38 | #define PHYPWR_NORMAL_MASK (0x19 << 0) | ||
39 | #define PHYPWR_OTG_DISABLE (0x1 << 4) | ||
40 | #define PHYPWR_ANALOG_POWERDOWN (0x1 << 3) | ||
41 | #define PHYPWR_FORCE_SUSPEND (0x1 << 1) | ||
42 | /* For Exynos4 */ | ||
43 | #define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0) | ||
44 | #define PHYPWR_SLEEP_PHY0 (0x1 << 5) | ||
45 | |||
46 | #define SAMSUNG_PHYCLK (0x04) | ||
47 | |||
48 | #define PHYCLK_MODE_USB11 (0x1 << 6) | ||
49 | #define PHYCLK_EXT_OSC (0x1 << 5) | ||
50 | #define PHYCLK_COMMON_ON_N (0x1 << 4) | ||
51 | #define PHYCLK_ID_PULL (0x1 << 2) | ||
52 | #define PHYCLK_CLKSEL_MASK (0x3 << 0) | ||
53 | #define PHYCLK_CLKSEL_48M (0x0 << 0) | ||
54 | #define PHYCLK_CLKSEL_12M (0x2 << 0) | ||
55 | #define PHYCLK_CLKSEL_24M (0x3 << 0) | ||
56 | |||
57 | #define SAMSUNG_RSTCON (0x08) | ||
58 | |||
59 | #define RSTCON_PHYLINK_SWRST (0x1 << 2) | ||
60 | #define RSTCON_HLINK_SWRST (0x1 << 1) | ||
61 | #define RSTCON_SWRST (0x1 << 0) | ||
62 | |||
63 | /* EXYNOS5 */ | ||
64 | #define EXYNOS5_PHY_HOST_CTRL0 (0x00) | ||
65 | |||
66 | #define HOST_CTRL0_PHYSWRSTALL (0x1 << 31) | ||
67 | |||
68 | #define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19) | ||
69 | #define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19) | ||
70 | #define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19) | ||
71 | #define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19) | ||
72 | |||
73 | #define HOST_CTRL0_FSEL_MASK (0x7 << 16) | ||
74 | #define HOST_CTRL0_FSEL(_x) ((_x) << 16) | ||
75 | |||
76 | #define FSEL_CLKSEL_50M (0x7) | ||
77 | #define FSEL_CLKSEL_24M (0x5) | ||
78 | #define FSEL_CLKSEL_20M (0x4) | ||
79 | #define FSEL_CLKSEL_19200K (0x3) | ||
80 | #define FSEL_CLKSEL_12M (0x2) | ||
81 | #define FSEL_CLKSEL_10M (0x1) | ||
82 | #define FSEL_CLKSEL_9600K (0x0) | ||
83 | |||
84 | #define HOST_CTRL0_TESTBURNIN (0x1 << 11) | ||
85 | #define HOST_CTRL0_RETENABLE (0x1 << 10) | ||
86 | #define HOST_CTRL0_COMMONON_N (0x1 << 9) | ||
87 | #define HOST_CTRL0_SIDDQ (0x1 << 6) | ||
88 | #define HOST_CTRL0_FORCESLEEP (0x1 << 5) | ||
89 | #define HOST_CTRL0_FORCESUSPEND (0x1 << 4) | ||
90 | #define HOST_CTRL0_WORDINTERFACE (0x1 << 3) | ||
91 | #define HOST_CTRL0_UTMISWRST (0x1 << 2) | ||
92 | #define HOST_CTRL0_LINKSWRST (0x1 << 1) | ||
93 | #define HOST_CTRL0_PHYSWRST (0x1 << 0) | ||
94 | |||
95 | #define EXYNOS5_PHY_HOST_TUNE0 (0x04) | ||
96 | |||
97 | #define EXYNOS5_PHY_HSIC_CTRL1 (0x10) | ||
98 | |||
99 | #define EXYNOS5_PHY_HSIC_TUNE1 (0x14) | ||
100 | |||
101 | #define EXYNOS5_PHY_HSIC_CTRL2 (0x20) | ||
102 | |||
103 | #define EXYNOS5_PHY_HSIC_TUNE2 (0x24) | ||
104 | |||
105 | #define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23) | ||
106 | #define HSIC_CTRL_REFCLKSEL (0x2 << 23) | ||
107 | |||
108 | #define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16) | ||
109 | #define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16) | ||
110 | #define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16) | ||
111 | #define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16) | ||
112 | #define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16) | ||
113 | #define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16) | ||
114 | #define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16) | ||
115 | |||
116 | #define HSIC_CTRL_SIDDQ (0x1 << 6) | ||
117 | #define HSIC_CTRL_FORCESLEEP (0x1 << 5) | ||
118 | #define HSIC_CTRL_FORCESUSPEND (0x1 << 4) | ||
119 | #define HSIC_CTRL_WORDINTERFACE (0x1 << 3) | ||
120 | #define HSIC_CTRL_UTMISWRST (0x1 << 2) | ||
121 | #define HSIC_CTRL_PHYSWRST (0x1 << 0) | ||
122 | |||
123 | #define EXYNOS5_PHY_HOST_EHCICTRL (0x30) | ||
124 | |||
125 | #define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29) | ||
126 | #define HOST_EHCICTRL_ENAINCR4 (0x1 << 28) | ||
127 | #define HOST_EHCICTRL_ENAINCR8 (0x1 << 27) | ||
128 | #define HOST_EHCICTRL_ENAINCR16 (0x1 << 26) | ||
129 | |||
130 | #define EXYNOS5_PHY_HOST_OHCICTRL (0x34) | ||
131 | |||
132 | #define HOST_OHCICTRL_SUSPLGCY (0x1 << 3) | ||
133 | #define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2) | ||
134 | #define HOST_OHCICTRL_CNTSEL (0x1 << 1) | ||
135 | #define HOST_OHCICTRL_CLKCKTRST (0x1 << 0) | ||
136 | |||
137 | #define EXYNOS5_PHY_OTG_SYS (0x38) | ||
138 | |||
139 | #define OTG_SYS_PHYLINK_SWRESET (0x1 << 14) | ||
140 | #define OTG_SYS_LINKSWRST_UOTG (0x1 << 13) | ||
141 | #define OTG_SYS_PHY0_SWRST (0x1 << 12) | ||
142 | |||
143 | #define OTG_SYS_REFCLKSEL_MASK (0x3 << 9) | ||
144 | #define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9) | ||
145 | #define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9) | ||
146 | #define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9) | ||
147 | |||
148 | #define OTG_SYS_IDPULLUP_UOTG (0x1 << 8) | ||
149 | #define OTG_SYS_COMMON_ON (0x1 << 7) | ||
150 | |||
151 | #define OTG_SYS_FSEL_MASK (0x7 << 4) | ||
152 | #define OTG_SYS_FSEL(_x) ((_x) << 4) | ||
153 | |||
154 | #define OTG_SYS_FORCESLEEP (0x1 << 3) | ||
155 | #define OTG_SYS_OTGDISABLE (0x1 << 2) | ||
156 | #define OTG_SYS_SIDDQ_UOTG (0x1 << 1) | ||
157 | #define OTG_SYS_FORCESUSPEND (0x1 << 0) | ||
158 | |||
159 | #define EXYNOS5_PHY_OTG_TUNE (0x40) | ||
160 | |||
161 | #ifndef MHZ | ||
162 | #define MHZ (1000*1000) | ||
163 | #endif | ||
164 | |||
165 | #ifndef KHZ | ||
166 | #define KHZ (1000) | ||
167 | #endif | ||
168 | |||
169 | #define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4) | ||
170 | #define S3C64XX_USBPHY_ENABLE (0x1 << 16) | ||
171 | #define EXYNOS_USBPHY_ENABLE (0x1 << 0) | ||
172 | #define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0) | ||
173 | |||
174 | enum samsung_cpu_type { | ||
175 | TYPE_S3C64XX, | ||
176 | TYPE_EXYNOS4210, | ||
177 | TYPE_EXYNOS5250, | ||
178 | }; | ||
179 | |||
180 | /* | ||
181 | * struct samsung_usbphy_drvdata - driver data for various SoC variants | ||
182 | * @cpu_type: machine identifier | ||
183 | * @devphy_en_mask: device phy enable mask for PHY CONTROL register | ||
184 | * @hostphy_en_mask: host phy enable mask for PHY CONTROL register | ||
185 | * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from | ||
186 | * mapped address of system controller. | ||
187 | * @hostphy_reg_offset: offset to HOST PHY CONTROL register from | ||
188 | * mapped address of system controller. | ||
189 | * | ||
190 | * Here we have a separate mask for device type phy. | ||
191 | * Having different masks for host and device type phy helps | ||
192 | * in setting independent masks in case of SoCs like S5PV210, | ||
193 | * in which PHY0 and PHY1 enable bits belong to same register | ||
194 | * placed at position 0 and 1 respectively. | ||
195 | * Although for newer SoCs like exynos these bits belong to | ||
196 | * different registers altogether placed at position 0. | ||
197 | */ | ||
198 | struct samsung_usbphy_drvdata { | ||
199 | int cpu_type; | ||
200 | int devphy_en_mask; | ||
201 | int hostphy_en_mask; | ||
202 | u32 devphy_reg_offset; | ||
203 | u32 hostphy_reg_offset; | ||
204 | }; | ||
205 | |||
206 | /* | ||
207 | * struct samsung_usbphy - transceiver driver state | ||
208 | * @phy: transceiver structure | ||
209 | * @plat: platform data | ||
210 | * @dev: The parent device supplied to the probe function | ||
211 | * @clk: usb phy clock | ||
212 | * @regs: usb phy controller registers memory base | ||
213 | * @pmuregs: USB device PHY_CONTROL register memory base | ||
214 | * @sysreg: USB2.0 PHY_CFG register memory base | ||
215 | * @ref_clk_freq: reference clock frequency selection | ||
216 | * @drv_data: driver data available for different SoCs | ||
217 | * @phy_type: Samsung SoCs specific phy types: #HOST | ||
218 | * #DEVICE | ||
219 | * @phy_usage: usage count for phy | ||
220 | * @lock: lock for phy operations | ||
221 | */ | ||
222 | struct samsung_usbphy { | ||
223 | struct usb_phy phy; | ||
224 | struct samsung_usbphy_data *plat; | ||
225 | struct device *dev; | ||
226 | struct clk *clk; | ||
227 | void __iomem *regs; | ||
228 | void __iomem *pmuregs; | ||
229 | void __iomem *sysreg; | ||
230 | int ref_clk_freq; | ||
231 | const struct samsung_usbphy_drvdata *drv_data; | ||
232 | enum samsung_usb_phy_type phy_type; | ||
233 | atomic_t phy_usage; | ||
234 | spinlock_t lock; | ||
235 | }; | ||
236 | |||
237 | #define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy) | ||
238 | |||
239 | int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host) | ||
240 | { | ||
241 | if (!otg) | ||
242 | return -ENODEV; | ||
243 | |||
244 | if (!otg->host) | ||
245 | otg->host = host; | ||
246 | |||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | static int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy) | ||
251 | { | ||
252 | struct device_node *usbphy_sys; | ||
253 | |||
254 | /* Getting node for system controller interface for usb-phy */ | ||
255 | usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys"); | ||
256 | if (!usbphy_sys) { | ||
257 | dev_err(sphy->dev, "No sys-controller interface for usb-phy\n"); | ||
258 | return -ENODEV; | ||
259 | } | ||
260 | |||
261 | sphy->pmuregs = of_iomap(usbphy_sys, 0); | ||
262 | |||
263 | if (sphy->pmuregs == NULL) { | ||
264 | dev_err(sphy->dev, "Can't get usb-phy pmu control register\n"); | ||
265 | goto err0; | ||
266 | } | ||
267 | |||
268 | sphy->sysreg = of_iomap(usbphy_sys, 1); | ||
269 | |||
270 | /* | ||
271 | * Not returning error code here, since this situation is not fatal. | ||
272 | * Few SoCs may not have this switch available | ||
273 | */ | ||
274 | if (sphy->sysreg == NULL) | ||
275 | dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n"); | ||
276 | |||
277 | of_node_put(usbphy_sys); | ||
278 | |||
279 | return 0; | ||
280 | |||
281 | err0: | ||
282 | of_node_put(usbphy_sys); | ||
283 | return -ENXIO; | ||
284 | } | ||
285 | |||
286 | /* | ||
287 | * Set isolation here for phy. | ||
288 | * Here 'on = true' would mean USB PHY block is isolated, hence | ||
289 | * de-activated and vice-versa. | ||
290 | */ | ||
291 | static void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on) | ||
292 | { | ||
293 | void __iomem *reg = NULL; | ||
294 | u32 reg_val; | ||
295 | u32 en_mask = 0; | ||
296 | |||
297 | if (!sphy->pmuregs) { | ||
298 | dev_warn(sphy->dev, "Can't set pmu isolation\n"); | ||
299 | return; | ||
300 | } | ||
301 | |||
302 | switch (sphy->drv_data->cpu_type) { | ||
303 | case TYPE_S3C64XX: | ||
304 | /* | ||
305 | * Do nothing: We will add here once S3C64xx goes for DT support | ||
306 | */ | ||
307 | break; | ||
308 | case TYPE_EXYNOS4210: | ||
309 | /* | ||
310 | * Fall through since exynos4210 and exynos5250 have similar | ||
311 | * register architecture: two separate registers for host and | ||
312 | * device phy control with enable bit at position 0. | ||
313 | */ | ||
314 | case TYPE_EXYNOS5250: | ||
315 | if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { | ||
316 | reg = sphy->pmuregs + | ||
317 | sphy->drv_data->devphy_reg_offset; | ||
318 | en_mask = sphy->drv_data->devphy_en_mask; | ||
319 | } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { | ||
320 | reg = sphy->pmuregs + | ||
321 | sphy->drv_data->hostphy_reg_offset; | ||
322 | en_mask = sphy->drv_data->hostphy_en_mask; | ||
323 | } | ||
324 | break; | ||
325 | default: | ||
326 | dev_err(sphy->dev, "Invalid SoC type\n"); | ||
327 | return; | ||
328 | } | ||
329 | |||
330 | reg_val = readl(reg); | ||
331 | |||
332 | if (on) | ||
333 | reg_val &= ~en_mask; | ||
334 | else | ||
335 | reg_val |= en_mask; | ||
336 | |||
337 | writel(reg_val, reg); | ||
338 | } | ||
339 | |||
340 | /* | ||
341 | * Configure the mode of working of usb-phy here: HOST/DEVICE. | ||
342 | */ | ||
343 | static void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy) | ||
344 | { | ||
345 | u32 reg; | ||
346 | |||
347 | if (!sphy->sysreg) { | ||
348 | dev_warn(sphy->dev, "Can't configure specified phy mode\n"); | ||
349 | return; | ||
350 | } | ||
351 | |||
352 | reg = readl(sphy->sysreg); | ||
353 | |||
354 | if (sphy->phy_type == USB_PHY_TYPE_DEVICE) | ||
355 | reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK; | ||
356 | else if (sphy->phy_type == USB_PHY_TYPE_HOST) | ||
357 | reg |= EXYNOS_USB20PHY_CFG_HOST_LINK; | ||
358 | |||
359 | writel(reg, sphy->sysreg); | ||
360 | } | ||
361 | |||
362 | /* | ||
363 | * PHYs are different for USB Device and USB Host. | ||
364 | * This make sure that correct PHY type is selected before | ||
365 | * any operation on PHY. | ||
366 | */ | ||
367 | static int samsung_usbphy_set_type(struct usb_phy *phy, | ||
368 | enum samsung_usb_phy_type phy_type) | ||
369 | { | ||
370 | struct samsung_usbphy *sphy = phy_to_sphy(phy); | ||
371 | |||
372 | sphy->phy_type = phy_type; | ||
373 | |||
374 | return 0; | ||
375 | } | ||
376 | |||
377 | /* | ||
378 | * Returns reference clock frequency selection value | ||
379 | */ | ||
380 | static int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy) | ||
381 | { | ||
382 | struct clk *ref_clk; | ||
383 | int refclk_freq = 0; | ||
384 | |||
385 | /* | ||
386 | * In exynos5250 USB host and device PHY use | ||
387 | * external crystal clock XXTI | ||
388 | */ | ||
389 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
390 | ref_clk = clk_get(sphy->dev, "ext_xtal"); | ||
391 | else | ||
392 | ref_clk = clk_get(sphy->dev, "xusbxti"); | ||
393 | if (IS_ERR(ref_clk)) { | ||
394 | dev_err(sphy->dev, "Failed to get reference clock\n"); | ||
395 | return PTR_ERR(ref_clk); | ||
396 | } | ||
397 | |||
398 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) { | ||
399 | /* set clock frequency for PLL */ | ||
400 | switch (clk_get_rate(ref_clk)) { | ||
401 | case 9600 * KHZ: | ||
402 | refclk_freq = FSEL_CLKSEL_9600K; | ||
403 | break; | ||
404 | case 10 * MHZ: | ||
405 | refclk_freq = FSEL_CLKSEL_10M; | ||
406 | break; | ||
407 | case 12 * MHZ: | ||
408 | refclk_freq = FSEL_CLKSEL_12M; | ||
409 | break; | ||
410 | case 19200 * KHZ: | ||
411 | refclk_freq = FSEL_CLKSEL_19200K; | ||
412 | break; | ||
413 | case 20 * MHZ: | ||
414 | refclk_freq = FSEL_CLKSEL_20M; | ||
415 | break; | ||
416 | case 50 * MHZ: | ||
417 | refclk_freq = FSEL_CLKSEL_50M; | ||
418 | break; | ||
419 | case 24 * MHZ: | ||
420 | default: | ||
421 | /* default reference clock */ | ||
422 | refclk_freq = FSEL_CLKSEL_24M; | ||
423 | break; | ||
424 | } | ||
425 | } else { | ||
426 | switch (clk_get_rate(ref_clk)) { | ||
427 | case 12 * MHZ: | ||
428 | refclk_freq = PHYCLK_CLKSEL_12M; | ||
429 | break; | ||
430 | case 24 * MHZ: | ||
431 | refclk_freq = PHYCLK_CLKSEL_24M; | ||
432 | break; | ||
433 | case 48 * MHZ: | ||
434 | refclk_freq = PHYCLK_CLKSEL_48M; | ||
435 | break; | ||
436 | default: | ||
437 | if (sphy->drv_data->cpu_type == TYPE_S3C64XX) | ||
438 | refclk_freq = PHYCLK_CLKSEL_48M; | ||
439 | else | ||
440 | refclk_freq = PHYCLK_CLKSEL_24M; | ||
441 | break; | ||
442 | } | ||
443 | } | ||
444 | clk_put(ref_clk); | ||
445 | |||
446 | return refclk_freq; | ||
447 | } | ||
448 | |||
449 | static bool exynos5_phyhost_is_on(void *regs) | ||
450 | { | ||
451 | u32 reg; | ||
452 | |||
453 | reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
454 | |||
455 | return !(reg & HOST_CTRL0_SIDDQ); | ||
456 | } | ||
457 | |||
458 | static void samsung_exynos5_usbphy_enable(struct samsung_usbphy *sphy) | ||
459 | { | ||
460 | void __iomem *regs = sphy->regs; | ||
461 | u32 phyclk = sphy->ref_clk_freq; | ||
462 | u32 phyhost; | ||
463 | u32 phyotg; | ||
464 | u32 phyhsic; | ||
465 | u32 ehcictrl; | ||
466 | u32 ohcictrl; | ||
467 | |||
468 | /* | ||
469 | * phy_usage helps in keeping usage count for phy | ||
470 | * so that the first consumer enabling the phy is also | ||
471 | * the last consumer to disable it. | ||
472 | */ | ||
473 | |||
474 | atomic_inc(&sphy->phy_usage); | ||
475 | |||
476 | if (exynos5_phyhost_is_on(regs)) { | ||
477 | dev_info(sphy->dev, "Already power on PHY\n"); | ||
478 | return; | ||
479 | } | ||
480 | |||
481 | /* Host configuration */ | ||
482 | phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
483 | |||
484 | /* phy reference clock configuration */ | ||
485 | phyhost &= ~HOST_CTRL0_FSEL_MASK; | ||
486 | phyhost |= HOST_CTRL0_FSEL(phyclk); | ||
487 | |||
488 | /* host phy reset */ | ||
489 | phyhost &= ~(HOST_CTRL0_PHYSWRST | | ||
490 | HOST_CTRL0_PHYSWRSTALL | | ||
491 | HOST_CTRL0_SIDDQ | | ||
492 | /* Enable normal mode of operation */ | ||
493 | HOST_CTRL0_FORCESUSPEND | | ||
494 | HOST_CTRL0_FORCESLEEP); | ||
495 | |||
496 | /* Link reset */ | ||
497 | phyhost |= (HOST_CTRL0_LINKSWRST | | ||
498 | HOST_CTRL0_UTMISWRST | | ||
499 | /* COMMON Block configuration during suspend */ | ||
500 | HOST_CTRL0_COMMONON_N); | ||
501 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
502 | udelay(10); | ||
503 | phyhost &= ~(HOST_CTRL0_LINKSWRST | | ||
504 | HOST_CTRL0_UTMISWRST); | ||
505 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
506 | |||
507 | /* OTG configuration */ | ||
508 | phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); | ||
509 | |||
510 | /* phy reference clock configuration */ | ||
511 | phyotg &= ~OTG_SYS_FSEL_MASK; | ||
512 | phyotg |= OTG_SYS_FSEL(phyclk); | ||
513 | |||
514 | /* Enable normal mode of operation */ | ||
515 | phyotg &= ~(OTG_SYS_FORCESUSPEND | | ||
516 | OTG_SYS_SIDDQ_UOTG | | ||
517 | OTG_SYS_FORCESLEEP | | ||
518 | OTG_SYS_REFCLKSEL_MASK | | ||
519 | /* COMMON Block configuration during suspend */ | ||
520 | OTG_SYS_COMMON_ON); | ||
521 | |||
522 | /* OTG phy & link reset */ | ||
523 | phyotg |= (OTG_SYS_PHY0_SWRST | | ||
524 | OTG_SYS_LINKSWRST_UOTG | | ||
525 | OTG_SYS_PHYLINK_SWRESET | | ||
526 | OTG_SYS_OTGDISABLE | | ||
527 | /* Set phy refclk */ | ||
528 | OTG_SYS_REFCLKSEL_CLKCORE); | ||
529 | |||
530 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
531 | udelay(10); | ||
532 | phyotg &= ~(OTG_SYS_PHY0_SWRST | | ||
533 | OTG_SYS_LINKSWRST_UOTG | | ||
534 | OTG_SYS_PHYLINK_SWRESET); | ||
535 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
536 | |||
537 | /* HSIC phy configuration */ | ||
538 | phyhsic = (HSIC_CTRL_REFCLKDIV_12 | | ||
539 | HSIC_CTRL_REFCLKSEL | | ||
540 | HSIC_CTRL_PHYSWRST); | ||
541 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
542 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
543 | udelay(10); | ||
544 | phyhsic &= ~HSIC_CTRL_PHYSWRST; | ||
545 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
546 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
547 | |||
548 | udelay(80); | ||
549 | |||
550 | /* enable EHCI DMA burst */ | ||
551 | ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL); | ||
552 | ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN | | ||
553 | HOST_EHCICTRL_ENAINCR4 | | ||
554 | HOST_EHCICTRL_ENAINCR8 | | ||
555 | HOST_EHCICTRL_ENAINCR16); | ||
556 | writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL); | ||
557 | |||
558 | /* set ohci_suspend_on_n */ | ||
559 | ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL); | ||
560 | ohcictrl |= HOST_OHCICTRL_SUSPLGCY; | ||
561 | writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL); | ||
562 | } | ||
563 | |||
564 | static void samsung_usbphy_enable(struct samsung_usbphy *sphy) | ||
565 | { | ||
566 | void __iomem *regs = sphy->regs; | ||
567 | u32 phypwr; | ||
568 | u32 phyclk; | ||
569 | u32 rstcon; | ||
570 | |||
571 | /* set clock frequency for PLL */ | ||
572 | phyclk = sphy->ref_clk_freq; | ||
573 | phypwr = readl(regs + SAMSUNG_PHYPWR); | ||
574 | rstcon = readl(regs + SAMSUNG_RSTCON); | ||
575 | |||
576 | switch (sphy->drv_data->cpu_type) { | ||
577 | case TYPE_S3C64XX: | ||
578 | phyclk &= ~PHYCLK_COMMON_ON_N; | ||
579 | phypwr &= ~PHYPWR_NORMAL_MASK; | ||
580 | rstcon |= RSTCON_SWRST; | ||
581 | break; | ||
582 | case TYPE_EXYNOS4210: | ||
583 | phypwr &= ~PHYPWR_NORMAL_MASK_PHY0; | ||
584 | rstcon |= RSTCON_SWRST; | ||
585 | default: | ||
586 | break; | ||
587 | } | ||
588 | |||
589 | writel(phyclk, regs + SAMSUNG_PHYCLK); | ||
590 | /* Configure PHY0 for normal operation*/ | ||
591 | writel(phypwr, regs + SAMSUNG_PHYPWR); | ||
592 | /* reset all ports of PHY and Link */ | ||
593 | writel(rstcon, regs + SAMSUNG_RSTCON); | ||
594 | udelay(10); | ||
595 | rstcon &= ~RSTCON_SWRST; | ||
596 | writel(rstcon, regs + SAMSUNG_RSTCON); | ||
597 | } | ||
598 | |||
599 | static void samsung_exynos5_usbphy_disable(struct samsung_usbphy *sphy) | ||
600 | { | ||
601 | void __iomem *regs = sphy->regs; | ||
602 | u32 phyhost; | ||
603 | u32 phyotg; | ||
604 | u32 phyhsic; | ||
605 | |||
606 | if (atomic_dec_return(&sphy->phy_usage) > 0) { | ||
607 | dev_info(sphy->dev, "still being used\n"); | ||
608 | return; | ||
609 | } | ||
610 | |||
611 | phyhsic = (HSIC_CTRL_REFCLKDIV_12 | | ||
612 | HSIC_CTRL_REFCLKSEL | | ||
613 | HSIC_CTRL_SIDDQ | | ||
614 | HSIC_CTRL_FORCESLEEP | | ||
615 | HSIC_CTRL_FORCESUSPEND); | ||
616 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
617 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
618 | |||
619 | phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
620 | phyhost |= (HOST_CTRL0_SIDDQ | | ||
621 | HOST_CTRL0_FORCESUSPEND | | ||
622 | HOST_CTRL0_FORCESLEEP | | ||
623 | HOST_CTRL0_PHYSWRST | | ||
624 | HOST_CTRL0_PHYSWRSTALL); | ||
625 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
626 | |||
627 | phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); | ||
628 | phyotg |= (OTG_SYS_FORCESUSPEND | | ||
629 | OTG_SYS_SIDDQ_UOTG | | ||
630 | OTG_SYS_FORCESLEEP); | ||
631 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
632 | } | ||
633 | |||
634 | static void samsung_usbphy_disable(struct samsung_usbphy *sphy) | ||
635 | { | ||
636 | void __iomem *regs = sphy->regs; | ||
637 | u32 phypwr; | ||
638 | |||
639 | phypwr = readl(regs + SAMSUNG_PHYPWR); | ||
640 | |||
641 | switch (sphy->drv_data->cpu_type) { | ||
642 | case TYPE_S3C64XX: | ||
643 | phypwr |= PHYPWR_NORMAL_MASK; | ||
644 | break; | ||
645 | case TYPE_EXYNOS4210: | ||
646 | phypwr |= PHYPWR_NORMAL_MASK_PHY0; | ||
647 | default: | ||
648 | break; | ||
649 | } | ||
650 | |||
651 | /* Disable analog and otg block power */ | ||
652 | writel(phypwr, regs + SAMSUNG_PHYPWR); | ||
653 | } | ||
654 | |||
655 | /* | ||
656 | * The function passed to the usb driver for phy initialization | ||
657 | */ | ||
658 | static int samsung_usbphy_init(struct usb_phy *phy) | ||
659 | { | ||
660 | struct samsung_usbphy *sphy; | ||
661 | struct usb_bus *host = NULL; | ||
662 | unsigned long flags; | ||
663 | int ret = 0; | ||
664 | |||
665 | sphy = phy_to_sphy(phy); | ||
666 | |||
667 | host = phy->otg->host; | ||
668 | |||
669 | /* Enable the phy clock */ | ||
670 | ret = clk_prepare_enable(sphy->clk); | ||
671 | if (ret) { | ||
672 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
673 | return ret; | ||
674 | } | ||
675 | |||
676 | spin_lock_irqsave(&sphy->lock, flags); | ||
677 | |||
678 | if (host) { | ||
679 | /* setting default phy-type for USB 2.0 */ | ||
680 | if (!strstr(dev_name(host->controller), "ehci") || | ||
681 | !strstr(dev_name(host->controller), "ohci")) | ||
682 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); | ||
683 | } else { | ||
684 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
685 | } | ||
686 | |||
687 | /* Disable phy isolation */ | ||
688 | if (sphy->plat && sphy->plat->pmu_isolation) | ||
689 | sphy->plat->pmu_isolation(false); | ||
690 | else | ||
691 | samsung_usbphy_set_isolation(sphy, false); | ||
692 | |||
693 | /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */ | ||
694 | samsung_usbphy_cfg_sel(sphy); | ||
695 | |||
696 | /* Initialize usb phy registers */ | ||
697 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
698 | samsung_exynos5_usbphy_enable(sphy); | ||
699 | else | ||
700 | samsung_usbphy_enable(sphy); | ||
701 | |||
702 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
703 | |||
704 | /* Disable the phy clock */ | ||
705 | clk_disable_unprepare(sphy->clk); | ||
706 | |||
707 | return ret; | ||
708 | } | ||
709 | |||
710 | /* | ||
711 | * The function passed to the usb driver for phy shutdown | ||
712 | */ | ||
713 | static void samsung_usbphy_shutdown(struct usb_phy *phy) | ||
714 | { | ||
715 | struct samsung_usbphy *sphy; | ||
716 | struct usb_bus *host = NULL; | ||
717 | unsigned long flags; | ||
718 | |||
719 | sphy = phy_to_sphy(phy); | ||
720 | |||
721 | host = phy->otg->host; | ||
722 | |||
723 | if (clk_prepare_enable(sphy->clk)) { | ||
724 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
725 | return; | ||
726 | } | ||
727 | |||
728 | spin_lock_irqsave(&sphy->lock, flags); | ||
729 | |||
730 | if (host) { | ||
731 | /* setting default phy-type for USB 2.0 */ | ||
732 | if (!strstr(dev_name(host->controller), "ehci") || | ||
733 | !strstr(dev_name(host->controller), "ohci")) | ||
734 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); | ||
735 | } else { | ||
736 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
737 | } | ||
738 | |||
739 | /* De-initialize usb phy registers */ | ||
740 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
741 | samsung_exynos5_usbphy_disable(sphy); | ||
742 | else | ||
743 | samsung_usbphy_disable(sphy); | ||
744 | |||
745 | /* Enable phy isolation */ | ||
746 | if (sphy->plat && sphy->plat->pmu_isolation) | ||
747 | sphy->plat->pmu_isolation(true); | ||
748 | else | ||
749 | samsung_usbphy_set_isolation(sphy, true); | ||
750 | |||
751 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
752 | |||
753 | clk_disable_unprepare(sphy->clk); | ||
754 | } | ||
755 | |||
756 | static const struct of_device_id samsung_usbphy_dt_match[]; | ||
757 | |||
758 | static inline const struct samsung_usbphy_drvdata | ||
759 | *samsung_usbphy_get_driver_data(struct platform_device *pdev) | ||
760 | { | ||
761 | if (pdev->dev.of_node) { | ||
762 | const struct of_device_id *match; | ||
763 | match = of_match_node(samsung_usbphy_dt_match, | ||
764 | pdev->dev.of_node); | ||
765 | return match->data; | ||
766 | } | ||
767 | |||
768 | return (struct samsung_usbphy_drvdata *) | ||
769 | platform_get_device_id(pdev)->driver_data; | ||
770 | } | ||
771 | |||
772 | static int samsung_usbphy_probe(struct platform_device *pdev) | ||
773 | { | ||
774 | struct samsung_usbphy *sphy; | ||
775 | struct usb_otg *otg; | ||
776 | struct samsung_usbphy_data *pdata = pdev->dev.platform_data; | ||
777 | const struct samsung_usbphy_drvdata *drv_data; | ||
778 | struct device *dev = &pdev->dev; | ||
779 | struct resource *phy_mem; | ||
780 | void __iomem *phy_base; | ||
781 | struct clk *clk; | ||
782 | int ret; | ||
783 | |||
784 | phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
785 | if (!phy_mem) { | ||
786 | dev_err(dev, "%s: missing mem resource\n", __func__); | ||
787 | return -ENODEV; | ||
788 | } | ||
789 | |||
790 | phy_base = devm_ioremap_resource(dev, phy_mem); | ||
791 | if (IS_ERR(phy_base)) | ||
792 | return PTR_ERR(phy_base); | ||
793 | |||
794 | sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); | ||
795 | if (!sphy) | ||
796 | return -ENOMEM; | ||
797 | |||
798 | otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL); | ||
799 | if (!otg) | ||
800 | return -ENOMEM; | ||
801 | |||
802 | drv_data = samsung_usbphy_get_driver_data(pdev); | ||
803 | |||
804 | if (drv_data->cpu_type == TYPE_EXYNOS5250) | ||
805 | clk = devm_clk_get(dev, "usbhost"); | ||
806 | else | ||
807 | clk = devm_clk_get(dev, "otg"); | ||
808 | |||
809 | if (IS_ERR(clk)) { | ||
810 | dev_err(dev, "Failed to get otg clock\n"); | ||
811 | return PTR_ERR(clk); | ||
812 | } | ||
813 | |||
814 | sphy->dev = dev; | ||
815 | |||
816 | if (dev->of_node) { | ||
817 | ret = samsung_usbphy_parse_dt(sphy); | ||
818 | if (ret < 0) | ||
819 | return ret; | ||
820 | } else { | ||
821 | if (!pdata) { | ||
822 | dev_err(dev, "no platform data specified\n"); | ||
823 | return -EINVAL; | ||
824 | } | ||
825 | } | ||
826 | |||
827 | sphy->plat = pdata; | ||
828 | sphy->regs = phy_base; | ||
829 | sphy->clk = clk; | ||
830 | sphy->drv_data = drv_data; | ||
831 | sphy->phy.dev = sphy->dev; | ||
832 | sphy->phy.label = "samsung-usbphy"; | ||
833 | sphy->phy.init = samsung_usbphy_init; | ||
834 | sphy->phy.shutdown = samsung_usbphy_shutdown; | ||
835 | sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); | ||
836 | |||
837 | sphy->phy.otg = otg; | ||
838 | sphy->phy.otg->phy = &sphy->phy; | ||
839 | sphy->phy.otg->set_host = samsung_usbphy_set_host; | ||
840 | |||
841 | spin_lock_init(&sphy->lock); | ||
842 | |||
843 | platform_set_drvdata(pdev, sphy); | ||
844 | |||
845 | return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2); | ||
846 | } | ||
847 | |||
848 | static int samsung_usbphy_remove(struct platform_device *pdev) | ||
849 | { | ||
850 | struct samsung_usbphy *sphy = platform_get_drvdata(pdev); | ||
851 | |||
852 | usb_remove_phy(&sphy->phy); | ||
853 | |||
854 | if (sphy->pmuregs) | ||
855 | iounmap(sphy->pmuregs); | ||
856 | if (sphy->sysreg) | ||
857 | iounmap(sphy->sysreg); | ||
858 | |||
859 | return 0; | ||
860 | } | ||
861 | |||
862 | static const struct samsung_usbphy_drvdata usbphy_s3c64xx = { | ||
863 | .cpu_type = TYPE_S3C64XX, | ||
864 | .devphy_en_mask = S3C64XX_USBPHY_ENABLE, | ||
865 | }; | ||
866 | |||
867 | static const struct samsung_usbphy_drvdata usbphy_exynos4 = { | ||
868 | .cpu_type = TYPE_EXYNOS4210, | ||
869 | .devphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
870 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
871 | }; | ||
872 | |||
873 | static struct samsung_usbphy_drvdata usbphy_exynos5 = { | ||
874 | .cpu_type = TYPE_EXYNOS5250, | ||
875 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
876 | .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET, | ||
877 | }; | ||
878 | |||
879 | #ifdef CONFIG_OF | ||
880 | static const struct of_device_id samsung_usbphy_dt_match[] = { | ||
881 | { | ||
882 | .compatible = "samsung,s3c64xx-usbphy", | ||
883 | .data = &usbphy_s3c64xx, | ||
884 | }, { | ||
885 | .compatible = "samsung,exynos4210-usbphy", | ||
886 | .data = &usbphy_exynos4, | ||
887 | }, { | ||
888 | .compatible = "samsung,exynos5250-usbphy", | ||
889 | .data = &usbphy_exynos5 | ||
890 | }, | ||
891 | {}, | ||
892 | }; | ||
893 | MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); | ||
894 | #endif | ||
895 | |||
896 | static struct platform_device_id samsung_usbphy_driver_ids[] = { | ||
897 | { | ||
898 | .name = "s3c64xx-usbphy", | ||
899 | .driver_data = (unsigned long)&usbphy_s3c64xx, | ||
900 | }, { | ||
901 | .name = "exynos4210-usbphy", | ||
902 | .driver_data = (unsigned long)&usbphy_exynos4, | ||
903 | }, { | ||
904 | .name = "exynos5250-usbphy", | ||
905 | .driver_data = (unsigned long)&usbphy_exynos5, | ||
906 | }, | ||
907 | {}, | ||
908 | }; | ||
909 | |||
910 | MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); | ||
911 | |||
912 | static struct platform_driver samsung_usbphy_driver = { | ||
913 | .probe = samsung_usbphy_probe, | ||
914 | .remove = samsung_usbphy_remove, | ||
915 | .id_table = samsung_usbphy_driver_ids, | ||
916 | .driver = { | ||
917 | .name = "samsung-usbphy", | ||
918 | .owner = THIS_MODULE, | ||
919 | .of_match_table = of_match_ptr(samsung_usbphy_dt_match), | ||
920 | }, | ||
921 | }; | ||
922 | |||
923 | module_platform_driver(samsung_usbphy_driver); | ||
924 | |||
925 | MODULE_DESCRIPTION("Samsung USB phy controller"); | ||
926 | MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>"); | ||
927 | MODULE_LICENSE("GPL"); | ||
928 | MODULE_ALIAS("platform:samsung-usbphy"); | ||
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index 9538f0feafe2..45b94019aec8 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c | |||
@@ -32,7 +32,6 @@ | |||
32 | */ | 32 | */ |
33 | void usbhs_pkt_init(struct usbhs_pkt *pkt) | 33 | void usbhs_pkt_init(struct usbhs_pkt *pkt) |
34 | { | 34 | { |
35 | pkt->dma = DMA_ADDR_INVALID; | ||
36 | INIT_LIST_HEAD(&pkt->node); | 35 | INIT_LIST_HEAD(&pkt->node); |
37 | } | 36 | } |
38 | 37 | ||
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h index c31731a843d1..a168a1760fce 100644 --- a/drivers/usb/renesas_usbhs/fifo.h +++ b/drivers/usb/renesas_usbhs/fifo.h | |||
@@ -23,8 +23,6 @@ | |||
23 | #include <asm/dma.h> | 23 | #include <asm/dma.h> |
24 | #include "pipe.h" | 24 | #include "pipe.h" |
25 | 25 | ||
26 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
27 | |||
28 | struct usbhs_fifo { | 26 | struct usbhs_fifo { |
29 | char *name; | 27 | char *name; |
30 | u32 port; /* xFIFO */ | 28 | u32 port; /* xFIFO */ |
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index 78fca978b2d0..ed4949faa70d 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c | |||
@@ -230,7 +230,7 @@ static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv, | |||
230 | return 0; | 230 | return 0; |
231 | } | 231 | } |
232 | 232 | ||
233 | struct usbhsg_recip_handle req_clear_feature = { | 233 | static struct usbhsg_recip_handle req_clear_feature = { |
234 | .name = "clear feature", | 234 | .name = "clear feature", |
235 | .device = usbhsg_recip_handler_std_control_done, | 235 | .device = usbhsg_recip_handler_std_control_done, |
236 | .interface = usbhsg_recip_handler_std_control_done, | 236 | .interface = usbhsg_recip_handler_std_control_done, |
@@ -271,7 +271,7 @@ static int usbhsg_recip_handler_std_set_endpoint(struct usbhs_priv *priv, | |||
271 | return 0; | 271 | return 0; |
272 | } | 272 | } |
273 | 273 | ||
274 | struct usbhsg_recip_handle req_set_feature = { | 274 | static struct usbhsg_recip_handle req_set_feature = { |
275 | .name = "set feature", | 275 | .name = "set feature", |
276 | .device = usbhsg_recip_handler_std_set_device, | 276 | .device = usbhsg_recip_handler_std_set_device, |
277 | .interface = usbhsg_recip_handler_std_control_done, | 277 | .interface = usbhsg_recip_handler_std_control_done, |
@@ -372,7 +372,7 @@ static int usbhsg_recip_handler_std_get_endpoint(struct usbhs_priv *priv, | |||
372 | return 0; | 372 | return 0; |
373 | } | 373 | } |
374 | 374 | ||
375 | struct usbhsg_recip_handle req_get_status = { | 375 | static struct usbhsg_recip_handle req_get_status = { |
376 | .name = "get status", | 376 | .name = "get status", |
377 | .device = usbhsg_recip_handler_std_get_device, | 377 | .device = usbhsg_recip_handler_std_get_device, |
378 | .interface = usbhsg_recip_handler_std_get_interface, | 378 | .interface = usbhsg_recip_handler_std_get_interface, |
@@ -845,7 +845,6 @@ static int usbhsg_gadget_start(struct usb_gadget *gadget, | |||
845 | 845 | ||
846 | /* first hook up the driver ... */ | 846 | /* first hook up the driver ... */ |
847 | gpriv->driver = driver; | 847 | gpriv->driver = driver; |
848 | gpriv->gadget.dev.driver = &driver->driver; | ||
849 | 848 | ||
850 | return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); | 849 | return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); |
851 | } | 850 | } |
@@ -861,7 +860,6 @@ static int usbhsg_gadget_stop(struct usb_gadget *gadget, | |||
861 | return -EINVAL; | 860 | return -EINVAL; |
862 | 861 | ||
863 | usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); | 862 | usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); |
864 | gpriv->gadget.dev.driver = NULL; | ||
865 | gpriv->driver = NULL; | 863 | gpriv->driver = NULL; |
866 | 864 | ||
867 | return 0; | 865 | return 0; |
@@ -925,11 +923,6 @@ static int usbhsg_stop(struct usbhs_priv *priv) | |||
925 | return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); | 923 | return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); |
926 | } | 924 | } |
927 | 925 | ||
928 | static void usbhs_mod_gadget_release(struct device *pdev) | ||
929 | { | ||
930 | /* do nothing */ | ||
931 | } | ||
932 | |||
933 | int usbhs_mod_gadget_probe(struct usbhs_priv *priv) | 926 | int usbhs_mod_gadget_probe(struct usbhs_priv *priv) |
934 | { | 927 | { |
935 | struct usbhsg_gpriv *gpriv; | 928 | struct usbhsg_gpriv *gpriv; |
@@ -976,15 +969,10 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv) | |||
976 | /* | 969 | /* |
977 | * init gadget | 970 | * init gadget |
978 | */ | 971 | */ |
979 | dev_set_name(&gpriv->gadget.dev, "gadget"); | ||
980 | gpriv->gadget.dev.parent = dev; | 972 | gpriv->gadget.dev.parent = dev; |
981 | gpriv->gadget.dev.release = usbhs_mod_gadget_release; | ||
982 | gpriv->gadget.name = "renesas_usbhs_udc"; | 973 | gpriv->gadget.name = "renesas_usbhs_udc"; |
983 | gpriv->gadget.ops = &usbhsg_gadget_ops; | 974 | gpriv->gadget.ops = &usbhsg_gadget_ops; |
984 | gpriv->gadget.max_speed = USB_SPEED_HIGH; | 975 | gpriv->gadget.max_speed = USB_SPEED_HIGH; |
985 | ret = device_register(&gpriv->gadget.dev); | ||
986 | if (ret < 0) | ||
987 | goto err_add_udc; | ||
988 | 976 | ||
989 | INIT_LIST_HEAD(&gpriv->gadget.ep_list); | 977 | INIT_LIST_HEAD(&gpriv->gadget.ep_list); |
990 | 978 | ||
@@ -1014,15 +1002,13 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv) | |||
1014 | 1002 | ||
1015 | ret = usb_add_gadget_udc(dev, &gpriv->gadget); | 1003 | ret = usb_add_gadget_udc(dev, &gpriv->gadget); |
1016 | if (ret) | 1004 | if (ret) |
1017 | goto err_register; | 1005 | goto err_add_udc; |
1018 | 1006 | ||
1019 | 1007 | ||
1020 | dev_info(dev, "gadget probed\n"); | 1008 | dev_info(dev, "gadget probed\n"); |
1021 | 1009 | ||
1022 | return 0; | 1010 | return 0; |
1023 | 1011 | ||
1024 | err_register: | ||
1025 | device_unregister(&gpriv->gadget.dev); | ||
1026 | err_add_udc: | 1012 | err_add_udc: |
1027 | kfree(gpriv->uep); | 1013 | kfree(gpriv->uep); |
1028 | 1014 | ||
@@ -1038,8 +1024,6 @@ void usbhs_mod_gadget_remove(struct usbhs_priv *priv) | |||
1038 | 1024 | ||
1039 | usb_del_gadget_udc(&gpriv->gadget); | 1025 | usb_del_gadget_udc(&gpriv->gadget); |
1040 | 1026 | ||
1041 | device_unregister(&gpriv->gadget.dev); | ||
1042 | |||
1043 | kfree(gpriv->uep); | 1027 | kfree(gpriv->uep); |
1044 | kfree(gpriv); | 1028 | kfree(gpriv); |
1045 | } | 1029 | } |
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c index d29503e954ab..0db0a919d72b 100644 --- a/drivers/usb/usb-common.c +++ b/drivers/usb/usb-common.c | |||
@@ -14,6 +14,32 @@ | |||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/usb/ch9.h> | 16 | #include <linux/usb/ch9.h> |
17 | #include <linux/usb/otg.h> | ||
18 | |||
19 | const char *usb_otg_state_string(enum usb_otg_state state) | ||
20 | { | ||
21 | static const char *const names[] = { | ||
22 | [OTG_STATE_A_IDLE] = "a_idle", | ||
23 | [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise", | ||
24 | [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon", | ||
25 | [OTG_STATE_A_HOST] = "a_host", | ||
26 | [OTG_STATE_A_SUSPEND] = "a_suspend", | ||
27 | [OTG_STATE_A_PERIPHERAL] = "a_peripheral", | ||
28 | [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall", | ||
29 | [OTG_STATE_A_VBUS_ERR] = "a_vbus_err", | ||
30 | [OTG_STATE_B_IDLE] = "b_idle", | ||
31 | [OTG_STATE_B_SRP_INIT] = "b_srp_init", | ||
32 | [OTG_STATE_B_PERIPHERAL] = "b_peripheral", | ||
33 | [OTG_STATE_B_WAIT_ACON] = "b_wait_acon", | ||
34 | [OTG_STATE_B_HOST] = "b_host", | ||
35 | }; | ||
36 | |||
37 | if (state < 0 || state >= ARRAY_SIZE(names)) | ||
38 | return "UNDEFINED"; | ||
39 | |||
40 | return names[state]; | ||
41 | } | ||
42 | EXPORT_SYMBOL_GPL(usb_otg_state_string); | ||
17 | 43 | ||
18 | const char *usb_speed_string(enum usb_device_speed speed) | 44 | const char *usb_speed_string(enum usb_device_speed speed) |
19 | { | 45 | { |
@@ -32,4 +58,25 @@ const char *usb_speed_string(enum usb_device_speed speed) | |||
32 | } | 58 | } |
33 | EXPORT_SYMBOL_GPL(usb_speed_string); | 59 | EXPORT_SYMBOL_GPL(usb_speed_string); |
34 | 60 | ||
61 | const char *usb_state_string(enum usb_device_state state) | ||
62 | { | ||
63 | static const char *const names[] = { | ||
64 | [USB_STATE_NOTATTACHED] = "not attached", | ||
65 | [USB_STATE_ATTACHED] = "attached", | ||
66 | [USB_STATE_POWERED] = "powered", | ||
67 | [USB_STATE_RECONNECTING] = "reconnecting", | ||
68 | [USB_STATE_UNAUTHENTICATED] = "unauthenticated", | ||
69 | [USB_STATE_DEFAULT] = "default", | ||
70 | [USB_STATE_ADDRESS] = "addresssed", | ||
71 | [USB_STATE_CONFIGURED] = "configured", | ||
72 | [USB_STATE_SUSPENDED] = "suspended", | ||
73 | }; | ||
74 | |||
75 | if (state < 0 || state >= ARRAY_SIZE(names)) | ||
76 | return "UNKNOWN"; | ||
77 | |||
78 | return names[state]; | ||
79 | } | ||
80 | EXPORT_SYMBOL_GPL(usb_state_string); | ||
81 | |||
35 | MODULE_LICENSE("GPL"); | 82 | MODULE_LICENSE("GPL"); |