diff options
Diffstat (limited to 'drivers')
28 files changed, 4466 insertions, 249 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 6585f0b67801..b8e70a982fd4 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig | |||
@@ -64,6 +64,7 @@ config USB_ARCH_HAS_EHCI | |||
64 | default y if ARCH_OMAP3 | 64 | default y if ARCH_OMAP3 |
65 | default y if ARCH_VT8500 | 65 | default y if ARCH_VT8500 |
66 | default y if PLAT_SPEAR | 66 | default y if PLAT_SPEAR |
67 | default y if ARCH_MSM | ||
67 | default PCI | 68 | default PCI |
68 | 69 | ||
69 | # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. | 70 | # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 23fac3857477..a776c35ca980 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -427,8 +427,8 @@ config USB_FSL_QE | |||
427 | default USB_GADGET | 427 | default USB_GADGET |
428 | select USB_GADGET_SELECTED | 428 | select USB_GADGET_SELECTED |
429 | 429 | ||
430 | config USB_GADGET_CI13XXX | 430 | config USB_GADGET_CI13XXX_PCI |
431 | boolean "MIPS USB CI13xxx" | 431 | boolean "MIPS USB CI13xxx PCI UDC" |
432 | depends on PCI | 432 | depends on PCI |
433 | select USB_GADGET_DUALSPEED | 433 | select USB_GADGET_DUALSPEED |
434 | help | 434 | help |
@@ -439,9 +439,9 @@ config USB_GADGET_CI13XXX | |||
439 | dynamically linked module called "ci13xxx_udc" and force all | 439 | dynamically linked module called "ci13xxx_udc" and force all |
440 | gadget drivers to also be dynamically linked. | 440 | gadget drivers to also be dynamically linked. |
441 | 441 | ||
442 | config USB_CI13XXX | 442 | config USB_CI13XXX_PCI |
443 | tristate | 443 | tristate |
444 | depends on USB_GADGET_CI13XXX | 444 | depends on USB_GADGET_CI13XXX_PCI |
445 | default USB_GADGET | 445 | default USB_GADGET |
446 | select USB_GADGET_SELECTED | 446 | select USB_GADGET_SELECTED |
447 | 447 | ||
@@ -531,6 +531,27 @@ config USB_EG20T | |||
531 | default USB_GADGET | 531 | default USB_GADGET |
532 | select USB_GADGET_SELECTED | 532 | select USB_GADGET_SELECTED |
533 | 533 | ||
534 | config USB_GADGET_CI13XXX_MSM | ||
535 | boolean "MIPS USB CI13xxx for MSM" | ||
536 | depends on ARCH_MSM | ||
537 | select USB_GADGET_DUALSPEED | ||
538 | select USB_MSM_OTG_72K | ||
539 | help | ||
540 | MSM SoC has chipidea USB controller. This driver uses | ||
541 | ci13xxx_udc core. | ||
542 | This driver depends on OTG driver for PHY initialization, | ||
543 | clock management, powering up VBUS, and power management. | ||
544 | |||
545 | Say "y" to link the driver statically, or "m" to build a | ||
546 | dynamically linked module called "ci13xxx_msm" and force all | ||
547 | gadget drivers to also be dynamically linked. | ||
548 | |||
549 | config USB_CI13XXX_MSM | ||
550 | tristate | ||
551 | depends on USB_GADGET_CI13XXX_MSM | ||
552 | default USB_GADGET | ||
553 | select USB_GADGET_SELECTED | ||
554 | |||
534 | # | 555 | # |
535 | # LAST -- dummy/emulated controller | 556 | # LAST -- dummy/emulated controller |
536 | # | 557 | # |
@@ -720,6 +741,19 @@ config USB_ETH_EEM | |||
720 | If you say "y" here, the Ethernet gadget driver will use the EEM | 741 | If you say "y" here, the Ethernet gadget driver will use the EEM |
721 | protocol rather than ECM. If unsure, say "n". | 742 | protocol rather than ECM. If unsure, say "n". |
722 | 743 | ||
744 | config USB_G_NCM | ||
745 | tristate "Network Control Model (NCM) support" | ||
746 | depends on NET | ||
747 | select CRC32 | ||
748 | help | ||
749 | This driver implements USB CDC NCM subclass standard. NCM is | ||
750 | an advanced protocol for Ethernet encapsulation, allows grouping | ||
751 | of several ethernet frames into one USB transfer and diffferent | ||
752 | alignment possibilities. | ||
753 | |||
754 | Say "y" to link the driver statically, or "m" to build a | ||
755 | dynamically linked module called "g_ncm". | ||
756 | |||
723 | config USB_GADGETFS | 757 | config USB_GADGETFS |
724 | tristate "Gadget Filesystem (EXPERIMENTAL)" | 758 | tristate "Gadget Filesystem (EXPERIMENTAL)" |
725 | depends on EXPERIMENTAL | 759 | depends on EXPERIMENTAL |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index a3e6b90c11d7..55f5e8ae5924 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -21,12 +21,13 @@ fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o | |||
21 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 21 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
22 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | 22 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o |
23 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | 23 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o |
24 | obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o | 24 | obj-$(CONFIG_USB_CI13XXX_PCI) += ci13xxx_pci.o |
25 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o | 25 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o |
26 | obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o | 26 | obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o |
27 | obj-$(CONFIG_USB_EG20T) += pch_udc.o | 27 | obj-$(CONFIG_USB_EG20T) += pch_udc.o |
28 | obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o | 28 | obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o |
29 | mv_udc-y := mv_udc_core.o mv_udc_phy.o | 29 | mv_udc-y := mv_udc_core.o mv_udc_phy.o |
30 | obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o | ||
30 | 31 | ||
31 | # | 32 | # |
32 | # USB gadget drivers | 33 | # USB gadget drivers |
@@ -46,6 +47,7 @@ g_hid-y := hid.o | |||
46 | g_dbgp-y := dbgp.o | 47 | g_dbgp-y := dbgp.o |
47 | g_nokia-y := nokia.o | 48 | g_nokia-y := nokia.o |
48 | g_webcam-y := webcam.o | 49 | g_webcam-y := webcam.o |
50 | g_ncm-y := ncm.o | ||
49 | 51 | ||
50 | obj-$(CONFIG_USB_ZERO) += g_zero.o | 52 | obj-$(CONFIG_USB_ZERO) += g_zero.o |
51 | obj-$(CONFIG_USB_AUDIO) += g_audio.o | 53 | obj-$(CONFIG_USB_AUDIO) += g_audio.o |
@@ -63,3 +65,4 @@ obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o | |||
63 | obj-$(CONFIG_USB_G_MULTI) += g_multi.o | 65 | obj-$(CONFIG_USB_G_MULTI) += g_multi.o |
64 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o | 66 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o |
65 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o | 67 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o |
68 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o | ||
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c new file mode 100644 index 000000000000..139ac9419597 --- /dev/null +++ b/drivers/usb/gadget/ci13xxx_msm.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* Copyright (c) 2010, Code Aurora Forum. All rights reserved. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License version 2 and | ||
5 | * only version 2 as published by the Free Software Foundation. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
15 | * 02110-1301, USA. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/pm_runtime.h> | ||
22 | #include <linux/usb/msm_hsusb_hw.h> | ||
23 | #include <linux/usb/ulpi.h> | ||
24 | |||
25 | #include "ci13xxx_udc.c" | ||
26 | |||
27 | #define MSM_USB_BASE (udc->regs) | ||
28 | |||
29 | static irqreturn_t msm_udc_irq(int irq, void *data) | ||
30 | { | ||
31 | return udc_irq(); | ||
32 | } | ||
33 | |||
34 | static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event) | ||
35 | { | ||
36 | struct device *dev = udc->gadget.dev.parent; | ||
37 | int val; | ||
38 | |||
39 | switch (event) { | ||
40 | case CI13XXX_CONTROLLER_RESET_EVENT: | ||
41 | dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n"); | ||
42 | writel(0, USB_AHBBURST); | ||
43 | writel(0, USB_AHBMODE); | ||
44 | break; | ||
45 | case CI13XXX_CONTROLLER_STOPPED_EVENT: | ||
46 | dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n"); | ||
47 | /* | ||
48 | * Put the transceiver in non-driving mode. Otherwise host | ||
49 | * may not detect soft-disconnection. | ||
50 | */ | ||
51 | val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL); | ||
52 | val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; | ||
53 | val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; | ||
54 | otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL); | ||
55 | break; | ||
56 | default: | ||
57 | dev_dbg(dev, "unknown ci13xxx_udc event\n"); | ||
58 | break; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = { | ||
63 | .name = "ci13xxx_msm", | ||
64 | .flags = CI13XXX_REGS_SHARED | | ||
65 | CI13XXX_REQUIRE_TRANSCEIVER | | ||
66 | CI13XXX_PULLUP_ON_VBUS | | ||
67 | CI13XXX_DISABLE_STREAMING, | ||
68 | |||
69 | .notify_event = ci13xxx_msm_notify_event, | ||
70 | }; | ||
71 | |||
72 | static int ci13xxx_msm_probe(struct platform_device *pdev) | ||
73 | { | ||
74 | struct resource *res; | ||
75 | void __iomem *regs; | ||
76 | int irq; | ||
77 | int ret; | ||
78 | |||
79 | dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); | ||
80 | |||
81 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
82 | if (!res) { | ||
83 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); | ||
84 | return -ENXIO; | ||
85 | } | ||
86 | |||
87 | regs = ioremap(res->start, resource_size(res)); | ||
88 | if (!regs) { | ||
89 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
90 | return -ENOMEM; | ||
91 | } | ||
92 | |||
93 | ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs); | ||
94 | if (ret < 0) { | ||
95 | dev_err(&pdev->dev, "udc_probe failed\n"); | ||
96 | goto iounmap; | ||
97 | } | ||
98 | |||
99 | irq = platform_get_irq(pdev, 0); | ||
100 | if (irq < 0) { | ||
101 | dev_err(&pdev->dev, "IRQ not found\n"); | ||
102 | ret = -ENXIO; | ||
103 | goto udc_remove; | ||
104 | } | ||
105 | |||
106 | ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev); | ||
107 | if (ret < 0) { | ||
108 | dev_err(&pdev->dev, "request_irq failed\n"); | ||
109 | goto udc_remove; | ||
110 | } | ||
111 | |||
112 | pm_runtime_no_callbacks(&pdev->dev); | ||
113 | pm_runtime_enable(&pdev->dev); | ||
114 | |||
115 | return 0; | ||
116 | |||
117 | udc_remove: | ||
118 | udc_remove(); | ||
119 | iounmap: | ||
120 | iounmap(regs); | ||
121 | |||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | static struct platform_driver ci13xxx_msm_driver = { | ||
126 | .probe = ci13xxx_msm_probe, | ||
127 | .driver = { .name = "msm_hsusb", }, | ||
128 | }; | ||
129 | |||
130 | static int __init ci13xxx_msm_init(void) | ||
131 | { | ||
132 | return platform_driver_register(&ci13xxx_msm_driver); | ||
133 | } | ||
134 | module_init(ci13xxx_msm_init); | ||
diff --git a/drivers/usb/gadget/ci13xxx_pci.c b/drivers/usb/gadget/ci13xxx_pci.c new file mode 100644 index 000000000000..883ab5e832d1 --- /dev/null +++ b/drivers/usb/gadget/ci13xxx_pci.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * ci13xxx_pci.c - MIPS USB IP core family device controller | ||
3 | * | ||
4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | ||
5 | * | ||
6 | * Author: David Lopo | ||
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/pci.h> | ||
15 | |||
16 | #include "ci13xxx_udc.c" | ||
17 | |||
18 | /* driver name */ | ||
19 | #define UDC_DRIVER_NAME "ci13xxx_pci" | ||
20 | |||
21 | /****************************************************************************** | ||
22 | * PCI block | ||
23 | *****************************************************************************/ | ||
24 | /** | ||
25 | * ci13xxx_pci_irq: interrut handler | ||
26 | * @irq: irq number | ||
27 | * @pdev: USB Device Controller interrupt source | ||
28 | * | ||
29 | * This function returns IRQ_HANDLED if the IRQ has been handled | ||
30 | * This is an ISR don't trace, use attribute interface instead | ||
31 | */ | ||
32 | static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev) | ||
33 | { | ||
34 | if (irq == 0) { | ||
35 | dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!"); | ||
36 | return IRQ_HANDLED; | ||
37 | } | ||
38 | return udc_irq(); | ||
39 | } | ||
40 | |||
41 | static struct ci13xxx_udc_driver ci13xxx_pci_udc_driver = { | ||
42 | .name = UDC_DRIVER_NAME, | ||
43 | }; | ||
44 | |||
45 | /** | ||
46 | * ci13xxx_pci_probe: PCI probe | ||
47 | * @pdev: USB device controller being probed | ||
48 | * @id: PCI hotplug ID connecting controller to UDC framework | ||
49 | * | ||
50 | * This function returns an error code | ||
51 | * Allocates basic PCI resources for this USB device controller, and then | ||
52 | * invokes the udc_probe() method to start the UDC associated with it | ||
53 | */ | ||
54 | static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, | ||
55 | const struct pci_device_id *id) | ||
56 | { | ||
57 | void __iomem *regs = NULL; | ||
58 | int retval = 0; | ||
59 | |||
60 | if (id == NULL) | ||
61 | return -EINVAL; | ||
62 | |||
63 | retval = pci_enable_device(pdev); | ||
64 | if (retval) | ||
65 | goto done; | ||
66 | |||
67 | if (!pdev->irq) { | ||
68 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); | ||
69 | retval = -ENODEV; | ||
70 | goto disable_device; | ||
71 | } | ||
72 | |||
73 | retval = pci_request_regions(pdev, UDC_DRIVER_NAME); | ||
74 | if (retval) | ||
75 | goto disable_device; | ||
76 | |||
77 | /* BAR 0 holds all the registers */ | ||
78 | regs = pci_iomap(pdev, 0, 0); | ||
79 | if (!regs) { | ||
80 | dev_err(&pdev->dev, "Error mapping memory!"); | ||
81 | retval = -EFAULT; | ||
82 | goto release_regions; | ||
83 | } | ||
84 | pci_set_drvdata(pdev, (__force void *)regs); | ||
85 | |||
86 | pci_set_master(pdev); | ||
87 | pci_try_set_mwi(pdev); | ||
88 | |||
89 | retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs); | ||
90 | if (retval) | ||
91 | goto iounmap; | ||
92 | |||
93 | /* our device does not have MSI capability */ | ||
94 | |||
95 | retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED, | ||
96 | UDC_DRIVER_NAME, pdev); | ||
97 | if (retval) | ||
98 | goto gadget_remove; | ||
99 | |||
100 | return 0; | ||
101 | |||
102 | gadget_remove: | ||
103 | udc_remove(); | ||
104 | iounmap: | ||
105 | pci_iounmap(pdev, regs); | ||
106 | release_regions: | ||
107 | pci_release_regions(pdev); | ||
108 | disable_device: | ||
109 | pci_disable_device(pdev); | ||
110 | done: | ||
111 | return retval; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * ci13xxx_pci_remove: PCI remove | ||
116 | * @pdev: USB Device Controller being removed | ||
117 | * | ||
118 | * Reverses the effect of ci13xxx_pci_probe(), | ||
119 | * first invoking the udc_remove() and then releases | ||
120 | * all PCI resources allocated for this USB device controller | ||
121 | */ | ||
122 | static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev) | ||
123 | { | ||
124 | free_irq(pdev->irq, pdev); | ||
125 | udc_remove(); | ||
126 | pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev)); | ||
127 | pci_release_regions(pdev); | ||
128 | pci_disable_device(pdev); | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * PCI device table | ||
133 | * PCI device structure | ||
134 | * | ||
135 | * Check "pci.h" for details | ||
136 | */ | ||
137 | static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = { | ||
138 | { PCI_DEVICE(0x153F, 0x1004) }, | ||
139 | { PCI_DEVICE(0x153F, 0x1006) }, | ||
140 | { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } | ||
141 | }; | ||
142 | MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table); | ||
143 | |||
144 | static struct pci_driver ci13xxx_pci_driver = { | ||
145 | .name = UDC_DRIVER_NAME, | ||
146 | .id_table = ci13xxx_pci_id_table, | ||
147 | .probe = ci13xxx_pci_probe, | ||
148 | .remove = __devexit_p(ci13xxx_pci_remove), | ||
149 | }; | ||
150 | |||
151 | /** | ||
152 | * ci13xxx_pci_init: module init | ||
153 | * | ||
154 | * Driver load | ||
155 | */ | ||
156 | static int __init ci13xxx_pci_init(void) | ||
157 | { | ||
158 | return pci_register_driver(&ci13xxx_pci_driver); | ||
159 | } | ||
160 | module_init(ci13xxx_pci_init); | ||
161 | |||
162 | /** | ||
163 | * ci13xxx_pci_exit: module exit | ||
164 | * | ||
165 | * Driver unload | ||
166 | */ | ||
167 | static void __exit ci13xxx_pci_exit(void) | ||
168 | { | ||
169 | pci_unregister_driver(&ci13xxx_pci_driver); | ||
170 | } | ||
171 | module_exit(ci13xxx_pci_exit); | ||
172 | |||
173 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); | ||
174 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); | ||
175 | MODULE_LICENSE("GPL"); | ||
176 | MODULE_VERSION("June 2008"); | ||
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c index 98b36fc88c77..f200e472e476 100644 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ b/drivers/usb/gadget/ci13xxx_udc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | * - ENDPT: endpoint operations (Gadget API) | 22 | * - ENDPT: endpoint operations (Gadget API) |
23 | * - GADGET: gadget operations (Gadget API) | 23 | * - GADGET: gadget operations (Gadget API) |
24 | * - BUS: bus glue code, bus abstraction layer | 24 | * - BUS: bus glue code, bus abstraction layer |
25 | * - PCI: PCI core interface and PCI resources (interrupts, memory...) | ||
26 | * | 25 | * |
27 | * Compile Options | 26 | * Compile Options |
28 | * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities | 27 | * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities |
@@ -60,11 +59,11 @@ | |||
60 | #include <linux/io.h> | 59 | #include <linux/io.h> |
61 | #include <linux/irq.h> | 60 | #include <linux/irq.h> |
62 | #include <linux/kernel.h> | 61 | #include <linux/kernel.h> |
63 | #include <linux/module.h> | ||
64 | #include <linux/pci.h> | ||
65 | #include <linux/slab.h> | 62 | #include <linux/slab.h> |
63 | #include <linux/pm_runtime.h> | ||
66 | #include <linux/usb/ch9.h> | 64 | #include <linux/usb/ch9.h> |
67 | #include <linux/usb/gadget.h> | 65 | #include <linux/usb/gadget.h> |
66 | #include <linux/usb/otg.h> | ||
68 | 67 | ||
69 | #include "ci13xxx_udc.h" | 68 | #include "ci13xxx_udc.h" |
70 | 69 | ||
@@ -75,9 +74,6 @@ | |||
75 | /* ctrl register bank access */ | 74 | /* ctrl register bank access */ |
76 | static DEFINE_SPINLOCK(udc_lock); | 75 | static DEFINE_SPINLOCK(udc_lock); |
77 | 76 | ||
78 | /* driver name */ | ||
79 | #define UDC_DRIVER_NAME "ci13xxx_udc" | ||
80 | |||
81 | /* control endpoint description */ | 77 | /* control endpoint description */ |
82 | static const struct usb_endpoint_descriptor | 78 | static const struct usb_endpoint_descriptor |
83 | ctrl_endpt_desc = { | 79 | ctrl_endpt_desc = { |
@@ -132,6 +128,9 @@ static struct { | |||
132 | size_t size; /* bank size */ | 128 | size_t size; /* bank size */ |
133 | } hw_bank; | 129 | } hw_bank; |
134 | 130 | ||
131 | /* MSM specific */ | ||
132 | #define ABS_AHBBURST (0x0090UL) | ||
133 | #define ABS_AHBMODE (0x0098UL) | ||
135 | /* UDC register map */ | 134 | /* UDC register map */ |
136 | #define ABS_CAPLENGTH (0x100UL) | 135 | #define ABS_CAPLENGTH (0x100UL) |
137 | #define ABS_HCCPARAMS (0x108UL) | 136 | #define ABS_HCCPARAMS (0x108UL) |
@@ -248,13 +247,7 @@ static u32 hw_ctest_and_write(u32 addr, u32 mask, u32 data) | |||
248 | return (reg & mask) >> ffs_nr(mask); | 247 | return (reg & mask) >> ffs_nr(mask); |
249 | } | 248 | } |
250 | 249 | ||
251 | /** | 250 | static int hw_device_init(void __iomem *base) |
252 | * hw_device_reset: resets chip (execute without interruption) | ||
253 | * @base: register base address | ||
254 | * | ||
255 | * This function returns an error code | ||
256 | */ | ||
257 | static int hw_device_reset(void __iomem *base) | ||
258 | { | 251 | { |
259 | u32 reg; | 252 | u32 reg; |
260 | 253 | ||
@@ -271,6 +264,28 @@ static int hw_device_reset(void __iomem *base) | |||
271 | hw_bank.size += CAP_LAST; | 264 | hw_bank.size += CAP_LAST; |
272 | hw_bank.size /= sizeof(u32); | 265 | hw_bank.size /= sizeof(u32); |
273 | 266 | ||
267 | reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN); | ||
268 | if (reg == 0 || reg > ENDPT_MAX) | ||
269 | return -ENODEV; | ||
270 | |||
271 | hw_ep_max = reg; /* cache hw ENDPT_MAX */ | ||
272 | |||
273 | /* setup lock mode ? */ | ||
274 | |||
275 | /* ENDPTSETUPSTAT is '0' by default */ | ||
276 | |||
277 | /* HCSPARAMS.bf.ppc SHOULD BE zero for device */ | ||
278 | |||
279 | return 0; | ||
280 | } | ||
281 | /** | ||
282 | * hw_device_reset: resets chip (execute without interruption) | ||
283 | * @base: register base address | ||
284 | * | ||
285 | * This function returns an error code | ||
286 | */ | ||
287 | static int hw_device_reset(struct ci13xxx *udc) | ||
288 | { | ||
274 | /* should flush & stop before reset */ | 289 | /* should flush & stop before reset */ |
275 | hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); | 290 | hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); |
276 | hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); | 291 | hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); |
@@ -279,6 +294,14 @@ static int hw_device_reset(void __iomem *base) | |||
279 | while (hw_cread(CAP_USBCMD, USBCMD_RST)) | 294 | while (hw_cread(CAP_USBCMD, USBCMD_RST)) |
280 | udelay(10); /* not RTOS friendly */ | 295 | udelay(10); /* not RTOS friendly */ |
281 | 296 | ||
297 | |||
298 | if (udc->udc_driver->notify_event) | ||
299 | udc->udc_driver->notify_event(udc, | ||
300 | CI13XXX_CONTROLLER_RESET_EVENT); | ||
301 | |||
302 | if (udc->udc_driver->flags && CI13XXX_DISABLE_STREAMING) | ||
303 | hw_cwrite(CAP_USBMODE, USBMODE_SDIS, USBMODE_SDIS); | ||
304 | |||
282 | /* USBMODE should be configured step by step */ | 305 | /* USBMODE should be configured step by step */ |
283 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); | 306 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); |
284 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); | 307 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); |
@@ -290,18 +313,6 @@ static int hw_device_reset(void __iomem *base) | |||
290 | return -ENODEV; | 313 | return -ENODEV; |
291 | } | 314 | } |
292 | 315 | ||
293 | reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN); | ||
294 | if (reg == 0 || reg > ENDPT_MAX) | ||
295 | return -ENODEV; | ||
296 | |||
297 | hw_ep_max = reg; /* cache hw ENDPT_MAX */ | ||
298 | |||
299 | /* setup lock mode ? */ | ||
300 | |||
301 | /* ENDPTSETUPSTAT is '0' by default */ | ||
302 | |||
303 | /* HCSPARAMS.bf.ppc SHOULD BE zero for device */ | ||
304 | |||
305 | return 0; | 316 | return 0; |
306 | } | 317 | } |
307 | 318 | ||
@@ -1557,8 +1568,6 @@ __acquires(mEp->lock) | |||
1557 | * Caller must hold lock | 1568 | * Caller must hold lock |
1558 | */ | 1569 | */ |
1559 | static int _gadget_stop_activity(struct usb_gadget *gadget) | 1570 | static int _gadget_stop_activity(struct usb_gadget *gadget) |
1560 | __releases(udc->lock) | ||
1561 | __acquires(udc->lock) | ||
1562 | { | 1571 | { |
1563 | struct usb_ep *ep; | 1572 | struct usb_ep *ep; |
1564 | struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); | 1573 | struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); |
@@ -1570,8 +1579,6 @@ __acquires(udc->lock) | |||
1570 | if (gadget == NULL) | 1579 | if (gadget == NULL) |
1571 | return -EINVAL; | 1580 | return -EINVAL; |
1572 | 1581 | ||
1573 | spin_unlock(udc->lock); | ||
1574 | |||
1575 | /* flush all endpoints */ | 1582 | /* flush all endpoints */ |
1576 | gadget_for_each_ep(ep, gadget) { | 1583 | gadget_for_each_ep(ep, gadget) { |
1577 | usb_ep_fifo_flush(ep); | 1584 | usb_ep_fifo_flush(ep); |
@@ -1591,8 +1598,6 @@ __acquires(udc->lock) | |||
1591 | mEp->status = NULL; | 1598 | mEp->status = NULL; |
1592 | } | 1599 | } |
1593 | 1600 | ||
1594 | spin_lock(udc->lock); | ||
1595 | |||
1596 | return 0; | 1601 | return 0; |
1597 | } | 1602 | } |
1598 | 1603 | ||
@@ -1621,6 +1626,7 @@ __acquires(udc->lock) | |||
1621 | 1626 | ||
1622 | dbg_event(0xFF, "BUS RST", 0); | 1627 | dbg_event(0xFF, "BUS RST", 0); |
1623 | 1628 | ||
1629 | spin_unlock(udc->lock); | ||
1624 | retval = _gadget_stop_activity(&udc->gadget); | 1630 | retval = _gadget_stop_activity(&udc->gadget); |
1625 | if (retval) | 1631 | if (retval) |
1626 | goto done; | 1632 | goto done; |
@@ -1629,10 +1635,9 @@ __acquires(udc->lock) | |||
1629 | if (retval) | 1635 | if (retval) |
1630 | goto done; | 1636 | goto done; |
1631 | 1637 | ||
1632 | spin_unlock(udc->lock); | ||
1633 | retval = usb_ep_enable(&mEp->ep, &ctrl_endpt_desc); | 1638 | retval = usb_ep_enable(&mEp->ep, &ctrl_endpt_desc); |
1634 | if (!retval) { | 1639 | if (!retval) { |
1635 | mEp->status = usb_ep_alloc_request(&mEp->ep, GFP_KERNEL); | 1640 | mEp->status = usb_ep_alloc_request(&mEp->ep, GFP_ATOMIC); |
1636 | if (mEp->status == NULL) { | 1641 | if (mEp->status == NULL) { |
1637 | usb_ep_disable(&mEp->ep); | 1642 | usb_ep_disable(&mEp->ep); |
1638 | retval = -ENOMEM; | 1643 | retval = -ENOMEM; |
@@ -2061,7 +2066,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | |||
2061 | { | 2066 | { |
2062 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | 2067 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); |
2063 | struct ci13xxx_req *mReq = NULL; | 2068 | struct ci13xxx_req *mReq = NULL; |
2064 | unsigned long flags; | ||
2065 | 2069 | ||
2066 | trace("%p, %i", ep, gfp_flags); | 2070 | trace("%p, %i", ep, gfp_flags); |
2067 | 2071 | ||
@@ -2070,8 +2074,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | |||
2070 | return NULL; | 2074 | return NULL; |
2071 | } | 2075 | } |
2072 | 2076 | ||
2073 | spin_lock_irqsave(mEp->lock, flags); | ||
2074 | |||
2075 | mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags); | 2077 | mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags); |
2076 | if (mReq != NULL) { | 2078 | if (mReq != NULL) { |
2077 | INIT_LIST_HEAD(&mReq->queue); | 2079 | INIT_LIST_HEAD(&mReq->queue); |
@@ -2086,8 +2088,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | |||
2086 | 2088 | ||
2087 | dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL); | 2089 | dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL); |
2088 | 2090 | ||
2089 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2090 | |||
2091 | return (mReq == NULL) ? NULL : &mReq->req; | 2091 | return (mReq == NULL) ? NULL : &mReq->req; |
2092 | } | 2092 | } |
2093 | 2093 | ||
@@ -2332,12 +2332,47 @@ static const struct usb_ep_ops usb_ep_ops = { | |||
2332 | /****************************************************************************** | 2332 | /****************************************************************************** |
2333 | * GADGET block | 2333 | * GADGET block |
2334 | *****************************************************************************/ | 2334 | *****************************************************************************/ |
2335 | static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) | ||
2336 | { | ||
2337 | struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); | ||
2338 | unsigned long flags; | ||
2339 | int gadget_ready = 0; | ||
2340 | |||
2341 | if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS)) | ||
2342 | return -EOPNOTSUPP; | ||
2343 | |||
2344 | spin_lock_irqsave(udc->lock, flags); | ||
2345 | udc->vbus_active = is_active; | ||
2346 | if (udc->driver) | ||
2347 | gadget_ready = 1; | ||
2348 | spin_unlock_irqrestore(udc->lock, flags); | ||
2349 | |||
2350 | if (gadget_ready) { | ||
2351 | if (is_active) { | ||
2352 | pm_runtime_get_sync(&_gadget->dev); | ||
2353 | hw_device_reset(udc); | ||
2354 | hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma); | ||
2355 | } else { | ||
2356 | hw_device_state(0); | ||
2357 | if (udc->udc_driver->notify_event) | ||
2358 | udc->udc_driver->notify_event(udc, | ||
2359 | CI13XXX_CONTROLLER_STOPPED_EVENT); | ||
2360 | _gadget_stop_activity(&udc->gadget); | ||
2361 | pm_runtime_put_sync(&_gadget->dev); | ||
2362 | } | ||
2363 | } | ||
2364 | |||
2365 | return 0; | ||
2366 | } | ||
2367 | |||
2335 | /** | 2368 | /** |
2336 | * Device operations part of the API to the USB controller hardware, | 2369 | * Device operations part of the API to the USB controller hardware, |
2337 | * which don't involve endpoints (or i/o) | 2370 | * which don't involve endpoints (or i/o) |
2338 | * Check "usb_gadget.h" for details | 2371 | * Check "usb_gadget.h" for details |
2339 | */ | 2372 | */ |
2340 | static const struct usb_gadget_ops usb_gadget_ops; | 2373 | static const struct usb_gadget_ops usb_gadget_ops = { |
2374 | .vbus_session = ci13xxx_vbus_session, | ||
2375 | }; | ||
2341 | 2376 | ||
2342 | /** | 2377 | /** |
2343 | * usb_gadget_probe_driver: register a gadget driver | 2378 | * usb_gadget_probe_driver: register a gadget driver |
@@ -2390,7 +2425,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2390 | info("hw_ep_max = %d", hw_ep_max); | 2425 | info("hw_ep_max = %d", hw_ep_max); |
2391 | 2426 | ||
2392 | udc->driver = driver; | 2427 | udc->driver = driver; |
2393 | udc->gadget.ops = NULL; | ||
2394 | udc->gadget.dev.driver = NULL; | 2428 | udc->gadget.dev.driver = NULL; |
2395 | 2429 | ||
2396 | retval = 0; | 2430 | retval = 0; |
@@ -2410,9 +2444,11 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2410 | /* this allocation cannot be random */ | 2444 | /* this allocation cannot be random */ |
2411 | for (k = RX; k <= TX; k++) { | 2445 | for (k = RX; k <= TX; k++) { |
2412 | INIT_LIST_HEAD(&mEp->qh[k].queue); | 2446 | INIT_LIST_HEAD(&mEp->qh[k].queue); |
2447 | spin_unlock_irqrestore(udc->lock, flags); | ||
2413 | mEp->qh[k].ptr = dma_pool_alloc(udc->qh_pool, | 2448 | mEp->qh[k].ptr = dma_pool_alloc(udc->qh_pool, |
2414 | GFP_KERNEL, | 2449 | GFP_KERNEL, |
2415 | &mEp->qh[k].dma); | 2450 | &mEp->qh[k].dma); |
2451 | spin_lock_irqsave(udc->lock, flags); | ||
2416 | if (mEp->qh[k].ptr == NULL) | 2452 | if (mEp->qh[k].ptr == NULL) |
2417 | retval = -ENOMEM; | 2453 | retval = -ENOMEM; |
2418 | else | 2454 | else |
@@ -2429,7 +2465,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2429 | 2465 | ||
2430 | /* bind gadget */ | 2466 | /* bind gadget */ |
2431 | driver->driver.bus = NULL; | 2467 | driver->driver.bus = NULL; |
2432 | udc->gadget.ops = &usb_gadget_ops; | ||
2433 | udc->gadget.dev.driver = &driver->driver; | 2468 | udc->gadget.dev.driver = &driver->driver; |
2434 | 2469 | ||
2435 | spin_unlock_irqrestore(udc->lock, flags); | 2470 | spin_unlock_irqrestore(udc->lock, flags); |
@@ -2437,12 +2472,24 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2437 | spin_lock_irqsave(udc->lock, flags); | 2472 | spin_lock_irqsave(udc->lock, flags); |
2438 | 2473 | ||
2439 | if (retval) { | 2474 | if (retval) { |
2440 | udc->gadget.ops = NULL; | ||
2441 | udc->gadget.dev.driver = NULL; | 2475 | udc->gadget.dev.driver = NULL; |
2442 | goto done; | 2476 | goto done; |
2443 | } | 2477 | } |
2444 | 2478 | ||
2479 | pm_runtime_get_sync(&udc->gadget.dev); | ||
2480 | if (udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) { | ||
2481 | if (udc->vbus_active) { | ||
2482 | if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) | ||
2483 | hw_device_reset(udc); | ||
2484 | } else { | ||
2485 | pm_runtime_put_sync(&udc->gadget.dev); | ||
2486 | goto done; | ||
2487 | } | ||
2488 | } | ||
2489 | |||
2445 | retval = hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma); | 2490 | retval = hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma); |
2491 | if (retval) | ||
2492 | pm_runtime_put_sync(&udc->gadget.dev); | ||
2446 | 2493 | ||
2447 | done: | 2494 | done: |
2448 | spin_unlock_irqrestore(udc->lock, flags); | 2495 | spin_unlock_irqrestore(udc->lock, flags); |
@@ -2475,19 +2522,22 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2475 | 2522 | ||
2476 | spin_lock_irqsave(udc->lock, flags); | 2523 | spin_lock_irqsave(udc->lock, flags); |
2477 | 2524 | ||
2478 | hw_device_state(0); | 2525 | if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) || |
2479 | 2526 | udc->vbus_active) { | |
2480 | /* unbind gadget */ | 2527 | hw_device_state(0); |
2481 | if (udc->gadget.ops != NULL) { | 2528 | if (udc->udc_driver->notify_event) |
2529 | udc->udc_driver->notify_event(udc, | ||
2530 | CI13XXX_CONTROLLER_STOPPED_EVENT); | ||
2482 | _gadget_stop_activity(&udc->gadget); | 2531 | _gadget_stop_activity(&udc->gadget); |
2532 | pm_runtime_put(&udc->gadget.dev); | ||
2533 | } | ||
2483 | 2534 | ||
2484 | spin_unlock_irqrestore(udc->lock, flags); | 2535 | /* unbind gadget */ |
2485 | driver->unbind(&udc->gadget); /* MAY SLEEP */ | 2536 | spin_unlock_irqrestore(udc->lock, flags); |
2486 | spin_lock_irqsave(udc->lock, flags); | 2537 | driver->unbind(&udc->gadget); /* MAY SLEEP */ |
2538 | spin_lock_irqsave(udc->lock, flags); | ||
2487 | 2539 | ||
2488 | udc->gadget.ops = NULL; | 2540 | udc->gadget.dev.driver = NULL; |
2489 | udc->gadget.dev.driver = NULL; | ||
2490 | } | ||
2491 | 2541 | ||
2492 | /* free resources */ | 2542 | /* free resources */ |
2493 | for (i = 0; i < hw_ep_max; i++) { | 2543 | for (i = 0; i < hw_ep_max; i++) { |
@@ -2544,6 +2594,14 @@ static irqreturn_t udc_irq(void) | |||
2544 | } | 2594 | } |
2545 | 2595 | ||
2546 | spin_lock(udc->lock); | 2596 | spin_lock(udc->lock); |
2597 | |||
2598 | if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { | ||
2599 | if (hw_cread(CAP_USBMODE, USBMODE_CM) != | ||
2600 | USBMODE_CM_DEVICE) { | ||
2601 | spin_unlock(udc->lock); | ||
2602 | return IRQ_NONE; | ||
2603 | } | ||
2604 | } | ||
2547 | intr = hw_test_and_clear_intr_active(); | 2605 | intr = hw_test_and_clear_intr_active(); |
2548 | if (intr) { | 2606 | if (intr) { |
2549 | isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr; | 2607 | isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr; |
@@ -2602,14 +2660,16 @@ static void udc_release(struct device *dev) | |||
2602 | * No interrupts active, the IRQ has not been requested yet | 2660 | * No interrupts active, the IRQ has not been requested yet |
2603 | * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask | 2661 | * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask |
2604 | */ | 2662 | */ |
2605 | static int udc_probe(struct device *dev, void __iomem *regs, const char *name) | 2663 | static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, |
2664 | void __iomem *regs) | ||
2606 | { | 2665 | { |
2607 | struct ci13xxx *udc; | 2666 | struct ci13xxx *udc; |
2608 | int retval = 0; | 2667 | int retval = 0; |
2609 | 2668 | ||
2610 | trace("%p, %p, %p", dev, regs, name); | 2669 | trace("%p, %p, %p", dev, regs, name); |
2611 | 2670 | ||
2612 | if (dev == NULL || regs == NULL || name == NULL) | 2671 | if (dev == NULL || regs == NULL || driver == NULL || |
2672 | driver->name == NULL) | ||
2613 | return -EINVAL; | 2673 | return -EINVAL; |
2614 | 2674 | ||
2615 | udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL); | 2675 | udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL); |
@@ -2617,42 +2677,77 @@ static int udc_probe(struct device *dev, void __iomem *regs, const char *name) | |||
2617 | return -ENOMEM; | 2677 | return -ENOMEM; |
2618 | 2678 | ||
2619 | udc->lock = &udc_lock; | 2679 | udc->lock = &udc_lock; |
2680 | udc->regs = regs; | ||
2681 | udc->udc_driver = driver; | ||
2620 | 2682 | ||
2621 | retval = hw_device_reset(regs); | 2683 | udc->gadget.ops = &usb_gadget_ops; |
2622 | if (retval) | ||
2623 | goto done; | ||
2624 | |||
2625 | udc->gadget.ops = NULL; | ||
2626 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 2684 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
2627 | udc->gadget.is_dualspeed = 1; | 2685 | udc->gadget.is_dualspeed = 1; |
2628 | udc->gadget.is_otg = 0; | 2686 | udc->gadget.is_otg = 0; |
2629 | udc->gadget.name = name; | 2687 | udc->gadget.name = driver->name; |
2630 | 2688 | ||
2631 | INIT_LIST_HEAD(&udc->gadget.ep_list); | 2689 | INIT_LIST_HEAD(&udc->gadget.ep_list); |
2632 | udc->gadget.ep0 = NULL; | 2690 | udc->gadget.ep0 = NULL; |
2633 | 2691 | ||
2634 | dev_set_name(&udc->gadget.dev, "gadget"); | 2692 | dev_set_name(&udc->gadget.dev, "gadget"); |
2635 | udc->gadget.dev.dma_mask = dev->dma_mask; | 2693 | udc->gadget.dev.dma_mask = dev->dma_mask; |
2694 | udc->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask; | ||
2636 | udc->gadget.dev.parent = dev; | 2695 | udc->gadget.dev.parent = dev; |
2637 | udc->gadget.dev.release = udc_release; | 2696 | udc->gadget.dev.release = udc_release; |
2638 | 2697 | ||
2698 | retval = hw_device_init(regs); | ||
2699 | if (retval < 0) | ||
2700 | goto free_udc; | ||
2701 | |||
2702 | udc->transceiver = otg_get_transceiver(); | ||
2703 | |||
2704 | if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) { | ||
2705 | if (udc->transceiver == NULL) { | ||
2706 | retval = -ENODEV; | ||
2707 | goto free_udc; | ||
2708 | } | ||
2709 | } | ||
2710 | |||
2711 | if (!(udc->udc_driver->flags & CI13XXX_REGS_SHARED)) { | ||
2712 | retval = hw_device_reset(udc); | ||
2713 | if (retval) | ||
2714 | goto put_transceiver; | ||
2715 | } | ||
2716 | |||
2639 | retval = device_register(&udc->gadget.dev); | 2717 | retval = device_register(&udc->gadget.dev); |
2640 | if (retval) | 2718 | if (retval) { |
2641 | goto done; | 2719 | put_device(&udc->gadget.dev); |
2720 | goto put_transceiver; | ||
2721 | } | ||
2642 | 2722 | ||
2643 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 2723 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
2644 | retval = dbg_create_files(&udc->gadget.dev); | 2724 | retval = dbg_create_files(&udc->gadget.dev); |
2645 | #endif | 2725 | #endif |
2646 | if (retval) { | 2726 | if (retval) |
2647 | device_unregister(&udc->gadget.dev); | 2727 | goto unreg_device; |
2648 | goto done; | 2728 | |
2729 | if (udc->transceiver) { | ||
2730 | retval = otg_set_peripheral(udc->transceiver, &udc->gadget); | ||
2731 | if (retval) | ||
2732 | goto remove_dbg; | ||
2649 | } | 2733 | } |
2734 | pm_runtime_no_callbacks(&udc->gadget.dev); | ||
2735 | pm_runtime_enable(&udc->gadget.dev); | ||
2650 | 2736 | ||
2651 | _udc = udc; | 2737 | _udc = udc; |
2652 | return retval; | 2738 | return retval; |
2653 | 2739 | ||
2654 | done: | ||
2655 | err("error = %i", retval); | 2740 | err("error = %i", retval); |
2741 | remove_dbg: | ||
2742 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2743 | dbg_remove_files(&udc->gadget.dev); | ||
2744 | #endif | ||
2745 | unreg_device: | ||
2746 | device_unregister(&udc->gadget.dev); | ||
2747 | put_transceiver: | ||
2748 | if (udc->transceiver) | ||
2749 | otg_put_transceiver(udc->transceiver); | ||
2750 | free_udc: | ||
2656 | kfree(udc); | 2751 | kfree(udc); |
2657 | _udc = NULL; | 2752 | _udc = NULL; |
2658 | return retval; | 2753 | return retval; |
@@ -2672,6 +2767,10 @@ static void udc_remove(void) | |||
2672 | return; | 2767 | return; |
2673 | } | 2768 | } |
2674 | 2769 | ||
2770 | if (udc->transceiver) { | ||
2771 | otg_set_peripheral(udc->transceiver, &udc->gadget); | ||
2772 | otg_put_transceiver(udc->transceiver); | ||
2773 | } | ||
2675 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 2774 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
2676 | dbg_remove_files(&udc->gadget.dev); | 2775 | dbg_remove_files(&udc->gadget.dev); |
2677 | #endif | 2776 | #endif |
@@ -2680,156 +2779,3 @@ static void udc_remove(void) | |||
2680 | kfree(udc); | 2779 | kfree(udc); |
2681 | _udc = NULL; | 2780 | _udc = NULL; |
2682 | } | 2781 | } |
2683 | |||
2684 | /****************************************************************************** | ||
2685 | * PCI block | ||
2686 | *****************************************************************************/ | ||
2687 | /** | ||
2688 | * ci13xxx_pci_irq: interrut handler | ||
2689 | * @irq: irq number | ||
2690 | * @pdev: USB Device Controller interrupt source | ||
2691 | * | ||
2692 | * This function returns IRQ_HANDLED if the IRQ has been handled | ||
2693 | * This is an ISR don't trace, use attribute interface instead | ||
2694 | */ | ||
2695 | static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev) | ||
2696 | { | ||
2697 | if (irq == 0) { | ||
2698 | dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!"); | ||
2699 | return IRQ_HANDLED; | ||
2700 | } | ||
2701 | return udc_irq(); | ||
2702 | } | ||
2703 | |||
2704 | /** | ||
2705 | * ci13xxx_pci_probe: PCI probe | ||
2706 | * @pdev: USB device controller being probed | ||
2707 | * @id: PCI hotplug ID connecting controller to UDC framework | ||
2708 | * | ||
2709 | * This function returns an error code | ||
2710 | * Allocates basic PCI resources for this USB device controller, and then | ||
2711 | * invokes the udc_probe() method to start the UDC associated with it | ||
2712 | */ | ||
2713 | static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, | ||
2714 | const struct pci_device_id *id) | ||
2715 | { | ||
2716 | void __iomem *regs = NULL; | ||
2717 | int retval = 0; | ||
2718 | |||
2719 | if (id == NULL) | ||
2720 | return -EINVAL; | ||
2721 | |||
2722 | retval = pci_enable_device(pdev); | ||
2723 | if (retval) | ||
2724 | goto done; | ||
2725 | |||
2726 | if (!pdev->irq) { | ||
2727 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); | ||
2728 | retval = -ENODEV; | ||
2729 | goto disable_device; | ||
2730 | } | ||
2731 | |||
2732 | retval = pci_request_regions(pdev, UDC_DRIVER_NAME); | ||
2733 | if (retval) | ||
2734 | goto disable_device; | ||
2735 | |||
2736 | /* BAR 0 holds all the registers */ | ||
2737 | regs = pci_iomap(pdev, 0, 0); | ||
2738 | if (!regs) { | ||
2739 | dev_err(&pdev->dev, "Error mapping memory!"); | ||
2740 | retval = -EFAULT; | ||
2741 | goto release_regions; | ||
2742 | } | ||
2743 | pci_set_drvdata(pdev, (__force void *)regs); | ||
2744 | |||
2745 | pci_set_master(pdev); | ||
2746 | pci_try_set_mwi(pdev); | ||
2747 | |||
2748 | retval = udc_probe(&pdev->dev, regs, UDC_DRIVER_NAME); | ||
2749 | if (retval) | ||
2750 | goto iounmap; | ||
2751 | |||
2752 | /* our device does not have MSI capability */ | ||
2753 | |||
2754 | retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED, | ||
2755 | UDC_DRIVER_NAME, pdev); | ||
2756 | if (retval) | ||
2757 | goto gadget_remove; | ||
2758 | |||
2759 | return 0; | ||
2760 | |||
2761 | gadget_remove: | ||
2762 | udc_remove(); | ||
2763 | iounmap: | ||
2764 | pci_iounmap(pdev, regs); | ||
2765 | release_regions: | ||
2766 | pci_release_regions(pdev); | ||
2767 | disable_device: | ||
2768 | pci_disable_device(pdev); | ||
2769 | done: | ||
2770 | return retval; | ||
2771 | } | ||
2772 | |||
2773 | /** | ||
2774 | * ci13xxx_pci_remove: PCI remove | ||
2775 | * @pdev: USB Device Controller being removed | ||
2776 | * | ||
2777 | * Reverses the effect of ci13xxx_pci_probe(), | ||
2778 | * first invoking the udc_remove() and then releases | ||
2779 | * all PCI resources allocated for this USB device controller | ||
2780 | */ | ||
2781 | static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev) | ||
2782 | { | ||
2783 | free_irq(pdev->irq, pdev); | ||
2784 | udc_remove(); | ||
2785 | pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev)); | ||
2786 | pci_release_regions(pdev); | ||
2787 | pci_disable_device(pdev); | ||
2788 | } | ||
2789 | |||
2790 | /** | ||
2791 | * PCI device table | ||
2792 | * PCI device structure | ||
2793 | * | ||
2794 | * Check "pci.h" for details | ||
2795 | */ | ||
2796 | static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = { | ||
2797 | { PCI_DEVICE(0x153F, 0x1004) }, | ||
2798 | { PCI_DEVICE(0x153F, 0x1006) }, | ||
2799 | { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } | ||
2800 | }; | ||
2801 | MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table); | ||
2802 | |||
2803 | static struct pci_driver ci13xxx_pci_driver = { | ||
2804 | .name = UDC_DRIVER_NAME, | ||
2805 | .id_table = ci13xxx_pci_id_table, | ||
2806 | .probe = ci13xxx_pci_probe, | ||
2807 | .remove = __devexit_p(ci13xxx_pci_remove), | ||
2808 | }; | ||
2809 | |||
2810 | /** | ||
2811 | * ci13xxx_pci_init: module init | ||
2812 | * | ||
2813 | * Driver load | ||
2814 | */ | ||
2815 | static int __init ci13xxx_pci_init(void) | ||
2816 | { | ||
2817 | return pci_register_driver(&ci13xxx_pci_driver); | ||
2818 | } | ||
2819 | module_init(ci13xxx_pci_init); | ||
2820 | |||
2821 | /** | ||
2822 | * ci13xxx_pci_exit: module exit | ||
2823 | * | ||
2824 | * Driver unload | ||
2825 | */ | ||
2826 | static void __exit ci13xxx_pci_exit(void) | ||
2827 | { | ||
2828 | pci_unregister_driver(&ci13xxx_pci_driver); | ||
2829 | } | ||
2830 | module_exit(ci13xxx_pci_exit); | ||
2831 | |||
2832 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); | ||
2833 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); | ||
2834 | MODULE_LICENSE("GPL"); | ||
2835 | MODULE_VERSION("June 2008"); | ||
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h index 4026e9cede34..4fd19313e238 100644 --- a/drivers/usb/gadget/ci13xxx_udc.h +++ b/drivers/usb/gadget/ci13xxx_udc.h | |||
@@ -97,9 +97,24 @@ struct ci13xxx_ep { | |||
97 | struct dma_pool *td_pool; | 97 | struct dma_pool *td_pool; |
98 | }; | 98 | }; |
99 | 99 | ||
100 | struct ci13xxx; | ||
101 | struct ci13xxx_udc_driver { | ||
102 | const char *name; | ||
103 | unsigned long flags; | ||
104 | #define CI13XXX_REGS_SHARED BIT(0) | ||
105 | #define CI13XXX_REQUIRE_TRANSCEIVER BIT(1) | ||
106 | #define CI13XXX_PULLUP_ON_VBUS BIT(2) | ||
107 | #define CI13XXX_DISABLE_STREAMING BIT(3) | ||
108 | |||
109 | #define CI13XXX_CONTROLLER_RESET_EVENT 0 | ||
110 | #define CI13XXX_CONTROLLER_STOPPED_EVENT 1 | ||
111 | void (*notify_event) (struct ci13xxx *udc, unsigned event); | ||
112 | }; | ||
113 | |||
100 | /* CI13XXX UDC descriptor & global resources */ | 114 | /* CI13XXX UDC descriptor & global resources */ |
101 | struct ci13xxx { | 115 | struct ci13xxx { |
102 | spinlock_t *lock; /* ctrl register bank access */ | 116 | spinlock_t *lock; /* ctrl register bank access */ |
117 | void __iomem *regs; /* registers address space */ | ||
103 | 118 | ||
104 | struct dma_pool *qh_pool; /* DMA pool for queue heads */ | 119 | struct dma_pool *qh_pool; /* DMA pool for queue heads */ |
105 | struct dma_pool *td_pool; /* DMA pool for transfer descs */ | 120 | struct dma_pool *td_pool; /* DMA pool for transfer descs */ |
@@ -108,6 +123,9 @@ struct ci13xxx { | |||
108 | struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ | 123 | struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ |
109 | 124 | ||
110 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ | 125 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ |
126 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ | ||
127 | int vbus_active; /* is VBUS active */ | ||
128 | struct otg_transceiver *transceiver; /* Transceiver struct */ | ||
111 | }; | 129 | }; |
112 | 130 | ||
113 | /****************************************************************************** | 131 | /****************************************************************************** |
@@ -157,6 +175,7 @@ struct ci13xxx { | |||
157 | #define USBMODE_CM_DEVICE (0x02UL << 0) | 175 | #define USBMODE_CM_DEVICE (0x02UL << 0) |
158 | #define USBMODE_CM_HOST (0x03UL << 0) | 176 | #define USBMODE_CM_HOST (0x03UL << 0) |
159 | #define USBMODE_SLOM BIT(3) | 177 | #define USBMODE_SLOM BIT(3) |
178 | #define USBMODE_SDIS BIT(4) | ||
160 | 179 | ||
161 | /* ENDPTCTRL */ | 180 | /* ENDPTCTRL */ |
162 | #define ENDPTCTRL_RXS BIT(0) | 181 | #define ENDPTCTRL_RXS BIT(0) |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 255969cd1639..1b7ae7c9d683 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -427,7 +427,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
427 | } | 427 | } |
428 | 428 | ||
429 | data = ffs_prepare_buffer(buf, len); | 429 | data = ffs_prepare_buffer(buf, len); |
430 | if (unlikely(IS_ERR(data))) { | 430 | if (IS_ERR(data)) { |
431 | ret = PTR_ERR(data); | 431 | ret = PTR_ERR(data); |
432 | break; | 432 | break; |
433 | } | 433 | } |
@@ -500,7 +500,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
500 | spin_unlock_irq(&ffs->ev.waitq.lock); | 500 | spin_unlock_irq(&ffs->ev.waitq.lock); |
501 | 501 | ||
502 | data = ffs_prepare_buffer(buf, len); | 502 | data = ffs_prepare_buffer(buf, len); |
503 | if (unlikely(IS_ERR(data))) { | 503 | if (IS_ERR(data)) { |
504 | ret = PTR_ERR(data); | 504 | ret = PTR_ERR(data); |
505 | break; | 505 | break; |
506 | } | 506 | } |
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c new file mode 100644 index 000000000000..130eee678c8b --- /dev/null +++ b/drivers/usb/gadget/f_ncm.c | |||
@@ -0,0 +1,1407 @@ | |||
1 | /* | ||
2 | * f_ncm.c -- USB CDC Network (NCM) link function driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Nokia Corporation | ||
5 | * Contact: Yauheni Kaliuta <yauheni.kaliuta@nokia.com> | ||
6 | * | ||
7 | * The driver borrows from f_ecm.c which is: | ||
8 | * | ||
9 | * Copyright (C) 2003-2005,2008 David Brownell | ||
10 | * Copyright (C) 2008 Nokia Corporation | ||
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 as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | */ | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/device.h> | ||
29 | #include <linux/etherdevice.h> | ||
30 | #include <linux/crc32.h> | ||
31 | |||
32 | #include <linux/usb/cdc.h> | ||
33 | |||
34 | #include "u_ether.h" | ||
35 | |||
36 | /* | ||
37 | * This function is a "CDC Network Control Model" (CDC NCM) Ethernet link. | ||
38 | * NCM is intended to be used with high-speed network attachments. | ||
39 | * | ||
40 | * Note that NCM requires the use of "alternate settings" for its data | ||
41 | * interface. This means that the set_alt() method has real work to do, | ||
42 | * and also means that a get_alt() method is required. | ||
43 | */ | ||
44 | |||
45 | /* to trigger crc/non-crc ndp signature */ | ||
46 | |||
47 | #define NCM_NDP_HDR_CRC_MASK 0x01000000 | ||
48 | #define NCM_NDP_HDR_CRC 0x01000000 | ||
49 | #define NCM_NDP_HDR_NOCRC 0x00000000 | ||
50 | |||
51 | struct ncm_ep_descs { | ||
52 | struct usb_endpoint_descriptor *in; | ||
53 | struct usb_endpoint_descriptor *out; | ||
54 | struct usb_endpoint_descriptor *notify; | ||
55 | }; | ||
56 | |||
57 | enum ncm_notify_state { | ||
58 | NCM_NOTIFY_NONE, /* don't notify */ | ||
59 | NCM_NOTIFY_CONNECT, /* issue CONNECT next */ | ||
60 | NCM_NOTIFY_SPEED, /* issue SPEED_CHANGE next */ | ||
61 | }; | ||
62 | |||
63 | struct f_ncm { | ||
64 | struct gether port; | ||
65 | u8 ctrl_id, data_id; | ||
66 | |||
67 | char ethaddr[14]; | ||
68 | |||
69 | struct ncm_ep_descs fs; | ||
70 | struct ncm_ep_descs hs; | ||
71 | |||
72 | struct usb_ep *notify; | ||
73 | struct usb_endpoint_descriptor *notify_desc; | ||
74 | struct usb_request *notify_req; | ||
75 | u8 notify_state; | ||
76 | bool is_open; | ||
77 | |||
78 | struct ndp_parser_opts *parser_opts; | ||
79 | bool is_crc; | ||
80 | |||
81 | /* | ||
82 | * for notification, it is accessed from both | ||
83 | * callback and ethernet open/close | ||
84 | */ | ||
85 | spinlock_t lock; | ||
86 | }; | ||
87 | |||
88 | static inline struct f_ncm *func_to_ncm(struct usb_function *f) | ||
89 | { | ||
90 | return container_of(f, struct f_ncm, port.func); | ||
91 | } | ||
92 | |||
93 | /* peak (theoretical) bulk transfer rate in bits-per-second */ | ||
94 | static inline unsigned ncm_bitrate(struct usb_gadget *g) | ||
95 | { | ||
96 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | ||
97 | return 13 * 512 * 8 * 1000 * 8; | ||
98 | else | ||
99 | return 19 * 64 * 1 * 1000 * 8; | ||
100 | } | ||
101 | |||
102 | /*-------------------------------------------------------------------------*/ | ||
103 | |||
104 | /* | ||
105 | * We cannot group frames so use just the minimal size which ok to put | ||
106 | * one max-size ethernet frame. | ||
107 | * If the host can group frames, allow it to do that, 16K is selected, | ||
108 | * because it's used by default by the current linux host driver | ||
109 | */ | ||
110 | #define NTB_DEFAULT_IN_SIZE USB_CDC_NCM_NTB_MIN_IN_SIZE | ||
111 | #define NTB_OUT_SIZE 16384 | ||
112 | |||
113 | /* | ||
114 | * skbs of size less than that will not be alligned | ||
115 | * to NCM's dwNtbInMaxSize to save bus bandwidth | ||
116 | */ | ||
117 | |||
118 | #define MAX_TX_NONFIXED (512 * 3) | ||
119 | |||
120 | #define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \ | ||
121 | USB_CDC_NCM_NTB32_SUPPORTED) | ||
122 | |||
123 | static struct usb_cdc_ncm_ntb_parameters ntb_parameters = { | ||
124 | .wLength = sizeof ntb_parameters, | ||
125 | .bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED), | ||
126 | .dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE), | ||
127 | .wNdpInDivisor = cpu_to_le16(4), | ||
128 | .wNdpInPayloadRemainder = cpu_to_le16(0), | ||
129 | .wNdpInAlignment = cpu_to_le16(4), | ||
130 | |||
131 | .dwNtbOutMaxSize = cpu_to_le32(NTB_OUT_SIZE), | ||
132 | .wNdpOutDivisor = cpu_to_le16(4), | ||
133 | .wNdpOutPayloadRemainder = cpu_to_le16(0), | ||
134 | .wNdpOutAlignment = cpu_to_le16(4), | ||
135 | }; | ||
136 | |||
137 | /* | ||
138 | * Use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one | ||
139 | * packet, to simplify cancellation; and a big transfer interval, to | ||
140 | * waste less bandwidth. | ||
141 | */ | ||
142 | |||
143 | #define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ | ||
144 | #define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */ | ||
145 | |||
146 | static struct usb_interface_assoc_descriptor ncm_iad_desc __initdata = { | ||
147 | .bLength = sizeof ncm_iad_desc, | ||
148 | .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, | ||
149 | |||
150 | /* .bFirstInterface = DYNAMIC, */ | ||
151 | .bInterfaceCount = 2, /* control + data */ | ||
152 | .bFunctionClass = USB_CLASS_COMM, | ||
153 | .bFunctionSubClass = USB_CDC_SUBCLASS_NCM, | ||
154 | .bFunctionProtocol = USB_CDC_PROTO_NONE, | ||
155 | /* .iFunction = DYNAMIC */ | ||
156 | }; | ||
157 | |||
158 | /* interface descriptor: */ | ||
159 | |||
160 | static struct usb_interface_descriptor ncm_control_intf __initdata = { | ||
161 | .bLength = sizeof ncm_control_intf, | ||
162 | .bDescriptorType = USB_DT_INTERFACE, | ||
163 | |||
164 | /* .bInterfaceNumber = DYNAMIC */ | ||
165 | .bNumEndpoints = 1, | ||
166 | .bInterfaceClass = USB_CLASS_COMM, | ||
167 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, | ||
168 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, | ||
169 | /* .iInterface = DYNAMIC */ | ||
170 | }; | ||
171 | |||
172 | static struct usb_cdc_header_desc ncm_header_desc __initdata = { | ||
173 | .bLength = sizeof ncm_header_desc, | ||
174 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
175 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, | ||
176 | |||
177 | .bcdCDC = cpu_to_le16(0x0110), | ||
178 | }; | ||
179 | |||
180 | static struct usb_cdc_union_desc ncm_union_desc __initdata = { | ||
181 | .bLength = sizeof(ncm_union_desc), | ||
182 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
183 | .bDescriptorSubType = USB_CDC_UNION_TYPE, | ||
184 | /* .bMasterInterface0 = DYNAMIC */ | ||
185 | /* .bSlaveInterface0 = DYNAMIC */ | ||
186 | }; | ||
187 | |||
188 | static struct usb_cdc_ether_desc ecm_desc __initdata = { | ||
189 | .bLength = sizeof ecm_desc, | ||
190 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
191 | .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, | ||
192 | |||
193 | /* this descriptor actually adds value, surprise! */ | ||
194 | /* .iMACAddress = DYNAMIC */ | ||
195 | .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */ | ||
196 | .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN), | ||
197 | .wNumberMCFilters = cpu_to_le16(0), | ||
198 | .bNumberPowerFilters = 0, | ||
199 | }; | ||
200 | |||
201 | #define NCAPS (USB_CDC_NCM_NCAP_ETH_FILTER | USB_CDC_NCM_NCAP_CRC_MODE) | ||
202 | |||
203 | static struct usb_cdc_ncm_desc ncm_desc __initdata = { | ||
204 | .bLength = sizeof ncm_desc, | ||
205 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
206 | .bDescriptorSubType = USB_CDC_NCM_TYPE, | ||
207 | |||
208 | .bcdNcmVersion = cpu_to_le16(0x0100), | ||
209 | /* can process SetEthernetPacketFilter */ | ||
210 | .bmNetworkCapabilities = NCAPS, | ||
211 | }; | ||
212 | |||
213 | /* the default data interface has no endpoints ... */ | ||
214 | |||
215 | static struct usb_interface_descriptor ncm_data_nop_intf __initdata = { | ||
216 | .bLength = sizeof ncm_data_nop_intf, | ||
217 | .bDescriptorType = USB_DT_INTERFACE, | ||
218 | |||
219 | .bInterfaceNumber = 1, | ||
220 | .bAlternateSetting = 0, | ||
221 | .bNumEndpoints = 0, | ||
222 | .bInterfaceClass = USB_CLASS_CDC_DATA, | ||
223 | .bInterfaceSubClass = 0, | ||
224 | .bInterfaceProtocol = USB_CDC_NCM_PROTO_NTB, | ||
225 | /* .iInterface = DYNAMIC */ | ||
226 | }; | ||
227 | |||
228 | /* ... but the "real" data interface has two bulk endpoints */ | ||
229 | |||
230 | static struct usb_interface_descriptor ncm_data_intf __initdata = { | ||
231 | .bLength = sizeof ncm_data_intf, | ||
232 | .bDescriptorType = USB_DT_INTERFACE, | ||
233 | |||
234 | .bInterfaceNumber = 1, | ||
235 | .bAlternateSetting = 1, | ||
236 | .bNumEndpoints = 2, | ||
237 | .bInterfaceClass = USB_CLASS_CDC_DATA, | ||
238 | .bInterfaceSubClass = 0, | ||
239 | .bInterfaceProtocol = USB_CDC_NCM_PROTO_NTB, | ||
240 | /* .iInterface = DYNAMIC */ | ||
241 | }; | ||
242 | |||
243 | /* full speed support: */ | ||
244 | |||
245 | static struct usb_endpoint_descriptor fs_ncm_notify_desc __initdata = { | ||
246 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
247 | .bDescriptorType = USB_DT_ENDPOINT, | ||
248 | |||
249 | .bEndpointAddress = USB_DIR_IN, | ||
250 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
251 | .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT), | ||
252 | .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, | ||
253 | }; | ||
254 | |||
255 | static struct usb_endpoint_descriptor fs_ncm_in_desc __initdata = { | ||
256 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
257 | .bDescriptorType = USB_DT_ENDPOINT, | ||
258 | |||
259 | .bEndpointAddress = USB_DIR_IN, | ||
260 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
261 | }; | ||
262 | |||
263 | static struct usb_endpoint_descriptor fs_ncm_out_desc __initdata = { | ||
264 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
265 | .bDescriptorType = USB_DT_ENDPOINT, | ||
266 | |||
267 | .bEndpointAddress = USB_DIR_OUT, | ||
268 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
269 | }; | ||
270 | |||
271 | static struct usb_descriptor_header *ncm_fs_function[] __initdata = { | ||
272 | (struct usb_descriptor_header *) &ncm_iad_desc, | ||
273 | /* CDC NCM control descriptors */ | ||
274 | (struct usb_descriptor_header *) &ncm_control_intf, | ||
275 | (struct usb_descriptor_header *) &ncm_header_desc, | ||
276 | (struct usb_descriptor_header *) &ncm_union_desc, | ||
277 | (struct usb_descriptor_header *) &ecm_desc, | ||
278 | (struct usb_descriptor_header *) &ncm_desc, | ||
279 | (struct usb_descriptor_header *) &fs_ncm_notify_desc, | ||
280 | /* data interface, altsettings 0 and 1 */ | ||
281 | (struct usb_descriptor_header *) &ncm_data_nop_intf, | ||
282 | (struct usb_descriptor_header *) &ncm_data_intf, | ||
283 | (struct usb_descriptor_header *) &fs_ncm_in_desc, | ||
284 | (struct usb_descriptor_header *) &fs_ncm_out_desc, | ||
285 | NULL, | ||
286 | }; | ||
287 | |||
288 | /* high speed support: */ | ||
289 | |||
290 | static struct usb_endpoint_descriptor hs_ncm_notify_desc __initdata = { | ||
291 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
292 | .bDescriptorType = USB_DT_ENDPOINT, | ||
293 | |||
294 | .bEndpointAddress = USB_DIR_IN, | ||
295 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
296 | .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT), | ||
297 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, | ||
298 | }; | ||
299 | static struct usb_endpoint_descriptor hs_ncm_in_desc __initdata = { | ||
300 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
301 | .bDescriptorType = USB_DT_ENDPOINT, | ||
302 | |||
303 | .bEndpointAddress = USB_DIR_IN, | ||
304 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
305 | .wMaxPacketSize = cpu_to_le16(512), | ||
306 | }; | ||
307 | |||
308 | static struct usb_endpoint_descriptor hs_ncm_out_desc __initdata = { | ||
309 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
310 | .bDescriptorType = USB_DT_ENDPOINT, | ||
311 | |||
312 | .bEndpointAddress = USB_DIR_OUT, | ||
313 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
314 | .wMaxPacketSize = cpu_to_le16(512), | ||
315 | }; | ||
316 | |||
317 | static struct usb_descriptor_header *ncm_hs_function[] __initdata = { | ||
318 | (struct usb_descriptor_header *) &ncm_iad_desc, | ||
319 | /* CDC NCM control descriptors */ | ||
320 | (struct usb_descriptor_header *) &ncm_control_intf, | ||
321 | (struct usb_descriptor_header *) &ncm_header_desc, | ||
322 | (struct usb_descriptor_header *) &ncm_union_desc, | ||
323 | (struct usb_descriptor_header *) &ecm_desc, | ||
324 | (struct usb_descriptor_header *) &ncm_desc, | ||
325 | (struct usb_descriptor_header *) &hs_ncm_notify_desc, | ||
326 | /* data interface, altsettings 0 and 1 */ | ||
327 | (struct usb_descriptor_header *) &ncm_data_nop_intf, | ||
328 | (struct usb_descriptor_header *) &ncm_data_intf, | ||
329 | (struct usb_descriptor_header *) &hs_ncm_in_desc, | ||
330 | (struct usb_descriptor_header *) &hs_ncm_out_desc, | ||
331 | NULL, | ||
332 | }; | ||
333 | |||
334 | /* string descriptors: */ | ||
335 | |||
336 | #define STRING_CTRL_IDX 0 | ||
337 | #define STRING_MAC_IDX 1 | ||
338 | #define STRING_DATA_IDX 2 | ||
339 | #define STRING_IAD_IDX 3 | ||
340 | |||
341 | static struct usb_string ncm_string_defs[] = { | ||
342 | [STRING_CTRL_IDX].s = "CDC Network Control Model (NCM)", | ||
343 | [STRING_MAC_IDX].s = NULL /* DYNAMIC */, | ||
344 | [STRING_DATA_IDX].s = "CDC Network Data", | ||
345 | [STRING_IAD_IDX].s = "CDC NCM", | ||
346 | { } /* end of list */ | ||
347 | }; | ||
348 | |||
349 | static struct usb_gadget_strings ncm_string_table = { | ||
350 | .language = 0x0409, /* en-us */ | ||
351 | .strings = ncm_string_defs, | ||
352 | }; | ||
353 | |||
354 | static struct usb_gadget_strings *ncm_strings[] = { | ||
355 | &ncm_string_table, | ||
356 | NULL, | ||
357 | }; | ||
358 | |||
359 | /* | ||
360 | * Here are options for NCM Datagram Pointer table (NDP) parser. | ||
361 | * There are 2 different formats: NDP16 and NDP32 in the spec (ch. 3), | ||
362 | * in NDP16 offsets and sizes fields are 1 16bit word wide, | ||
363 | * in NDP32 -- 2 16bit words wide. Also signatures are different. | ||
364 | * To make the parser code the same, put the differences in the structure, | ||
365 | * and switch pointers to the structures when the format is changed. | ||
366 | */ | ||
367 | |||
368 | struct ndp_parser_opts { | ||
369 | u32 nth_sign; | ||
370 | u32 ndp_sign; | ||
371 | unsigned nth_size; | ||
372 | unsigned ndp_size; | ||
373 | unsigned ndplen_align; | ||
374 | /* sizes in u16 units */ | ||
375 | unsigned dgram_item_len; /* index or length */ | ||
376 | unsigned block_length; | ||
377 | unsigned fp_index; | ||
378 | unsigned reserved1; | ||
379 | unsigned reserved2; | ||
380 | unsigned next_fp_index; | ||
381 | }; | ||
382 | |||
383 | #define INIT_NDP16_OPTS { \ | ||
384 | .nth_sign = USB_CDC_NCM_NTH16_SIGN, \ | ||
385 | .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, \ | ||
386 | .nth_size = sizeof(struct usb_cdc_ncm_nth16), \ | ||
387 | .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \ | ||
388 | .ndplen_align = 4, \ | ||
389 | .dgram_item_len = 1, \ | ||
390 | .block_length = 1, \ | ||
391 | .fp_index = 1, \ | ||
392 | .reserved1 = 0, \ | ||
393 | .reserved2 = 0, \ | ||
394 | .next_fp_index = 1, \ | ||
395 | } | ||
396 | |||
397 | |||
398 | #define INIT_NDP32_OPTS { \ | ||
399 | .nth_sign = USB_CDC_NCM_NTH32_SIGN, \ | ||
400 | .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, \ | ||
401 | .nth_size = sizeof(struct usb_cdc_ncm_nth32), \ | ||
402 | .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \ | ||
403 | .ndplen_align = 8, \ | ||
404 | .dgram_item_len = 2, \ | ||
405 | .block_length = 2, \ | ||
406 | .fp_index = 2, \ | ||
407 | .reserved1 = 1, \ | ||
408 | .reserved2 = 2, \ | ||
409 | .next_fp_index = 2, \ | ||
410 | } | ||
411 | |||
412 | static struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; | ||
413 | static struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS; | ||
414 | |||
415 | static inline void put_ncm(__le16 **p, unsigned size, unsigned val) | ||
416 | { | ||
417 | switch (size) { | ||
418 | case 1: | ||
419 | put_unaligned_le16((u16)val, *p); | ||
420 | break; | ||
421 | case 2: | ||
422 | put_unaligned_le32((u32)val, *p); | ||
423 | |||
424 | break; | ||
425 | default: | ||
426 | BUG(); | ||
427 | } | ||
428 | |||
429 | *p += size; | ||
430 | } | ||
431 | |||
432 | static inline unsigned get_ncm(__le16 **p, unsigned size) | ||
433 | { | ||
434 | unsigned tmp; | ||
435 | |||
436 | switch (size) { | ||
437 | case 1: | ||
438 | tmp = get_unaligned_le16(*p); | ||
439 | break; | ||
440 | case 2: | ||
441 | tmp = get_unaligned_le32(*p); | ||
442 | break; | ||
443 | default: | ||
444 | BUG(); | ||
445 | } | ||
446 | |||
447 | *p += size; | ||
448 | return tmp; | ||
449 | } | ||
450 | |||
451 | /*-------------------------------------------------------------------------*/ | ||
452 | |||
453 | static inline void ncm_reset_values(struct f_ncm *ncm) | ||
454 | { | ||
455 | ncm->parser_opts = &ndp16_opts; | ||
456 | ncm->is_crc = false; | ||
457 | ncm->port.cdc_filter = DEFAULT_FILTER; | ||
458 | |||
459 | /* doesn't make sense for ncm, fixed size used */ | ||
460 | ncm->port.header_len = 0; | ||
461 | |||
462 | ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); | ||
463 | ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; | ||
464 | } | ||
465 | |||
466 | /* | ||
467 | * Context: ncm->lock held | ||
468 | */ | ||
469 | static void ncm_do_notify(struct f_ncm *ncm) | ||
470 | { | ||
471 | struct usb_request *req = ncm->notify_req; | ||
472 | struct usb_cdc_notification *event; | ||
473 | struct usb_composite_dev *cdev = ncm->port.func.config->cdev; | ||
474 | __le32 *data; | ||
475 | int status; | ||
476 | |||
477 | /* notification already in flight? */ | ||
478 | if (!req) | ||
479 | return; | ||
480 | |||
481 | event = req->buf; | ||
482 | switch (ncm->notify_state) { | ||
483 | case NCM_NOTIFY_NONE: | ||
484 | return; | ||
485 | |||
486 | case NCM_NOTIFY_CONNECT: | ||
487 | event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION; | ||
488 | if (ncm->is_open) | ||
489 | event->wValue = cpu_to_le16(1); | ||
490 | else | ||
491 | event->wValue = cpu_to_le16(0); | ||
492 | event->wLength = 0; | ||
493 | req->length = sizeof *event; | ||
494 | |||
495 | DBG(cdev, "notify connect %s\n", | ||
496 | ncm->is_open ? "true" : "false"); | ||
497 | ncm->notify_state = NCM_NOTIFY_NONE; | ||
498 | break; | ||
499 | |||
500 | case NCM_NOTIFY_SPEED: | ||
501 | event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; | ||
502 | event->wValue = cpu_to_le16(0); | ||
503 | event->wLength = cpu_to_le16(8); | ||
504 | req->length = NCM_STATUS_BYTECOUNT; | ||
505 | |||
506 | /* SPEED_CHANGE data is up/down speeds in bits/sec */ | ||
507 | data = req->buf + sizeof *event; | ||
508 | data[0] = cpu_to_le32(ncm_bitrate(cdev->gadget)); | ||
509 | data[1] = data[0]; | ||
510 | |||
511 | DBG(cdev, "notify speed %d\n", ncm_bitrate(cdev->gadget)); | ||
512 | ncm->notify_state = NCM_NOTIFY_CONNECT; | ||
513 | break; | ||
514 | } | ||
515 | event->bmRequestType = 0xA1; | ||
516 | event->wIndex = cpu_to_le16(ncm->ctrl_id); | ||
517 | |||
518 | ncm->notify_req = NULL; | ||
519 | /* | ||
520 | * In double buffering if there is a space in FIFO, | ||
521 | * completion callback can be called right after the call, | ||
522 | * so unlocking | ||
523 | */ | ||
524 | spin_unlock(&ncm->lock); | ||
525 | status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); | ||
526 | spin_lock(&ncm->lock); | ||
527 | if (status < 0) { | ||
528 | ncm->notify_req = req; | ||
529 | DBG(cdev, "notify --> %d\n", status); | ||
530 | } | ||
531 | } | ||
532 | |||
533 | /* | ||
534 | * Context: ncm->lock held | ||
535 | */ | ||
536 | static void ncm_notify(struct f_ncm *ncm) | ||
537 | { | ||
538 | /* | ||
539 | * NOTE on most versions of Linux, host side cdc-ethernet | ||
540 | * won't listen for notifications until its netdevice opens. | ||
541 | * The first notification then sits in the FIFO for a long | ||
542 | * time, and the second one is queued. | ||
543 | * | ||
544 | * If ncm_notify() is called before the second (CONNECT) | ||
545 | * notification is sent, then it will reset to send the SPEED | ||
546 | * notificaion again (and again, and again), but it's not a problem | ||
547 | */ | ||
548 | ncm->notify_state = NCM_NOTIFY_SPEED; | ||
549 | ncm_do_notify(ncm); | ||
550 | } | ||
551 | |||
552 | static void ncm_notify_complete(struct usb_ep *ep, struct usb_request *req) | ||
553 | { | ||
554 | struct f_ncm *ncm = req->context; | ||
555 | struct usb_composite_dev *cdev = ncm->port.func.config->cdev; | ||
556 | struct usb_cdc_notification *event = req->buf; | ||
557 | |||
558 | spin_lock(&ncm->lock); | ||
559 | switch (req->status) { | ||
560 | case 0: | ||
561 | VDBG(cdev, "Notification %02x sent\n", | ||
562 | event->bNotificationType); | ||
563 | break; | ||
564 | case -ECONNRESET: | ||
565 | case -ESHUTDOWN: | ||
566 | ncm->notify_state = NCM_NOTIFY_NONE; | ||
567 | break; | ||
568 | default: | ||
569 | DBG(cdev, "event %02x --> %d\n", | ||
570 | event->bNotificationType, req->status); | ||
571 | break; | ||
572 | } | ||
573 | ncm->notify_req = req; | ||
574 | ncm_do_notify(ncm); | ||
575 | spin_unlock(&ncm->lock); | ||
576 | } | ||
577 | |||
578 | static void ncm_ep0out_complete(struct usb_ep *ep, struct usb_request *req) | ||
579 | { | ||
580 | /* now for SET_NTB_INPUT_SIZE only */ | ||
581 | unsigned in_size; | ||
582 | struct usb_function *f = req->context; | ||
583 | struct f_ncm *ncm = func_to_ncm(f); | ||
584 | struct usb_composite_dev *cdev = ep->driver_data; | ||
585 | |||
586 | req->context = NULL; | ||
587 | if (req->status || req->actual != req->length) { | ||
588 | DBG(cdev, "Bad control-OUT transfer\n"); | ||
589 | goto invalid; | ||
590 | } | ||
591 | |||
592 | in_size = get_unaligned_le32(req->buf); | ||
593 | if (in_size < USB_CDC_NCM_NTB_MIN_IN_SIZE || | ||
594 | in_size > le32_to_cpu(ntb_parameters.dwNtbInMaxSize)) { | ||
595 | DBG(cdev, "Got wrong INPUT SIZE (%d) from host\n", in_size); | ||
596 | goto invalid; | ||
597 | } | ||
598 | |||
599 | ncm->port.fixed_in_len = in_size; | ||
600 | VDBG(cdev, "Set NTB INPUT SIZE %d\n", in_size); | ||
601 | return; | ||
602 | |||
603 | invalid: | ||
604 | usb_ep_set_halt(ep); | ||
605 | return; | ||
606 | } | ||
607 | |||
608 | static int ncm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | ||
609 | { | ||
610 | struct f_ncm *ncm = func_to_ncm(f); | ||
611 | struct usb_composite_dev *cdev = f->config->cdev; | ||
612 | struct usb_request *req = cdev->req; | ||
613 | int value = -EOPNOTSUPP; | ||
614 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
615 | u16 w_value = le16_to_cpu(ctrl->wValue); | ||
616 | u16 w_length = le16_to_cpu(ctrl->wLength); | ||
617 | |||
618 | /* | ||
619 | * composite driver infrastructure handles everything except | ||
620 | * CDC class messages; interface activation uses set_alt(). | ||
621 | */ | ||
622 | switch ((ctrl->bRequestType << 8) | ctrl->bRequest) { | ||
623 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
624 | | USB_CDC_SET_ETHERNET_PACKET_FILTER: | ||
625 | /* | ||
626 | * see 6.2.30: no data, wIndex = interface, | ||
627 | * wValue = packet filter bitmap | ||
628 | */ | ||
629 | if (w_length != 0 || w_index != ncm->ctrl_id) | ||
630 | goto invalid; | ||
631 | DBG(cdev, "packet filter %02x\n", w_value); | ||
632 | /* | ||
633 | * REVISIT locking of cdc_filter. This assumes the UDC | ||
634 | * driver won't have a concurrent packet TX irq running on | ||
635 | * another CPU; or that if it does, this write is atomic... | ||
636 | */ | ||
637 | ncm->port.cdc_filter = w_value; | ||
638 | value = 0; | ||
639 | break; | ||
640 | /* | ||
641 | * and optionally: | ||
642 | * case USB_CDC_SEND_ENCAPSULATED_COMMAND: | ||
643 | * case USB_CDC_GET_ENCAPSULATED_RESPONSE: | ||
644 | * case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS: | ||
645 | * case USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER: | ||
646 | * case USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER: | ||
647 | * case USB_CDC_GET_ETHERNET_STATISTIC: | ||
648 | */ | ||
649 | |||
650 | case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
651 | | USB_CDC_GET_NTB_PARAMETERS: | ||
652 | |||
653 | if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) | ||
654 | goto invalid; | ||
655 | value = w_length > sizeof ntb_parameters ? | ||
656 | sizeof ntb_parameters : w_length; | ||
657 | memcpy(req->buf, &ntb_parameters, value); | ||
658 | VDBG(cdev, "Host asked NTB parameters\n"); | ||
659 | break; | ||
660 | |||
661 | case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
662 | | USB_CDC_GET_NTB_INPUT_SIZE: | ||
663 | |||
664 | if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) | ||
665 | goto invalid; | ||
666 | put_unaligned_le32(ncm->port.fixed_in_len, req->buf); | ||
667 | value = 4; | ||
668 | VDBG(cdev, "Host asked INPUT SIZE, sending %d\n", | ||
669 | ncm->port.fixed_in_len); | ||
670 | break; | ||
671 | |||
672 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
673 | | USB_CDC_SET_NTB_INPUT_SIZE: | ||
674 | { | ||
675 | if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) | ||
676 | goto invalid; | ||
677 | req->complete = ncm_ep0out_complete; | ||
678 | req->length = w_length; | ||
679 | req->context = f; | ||
680 | |||
681 | value = req->length; | ||
682 | break; | ||
683 | } | ||
684 | |||
685 | case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
686 | | USB_CDC_GET_NTB_FORMAT: | ||
687 | { | ||
688 | uint16_t format; | ||
689 | |||
690 | if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) | ||
691 | goto invalid; | ||
692 | format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; | ||
693 | put_unaligned_le16(format, req->buf); | ||
694 | value = 2; | ||
695 | VDBG(cdev, "Host asked NTB FORMAT, sending %d\n", format); | ||
696 | break; | ||
697 | } | ||
698 | |||
699 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
700 | | USB_CDC_SET_NTB_FORMAT: | ||
701 | { | ||
702 | if (w_length != 0 || w_index != ncm->ctrl_id) | ||
703 | goto invalid; | ||
704 | switch (w_value) { | ||
705 | case 0x0000: | ||
706 | ncm->parser_opts = &ndp16_opts; | ||
707 | DBG(cdev, "NCM16 selected\n"); | ||
708 | break; | ||
709 | case 0x0001: | ||
710 | ncm->parser_opts = &ndp32_opts; | ||
711 | DBG(cdev, "NCM32 selected\n"); | ||
712 | break; | ||
713 | default: | ||
714 | goto invalid; | ||
715 | } | ||
716 | value = 0; | ||
717 | break; | ||
718 | } | ||
719 | case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
720 | | USB_CDC_GET_CRC_MODE: | ||
721 | { | ||
722 | uint16_t is_crc; | ||
723 | |||
724 | if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) | ||
725 | goto invalid; | ||
726 | is_crc = ncm->is_crc ? 0x0001 : 0x0000; | ||
727 | put_unaligned_le16(is_crc, req->buf); | ||
728 | value = 2; | ||
729 | VDBG(cdev, "Host asked CRC MODE, sending %d\n", is_crc); | ||
730 | break; | ||
731 | } | ||
732 | |||
733 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | ||
734 | | USB_CDC_SET_CRC_MODE: | ||
735 | { | ||
736 | int ndp_hdr_crc = 0; | ||
737 | |||
738 | if (w_length != 0 || w_index != ncm->ctrl_id) | ||
739 | goto invalid; | ||
740 | switch (w_value) { | ||
741 | case 0x0000: | ||
742 | ncm->is_crc = false; | ||
743 | ndp_hdr_crc = NCM_NDP_HDR_NOCRC; | ||
744 | DBG(cdev, "non-CRC mode selected\n"); | ||
745 | break; | ||
746 | case 0x0001: | ||
747 | ncm->is_crc = true; | ||
748 | ndp_hdr_crc = NCM_NDP_HDR_CRC; | ||
749 | DBG(cdev, "CRC mode selected\n"); | ||
750 | break; | ||
751 | default: | ||
752 | goto invalid; | ||
753 | } | ||
754 | ncm->parser_opts->ndp_sign &= ~NCM_NDP_HDR_CRC_MASK; | ||
755 | ncm->parser_opts->ndp_sign |= ndp_hdr_crc; | ||
756 | value = 0; | ||
757 | break; | ||
758 | } | ||
759 | |||
760 | /* and disabled in ncm descriptor: */ | ||
761 | /* case USB_CDC_GET_NET_ADDRESS: */ | ||
762 | /* case USB_CDC_SET_NET_ADDRESS: */ | ||
763 | /* case USB_CDC_GET_MAX_DATAGRAM_SIZE: */ | ||
764 | /* case USB_CDC_SET_MAX_DATAGRAM_SIZE: */ | ||
765 | |||
766 | default: | ||
767 | invalid: | ||
768 | DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", | ||
769 | ctrl->bRequestType, ctrl->bRequest, | ||
770 | w_value, w_index, w_length); | ||
771 | } | ||
772 | |||
773 | /* respond with data transfer or status phase? */ | ||
774 | if (value >= 0) { | ||
775 | DBG(cdev, "ncm req%02x.%02x v%04x i%04x l%d\n", | ||
776 | ctrl->bRequestType, ctrl->bRequest, | ||
777 | w_value, w_index, w_length); | ||
778 | req->zero = 0; | ||
779 | req->length = value; | ||
780 | value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); | ||
781 | if (value < 0) | ||
782 | ERROR(cdev, "ncm req %02x.%02x response err %d\n", | ||
783 | ctrl->bRequestType, ctrl->bRequest, | ||
784 | value); | ||
785 | } | ||
786 | |||
787 | /* device either stalls (value < 0) or reports success */ | ||
788 | return value; | ||
789 | } | ||
790 | |||
791 | |||
792 | static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | ||
793 | { | ||
794 | struct f_ncm *ncm = func_to_ncm(f); | ||
795 | struct usb_composite_dev *cdev = f->config->cdev; | ||
796 | |||
797 | /* Control interface has only altsetting 0 */ | ||
798 | if (intf == ncm->ctrl_id) { | ||
799 | if (alt != 0) | ||
800 | goto fail; | ||
801 | |||
802 | if (ncm->notify->driver_data) { | ||
803 | DBG(cdev, "reset ncm control %d\n", intf); | ||
804 | usb_ep_disable(ncm->notify); | ||
805 | } else { | ||
806 | DBG(cdev, "init ncm ctrl %d\n", intf); | ||
807 | ncm->notify_desc = ep_choose(cdev->gadget, | ||
808 | ncm->hs.notify, | ||
809 | ncm->fs.notify); | ||
810 | } | ||
811 | usb_ep_enable(ncm->notify, ncm->notify_desc); | ||
812 | ncm->notify->driver_data = ncm; | ||
813 | |||
814 | /* Data interface has two altsettings, 0 and 1 */ | ||
815 | } else if (intf == ncm->data_id) { | ||
816 | if (alt > 1) | ||
817 | goto fail; | ||
818 | |||
819 | if (ncm->port.in_ep->driver_data) { | ||
820 | DBG(cdev, "reset ncm\n"); | ||
821 | gether_disconnect(&ncm->port); | ||
822 | ncm_reset_values(ncm); | ||
823 | } | ||
824 | |||
825 | /* | ||
826 | * CDC Network only sends data in non-default altsettings. | ||
827 | * Changing altsettings resets filters, statistics, etc. | ||
828 | */ | ||
829 | if (alt == 1) { | ||
830 | struct net_device *net; | ||
831 | |||
832 | if (!ncm->port.in) { | ||
833 | DBG(cdev, "init ncm\n"); | ||
834 | ncm->port.in = ep_choose(cdev->gadget, | ||
835 | ncm->hs.in, | ||
836 | ncm->fs.in); | ||
837 | ncm->port.out = ep_choose(cdev->gadget, | ||
838 | ncm->hs.out, | ||
839 | ncm->fs.out); | ||
840 | } | ||
841 | |||
842 | /* TODO */ | ||
843 | /* Enable zlps by default for NCM conformance; | ||
844 | * override for musb_hdrc (avoids txdma ovhead) | ||
845 | */ | ||
846 | ncm->port.is_zlp_ok = !( | ||
847 | gadget_is_musbhdrc(cdev->gadget) | ||
848 | ); | ||
849 | ncm->port.cdc_filter = DEFAULT_FILTER; | ||
850 | DBG(cdev, "activate ncm\n"); | ||
851 | net = gether_connect(&ncm->port); | ||
852 | if (IS_ERR(net)) | ||
853 | return PTR_ERR(net); | ||
854 | } | ||
855 | |||
856 | spin_lock(&ncm->lock); | ||
857 | ncm_notify(ncm); | ||
858 | spin_unlock(&ncm->lock); | ||
859 | } else | ||
860 | goto fail; | ||
861 | |||
862 | return 0; | ||
863 | fail: | ||
864 | return -EINVAL; | ||
865 | } | ||
866 | |||
867 | /* | ||
868 | * Because the data interface supports multiple altsettings, | ||
869 | * this NCM function *MUST* implement a get_alt() method. | ||
870 | */ | ||
871 | static int ncm_get_alt(struct usb_function *f, unsigned intf) | ||
872 | { | ||
873 | struct f_ncm *ncm = func_to_ncm(f); | ||
874 | |||
875 | if (intf == ncm->ctrl_id) | ||
876 | return 0; | ||
877 | return ncm->port.in_ep->driver_data ? 1 : 0; | ||
878 | } | ||
879 | |||
880 | static struct sk_buff *ncm_wrap_ntb(struct gether *port, | ||
881 | struct sk_buff *skb) | ||
882 | { | ||
883 | struct f_ncm *ncm = func_to_ncm(&port->func); | ||
884 | struct sk_buff *skb2; | ||
885 | int ncb_len = 0; | ||
886 | __le16 *tmp; | ||
887 | int div = ntb_parameters.wNdpInDivisor; | ||
888 | int rem = ntb_parameters.wNdpInPayloadRemainder; | ||
889 | int pad; | ||
890 | int ndp_align = ntb_parameters.wNdpInAlignment; | ||
891 | int ndp_pad; | ||
892 | unsigned max_size = ncm->port.fixed_in_len; | ||
893 | struct ndp_parser_opts *opts = ncm->parser_opts; | ||
894 | unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; | ||
895 | |||
896 | ncb_len += opts->nth_size; | ||
897 | ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len; | ||
898 | ncb_len += ndp_pad; | ||
899 | ncb_len += opts->ndp_size; | ||
900 | ncb_len += 2 * 2 * opts->dgram_item_len; /* Datagram entry */ | ||
901 | ncb_len += 2 * 2 * opts->dgram_item_len; /* Zero datagram entry */ | ||
902 | pad = ALIGN(ncb_len, div) + rem - ncb_len; | ||
903 | ncb_len += pad; | ||
904 | |||
905 | if (ncb_len + skb->len + crc_len > max_size) { | ||
906 | dev_kfree_skb_any(skb); | ||
907 | return NULL; | ||
908 | } | ||
909 | |||
910 | skb2 = skb_copy_expand(skb, ncb_len, | ||
911 | max_size - skb->len - ncb_len - crc_len, | ||
912 | GFP_ATOMIC); | ||
913 | dev_kfree_skb_any(skb); | ||
914 | if (!skb2) | ||
915 | return NULL; | ||
916 | |||
917 | skb = skb2; | ||
918 | |||
919 | tmp = (void *) skb_push(skb, ncb_len); | ||
920 | memset(tmp, 0, ncb_len); | ||
921 | |||
922 | put_unaligned_le32(opts->nth_sign, tmp); /* dwSignature */ | ||
923 | tmp += 2; | ||
924 | /* wHeaderLength */ | ||
925 | put_unaligned_le16(opts->nth_size, tmp++); | ||
926 | tmp++; /* skip wSequence */ | ||
927 | put_ncm(&tmp, opts->block_length, skb->len); /* (d)wBlockLength */ | ||
928 | /* (d)wFpIndex */ | ||
929 | /* the first pointer is right after the NTH + align */ | ||
930 | put_ncm(&tmp, opts->fp_index, opts->nth_size + ndp_pad); | ||
931 | |||
932 | tmp = (void *)tmp + ndp_pad; | ||
933 | |||
934 | /* NDP */ | ||
935 | put_unaligned_le32(opts->ndp_sign, tmp); /* dwSignature */ | ||
936 | tmp += 2; | ||
937 | /* wLength */ | ||
938 | put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++); | ||
939 | |||
940 | tmp += opts->reserved1; | ||
941 | tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */ | ||
942 | tmp += opts->reserved2; | ||
943 | |||
944 | if (ncm->is_crc) { | ||
945 | uint32_t crc; | ||
946 | |||
947 | crc = ~crc32_le(~0, | ||
948 | skb->data + ncb_len, | ||
949 | skb->len - ncb_len); | ||
950 | put_unaligned_le32(crc, skb->data + skb->len); | ||
951 | skb_put(skb, crc_len); | ||
952 | } | ||
953 | |||
954 | /* (d)wDatagramIndex[0] */ | ||
955 | put_ncm(&tmp, opts->dgram_item_len, ncb_len); | ||
956 | /* (d)wDatagramLength[0] */ | ||
957 | put_ncm(&tmp, opts->dgram_item_len, skb->len - ncb_len); | ||
958 | /* (d)wDatagramIndex[1] and (d)wDatagramLength[1] already zeroed */ | ||
959 | |||
960 | if (skb->len > MAX_TX_NONFIXED) | ||
961 | memset(skb_put(skb, max_size - skb->len), | ||
962 | 0, max_size - skb->len); | ||
963 | |||
964 | return skb; | ||
965 | } | ||
966 | |||
967 | static int ncm_unwrap_ntb(struct gether *port, | ||
968 | struct sk_buff *skb, | ||
969 | struct sk_buff_head *list) | ||
970 | { | ||
971 | struct f_ncm *ncm = func_to_ncm(&port->func); | ||
972 | __le16 *tmp = (void *) skb->data; | ||
973 | unsigned index, index2; | ||
974 | unsigned dg_len, dg_len2; | ||
975 | unsigned ndp_len; | ||
976 | struct sk_buff *skb2; | ||
977 | int ret = -EINVAL; | ||
978 | unsigned max_size = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); | ||
979 | struct ndp_parser_opts *opts = ncm->parser_opts; | ||
980 | unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; | ||
981 | int dgram_counter; | ||
982 | |||
983 | /* dwSignature */ | ||
984 | if (get_unaligned_le32(tmp) != opts->nth_sign) { | ||
985 | INFO(port->func.config->cdev, "Wrong NTH SIGN, skblen %d\n", | ||
986 | skb->len); | ||
987 | print_hex_dump(KERN_INFO, "HEAD:", DUMP_PREFIX_ADDRESS, 32, 1, | ||
988 | skb->data, 32, false); | ||
989 | |||
990 | goto err; | ||
991 | } | ||
992 | tmp += 2; | ||
993 | /* wHeaderLength */ | ||
994 | if (get_unaligned_le16(tmp++) != opts->nth_size) { | ||
995 | INFO(port->func.config->cdev, "Wrong NTB headersize\n"); | ||
996 | goto err; | ||
997 | } | ||
998 | tmp++; /* skip wSequence */ | ||
999 | |||
1000 | /* (d)wBlockLength */ | ||
1001 | if (get_ncm(&tmp, opts->block_length) > max_size) { | ||
1002 | INFO(port->func.config->cdev, "OUT size exceeded\n"); | ||
1003 | goto err; | ||
1004 | } | ||
1005 | |||
1006 | index = get_ncm(&tmp, opts->fp_index); | ||
1007 | /* NCM 3.2 */ | ||
1008 | if (((index % 4) != 0) && (index < opts->nth_size)) { | ||
1009 | INFO(port->func.config->cdev, "Bad index: %x\n", | ||
1010 | index); | ||
1011 | goto err; | ||
1012 | } | ||
1013 | |||
1014 | /* walk through NDP */ | ||
1015 | tmp = ((void *)skb->data) + index; | ||
1016 | if (get_unaligned_le32(tmp) != opts->ndp_sign) { | ||
1017 | INFO(port->func.config->cdev, "Wrong NDP SIGN\n"); | ||
1018 | goto err; | ||
1019 | } | ||
1020 | tmp += 2; | ||
1021 | |||
1022 | ndp_len = get_unaligned_le16(tmp++); | ||
1023 | /* | ||
1024 | * NCM 3.3.1 | ||
1025 | * entry is 2 items | ||
1026 | * item size is 16/32 bits, opts->dgram_item_len * 2 bytes | ||
1027 | * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry | ||
1028 | */ | ||
1029 | if ((ndp_len < opts->ndp_size + 2 * 2 * (opts->dgram_item_len * 2)) | ||
1030 | || (ndp_len % opts->ndplen_align != 0)) { | ||
1031 | INFO(port->func.config->cdev, "Bad NDP length: %x\n", ndp_len); | ||
1032 | goto err; | ||
1033 | } | ||
1034 | tmp += opts->reserved1; | ||
1035 | tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */ | ||
1036 | tmp += opts->reserved2; | ||
1037 | |||
1038 | ndp_len -= opts->ndp_size; | ||
1039 | index2 = get_ncm(&tmp, opts->dgram_item_len); | ||
1040 | dg_len2 = get_ncm(&tmp, opts->dgram_item_len); | ||
1041 | dgram_counter = 0; | ||
1042 | |||
1043 | do { | ||
1044 | index = index2; | ||
1045 | dg_len = dg_len2; | ||
1046 | if (dg_len < 14 + crc_len) { /* ethernet header + crc */ | ||
1047 | INFO(port->func.config->cdev, "Bad dgram length: %x\n", | ||
1048 | dg_len); | ||
1049 | goto err; | ||
1050 | } | ||
1051 | if (ncm->is_crc) { | ||
1052 | uint32_t crc, crc2; | ||
1053 | |||
1054 | crc = get_unaligned_le32(skb->data + | ||
1055 | index + dg_len - crc_len); | ||
1056 | crc2 = ~crc32_le(~0, | ||
1057 | skb->data + index, | ||
1058 | dg_len - crc_len); | ||
1059 | if (crc != crc2) { | ||
1060 | INFO(port->func.config->cdev, "Bad CRC\n"); | ||
1061 | goto err; | ||
1062 | } | ||
1063 | } | ||
1064 | |||
1065 | index2 = get_ncm(&tmp, opts->dgram_item_len); | ||
1066 | dg_len2 = get_ncm(&tmp, opts->dgram_item_len); | ||
1067 | |||
1068 | if (index2 == 0 || dg_len2 == 0) { | ||
1069 | skb2 = skb; | ||
1070 | } else { | ||
1071 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
1072 | if (skb2 == NULL) | ||
1073 | goto err; | ||
1074 | } | ||
1075 | |||
1076 | if (!skb_pull(skb2, index)) { | ||
1077 | ret = -EOVERFLOW; | ||
1078 | goto err; | ||
1079 | } | ||
1080 | |||
1081 | skb_trim(skb2, dg_len - crc_len); | ||
1082 | skb_queue_tail(list, skb2); | ||
1083 | |||
1084 | ndp_len -= 2 * (opts->dgram_item_len * 2); | ||
1085 | |||
1086 | dgram_counter++; | ||
1087 | |||
1088 | if (index2 == 0 || dg_len2 == 0) | ||
1089 | break; | ||
1090 | } while (ndp_len > 2 * (opts->dgram_item_len * 2)); /* zero entry */ | ||
1091 | |||
1092 | VDBG(port->func.config->cdev, | ||
1093 | "Parsed NTB with %d frames\n", dgram_counter); | ||
1094 | return 0; | ||
1095 | err: | ||
1096 | skb_queue_purge(list); | ||
1097 | dev_kfree_skb_any(skb); | ||
1098 | return ret; | ||
1099 | } | ||
1100 | |||
1101 | static void ncm_disable(struct usb_function *f) | ||
1102 | { | ||
1103 | struct f_ncm *ncm = func_to_ncm(f); | ||
1104 | struct usb_composite_dev *cdev = f->config->cdev; | ||
1105 | |||
1106 | DBG(cdev, "ncm deactivated\n"); | ||
1107 | |||
1108 | if (ncm->port.in_ep->driver_data) | ||
1109 | gether_disconnect(&ncm->port); | ||
1110 | |||
1111 | if (ncm->notify->driver_data) { | ||
1112 | usb_ep_disable(ncm->notify); | ||
1113 | ncm->notify->driver_data = NULL; | ||
1114 | ncm->notify_desc = NULL; | ||
1115 | } | ||
1116 | } | ||
1117 | |||
1118 | /*-------------------------------------------------------------------------*/ | ||
1119 | |||
1120 | /* | ||
1121 | * Callbacks let us notify the host about connect/disconnect when the | ||
1122 | * net device is opened or closed. | ||
1123 | * | ||
1124 | * For testing, note that link states on this side include both opened | ||
1125 | * and closed variants of: | ||
1126 | * | ||
1127 | * - disconnected/unconfigured | ||
1128 | * - configured but inactive (data alt 0) | ||
1129 | * - configured and active (data alt 1) | ||
1130 | * | ||
1131 | * Each needs to be tested with unplug, rmmod, SET_CONFIGURATION, and | ||
1132 | * SET_INTERFACE (altsetting). Remember also that "configured" doesn't | ||
1133 | * imply the host is actually polling the notification endpoint, and | ||
1134 | * likewise that "active" doesn't imply it's actually using the data | ||
1135 | * endpoints for traffic. | ||
1136 | */ | ||
1137 | |||
1138 | static void ncm_open(struct gether *geth) | ||
1139 | { | ||
1140 | struct f_ncm *ncm = func_to_ncm(&geth->func); | ||
1141 | |||
1142 | DBG(ncm->port.func.config->cdev, "%s\n", __func__); | ||
1143 | |||
1144 | spin_lock(&ncm->lock); | ||
1145 | ncm->is_open = true; | ||
1146 | ncm_notify(ncm); | ||
1147 | spin_unlock(&ncm->lock); | ||
1148 | } | ||
1149 | |||
1150 | static void ncm_close(struct gether *geth) | ||
1151 | { | ||
1152 | struct f_ncm *ncm = func_to_ncm(&geth->func); | ||
1153 | |||
1154 | DBG(ncm->port.func.config->cdev, "%s\n", __func__); | ||
1155 | |||
1156 | spin_lock(&ncm->lock); | ||
1157 | ncm->is_open = false; | ||
1158 | ncm_notify(ncm); | ||
1159 | spin_unlock(&ncm->lock); | ||
1160 | } | ||
1161 | |||
1162 | /*-------------------------------------------------------------------------*/ | ||
1163 | |||
1164 | /* ethernet function driver setup/binding */ | ||
1165 | |||
1166 | static int __init | ||
1167 | ncm_bind(struct usb_configuration *c, struct usb_function *f) | ||
1168 | { | ||
1169 | struct usb_composite_dev *cdev = c->cdev; | ||
1170 | struct f_ncm *ncm = func_to_ncm(f); | ||
1171 | int status; | ||
1172 | struct usb_ep *ep; | ||
1173 | |||
1174 | /* allocate instance-specific interface IDs */ | ||
1175 | status = usb_interface_id(c, f); | ||
1176 | if (status < 0) | ||
1177 | goto fail; | ||
1178 | ncm->ctrl_id = status; | ||
1179 | ncm_iad_desc.bFirstInterface = status; | ||
1180 | |||
1181 | ncm_control_intf.bInterfaceNumber = status; | ||
1182 | ncm_union_desc.bMasterInterface0 = status; | ||
1183 | |||
1184 | status = usb_interface_id(c, f); | ||
1185 | if (status < 0) | ||
1186 | goto fail; | ||
1187 | ncm->data_id = status; | ||
1188 | |||
1189 | ncm_data_nop_intf.bInterfaceNumber = status; | ||
1190 | ncm_data_intf.bInterfaceNumber = status; | ||
1191 | ncm_union_desc.bSlaveInterface0 = status; | ||
1192 | |||
1193 | status = -ENODEV; | ||
1194 | |||
1195 | /* allocate instance-specific endpoints */ | ||
1196 | ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_in_desc); | ||
1197 | if (!ep) | ||
1198 | goto fail; | ||
1199 | ncm->port.in_ep = ep; | ||
1200 | ep->driver_data = cdev; /* claim */ | ||
1201 | |||
1202 | ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_out_desc); | ||
1203 | if (!ep) | ||
1204 | goto fail; | ||
1205 | ncm->port.out_ep = ep; | ||
1206 | ep->driver_data = cdev; /* claim */ | ||
1207 | |||
1208 | ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_notify_desc); | ||
1209 | if (!ep) | ||
1210 | goto fail; | ||
1211 | ncm->notify = ep; | ||
1212 | ep->driver_data = cdev; /* claim */ | ||
1213 | |||
1214 | status = -ENOMEM; | ||
1215 | |||
1216 | /* allocate notification request and buffer */ | ||
1217 | ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); | ||
1218 | if (!ncm->notify_req) | ||
1219 | goto fail; | ||
1220 | ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); | ||
1221 | if (!ncm->notify_req->buf) | ||
1222 | goto fail; | ||
1223 | ncm->notify_req->context = ncm; | ||
1224 | ncm->notify_req->complete = ncm_notify_complete; | ||
1225 | |||
1226 | /* copy descriptors, and track endpoint copies */ | ||
1227 | f->descriptors = usb_copy_descriptors(ncm_fs_function); | ||
1228 | if (!f->descriptors) | ||
1229 | goto fail; | ||
1230 | |||
1231 | ncm->fs.in = usb_find_endpoint(ncm_fs_function, | ||
1232 | f->descriptors, &fs_ncm_in_desc); | ||
1233 | ncm->fs.out = usb_find_endpoint(ncm_fs_function, | ||
1234 | f->descriptors, &fs_ncm_out_desc); | ||
1235 | ncm->fs.notify = usb_find_endpoint(ncm_fs_function, | ||
1236 | f->descriptors, &fs_ncm_notify_desc); | ||
1237 | |||
1238 | /* | ||
1239 | * support all relevant hardware speeds... we expect that when | ||
1240 | * hardware is dual speed, all bulk-capable endpoints work at | ||
1241 | * both speeds | ||
1242 | */ | ||
1243 | if (gadget_is_dualspeed(c->cdev->gadget)) { | ||
1244 | hs_ncm_in_desc.bEndpointAddress = | ||
1245 | fs_ncm_in_desc.bEndpointAddress; | ||
1246 | hs_ncm_out_desc.bEndpointAddress = | ||
1247 | fs_ncm_out_desc.bEndpointAddress; | ||
1248 | hs_ncm_notify_desc.bEndpointAddress = | ||
1249 | fs_ncm_notify_desc.bEndpointAddress; | ||
1250 | |||
1251 | /* copy descriptors, and track endpoint copies */ | ||
1252 | f->hs_descriptors = usb_copy_descriptors(ncm_hs_function); | ||
1253 | if (!f->hs_descriptors) | ||
1254 | goto fail; | ||
1255 | |||
1256 | ncm->hs.in = usb_find_endpoint(ncm_hs_function, | ||
1257 | f->hs_descriptors, &hs_ncm_in_desc); | ||
1258 | ncm->hs.out = usb_find_endpoint(ncm_hs_function, | ||
1259 | f->hs_descriptors, &hs_ncm_out_desc); | ||
1260 | ncm->hs.notify = usb_find_endpoint(ncm_hs_function, | ||
1261 | f->hs_descriptors, &hs_ncm_notify_desc); | ||
1262 | } | ||
1263 | |||
1264 | /* | ||
1265 | * NOTE: all that is done without knowing or caring about | ||
1266 | * the network link ... which is unavailable to this code | ||
1267 | * until we're activated via set_alt(). | ||
1268 | */ | ||
1269 | |||
1270 | ncm->port.open = ncm_open; | ||
1271 | ncm->port.close = ncm_close; | ||
1272 | |||
1273 | DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n", | ||
1274 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | ||
1275 | ncm->port.in_ep->name, ncm->port.out_ep->name, | ||
1276 | ncm->notify->name); | ||
1277 | return 0; | ||
1278 | |||
1279 | fail: | ||
1280 | if (f->descriptors) | ||
1281 | usb_free_descriptors(f->descriptors); | ||
1282 | |||
1283 | if (ncm->notify_req) { | ||
1284 | kfree(ncm->notify_req->buf); | ||
1285 | usb_ep_free_request(ncm->notify, ncm->notify_req); | ||
1286 | } | ||
1287 | |||
1288 | /* we might as well release our claims on endpoints */ | ||
1289 | if (ncm->notify) | ||
1290 | ncm->notify->driver_data = NULL; | ||
1291 | if (ncm->port.out) | ||
1292 | ncm->port.out_ep->driver_data = NULL; | ||
1293 | if (ncm->port.in) | ||
1294 | ncm->port.in_ep->driver_data = NULL; | ||
1295 | |||
1296 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | ||
1297 | |||
1298 | return status; | ||
1299 | } | ||
1300 | |||
1301 | static void | ||
1302 | ncm_unbind(struct usb_configuration *c, struct usb_function *f) | ||
1303 | { | ||
1304 | struct f_ncm *ncm = func_to_ncm(f); | ||
1305 | |||
1306 | DBG(c->cdev, "ncm unbind\n"); | ||
1307 | |||
1308 | if (gadget_is_dualspeed(c->cdev->gadget)) | ||
1309 | usb_free_descriptors(f->hs_descriptors); | ||
1310 | usb_free_descriptors(f->descriptors); | ||
1311 | |||
1312 | kfree(ncm->notify_req->buf); | ||
1313 | usb_ep_free_request(ncm->notify, ncm->notify_req); | ||
1314 | |||
1315 | ncm_string_defs[1].s = NULL; | ||
1316 | kfree(ncm); | ||
1317 | } | ||
1318 | |||
1319 | /** | ||
1320 | * ncm_bind_config - add CDC Network link to a configuration | ||
1321 | * @c: the configuration to support the network link | ||
1322 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
1323 | * side of the link was recorded | ||
1324 | * Context: single threaded during gadget setup | ||
1325 | * | ||
1326 | * Returns zero on success, else negative errno. | ||
1327 | * | ||
1328 | * Caller must have called @gether_setup(). Caller is also responsible | ||
1329 | * for calling @gether_cleanup() before module unload. | ||
1330 | */ | ||
1331 | int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | ||
1332 | { | ||
1333 | struct f_ncm *ncm; | ||
1334 | int status; | ||
1335 | |||
1336 | if (!can_support_ecm(c->cdev->gadget) || !ethaddr) | ||
1337 | return -EINVAL; | ||
1338 | |||
1339 | /* maybe allocate device-global string IDs */ | ||
1340 | if (ncm_string_defs[0].id == 0) { | ||
1341 | |||
1342 | /* control interface label */ | ||
1343 | status = usb_string_id(c->cdev); | ||
1344 | if (status < 0) | ||
1345 | return status; | ||
1346 | ncm_string_defs[STRING_CTRL_IDX].id = status; | ||
1347 | ncm_control_intf.iInterface = status; | ||
1348 | |||
1349 | /* data interface label */ | ||
1350 | status = usb_string_id(c->cdev); | ||
1351 | if (status < 0) | ||
1352 | return status; | ||
1353 | ncm_string_defs[STRING_DATA_IDX].id = status; | ||
1354 | ncm_data_nop_intf.iInterface = status; | ||
1355 | ncm_data_intf.iInterface = status; | ||
1356 | |||
1357 | /* MAC address */ | ||
1358 | status = usb_string_id(c->cdev); | ||
1359 | if (status < 0) | ||
1360 | return status; | ||
1361 | ncm_string_defs[STRING_MAC_IDX].id = status; | ||
1362 | ecm_desc.iMACAddress = status; | ||
1363 | |||
1364 | /* IAD */ | ||
1365 | status = usb_string_id(c->cdev); | ||
1366 | if (status < 0) | ||
1367 | return status; | ||
1368 | ncm_string_defs[STRING_IAD_IDX].id = status; | ||
1369 | ncm_iad_desc.iFunction = status; | ||
1370 | } | ||
1371 | |||
1372 | /* allocate and initialize one new instance */ | ||
1373 | ncm = kzalloc(sizeof *ncm, GFP_KERNEL); | ||
1374 | if (!ncm) | ||
1375 | return -ENOMEM; | ||
1376 | |||
1377 | /* export host's Ethernet address in CDC format */ | ||
1378 | snprintf(ncm->ethaddr, sizeof ncm->ethaddr, | ||
1379 | "%02X%02X%02X%02X%02X%02X", | ||
1380 | ethaddr[0], ethaddr[1], ethaddr[2], | ||
1381 | ethaddr[3], ethaddr[4], ethaddr[5]); | ||
1382 | ncm_string_defs[1].s = ncm->ethaddr; | ||
1383 | |||
1384 | spin_lock_init(&ncm->lock); | ||
1385 | ncm_reset_values(ncm); | ||
1386 | ncm->port.is_fixed = true; | ||
1387 | |||
1388 | ncm->port.func.name = "cdc_network"; | ||
1389 | ncm->port.func.strings = ncm_strings; | ||
1390 | /* descriptors are per-instance copies */ | ||
1391 | ncm->port.func.bind = ncm_bind; | ||
1392 | ncm->port.func.unbind = ncm_unbind; | ||
1393 | ncm->port.func.set_alt = ncm_set_alt; | ||
1394 | ncm->port.func.get_alt = ncm_get_alt; | ||
1395 | ncm->port.func.setup = ncm_setup; | ||
1396 | ncm->port.func.disable = ncm_disable; | ||
1397 | |||
1398 | ncm->port.wrap = ncm_wrap_ntb; | ||
1399 | ncm->port.unwrap = ncm_unwrap_ntb; | ||
1400 | |||
1401 | status = usb_add_function(c, &ncm->port.func); | ||
1402 | if (status) { | ||
1403 | ncm_string_defs[1].s = NULL; | ||
1404 | kfree(ncm); | ||
1405 | } | ||
1406 | return status; | ||
1407 | } | ||
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index aeb109bd317d..5c2720d64ffa 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -120,10 +120,10 @@ | |||
120 | #define gadget_is_fsl_qe(g) 0 | 120 | #define gadget_is_fsl_qe(g) 0 |
121 | #endif | 121 | #endif |
122 | 122 | ||
123 | #ifdef CONFIG_USB_GADGET_CI13XXX | 123 | #ifdef CONFIG_USB_GADGET_CI13XXX_PCI |
124 | #define gadget_is_ci13xxx(g) (!strcmp("ci13xxx_udc", (g)->name)) | 124 | #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name)) |
125 | #else | 125 | #else |
126 | #define gadget_is_ci13xxx(g) 0 | 126 | #define gadget_is_ci13xxx_pci(g) 0 |
127 | #endif | 127 | #endif |
128 | 128 | ||
129 | // CONFIG_USB_GADGET_SX2 | 129 | // CONFIG_USB_GADGET_SX2 |
@@ -148,6 +148,12 @@ | |||
148 | #define gadget_is_pch(g) 0 | 148 | #define gadget_is_pch(g) 0 |
149 | #endif | 149 | #endif |
150 | 150 | ||
151 | #ifdef CONFIG_USB_GADGET_CI13XXX_MSM | ||
152 | #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) | ||
153 | #else | ||
154 | #define gadget_is_ci13xxx_msm(g) 0 | ||
155 | #endif | ||
156 | |||
151 | /** | 157 | /** |
152 | * usb_gadget_controller_number - support bcdDevice id convention | 158 | * usb_gadget_controller_number - support bcdDevice id convention |
153 | * @gadget: the controller being driven | 159 | * @gadget: the controller being driven |
@@ -197,7 +203,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
197 | return 0x21; | 203 | return 0x21; |
198 | else if (gadget_is_fsl_qe(gadget)) | 204 | else if (gadget_is_fsl_qe(gadget)) |
199 | return 0x22; | 205 | return 0x22; |
200 | else if (gadget_is_ci13xxx(gadget)) | 206 | else if (gadget_is_ci13xxx_pci(gadget)) |
201 | return 0x23; | 207 | return 0x23; |
202 | else if (gadget_is_langwell(gadget)) | 208 | else if (gadget_is_langwell(gadget)) |
203 | return 0x24; | 209 | return 0x24; |
@@ -207,6 +213,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
207 | return 0x26; | 213 | return 0x26; |
208 | else if (gadget_is_pch(gadget)) | 214 | else if (gadget_is_pch(gadget)) |
209 | return 0x27; | 215 | return 0x27; |
216 | else if (gadget_is_ci13xxx_msm(gadget)) | ||
217 | return 0x28; | ||
210 | return -ENOENT; | 218 | return -ENOENT; |
211 | } | 219 | } |
212 | 220 | ||
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c index b30f85d70480..1210534822d6 100644 --- a/drivers/usb/gadget/imx_udc.c +++ b/drivers/usb/gadget/imx_udc.c | |||
@@ -1191,13 +1191,17 @@ static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev) | |||
1191 | return IRQ_HANDLED; | 1191 | return IRQ_HANDLED; |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | #ifndef MX1_INT_USBD0 | ||
1195 | #define MX1_INT_USBD0 MX1_USBD_INT0 | ||
1196 | #endif | ||
1197 | |||
1194 | static irqreturn_t imx_udc_bulk_irq(int irq, void *dev) | 1198 | static irqreturn_t imx_udc_bulk_irq(int irq, void *dev) |
1195 | { | 1199 | { |
1196 | struct imx_udc_struct *imx_usb = dev; | 1200 | struct imx_udc_struct *imx_usb = dev; |
1197 | struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[irq - MX1_USBD_INT0]; | 1201 | struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[irq - MX1_INT_USBD0]; |
1198 | int intr = __raw_readl(imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); | 1202 | int intr = __raw_readl(imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); |
1199 | 1203 | ||
1200 | dump_ep_intr(__func__, irq - MX1_USBD_INT0, intr, imx_usb->dev); | 1204 | dump_ep_intr(__func__, irq - MX1_INT_USBD0, intr, imx_usb->dev); |
1201 | 1205 | ||
1202 | if (!imx_usb->driver) { | 1206 | if (!imx_usb->driver) { |
1203 | __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); | 1207 | __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); |
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c new file mode 100644 index 000000000000..99c179ad729d --- /dev/null +++ b/drivers/usb/gadget/ncm.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /* | ||
2 | * ncm.c -- NCM gadget driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Nokia Corporation | ||
5 | * Contact: Yauheni Kaliuta <yauheni.kaliuta@nokia.com> | ||
6 | * | ||
7 | * The driver borrows from ether.c which is: | ||
8 | * | ||
9 | * Copyright (C) 2003-2005,2008 David Brownell | ||
10 | * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger | ||
11 | * Copyright (C) 2008 Nokia Corporation | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
26 | */ | ||
27 | |||
28 | /* #define DEBUG */ | ||
29 | /* #define VERBOSE_DEBUG */ | ||
30 | |||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/utsname.h> | ||
33 | |||
34 | |||
35 | #include "u_ether.h" | ||
36 | |||
37 | #define DRIVER_DESC "NCM Gadget" | ||
38 | |||
39 | /*-------------------------------------------------------------------------*/ | ||
40 | |||
41 | /* | ||
42 | * Kbuild is not very cooperative with respect to linking separately | ||
43 | * compiled library objects into one module. So for now we won't use | ||
44 | * separate compilation ... ensuring init/exit sections work to shrink | ||
45 | * the runtime footprint, and giving us at least some parts of what | ||
46 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
47 | */ | ||
48 | #include "composite.c" | ||
49 | #include "usbstring.c" | ||
50 | #include "config.c" | ||
51 | #include "epautoconf.c" | ||
52 | |||
53 | #include "f_ncm.c" | ||
54 | #include "u_ether.c" | ||
55 | |||
56 | /*-------------------------------------------------------------------------*/ | ||
57 | |||
58 | /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! | ||
59 | * Instead: allocate your own, using normal USB-IF procedures. | ||
60 | */ | ||
61 | |||
62 | /* Thanks to NetChip Technologies for donating this product ID. | ||
63 | * It's for devices with only CDC Ethernet configurations. | ||
64 | */ | ||
65 | #define CDC_VENDOR_NUM 0x0525 /* NetChip */ | ||
66 | #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ | ||
67 | |||
68 | /*-------------------------------------------------------------------------*/ | ||
69 | |||
70 | static struct usb_device_descriptor device_desc = { | ||
71 | .bLength = sizeof device_desc, | ||
72 | .bDescriptorType = USB_DT_DEVICE, | ||
73 | |||
74 | .bcdUSB = cpu_to_le16 (0x0200), | ||
75 | |||
76 | .bDeviceClass = USB_CLASS_COMM, | ||
77 | .bDeviceSubClass = 0, | ||
78 | .bDeviceProtocol = 0, | ||
79 | /* .bMaxPacketSize0 = f(hardware) */ | ||
80 | |||
81 | /* Vendor and product id defaults change according to what configs | ||
82 | * we support. (As does bNumConfigurations.) These values can | ||
83 | * also be overridden by module parameters. | ||
84 | */ | ||
85 | .idVendor = cpu_to_le16 (CDC_VENDOR_NUM), | ||
86 | .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM), | ||
87 | /* .bcdDevice = f(hardware) */ | ||
88 | /* .iManufacturer = DYNAMIC */ | ||
89 | /* .iProduct = DYNAMIC */ | ||
90 | /* NO SERIAL NUMBER */ | ||
91 | .bNumConfigurations = 1, | ||
92 | }; | ||
93 | |||
94 | static struct usb_otg_descriptor otg_descriptor = { | ||
95 | .bLength = sizeof otg_descriptor, | ||
96 | .bDescriptorType = USB_DT_OTG, | ||
97 | |||
98 | /* REVISIT SRP-only hardware is possible, although | ||
99 | * it would not be called "OTG" ... | ||
100 | */ | ||
101 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, | ||
102 | }; | ||
103 | |||
104 | static const struct usb_descriptor_header *otg_desc[] = { | ||
105 | (struct usb_descriptor_header *) &otg_descriptor, | ||
106 | NULL, | ||
107 | }; | ||
108 | |||
109 | |||
110 | /* string IDs are assigned dynamically */ | ||
111 | |||
112 | #define STRING_MANUFACTURER_IDX 0 | ||
113 | #define STRING_PRODUCT_IDX 1 | ||
114 | |||
115 | static char manufacturer[50]; | ||
116 | |||
117 | static struct usb_string strings_dev[] = { | ||
118 | [STRING_MANUFACTURER_IDX].s = manufacturer, | ||
119 | [STRING_PRODUCT_IDX].s = DRIVER_DESC, | ||
120 | { } /* end of list */ | ||
121 | }; | ||
122 | |||
123 | static struct usb_gadget_strings stringtab_dev = { | ||
124 | .language = 0x0409, /* en-us */ | ||
125 | .strings = strings_dev, | ||
126 | }; | ||
127 | |||
128 | static struct usb_gadget_strings *dev_strings[] = { | ||
129 | &stringtab_dev, | ||
130 | NULL, | ||
131 | }; | ||
132 | |||
133 | static u8 hostaddr[ETH_ALEN]; | ||
134 | |||
135 | /*-------------------------------------------------------------------------*/ | ||
136 | |||
137 | static int __init ncm_do_config(struct usb_configuration *c) | ||
138 | { | ||
139 | /* FIXME alloc iConfiguration string, set it in c->strings */ | ||
140 | |||
141 | if (gadget_is_otg(c->cdev->gadget)) { | ||
142 | c->descriptors = otg_desc; | ||
143 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | ||
144 | } | ||
145 | |||
146 | return ncm_bind_config(c, hostaddr); | ||
147 | } | ||
148 | |||
149 | static struct usb_configuration ncm_config_driver = { | ||
150 | /* .label = f(hardware) */ | ||
151 | .label = "CDC Ethernet (NCM)", | ||
152 | .bConfigurationValue = 1, | ||
153 | /* .iConfiguration = DYNAMIC */ | ||
154 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
155 | }; | ||
156 | |||
157 | /*-------------------------------------------------------------------------*/ | ||
158 | |||
159 | static int __init gncm_bind(struct usb_composite_dev *cdev) | ||
160 | { | ||
161 | int gcnum; | ||
162 | struct usb_gadget *gadget = cdev->gadget; | ||
163 | int status; | ||
164 | |||
165 | /* set up network link layer */ | ||
166 | status = gether_setup(cdev->gadget, hostaddr); | ||
167 | if (status < 0) | ||
168 | return status; | ||
169 | |||
170 | gcnum = usb_gadget_controller_number(gadget); | ||
171 | if (gcnum >= 0) | ||
172 | device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); | ||
173 | else { | ||
174 | /* We assume that can_support_ecm() tells the truth; | ||
175 | * but if the controller isn't recognized at all then | ||
176 | * that assumption is a bit more likely to be wrong. | ||
177 | */ | ||
178 | dev_warn(&gadget->dev, | ||
179 | "controller '%s' not recognized; trying %s\n", | ||
180 | gadget->name, | ||
181 | ncm_config_driver.label); | ||
182 | device_desc.bcdDevice = | ||
183 | cpu_to_le16(0x0300 | 0x0099); | ||
184 | } | ||
185 | |||
186 | |||
187 | /* Allocate string descriptor numbers ... note that string | ||
188 | * contents can be overridden by the composite_dev glue. | ||
189 | */ | ||
190 | |||
191 | /* device descriptor strings: manufacturer, product */ | ||
192 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", | ||
193 | init_utsname()->sysname, init_utsname()->release, | ||
194 | gadget->name); | ||
195 | status = usb_string_id(cdev); | ||
196 | if (status < 0) | ||
197 | goto fail; | ||
198 | strings_dev[STRING_MANUFACTURER_IDX].id = status; | ||
199 | device_desc.iManufacturer = status; | ||
200 | |||
201 | status = usb_string_id(cdev); | ||
202 | if (status < 0) | ||
203 | goto fail; | ||
204 | strings_dev[STRING_PRODUCT_IDX].id = status; | ||
205 | device_desc.iProduct = status; | ||
206 | |||
207 | status = usb_add_config(cdev, &ncm_config_driver, | ||
208 | ncm_do_config); | ||
209 | if (status < 0) | ||
210 | goto fail; | ||
211 | |||
212 | dev_info(&gadget->dev, "%s\n", DRIVER_DESC); | ||
213 | |||
214 | return 0; | ||
215 | |||
216 | fail: | ||
217 | gether_cleanup(); | ||
218 | return status; | ||
219 | } | ||
220 | |||
221 | static int __exit gncm_unbind(struct usb_composite_dev *cdev) | ||
222 | { | ||
223 | gether_cleanup(); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | static struct usb_composite_driver ncm_driver = { | ||
228 | .name = "g_ncm", | ||
229 | .dev = &device_desc, | ||
230 | .strings = dev_strings, | ||
231 | .unbind = __exit_p(gncm_unbind), | ||
232 | }; | ||
233 | |||
234 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
235 | MODULE_AUTHOR("Yauheni Kaliuta"); | ||
236 | MODULE_LICENSE("GPL"); | ||
237 | |||
238 | static int __init init(void) | ||
239 | { | ||
240 | return usb_composite_probe(&ncm_driver, gncm_bind); | ||
241 | } | ||
242 | module_init(init); | ||
243 | |||
244 | static void __exit cleanup(void) | ||
245 | { | ||
246 | usb_composite_unregister(&ncm_driver); | ||
247 | } | ||
248 | module_exit(cleanup); | ||
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index 4a5256977d29..0c8dd81dddca 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -337,7 +337,7 @@ struct pch_udc_dev { | |||
337 | struct usb_gadget_driver *driver; | 337 | struct usb_gadget_driver *driver; |
338 | struct pci_dev *pdev; | 338 | struct pci_dev *pdev; |
339 | struct pch_udc_ep ep[PCH_UDC_EP_NUM]; | 339 | struct pch_udc_ep ep[PCH_UDC_EP_NUM]; |
340 | spinlock_t lock; | 340 | spinlock_t lock; /* protects all state */ |
341 | unsigned active:1, | 341 | unsigned active:1, |
342 | stall:1, | 342 | stall:1, |
343 | prot_stall:1, | 343 | prot_stall:1, |
@@ -1980,7 +1980,7 @@ static void pch_udc_svc_data_in(struct pch_udc_dev *dev, int ep_num) | |||
1980 | pch_udc_enable_ep_interrupts(ep->dev, | 1980 | pch_udc_enable_ep_interrupts(ep->dev, |
1981 | PCH_UDC_EPINT(ep->in, ep->num)); | 1981 | PCH_UDC_EPINT(ep->in, ep->num)); |
1982 | } | 1982 | } |
1983 | if (epsts & UDC_EPSTS_RCS) | 1983 | if (epsts & UDC_EPSTS_RCS) { |
1984 | if (!dev->prot_stall) { | 1984 | if (!dev->prot_stall) { |
1985 | pch_udc_ep_clear_stall(ep); | 1985 | pch_udc_ep_clear_stall(ep); |
1986 | } else { | 1986 | } else { |
@@ -1988,6 +1988,7 @@ static void pch_udc_svc_data_in(struct pch_udc_dev *dev, int ep_num) | |||
1988 | pch_udc_enable_ep_interrupts(ep->dev, | 1988 | pch_udc_enable_ep_interrupts(ep->dev, |
1989 | PCH_UDC_EPINT(ep->in, ep->num)); | 1989 | PCH_UDC_EPINT(ep->in, ep->num)); |
1990 | } | 1990 | } |
1991 | } | ||
1991 | if (epsts & UDC_EPSTS_TDC) | 1992 | if (epsts & UDC_EPSTS_TDC) |
1992 | pch_udc_complete_transfer(ep); | 1993 | pch_udc_complete_transfer(ep); |
1993 | /* On IN interrupt, provide data if we have any */ | 1994 | /* On IN interrupt, provide data if we have any */ |
@@ -2028,7 +2029,7 @@ static void pch_udc_svc_data_out(struct pch_udc_dev *dev, int ep_num) | |||
2028 | pch_udc_ep_set_stall(ep); | 2029 | pch_udc_ep_set_stall(ep); |
2029 | pch_udc_enable_ep_interrupts(ep->dev, | 2030 | pch_udc_enable_ep_interrupts(ep->dev, |
2030 | PCH_UDC_EPINT(ep->in, ep->num)); | 2031 | PCH_UDC_EPINT(ep->in, ep->num)); |
2031 | if (epsts & UDC_EPSTS_RCS) | 2032 | if (epsts & UDC_EPSTS_RCS) { |
2032 | if (!dev->prot_stall) { | 2033 | if (!dev->prot_stall) { |
2033 | pch_udc_ep_clear_stall(ep); | 2034 | pch_udc_ep_clear_stall(ep); |
2034 | } else { | 2035 | } else { |
@@ -2036,6 +2037,7 @@ static void pch_udc_svc_data_out(struct pch_udc_dev *dev, int ep_num) | |||
2036 | pch_udc_enable_ep_interrupts(ep->dev, | 2037 | pch_udc_enable_ep_interrupts(ep->dev, |
2037 | PCH_UDC_EPINT(ep->in, ep->num)); | 2038 | PCH_UDC_EPINT(ep->in, ep->num)); |
2038 | } | 2039 | } |
2040 | } | ||
2039 | if (((epsts & UDC_EPSTS_OUT_MASK) >> UDC_EPSTS_OUT_SHIFT) == | 2041 | if (((epsts & UDC_EPSTS_OUT_MASK) >> UDC_EPSTS_OUT_SHIFT) == |
2040 | UDC_EPSTS_OUT_DATA) { | 2042 | UDC_EPSTS_OUT_DATA) { |
2041 | if (ep->dev->prot_stall == 1) { | 2043 | if (ep->dev->prot_stall == 1) { |
@@ -2148,7 +2150,10 @@ static void pch_udc_svc_control_out(struct pch_udc_dev *dev) | |||
2148 | pch_udc_set_dma(dev, DMA_DIR_RX); | 2150 | pch_udc_set_dma(dev, DMA_DIR_RX); |
2149 | } else { | 2151 | } else { |
2150 | /* control write */ | 2152 | /* control write */ |
2151 | pch_udc_svc_data_out(dev, UDC_EP0OUT_IDX); | 2153 | /* next function will pickuo an clear the status */ |
2154 | ep->epsts = stat; | ||
2155 | |||
2156 | pch_udc_svc_data_out(dev, 0); | ||
2152 | /* re-program desc. pointer for possible ZLPs */ | 2157 | /* re-program desc. pointer for possible ZLPs */ |
2153 | pch_udc_ep_set_ddptr(ep, ep->td_data_phys); | 2158 | pch_udc_ep_set_ddptr(ep, ep->td_data_phys); |
2154 | pch_udc_set_dma(dev, DMA_DIR_RX); | 2159 | pch_udc_set_dma(dev, DMA_DIR_RX); |
@@ -2635,12 +2640,13 @@ static int init_dma_pools(struct pch_udc_dev *dev) | |||
2635 | return 0; | 2640 | return 0; |
2636 | } | 2641 | } |
2637 | 2642 | ||
2638 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | 2643 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, |
2644 | int (*bind)(struct usb_gadget *)) | ||
2639 | { | 2645 | { |
2640 | struct pch_udc_dev *dev = pch_udc; | 2646 | struct pch_udc_dev *dev = pch_udc; |
2641 | int retval; | 2647 | int retval; |
2642 | 2648 | ||
2643 | if (!driver || (driver->speed == USB_SPEED_UNKNOWN) || !driver->bind || | 2649 | if (!driver || (driver->speed == USB_SPEED_UNKNOWN) || !bind || |
2644 | !driver->setup || !driver->unbind || !driver->disconnect) { | 2650 | !driver->setup || !driver->unbind || !driver->disconnect) { |
2645 | dev_err(&dev->pdev->dev, | 2651 | dev_err(&dev->pdev->dev, |
2646 | "%s: invalid driver parameter\n", __func__); | 2652 | "%s: invalid driver parameter\n", __func__); |
@@ -2659,7 +2665,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
2659 | dev->gadget.dev.driver = &driver->driver; | 2665 | dev->gadget.dev.driver = &driver->driver; |
2660 | 2666 | ||
2661 | /* Invoke the bind routine of the gadget driver */ | 2667 | /* Invoke the bind routine of the gadget driver */ |
2662 | retval = driver->bind(&dev->gadget); | 2668 | retval = bind(&dev->gadget); |
2663 | 2669 | ||
2664 | if (retval) { | 2670 | if (retval) { |
2665 | dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n", | 2671 | dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n", |
@@ -2677,7 +2683,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
2677 | dev->connected = 1; | 2683 | dev->connected = 1; |
2678 | return 0; | 2684 | return 0; |
2679 | } | 2685 | } |
2680 | EXPORT_SYMBOL(usb_gadget_register_driver); | 2686 | EXPORT_SYMBOL(usb_gadget_probe_driver); |
2681 | 2687 | ||
2682 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2688 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) |
2683 | { | 2689 | { |
@@ -2902,7 +2908,7 @@ finished: | |||
2902 | return retval; | 2908 | return retval; |
2903 | } | 2909 | } |
2904 | 2910 | ||
2905 | static const struct pci_device_id pch_udc_pcidev_id[] = { | 2911 | static DEFINE_PCI_DEVICE_TABLE(pch_udc_pcidev_id) = { |
2906 | { | 2912 | { |
2907 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC), | 2913 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC), |
2908 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, | 2914 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index cb23355f52d3..a7826a6dcd8c 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -240,6 +240,9 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags) | |||
240 | size += out->maxpacket - 1; | 240 | size += out->maxpacket - 1; |
241 | size -= size % out->maxpacket; | 241 | size -= size % out->maxpacket; |
242 | 242 | ||
243 | if (dev->port_usb->is_fixed) | ||
244 | size = max(size, dev->port_usb->fixed_out_len); | ||
245 | |||
243 | skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); | 246 | skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); |
244 | if (skb == NULL) { | 247 | if (skb == NULL) { |
245 | DBG(dev, "no rx skb\n"); | 248 | DBG(dev, "no rx skb\n"); |
@@ -578,12 +581,19 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, | |||
578 | req->context = skb; | 581 | req->context = skb; |
579 | req->complete = tx_complete; | 582 | req->complete = tx_complete; |
580 | 583 | ||
584 | /* NCM requires no zlp if transfer is dwNtbInMaxSize */ | ||
585 | if (dev->port_usb->is_fixed && | ||
586 | length == dev->port_usb->fixed_in_len && | ||
587 | (length % in->maxpacket) == 0) | ||
588 | req->zero = 0; | ||
589 | else | ||
590 | req->zero = 1; | ||
591 | |||
581 | /* use zlp framing on tx for strict CDC-Ether conformance, | 592 | /* use zlp framing on tx for strict CDC-Ether conformance, |
582 | * though any robust network rx path ignores extra padding. | 593 | * though any robust network rx path ignores extra padding. |
583 | * and some hardware doesn't like to write zlps. | 594 | * and some hardware doesn't like to write zlps. |
584 | */ | 595 | */ |
585 | req->zero = 1; | 596 | if (req->zero && !dev->zlp && (length % in->maxpacket) == 0) |
586 | if (!dev->zlp && (length % in->maxpacket) == 0) | ||
587 | length++; | 597 | length++; |
588 | 598 | ||
589 | req->length = length; | 599 | req->length = length; |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 3c8c0c9f9d72..b56e1e7d423c 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -62,6 +62,10 @@ struct gether { | |||
62 | 62 | ||
63 | /* hooks for added framing, as needed for RNDIS and EEM. */ | 63 | /* hooks for added framing, as needed for RNDIS and EEM. */ |
64 | u32 header_len; | 64 | u32 header_len; |
65 | /* NCM requires fixed size bundles */ | ||
66 | bool is_fixed; | ||
67 | u32 fixed_out_len; | ||
68 | u32 fixed_in_len; | ||
65 | struct sk_buff *(*wrap)(struct gether *port, | 69 | struct sk_buff *(*wrap)(struct gether *port, |
66 | struct sk_buff *skb); | 70 | struct sk_buff *skb); |
67 | int (*unwrap)(struct gether *port, | 71 | int (*unwrap)(struct gether *port, |
@@ -103,6 +107,7 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) | |||
103 | /* each configuration may bind one instance of an ethernet link */ | 107 | /* each configuration may bind one instance of an ethernet link */ |
104 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 108 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
105 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 109 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
110 | int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | ||
106 | int eem_bind_config(struct usb_configuration *c); | 111 | int eem_bind_config(struct usb_configuration *c); |
107 | 112 | ||
108 | #ifdef USB_ETH_RNDIS | 113 | #ifdef USB_ETH_RNDIS |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 6a7c688b4781..b9cc31172fbd 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -141,6 +141,17 @@ config USB_EHCI_HCD_OMAP | |||
141 | Enables support for the on-chip EHCI controller on | 141 | Enables support for the on-chip EHCI controller on |
142 | OMAP3 and later chips. | 142 | OMAP3 and later chips. |
143 | 143 | ||
144 | config USB_EHCI_MSM | ||
145 | bool "Support for MSM on-chip EHCI USB controller" | ||
146 | depends on USB_EHCI_HCD && ARCH_MSM | ||
147 | select USB_EHCI_ROOT_HUB_TT | ||
148 | select USB_MSM_OTG_72K | ||
149 | ---help--- | ||
150 | Enables support for the USB Host controller present on the | ||
151 | Qualcomm chipsets. Root Hub has inbuilt TT. | ||
152 | This driver depends on OTG driver for PHY initialization, | ||
153 | clock management, powering up VBUS, and power management. | ||
154 | |||
144 | config USB_EHCI_HCD_PPC_OF | 155 | config USB_EHCI_HCD_PPC_OF |
145 | bool "EHCI support for PPC USB controller on OF platform bus" | 156 | bool "EHCI support for PPC USB controller on OF platform bus" |
146 | depends on USB_EHCI_HCD && PPC_OF | 157 | depends on USB_EHCI_HCD && PPC_OF |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index abe8336ebffa..48021d26024c 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -114,6 +114,9 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n"); | |||
114 | 114 | ||
115 | #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) | 115 | #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) |
116 | 116 | ||
117 | /* for ASPM quirk of ISOC on AMD SB800 */ | ||
118 | static struct pci_dev *amd_nb_dev; | ||
119 | |||
117 | /*-------------------------------------------------------------------------*/ | 120 | /*-------------------------------------------------------------------------*/ |
118 | 121 | ||
119 | #include "ehci.h" | 122 | #include "ehci.h" |
@@ -529,6 +532,11 @@ static void ehci_stop (struct usb_hcd *hcd) | |||
529 | spin_unlock_irq (&ehci->lock); | 532 | spin_unlock_irq (&ehci->lock); |
530 | ehci_mem_cleanup (ehci); | 533 | ehci_mem_cleanup (ehci); |
531 | 534 | ||
535 | if (amd_nb_dev) { | ||
536 | pci_dev_put(amd_nb_dev); | ||
537 | amd_nb_dev = NULL; | ||
538 | } | ||
539 | |||
532 | #ifdef EHCI_STATS | 540 | #ifdef EHCI_STATS |
533 | ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", | 541 | ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", |
534 | ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, | 542 | ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, |
@@ -1231,6 +1239,11 @@ MODULE_LICENSE ("GPL"); | |||
1231 | #define PLATFORM_DRIVER spear_ehci_hcd_driver | 1239 | #define PLATFORM_DRIVER spear_ehci_hcd_driver |
1232 | #endif | 1240 | #endif |
1233 | 1241 | ||
1242 | #ifdef CONFIG_USB_EHCI_MSM | ||
1243 | #include "ehci-msm.c" | ||
1244 | #define PLATFORM_DRIVER ehci_msm_driver | ||
1245 | #endif | ||
1246 | |||
1234 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ | 1247 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
1235 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ | 1248 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ |
1236 | !defined(XILINX_OF_PLATFORM_DRIVER) | 1249 | !defined(XILINX_OF_PLATFORM_DRIVER) |
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c new file mode 100644 index 000000000000..413f4deca532 --- /dev/null +++ b/drivers/usb/host/ehci-msm.c | |||
@@ -0,0 +1,345 @@ | |||
1 | /* ehci-msm.c - HSUSB Host Controller Driver Implementation | ||
2 | * | ||
3 | * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved. | ||
4 | * | ||
5 | * Partly derived from ehci-fsl.c and ehci-hcd.c | ||
6 | * Copyright (c) 2000-2004 by David Brownell | ||
7 | * Copyright (c) 2005 MontaVista Software | ||
8 | * | ||
9 | * All source code in this file is licensed under the following license except | ||
10 | * where indicated. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License version 2 as published | ||
14 | * 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. | ||
19 | * | ||
20 | * See the GNU General Public License for more details. | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, you can find it at http://www.fsf.org | ||
23 | */ | ||
24 | |||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/clk.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/pm_runtime.h> | ||
29 | |||
30 | #include <linux/usb/otg.h> | ||
31 | #include <linux/usb/msm_hsusb_hw.h> | ||
32 | |||
33 | #define MSM_USB_BASE (hcd->regs) | ||
34 | |||
35 | static struct otg_transceiver *otg; | ||
36 | |||
37 | /* | ||
38 | * ehci_run defined in drivers/usb/host/ehci-hcd.c reset the controller and | ||
39 | * the configuration settings in ehci_msm_reset vanish after controller is | ||
40 | * reset. Resetting the controler in ehci_run seems to be un-necessary | ||
41 | * provided HCD reset the controller before calling ehci_run. Most of the HCD | ||
42 | * do but some are not. So this function is same as ehci_run but we don't | ||
43 | * reset the controller here. | ||
44 | */ | ||
45 | static int ehci_msm_run(struct usb_hcd *hcd) | ||
46 | { | ||
47 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
48 | u32 temp; | ||
49 | u32 hcc_params; | ||
50 | |||
51 | hcd->uses_new_polling = 1; | ||
52 | |||
53 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); | ||
54 | ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); | ||
55 | |||
56 | /* | ||
57 | * hcc_params controls whether ehci->regs->segment must (!!!) | ||
58 | * be used; it constrains QH/ITD/SITD and QTD locations. | ||
59 | * pci_pool consistent memory always uses segment zero. | ||
60 | * streaming mappings for I/O buffers, like pci_map_single(), | ||
61 | * can return segments above 4GB, if the device allows. | ||
62 | * | ||
63 | * NOTE: the dma mask is visible through dma_supported(), so | ||
64 | * drivers can pass this info along ... like NETIF_F_HIGHDMA, | ||
65 | * Scsi_Host.highmem_io, and so forth. It's readonly to all | ||
66 | * host side drivers though. | ||
67 | */ | ||
68 | hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); | ||
69 | if (HCC_64BIT_ADDR(hcc_params)) | ||
70 | ehci_writel(ehci, 0, &ehci->regs->segment); | ||
71 | |||
72 | /* | ||
73 | * Philips, Intel, and maybe others need CMD_RUN before the | ||
74 | * root hub will detect new devices (why?); NEC doesn't | ||
75 | */ | ||
76 | ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); | ||
77 | ehci->command |= CMD_RUN; | ||
78 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | ||
79 | dbg_cmd(ehci, "init", ehci->command); | ||
80 | |||
81 | /* | ||
82 | * Start, enabling full USB 2.0 functionality ... usb 1.1 devices | ||
83 | * are explicitly handed to companion controller(s), so no TT is | ||
84 | * involved with the root hub. (Except where one is integrated, | ||
85 | * and there's no companion controller unless maybe for USB OTG.) | ||
86 | * | ||
87 | * Turning on the CF flag will transfer ownership of all ports | ||
88 | * from the companions to the EHCI controller. If any of the | ||
89 | * companions are in the middle of a port reset at the time, it | ||
90 | * could cause trouble. Write-locking ehci_cf_port_reset_rwsem | ||
91 | * guarantees that no resets are in progress. After we set CF, | ||
92 | * a short delay lets the hardware catch up; new resets shouldn't | ||
93 | * be started before the port switching actions could complete. | ||
94 | */ | ||
95 | down_write(&ehci_cf_port_reset_rwsem); | ||
96 | hcd->state = HC_STATE_RUNNING; | ||
97 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | ||
98 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ | ||
99 | usleep_range(5000, 5500); | ||
100 | up_write(&ehci_cf_port_reset_rwsem); | ||
101 | ehci->last_periodic_enable = ktime_get_real(); | ||
102 | |||
103 | temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
104 | ehci_info(ehci, | ||
105 | "USB %x.%x started, EHCI %x.%02x%s\n", | ||
106 | ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), | ||
107 | temp >> 8, temp & 0xff, | ||
108 | ignore_oc ? ", overcurrent ignored" : ""); | ||
109 | |||
110 | ehci_writel(ehci, INTR_MASK, | ||
111 | &ehci->regs->intr_enable); /* Turn On Interrupts */ | ||
112 | |||
113 | /* GRR this is run-once init(), being done every time the HC starts. | ||
114 | * So long as they're part of class devices, we can't do it init() | ||
115 | * since the class device isn't created that early. | ||
116 | */ | ||
117 | create_debug_files(ehci); | ||
118 | create_companion_file(ehci); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | static int ehci_msm_reset(struct usb_hcd *hcd) | ||
124 | { | ||
125 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
126 | int retval; | ||
127 | |||
128 | ehci->caps = USB_CAPLENGTH; | ||
129 | ehci->regs = USB_CAPLENGTH + | ||
130 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
131 | |||
132 | /* cache the data to minimize the chip reads*/ | ||
133 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
134 | |||
135 | hcd->has_tt = 1; | ||
136 | ehci->sbrn = HCD_USB2; | ||
137 | |||
138 | /* data structure init */ | ||
139 | retval = ehci_init(hcd); | ||
140 | if (retval) | ||
141 | return retval; | ||
142 | |||
143 | retval = ehci_reset(ehci); | ||
144 | if (retval) | ||
145 | return retval; | ||
146 | |||
147 | /* bursts of unspecified length. */ | ||
148 | writel(0, USB_AHBBURST); | ||
149 | /* Use the AHB transactor */ | ||
150 | writel(0, USB_AHBMODE); | ||
151 | /* Disable streaming mode and select host mode */ | ||
152 | writel(0x13, USB_USBMODE); | ||
153 | |||
154 | ehci_port_power(ehci, 1); | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static struct hc_driver msm_hc_driver = { | ||
159 | .description = hcd_name, | ||
160 | .product_desc = "Qualcomm On-Chip EHCI Host Controller", | ||
161 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
162 | |||
163 | /* | ||
164 | * generic hardware linkage | ||
165 | */ | ||
166 | .irq = ehci_irq, | ||
167 | .flags = HCD_USB2 | HCD_MEMORY, | ||
168 | |||
169 | .reset = ehci_msm_reset, | ||
170 | .start = ehci_msm_run, | ||
171 | |||
172 | .stop = ehci_stop, | ||
173 | .shutdown = ehci_shutdown, | ||
174 | |||
175 | /* | ||
176 | * managing i/o requests and associated device resources | ||
177 | */ | ||
178 | .urb_enqueue = ehci_urb_enqueue, | ||
179 | .urb_dequeue = ehci_urb_dequeue, | ||
180 | .endpoint_disable = ehci_endpoint_disable, | ||
181 | .endpoint_reset = ehci_endpoint_reset, | ||
182 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
183 | |||
184 | /* | ||
185 | * scheduling support | ||
186 | */ | ||
187 | .get_frame_number = ehci_get_frame, | ||
188 | |||
189 | /* | ||
190 | * root hub support | ||
191 | */ | ||
192 | .hub_status_data = ehci_hub_status_data, | ||
193 | .hub_control = ehci_hub_control, | ||
194 | .relinquish_port = ehci_relinquish_port, | ||
195 | .port_handed_over = ehci_port_handed_over, | ||
196 | |||
197 | /* | ||
198 | * PM support | ||
199 | */ | ||
200 | .bus_suspend = ehci_bus_suspend, | ||
201 | .bus_resume = ehci_bus_resume, | ||
202 | }; | ||
203 | |||
204 | static int ehci_msm_probe(struct platform_device *pdev) | ||
205 | { | ||
206 | struct usb_hcd *hcd; | ||
207 | struct resource *res; | ||
208 | int ret; | ||
209 | |||
210 | dev_dbg(&pdev->dev, "ehci_msm proble\n"); | ||
211 | |||
212 | hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev)); | ||
213 | if (!hcd) { | ||
214 | dev_err(&pdev->dev, "Unable to create HCD\n"); | ||
215 | return -ENOMEM; | ||
216 | } | ||
217 | |||
218 | hcd->irq = platform_get_irq(pdev, 0); | ||
219 | if (hcd->irq < 0) { | ||
220 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); | ||
221 | ret = hcd->irq; | ||
222 | goto put_hcd; | ||
223 | } | ||
224 | |||
225 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
226 | if (!res) { | ||
227 | dev_err(&pdev->dev, "Unable to get memory resource\n"); | ||
228 | ret = -ENODEV; | ||
229 | goto put_hcd; | ||
230 | } | ||
231 | |||
232 | hcd->rsrc_start = res->start; | ||
233 | hcd->rsrc_len = resource_size(res); | ||
234 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
235 | if (!hcd->regs) { | ||
236 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
237 | ret = -ENOMEM; | ||
238 | goto put_hcd; | ||
239 | } | ||
240 | |||
241 | /* | ||
242 | * OTG driver takes care of PHY initialization, clock management, | ||
243 | * powering up VBUS, mapping of registers address space and power | ||
244 | * management. | ||
245 | */ | ||
246 | otg = otg_get_transceiver(); | ||
247 | if (!otg) { | ||
248 | dev_err(&pdev->dev, "unable to find transceiver\n"); | ||
249 | ret = -ENODEV; | ||
250 | goto unmap; | ||
251 | } | ||
252 | |||
253 | ret = otg_set_host(otg, &hcd->self); | ||
254 | if (ret < 0) { | ||
255 | dev_err(&pdev->dev, "unable to register with transceiver\n"); | ||
256 | goto put_transceiver; | ||
257 | } | ||
258 | |||
259 | device_init_wakeup(&pdev->dev, 1); | ||
260 | /* | ||
261 | * OTG device parent of HCD takes care of putting | ||
262 | * hardware into low power mode. | ||
263 | */ | ||
264 | pm_runtime_no_callbacks(&pdev->dev); | ||
265 | pm_runtime_enable(&pdev->dev); | ||
266 | |||
267 | return 0; | ||
268 | |||
269 | put_transceiver: | ||
270 | otg_put_transceiver(otg); | ||
271 | unmap: | ||
272 | iounmap(hcd->regs); | ||
273 | put_hcd: | ||
274 | usb_put_hcd(hcd); | ||
275 | |||
276 | return ret; | ||
277 | } | ||
278 | |||
279 | static int __devexit ehci_msm_remove(struct platform_device *pdev) | ||
280 | { | ||
281 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
282 | |||
283 | device_init_wakeup(&pdev->dev, 0); | ||
284 | pm_runtime_disable(&pdev->dev); | ||
285 | pm_runtime_set_suspended(&pdev->dev); | ||
286 | |||
287 | otg_set_host(otg, NULL); | ||
288 | otg_put_transceiver(otg); | ||
289 | |||
290 | usb_put_hcd(hcd); | ||
291 | |||
292 | return 0; | ||
293 | } | ||
294 | |||
295 | #ifdef CONFIG_PM | ||
296 | static int ehci_msm_pm_suspend(struct device *dev) | ||
297 | { | ||
298 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
299 | bool wakeup = device_may_wakeup(dev); | ||
300 | |||
301 | dev_dbg(dev, "ehci-msm PM suspend\n"); | ||
302 | |||
303 | /* | ||
304 | * EHCI helper function has also the same check before manipulating | ||
305 | * port wakeup flags. We do check here the same condition before | ||
306 | * calling the same helper function to avoid bringing hardware | ||
307 | * from Low power mode when there is no need for adjusting port | ||
308 | * wakeup flags. | ||
309 | */ | ||
310 | if (hcd->self.root_hub->do_remote_wakeup && !wakeup) { | ||
311 | pm_runtime_resume(dev); | ||
312 | ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), | ||
313 | wakeup); | ||
314 | } | ||
315 | |||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | static int ehci_msm_pm_resume(struct device *dev) | ||
320 | { | ||
321 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
322 | |||
323 | dev_dbg(dev, "ehci-msm PM resume\n"); | ||
324 | ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); | ||
325 | |||
326 | return 0; | ||
327 | } | ||
328 | #else | ||
329 | #define ehci_msm_pm_suspend NULL | ||
330 | #define ehci_msm_pm_resume NULL | ||
331 | #endif | ||
332 | |||
333 | static const struct dev_pm_ops ehci_msm_dev_pm_ops = { | ||
334 | .suspend = ehci_msm_pm_suspend, | ||
335 | .resume = ehci_msm_pm_resume, | ||
336 | }; | ||
337 | |||
338 | static struct platform_driver ehci_msm_driver = { | ||
339 | .probe = ehci_msm_probe, | ||
340 | .remove = __devexit_p(ehci_msm_remove), | ||
341 | .driver = { | ||
342 | .name = "msm_hsusb_host", | ||
343 | .pm = &ehci_msm_dev_pm_ops, | ||
344 | }, | ||
345 | }; | ||
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 56c78e93440f..35a533e4c01d 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -44,6 +44,35 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) | |||
44 | return 0; | 44 | return 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | static int ehci_quirk_amd_SB800(struct ehci_hcd *ehci) | ||
48 | { | ||
49 | struct pci_dev *amd_smbus_dev; | ||
50 | u8 rev = 0; | ||
51 | |||
52 | amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); | ||
53 | if (!amd_smbus_dev) | ||
54 | return 0; | ||
55 | |||
56 | pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev); | ||
57 | if (rev < 0x40) { | ||
58 | pci_dev_put(amd_smbus_dev); | ||
59 | amd_smbus_dev = NULL; | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | if (!amd_nb_dev) | ||
64 | amd_nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL); | ||
65 | if (!amd_nb_dev) | ||
66 | ehci_err(ehci, "QUIRK: unable to get AMD NB device\n"); | ||
67 | |||
68 | ehci_info(ehci, "QUIRK: Enable AMD SB800 L1 fix\n"); | ||
69 | |||
70 | pci_dev_put(amd_smbus_dev); | ||
71 | amd_smbus_dev = NULL; | ||
72 | |||
73 | return 1; | ||
74 | } | ||
75 | |||
47 | /* called during probe() after chip reset completes */ | 76 | /* called during probe() after chip reset completes */ |
48 | static int ehci_pci_setup(struct usb_hcd *hcd) | 77 | static int ehci_pci_setup(struct usb_hcd *hcd) |
49 | { | 78 | { |
@@ -102,6 +131,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
102 | /* cache this readonly data; minimize chip reads */ | 131 | /* cache this readonly data; minimize chip reads */ |
103 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | 132 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
104 | 133 | ||
134 | if (ehci_quirk_amd_SB800(ehci)) | ||
135 | ehci->amd_l1_fix = 1; | ||
136 | |||
105 | retval = ehci_halt(ehci); | 137 | retval = ehci_halt(ehci); |
106 | if (retval) | 138 | if (retval) |
107 | return retval; | 139 | return retval; |
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index a92526d6e5ae..724ba7133c4f 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -1583,6 +1583,63 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd) | |||
1583 | *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); | 1583 | *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); |
1584 | } | 1584 | } |
1585 | 1585 | ||
1586 | #define AB_REG_BAR_LOW 0xe0 | ||
1587 | #define AB_REG_BAR_HIGH 0xe1 | ||
1588 | #define AB_INDX(addr) ((addr) + 0x00) | ||
1589 | #define AB_DATA(addr) ((addr) + 0x04) | ||
1590 | #define NB_PCIE_INDX_ADDR 0xe0 | ||
1591 | #define NB_PCIE_INDX_DATA 0xe4 | ||
1592 | #define NB_PIF0_PWRDOWN_0 0x01100012 | ||
1593 | #define NB_PIF0_PWRDOWN_1 0x01100013 | ||
1594 | |||
1595 | static void ehci_quirk_amd_L1(struct ehci_hcd *ehci, int disable) | ||
1596 | { | ||
1597 | u32 addr, addr_low, addr_high, val; | ||
1598 | |||
1599 | outb_p(AB_REG_BAR_LOW, 0xcd6); | ||
1600 | addr_low = inb_p(0xcd7); | ||
1601 | outb_p(AB_REG_BAR_HIGH, 0xcd6); | ||
1602 | addr_high = inb_p(0xcd7); | ||
1603 | addr = addr_high << 8 | addr_low; | ||
1604 | outl_p(0x30, AB_INDX(addr)); | ||
1605 | outl_p(0x40, AB_DATA(addr)); | ||
1606 | outl_p(0x34, AB_INDX(addr)); | ||
1607 | val = inl_p(AB_DATA(addr)); | ||
1608 | |||
1609 | if (disable) { | ||
1610 | val &= ~0x8; | ||
1611 | val |= (1 << 4) | (1 << 9); | ||
1612 | } else { | ||
1613 | val |= 0x8; | ||
1614 | val &= ~((1 << 4) | (1 << 9)); | ||
1615 | } | ||
1616 | outl_p(val, AB_DATA(addr)); | ||
1617 | |||
1618 | if (amd_nb_dev) { | ||
1619 | addr = NB_PIF0_PWRDOWN_0; | ||
1620 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_ADDR, addr); | ||
1621 | pci_read_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, &val); | ||
1622 | if (disable) | ||
1623 | val &= ~(0x3f << 7); | ||
1624 | else | ||
1625 | val |= 0x3f << 7; | ||
1626 | |||
1627 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, val); | ||
1628 | |||
1629 | addr = NB_PIF0_PWRDOWN_1; | ||
1630 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_ADDR, addr); | ||
1631 | pci_read_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, &val); | ||
1632 | if (disable) | ||
1633 | val &= ~(0x3f << 7); | ||
1634 | else | ||
1635 | val |= 0x3f << 7; | ||
1636 | |||
1637 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, val); | ||
1638 | } | ||
1639 | |||
1640 | return; | ||
1641 | } | ||
1642 | |||
1586 | /* fit urb's itds into the selected schedule slot; activate as needed */ | 1643 | /* fit urb's itds into the selected schedule slot; activate as needed */ |
1587 | static int | 1644 | static int |
1588 | itd_link_urb ( | 1645 | itd_link_urb ( |
@@ -1609,6 +1666,12 @@ itd_link_urb ( | |||
1609 | urb->interval, | 1666 | urb->interval, |
1610 | next_uframe >> 3, next_uframe & 0x7); | 1667 | next_uframe >> 3, next_uframe & 0x7); |
1611 | } | 1668 | } |
1669 | |||
1670 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | ||
1671 | if (ehci->amd_l1_fix == 1) | ||
1672 | ehci_quirk_amd_L1(ehci, 1); | ||
1673 | } | ||
1674 | |||
1612 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 1675 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
1613 | 1676 | ||
1614 | /* fill iTDs uframe by uframe */ | 1677 | /* fill iTDs uframe by uframe */ |
@@ -1733,6 +1796,11 @@ itd_complete ( | |||
1733 | (void) disable_periodic(ehci); | 1796 | (void) disable_periodic(ehci); |
1734 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; | 1797 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; |
1735 | 1798 | ||
1799 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | ||
1800 | if (ehci->amd_l1_fix == 1) | ||
1801 | ehci_quirk_amd_L1(ehci, 0); | ||
1802 | } | ||
1803 | |||
1736 | if (unlikely(list_is_singular(&stream->td_list))) { | 1804 | if (unlikely(list_is_singular(&stream->td_list))) { |
1737 | ehci_to_hcd(ehci)->self.bandwidth_allocated | 1805 | ehci_to_hcd(ehci)->self.bandwidth_allocated |
1738 | -= stream->bandwidth; | 1806 | -= stream->bandwidth; |
@@ -2018,6 +2086,12 @@ sitd_link_urb ( | |||
2018 | (next_uframe >> 3) & (ehci->periodic_size - 1), | 2086 | (next_uframe >> 3) & (ehci->periodic_size - 1), |
2019 | stream->interval, hc32_to_cpu(ehci, stream->splits)); | 2087 | stream->interval, hc32_to_cpu(ehci, stream->splits)); |
2020 | } | 2088 | } |
2089 | |||
2090 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | ||
2091 | if (ehci->amd_l1_fix == 1) | ||
2092 | ehci_quirk_amd_L1(ehci, 1); | ||
2093 | } | ||
2094 | |||
2021 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 2095 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
2022 | 2096 | ||
2023 | /* fill sITDs frame by frame */ | 2097 | /* fill sITDs frame by frame */ |
@@ -2118,6 +2192,11 @@ sitd_complete ( | |||
2118 | (void) disable_periodic(ehci); | 2192 | (void) disable_periodic(ehci); |
2119 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; | 2193 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; |
2120 | 2194 | ||
2195 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | ||
2196 | if (ehci->amd_l1_fix == 1) | ||
2197 | ehci_quirk_amd_L1(ehci, 0); | ||
2198 | } | ||
2199 | |||
2121 | if (list_is_singular(&stream->td_list)) { | 2200 | if (list_is_singular(&stream->td_list)) { |
2122 | ehci_to_hcd(ehci)->self.bandwidth_allocated | 2201 | ehci_to_hcd(ehci)->self.bandwidth_allocated |
2123 | -= stream->bandwidth; | 2202 | -= stream->bandwidth; |
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index bde823f704e9..fd1c53da89e4 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -130,6 +130,7 @@ struct ehci_hcd { /* one per controller */ | |||
130 | unsigned has_amcc_usb23:1; | 130 | unsigned has_amcc_usb23:1; |
131 | unsigned need_io_watchdog:1; | 131 | unsigned need_io_watchdog:1; |
132 | unsigned broken_periodic:1; | 132 | unsigned broken_periodic:1; |
133 | unsigned amd_l1_fix:1; | ||
133 | unsigned fs_i_thresh:1; /* Intel iso scheduling */ | 134 | unsigned fs_i_thresh:1; /* Intel iso scheduling */ |
134 | 135 | ||
135 | /* required for usb32 quirk */ | 136 | /* required for usb32 quirk */ |
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index 2090b45eb606..af77abb5c68b 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
@@ -29,7 +29,7 @@ static void uhci_set_next_interrupt(struct uhci_hcd *uhci) | |||
29 | { | 29 | { |
30 | if (uhci->is_stopped) | 30 | if (uhci->is_stopped) |
31 | mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); | 31 | mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); |
32 | uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); | 32 | uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); |
33 | } | 33 | } |
34 | 34 | ||
35 | static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) | 35 | static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) |
@@ -195,7 +195,9 @@ static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci, | |||
195 | } else { | 195 | } else { |
196 | struct uhci_td *ntd; | 196 | struct uhci_td *ntd; |
197 | 197 | ||
198 | ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); | 198 | ntd = list_entry(td->fl_list.next, |
199 | struct uhci_td, | ||
200 | fl_list); | ||
199 | uhci->frame[td->frame] = LINK_TO_TD(ntd); | 201 | uhci->frame[td->frame] = LINK_TO_TD(ntd); |
200 | uhci->frame_cpu[td->frame] = ntd; | 202 | uhci->frame_cpu[td->frame] = ntd; |
201 | } | 203 | } |
@@ -728,7 +730,7 @@ static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, | |||
728 | 730 | ||
729 | urbp->urb = urb; | 731 | urbp->urb = urb; |
730 | urb->hcpriv = urbp; | 732 | urb->hcpriv = urbp; |
731 | 733 | ||
732 | INIT_LIST_HEAD(&urbp->node); | 734 | INIT_LIST_HEAD(&urbp->node); |
733 | INIT_LIST_HEAD(&urbp->td_list); | 735 | INIT_LIST_HEAD(&urbp->td_list); |
734 | 736 | ||
@@ -846,7 +848,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
846 | 848 | ||
847 | /* Alternate Data0/1 (start with Data1) */ | 849 | /* Alternate Data0/1 (start with Data1) */ |
848 | destination ^= TD_TOKEN_TOGGLE; | 850 | destination ^= TD_TOKEN_TOGGLE; |
849 | 851 | ||
850 | uhci_add_td_to_urbp(td, urbp); | 852 | uhci_add_td_to_urbp(td, urbp); |
851 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), | 853 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), |
852 | data); | 854 | data); |
@@ -857,7 +859,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
857 | } | 859 | } |
858 | 860 | ||
859 | /* | 861 | /* |
860 | * Build the final TD for control status | 862 | * Build the final TD for control status |
861 | */ | 863 | */ |
862 | td = uhci_alloc_td(uhci); | 864 | td = uhci_alloc_td(uhci); |
863 | if (!td) | 865 | if (!td) |
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index 72b6892fda67..9546f6cd01f0 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c | |||
@@ -356,7 +356,7 @@ static void __exit whci_hc_driver_exit(void) | |||
356 | module_exit(whci_hc_driver_exit); | 356 | module_exit(whci_hc_driver_exit); |
357 | 357 | ||
358 | /* PCI device ID's that we handle (so it gets loaded) */ | 358 | /* PCI device ID's that we handle (so it gets loaded) */ |
359 | static struct pci_device_id whci_hcd_id_table[] = { | 359 | static struct pci_device_id __used whci_hcd_id_table[] = { |
360 | { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) }, | 360 | { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) }, |
361 | { /* empty last entry */ } | 361 | { /* empty last entry */ } |
362 | }; | 362 | }; |
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig index e3ecc211fe5f..9fb875d5f09c 100644 --- a/drivers/usb/otg/Kconfig +++ b/drivers/usb/otg/Kconfig | |||
@@ -93,4 +93,24 @@ config USB_LANGWELL_OTG | |||
93 | To compile this driver as a module, choose M here: the | 93 | To compile this driver as a module, choose M here: the |
94 | module will be called langwell_otg. | 94 | module will be called langwell_otg. |
95 | 95 | ||
96 | config USB_MSM_OTG_72K | ||
97 | tristate "OTG support for Qualcomm on-chip USB controller" | ||
98 | depends on (USB || USB_GADGET) && ARCH_MSM | ||
99 | select USB_OTG_UTILS | ||
100 | help | ||
101 | Enable this to support the USB OTG transceiver on MSM chips. It | ||
102 | handles PHY initialization, clock management, and workarounds | ||
103 | required after resetting the hardware and power management. | ||
104 | This driver is required even for peripheral only or host only | ||
105 | mode configurations. | ||
106 | |||
107 | config AB8500_USB | ||
108 | tristate "AB8500 USB Transceiver Driver" | ||
109 | depends on AB8500_CORE | ||
110 | select USB_OTG_UTILS | ||
111 | help | ||
112 | Enable this to support the USB OTG transceiver in AB8500 chip. | ||
113 | This transceiver supports high and full speed devices plus, | ||
114 | in host mode, low speed. | ||
115 | |||
96 | endif # USB || OTG | 116 | endif # USB || OTG |
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile index ff01f5fe0bd5..a520e715cfd6 100644 --- a/drivers/usb/otg/Makefile +++ b/drivers/usb/otg/Makefile | |||
@@ -16,3 +16,5 @@ obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o | |||
16 | obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o | 16 | obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o |
17 | obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o | 17 | obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o |
18 | obj-$(CONFIG_USB_ULPI) += ulpi.o | 18 | obj-$(CONFIG_USB_ULPI) += ulpi.o |
19 | obj-$(CONFIG_USB_MSM_OTG_72K) += msm72k_otg.o | ||
20 | obj-$(CONFIG_AB8500_USB) += ab8500-usb.o | ||
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c new file mode 100644 index 000000000000..d14736b3107b --- /dev/null +++ b/drivers/usb/otg/ab8500-usb.c | |||
@@ -0,0 +1,585 @@ | |||
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/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 otg_transceiver otg; | ||
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 *xceiv_to_ab(struct otg_transceiver *x) | ||
86 | { | ||
87 | return container_of(x, struct ab8500_usb, otg); | ||
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_xceiv_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->otg.state = OTG_STATE_B_IDLE; | ||
173 | ab->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->otg.gadget) { | ||
185 | /* TODO: Enable regulators. */ | ||
186 | ab8500_usb_peri_phy_en(ab); | ||
187 | v = ab->otg.gadget; | ||
188 | } | ||
189 | event = USB_EVENT_VBUS; | ||
190 | break; | ||
191 | |||
192 | case USB_LINK_HM_IDGND: | ||
193 | if (ab->otg.host) { | ||
194 | /* TODO: Enable regulators. */ | ||
195 | ab8500_usb_host_phy_en(ab); | ||
196 | v = ab->otg.host; | ||
197 | } | ||
198 | ab->otg.state = OTG_STATE_A_IDLE; | ||
199 | ab->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 | blocking_notifier_call_chain(&ab->otg.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->otg.host) | ||
266 | ab8500_usb_host_phy_dis(ab); | ||
267 | |||
268 | if (!ab->otg.gadget) | ||
269 | ab8500_usb_peri_phy_dis(ab); | ||
270 | } | ||
271 | |||
272 | static int ab8500_usb_set_power(struct otg_transceiver *otg, unsigned mA) | ||
273 | { | ||
274 | struct ab8500_usb *ab; | ||
275 | |||
276 | if (!otg) | ||
277 | return -ENODEV; | ||
278 | |||
279 | ab = xceiv_to_ab(otg); | ||
280 | |||
281 | ab->vbus_draw = mA; | ||
282 | |||
283 | if (mA) | ||
284 | blocking_notifier_call_chain(&ab->otg.notifier, | ||
285 | USB_EVENT_ENUMERATED, ab->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 otg_transceiver *x, int suspend) | ||
294 | { | ||
295 | /* TODO */ | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static int ab8500_usb_set_peripheral(struct otg_transceiver *otg, | ||
300 | struct usb_gadget *gadget) | ||
301 | { | ||
302 | struct ab8500_usb *ab; | ||
303 | |||
304 | if (!otg) | ||
305 | return -ENODEV; | ||
306 | |||
307 | ab = xceiv_to_ab(otg); | ||
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 | ab->otg.gadget = NULL; | ||
317 | schedule_work(&ab->phy_dis_work); | ||
318 | } else { | ||
319 | ab->otg.gadget = gadget; | ||
320 | ab->otg.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 otg_transceiver *otg, | ||
333 | struct usb_bus *host) | ||
334 | { | ||
335 | struct ab8500_usb *ab; | ||
336 | |||
337 | if (!otg) | ||
338 | return -ENODEV; | ||
339 | |||
340 | ab = xceiv_to_ab(otg); | ||
341 | |||
342 | /* Some drivers call this function in atomic context. | ||
343 | * Do not update ab8500 registers directly till this | ||
344 | * is fixed. | ||
345 | */ | ||
346 | |||
347 | if (!host) { | ||
348 | /* TODO: Disable regulators. */ | ||
349 | ab->otg.host = NULL; | ||
350 | schedule_work(&ab->phy_dis_work); | ||
351 | } else { | ||
352 | ab->otg.host = host; | ||
353 | /* Phy will not be enabled if cable is already | ||
354 | * plugged-in. Schedule to enable phy. | ||
355 | * Use same delay to avoid any race condition. | ||
356 | */ | ||
357 | schedule_delayed_work(&ab->dwork, ab->link_status_wait); | ||
358 | } | ||
359 | |||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | static void ab8500_usb_irq_free(struct ab8500_usb *ab) | ||
364 | { | ||
365 | if (ab->rev < 0x20) { | ||
366 | free_irq(ab->irq_num_id_rise, ab); | ||
367 | free_irq(ab->irq_num_id_fall, ab); | ||
368 | free_irq(ab->irq_num_vbus_rise, ab); | ||
369 | free_irq(ab->irq_num_vbus_fall, ab); | ||
370 | } else { | ||
371 | free_irq(ab->irq_num_link_status, ab); | ||
372 | } | ||
373 | } | ||
374 | |||
375 | static int ab8500_usb_v1x_res_setup(struct platform_device *pdev, | ||
376 | struct ab8500_usb *ab) | ||
377 | { | ||
378 | int err; | ||
379 | |||
380 | ab->irq_num_id_rise = platform_get_irq_byname(pdev, "ID_WAKEUP_R"); | ||
381 | if (ab->irq_num_id_rise < 0) { | ||
382 | dev_err(&pdev->dev, "ID rise irq not found\n"); | ||
383 | return ab->irq_num_id_rise; | ||
384 | } | ||
385 | err = request_threaded_irq(ab->irq_num_id_rise, NULL, | ||
386 | ab8500_usb_v1x_common_irq, | ||
387 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
388 | "usb-id-rise", ab); | ||
389 | if (err < 0) { | ||
390 | dev_err(ab->dev, "request_irq failed for ID rise irq\n"); | ||
391 | goto fail0; | ||
392 | } | ||
393 | |||
394 | ab->irq_num_id_fall = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); | ||
395 | if (ab->irq_num_id_fall < 0) { | ||
396 | dev_err(&pdev->dev, "ID fall irq not found\n"); | ||
397 | return ab->irq_num_id_fall; | ||
398 | } | ||
399 | err = request_threaded_irq(ab->irq_num_id_fall, NULL, | ||
400 | ab8500_usb_v1x_common_irq, | ||
401 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
402 | "usb-id-fall", ab); | ||
403 | if (err < 0) { | ||
404 | dev_err(ab->dev, "request_irq failed for ID fall irq\n"); | ||
405 | goto fail1; | ||
406 | } | ||
407 | |||
408 | ab->irq_num_vbus_rise = platform_get_irq_byname(pdev, "VBUS_DET_R"); | ||
409 | if (ab->irq_num_vbus_rise < 0) { | ||
410 | dev_err(&pdev->dev, "VBUS rise irq not found\n"); | ||
411 | return ab->irq_num_vbus_rise; | ||
412 | } | ||
413 | err = request_threaded_irq(ab->irq_num_vbus_rise, NULL, | ||
414 | ab8500_usb_v1x_common_irq, | ||
415 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
416 | "usb-vbus-rise", ab); | ||
417 | if (err < 0) { | ||
418 | dev_err(ab->dev, "request_irq failed for Vbus rise irq\n"); | ||
419 | goto fail2; | ||
420 | } | ||
421 | |||
422 | ab->irq_num_vbus_fall = platform_get_irq_byname(pdev, "VBUS_DET_F"); | ||
423 | if (ab->irq_num_vbus_fall < 0) { | ||
424 | dev_err(&pdev->dev, "VBUS fall irq not found\n"); | ||
425 | return ab->irq_num_vbus_fall; | ||
426 | } | ||
427 | err = request_threaded_irq(ab->irq_num_vbus_fall, NULL, | ||
428 | ab8500_usb_v1x_vbus_fall_irq, | ||
429 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
430 | "usb-vbus-fall", ab); | ||
431 | if (err < 0) { | ||
432 | dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); | ||
433 | goto fail3; | ||
434 | } | ||
435 | |||
436 | return 0; | ||
437 | fail3: | ||
438 | free_irq(ab->irq_num_vbus_rise, ab); | ||
439 | fail2: | ||
440 | free_irq(ab->irq_num_id_fall, ab); | ||
441 | fail1: | ||
442 | free_irq(ab->irq_num_id_rise, ab); | ||
443 | fail0: | ||
444 | return err; | ||
445 | } | ||
446 | |||
447 | static int ab8500_usb_v2_res_setup(struct platform_device *pdev, | ||
448 | struct ab8500_usb *ab) | ||
449 | { | ||
450 | int err; | ||
451 | |||
452 | ab->irq_num_link_status = platform_get_irq_byname(pdev, | ||
453 | "USB_LINK_STATUS"); | ||
454 | if (ab->irq_num_link_status < 0) { | ||
455 | dev_err(&pdev->dev, "Link status irq not found\n"); | ||
456 | return ab->irq_num_link_status; | ||
457 | } | ||
458 | |||
459 | err = request_threaded_irq(ab->irq_num_link_status, NULL, | ||
460 | ab8500_usb_v20_irq, | ||
461 | IRQF_NO_SUSPEND | IRQF_SHARED, | ||
462 | "usb-link-status", ab); | ||
463 | if (err < 0) { | ||
464 | dev_err(ab->dev, | ||
465 | "request_irq failed for link status irq\n"); | ||
466 | return err; | ||
467 | } | ||
468 | |||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static int __devinit ab8500_usb_probe(struct platform_device *pdev) | ||
473 | { | ||
474 | struct ab8500_usb *ab; | ||
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 | ab->dev = &pdev->dev; | ||
492 | ab->rev = rev; | ||
493 | ab->otg.dev = ab->dev; | ||
494 | ab->otg.label = "ab8500"; | ||
495 | ab->otg.state = OTG_STATE_UNDEFINED; | ||
496 | ab->otg.set_host = ab8500_usb_set_host; | ||
497 | ab->otg.set_peripheral = ab8500_usb_set_peripheral; | ||
498 | ab->otg.set_suspend = ab8500_usb_set_suspend; | ||
499 | ab->otg.set_power = ab8500_usb_set_power; | ||
500 | |||
501 | platform_set_drvdata(pdev, ab); | ||
502 | |||
503 | BLOCKING_INIT_NOTIFIER_HEAD(&ab->otg.notifier); | ||
504 | |||
505 | /* v1: Wait for link status to become stable. | ||
506 | * all: Updates form set_host and set_peripheral as they are atomic. | ||
507 | */ | ||
508 | INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work); | ||
509 | |||
510 | /* all: Disable phy when called from set_host and set_peripheral */ | ||
511 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); | ||
512 | |||
513 | if (ab->rev < 0x20) { | ||
514 | err = ab8500_usb_v1x_res_setup(pdev, ab); | ||
515 | ab->link_status_wait = AB8500_V1x_LINK_STAT_WAIT; | ||
516 | } else { | ||
517 | err = ab8500_usb_v2_res_setup(pdev, ab); | ||
518 | } | ||
519 | |||
520 | if (err < 0) | ||
521 | goto fail0; | ||
522 | |||
523 | err = otg_set_transceiver(&ab->otg); | ||
524 | if (err) { | ||
525 | dev_err(&pdev->dev, "Can't register transceiver\n"); | ||
526 | goto fail1; | ||
527 | } | ||
528 | |||
529 | dev_info(&pdev->dev, "AB8500 usb driver initialized\n"); | ||
530 | |||
531 | return 0; | ||
532 | fail1: | ||
533 | ab8500_usb_irq_free(ab); | ||
534 | fail0: | ||
535 | kfree(ab); | ||
536 | return err; | ||
537 | } | ||
538 | |||
539 | static int __devexit ab8500_usb_remove(struct platform_device *pdev) | ||
540 | { | ||
541 | struct ab8500_usb *ab = platform_get_drvdata(pdev); | ||
542 | |||
543 | ab8500_usb_irq_free(ab); | ||
544 | |||
545 | cancel_delayed_work_sync(&ab->dwork); | ||
546 | |||
547 | cancel_work_sync(&ab->phy_dis_work); | ||
548 | |||
549 | otg_set_transceiver(NULL); | ||
550 | |||
551 | ab8500_usb_host_phy_dis(ab); | ||
552 | ab8500_usb_peri_phy_dis(ab); | ||
553 | |||
554 | platform_set_drvdata(pdev, NULL); | ||
555 | |||
556 | kfree(ab); | ||
557 | |||
558 | return 0; | ||
559 | } | ||
560 | |||
561 | static struct platform_driver ab8500_usb_driver = { | ||
562 | .probe = ab8500_usb_probe, | ||
563 | .remove = __devexit_p(ab8500_usb_remove), | ||
564 | .driver = { | ||
565 | .name = "ab8500-usb", | ||
566 | .owner = THIS_MODULE, | ||
567 | }, | ||
568 | }; | ||
569 | |||
570 | static int __init ab8500_usb_init(void) | ||
571 | { | ||
572 | return platform_driver_register(&ab8500_usb_driver); | ||
573 | } | ||
574 | subsys_initcall(ab8500_usb_init); | ||
575 | |||
576 | static void __exit ab8500_usb_exit(void) | ||
577 | { | ||
578 | platform_driver_unregister(&ab8500_usb_driver); | ||
579 | } | ||
580 | module_exit(ab8500_usb_exit); | ||
581 | |||
582 | MODULE_ALIAS("platform:ab8500_usb"); | ||
583 | MODULE_AUTHOR("ST-Ericsson AB"); | ||
584 | MODULE_DESCRIPTION("AB8500 usb transceiver driver"); | ||
585 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/otg/msm72k_otg.c b/drivers/usb/otg/msm72k_otg.c new file mode 100644 index 000000000000..1cd52edcd0c2 --- /dev/null +++ b/drivers/usb/otg/msm72k_otg.c | |||
@@ -0,0 +1,1125 @@ | |||
1 | /* Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License version 2 and | ||
5 | * only version 2 as published by the Free Software Foundation. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
15 | * 02110-1301, USA. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/clk.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/err.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/ioport.h> | ||
29 | #include <linux/uaccess.h> | ||
30 | #include <linux/debugfs.h> | ||
31 | #include <linux/seq_file.h> | ||
32 | #include <linux/pm_runtime.h> | ||
33 | |||
34 | #include <linux/usb.h> | ||
35 | #include <linux/usb/otg.h> | ||
36 | #include <linux/usb/ulpi.h> | ||
37 | #include <linux/usb/gadget.h> | ||
38 | #include <linux/usb/hcd.h> | ||
39 | #include <linux/usb/msm_hsusb.h> | ||
40 | #include <linux/usb/msm_hsusb_hw.h> | ||
41 | |||
42 | #include <mach/clk.h> | ||
43 | |||
44 | #define MSM_USB_BASE (motg->regs) | ||
45 | #define DRIVER_NAME "msm_otg" | ||
46 | |||
47 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) | ||
48 | static int ulpi_read(struct otg_transceiver *otg, u32 reg) | ||
49 | { | ||
50 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
51 | int cnt = 0; | ||
52 | |||
53 | /* initiate read operation */ | ||
54 | writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), | ||
55 | USB_ULPI_VIEWPORT); | ||
56 | |||
57 | /* wait for completion */ | ||
58 | while (cnt < ULPI_IO_TIMEOUT_USEC) { | ||
59 | if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN)) | ||
60 | break; | ||
61 | udelay(1); | ||
62 | cnt++; | ||
63 | } | ||
64 | |||
65 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { | ||
66 | dev_err(otg->dev, "ulpi_read: timeout %08x\n", | ||
67 | readl(USB_ULPI_VIEWPORT)); | ||
68 | return -ETIMEDOUT; | ||
69 | } | ||
70 | return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT)); | ||
71 | } | ||
72 | |||
73 | static int ulpi_write(struct otg_transceiver *otg, u32 val, u32 reg) | ||
74 | { | ||
75 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
76 | int cnt = 0; | ||
77 | |||
78 | /* initiate write operation */ | ||
79 | writel(ULPI_RUN | ULPI_WRITE | | ||
80 | ULPI_ADDR(reg) | ULPI_DATA(val), | ||
81 | USB_ULPI_VIEWPORT); | ||
82 | |||
83 | /* wait for completion */ | ||
84 | while (cnt < ULPI_IO_TIMEOUT_USEC) { | ||
85 | if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN)) | ||
86 | break; | ||
87 | udelay(1); | ||
88 | cnt++; | ||
89 | } | ||
90 | |||
91 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { | ||
92 | dev_err(otg->dev, "ulpi_write: timeout\n"); | ||
93 | return -ETIMEDOUT; | ||
94 | } | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static struct otg_io_access_ops msm_otg_io_ops = { | ||
99 | .read = ulpi_read, | ||
100 | .write = ulpi_write, | ||
101 | }; | ||
102 | |||
103 | static void ulpi_init(struct msm_otg *motg) | ||
104 | { | ||
105 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
106 | int *seq = pdata->phy_init_seq; | ||
107 | |||
108 | if (!seq) | ||
109 | return; | ||
110 | |||
111 | while (seq[0] >= 0) { | ||
112 | dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n", | ||
113 | seq[0], seq[1]); | ||
114 | ulpi_write(&motg->otg, seq[0], seq[1]); | ||
115 | seq += 2; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) | ||
120 | { | ||
121 | int ret; | ||
122 | |||
123 | if (assert) { | ||
124 | ret = clk_reset(motg->clk, CLK_RESET_ASSERT); | ||
125 | if (ret) | ||
126 | dev_err(motg->otg.dev, "usb hs_clk assert failed\n"); | ||
127 | } else { | ||
128 | ret = clk_reset(motg->clk, CLK_RESET_DEASSERT); | ||
129 | if (ret) | ||
130 | dev_err(motg->otg.dev, "usb hs_clk deassert failed\n"); | ||
131 | } | ||
132 | return ret; | ||
133 | } | ||
134 | |||
135 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) | ||
136 | { | ||
137 | int ret; | ||
138 | |||
139 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT); | ||
140 | if (ret) { | ||
141 | dev_err(motg->otg.dev, "usb phy clk assert failed\n"); | ||
142 | return ret; | ||
143 | } | ||
144 | usleep_range(10000, 12000); | ||
145 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT); | ||
146 | if (ret) | ||
147 | dev_err(motg->otg.dev, "usb phy clk deassert failed\n"); | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | static int msm_otg_phy_reset(struct msm_otg *motg) | ||
152 | { | ||
153 | u32 val; | ||
154 | int ret; | ||
155 | int retries; | ||
156 | |||
157 | ret = msm_otg_link_clk_reset(motg, 1); | ||
158 | if (ret) | ||
159 | return ret; | ||
160 | ret = msm_otg_phy_clk_reset(motg); | ||
161 | if (ret) | ||
162 | return ret; | ||
163 | ret = msm_otg_link_clk_reset(motg, 0); | ||
164 | if (ret) | ||
165 | return ret; | ||
166 | |||
167 | val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; | ||
168 | writel(val | PORTSC_PTS_ULPI, USB_PORTSC); | ||
169 | |||
170 | for (retries = 3; retries > 0; retries--) { | ||
171 | ret = ulpi_write(&motg->otg, ULPI_FUNC_CTRL_SUSPENDM, | ||
172 | ULPI_CLR(ULPI_FUNC_CTRL)); | ||
173 | if (!ret) | ||
174 | break; | ||
175 | ret = msm_otg_phy_clk_reset(motg); | ||
176 | if (ret) | ||
177 | return ret; | ||
178 | } | ||
179 | if (!retries) | ||
180 | return -ETIMEDOUT; | ||
181 | |||
182 | /* This reset calibrates the phy, if the above write succeeded */ | ||
183 | ret = msm_otg_phy_clk_reset(motg); | ||
184 | if (ret) | ||
185 | return ret; | ||
186 | |||
187 | for (retries = 3; retries > 0; retries--) { | ||
188 | ret = ulpi_read(&motg->otg, ULPI_DEBUG); | ||
189 | if (ret != -ETIMEDOUT) | ||
190 | break; | ||
191 | ret = msm_otg_phy_clk_reset(motg); | ||
192 | if (ret) | ||
193 | return ret; | ||
194 | } | ||
195 | if (!retries) | ||
196 | return -ETIMEDOUT; | ||
197 | |||
198 | dev_info(motg->otg.dev, "phy_reset: success\n"); | ||
199 | return 0; | ||
200 | } | ||
201 | |||
202 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) | ||
203 | static int msm_otg_reset(struct otg_transceiver *otg) | ||
204 | { | ||
205 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
206 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
207 | int cnt = 0; | ||
208 | int ret; | ||
209 | u32 val = 0; | ||
210 | u32 ulpi_val = 0; | ||
211 | |||
212 | ret = msm_otg_phy_reset(motg); | ||
213 | if (ret) { | ||
214 | dev_err(otg->dev, "phy_reset failed\n"); | ||
215 | return ret; | ||
216 | } | ||
217 | |||
218 | ulpi_init(motg); | ||
219 | |||
220 | writel(USBCMD_RESET, USB_USBCMD); | ||
221 | while (cnt < LINK_RESET_TIMEOUT_USEC) { | ||
222 | if (!(readl(USB_USBCMD) & USBCMD_RESET)) | ||
223 | break; | ||
224 | udelay(1); | ||
225 | cnt++; | ||
226 | } | ||
227 | if (cnt >= LINK_RESET_TIMEOUT_USEC) | ||
228 | return -ETIMEDOUT; | ||
229 | |||
230 | /* select ULPI phy */ | ||
231 | writel(0x80000000, USB_PORTSC); | ||
232 | |||
233 | msleep(100); | ||
234 | |||
235 | writel(0x0, USB_AHBBURST); | ||
236 | writel(0x00, USB_AHBMODE); | ||
237 | |||
238 | if (pdata->otg_control == OTG_PHY_CONTROL) { | ||
239 | val = readl(USB_OTGSC); | ||
240 | if (pdata->mode == USB_OTG) { | ||
241 | ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; | ||
242 | val |= OTGSC_IDIE | OTGSC_BSVIE; | ||
243 | } else if (pdata->mode == USB_PERIPHERAL) { | ||
244 | ulpi_val = ULPI_INT_SESS_VALID; | ||
245 | val |= OTGSC_BSVIE; | ||
246 | } | ||
247 | writel(val, USB_OTGSC); | ||
248 | ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_RISE); | ||
249 | ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_FALL); | ||
250 | } | ||
251 | |||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) | ||
256 | static int msm_otg_suspend(struct msm_otg *motg) | ||
257 | { | ||
258 | struct otg_transceiver *otg = &motg->otg; | ||
259 | struct usb_bus *bus = otg->host; | ||
260 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
261 | int cnt = 0; | ||
262 | |||
263 | if (atomic_read(&motg->in_lpm)) | ||
264 | return 0; | ||
265 | |||
266 | disable_irq(motg->irq); | ||
267 | /* | ||
268 | * Interrupt Latch Register auto-clear feature is not present | ||
269 | * in all PHY versions. Latch register is clear on read type. | ||
270 | * Clear latch register to avoid spurious wakeup from | ||
271 | * low power mode (LPM). | ||
272 | */ | ||
273 | ulpi_read(otg, 0x14); | ||
274 | |||
275 | /* | ||
276 | * PHY comparators are disabled when PHY enters into low power | ||
277 | * mode (LPM). Keep PHY comparators ON in LPM only when we expect | ||
278 | * VBUS/Id notifications from USB PHY. Otherwise turn off USB | ||
279 | * PHY comparators. This save significant amount of power. | ||
280 | */ | ||
281 | if (pdata->otg_control == OTG_PHY_CONTROL) | ||
282 | ulpi_write(otg, 0x01, 0x30); | ||
283 | |||
284 | /* | ||
285 | * PLL is not turned off when PHY enters into low power mode (LPM). | ||
286 | * Disable PLL for maximum power savings. | ||
287 | */ | ||
288 | ulpi_write(otg, 0x08, 0x09); | ||
289 | |||
290 | /* | ||
291 | * PHY may take some time or even fail to enter into low power | ||
292 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link | ||
293 | * in failure case. | ||
294 | */ | ||
295 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); | ||
296 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { | ||
297 | if (readl(USB_PORTSC) & PORTSC_PHCD) | ||
298 | break; | ||
299 | udelay(1); | ||
300 | cnt++; | ||
301 | } | ||
302 | |||
303 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { | ||
304 | dev_err(otg->dev, "Unable to suspend PHY\n"); | ||
305 | msm_otg_reset(otg); | ||
306 | enable_irq(motg->irq); | ||
307 | return -ETIMEDOUT; | ||
308 | } | ||
309 | |||
310 | /* | ||
311 | * PHY has capability to generate interrupt asynchronously in low | ||
312 | * power mode (LPM). This interrupt is level triggered. So USB IRQ | ||
313 | * line must be disabled till async interrupt enable bit is cleared | ||
314 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to | ||
315 | * block data communication from PHY. | ||
316 | */ | ||
317 | writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD); | ||
318 | |||
319 | clk_disable(motg->pclk); | ||
320 | clk_disable(motg->clk); | ||
321 | if (motg->core_clk) | ||
322 | clk_disable(motg->core_clk); | ||
323 | |||
324 | if (device_may_wakeup(otg->dev)) | ||
325 | enable_irq_wake(motg->irq); | ||
326 | if (bus) | ||
327 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); | ||
328 | |||
329 | atomic_set(&motg->in_lpm, 1); | ||
330 | enable_irq(motg->irq); | ||
331 | |||
332 | dev_info(otg->dev, "USB in low power mode\n"); | ||
333 | |||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) | ||
338 | static int msm_otg_resume(struct msm_otg *motg) | ||
339 | { | ||
340 | struct otg_transceiver *otg = &motg->otg; | ||
341 | struct usb_bus *bus = otg->host; | ||
342 | int cnt = 0; | ||
343 | unsigned temp; | ||
344 | |||
345 | if (!atomic_read(&motg->in_lpm)) | ||
346 | return 0; | ||
347 | |||
348 | clk_enable(motg->pclk); | ||
349 | clk_enable(motg->clk); | ||
350 | if (motg->core_clk) | ||
351 | clk_enable(motg->core_clk); | ||
352 | |||
353 | temp = readl(USB_USBCMD); | ||
354 | temp &= ~ASYNC_INTR_CTRL; | ||
355 | temp &= ~ULPI_STP_CTRL; | ||
356 | writel(temp, USB_USBCMD); | ||
357 | |||
358 | /* | ||
359 | * PHY comes out of low power mode (LPM) in case of wakeup | ||
360 | * from asynchronous interrupt. | ||
361 | */ | ||
362 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) | ||
363 | goto skip_phy_resume; | ||
364 | |||
365 | writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC); | ||
366 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { | ||
367 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) | ||
368 | break; | ||
369 | udelay(1); | ||
370 | cnt++; | ||
371 | } | ||
372 | |||
373 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { | ||
374 | /* | ||
375 | * This is a fatal error. Reset the link and | ||
376 | * PHY. USB state can not be restored. Re-insertion | ||
377 | * of USB cable is the only way to get USB working. | ||
378 | */ | ||
379 | dev_err(otg->dev, "Unable to resume USB." | ||
380 | "Re-plugin the cable\n"); | ||
381 | msm_otg_reset(otg); | ||
382 | } | ||
383 | |||
384 | skip_phy_resume: | ||
385 | if (device_may_wakeup(otg->dev)) | ||
386 | disable_irq_wake(motg->irq); | ||
387 | if (bus) | ||
388 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); | ||
389 | |||
390 | if (motg->async_int) { | ||
391 | motg->async_int = 0; | ||
392 | pm_runtime_put(otg->dev); | ||
393 | enable_irq(motg->irq); | ||
394 | } | ||
395 | |||
396 | atomic_set(&motg->in_lpm, 0); | ||
397 | |||
398 | dev_info(otg->dev, "USB exited from low power mode\n"); | ||
399 | |||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | static void msm_otg_start_host(struct otg_transceiver *otg, int on) | ||
404 | { | ||
405 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
406 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
407 | struct usb_hcd *hcd; | ||
408 | |||
409 | if (!otg->host) | ||
410 | return; | ||
411 | |||
412 | hcd = bus_to_hcd(otg->host); | ||
413 | |||
414 | if (on) { | ||
415 | dev_dbg(otg->dev, "host on\n"); | ||
416 | |||
417 | if (pdata->vbus_power) | ||
418 | pdata->vbus_power(1); | ||
419 | /* | ||
420 | * Some boards have a switch cotrolled by gpio | ||
421 | * to enable/disable internal HUB. Enable internal | ||
422 | * HUB before kicking the host. | ||
423 | */ | ||
424 | if (pdata->setup_gpio) | ||
425 | pdata->setup_gpio(OTG_STATE_A_HOST); | ||
426 | #ifdef CONFIG_USB | ||
427 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); | ||
428 | #endif | ||
429 | } else { | ||
430 | dev_dbg(otg->dev, "host off\n"); | ||
431 | |||
432 | #ifdef CONFIG_USB | ||
433 | usb_remove_hcd(hcd); | ||
434 | #endif | ||
435 | if (pdata->setup_gpio) | ||
436 | pdata->setup_gpio(OTG_STATE_UNDEFINED); | ||
437 | if (pdata->vbus_power) | ||
438 | pdata->vbus_power(0); | ||
439 | } | ||
440 | } | ||
441 | |||
442 | static int msm_otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) | ||
443 | { | ||
444 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
445 | struct usb_hcd *hcd; | ||
446 | |||
447 | /* | ||
448 | * Fail host registration if this board can support | ||
449 | * only peripheral configuration. | ||
450 | */ | ||
451 | if (motg->pdata->mode == USB_PERIPHERAL) { | ||
452 | dev_info(otg->dev, "Host mode is not supported\n"); | ||
453 | return -ENODEV; | ||
454 | } | ||
455 | |||
456 | if (!host) { | ||
457 | if (otg->state == OTG_STATE_A_HOST) { | ||
458 | pm_runtime_get_sync(otg->dev); | ||
459 | msm_otg_start_host(otg, 0); | ||
460 | otg->host = NULL; | ||
461 | otg->state = OTG_STATE_UNDEFINED; | ||
462 | schedule_work(&motg->sm_work); | ||
463 | } else { | ||
464 | otg->host = NULL; | ||
465 | } | ||
466 | |||
467 | return 0; | ||
468 | } | ||
469 | |||
470 | hcd = bus_to_hcd(host); | ||
471 | hcd->power_budget = motg->pdata->power_budget; | ||
472 | |||
473 | otg->host = host; | ||
474 | dev_dbg(otg->dev, "host driver registered w/ tranceiver\n"); | ||
475 | |||
476 | /* | ||
477 | * Kick the state machine work, if peripheral is not supported | ||
478 | * or peripheral is already registered with us. | ||
479 | */ | ||
480 | if (motg->pdata->mode == USB_HOST || otg->gadget) { | ||
481 | pm_runtime_get_sync(otg->dev); | ||
482 | schedule_work(&motg->sm_work); | ||
483 | } | ||
484 | |||
485 | return 0; | ||
486 | } | ||
487 | |||
488 | static void msm_otg_start_peripheral(struct otg_transceiver *otg, int on) | ||
489 | { | ||
490 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
491 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
492 | |||
493 | if (!otg->gadget) | ||
494 | return; | ||
495 | |||
496 | if (on) { | ||
497 | dev_dbg(otg->dev, "gadget on\n"); | ||
498 | /* | ||
499 | * Some boards have a switch cotrolled by gpio | ||
500 | * to enable/disable internal HUB. Disable internal | ||
501 | * HUB before kicking the gadget. | ||
502 | */ | ||
503 | if (pdata->setup_gpio) | ||
504 | pdata->setup_gpio(OTG_STATE_B_PERIPHERAL); | ||
505 | usb_gadget_vbus_connect(otg->gadget); | ||
506 | } else { | ||
507 | dev_dbg(otg->dev, "gadget off\n"); | ||
508 | usb_gadget_vbus_disconnect(otg->gadget); | ||
509 | if (pdata->setup_gpio) | ||
510 | pdata->setup_gpio(OTG_STATE_UNDEFINED); | ||
511 | } | ||
512 | |||
513 | } | ||
514 | |||
515 | static int msm_otg_set_peripheral(struct otg_transceiver *otg, | ||
516 | struct usb_gadget *gadget) | ||
517 | { | ||
518 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); | ||
519 | |||
520 | /* | ||
521 | * Fail peripheral registration if this board can support | ||
522 | * only host configuration. | ||
523 | */ | ||
524 | if (motg->pdata->mode == USB_HOST) { | ||
525 | dev_info(otg->dev, "Peripheral mode is not supported\n"); | ||
526 | return -ENODEV; | ||
527 | } | ||
528 | |||
529 | if (!gadget) { | ||
530 | if (otg->state == OTG_STATE_B_PERIPHERAL) { | ||
531 | pm_runtime_get_sync(otg->dev); | ||
532 | msm_otg_start_peripheral(otg, 0); | ||
533 | otg->gadget = NULL; | ||
534 | otg->state = OTG_STATE_UNDEFINED; | ||
535 | schedule_work(&motg->sm_work); | ||
536 | } else { | ||
537 | otg->gadget = NULL; | ||
538 | } | ||
539 | |||
540 | return 0; | ||
541 | } | ||
542 | otg->gadget = gadget; | ||
543 | dev_dbg(otg->dev, "peripheral driver registered w/ tranceiver\n"); | ||
544 | |||
545 | /* | ||
546 | * Kick the state machine work, if host is not supported | ||
547 | * or host is already registered with us. | ||
548 | */ | ||
549 | if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { | ||
550 | pm_runtime_get_sync(otg->dev); | ||
551 | schedule_work(&motg->sm_work); | ||
552 | } | ||
553 | |||
554 | return 0; | ||
555 | } | ||
556 | |||
557 | /* | ||
558 | * We support OTG, Peripheral only and Host only configurations. In case | ||
559 | * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen | ||
560 | * via Id pin status or user request (debugfs). Id/BSV interrupts are not | ||
561 | * enabled when switch is controlled by user and default mode is supplied | ||
562 | * by board file, which can be changed by userspace later. | ||
563 | */ | ||
564 | static void msm_otg_init_sm(struct msm_otg *motg) | ||
565 | { | ||
566 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
567 | u32 otgsc = readl(USB_OTGSC); | ||
568 | |||
569 | switch (pdata->mode) { | ||
570 | case USB_OTG: | ||
571 | if (pdata->otg_control == OTG_PHY_CONTROL) { | ||
572 | if (otgsc & OTGSC_ID) | ||
573 | set_bit(ID, &motg->inputs); | ||
574 | else | ||
575 | clear_bit(ID, &motg->inputs); | ||
576 | |||
577 | if (otgsc & OTGSC_BSV) | ||
578 | set_bit(B_SESS_VLD, &motg->inputs); | ||
579 | else | ||
580 | clear_bit(B_SESS_VLD, &motg->inputs); | ||
581 | } else if (pdata->otg_control == OTG_USER_CONTROL) { | ||
582 | if (pdata->default_mode == USB_HOST) { | ||
583 | clear_bit(ID, &motg->inputs); | ||
584 | } else if (pdata->default_mode == USB_PERIPHERAL) { | ||
585 | set_bit(ID, &motg->inputs); | ||
586 | set_bit(B_SESS_VLD, &motg->inputs); | ||
587 | } else { | ||
588 | set_bit(ID, &motg->inputs); | ||
589 | clear_bit(B_SESS_VLD, &motg->inputs); | ||
590 | } | ||
591 | } | ||
592 | break; | ||
593 | case USB_HOST: | ||
594 | clear_bit(ID, &motg->inputs); | ||
595 | break; | ||
596 | case USB_PERIPHERAL: | ||
597 | set_bit(ID, &motg->inputs); | ||
598 | if (otgsc & OTGSC_BSV) | ||
599 | set_bit(B_SESS_VLD, &motg->inputs); | ||
600 | else | ||
601 | clear_bit(B_SESS_VLD, &motg->inputs); | ||
602 | break; | ||
603 | default: | ||
604 | break; | ||
605 | } | ||
606 | } | ||
607 | |||
608 | static void msm_otg_sm_work(struct work_struct *w) | ||
609 | { | ||
610 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); | ||
611 | struct otg_transceiver *otg = &motg->otg; | ||
612 | |||
613 | switch (otg->state) { | ||
614 | case OTG_STATE_UNDEFINED: | ||
615 | dev_dbg(otg->dev, "OTG_STATE_UNDEFINED state\n"); | ||
616 | msm_otg_reset(otg); | ||
617 | msm_otg_init_sm(motg); | ||
618 | otg->state = OTG_STATE_B_IDLE; | ||
619 | /* FALL THROUGH */ | ||
620 | case OTG_STATE_B_IDLE: | ||
621 | dev_dbg(otg->dev, "OTG_STATE_B_IDLE state\n"); | ||
622 | if (!test_bit(ID, &motg->inputs) && otg->host) { | ||
623 | /* disable BSV bit */ | ||
624 | writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC); | ||
625 | msm_otg_start_host(otg, 1); | ||
626 | otg->state = OTG_STATE_A_HOST; | ||
627 | } else if (test_bit(B_SESS_VLD, &motg->inputs) && otg->gadget) { | ||
628 | msm_otg_start_peripheral(otg, 1); | ||
629 | otg->state = OTG_STATE_B_PERIPHERAL; | ||
630 | } | ||
631 | pm_runtime_put_sync(otg->dev); | ||
632 | break; | ||
633 | case OTG_STATE_B_PERIPHERAL: | ||
634 | dev_dbg(otg->dev, "OTG_STATE_B_PERIPHERAL state\n"); | ||
635 | if (!test_bit(B_SESS_VLD, &motg->inputs) || | ||
636 | !test_bit(ID, &motg->inputs)) { | ||
637 | msm_otg_start_peripheral(otg, 0); | ||
638 | otg->state = OTG_STATE_B_IDLE; | ||
639 | msm_otg_reset(otg); | ||
640 | schedule_work(w); | ||
641 | } | ||
642 | break; | ||
643 | case OTG_STATE_A_HOST: | ||
644 | dev_dbg(otg->dev, "OTG_STATE_A_HOST state\n"); | ||
645 | if (test_bit(ID, &motg->inputs)) { | ||
646 | msm_otg_start_host(otg, 0); | ||
647 | otg->state = OTG_STATE_B_IDLE; | ||
648 | msm_otg_reset(otg); | ||
649 | schedule_work(w); | ||
650 | } | ||
651 | break; | ||
652 | default: | ||
653 | break; | ||
654 | } | ||
655 | } | ||
656 | |||
657 | static irqreturn_t msm_otg_irq(int irq, void *data) | ||
658 | { | ||
659 | struct msm_otg *motg = data; | ||
660 | struct otg_transceiver *otg = &motg->otg; | ||
661 | u32 otgsc = 0; | ||
662 | |||
663 | if (atomic_read(&motg->in_lpm)) { | ||
664 | disable_irq_nosync(irq); | ||
665 | motg->async_int = 1; | ||
666 | pm_runtime_get(otg->dev); | ||
667 | return IRQ_HANDLED; | ||
668 | } | ||
669 | |||
670 | otgsc = readl(USB_OTGSC); | ||
671 | if (!(otgsc & (OTGSC_IDIS | OTGSC_BSVIS))) | ||
672 | return IRQ_NONE; | ||
673 | |||
674 | if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) { | ||
675 | if (otgsc & OTGSC_ID) | ||
676 | set_bit(ID, &motg->inputs); | ||
677 | else | ||
678 | clear_bit(ID, &motg->inputs); | ||
679 | dev_dbg(otg->dev, "ID set/clear\n"); | ||
680 | pm_runtime_get_noresume(otg->dev); | ||
681 | } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) { | ||
682 | if (otgsc & OTGSC_BSV) | ||
683 | set_bit(B_SESS_VLD, &motg->inputs); | ||
684 | else | ||
685 | clear_bit(B_SESS_VLD, &motg->inputs); | ||
686 | dev_dbg(otg->dev, "BSV set/clear\n"); | ||
687 | pm_runtime_get_noresume(otg->dev); | ||
688 | } | ||
689 | |||
690 | writel(otgsc, USB_OTGSC); | ||
691 | schedule_work(&motg->sm_work); | ||
692 | return IRQ_HANDLED; | ||
693 | } | ||
694 | |||
695 | static int msm_otg_mode_show(struct seq_file *s, void *unused) | ||
696 | { | ||
697 | struct msm_otg *motg = s->private; | ||
698 | struct otg_transceiver *otg = &motg->otg; | ||
699 | |||
700 | switch (otg->state) { | ||
701 | case OTG_STATE_A_HOST: | ||
702 | seq_printf(s, "host\n"); | ||
703 | break; | ||
704 | case OTG_STATE_B_PERIPHERAL: | ||
705 | seq_printf(s, "peripheral\n"); | ||
706 | break; | ||
707 | default: | ||
708 | seq_printf(s, "none\n"); | ||
709 | break; | ||
710 | } | ||
711 | |||
712 | return 0; | ||
713 | } | ||
714 | |||
715 | static int msm_otg_mode_open(struct inode *inode, struct file *file) | ||
716 | { | ||
717 | return single_open(file, msm_otg_mode_show, inode->i_private); | ||
718 | } | ||
719 | |||
720 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | ||
721 | size_t count, loff_t *ppos) | ||
722 | { | ||
723 | struct msm_otg *motg = file->private_data; | ||
724 | char buf[16]; | ||
725 | struct otg_transceiver *otg = &motg->otg; | ||
726 | int status = count; | ||
727 | enum usb_mode_type req_mode; | ||
728 | |||
729 | memset(buf, 0x00, sizeof(buf)); | ||
730 | |||
731 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) { | ||
732 | status = -EFAULT; | ||
733 | goto out; | ||
734 | } | ||
735 | |||
736 | if (!strncmp(buf, "host", 4)) { | ||
737 | req_mode = USB_HOST; | ||
738 | } else if (!strncmp(buf, "peripheral", 10)) { | ||
739 | req_mode = USB_PERIPHERAL; | ||
740 | } else if (!strncmp(buf, "none", 4)) { | ||
741 | req_mode = USB_NONE; | ||
742 | } else { | ||
743 | status = -EINVAL; | ||
744 | goto out; | ||
745 | } | ||
746 | |||
747 | switch (req_mode) { | ||
748 | case USB_NONE: | ||
749 | switch (otg->state) { | ||
750 | case OTG_STATE_A_HOST: | ||
751 | case OTG_STATE_B_PERIPHERAL: | ||
752 | set_bit(ID, &motg->inputs); | ||
753 | clear_bit(B_SESS_VLD, &motg->inputs); | ||
754 | break; | ||
755 | default: | ||
756 | goto out; | ||
757 | } | ||
758 | break; | ||
759 | case USB_PERIPHERAL: | ||
760 | switch (otg->state) { | ||
761 | case OTG_STATE_B_IDLE: | ||
762 | case OTG_STATE_A_HOST: | ||
763 | set_bit(ID, &motg->inputs); | ||
764 | set_bit(B_SESS_VLD, &motg->inputs); | ||
765 | break; | ||
766 | default: | ||
767 | goto out; | ||
768 | } | ||
769 | break; | ||
770 | case USB_HOST: | ||
771 | switch (otg->state) { | ||
772 | case OTG_STATE_B_IDLE: | ||
773 | case OTG_STATE_B_PERIPHERAL: | ||
774 | clear_bit(ID, &motg->inputs); | ||
775 | break; | ||
776 | default: | ||
777 | goto out; | ||
778 | } | ||
779 | break; | ||
780 | default: | ||
781 | goto out; | ||
782 | } | ||
783 | |||
784 | pm_runtime_get_sync(otg->dev); | ||
785 | schedule_work(&motg->sm_work); | ||
786 | out: | ||
787 | return status; | ||
788 | } | ||
789 | |||
790 | const struct file_operations msm_otg_mode_fops = { | ||
791 | .open = msm_otg_mode_open, | ||
792 | .read = seq_read, | ||
793 | .write = msm_otg_mode_write, | ||
794 | .llseek = seq_lseek, | ||
795 | .release = single_release, | ||
796 | }; | ||
797 | |||
798 | static struct dentry *msm_otg_dbg_root; | ||
799 | static struct dentry *msm_otg_dbg_mode; | ||
800 | |||
801 | static int msm_otg_debugfs_init(struct msm_otg *motg) | ||
802 | { | ||
803 | msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL); | ||
804 | |||
805 | if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root)) | ||
806 | return -ENODEV; | ||
807 | |||
808 | msm_otg_dbg_mode = debugfs_create_file("mode", S_IRUGO | S_IWUSR, | ||
809 | msm_otg_dbg_root, motg, &msm_otg_mode_fops); | ||
810 | if (!msm_otg_dbg_mode) { | ||
811 | debugfs_remove(msm_otg_dbg_root); | ||
812 | msm_otg_dbg_root = NULL; | ||
813 | return -ENODEV; | ||
814 | } | ||
815 | |||
816 | return 0; | ||
817 | } | ||
818 | |||
819 | static void msm_otg_debugfs_cleanup(void) | ||
820 | { | ||
821 | debugfs_remove(msm_otg_dbg_mode); | ||
822 | debugfs_remove(msm_otg_dbg_root); | ||
823 | } | ||
824 | |||
825 | static int __init msm_otg_probe(struct platform_device *pdev) | ||
826 | { | ||
827 | int ret = 0; | ||
828 | struct resource *res; | ||
829 | struct msm_otg *motg; | ||
830 | struct otg_transceiver *otg; | ||
831 | |||
832 | dev_info(&pdev->dev, "msm_otg probe\n"); | ||
833 | if (!pdev->dev.platform_data) { | ||
834 | dev_err(&pdev->dev, "No platform data given. Bailing out\n"); | ||
835 | return -ENODEV; | ||
836 | } | ||
837 | |||
838 | motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL); | ||
839 | if (!motg) { | ||
840 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); | ||
841 | return -ENOMEM; | ||
842 | } | ||
843 | |||
844 | motg->pdata = pdev->dev.platform_data; | ||
845 | otg = &motg->otg; | ||
846 | otg->dev = &pdev->dev; | ||
847 | |||
848 | motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk"); | ||
849 | if (IS_ERR(motg->phy_reset_clk)) { | ||
850 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); | ||
851 | ret = PTR_ERR(motg->phy_reset_clk); | ||
852 | goto free_motg; | ||
853 | } | ||
854 | |||
855 | motg->clk = clk_get(&pdev->dev, "usb_hs_clk"); | ||
856 | if (IS_ERR(motg->clk)) { | ||
857 | dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); | ||
858 | ret = PTR_ERR(motg->clk); | ||
859 | goto put_phy_reset_clk; | ||
860 | } | ||
861 | |||
862 | motg->pclk = clk_get(&pdev->dev, "usb_hs_pclk"); | ||
863 | if (IS_ERR(motg->pclk)) { | ||
864 | dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); | ||
865 | ret = PTR_ERR(motg->pclk); | ||
866 | goto put_clk; | ||
867 | } | ||
868 | |||
869 | /* | ||
870 | * USB core clock is not present on all MSM chips. This | ||
871 | * clock is introduced to remove the dependency on AXI | ||
872 | * bus frequency. | ||
873 | */ | ||
874 | motg->core_clk = clk_get(&pdev->dev, "usb_hs_core_clk"); | ||
875 | if (IS_ERR(motg->core_clk)) | ||
876 | motg->core_clk = NULL; | ||
877 | |||
878 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
879 | if (!res) { | ||
880 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); | ||
881 | ret = -ENODEV; | ||
882 | goto put_core_clk; | ||
883 | } | ||
884 | |||
885 | motg->regs = ioremap(res->start, resource_size(res)); | ||
886 | if (!motg->regs) { | ||
887 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
888 | ret = -ENOMEM; | ||
889 | goto put_core_clk; | ||
890 | } | ||
891 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); | ||
892 | |||
893 | motg->irq = platform_get_irq(pdev, 0); | ||
894 | if (!motg->irq) { | ||
895 | dev_err(&pdev->dev, "platform_get_irq failed\n"); | ||
896 | ret = -ENODEV; | ||
897 | goto free_regs; | ||
898 | } | ||
899 | |||
900 | clk_enable(motg->clk); | ||
901 | clk_enable(motg->pclk); | ||
902 | if (motg->core_clk) | ||
903 | clk_enable(motg->core_clk); | ||
904 | |||
905 | writel(0, USB_USBINTR); | ||
906 | writel(0, USB_OTGSC); | ||
907 | |||
908 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); | ||
909 | ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED, | ||
910 | "msm_otg", motg); | ||
911 | if (ret) { | ||
912 | dev_err(&pdev->dev, "request irq failed\n"); | ||
913 | goto disable_clks; | ||
914 | } | ||
915 | |||
916 | otg->init = msm_otg_reset; | ||
917 | otg->set_host = msm_otg_set_host; | ||
918 | otg->set_peripheral = msm_otg_set_peripheral; | ||
919 | |||
920 | otg->io_ops = &msm_otg_io_ops; | ||
921 | |||
922 | ret = otg_set_transceiver(&motg->otg); | ||
923 | if (ret) { | ||
924 | dev_err(&pdev->dev, "otg_set_transceiver failed\n"); | ||
925 | goto free_irq; | ||
926 | } | ||
927 | |||
928 | platform_set_drvdata(pdev, motg); | ||
929 | device_init_wakeup(&pdev->dev, 1); | ||
930 | |||
931 | if (motg->pdata->mode == USB_OTG && | ||
932 | motg->pdata->otg_control == OTG_USER_CONTROL) { | ||
933 | ret = msm_otg_debugfs_init(motg); | ||
934 | if (ret) | ||
935 | dev_dbg(&pdev->dev, "mode debugfs file is" | ||
936 | "not available\n"); | ||
937 | } | ||
938 | |||
939 | pm_runtime_set_active(&pdev->dev); | ||
940 | pm_runtime_enable(&pdev->dev); | ||
941 | |||
942 | return 0; | ||
943 | free_irq: | ||
944 | free_irq(motg->irq, motg); | ||
945 | disable_clks: | ||
946 | clk_disable(motg->pclk); | ||
947 | clk_disable(motg->clk); | ||
948 | free_regs: | ||
949 | iounmap(motg->regs); | ||
950 | put_core_clk: | ||
951 | if (motg->core_clk) | ||
952 | clk_put(motg->core_clk); | ||
953 | clk_put(motg->pclk); | ||
954 | put_clk: | ||
955 | clk_put(motg->clk); | ||
956 | put_phy_reset_clk: | ||
957 | clk_put(motg->phy_reset_clk); | ||
958 | free_motg: | ||
959 | kfree(motg); | ||
960 | return ret; | ||
961 | } | ||
962 | |||
963 | static int __devexit msm_otg_remove(struct platform_device *pdev) | ||
964 | { | ||
965 | struct msm_otg *motg = platform_get_drvdata(pdev); | ||
966 | struct otg_transceiver *otg = &motg->otg; | ||
967 | int cnt = 0; | ||
968 | |||
969 | if (otg->host || otg->gadget) | ||
970 | return -EBUSY; | ||
971 | |||
972 | msm_otg_debugfs_cleanup(); | ||
973 | cancel_work_sync(&motg->sm_work); | ||
974 | |||
975 | msm_otg_resume(motg); | ||
976 | |||
977 | device_init_wakeup(&pdev->dev, 0); | ||
978 | pm_runtime_disable(&pdev->dev); | ||
979 | |||
980 | otg_set_transceiver(NULL); | ||
981 | free_irq(motg->irq, motg); | ||
982 | |||
983 | /* | ||
984 | * Put PHY in low power mode. | ||
985 | */ | ||
986 | ulpi_read(otg, 0x14); | ||
987 | ulpi_write(otg, 0x08, 0x09); | ||
988 | |||
989 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); | ||
990 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { | ||
991 | if (readl(USB_PORTSC) & PORTSC_PHCD) | ||
992 | break; | ||
993 | udelay(1); | ||
994 | cnt++; | ||
995 | } | ||
996 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) | ||
997 | dev_err(otg->dev, "Unable to suspend PHY\n"); | ||
998 | |||
999 | clk_disable(motg->pclk); | ||
1000 | clk_disable(motg->clk); | ||
1001 | if (motg->core_clk) | ||
1002 | clk_disable(motg->core_clk); | ||
1003 | |||
1004 | iounmap(motg->regs); | ||
1005 | pm_runtime_set_suspended(&pdev->dev); | ||
1006 | |||
1007 | clk_put(motg->phy_reset_clk); | ||
1008 | clk_put(motg->pclk); | ||
1009 | clk_put(motg->clk); | ||
1010 | if (motg->core_clk) | ||
1011 | clk_put(motg->core_clk); | ||
1012 | |||
1013 | kfree(motg); | ||
1014 | |||
1015 | return 0; | ||
1016 | } | ||
1017 | |||
1018 | #ifdef CONFIG_PM_RUNTIME | ||
1019 | static int msm_otg_runtime_idle(struct device *dev) | ||
1020 | { | ||
1021 | struct msm_otg *motg = dev_get_drvdata(dev); | ||
1022 | struct otg_transceiver *otg = &motg->otg; | ||
1023 | |||
1024 | dev_dbg(dev, "OTG runtime idle\n"); | ||
1025 | |||
1026 | /* | ||
1027 | * It is observed some times that a spurious interrupt | ||
1028 | * comes when PHY is put into LPM immediately after PHY reset. | ||
1029 | * This 1 sec delay also prevents entering into LPM immediately | ||
1030 | * after asynchronous interrupt. | ||
1031 | */ | ||
1032 | if (otg->state != OTG_STATE_UNDEFINED) | ||
1033 | pm_schedule_suspend(dev, 1000); | ||
1034 | |||
1035 | return -EAGAIN; | ||
1036 | } | ||
1037 | |||
1038 | static int msm_otg_runtime_suspend(struct device *dev) | ||
1039 | { | ||
1040 | struct msm_otg *motg = dev_get_drvdata(dev); | ||
1041 | |||
1042 | dev_dbg(dev, "OTG runtime suspend\n"); | ||
1043 | return msm_otg_suspend(motg); | ||
1044 | } | ||
1045 | |||
1046 | static int msm_otg_runtime_resume(struct device *dev) | ||
1047 | { | ||
1048 | struct msm_otg *motg = dev_get_drvdata(dev); | ||
1049 | |||
1050 | dev_dbg(dev, "OTG runtime resume\n"); | ||
1051 | return msm_otg_resume(motg); | ||
1052 | } | ||
1053 | #else | ||
1054 | #define msm_otg_runtime_idle NULL | ||
1055 | #define msm_otg_runtime_suspend NULL | ||
1056 | #define msm_otg_runtime_resume NULL | ||
1057 | #endif | ||
1058 | |||
1059 | #ifdef CONFIG_PM | ||
1060 | static int msm_otg_pm_suspend(struct device *dev) | ||
1061 | { | ||
1062 | struct msm_otg *motg = dev_get_drvdata(dev); | ||
1063 | |||
1064 | dev_dbg(dev, "OTG PM suspend\n"); | ||
1065 | return msm_otg_suspend(motg); | ||
1066 | } | ||
1067 | |||
1068 | static int msm_otg_pm_resume(struct device *dev) | ||
1069 | { | ||
1070 | struct msm_otg *motg = dev_get_drvdata(dev); | ||
1071 | int ret; | ||
1072 | |||
1073 | dev_dbg(dev, "OTG PM resume\n"); | ||
1074 | |||
1075 | ret = msm_otg_resume(motg); | ||
1076 | if (ret) | ||
1077 | return ret; | ||
1078 | |||
1079 | /* | ||
1080 | * Runtime PM Documentation recommends bringing the | ||
1081 | * device to full powered state upon resume. | ||
1082 | */ | ||
1083 | pm_runtime_disable(dev); | ||
1084 | pm_runtime_set_active(dev); | ||
1085 | pm_runtime_enable(dev); | ||
1086 | |||
1087 | return 0; | ||
1088 | } | ||
1089 | #else | ||
1090 | #define msm_otg_pm_suspend NULL | ||
1091 | #define msm_otg_pm_resume NULL | ||
1092 | #endif | ||
1093 | |||
1094 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { | ||
1095 | .runtime_suspend = msm_otg_runtime_suspend, | ||
1096 | .runtime_resume = msm_otg_runtime_resume, | ||
1097 | .runtime_idle = msm_otg_runtime_idle, | ||
1098 | .suspend = msm_otg_pm_suspend, | ||
1099 | .resume = msm_otg_pm_resume, | ||
1100 | }; | ||
1101 | |||
1102 | static struct platform_driver msm_otg_driver = { | ||
1103 | .remove = __devexit_p(msm_otg_remove), | ||
1104 | .driver = { | ||
1105 | .name = DRIVER_NAME, | ||
1106 | .owner = THIS_MODULE, | ||
1107 | .pm = &msm_otg_dev_pm_ops, | ||
1108 | }, | ||
1109 | }; | ||
1110 | |||
1111 | static int __init msm_otg_init(void) | ||
1112 | { | ||
1113 | return platform_driver_probe(&msm_otg_driver, msm_otg_probe); | ||
1114 | } | ||
1115 | |||
1116 | static void __exit msm_otg_exit(void) | ||
1117 | { | ||
1118 | platform_driver_unregister(&msm_otg_driver); | ||
1119 | } | ||
1120 | |||
1121 | module_init(msm_otg_init); | ||
1122 | module_exit(msm_otg_exit); | ||
1123 | |||
1124 | MODULE_LICENSE("GPL v2"); | ||
1125 | MODULE_DESCRIPTION("MSM USB transceiver driver"); | ||
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index 660b7caef784..b004b2a485c3 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/tty_flip.h> | 31 | #include <linux/tty_flip.h> |
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/bitops.h> | 33 | #include <linux/bitops.h> |
34 | #include <linux/uaccess.h> | ||
34 | #include <linux/usb.h> | 35 | #include <linux/usb.h> |
35 | #include <linux/usb/serial.h> | 36 | #include <linux/usb/serial.h> |
36 | #include <linux/serial.h> | 37 | #include <linux/serial.h> |