diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-24 17:57:49 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-24 17:57:49 -0400 |
commit | 1c41a9570a02cec80be5fb4f7f9cf206220d84a5 (patch) | |
tree | 21eeee43b0cb88415ea809bfab3f2b432fd5ac45 | |
parent | cd0e075784f4bce97b4ed47d4b354f045e895546 (diff) | |
parent | 3e457371f436e89ce9239674828f9729a36b2595 (diff) |
Merge tag 'usb-for-v4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes:
usb: patches for v4.1 merge window
As usual, a big pile of commits. This time a total
of 111 non-merge commits.
Other than the usual set of cleanups and non-critical
fixes, we have some interesting work for AM335x's MUSB
babble recovery. Now that takes a lot less time and we
don't have to Reset MUSB all the time.
The printer gadget has been converted to configfs interface
and the atmel udc has learned suspend/resume with wakeup.
Signed-off-by: Felipe Balbi <balbi@ti.com>
59 files changed, 2847 insertions, 1995 deletions
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-printer b/Documentation/ABI/testing/configfs-usb-gadget-printer new file mode 100644 index 000000000000..6b0714e3c605 --- /dev/null +++ b/Documentation/ABI/testing/configfs-usb-gadget-printer | |||
@@ -0,0 +1,9 @@ | |||
1 | What: /config/usb-gadget/gadget/functions/printer.name | ||
2 | Date: Apr 2015 | ||
3 | KernelVersion: 4.1 | ||
4 | Description: | ||
5 | The attributes: | ||
6 | |||
7 | pnp_string - Data to be passed to the host in pnp string | ||
8 | q_len - Number of requests per endpoint | ||
9 | |||
diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index cd7f0454e13a..5cc364309edb 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt | |||
@@ -14,6 +14,7 @@ Optional properties: | |||
14 | - phys: from the *Generic PHY* bindings | 14 | - phys: from the *Generic PHY* bindings |
15 | - phy-names: from the *Generic PHY* bindings | 15 | - phy-names: from the *Generic PHY* bindings |
16 | - tx-fifo-resize: determines if the FIFO *has* to be reallocated. | 16 | - tx-fifo-resize: determines if the FIFO *has* to be reallocated. |
17 | - snps,usb3_lpm_capable: determines if platform is USB3 LPM capable | ||
17 | - snps,disable_scramble_quirk: true when SW should disable data scrambling. | 18 | - snps,disable_scramble_quirk: true when SW should disable data scrambling. |
18 | Only really useful for FPGA builds. | 19 | Only really useful for FPGA builds. |
19 | - snps,has-lpm-erratum: true when DWC3 was configured with LPM Erratum enabled | 20 | - snps,has-lpm-erratum: true when DWC3 was configured with LPM Erratum enabled |
diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt index 61b045b6d50e..dc2a18f0b3a1 100644 --- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt +++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt | |||
@@ -15,7 +15,10 @@ Optional properties: | |||
15 | - phys: phandle + phy specifier pair | 15 | - phys: phandle + phy specifier pair |
16 | - phy-names: must be "usb" | 16 | - phy-names: must be "usb" |
17 | - dmas: Must contain a list of references to DMA specifiers. | 17 | - dmas: Must contain a list of references to DMA specifiers. |
18 | - dma-names : Must contain a list of DMA names, "tx" or "rx". | 18 | - dma-names : Must contain a list of DMA names: |
19 | - tx0 ... tx<n> | ||
20 | - rx0 ... rx<n> | ||
21 | - This <n> means DnFIFO in USBHS module. | ||
19 | 22 | ||
20 | Example: | 23 | Example: |
21 | usbhs: usb@e6590000 { | 24 | usbhs: usb@e6590000 { |
diff --git a/Documentation/usb/gadget-testing.txt b/Documentation/usb/gadget-testing.txt index 076ac7ba7f93..f45b2bf4b41d 100644 --- a/Documentation/usb/gadget-testing.txt +++ b/Documentation/usb/gadget-testing.txt | |||
@@ -19,6 +19,7 @@ provided by gadgets. | |||
19 | 16. UAC1 function | 19 | 16. UAC1 function |
20 | 17. UAC2 function | 20 | 17. UAC2 function |
21 | 18. UVC function | 21 | 18. UVC function |
22 | 19. PRINTER function | ||
22 | 23 | ||
23 | 24 | ||
24 | 1. ACM function | 25 | 1. ACM function |
@@ -726,3 +727,49 @@ with these patches: | |||
726 | http://www.spinics.net/lists/linux-usb/msg99220.html | 727 | http://www.spinics.net/lists/linux-usb/msg99220.html |
727 | 728 | ||
728 | host: luvcview -f yuv | 729 | host: luvcview -f yuv |
730 | |||
731 | 19. PRINTER function | ||
732 | ==================== | ||
733 | |||
734 | The function is provided by usb_f_printer.ko module. | ||
735 | |||
736 | Function-specific configfs interface | ||
737 | ------------------------------------ | ||
738 | |||
739 | The function name to use when creating the function directory is "printer". | ||
740 | The printer function provides these attributes in its function directory: | ||
741 | |||
742 | pnp_string - Data to be passed to the host in pnp string | ||
743 | q_len - Number of requests per endpoint | ||
744 | |||
745 | Testing the PRINTER function | ||
746 | ---------------------------- | ||
747 | |||
748 | The most basic testing: | ||
749 | |||
750 | device: run the gadget | ||
751 | # ls -l /devices/virtual/usb_printer_gadget/ | ||
752 | |||
753 | should show g_printer<number>. | ||
754 | |||
755 | If udev is active, then /dev/g_printer<number> should appear automatically. | ||
756 | |||
757 | host: | ||
758 | |||
759 | If udev is active, then e.g. /dev/usb/lp0 should appear. | ||
760 | |||
761 | host->device transmission: | ||
762 | |||
763 | device: | ||
764 | # cat /dev/g_printer<number> | ||
765 | host: | ||
766 | # cat > /dev/usb/lp0 | ||
767 | |||
768 | device->host transmission: | ||
769 | |||
770 | # cat > /dev/g_printer<number> | ||
771 | host: | ||
772 | # cat /dev/usb/lp0 | ||
773 | |||
774 | More advanced testing can be done with the prn_example | ||
775 | described in Documentation/usb/gadget-printer.txt. | ||
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 228654c94843..41914a55055d 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -86,10 +86,8 @@ static int hw_device_state(struct ci_hdrc *ci, u32 dma) | |||
86 | /* interrupt, error, port change, reset, sleep/suspend */ | 86 | /* interrupt, error, port change, reset, sleep/suspend */ |
87 | hw_write(ci, OP_USBINTR, ~0, | 87 | hw_write(ci, OP_USBINTR, ~0, |
88 | USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); | 88 | USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); |
89 | hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); | ||
90 | } else { | 89 | } else { |
91 | hw_write(ci, OP_USBINTR, ~0, 0); | 90 | hw_write(ci, OP_USBINTR, ~0, 0); |
92 | hw_write(ci, OP_USBCMD, USBCMD_RS, 0); | ||
93 | } | 91 | } |
94 | return 0; | 92 | return 0; |
95 | } | 93 | } |
@@ -1508,7 +1506,9 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) | |||
1508 | hw_device_reset(ci); | 1506 | hw_device_reset(ci); |
1509 | hw_device_state(ci, ci->ep0out->qh.dma); | 1507 | hw_device_state(ci, ci->ep0out->qh.dma); |
1510 | usb_gadget_set_state(_gadget, USB_STATE_POWERED); | 1508 | usb_gadget_set_state(_gadget, USB_STATE_POWERED); |
1509 | usb_udc_vbus_handler(_gadget, true); | ||
1511 | } else { | 1510 | } else { |
1511 | usb_udc_vbus_handler(_gadget, false); | ||
1512 | if (ci->driver) | 1512 | if (ci->driver) |
1513 | ci->driver->disconnect(&ci->gadget); | 1513 | ci->driver->disconnect(&ci->gadget); |
1514 | hw_device_state(ci, 0); | 1514 | hw_device_state(ci, 0); |
@@ -1574,13 +1574,12 @@ static int ci_udc_pullup(struct usb_gadget *_gadget, int is_on) | |||
1574 | { | 1574 | { |
1575 | struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); | 1575 | struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); |
1576 | 1576 | ||
1577 | if (!ci->vbus_active) | 1577 | pm_runtime_get_sync(&ci->gadget.dev); |
1578 | return -EOPNOTSUPP; | ||
1579 | |||
1580 | if (is_on) | 1578 | if (is_on) |
1581 | hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); | 1579 | hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); |
1582 | else | 1580 | else |
1583 | hw_write(ci, OP_USBCMD, USBCMD_RS, 0); | 1581 | hw_write(ci, OP_USBCMD, USBCMD_RS, 0); |
1582 | pm_runtime_put_sync(&ci->gadget.dev); | ||
1584 | 1583 | ||
1585 | return 0; | 1584 | return 0; |
1586 | } | 1585 | } |
@@ -1710,6 +1709,7 @@ static int ci_udc_start(struct usb_gadget *gadget, | |||
1710 | spin_lock_irqsave(&ci->lock, flags); | 1709 | spin_lock_irqsave(&ci->lock, flags); |
1711 | hw_device_reset(ci); | 1710 | hw_device_reset(ci); |
1712 | } else { | 1711 | } else { |
1712 | usb_udc_vbus_handler(&ci->gadget, false); | ||
1713 | pm_runtime_put_sync(&ci->gadget.dev); | 1713 | pm_runtime_put_sync(&ci->gadget.dev); |
1714 | return retval; | 1714 | return retval; |
1715 | } | 1715 | } |
diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig index 76b9ba4dc925..1bcb36ae6505 100644 --- a/drivers/usb/dwc2/Kconfig +++ b/drivers/usb/dwc2/Kconfig | |||
@@ -59,11 +59,13 @@ config USB_DWC2_PLATFORM | |||
59 | 59 | ||
60 | config USB_DWC2_PCI | 60 | config USB_DWC2_PCI |
61 | tristate "DWC2 PCI" | 61 | tristate "DWC2 PCI" |
62 | depends on USB_DWC2_HOST && PCI | 62 | depends on PCI |
63 | default USB_DWC2_HOST | 63 | default n |
64 | select USB_DWC2_PLATFORM | ||
65 | select NOP_USB_XCEIV | ||
64 | help | 66 | help |
65 | The Designware USB2.0 PCI interface module for controllers | 67 | The Designware USB2.0 PCI interface module for controllers |
66 | connected to a PCI bus. This is only used for host mode. | 68 | connected to a PCI bus. |
67 | 69 | ||
68 | config USB_DWC2_DEBUG | 70 | config USB_DWC2_DEBUG |
69 | bool "Enable Debugging Messages" | 71 | bool "Enable Debugging Messages" |
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile index 8f752679752a..f07b425eaff3 100644 --- a/drivers/usb/dwc2/Makefile +++ b/drivers/usb/dwc2/Makefile | |||
@@ -19,10 +19,8 @@ endif | |||
19 | # mode. The PCI bus interface module will called dwc2_pci.ko and the platform | 19 | # mode. The PCI bus interface module will called dwc2_pci.ko and the platform |
20 | # interface module will be called dwc2_platform.ko. | 20 | # interface module will be called dwc2_platform.ko. |
21 | 21 | ||
22 | ifneq ($(CONFIG_USB_DWC2_PCI),) | 22 | obj-$(CONFIG_USB_DWC2_PCI) += dwc2_pci.o |
23 | obj-$(CONFIG_USB_DWC2) += dwc2_pci.o | 23 | dwc2_pci-y := pci.o |
24 | dwc2_pci-y := pci.o | ||
25 | endif | ||
26 | 24 | ||
27 | obj-$(CONFIG_USB_DWC2_PLATFORM) += dwc2_platform.o | 25 | obj-$(CONFIG_USB_DWC2_PLATFORM) += dwc2_platform.o |
28 | dwc2_platform-y := platform.o | 26 | dwc2_platform-y := platform.o |
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index f74304b12652..836c012c7707 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h | |||
@@ -593,6 +593,8 @@ struct dwc2_hsotg { | |||
593 | struct dwc2_core_params *core_params; | 593 | struct dwc2_core_params *core_params; |
594 | enum usb_otg_state op_state; | 594 | enum usb_otg_state op_state; |
595 | enum usb_dr_mode dr_mode; | 595 | enum usb_dr_mode dr_mode; |
596 | unsigned int hcd_enabled:1; | ||
597 | unsigned int gadget_enabled:1; | ||
596 | 598 | ||
597 | struct phy *phy; | 599 | struct phy *phy; |
598 | struct usb_phy *uphy; | 600 | struct usb_phy *uphy; |
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index c78c8740db1d..559b55e5debb 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c | |||
@@ -257,6 +257,14 @@ static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg) | |||
257 | */ | 257 | */ |
258 | channel->qh = NULL; | 258 | channel->qh = NULL; |
259 | } | 259 | } |
260 | /* All channels have been freed, mark them available */ | ||
261 | if (hsotg->core_params->uframe_sched > 0) { | ||
262 | hsotg->available_host_channels = | ||
263 | hsotg->core_params->host_channels; | ||
264 | } else { | ||
265 | hsotg->non_periodic_channels = 0; | ||
266 | hsotg->periodic_channels = 0; | ||
267 | } | ||
260 | } | 268 | } |
261 | 269 | ||
262 | /** | 270 | /** |
diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c index a4e724b0a62e..ae419615a176 100644 --- a/drivers/usb/dwc2/pci.c +++ b/drivers/usb/dwc2/pci.c | |||
@@ -50,113 +50,97 @@ | |||
50 | 50 | ||
51 | #include <linux/usb/hcd.h> | 51 | #include <linux/usb/hcd.h> |
52 | #include <linux/usb/ch11.h> | 52 | #include <linux/usb/ch11.h> |
53 | #include <linux/platform_device.h> | ||
54 | #include <linux/usb/usb_phy_generic.h> | ||
53 | 55 | ||
54 | #include "core.h" | ||
55 | #include "hcd.h" | ||
56 | |||
57 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 | ||
58 | #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 | 56 | #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 |
59 | 57 | ||
60 | static const char dwc2_driver_name[] = "dwc2"; | 58 | static const char dwc2_driver_name[] = "dwc2-pci"; |
61 | 59 | ||
62 | static const struct dwc2_core_params dwc2_module_params = { | 60 | struct dwc2_pci_glue { |
63 | .otg_cap = -1, | 61 | struct platform_device *dwc2; |
64 | .otg_ver = -1, | 62 | struct platform_device *phy; |
65 | .dma_enable = -1, | ||
66 | .dma_desc_enable = 0, | ||
67 | .speed = -1, | ||
68 | .enable_dynamic_fifo = -1, | ||
69 | .en_multiple_tx_fifo = -1, | ||
70 | .host_rx_fifo_size = 1024, | ||
71 | .host_nperio_tx_fifo_size = 256, | ||
72 | .host_perio_tx_fifo_size = 1024, | ||
73 | .max_transfer_size = 65535, | ||
74 | .max_packet_count = 511, | ||
75 | .host_channels = -1, | ||
76 | .phy_type = -1, | ||
77 | .phy_utmi_width = -1, | ||
78 | .phy_ulpi_ddr = -1, | ||
79 | .phy_ulpi_ext_vbus = -1, | ||
80 | .i2c_enable = -1, | ||
81 | .ulpi_fs_ls = -1, | ||
82 | .host_support_fs_ls_low_power = -1, | ||
83 | .host_ls_low_power_phy_clk = -1, | ||
84 | .ts_dline = -1, | ||
85 | .reload_ctl = -1, | ||
86 | .ahbcfg = -1, | ||
87 | .uframe_sched = -1, | ||
88 | }; | 63 | }; |
89 | 64 | ||
90 | /** | 65 | static void dwc2_pci_remove(struct pci_dev *pci) |
91 | * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the | ||
92 | * DWC_otg driver | ||
93 | * | ||
94 | * @dev: Bus device | ||
95 | * | ||
96 | * This routine is called, for example, when the rmmod command is executed. The | ||
97 | * device may or may not be electrically present. If it is present, the driver | ||
98 | * stops device processing. Any resources used on behalf of this device are | ||
99 | * freed. | ||
100 | */ | ||
101 | static void dwc2_driver_remove(struct pci_dev *dev) | ||
102 | { | 66 | { |
103 | struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); | 67 | struct dwc2_pci_glue *glue = pci_get_drvdata(pci); |
104 | 68 | ||
105 | dwc2_hcd_remove(hsotg); | 69 | platform_device_unregister(glue->dwc2); |
106 | pci_disable_device(dev); | 70 | usb_phy_generic_unregister(glue->phy); |
71 | kfree(glue); | ||
72 | pci_set_drvdata(pci, NULL); | ||
107 | } | 73 | } |
108 | 74 | ||
109 | /** | 75 | static int dwc2_pci_probe(struct pci_dev *pci, |
110 | * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg | 76 | const struct pci_device_id *id) |
111 | * driver | ||
112 | * | ||
113 | * @dev: Bus device | ||
114 | * | ||
115 | * This routine creates the driver components required to control the device | ||
116 | * (core, HCD, and PCD) and initializes the device. The driver components are | ||
117 | * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved | ||
118 | * in the device private data. This allows the driver to access the dwc2_hsotg | ||
119 | * structure on subsequent calls to driver methods for this device. | ||
120 | */ | ||
121 | static int dwc2_driver_probe(struct pci_dev *dev, | ||
122 | const struct pci_device_id *id) | ||
123 | { | 77 | { |
124 | struct dwc2_hsotg *hsotg; | 78 | struct resource res[2]; |
125 | int retval; | 79 | struct platform_device *dwc2; |
80 | struct platform_device *phy; | ||
81 | int ret; | ||
82 | struct device *dev = &pci->dev; | ||
83 | struct dwc2_pci_glue *glue; | ||
84 | |||
85 | ret = pcim_enable_device(pci); | ||
86 | if (ret) { | ||
87 | dev_err(dev, "failed to enable pci device\n"); | ||
88 | return -ENODEV; | ||
89 | } | ||
90 | |||
91 | pci_set_master(pci); | ||
126 | 92 | ||
127 | hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); | 93 | dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO); |
128 | if (!hsotg) | 94 | if (!dwc2) { |
95 | dev_err(dev, "couldn't allocate dwc2 device\n"); | ||
129 | return -ENOMEM; | 96 | return -ENOMEM; |
97 | } | ||
130 | 98 | ||
131 | hsotg->dev = &dev->dev; | 99 | memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); |
132 | hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); | ||
133 | if (IS_ERR(hsotg->regs)) | ||
134 | return PTR_ERR(hsotg->regs); | ||
135 | 100 | ||
136 | dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", | 101 | res[0].start = pci_resource_start(pci, 0); |
137 | (unsigned long)pci_resource_start(dev, 0), hsotg->regs); | 102 | res[0].end = pci_resource_end(pci, 0); |
103 | res[0].name = "dwc2"; | ||
104 | res[0].flags = IORESOURCE_MEM; | ||
138 | 105 | ||
139 | if (pci_enable_device(dev) < 0) | 106 | res[1].start = pci->irq; |
140 | return -ENODEV; | 107 | res[1].name = "dwc2"; |
108 | res[1].flags = IORESOURCE_IRQ; | ||
141 | 109 | ||
142 | pci_set_master(dev); | 110 | ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res)); |
111 | if (ret) { | ||
112 | dev_err(dev, "couldn't add resources to dwc2 device\n"); | ||
113 | return ret; | ||
114 | } | ||
143 | 115 | ||
144 | retval = devm_request_irq(hsotg->dev, dev->irq, | 116 | dwc2->dev.parent = dev; |
145 | dwc2_handle_common_intr, IRQF_SHARED, | ||
146 | dev_name(hsotg->dev), hsotg); | ||
147 | if (retval) | ||
148 | return retval; | ||
149 | 117 | ||
150 | spin_lock_init(&hsotg->lock); | 118 | phy = usb_phy_generic_register(); |
151 | retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); | 119 | if (IS_ERR(phy)) { |
152 | if (retval) { | 120 | dev_err(dev, "error registering generic PHY (%ld)\n", |
153 | pci_disable_device(dev); | 121 | PTR_ERR(phy)); |
154 | return retval; | 122 | return PTR_ERR(phy); |
155 | } | 123 | } |
156 | 124 | ||
157 | pci_set_drvdata(dev, hsotg); | 125 | ret = platform_device_add(dwc2); |
126 | if (ret) { | ||
127 | dev_err(dev, "failed to register dwc2 device\n"); | ||
128 | goto err; | ||
129 | } | ||
130 | |||
131 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | ||
132 | if (!glue) | ||
133 | return -ENOMEM; | ||
134 | |||
135 | glue->phy = phy; | ||
136 | glue->dwc2 = dwc2; | ||
137 | pci_set_drvdata(pci, glue); | ||
158 | 138 | ||
159 | return retval; | 139 | return 0; |
140 | err: | ||
141 | usb_phy_generic_unregister(phy); | ||
142 | platform_device_put(dwc2); | ||
143 | return ret; | ||
160 | } | 144 | } |
161 | 145 | ||
162 | static const struct pci_device_id dwc2_pci_ids[] = { | 146 | static const struct pci_device_id dwc2_pci_ids[] = { |
@@ -174,8 +158,8 @@ MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); | |||
174 | static struct pci_driver dwc2_pci_driver = { | 158 | static struct pci_driver dwc2_pci_driver = { |
175 | .name = dwc2_driver_name, | 159 | .name = dwc2_driver_name, |
176 | .id_table = dwc2_pci_ids, | 160 | .id_table = dwc2_pci_ids, |
177 | .probe = dwc2_driver_probe, | 161 | .probe = dwc2_pci_probe, |
178 | .remove = dwc2_driver_remove, | 162 | .remove = dwc2_pci_remove, |
179 | }; | 163 | }; |
180 | 164 | ||
181 | module_pci_driver(dwc2_pci_driver); | 165 | module_pci_driver(dwc2_pci_driver); |
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index ae095f009b4f..185663e0b5f4 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c | |||
@@ -121,8 +121,10 @@ static int dwc2_driver_remove(struct platform_device *dev) | |||
121 | { | 121 | { |
122 | struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); | 122 | struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); |
123 | 123 | ||
124 | dwc2_hcd_remove(hsotg); | 124 | if (hsotg->hcd_enabled) |
125 | s3c_hsotg_remove(hsotg); | 125 | dwc2_hcd_remove(hsotg); |
126 | if (hsotg->gadget_enabled) | ||
127 | s3c_hsotg_remove(hsotg); | ||
126 | 128 | ||
127 | return 0; | 129 | return 0; |
128 | } | 130 | } |
@@ -234,12 +236,23 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
234 | 236 | ||
235 | spin_lock_init(&hsotg->lock); | 237 | spin_lock_init(&hsotg->lock); |
236 | mutex_init(&hsotg->init_mutex); | 238 | mutex_init(&hsotg->init_mutex); |
237 | retval = dwc2_gadget_init(hsotg, irq); | 239 | |
238 | if (retval) | 240 | if (hsotg->dr_mode != USB_DR_MODE_HOST) { |
239 | return retval; | 241 | retval = dwc2_gadget_init(hsotg, irq); |
240 | retval = dwc2_hcd_init(hsotg, irq, params); | 242 | if (retval) |
241 | if (retval) | 243 | return retval; |
242 | return retval; | 244 | hsotg->gadget_enabled = 1; |
245 | } | ||
246 | |||
247 | if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { | ||
248 | retval = dwc2_hcd_init(hsotg, irq, params); | ||
249 | if (retval) { | ||
250 | if (hsotg->gadget_enabled) | ||
251 | s3c_hsotg_remove(hsotg); | ||
252 | return retval; | ||
253 | } | ||
254 | hsotg->hcd_enabled = 1; | ||
255 | } | ||
243 | 256 | ||
244 | platform_set_drvdata(dev, hsotg); | 257 | platform_set_drvdata(dev, hsotg); |
245 | 258 | ||
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index edbf9c85af7e..827c4f80379f 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig | |||
@@ -104,11 +104,4 @@ config USB_DWC3_DEBUG | |||
104 | help | 104 | help |
105 | Say Y here to enable debugging messages on DWC3 Driver. | 105 | Say Y here to enable debugging messages on DWC3 Driver. |
106 | 106 | ||
107 | config DWC3_HOST_USB3_LPM_ENABLE | ||
108 | bool "Enable USB3 LPM Capability" | ||
109 | depends on USB_DWC3_HOST=y || USB_DWC3_DUAL_ROLE=y | ||
110 | default n | ||
111 | help | ||
112 | Select this when you want to enable USB3 LPM with dwc3 xhci host. | ||
113 | |||
114 | endif | 107 | endif |
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 9f0e209b8f6c..2bbab3d86fff 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -774,17 +774,13 @@ static int dwc3_probe(struct platform_device *pdev) | |||
774 | * since it will be requested by the xhci-plat driver. | 774 | * since it will be requested by the xhci-plat driver. |
775 | */ | 775 | */ |
776 | regs = devm_ioremap_resource(dev, res); | 776 | regs = devm_ioremap_resource(dev, res); |
777 | if (IS_ERR(regs)) | 777 | if (IS_ERR(regs)) { |
778 | return PTR_ERR(regs); | 778 | ret = PTR_ERR(regs); |
779 | goto err0; | ||
780 | } | ||
779 | 781 | ||
780 | dwc->regs = regs; | 782 | dwc->regs = regs; |
781 | dwc->regs_size = resource_size(res); | 783 | dwc->regs_size = resource_size(res); |
782 | /* | ||
783 | * restore res->start back to its original value so that, | ||
784 | * in case the probe is deferred, we don't end up getting error in | ||
785 | * request the memory region the next time probe is called. | ||
786 | */ | ||
787 | res->start -= DWC3_GLOBALS_REGS_START; | ||
788 | 784 | ||
789 | /* default to highest possible threshold */ | 785 | /* default to highest possible threshold */ |
790 | lpm_nyet_threshold = 0xff; | 786 | lpm_nyet_threshold = 0xff; |
@@ -808,6 +804,8 @@ static int dwc3_probe(struct platform_device *pdev) | |||
808 | "snps,is-utmi-l1-suspend"); | 804 | "snps,is-utmi-l1-suspend"); |
809 | of_property_read_u8(node, "snps,hird-threshold", | 805 | of_property_read_u8(node, "snps,hird-threshold", |
810 | &hird_threshold); | 806 | &hird_threshold); |
807 | dwc->usb3_lpm_capable = of_property_read_bool(node, | ||
808 | "snps,usb3_lpm_capable"); | ||
811 | 809 | ||
812 | dwc->needs_fifo_resize = of_property_read_bool(node, | 810 | dwc->needs_fifo_resize = of_property_read_bool(node, |
813 | "tx-fifo-resize"); | 811 | "tx-fifo-resize"); |
@@ -848,6 +846,7 @@ static int dwc3_probe(struct platform_device *pdev) | |||
848 | hird_threshold = pdata->hird_threshold; | 846 | hird_threshold = pdata->hird_threshold; |
849 | 847 | ||
850 | dwc->needs_fifo_resize = pdata->tx_fifo_resize; | 848 | dwc->needs_fifo_resize = pdata->tx_fifo_resize; |
849 | dwc->usb3_lpm_capable = pdata->usb3_lpm_capable; | ||
851 | dwc->dr_mode = pdata->dr_mode; | 850 | dwc->dr_mode = pdata->dr_mode; |
852 | 851 | ||
853 | dwc->disable_scramble_quirk = pdata->disable_scramble_quirk; | 852 | dwc->disable_scramble_quirk = pdata->disable_scramble_quirk; |
@@ -878,7 +877,7 @@ static int dwc3_probe(struct platform_device *pdev) | |||
878 | 877 | ||
879 | ret = dwc3_core_get_phy(dwc); | 878 | ret = dwc3_core_get_phy(dwc); |
880 | if (ret) | 879 | if (ret) |
881 | return ret; | 880 | goto err0; |
882 | 881 | ||
883 | spin_lock_init(&dwc->lock); | 882 | spin_lock_init(&dwc->lock); |
884 | platform_set_drvdata(pdev, dwc); | 883 | platform_set_drvdata(pdev, dwc); |
@@ -899,7 +898,7 @@ static int dwc3_probe(struct platform_device *pdev) | |||
899 | if (ret) { | 898 | if (ret) { |
900 | dev_err(dwc->dev, "failed to allocate event buffers\n"); | 899 | dev_err(dwc->dev, "failed to allocate event buffers\n"); |
901 | ret = -ENOMEM; | 900 | ret = -ENOMEM; |
902 | goto err0; | 901 | goto err1; |
903 | } | 902 | } |
904 | 903 | ||
905 | if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) | 904 | if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) |
@@ -913,65 +912,81 @@ static int dwc3_probe(struct platform_device *pdev) | |||
913 | ret = dwc3_core_init(dwc); | 912 | ret = dwc3_core_init(dwc); |
914 | if (ret) { | 913 | if (ret) { |
915 | dev_err(dev, "failed to initialize core\n"); | 914 | dev_err(dev, "failed to initialize core\n"); |
916 | goto err0; | 915 | goto err1; |
917 | } | 916 | } |
918 | 917 | ||
919 | usb_phy_set_suspend(dwc->usb2_phy, 0); | 918 | usb_phy_set_suspend(dwc->usb2_phy, 0); |
920 | usb_phy_set_suspend(dwc->usb3_phy, 0); | 919 | usb_phy_set_suspend(dwc->usb3_phy, 0); |
921 | ret = phy_power_on(dwc->usb2_generic_phy); | 920 | ret = phy_power_on(dwc->usb2_generic_phy); |
922 | if (ret < 0) | 921 | if (ret < 0) |
923 | goto err1; | 922 | goto err2; |
924 | 923 | ||
925 | ret = phy_power_on(dwc->usb3_generic_phy); | 924 | ret = phy_power_on(dwc->usb3_generic_phy); |
926 | if (ret < 0) | 925 | if (ret < 0) |
927 | goto err_usb2phy_power; | 926 | goto err3; |
928 | 927 | ||
929 | ret = dwc3_event_buffers_setup(dwc); | 928 | ret = dwc3_event_buffers_setup(dwc); |
930 | if (ret) { | 929 | if (ret) { |
931 | dev_err(dwc->dev, "failed to setup event buffers\n"); | 930 | dev_err(dwc->dev, "failed to setup event buffers\n"); |
932 | goto err_usb3phy_power; | 931 | goto err4; |
933 | } | 932 | } |
934 | 933 | ||
935 | ret = dwc3_core_init_mode(dwc); | 934 | ret = dwc3_core_init_mode(dwc); |
936 | if (ret) | 935 | if (ret) |
937 | goto err2; | 936 | goto err5; |
938 | 937 | ||
939 | ret = dwc3_debugfs_init(dwc); | 938 | ret = dwc3_debugfs_init(dwc); |
940 | if (ret) { | 939 | if (ret) { |
941 | dev_err(dev, "failed to initialize debugfs\n"); | 940 | dev_err(dev, "failed to initialize debugfs\n"); |
942 | goto err3; | 941 | goto err6; |
943 | } | 942 | } |
944 | 943 | ||
945 | pm_runtime_allow(dev); | 944 | pm_runtime_allow(dev); |
946 | 945 | ||
947 | return 0; | 946 | return 0; |
948 | 947 | ||
949 | err3: | 948 | err6: |
950 | dwc3_core_exit_mode(dwc); | 949 | dwc3_core_exit_mode(dwc); |
951 | 950 | ||
952 | err2: | 951 | err5: |
953 | dwc3_event_buffers_cleanup(dwc); | 952 | dwc3_event_buffers_cleanup(dwc); |
954 | 953 | ||
955 | err_usb3phy_power: | 954 | err4: |
956 | phy_power_off(dwc->usb3_generic_phy); | 955 | phy_power_off(dwc->usb3_generic_phy); |
957 | 956 | ||
958 | err_usb2phy_power: | 957 | err3: |
959 | phy_power_off(dwc->usb2_generic_phy); | 958 | phy_power_off(dwc->usb2_generic_phy); |
960 | 959 | ||
961 | err1: | 960 | err2: |
962 | usb_phy_set_suspend(dwc->usb2_phy, 1); | 961 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
963 | usb_phy_set_suspend(dwc->usb3_phy, 1); | 962 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
964 | dwc3_core_exit(dwc); | 963 | dwc3_core_exit(dwc); |
965 | 964 | ||
966 | err0: | 965 | err1: |
967 | dwc3_free_event_buffers(dwc); | 966 | dwc3_free_event_buffers(dwc); |
968 | 967 | ||
968 | err0: | ||
969 | /* | ||
970 | * restore res->start back to its original value so that, in case the | ||
971 | * probe is deferred, we don't end up getting error in request the | ||
972 | * memory region the next time probe is called. | ||
973 | */ | ||
974 | res->start -= DWC3_GLOBALS_REGS_START; | ||
975 | |||
969 | return ret; | 976 | return ret; |
970 | } | 977 | } |
971 | 978 | ||
972 | static int dwc3_remove(struct platform_device *pdev) | 979 | static int dwc3_remove(struct platform_device *pdev) |
973 | { | 980 | { |
974 | struct dwc3 *dwc = platform_get_drvdata(pdev); | 981 | struct dwc3 *dwc = platform_get_drvdata(pdev); |
982 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
983 | |||
984 | /* | ||
985 | * restore res->start back to its original value so that, in case the | ||
986 | * probe is deferred, we don't end up getting error in request the | ||
987 | * memory region the next time probe is called. | ||
988 | */ | ||
989 | res->start -= DWC3_GLOBALS_REGS_START; | ||
975 | 990 | ||
976 | dwc3_debugfs_exit(dwc); | 991 | dwc3_debugfs_exit(dwc); |
977 | dwc3_core_exit_mode(dwc); | 992 | dwc3_core_exit_mode(dwc); |
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index d201910b892f..fdab715a0631 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h | |||
@@ -689,6 +689,7 @@ struct dwc3_scratchpad_array { | |||
689 | * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround | 689 | * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround |
690 | * @start_config_issued: true when StartConfig command has been issued | 690 | * @start_config_issued: true when StartConfig command has been issued |
691 | * @three_stage_setup: set if we perform a three phase setup | 691 | * @three_stage_setup: set if we perform a three phase setup |
692 | * @usb3_lpm_capable: set if hadrware supports Link Power Management | ||
692 | * @disable_scramble_quirk: set if we enable the disable scramble quirk | 693 | * @disable_scramble_quirk: set if we enable the disable scramble quirk |
693 | * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk | 694 | * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk |
694 | * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk | 695 | * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk |
@@ -812,6 +813,7 @@ struct dwc3 { | |||
812 | unsigned setup_packet_pending:1; | 813 | unsigned setup_packet_pending:1; |
813 | unsigned start_config_issued:1; | 814 | unsigned start_config_issued:1; |
814 | unsigned three_stage_setup:1; | 815 | unsigned three_stage_setup:1; |
816 | unsigned usb3_lpm_capable:1; | ||
815 | 817 | ||
816 | unsigned disable_scramble_quirk:1; | 818 | unsigned disable_scramble_quirk:1; |
817 | unsigned u2exit_lfps_quirk:1; | 819 | unsigned u2exit_lfps_quirk:1; |
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 52e0c4e5e48e..edba5348be18 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -325,15 +325,6 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) | |||
325 | return IRQ_HANDLED; | 325 | return IRQ_HANDLED; |
326 | } | 326 | } |
327 | 327 | ||
328 | static int dwc3_omap_remove_core(struct device *dev, void *c) | ||
329 | { | ||
330 | struct platform_device *pdev = to_platform_device(dev); | ||
331 | |||
332 | of_device_unregister(pdev); | ||
333 | |||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) | 328 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) |
338 | { | 329 | { |
339 | u32 reg; | 330 | u32 reg; |
@@ -600,7 +591,7 @@ static int dwc3_omap_remove(struct platform_device *pdev) | |||
600 | if (omap->extcon_id_dev.edev) | 591 | if (omap->extcon_id_dev.edev) |
601 | extcon_unregister_interest(&omap->extcon_id_dev); | 592 | extcon_unregister_interest(&omap->extcon_id_dev); |
602 | dwc3_omap_disable_irqs(omap); | 593 | dwc3_omap_disable_irqs(omap); |
603 | device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); | 594 | of_platform_depopulate(omap->dev); |
604 | pm_runtime_put_sync(&pdev->dev); | 595 | pm_runtime_put_sync(&pdev->dev); |
605 | pm_runtime_disable(&pdev->dev); | 596 | pm_runtime_disable(&pdev->dev); |
606 | 597 | ||
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index 8d950569d557..b773fb53d6a7 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -24,8 +24,6 @@ | |||
24 | 24 | ||
25 | #include "platform_data.h" | 25 | #include "platform_data.h" |
26 | 26 | ||
27 | /* FIXME define these in <linux/pci_ids.h> */ | ||
28 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 | ||
29 | #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd | 27 | #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd |
30 | #define PCI_DEVICE_ID_INTEL_BYT 0x0f37 | 28 | #define PCI_DEVICE_ID_INTEL_BYT 0x0f37 |
31 | #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e | 29 | #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e |
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a03a485205c7..8946c32047e9 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -1855,32 +1855,27 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, | |||
1855 | unsigned int i; | 1855 | unsigned int i; |
1856 | int ret; | 1856 | int ret; |
1857 | 1857 | ||
1858 | req = next_request(&dep->req_queued); | ||
1859 | if (!req) { | ||
1860 | WARN_ON_ONCE(1); | ||
1861 | return 1; | ||
1862 | } | ||
1863 | i = 0; | ||
1858 | do { | 1864 | do { |
1859 | req = next_request(&dep->req_queued); | 1865 | slot = req->start_slot + i; |
1860 | if (!req) { | 1866 | if ((slot == DWC3_TRB_NUM - 1) && |
1861 | WARN_ON_ONCE(1); | ||
1862 | return 1; | ||
1863 | } | ||
1864 | i = 0; | ||
1865 | do { | ||
1866 | slot = req->start_slot + i; | ||
1867 | if ((slot == DWC3_TRB_NUM - 1) && | ||
1868 | usb_endpoint_xfer_isoc(dep->endpoint.desc)) | 1867 | usb_endpoint_xfer_isoc(dep->endpoint.desc)) |
1869 | slot++; | 1868 | slot++; |
1870 | slot %= DWC3_TRB_NUM; | 1869 | slot %= DWC3_TRB_NUM; |
1871 | trb = &dep->trb_pool[slot]; | 1870 | trb = &dep->trb_pool[slot]; |
1872 | |||
1873 | ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, | ||
1874 | event, status); | ||
1875 | if (ret) | ||
1876 | break; | ||
1877 | }while (++i < req->request.num_mapped_sgs); | ||
1878 | |||
1879 | dwc3_gadget_giveback(dep, req, status); | ||
1880 | 1871 | ||
1872 | ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, | ||
1873 | event, status); | ||
1881 | if (ret) | 1874 | if (ret) |
1882 | break; | 1875 | break; |
1883 | } while (1); | 1876 | } while (++i < req->request.num_mapped_sgs); |
1877 | |||
1878 | dwc3_gadget_giveback(dep, req, status); | ||
1884 | 1879 | ||
1885 | if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && | 1880 | if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && |
1886 | list_empty(&dep->req_queued)) { | 1881 | list_empty(&dep->req_queued)) { |
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 12bfd3c5405e..c679f63783ae 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c | |||
@@ -49,9 +49,7 @@ int dwc3_host_init(struct dwc3 *dwc) | |||
49 | 49 | ||
50 | memset(&pdata, 0, sizeof(pdata)); | 50 | memset(&pdata, 0, sizeof(pdata)); |
51 | 51 | ||
52 | #ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE | 52 | pdata.usb3_lpm_capable = dwc->usb3_lpm_capable; |
53 | pdata.usb3_lpm_capable = 1; | ||
54 | #endif | ||
55 | 53 | ||
56 | ret = platform_device_add_data(xhci, &pdata, sizeof(pdata)); | 54 | ret = platform_device_add_data(xhci, &pdata, sizeof(pdata)); |
57 | if (ret) { | 55 | if (ret) { |
diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h index a3a3b6d5668c..a2bd464be828 100644 --- a/drivers/usb/dwc3/platform_data.h +++ b/drivers/usb/dwc3/platform_data.h | |||
@@ -24,6 +24,7 @@ struct dwc3_platform_data { | |||
24 | enum usb_device_speed maximum_speed; | 24 | enum usb_device_speed maximum_speed; |
25 | enum usb_dr_mode dr_mode; | 25 | enum usb_dr_mode dr_mode; |
26 | bool tx_fifo_resize; | 26 | bool tx_fifo_resize; |
27 | bool usb3_lpm_capable; | ||
27 | 28 | ||
28 | unsigned is_utmi_l1_suspend:1; | 29 | unsigned is_utmi_l1_suspend:1; |
29 | u8 hird_threshold; | 30 | u8 hird_threshold; |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index b454d05be583..bcf83c0a6e62 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -196,6 +196,9 @@ config USB_F_MIDI | |||
196 | config USB_F_HID | 196 | config USB_F_HID |
197 | tristate | 197 | tristate |
198 | 198 | ||
199 | config USB_F_PRINTER | ||
200 | tristate | ||
201 | |||
199 | choice | 202 | choice |
200 | tristate "USB Gadget Drivers" | 203 | tristate "USB Gadget Drivers" |
201 | default USB_ETH | 204 | default USB_ETH |
@@ -434,6 +437,20 @@ config USB_CONFIGFS_F_UVC | |||
434 | device. It provides a userspace API to process UVC control requests | 437 | device. It provides a userspace API to process UVC control requests |
435 | and stream video data to the host. | 438 | and stream video data to the host. |
436 | 439 | ||
440 | config USB_CONFIGFS_F_PRINTER | ||
441 | bool "Printer function" | ||
442 | select USB_F_PRINTER | ||
443 | depends on USB_CONFIGFS | ||
444 | help | ||
445 | The Printer function channels data between the USB host and a | ||
446 | userspace program driving the print engine. The user space | ||
447 | program reads and writes the device file /dev/g_printer<X> to | ||
448 | receive or send printer data. It can use ioctl calls to | ||
449 | the device file to get or set printer status. | ||
450 | |||
451 | For more information, see Documentation/usb/gadget_printer.txt | ||
452 | which includes sample code for accessing the device file. | ||
453 | |||
437 | source "drivers/usb/gadget/legacy/Kconfig" | 454 | source "drivers/usb/gadget/legacy/Kconfig" |
438 | 455 | ||
439 | endchoice | 456 | endchoice |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 13adfd1a3f54..4e3447bbd097 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -1161,11 +1161,11 @@ static struct usb_gadget_string_container *copy_gadget_strings( | |||
1161 | * This function will create a deep copy of usb_gadget_strings and usb_string | 1161 | * This function will create a deep copy of usb_gadget_strings and usb_string |
1162 | * and attach it to the cdev. The actual string (usb_string.s) will not be | 1162 | * and attach it to the cdev. The actual string (usb_string.s) will not be |
1163 | * copied but only a referenced will be made. The struct usb_gadget_strings | 1163 | * copied but only a referenced will be made. The struct usb_gadget_strings |
1164 | * array may contain multiple languges and should be NULL terminated. | 1164 | * array may contain multiple languages and should be NULL terminated. |
1165 | * The ->language pointer of each struct usb_gadget_strings has to contain the | 1165 | * The ->language pointer of each struct usb_gadget_strings has to contain the |
1166 | * same amount of entries. | 1166 | * same amount of entries. |
1167 | * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first | 1167 | * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first |
1168 | * usb_string entry of es-ES containts the translation of the first usb_string | 1168 | * usb_string entry of es-ES contains the translation of the first usb_string |
1169 | * entry of en-US. Therefore both entries become the same id assign. | 1169 | * entry of en-US. Therefore both entries become the same id assign. |
1170 | */ | 1170 | */ |
1171 | struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, | 1171 | struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, |
@@ -1472,6 +1472,13 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1472 | req->length = 0; | 1472 | req->length = 0; |
1473 | gadget->ep0->driver_data = cdev; | 1473 | gadget->ep0->driver_data = cdev; |
1474 | 1474 | ||
1475 | /* | ||
1476 | * Don't let non-standard requests match any of the cases below | ||
1477 | * by accident. | ||
1478 | */ | ||
1479 | if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) | ||
1480 | goto unknown; | ||
1481 | |||
1475 | switch (ctrl->bRequest) { | 1482 | switch (ctrl->bRequest) { |
1476 | 1483 | ||
1477 | /* we handle all standard USB descriptors */ | 1484 | /* we handle all standard USB descriptors */ |
@@ -1751,6 +1758,10 @@ unknown: | |||
1751 | * take such requests too, if that's ever needed: to work | 1758 | * take such requests too, if that's ever needed: to work |
1752 | * in config 0, etc. | 1759 | * in config 0, etc. |
1753 | */ | 1760 | */ |
1761 | list_for_each_entry(f, &cdev->config->functions, list) | ||
1762 | if (f->req_match && f->req_match(f, ctrl)) | ||
1763 | goto try_fun_setup; | ||
1764 | f = NULL; | ||
1754 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | 1765 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
1755 | case USB_RECIP_INTERFACE: | 1766 | case USB_RECIP_INTERFACE: |
1756 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) | 1767 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) |
@@ -1768,7 +1779,7 @@ unknown: | |||
1768 | f = NULL; | 1779 | f = NULL; |
1769 | break; | 1780 | break; |
1770 | } | 1781 | } |
1771 | 1782 | try_fun_setup: | |
1772 | if (f && f->setup) | 1783 | if (f && f->setup) |
1773 | value = f->setup(f, ctrl); | 1784 | value = f->setup(f, ctrl); |
1774 | else { | 1785 | else { |
diff --git a/drivers/usb/gadget/function/Makefile b/drivers/usb/gadget/function/Makefile index f71b1aaa0edf..bd7def576955 100644 --- a/drivers/usb/gadget/function/Makefile +++ b/drivers/usb/gadget/function/Makefile | |||
@@ -42,3 +42,5 @@ usb_f_midi-y := f_midi.o | |||
42 | obj-$(CONFIG_USB_F_MIDI) += usb_f_midi.o | 42 | obj-$(CONFIG_USB_F_MIDI) += usb_f_midi.o |
43 | usb_f_hid-y := f_hid.o | 43 | usb_f_hid-y := f_hid.o |
44 | obj-$(CONFIG_USB_F_HID) += usb_f_hid.o | 44 | obj-$(CONFIG_USB_F_HID) += usb_f_hid.o |
45 | usb_f_printer-y := f_printer.o | ||
46 | obj-$(CONFIG_USB_F_PRINTER) += usb_f_printer.o | ||
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index a2612fb79eff..13dfc9915b1d 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c | |||
@@ -908,7 +908,6 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) | |||
908 | 908 | ||
909 | /* disable/free request and end point */ | 909 | /* disable/free request and end point */ |
910 | usb_ep_disable(hidg->in_ep); | 910 | usb_ep_disable(hidg->in_ep); |
911 | usb_ep_dequeue(hidg->in_ep, hidg->req); | ||
912 | kfree(hidg->req->buf); | 911 | kfree(hidg->req->buf); |
913 | usb_ep_free_request(hidg->in_ep, hidg->req); | 912 | usb_ep_free_request(hidg->in_ep, hidg->req); |
914 | 913 | ||
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 49a2f19c2b87..3cc109f3c9c8 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c | |||
@@ -1085,7 +1085,7 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1085 | if (!curlun) { /* Unsupported LUNs are okay */ | 1085 | if (!curlun) { /* Unsupported LUNs are okay */ |
1086 | common->bad_lun_okay = 1; | 1086 | common->bad_lun_okay = 1; |
1087 | memset(buf, 0, 36); | 1087 | memset(buf, 0, 36); |
1088 | buf[0] = 0x7f; /* Unsupported, no device-type */ | 1088 | buf[0] = TYPE_NO_LUN; /* Unsupported, no device-type */ |
1089 | buf[4] = 31; /* Additional length */ | 1089 | buf[4] = 31; /* Additional length */ |
1090 | return 36; | 1090 | return 36; |
1091 | } | 1091 | } |
diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c new file mode 100644 index 000000000000..44173df27273 --- /dev/null +++ b/drivers/usb/gadget/function/f_printer.c | |||
@@ -0,0 +1,1471 @@ | |||
1 | /* | ||
2 | * f_printer.c - USB printer function driver | ||
3 | * | ||
4 | * Copied from drivers/usb/gadget/legacy/printer.c, | ||
5 | * which was: | ||
6 | * | ||
7 | * printer.c -- Printer gadget driver | ||
8 | * | ||
9 | * Copyright (C) 2003-2005 David Brownell | ||
10 | * Copyright (C) 2006 Craig W. Nadler | ||
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 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/ioport.h> | ||
22 | #include <linux/sched.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/mutex.h> | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/idr.h> | ||
28 | #include <linux/timer.h> | ||
29 | #include <linux/list.h> | ||
30 | #include <linux/interrupt.h> | ||
31 | #include <linux/device.h> | ||
32 | #include <linux/moduleparam.h> | ||
33 | #include <linux/fs.h> | ||
34 | #include <linux/poll.h> | ||
35 | #include <linux/types.h> | ||
36 | #include <linux/ctype.h> | ||
37 | #include <linux/cdev.h> | ||
38 | |||
39 | #include <asm/byteorder.h> | ||
40 | #include <linux/io.h> | ||
41 | #include <linux/irq.h> | ||
42 | #include <linux/uaccess.h> | ||
43 | #include <asm/unaligned.h> | ||
44 | |||
45 | #include <linux/usb/ch9.h> | ||
46 | #include <linux/usb/composite.h> | ||
47 | #include <linux/usb/gadget.h> | ||
48 | #include <linux/usb/g_printer.h> | ||
49 | |||
50 | #include "u_printer.h" | ||
51 | |||
52 | #define PNP_STRING_LEN 1024 | ||
53 | #define PRINTER_MINORS 4 | ||
54 | #define GET_DEVICE_ID 0 | ||
55 | #define GET_PORT_STATUS 1 | ||
56 | #define SOFT_RESET 2 | ||
57 | |||
58 | static int major, minors; | ||
59 | static struct class *usb_gadget_class; | ||
60 | static DEFINE_IDA(printer_ida); | ||
61 | static DEFINE_MUTEX(printer_ida_lock); /* protects access do printer_ida */ | ||
62 | |||
63 | /*-------------------------------------------------------------------------*/ | ||
64 | |||
65 | struct printer_dev { | ||
66 | spinlock_t lock; /* lock this structure */ | ||
67 | /* lock buffer lists during read/write calls */ | ||
68 | struct mutex lock_printer_io; | ||
69 | struct usb_gadget *gadget; | ||
70 | s8 interface; | ||
71 | struct usb_ep *in_ep, *out_ep; | ||
72 | |||
73 | struct list_head rx_reqs; /* List of free RX structs */ | ||
74 | struct list_head rx_reqs_active; /* List of Active RX xfers */ | ||
75 | struct list_head rx_buffers; /* List of completed xfers */ | ||
76 | /* wait until there is data to be read. */ | ||
77 | wait_queue_head_t rx_wait; | ||
78 | struct list_head tx_reqs; /* List of free TX structs */ | ||
79 | struct list_head tx_reqs_active; /* List of Active TX xfers */ | ||
80 | /* Wait until there are write buffers available to use. */ | ||
81 | wait_queue_head_t tx_wait; | ||
82 | /* Wait until all write buffers have been sent. */ | ||
83 | wait_queue_head_t tx_flush_wait; | ||
84 | struct usb_request *current_rx_req; | ||
85 | size_t current_rx_bytes; | ||
86 | u8 *current_rx_buf; | ||
87 | u8 printer_status; | ||
88 | u8 reset_printer; | ||
89 | int minor; | ||
90 | struct cdev printer_cdev; | ||
91 | u8 printer_cdev_open; | ||
92 | wait_queue_head_t wait; | ||
93 | unsigned q_len; | ||
94 | char *pnp_string; /* We don't own memory! */ | ||
95 | struct usb_function function; | ||
96 | }; | ||
97 | |||
98 | static inline struct printer_dev *func_to_printer(struct usb_function *f) | ||
99 | { | ||
100 | return container_of(f, struct printer_dev, function); | ||
101 | } | ||
102 | |||
103 | /*-------------------------------------------------------------------------*/ | ||
104 | |||
105 | /* | ||
106 | * DESCRIPTORS ... most are static, but strings and (full) configuration | ||
107 | * descriptors are built on demand. | ||
108 | */ | ||
109 | |||
110 | /* holds our biggest descriptor */ | ||
111 | #define USB_DESC_BUFSIZE 256 | ||
112 | #define USB_BUFSIZE 8192 | ||
113 | |||
114 | static struct usb_interface_descriptor intf_desc = { | ||
115 | .bLength = sizeof(intf_desc), | ||
116 | .bDescriptorType = USB_DT_INTERFACE, | ||
117 | .bNumEndpoints = 2, | ||
118 | .bInterfaceClass = USB_CLASS_PRINTER, | ||
119 | .bInterfaceSubClass = 1, /* Printer Sub-Class */ | ||
120 | .bInterfaceProtocol = 2, /* Bi-Directional */ | ||
121 | .iInterface = 0 | ||
122 | }; | ||
123 | |||
124 | static struct usb_endpoint_descriptor fs_ep_in_desc = { | ||
125 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
126 | .bDescriptorType = USB_DT_ENDPOINT, | ||
127 | .bEndpointAddress = USB_DIR_IN, | ||
128 | .bmAttributes = USB_ENDPOINT_XFER_BULK | ||
129 | }; | ||
130 | |||
131 | static struct usb_endpoint_descriptor fs_ep_out_desc = { | ||
132 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
133 | .bDescriptorType = USB_DT_ENDPOINT, | ||
134 | .bEndpointAddress = USB_DIR_OUT, | ||
135 | .bmAttributes = USB_ENDPOINT_XFER_BULK | ||
136 | }; | ||
137 | |||
138 | static struct usb_descriptor_header *fs_printer_function[] = { | ||
139 | (struct usb_descriptor_header *) &intf_desc, | ||
140 | (struct usb_descriptor_header *) &fs_ep_in_desc, | ||
141 | (struct usb_descriptor_header *) &fs_ep_out_desc, | ||
142 | NULL | ||
143 | }; | ||
144 | |||
145 | /* | ||
146 | * usb 2.0 devices need to expose both high speed and full speed | ||
147 | * descriptors, unless they only run at full speed. | ||
148 | */ | ||
149 | |||
150 | static struct usb_endpoint_descriptor hs_ep_in_desc = { | ||
151 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
152 | .bDescriptorType = USB_DT_ENDPOINT, | ||
153 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
154 | .wMaxPacketSize = cpu_to_le16(512) | ||
155 | }; | ||
156 | |||
157 | static struct usb_endpoint_descriptor hs_ep_out_desc = { | ||
158 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
159 | .bDescriptorType = USB_DT_ENDPOINT, | ||
160 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
161 | .wMaxPacketSize = cpu_to_le16(512) | ||
162 | }; | ||
163 | |||
164 | static struct usb_qualifier_descriptor dev_qualifier = { | ||
165 | .bLength = sizeof(dev_qualifier), | ||
166 | .bDescriptorType = USB_DT_DEVICE_QUALIFIER, | ||
167 | .bcdUSB = cpu_to_le16(0x0200), | ||
168 | .bDeviceClass = USB_CLASS_PRINTER, | ||
169 | .bNumConfigurations = 1 | ||
170 | }; | ||
171 | |||
172 | static struct usb_descriptor_header *hs_printer_function[] = { | ||
173 | (struct usb_descriptor_header *) &intf_desc, | ||
174 | (struct usb_descriptor_header *) &hs_ep_in_desc, | ||
175 | (struct usb_descriptor_header *) &hs_ep_out_desc, | ||
176 | NULL | ||
177 | }; | ||
178 | |||
179 | /* | ||
180 | * Added endpoint descriptors for 3.0 devices | ||
181 | */ | ||
182 | |||
183 | static struct usb_endpoint_descriptor ss_ep_in_desc = { | ||
184 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
185 | .bDescriptorType = USB_DT_ENDPOINT, | ||
186 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
187 | .wMaxPacketSize = cpu_to_le16(1024), | ||
188 | }; | ||
189 | |||
190 | static struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = { | ||
191 | .bLength = sizeof(ss_ep_in_comp_desc), | ||
192 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
193 | }; | ||
194 | |||
195 | static struct usb_endpoint_descriptor ss_ep_out_desc = { | ||
196 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
197 | .bDescriptorType = USB_DT_ENDPOINT, | ||
198 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
199 | .wMaxPacketSize = cpu_to_le16(1024), | ||
200 | }; | ||
201 | |||
202 | static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = { | ||
203 | .bLength = sizeof(ss_ep_out_comp_desc), | ||
204 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
205 | }; | ||
206 | |||
207 | static struct usb_descriptor_header *ss_printer_function[] = { | ||
208 | (struct usb_descriptor_header *) &intf_desc, | ||
209 | (struct usb_descriptor_header *) &ss_ep_in_desc, | ||
210 | (struct usb_descriptor_header *) &ss_ep_in_comp_desc, | ||
211 | (struct usb_descriptor_header *) &ss_ep_out_desc, | ||
212 | (struct usb_descriptor_header *) &ss_ep_out_comp_desc, | ||
213 | NULL | ||
214 | }; | ||
215 | |||
216 | /* maxpacket and other transfer characteristics vary by speed. */ | ||
217 | static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget, | ||
218 | struct usb_endpoint_descriptor *fs, | ||
219 | struct usb_endpoint_descriptor *hs, | ||
220 | struct usb_endpoint_descriptor *ss) | ||
221 | { | ||
222 | switch (gadget->speed) { | ||
223 | case USB_SPEED_SUPER: | ||
224 | return ss; | ||
225 | case USB_SPEED_HIGH: | ||
226 | return hs; | ||
227 | default: | ||
228 | return fs; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | /*-------------------------------------------------------------------------*/ | ||
233 | |||
234 | static struct usb_request * | ||
235 | printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags) | ||
236 | { | ||
237 | struct usb_request *req; | ||
238 | |||
239 | req = usb_ep_alloc_request(ep, gfp_flags); | ||
240 | |||
241 | if (req != NULL) { | ||
242 | req->length = len; | ||
243 | req->buf = kmalloc(len, gfp_flags); | ||
244 | if (req->buf == NULL) { | ||
245 | usb_ep_free_request(ep, req); | ||
246 | return NULL; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | return req; | ||
251 | } | ||
252 | |||
253 | static void | ||
254 | printer_req_free(struct usb_ep *ep, struct usb_request *req) | ||
255 | { | ||
256 | if (ep != NULL && req != NULL) { | ||
257 | kfree(req->buf); | ||
258 | usb_ep_free_request(ep, req); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /*-------------------------------------------------------------------------*/ | ||
263 | |||
264 | static void rx_complete(struct usb_ep *ep, struct usb_request *req) | ||
265 | { | ||
266 | struct printer_dev *dev = ep->driver_data; | ||
267 | int status = req->status; | ||
268 | unsigned long flags; | ||
269 | |||
270 | spin_lock_irqsave(&dev->lock, flags); | ||
271 | |||
272 | list_del_init(&req->list); /* Remode from Active List */ | ||
273 | |||
274 | switch (status) { | ||
275 | |||
276 | /* normal completion */ | ||
277 | case 0: | ||
278 | if (req->actual > 0) { | ||
279 | list_add_tail(&req->list, &dev->rx_buffers); | ||
280 | DBG(dev, "G_Printer : rx length %d\n", req->actual); | ||
281 | } else { | ||
282 | list_add(&req->list, &dev->rx_reqs); | ||
283 | } | ||
284 | break; | ||
285 | |||
286 | /* software-driven interface shutdown */ | ||
287 | case -ECONNRESET: /* unlink */ | ||
288 | case -ESHUTDOWN: /* disconnect etc */ | ||
289 | VDBG(dev, "rx shutdown, code %d\n", status); | ||
290 | list_add(&req->list, &dev->rx_reqs); | ||
291 | break; | ||
292 | |||
293 | /* for hardware automagic (such as pxa) */ | ||
294 | case -ECONNABORTED: /* endpoint reset */ | ||
295 | DBG(dev, "rx %s reset\n", ep->name); | ||
296 | list_add(&req->list, &dev->rx_reqs); | ||
297 | break; | ||
298 | |||
299 | /* data overrun */ | ||
300 | case -EOVERFLOW: | ||
301 | /* FALLTHROUGH */ | ||
302 | |||
303 | default: | ||
304 | DBG(dev, "rx status %d\n", status); | ||
305 | list_add(&req->list, &dev->rx_reqs); | ||
306 | break; | ||
307 | } | ||
308 | |||
309 | wake_up_interruptible(&dev->rx_wait); | ||
310 | spin_unlock_irqrestore(&dev->lock, flags); | ||
311 | } | ||
312 | |||
313 | static void tx_complete(struct usb_ep *ep, struct usb_request *req) | ||
314 | { | ||
315 | struct printer_dev *dev = ep->driver_data; | ||
316 | |||
317 | switch (req->status) { | ||
318 | default: | ||
319 | VDBG(dev, "tx err %d\n", req->status); | ||
320 | /* FALLTHROUGH */ | ||
321 | case -ECONNRESET: /* unlink */ | ||
322 | case -ESHUTDOWN: /* disconnect etc */ | ||
323 | break; | ||
324 | case 0: | ||
325 | break; | ||
326 | } | ||
327 | |||
328 | spin_lock(&dev->lock); | ||
329 | /* Take the request struct off the active list and put it on the | ||
330 | * free list. | ||
331 | */ | ||
332 | list_del_init(&req->list); | ||
333 | list_add(&req->list, &dev->tx_reqs); | ||
334 | wake_up_interruptible(&dev->tx_wait); | ||
335 | if (likely(list_empty(&dev->tx_reqs_active))) | ||
336 | wake_up_interruptible(&dev->tx_flush_wait); | ||
337 | |||
338 | spin_unlock(&dev->lock); | ||
339 | } | ||
340 | |||
341 | /*-------------------------------------------------------------------------*/ | ||
342 | |||
343 | static int | ||
344 | printer_open(struct inode *inode, struct file *fd) | ||
345 | { | ||
346 | struct printer_dev *dev; | ||
347 | unsigned long flags; | ||
348 | int ret = -EBUSY; | ||
349 | |||
350 | dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); | ||
351 | |||
352 | spin_lock_irqsave(&dev->lock, flags); | ||
353 | |||
354 | if (!dev->printer_cdev_open) { | ||
355 | dev->printer_cdev_open = 1; | ||
356 | fd->private_data = dev; | ||
357 | ret = 0; | ||
358 | /* Change the printer status to show that it's on-line. */ | ||
359 | dev->printer_status |= PRINTER_SELECTED; | ||
360 | } | ||
361 | |||
362 | spin_unlock_irqrestore(&dev->lock, flags); | ||
363 | |||
364 | DBG(dev, "printer_open returned %x\n", ret); | ||
365 | return ret; | ||
366 | } | ||
367 | |||
368 | static int | ||
369 | printer_close(struct inode *inode, struct file *fd) | ||
370 | { | ||
371 | struct printer_dev *dev = fd->private_data; | ||
372 | unsigned long flags; | ||
373 | |||
374 | spin_lock_irqsave(&dev->lock, flags); | ||
375 | dev->printer_cdev_open = 0; | ||
376 | fd->private_data = NULL; | ||
377 | /* Change printer status to show that the printer is off-line. */ | ||
378 | dev->printer_status &= ~PRINTER_SELECTED; | ||
379 | spin_unlock_irqrestore(&dev->lock, flags); | ||
380 | |||
381 | DBG(dev, "printer_close\n"); | ||
382 | |||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | /* This function must be called with interrupts turned off. */ | ||
387 | static void | ||
388 | setup_rx_reqs(struct printer_dev *dev) | ||
389 | { | ||
390 | struct usb_request *req; | ||
391 | |||
392 | while (likely(!list_empty(&dev->rx_reqs))) { | ||
393 | int error; | ||
394 | |||
395 | req = container_of(dev->rx_reqs.next, | ||
396 | struct usb_request, list); | ||
397 | list_del_init(&req->list); | ||
398 | |||
399 | /* The USB Host sends us whatever amount of data it wants to | ||
400 | * so we always set the length field to the full USB_BUFSIZE. | ||
401 | * If the amount of data is more than the read() caller asked | ||
402 | * for it will be stored in the request buffer until it is | ||
403 | * asked for by read(). | ||
404 | */ | ||
405 | req->length = USB_BUFSIZE; | ||
406 | req->complete = rx_complete; | ||
407 | |||
408 | /* here, we unlock, and only unlock, to avoid deadlock. */ | ||
409 | spin_unlock(&dev->lock); | ||
410 | error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC); | ||
411 | spin_lock(&dev->lock); | ||
412 | if (error) { | ||
413 | DBG(dev, "rx submit --> %d\n", error); | ||
414 | list_add(&req->list, &dev->rx_reqs); | ||
415 | break; | ||
416 | } | ||
417 | /* if the req is empty, then add it into dev->rx_reqs_active. */ | ||
418 | else if (list_empty(&req->list)) | ||
419 | list_add(&req->list, &dev->rx_reqs_active); | ||
420 | } | ||
421 | } | ||
422 | |||
423 | static ssize_t | ||
424 | printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) | ||
425 | { | ||
426 | struct printer_dev *dev = fd->private_data; | ||
427 | unsigned long flags; | ||
428 | size_t size; | ||
429 | size_t bytes_copied; | ||
430 | struct usb_request *req; | ||
431 | /* This is a pointer to the current USB rx request. */ | ||
432 | struct usb_request *current_rx_req; | ||
433 | /* This is the number of bytes in the current rx buffer. */ | ||
434 | size_t current_rx_bytes; | ||
435 | /* This is a pointer to the current rx buffer. */ | ||
436 | u8 *current_rx_buf; | ||
437 | |||
438 | if (len == 0) | ||
439 | return -EINVAL; | ||
440 | |||
441 | DBG(dev, "printer_read trying to read %d bytes\n", (int)len); | ||
442 | |||
443 | mutex_lock(&dev->lock_printer_io); | ||
444 | spin_lock_irqsave(&dev->lock, flags); | ||
445 | |||
446 | /* We will use this flag later to check if a printer reset happened | ||
447 | * after we turn interrupts back on. | ||
448 | */ | ||
449 | dev->reset_printer = 0; | ||
450 | |||
451 | setup_rx_reqs(dev); | ||
452 | |||
453 | bytes_copied = 0; | ||
454 | current_rx_req = dev->current_rx_req; | ||
455 | current_rx_bytes = dev->current_rx_bytes; | ||
456 | current_rx_buf = dev->current_rx_buf; | ||
457 | dev->current_rx_req = NULL; | ||
458 | dev->current_rx_bytes = 0; | ||
459 | dev->current_rx_buf = NULL; | ||
460 | |||
461 | /* Check if there is any data in the read buffers. Please note that | ||
462 | * current_rx_bytes is the number of bytes in the current rx buffer. | ||
463 | * If it is zero then check if there are any other rx_buffers that | ||
464 | * are on the completed list. We are only out of data if all rx | ||
465 | * buffers are empty. | ||
466 | */ | ||
467 | if ((current_rx_bytes == 0) && | ||
468 | (likely(list_empty(&dev->rx_buffers)))) { | ||
469 | /* Turn interrupts back on before sleeping. */ | ||
470 | spin_unlock_irqrestore(&dev->lock, flags); | ||
471 | |||
472 | /* | ||
473 | * If no data is available check if this is a NON-Blocking | ||
474 | * call or not. | ||
475 | */ | ||
476 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { | ||
477 | mutex_unlock(&dev->lock_printer_io); | ||
478 | return -EAGAIN; | ||
479 | } | ||
480 | |||
481 | /* Sleep until data is available */ | ||
482 | wait_event_interruptible(dev->rx_wait, | ||
483 | (likely(!list_empty(&dev->rx_buffers)))); | ||
484 | spin_lock_irqsave(&dev->lock, flags); | ||
485 | } | ||
486 | |||
487 | /* We have data to return then copy it to the caller's buffer.*/ | ||
488 | while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers))) | ||
489 | && len) { | ||
490 | if (current_rx_bytes == 0) { | ||
491 | req = container_of(dev->rx_buffers.next, | ||
492 | struct usb_request, list); | ||
493 | list_del_init(&req->list); | ||
494 | |||
495 | if (req->actual && req->buf) { | ||
496 | current_rx_req = req; | ||
497 | current_rx_bytes = req->actual; | ||
498 | current_rx_buf = req->buf; | ||
499 | } else { | ||
500 | list_add(&req->list, &dev->rx_reqs); | ||
501 | continue; | ||
502 | } | ||
503 | } | ||
504 | |||
505 | /* Don't leave irqs off while doing memory copies */ | ||
506 | spin_unlock_irqrestore(&dev->lock, flags); | ||
507 | |||
508 | if (len > current_rx_bytes) | ||
509 | size = current_rx_bytes; | ||
510 | else | ||
511 | size = len; | ||
512 | |||
513 | size -= copy_to_user(buf, current_rx_buf, size); | ||
514 | bytes_copied += size; | ||
515 | len -= size; | ||
516 | buf += size; | ||
517 | |||
518 | spin_lock_irqsave(&dev->lock, flags); | ||
519 | |||
520 | /* We've disconnected or reset so return. */ | ||
521 | if (dev->reset_printer) { | ||
522 | list_add(¤t_rx_req->list, &dev->rx_reqs); | ||
523 | spin_unlock_irqrestore(&dev->lock, flags); | ||
524 | mutex_unlock(&dev->lock_printer_io); | ||
525 | return -EAGAIN; | ||
526 | } | ||
527 | |||
528 | /* If we not returning all the data left in this RX request | ||
529 | * buffer then adjust the amount of data left in the buffer. | ||
530 | * Othewise if we are done with this RX request buffer then | ||
531 | * requeue it to get any incoming data from the USB host. | ||
532 | */ | ||
533 | if (size < current_rx_bytes) { | ||
534 | current_rx_bytes -= size; | ||
535 | current_rx_buf += size; | ||
536 | } else { | ||
537 | list_add(¤t_rx_req->list, &dev->rx_reqs); | ||
538 | current_rx_bytes = 0; | ||
539 | current_rx_buf = NULL; | ||
540 | current_rx_req = NULL; | ||
541 | } | ||
542 | } | ||
543 | |||
544 | dev->current_rx_req = current_rx_req; | ||
545 | dev->current_rx_bytes = current_rx_bytes; | ||
546 | dev->current_rx_buf = current_rx_buf; | ||
547 | |||
548 | spin_unlock_irqrestore(&dev->lock, flags); | ||
549 | mutex_unlock(&dev->lock_printer_io); | ||
550 | |||
551 | DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); | ||
552 | |||
553 | if (bytes_copied) | ||
554 | return bytes_copied; | ||
555 | else | ||
556 | return -EAGAIN; | ||
557 | } | ||
558 | |||
559 | static ssize_t | ||
560 | printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | ||
561 | { | ||
562 | struct printer_dev *dev = fd->private_data; | ||
563 | unsigned long flags; | ||
564 | size_t size; /* Amount of data in a TX request. */ | ||
565 | size_t bytes_copied = 0; | ||
566 | struct usb_request *req; | ||
567 | |||
568 | DBG(dev, "printer_write trying to send %d bytes\n", (int)len); | ||
569 | |||
570 | if (len == 0) | ||
571 | return -EINVAL; | ||
572 | |||
573 | mutex_lock(&dev->lock_printer_io); | ||
574 | spin_lock_irqsave(&dev->lock, flags); | ||
575 | |||
576 | /* Check if a printer reset happens while we have interrupts on */ | ||
577 | dev->reset_printer = 0; | ||
578 | |||
579 | /* Check if there is any available write buffers */ | ||
580 | if (likely(list_empty(&dev->tx_reqs))) { | ||
581 | /* Turn interrupts back on before sleeping. */ | ||
582 | spin_unlock_irqrestore(&dev->lock, flags); | ||
583 | |||
584 | /* | ||
585 | * If write buffers are available check if this is | ||
586 | * a NON-Blocking call or not. | ||
587 | */ | ||
588 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { | ||
589 | mutex_unlock(&dev->lock_printer_io); | ||
590 | return -EAGAIN; | ||
591 | } | ||
592 | |||
593 | /* Sleep until a write buffer is available */ | ||
594 | wait_event_interruptible(dev->tx_wait, | ||
595 | (likely(!list_empty(&dev->tx_reqs)))); | ||
596 | spin_lock_irqsave(&dev->lock, flags); | ||
597 | } | ||
598 | |||
599 | while (likely(!list_empty(&dev->tx_reqs)) && len) { | ||
600 | |||
601 | if (len > USB_BUFSIZE) | ||
602 | size = USB_BUFSIZE; | ||
603 | else | ||
604 | size = len; | ||
605 | |||
606 | req = container_of(dev->tx_reqs.next, struct usb_request, | ||
607 | list); | ||
608 | list_del_init(&req->list); | ||
609 | |||
610 | req->complete = tx_complete; | ||
611 | req->length = size; | ||
612 | |||
613 | /* Check if we need to send a zero length packet. */ | ||
614 | if (len > size) | ||
615 | /* They will be more TX requests so no yet. */ | ||
616 | req->zero = 0; | ||
617 | else | ||
618 | /* If the data amount is not a multiple of the | ||
619 | * maxpacket size then send a zero length packet. | ||
620 | */ | ||
621 | req->zero = ((len % dev->in_ep->maxpacket) == 0); | ||
622 | |||
623 | /* Don't leave irqs off while doing memory copies */ | ||
624 | spin_unlock_irqrestore(&dev->lock, flags); | ||
625 | |||
626 | if (copy_from_user(req->buf, buf, size)) { | ||
627 | list_add(&req->list, &dev->tx_reqs); | ||
628 | mutex_unlock(&dev->lock_printer_io); | ||
629 | return bytes_copied; | ||
630 | } | ||
631 | |||
632 | bytes_copied += size; | ||
633 | len -= size; | ||
634 | buf += size; | ||
635 | |||
636 | spin_lock_irqsave(&dev->lock, flags); | ||
637 | |||
638 | /* We've disconnected or reset so free the req and buffer */ | ||
639 | if (dev->reset_printer) { | ||
640 | list_add(&req->list, &dev->tx_reqs); | ||
641 | spin_unlock_irqrestore(&dev->lock, flags); | ||
642 | mutex_unlock(&dev->lock_printer_io); | ||
643 | return -EAGAIN; | ||
644 | } | ||
645 | |||
646 | if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { | ||
647 | list_add(&req->list, &dev->tx_reqs); | ||
648 | spin_unlock_irqrestore(&dev->lock, flags); | ||
649 | mutex_unlock(&dev->lock_printer_io); | ||
650 | return -EAGAIN; | ||
651 | } | ||
652 | |||
653 | list_add(&req->list, &dev->tx_reqs_active); | ||
654 | |||
655 | } | ||
656 | |||
657 | spin_unlock_irqrestore(&dev->lock, flags); | ||
658 | mutex_unlock(&dev->lock_printer_io); | ||
659 | |||
660 | DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); | ||
661 | |||
662 | if (bytes_copied) | ||
663 | return bytes_copied; | ||
664 | else | ||
665 | return -EAGAIN; | ||
666 | } | ||
667 | |||
668 | static int | ||
669 | printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync) | ||
670 | { | ||
671 | struct printer_dev *dev = fd->private_data; | ||
672 | struct inode *inode = file_inode(fd); | ||
673 | unsigned long flags; | ||
674 | int tx_list_empty; | ||
675 | |||
676 | mutex_lock(&inode->i_mutex); | ||
677 | spin_lock_irqsave(&dev->lock, flags); | ||
678 | tx_list_empty = (likely(list_empty(&dev->tx_reqs))); | ||
679 | spin_unlock_irqrestore(&dev->lock, flags); | ||
680 | |||
681 | if (!tx_list_empty) { | ||
682 | /* Sleep until all data has been sent */ | ||
683 | wait_event_interruptible(dev->tx_flush_wait, | ||
684 | (likely(list_empty(&dev->tx_reqs_active)))); | ||
685 | } | ||
686 | mutex_unlock(&inode->i_mutex); | ||
687 | |||
688 | return 0; | ||
689 | } | ||
690 | |||
691 | static unsigned int | ||
692 | printer_poll(struct file *fd, poll_table *wait) | ||
693 | { | ||
694 | struct printer_dev *dev = fd->private_data; | ||
695 | unsigned long flags; | ||
696 | int status = 0; | ||
697 | |||
698 | mutex_lock(&dev->lock_printer_io); | ||
699 | spin_lock_irqsave(&dev->lock, flags); | ||
700 | setup_rx_reqs(dev); | ||
701 | spin_unlock_irqrestore(&dev->lock, flags); | ||
702 | mutex_unlock(&dev->lock_printer_io); | ||
703 | |||
704 | poll_wait(fd, &dev->rx_wait, wait); | ||
705 | poll_wait(fd, &dev->tx_wait, wait); | ||
706 | |||
707 | spin_lock_irqsave(&dev->lock, flags); | ||
708 | if (likely(!list_empty(&dev->tx_reqs))) | ||
709 | status |= POLLOUT | POLLWRNORM; | ||
710 | |||
711 | if (likely(dev->current_rx_bytes) || | ||
712 | likely(!list_empty(&dev->rx_buffers))) | ||
713 | status |= POLLIN | POLLRDNORM; | ||
714 | |||
715 | spin_unlock_irqrestore(&dev->lock, flags); | ||
716 | |||
717 | return status; | ||
718 | } | ||
719 | |||
720 | static long | ||
721 | printer_ioctl(struct file *fd, unsigned int code, unsigned long arg) | ||
722 | { | ||
723 | struct printer_dev *dev = fd->private_data; | ||
724 | unsigned long flags; | ||
725 | int status = 0; | ||
726 | |||
727 | DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg); | ||
728 | |||
729 | /* handle ioctls */ | ||
730 | |||
731 | spin_lock_irqsave(&dev->lock, flags); | ||
732 | |||
733 | switch (code) { | ||
734 | case GADGET_GET_PRINTER_STATUS: | ||
735 | status = (int)dev->printer_status; | ||
736 | break; | ||
737 | case GADGET_SET_PRINTER_STATUS: | ||
738 | dev->printer_status = (u8)arg; | ||
739 | break; | ||
740 | default: | ||
741 | /* could not handle ioctl */ | ||
742 | DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n", | ||
743 | code); | ||
744 | status = -ENOTTY; | ||
745 | } | ||
746 | |||
747 | spin_unlock_irqrestore(&dev->lock, flags); | ||
748 | |||
749 | return status; | ||
750 | } | ||
751 | |||
752 | /* used after endpoint configuration */ | ||
753 | static const struct file_operations printer_io_operations = { | ||
754 | .owner = THIS_MODULE, | ||
755 | .open = printer_open, | ||
756 | .read = printer_read, | ||
757 | .write = printer_write, | ||
758 | .fsync = printer_fsync, | ||
759 | .poll = printer_poll, | ||
760 | .unlocked_ioctl = printer_ioctl, | ||
761 | .release = printer_close, | ||
762 | .llseek = noop_llseek, | ||
763 | }; | ||
764 | |||
765 | /*-------------------------------------------------------------------------*/ | ||
766 | |||
767 | static int | ||
768 | set_printer_interface(struct printer_dev *dev) | ||
769 | { | ||
770 | int result = 0; | ||
771 | |||
772 | dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc, | ||
773 | &ss_ep_in_desc); | ||
774 | dev->in_ep->driver_data = dev; | ||
775 | |||
776 | dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc, | ||
777 | &hs_ep_out_desc, &ss_ep_out_desc); | ||
778 | dev->out_ep->driver_data = dev; | ||
779 | |||
780 | result = usb_ep_enable(dev->in_ep); | ||
781 | if (result != 0) { | ||
782 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); | ||
783 | goto done; | ||
784 | } | ||
785 | |||
786 | result = usb_ep_enable(dev->out_ep); | ||
787 | if (result != 0) { | ||
788 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); | ||
789 | goto done; | ||
790 | } | ||
791 | |||
792 | done: | ||
793 | /* on error, disable any endpoints */ | ||
794 | if (result != 0) { | ||
795 | (void) usb_ep_disable(dev->in_ep); | ||
796 | (void) usb_ep_disable(dev->out_ep); | ||
797 | dev->in_ep->desc = NULL; | ||
798 | dev->out_ep->desc = NULL; | ||
799 | } | ||
800 | |||
801 | /* caller is responsible for cleanup on error */ | ||
802 | return result; | ||
803 | } | ||
804 | |||
805 | static void printer_reset_interface(struct printer_dev *dev) | ||
806 | { | ||
807 | if (dev->interface < 0) | ||
808 | return; | ||
809 | |||
810 | DBG(dev, "%s\n", __func__); | ||
811 | |||
812 | if (dev->in_ep->desc) | ||
813 | usb_ep_disable(dev->in_ep); | ||
814 | |||
815 | if (dev->out_ep->desc) | ||
816 | usb_ep_disable(dev->out_ep); | ||
817 | |||
818 | dev->in_ep->desc = NULL; | ||
819 | dev->out_ep->desc = NULL; | ||
820 | dev->interface = -1; | ||
821 | } | ||
822 | |||
823 | /* Change our operational Interface. */ | ||
824 | static int set_interface(struct printer_dev *dev, unsigned number) | ||
825 | { | ||
826 | int result = 0; | ||
827 | |||
828 | /* Free the current interface */ | ||
829 | printer_reset_interface(dev); | ||
830 | |||
831 | result = set_printer_interface(dev); | ||
832 | if (result) | ||
833 | printer_reset_interface(dev); | ||
834 | else | ||
835 | dev->interface = number; | ||
836 | |||
837 | if (!result) | ||
838 | INFO(dev, "Using interface %x\n", number); | ||
839 | |||
840 | return result; | ||
841 | } | ||
842 | |||
843 | static void printer_soft_reset(struct printer_dev *dev) | ||
844 | { | ||
845 | struct usb_request *req; | ||
846 | |||
847 | INFO(dev, "Received Printer Reset Request\n"); | ||
848 | |||
849 | if (usb_ep_disable(dev->in_ep)) | ||
850 | DBG(dev, "Failed to disable USB in_ep\n"); | ||
851 | if (usb_ep_disable(dev->out_ep)) | ||
852 | DBG(dev, "Failed to disable USB out_ep\n"); | ||
853 | |||
854 | if (dev->current_rx_req != NULL) { | ||
855 | list_add(&dev->current_rx_req->list, &dev->rx_reqs); | ||
856 | dev->current_rx_req = NULL; | ||
857 | } | ||
858 | dev->current_rx_bytes = 0; | ||
859 | dev->current_rx_buf = NULL; | ||
860 | dev->reset_printer = 1; | ||
861 | |||
862 | while (likely(!(list_empty(&dev->rx_buffers)))) { | ||
863 | req = container_of(dev->rx_buffers.next, struct usb_request, | ||
864 | list); | ||
865 | list_del_init(&req->list); | ||
866 | list_add(&req->list, &dev->rx_reqs); | ||
867 | } | ||
868 | |||
869 | while (likely(!(list_empty(&dev->rx_reqs_active)))) { | ||
870 | req = container_of(dev->rx_buffers.next, struct usb_request, | ||
871 | list); | ||
872 | list_del_init(&req->list); | ||
873 | list_add(&req->list, &dev->rx_reqs); | ||
874 | } | ||
875 | |||
876 | while (likely(!(list_empty(&dev->tx_reqs_active)))) { | ||
877 | req = container_of(dev->tx_reqs_active.next, | ||
878 | struct usb_request, list); | ||
879 | list_del_init(&req->list); | ||
880 | list_add(&req->list, &dev->tx_reqs); | ||
881 | } | ||
882 | |||
883 | if (usb_ep_enable(dev->in_ep)) | ||
884 | DBG(dev, "Failed to enable USB in_ep\n"); | ||
885 | if (usb_ep_enable(dev->out_ep)) | ||
886 | DBG(dev, "Failed to enable USB out_ep\n"); | ||
887 | |||
888 | wake_up_interruptible(&dev->rx_wait); | ||
889 | wake_up_interruptible(&dev->tx_wait); | ||
890 | wake_up_interruptible(&dev->tx_flush_wait); | ||
891 | } | ||
892 | |||
893 | /*-------------------------------------------------------------------------*/ | ||
894 | |||
895 | static bool gprinter_req_match(struct usb_function *f, | ||
896 | const struct usb_ctrlrequest *ctrl) | ||
897 | { | ||
898 | struct printer_dev *dev = func_to_printer(f); | ||
899 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
900 | u16 w_value = le16_to_cpu(ctrl->wValue); | ||
901 | u16 w_length = le16_to_cpu(ctrl->wLength); | ||
902 | |||
903 | if ((ctrl->bRequestType & USB_RECIP_MASK) != USB_RECIP_INTERFACE || | ||
904 | (ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) | ||
905 | return false; | ||
906 | |||
907 | switch (ctrl->bRequest) { | ||
908 | case GET_DEVICE_ID: | ||
909 | w_index >>= 8; | ||
910 | if (w_length <= PNP_STRING_LEN && | ||
911 | (USB_DIR_IN & ctrl->bRequestType)) | ||
912 | break; | ||
913 | return false; | ||
914 | case GET_PORT_STATUS: | ||
915 | if (!w_value && w_length == 1 && | ||
916 | (USB_DIR_IN & ctrl->bRequestType)) | ||
917 | break; | ||
918 | return false; | ||
919 | case SOFT_RESET: | ||
920 | if (!w_value && !w_length && | ||
921 | !(USB_DIR_IN & ctrl->bRequestType)) | ||
922 | break; | ||
923 | /* fall through */ | ||
924 | default: | ||
925 | return false; | ||
926 | } | ||
927 | return w_index == dev->interface; | ||
928 | } | ||
929 | |||
930 | /* | ||
931 | * The setup() callback implements all the ep0 functionality that's not | ||
932 | * handled lower down. | ||
933 | */ | ||
934 | static int printer_func_setup(struct usb_function *f, | ||
935 | const struct usb_ctrlrequest *ctrl) | ||
936 | { | ||
937 | struct printer_dev *dev = func_to_printer(f); | ||
938 | struct usb_composite_dev *cdev = f->config->cdev; | ||
939 | struct usb_request *req = cdev->req; | ||
940 | int value = -EOPNOTSUPP; | ||
941 | u16 wIndex = le16_to_cpu(ctrl->wIndex); | ||
942 | u16 wValue = le16_to_cpu(ctrl->wValue); | ||
943 | u16 wLength = le16_to_cpu(ctrl->wLength); | ||
944 | |||
945 | DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", | ||
946 | ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); | ||
947 | |||
948 | switch (ctrl->bRequestType&USB_TYPE_MASK) { | ||
949 | case USB_TYPE_CLASS: | ||
950 | switch (ctrl->bRequest) { | ||
951 | case GET_DEVICE_ID: /* Get the IEEE-1284 PNP String */ | ||
952 | /* Only one printer interface is supported. */ | ||
953 | if ((wIndex>>8) != dev->interface) | ||
954 | break; | ||
955 | |||
956 | value = (dev->pnp_string[0] << 8) | dev->pnp_string[1]; | ||
957 | memcpy(req->buf, dev->pnp_string, value); | ||
958 | DBG(dev, "1284 PNP String: %x %s\n", value, | ||
959 | &dev->pnp_string[2]); | ||
960 | break; | ||
961 | |||
962 | case GET_PORT_STATUS: /* Get Port Status */ | ||
963 | /* Only one printer interface is supported. */ | ||
964 | if (wIndex != dev->interface) | ||
965 | break; | ||
966 | |||
967 | *(u8 *)req->buf = dev->printer_status; | ||
968 | value = min_t(u16, wLength, 1); | ||
969 | break; | ||
970 | |||
971 | case SOFT_RESET: /* Soft Reset */ | ||
972 | /* Only one printer interface is supported. */ | ||
973 | if (wIndex != dev->interface) | ||
974 | break; | ||
975 | |||
976 | printer_soft_reset(dev); | ||
977 | |||
978 | value = 0; | ||
979 | break; | ||
980 | |||
981 | default: | ||
982 | goto unknown; | ||
983 | } | ||
984 | break; | ||
985 | |||
986 | default: | ||
987 | unknown: | ||
988 | VDBG(dev, | ||
989 | "unknown ctrl req%02x.%02x v%04x i%04x l%d\n", | ||
990 | ctrl->bRequestType, ctrl->bRequest, | ||
991 | wValue, wIndex, wLength); | ||
992 | break; | ||
993 | } | ||
994 | /* host either stalls (value < 0) or reports success */ | ||
995 | if (value >= 0) { | ||
996 | req->length = value; | ||
997 | req->zero = value < wLength; | ||
998 | value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); | ||
999 | if (value < 0) { | ||
1000 | ERROR(dev, "%s:%d Error!\n", __func__, __LINE__); | ||
1001 | req->status = 0; | ||
1002 | } | ||
1003 | } | ||
1004 | return value; | ||
1005 | } | ||
1006 | |||
1007 | static int printer_func_bind(struct usb_configuration *c, | ||
1008 | struct usb_function *f) | ||
1009 | { | ||
1010 | struct usb_gadget *gadget = c->cdev->gadget; | ||
1011 | struct printer_dev *dev = func_to_printer(f); | ||
1012 | struct device *pdev; | ||
1013 | struct usb_composite_dev *cdev = c->cdev; | ||
1014 | struct usb_ep *in_ep; | ||
1015 | struct usb_ep *out_ep = NULL; | ||
1016 | struct usb_request *req; | ||
1017 | dev_t devt; | ||
1018 | int id; | ||
1019 | int ret; | ||
1020 | u32 i; | ||
1021 | |||
1022 | id = usb_interface_id(c, f); | ||
1023 | if (id < 0) | ||
1024 | return id; | ||
1025 | intf_desc.bInterfaceNumber = id; | ||
1026 | |||
1027 | /* finish hookup to lower layer ... */ | ||
1028 | dev->gadget = gadget; | ||
1029 | |||
1030 | /* all we really need is bulk IN/OUT */ | ||
1031 | in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc); | ||
1032 | if (!in_ep) { | ||
1033 | autoconf_fail: | ||
1034 | dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n", | ||
1035 | cdev->gadget->name); | ||
1036 | return -ENODEV; | ||
1037 | } | ||
1038 | in_ep->driver_data = in_ep; /* claim */ | ||
1039 | |||
1040 | out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc); | ||
1041 | if (!out_ep) | ||
1042 | goto autoconf_fail; | ||
1043 | out_ep->driver_data = out_ep; /* claim */ | ||
1044 | |||
1045 | /* assumes that all endpoints are dual-speed */ | ||
1046 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | ||
1047 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | ||
1048 | ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | ||
1049 | ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | ||
1050 | |||
1051 | ret = usb_assign_descriptors(f, fs_printer_function, | ||
1052 | hs_printer_function, ss_printer_function); | ||
1053 | if (ret) | ||
1054 | return ret; | ||
1055 | |||
1056 | dev->in_ep = in_ep; | ||
1057 | dev->out_ep = out_ep; | ||
1058 | |||
1059 | ret = -ENOMEM; | ||
1060 | for (i = 0; i < dev->q_len; i++) { | ||
1061 | req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); | ||
1062 | if (!req) | ||
1063 | goto fail_tx_reqs; | ||
1064 | list_add(&req->list, &dev->tx_reqs); | ||
1065 | } | ||
1066 | |||
1067 | for (i = 0; i < dev->q_len; i++) { | ||
1068 | req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); | ||
1069 | if (!req) | ||
1070 | goto fail_rx_reqs; | ||
1071 | list_add(&req->list, &dev->rx_reqs); | ||
1072 | } | ||
1073 | |||
1074 | /* Setup the sysfs files for the printer gadget. */ | ||
1075 | devt = MKDEV(major, dev->minor); | ||
1076 | pdev = device_create(usb_gadget_class, NULL, devt, | ||
1077 | NULL, "g_printer%d", dev->minor); | ||
1078 | if (IS_ERR(pdev)) { | ||
1079 | ERROR(dev, "Failed to create device: g_printer\n"); | ||
1080 | ret = PTR_ERR(pdev); | ||
1081 | goto fail_rx_reqs; | ||
1082 | } | ||
1083 | |||
1084 | /* | ||
1085 | * Register a character device as an interface to a user mode | ||
1086 | * program that handles the printer specific functionality. | ||
1087 | */ | ||
1088 | cdev_init(&dev->printer_cdev, &printer_io_operations); | ||
1089 | dev->printer_cdev.owner = THIS_MODULE; | ||
1090 | ret = cdev_add(&dev->printer_cdev, devt, 1); | ||
1091 | if (ret) { | ||
1092 | ERROR(dev, "Failed to open char device\n"); | ||
1093 | goto fail_cdev_add; | ||
1094 | } | ||
1095 | |||
1096 | return 0; | ||
1097 | |||
1098 | fail_cdev_add: | ||
1099 | device_destroy(usb_gadget_class, devt); | ||
1100 | |||
1101 | fail_rx_reqs: | ||
1102 | while (!list_empty(&dev->rx_reqs)) { | ||
1103 | req = container_of(dev->rx_reqs.next, struct usb_request, list); | ||
1104 | list_del(&req->list); | ||
1105 | printer_req_free(dev->out_ep, req); | ||
1106 | } | ||
1107 | |||
1108 | fail_tx_reqs: | ||
1109 | while (!list_empty(&dev->tx_reqs)) { | ||
1110 | req = container_of(dev->tx_reqs.next, struct usb_request, list); | ||
1111 | list_del(&req->list); | ||
1112 | printer_req_free(dev->in_ep, req); | ||
1113 | } | ||
1114 | |||
1115 | return ret; | ||
1116 | |||
1117 | } | ||
1118 | |||
1119 | static int printer_func_set_alt(struct usb_function *f, | ||
1120 | unsigned intf, unsigned alt) | ||
1121 | { | ||
1122 | struct printer_dev *dev = func_to_printer(f); | ||
1123 | int ret = -ENOTSUPP; | ||
1124 | |||
1125 | if (!alt) | ||
1126 | ret = set_interface(dev, intf); | ||
1127 | |||
1128 | return ret; | ||
1129 | } | ||
1130 | |||
1131 | static void printer_func_disable(struct usb_function *f) | ||
1132 | { | ||
1133 | struct printer_dev *dev = func_to_printer(f); | ||
1134 | unsigned long flags; | ||
1135 | |||
1136 | DBG(dev, "%s\n", __func__); | ||
1137 | |||
1138 | spin_lock_irqsave(&dev->lock, flags); | ||
1139 | printer_reset_interface(dev); | ||
1140 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1141 | } | ||
1142 | |||
1143 | static inline struct f_printer_opts | ||
1144 | *to_f_printer_opts(struct config_item *item) | ||
1145 | { | ||
1146 | return container_of(to_config_group(item), struct f_printer_opts, | ||
1147 | func_inst.group); | ||
1148 | } | ||
1149 | |||
1150 | CONFIGFS_ATTR_STRUCT(f_printer_opts); | ||
1151 | CONFIGFS_ATTR_OPS(f_printer_opts); | ||
1152 | |||
1153 | static void printer_attr_release(struct config_item *item) | ||
1154 | { | ||
1155 | struct f_printer_opts *opts = to_f_printer_opts(item); | ||
1156 | |||
1157 | usb_put_function_instance(&opts->func_inst); | ||
1158 | } | ||
1159 | |||
1160 | static struct configfs_item_operations printer_item_ops = { | ||
1161 | .release = printer_attr_release, | ||
1162 | .show_attribute = f_printer_opts_attr_show, | ||
1163 | .store_attribute = f_printer_opts_attr_store, | ||
1164 | }; | ||
1165 | |||
1166 | static ssize_t f_printer_opts_pnp_string_show(struct f_printer_opts *opts, | ||
1167 | char *page) | ||
1168 | { | ||
1169 | int result; | ||
1170 | |||
1171 | mutex_lock(&opts->lock); | ||
1172 | result = strlcpy(page, opts->pnp_string + 2, PNP_STRING_LEN - 2); | ||
1173 | mutex_unlock(&opts->lock); | ||
1174 | |||
1175 | return result; | ||
1176 | } | ||
1177 | |||
1178 | static ssize_t f_printer_opts_pnp_string_store(struct f_printer_opts *opts, | ||
1179 | const char *page, size_t len) | ||
1180 | { | ||
1181 | int result, l; | ||
1182 | |||
1183 | mutex_lock(&opts->lock); | ||
1184 | result = strlcpy(opts->pnp_string + 2, page, PNP_STRING_LEN - 2); | ||
1185 | l = strlen(opts->pnp_string + 2) + 2; | ||
1186 | opts->pnp_string[0] = (l >> 8) & 0xFF; | ||
1187 | opts->pnp_string[1] = l & 0xFF; | ||
1188 | mutex_unlock(&opts->lock); | ||
1189 | |||
1190 | return result; | ||
1191 | } | ||
1192 | |||
1193 | static struct f_printer_opts_attribute f_printer_opts_pnp_string = | ||
1194 | __CONFIGFS_ATTR(pnp_string, S_IRUGO | S_IWUSR, | ||
1195 | f_printer_opts_pnp_string_show, | ||
1196 | f_printer_opts_pnp_string_store); | ||
1197 | |||
1198 | static ssize_t f_printer_opts_q_len_show(struct f_printer_opts *opts, | ||
1199 | char *page) | ||
1200 | { | ||
1201 | int result; | ||
1202 | |||
1203 | mutex_lock(&opts->lock); | ||
1204 | result = sprintf(page, "%d\n", opts->q_len); | ||
1205 | mutex_unlock(&opts->lock); | ||
1206 | |||
1207 | return result; | ||
1208 | } | ||
1209 | |||
1210 | static ssize_t f_printer_opts_q_len_store(struct f_printer_opts *opts, | ||
1211 | const char *page, size_t len) | ||
1212 | { | ||
1213 | int ret; | ||
1214 | u16 num; | ||
1215 | |||
1216 | mutex_lock(&opts->lock); | ||
1217 | if (opts->refcnt) { | ||
1218 | ret = -EBUSY; | ||
1219 | goto end; | ||
1220 | } | ||
1221 | |||
1222 | ret = kstrtou16(page, 0, &num); | ||
1223 | if (ret) | ||
1224 | goto end; | ||
1225 | |||
1226 | opts->q_len = (unsigned)num; | ||
1227 | ret = len; | ||
1228 | end: | ||
1229 | mutex_unlock(&opts->lock); | ||
1230 | return ret; | ||
1231 | } | ||
1232 | |||
1233 | static struct f_printer_opts_attribute f_printer_opts_q_len = | ||
1234 | __CONFIGFS_ATTR(q_len, S_IRUGO | S_IWUSR, f_printer_opts_q_len_show, | ||
1235 | f_printer_opts_q_len_store); | ||
1236 | |||
1237 | static struct configfs_attribute *printer_attrs[] = { | ||
1238 | &f_printer_opts_pnp_string.attr, | ||
1239 | &f_printer_opts_q_len.attr, | ||
1240 | NULL, | ||
1241 | }; | ||
1242 | |||
1243 | static struct config_item_type printer_func_type = { | ||
1244 | .ct_item_ops = &printer_item_ops, | ||
1245 | .ct_attrs = printer_attrs, | ||
1246 | .ct_owner = THIS_MODULE, | ||
1247 | }; | ||
1248 | |||
1249 | static inline int gprinter_get_minor(void) | ||
1250 | { | ||
1251 | return ida_simple_get(&printer_ida, 0, 0, GFP_KERNEL); | ||
1252 | } | ||
1253 | |||
1254 | static inline void gprinter_put_minor(int minor) | ||
1255 | { | ||
1256 | ida_simple_remove(&printer_ida, minor); | ||
1257 | } | ||
1258 | |||
1259 | static int gprinter_setup(int); | ||
1260 | static void gprinter_cleanup(void); | ||
1261 | |||
1262 | static void gprinter_free_inst(struct usb_function_instance *f) | ||
1263 | { | ||
1264 | struct f_printer_opts *opts; | ||
1265 | |||
1266 | opts = container_of(f, struct f_printer_opts, func_inst); | ||
1267 | |||
1268 | mutex_lock(&printer_ida_lock); | ||
1269 | |||
1270 | gprinter_put_minor(opts->minor); | ||
1271 | if (idr_is_empty(&printer_ida.idr)) | ||
1272 | gprinter_cleanup(); | ||
1273 | |||
1274 | mutex_unlock(&printer_ida_lock); | ||
1275 | |||
1276 | kfree(opts); | ||
1277 | } | ||
1278 | |||
1279 | static struct usb_function_instance *gprinter_alloc_inst(void) | ||
1280 | { | ||
1281 | struct f_printer_opts *opts; | ||
1282 | struct usb_function_instance *ret; | ||
1283 | int status = 0; | ||
1284 | |||
1285 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
1286 | if (!opts) | ||
1287 | return ERR_PTR(-ENOMEM); | ||
1288 | |||
1289 | mutex_init(&opts->lock); | ||
1290 | opts->func_inst.free_func_inst = gprinter_free_inst; | ||
1291 | ret = &opts->func_inst; | ||
1292 | |||
1293 | mutex_lock(&printer_ida_lock); | ||
1294 | |||
1295 | if (idr_is_empty(&printer_ida.idr)) { | ||
1296 | status = gprinter_setup(PRINTER_MINORS); | ||
1297 | if (status) { | ||
1298 | ret = ERR_PTR(status); | ||
1299 | kfree(opts); | ||
1300 | goto unlock; | ||
1301 | } | ||
1302 | } | ||
1303 | |||
1304 | opts->minor = gprinter_get_minor(); | ||
1305 | if (opts->minor < 0) { | ||
1306 | ret = ERR_PTR(opts->minor); | ||
1307 | kfree(opts); | ||
1308 | if (idr_is_empty(&printer_ida.idr)) | ||
1309 | gprinter_cleanup(); | ||
1310 | goto unlock; | ||
1311 | } | ||
1312 | config_group_init_type_name(&opts->func_inst.group, "", | ||
1313 | &printer_func_type); | ||
1314 | |||
1315 | unlock: | ||
1316 | mutex_unlock(&printer_ida_lock); | ||
1317 | return ret; | ||
1318 | } | ||
1319 | |||
1320 | static void gprinter_free(struct usb_function *f) | ||
1321 | { | ||
1322 | struct printer_dev *dev = func_to_printer(f); | ||
1323 | struct f_printer_opts *opts; | ||
1324 | |||
1325 | opts = container_of(f->fi, struct f_printer_opts, func_inst); | ||
1326 | kfree(dev); | ||
1327 | mutex_lock(&opts->lock); | ||
1328 | --opts->refcnt; | ||
1329 | mutex_unlock(&opts->lock); | ||
1330 | } | ||
1331 | |||
1332 | static void printer_func_unbind(struct usb_configuration *c, | ||
1333 | struct usb_function *f) | ||
1334 | { | ||
1335 | struct printer_dev *dev; | ||
1336 | struct usb_request *req; | ||
1337 | |||
1338 | dev = func_to_printer(f); | ||
1339 | |||
1340 | device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); | ||
1341 | |||
1342 | /* Remove Character Device */ | ||
1343 | cdev_del(&dev->printer_cdev); | ||
1344 | |||
1345 | /* we must already have been disconnected ... no i/o may be active */ | ||
1346 | WARN_ON(!list_empty(&dev->tx_reqs_active)); | ||
1347 | WARN_ON(!list_empty(&dev->rx_reqs_active)); | ||
1348 | |||
1349 | /* Free all memory for this driver. */ | ||
1350 | while (!list_empty(&dev->tx_reqs)) { | ||
1351 | req = container_of(dev->tx_reqs.next, struct usb_request, | ||
1352 | list); | ||
1353 | list_del(&req->list); | ||
1354 | printer_req_free(dev->in_ep, req); | ||
1355 | } | ||
1356 | |||
1357 | if (dev->current_rx_req != NULL) | ||
1358 | printer_req_free(dev->out_ep, dev->current_rx_req); | ||
1359 | |||
1360 | while (!list_empty(&dev->rx_reqs)) { | ||
1361 | req = container_of(dev->rx_reqs.next, | ||
1362 | struct usb_request, list); | ||
1363 | list_del(&req->list); | ||
1364 | printer_req_free(dev->out_ep, req); | ||
1365 | } | ||
1366 | |||
1367 | while (!list_empty(&dev->rx_buffers)) { | ||
1368 | req = container_of(dev->rx_buffers.next, | ||
1369 | struct usb_request, list); | ||
1370 | list_del(&req->list); | ||
1371 | printer_req_free(dev->out_ep, req); | ||
1372 | } | ||
1373 | usb_free_all_descriptors(f); | ||
1374 | } | ||
1375 | |||
1376 | static struct usb_function *gprinter_alloc(struct usb_function_instance *fi) | ||
1377 | { | ||
1378 | struct printer_dev *dev; | ||
1379 | struct f_printer_opts *opts; | ||
1380 | |||
1381 | opts = container_of(fi, struct f_printer_opts, func_inst); | ||
1382 | |||
1383 | mutex_lock(&opts->lock); | ||
1384 | if (opts->minor >= minors) { | ||
1385 | mutex_unlock(&opts->lock); | ||
1386 | return ERR_PTR(-ENOENT); | ||
1387 | } | ||
1388 | |||
1389 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
1390 | if (!dev) { | ||
1391 | mutex_unlock(&opts->lock); | ||
1392 | return ERR_PTR(-ENOMEM); | ||
1393 | } | ||
1394 | |||
1395 | ++opts->refcnt; | ||
1396 | dev->minor = opts->minor; | ||
1397 | dev->pnp_string = opts->pnp_string; | ||
1398 | dev->q_len = opts->q_len; | ||
1399 | mutex_unlock(&opts->lock); | ||
1400 | |||
1401 | dev->function.name = "printer"; | ||
1402 | dev->function.bind = printer_func_bind; | ||
1403 | dev->function.setup = printer_func_setup; | ||
1404 | dev->function.unbind = printer_func_unbind; | ||
1405 | dev->function.set_alt = printer_func_set_alt; | ||
1406 | dev->function.disable = printer_func_disable; | ||
1407 | dev->function.req_match = gprinter_req_match; | ||
1408 | dev->function.free_func = gprinter_free; | ||
1409 | |||
1410 | INIT_LIST_HEAD(&dev->tx_reqs); | ||
1411 | INIT_LIST_HEAD(&dev->rx_reqs); | ||
1412 | INIT_LIST_HEAD(&dev->rx_buffers); | ||
1413 | INIT_LIST_HEAD(&dev->tx_reqs_active); | ||
1414 | INIT_LIST_HEAD(&dev->rx_reqs_active); | ||
1415 | |||
1416 | spin_lock_init(&dev->lock); | ||
1417 | mutex_init(&dev->lock_printer_io); | ||
1418 | init_waitqueue_head(&dev->rx_wait); | ||
1419 | init_waitqueue_head(&dev->tx_wait); | ||
1420 | init_waitqueue_head(&dev->tx_flush_wait); | ||
1421 | |||
1422 | dev->interface = -1; | ||
1423 | dev->printer_cdev_open = 0; | ||
1424 | dev->printer_status = PRINTER_NOT_ERROR; | ||
1425 | dev->current_rx_req = NULL; | ||
1426 | dev->current_rx_bytes = 0; | ||
1427 | dev->current_rx_buf = NULL; | ||
1428 | |||
1429 | return &dev->function; | ||
1430 | } | ||
1431 | |||
1432 | DECLARE_USB_FUNCTION_INIT(printer, gprinter_alloc_inst, gprinter_alloc); | ||
1433 | MODULE_LICENSE("GPL"); | ||
1434 | MODULE_AUTHOR("Craig Nadler"); | ||
1435 | |||
1436 | static int gprinter_setup(int count) | ||
1437 | { | ||
1438 | int status; | ||
1439 | dev_t devt; | ||
1440 | |||
1441 | usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); | ||
1442 | if (IS_ERR(usb_gadget_class)) { | ||
1443 | status = PTR_ERR(usb_gadget_class); | ||
1444 | usb_gadget_class = NULL; | ||
1445 | pr_err("unable to create usb_gadget class %d\n", status); | ||
1446 | return status; | ||
1447 | } | ||
1448 | |||
1449 | status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget"); | ||
1450 | if (status) { | ||
1451 | pr_err("alloc_chrdev_region %d\n", status); | ||
1452 | class_destroy(usb_gadget_class); | ||
1453 | usb_gadget_class = NULL; | ||
1454 | return status; | ||
1455 | } | ||
1456 | |||
1457 | major = MAJOR(devt); | ||
1458 | minors = count; | ||
1459 | |||
1460 | return status; | ||
1461 | } | ||
1462 | |||
1463 | static void gprinter_cleanup(void) | ||
1464 | { | ||
1465 | if (major) { | ||
1466 | unregister_chrdev_region(MKDEV(major, 0), minors); | ||
1467 | major = minors = 0; | ||
1468 | } | ||
1469 | class_destroy(usb_gadget_class); | ||
1470 | usb_gadget_class = NULL; | ||
1471 | } | ||
diff --git a/drivers/usb/gadget/function/u_printer.h b/drivers/usb/gadget/function/u_printer.h new file mode 100644 index 000000000000..0e2c49d4274e --- /dev/null +++ b/drivers/usb/gadget/function/u_printer.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * u_printer.h | ||
3 | * | ||
4 | * Utility definitions for the printer function | ||
5 | * | ||
6 | * Copyright (c) 2015 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef U_PRINTER_H | ||
17 | #define U_PRINTER_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | |||
21 | #define PNP_STRING_LEN 1024 | ||
22 | |||
23 | struct f_printer_opts { | ||
24 | struct usb_function_instance func_inst; | ||
25 | int minor; | ||
26 | char pnp_string[PNP_STRING_LEN]; | ||
27 | unsigned q_len; | ||
28 | |||
29 | /* | ||
30 | * Protect the data from concurrent access by read/write | ||
31 | * and create symlink/remove symlink | ||
32 | */ | ||
33 | struct mutex lock; | ||
34 | int refcnt; | ||
35 | }; | ||
36 | |||
37 | #endif /* U_PRINTER_H */ | ||
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 491082aaf103..89179ab20c10 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c | |||
@@ -912,7 +912,7 @@ static int gs_put_char(struct tty_struct *tty, unsigned char ch) | |||
912 | unsigned long flags; | 912 | unsigned long flags; |
913 | int status; | 913 | int status; |
914 | 914 | ||
915 | pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %pf\n", | 915 | pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %ps\n", |
916 | port->port_num, tty, ch, __builtin_return_address(0)); | 916 | port->port_num, tty, ch, __builtin_return_address(0)); |
917 | 917 | ||
918 | spin_lock_irqsave(&port->port_lock, flags); | 918 | spin_lock_irqsave(&port->port_lock, flags); |
diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig index 113c87e22117..d5a7102de696 100644 --- a/drivers/usb/gadget/legacy/Kconfig +++ b/drivers/usb/gadget/legacy/Kconfig | |||
@@ -301,6 +301,7 @@ config USB_MIDI_GADGET | |||
301 | config USB_G_PRINTER | 301 | config USB_G_PRINTER |
302 | tristate "Printer Gadget" | 302 | tristate "Printer Gadget" |
303 | select USB_LIBCOMPOSITE | 303 | select USB_LIBCOMPOSITE |
304 | select USB_F_PRINTER | ||
304 | help | 305 | help |
305 | The Printer Gadget channels data between the USB host and a | 306 | The Printer Gadget channels data between the USB host and a |
306 | userspace program driving the print engine. The user space | 307 | userspace program driving the print engine. The user space |
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 90545980542f..d5b6ee725a2a 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c | |||
@@ -12,29 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/delay.h> | ||
16 | #include <linux/ioport.h> | ||
17 | #include <linux/sched.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/mutex.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/timer.h> | ||
23 | #include <linux/list.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/moduleparam.h> | ||
27 | #include <linux/fs.h> | ||
28 | #include <linux/poll.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/ctype.h> | ||
31 | #include <linux/cdev.h> | ||
32 | |||
33 | #include <asm/byteorder.h> | 15 | #include <asm/byteorder.h> |
34 | #include <linux/io.h> | ||
35 | #include <linux/irq.h> | ||
36 | #include <linux/uaccess.h> | ||
37 | #include <asm/unaligned.h> | ||
38 | 16 | ||
39 | #include <linux/usb/ch9.h> | 17 | #include <linux/usb/ch9.h> |
40 | #include <linux/usb/composite.h> | 18 | #include <linux/usb/composite.h> |
@@ -46,50 +24,12 @@ | |||
46 | USB_GADGET_COMPOSITE_OPTIONS(); | 24 | USB_GADGET_COMPOSITE_OPTIONS(); |
47 | 25 | ||
48 | #define DRIVER_DESC "Printer Gadget" | 26 | #define DRIVER_DESC "Printer Gadget" |
49 | #define DRIVER_VERSION "2007 OCT 06" | 27 | #define DRIVER_VERSION "2015 FEB 17" |
50 | 28 | ||
51 | static DEFINE_MUTEX(printer_mutex); | ||
52 | static const char shortname [] = "printer"; | 29 | static const char shortname [] = "printer"; |
53 | static const char driver_desc [] = DRIVER_DESC; | 30 | static const char driver_desc [] = DRIVER_DESC; |
54 | 31 | ||
55 | static dev_t g_printer_devno; | 32 | #include "u_printer.h" |
56 | |||
57 | static struct class *usb_gadget_class; | ||
58 | |||
59 | /*-------------------------------------------------------------------------*/ | ||
60 | |||
61 | struct printer_dev { | ||
62 | spinlock_t lock; /* lock this structure */ | ||
63 | /* lock buffer lists during read/write calls */ | ||
64 | struct mutex lock_printer_io; | ||
65 | struct usb_gadget *gadget; | ||
66 | s8 interface; | ||
67 | struct usb_ep *in_ep, *out_ep; | ||
68 | |||
69 | struct list_head rx_reqs; /* List of free RX structs */ | ||
70 | struct list_head rx_reqs_active; /* List of Active RX xfers */ | ||
71 | struct list_head rx_buffers; /* List of completed xfers */ | ||
72 | /* wait until there is data to be read. */ | ||
73 | wait_queue_head_t rx_wait; | ||
74 | struct list_head tx_reqs; /* List of free TX structs */ | ||
75 | struct list_head tx_reqs_active; /* List of Active TX xfers */ | ||
76 | /* Wait until there are write buffers available to use. */ | ||
77 | wait_queue_head_t tx_wait; | ||
78 | /* Wait until all write buffers have been sent. */ | ||
79 | wait_queue_head_t tx_flush_wait; | ||
80 | struct usb_request *current_rx_req; | ||
81 | size_t current_rx_bytes; | ||
82 | u8 *current_rx_buf; | ||
83 | u8 printer_status; | ||
84 | u8 reset_printer; | ||
85 | struct cdev printer_cdev; | ||
86 | struct device *pdev; | ||
87 | u8 printer_cdev_open; | ||
88 | wait_queue_head_t wait; | ||
89 | struct usb_function function; | ||
90 | }; | ||
91 | |||
92 | static struct printer_dev usb_printer_gadget; | ||
93 | 33 | ||
94 | /*-------------------------------------------------------------------------*/ | 34 | /*-------------------------------------------------------------------------*/ |
95 | 35 | ||
@@ -120,6 +60,9 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR); | |||
120 | 60 | ||
121 | #define QLEN qlen | 61 | #define QLEN qlen |
122 | 62 | ||
63 | static struct usb_function_instance *fi_printer; | ||
64 | static struct usb_function *f_printer; | ||
65 | |||
123 | /*-------------------------------------------------------------------------*/ | 66 | /*-------------------------------------------------------------------------*/ |
124 | 67 | ||
125 | /* | 68 | /* |
@@ -127,10 +70,6 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR); | |||
127 | * descriptors are built on demand. | 70 | * descriptors are built on demand. |
128 | */ | 71 | */ |
129 | 72 | ||
130 | /* holds our biggest descriptor */ | ||
131 | #define USB_DESC_BUFSIZE 256 | ||
132 | #define USB_BUFSIZE 8192 | ||
133 | |||
134 | static struct usb_device_descriptor device_desc = { | 73 | static struct usb_device_descriptor device_desc = { |
135 | .bLength = sizeof device_desc, | 74 | .bLength = sizeof device_desc, |
136 | .bDescriptorType = USB_DT_DEVICE, | 75 | .bDescriptorType = USB_DT_DEVICE, |
@@ -143,108 +82,6 @@ static struct usb_device_descriptor device_desc = { | |||
143 | .bNumConfigurations = 1 | 82 | .bNumConfigurations = 1 |
144 | }; | 83 | }; |
145 | 84 | ||
146 | static struct usb_interface_descriptor intf_desc = { | ||
147 | .bLength = sizeof intf_desc, | ||
148 | .bDescriptorType = USB_DT_INTERFACE, | ||
149 | .bNumEndpoints = 2, | ||
150 | .bInterfaceClass = USB_CLASS_PRINTER, | ||
151 | .bInterfaceSubClass = 1, /* Printer Sub-Class */ | ||
152 | .bInterfaceProtocol = 2, /* Bi-Directional */ | ||
153 | .iInterface = 0 | ||
154 | }; | ||
155 | |||
156 | static struct usb_endpoint_descriptor fs_ep_in_desc = { | ||
157 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
158 | .bDescriptorType = USB_DT_ENDPOINT, | ||
159 | .bEndpointAddress = USB_DIR_IN, | ||
160 | .bmAttributes = USB_ENDPOINT_XFER_BULK | ||
161 | }; | ||
162 | |||
163 | static struct usb_endpoint_descriptor fs_ep_out_desc = { | ||
164 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
165 | .bDescriptorType = USB_DT_ENDPOINT, | ||
166 | .bEndpointAddress = USB_DIR_OUT, | ||
167 | .bmAttributes = USB_ENDPOINT_XFER_BULK | ||
168 | }; | ||
169 | |||
170 | static struct usb_descriptor_header *fs_printer_function[] = { | ||
171 | (struct usb_descriptor_header *) &intf_desc, | ||
172 | (struct usb_descriptor_header *) &fs_ep_in_desc, | ||
173 | (struct usb_descriptor_header *) &fs_ep_out_desc, | ||
174 | NULL | ||
175 | }; | ||
176 | |||
177 | /* | ||
178 | * usb 2.0 devices need to expose both high speed and full speed | ||
179 | * descriptors, unless they only run at full speed. | ||
180 | */ | ||
181 | |||
182 | static struct usb_endpoint_descriptor hs_ep_in_desc = { | ||
183 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
184 | .bDescriptorType = USB_DT_ENDPOINT, | ||
185 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
186 | .wMaxPacketSize = cpu_to_le16(512) | ||
187 | }; | ||
188 | |||
189 | static struct usb_endpoint_descriptor hs_ep_out_desc = { | ||
190 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
191 | .bDescriptorType = USB_DT_ENDPOINT, | ||
192 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
193 | .wMaxPacketSize = cpu_to_le16(512) | ||
194 | }; | ||
195 | |||
196 | static struct usb_qualifier_descriptor dev_qualifier = { | ||
197 | .bLength = sizeof dev_qualifier, | ||
198 | .bDescriptorType = USB_DT_DEVICE_QUALIFIER, | ||
199 | .bcdUSB = cpu_to_le16(0x0200), | ||
200 | .bDeviceClass = USB_CLASS_PRINTER, | ||
201 | .bNumConfigurations = 1 | ||
202 | }; | ||
203 | |||
204 | static struct usb_descriptor_header *hs_printer_function[] = { | ||
205 | (struct usb_descriptor_header *) &intf_desc, | ||
206 | (struct usb_descriptor_header *) &hs_ep_in_desc, | ||
207 | (struct usb_descriptor_header *) &hs_ep_out_desc, | ||
208 | NULL | ||
209 | }; | ||
210 | |||
211 | /* | ||
212 | * Added endpoint descriptors for 3.0 devices | ||
213 | */ | ||
214 | |||
215 | static struct usb_endpoint_descriptor ss_ep_in_desc = { | ||
216 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
217 | .bDescriptorType = USB_DT_ENDPOINT, | ||
218 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
219 | .wMaxPacketSize = cpu_to_le16(1024), | ||
220 | }; | ||
221 | |||
222 | static struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = { | ||
223 | .bLength = sizeof(ss_ep_in_comp_desc), | ||
224 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
225 | }; | ||
226 | |||
227 | static struct usb_endpoint_descriptor ss_ep_out_desc = { | ||
228 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
229 | .bDescriptorType = USB_DT_ENDPOINT, | ||
230 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
231 | .wMaxPacketSize = cpu_to_le16(1024), | ||
232 | }; | ||
233 | |||
234 | static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = { | ||
235 | .bLength = sizeof(ss_ep_out_comp_desc), | ||
236 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
237 | }; | ||
238 | |||
239 | static struct usb_descriptor_header *ss_printer_function[] = { | ||
240 | (struct usb_descriptor_header *) &intf_desc, | ||
241 | (struct usb_descriptor_header *) &ss_ep_in_desc, | ||
242 | (struct usb_descriptor_header *) &ss_ep_in_comp_desc, | ||
243 | (struct usb_descriptor_header *) &ss_ep_out_desc, | ||
244 | (struct usb_descriptor_header *) &ss_ep_out_comp_desc, | ||
245 | NULL | ||
246 | }; | ||
247 | |||
248 | static struct usb_otg_descriptor otg_descriptor = { | 85 | static struct usb_otg_descriptor otg_descriptor = { |
249 | .bLength = sizeof otg_descriptor, | 86 | .bLength = sizeof otg_descriptor, |
250 | .bDescriptorType = USB_DT_OTG, | 87 | .bDescriptorType = USB_DT_OTG, |
@@ -256,29 +93,13 @@ static const struct usb_descriptor_header *otg_desc[] = { | |||
256 | NULL, | 93 | NULL, |
257 | }; | 94 | }; |
258 | 95 | ||
259 | /* maxpacket and other transfer characteristics vary by speed. */ | ||
260 | static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget, | ||
261 | struct usb_endpoint_descriptor *fs, | ||
262 | struct usb_endpoint_descriptor *hs, | ||
263 | struct usb_endpoint_descriptor *ss) | ||
264 | { | ||
265 | switch (gadget->speed) { | ||
266 | case USB_SPEED_SUPER: | ||
267 | return ss; | ||
268 | case USB_SPEED_HIGH: | ||
269 | return hs; | ||
270 | default: | ||
271 | return fs; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | /*-------------------------------------------------------------------------*/ | 96 | /*-------------------------------------------------------------------------*/ |
276 | 97 | ||
277 | /* descriptors that are built on-demand */ | 98 | /* descriptors that are built on-demand */ |
278 | 99 | ||
279 | static char product_desc [40] = DRIVER_DESC; | 100 | static char product_desc [40] = DRIVER_DESC; |
280 | static char serial_num [40] = "1"; | 101 | static char serial_num [40] = "1"; |
281 | static char pnp_string [1024] = | 102 | static char pnp_string[PNP_STRING_LEN] = |
282 | "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;"; | 103 | "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;"; |
283 | 104 | ||
284 | /* static strings, in UTF-8 */ | 105 | /* static strings, in UTF-8 */ |
@@ -299,921 +120,19 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
299 | NULL, | 120 | NULL, |
300 | }; | 121 | }; |
301 | 122 | ||
302 | /*-------------------------------------------------------------------------*/ | ||
303 | |||
304 | static struct usb_request * | ||
305 | printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags) | ||
306 | { | ||
307 | struct usb_request *req; | ||
308 | |||
309 | req = usb_ep_alloc_request(ep, gfp_flags); | ||
310 | |||
311 | if (req != NULL) { | ||
312 | req->length = len; | ||
313 | req->buf = kmalloc(len, gfp_flags); | ||
314 | if (req->buf == NULL) { | ||
315 | usb_ep_free_request(ep, req); | ||
316 | return NULL; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return req; | ||
321 | } | ||
322 | |||
323 | static void | ||
324 | printer_req_free(struct usb_ep *ep, struct usb_request *req) | ||
325 | { | ||
326 | if (ep != NULL && req != NULL) { | ||
327 | kfree(req->buf); | ||
328 | usb_ep_free_request(ep, req); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | /*-------------------------------------------------------------------------*/ | ||
333 | |||
334 | static void rx_complete(struct usb_ep *ep, struct usb_request *req) | ||
335 | { | ||
336 | struct printer_dev *dev = ep->driver_data; | ||
337 | int status = req->status; | ||
338 | unsigned long flags; | ||
339 | |||
340 | spin_lock_irqsave(&dev->lock, flags); | ||
341 | |||
342 | list_del_init(&req->list); /* Remode from Active List */ | ||
343 | |||
344 | switch (status) { | ||
345 | |||
346 | /* normal completion */ | ||
347 | case 0: | ||
348 | if (req->actual > 0) { | ||
349 | list_add_tail(&req->list, &dev->rx_buffers); | ||
350 | DBG(dev, "G_Printer : rx length %d\n", req->actual); | ||
351 | } else { | ||
352 | list_add(&req->list, &dev->rx_reqs); | ||
353 | } | ||
354 | break; | ||
355 | |||
356 | /* software-driven interface shutdown */ | ||
357 | case -ECONNRESET: /* unlink */ | ||
358 | case -ESHUTDOWN: /* disconnect etc */ | ||
359 | VDBG(dev, "rx shutdown, code %d\n", status); | ||
360 | list_add(&req->list, &dev->rx_reqs); | ||
361 | break; | ||
362 | |||
363 | /* for hardware automagic (such as pxa) */ | ||
364 | case -ECONNABORTED: /* endpoint reset */ | ||
365 | DBG(dev, "rx %s reset\n", ep->name); | ||
366 | list_add(&req->list, &dev->rx_reqs); | ||
367 | break; | ||
368 | |||
369 | /* data overrun */ | ||
370 | case -EOVERFLOW: | ||
371 | /* FALLTHROUGH */ | ||
372 | |||
373 | default: | ||
374 | DBG(dev, "rx status %d\n", status); | ||
375 | list_add(&req->list, &dev->rx_reqs); | ||
376 | break; | ||
377 | } | ||
378 | |||
379 | wake_up_interruptible(&dev->rx_wait); | ||
380 | spin_unlock_irqrestore(&dev->lock, flags); | ||
381 | } | ||
382 | |||
383 | static void tx_complete(struct usb_ep *ep, struct usb_request *req) | ||
384 | { | ||
385 | struct printer_dev *dev = ep->driver_data; | ||
386 | |||
387 | switch (req->status) { | ||
388 | default: | ||
389 | VDBG(dev, "tx err %d\n", req->status); | ||
390 | /* FALLTHROUGH */ | ||
391 | case -ECONNRESET: /* unlink */ | ||
392 | case -ESHUTDOWN: /* disconnect etc */ | ||
393 | break; | ||
394 | case 0: | ||
395 | break; | ||
396 | } | ||
397 | |||
398 | spin_lock(&dev->lock); | ||
399 | /* Take the request struct off the active list and put it on the | ||
400 | * free list. | ||
401 | */ | ||
402 | list_del_init(&req->list); | ||
403 | list_add(&req->list, &dev->tx_reqs); | ||
404 | wake_up_interruptible(&dev->tx_wait); | ||
405 | if (likely(list_empty(&dev->tx_reqs_active))) | ||
406 | wake_up_interruptible(&dev->tx_flush_wait); | ||
407 | |||
408 | spin_unlock(&dev->lock); | ||
409 | } | ||
410 | |||
411 | /*-------------------------------------------------------------------------*/ | ||
412 | |||
413 | static int | ||
414 | printer_open(struct inode *inode, struct file *fd) | ||
415 | { | ||
416 | struct printer_dev *dev; | ||
417 | unsigned long flags; | ||
418 | int ret = -EBUSY; | ||
419 | |||
420 | mutex_lock(&printer_mutex); | ||
421 | dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); | ||
422 | |||
423 | spin_lock_irqsave(&dev->lock, flags); | ||
424 | |||
425 | if (!dev->printer_cdev_open) { | ||
426 | dev->printer_cdev_open = 1; | ||
427 | fd->private_data = dev; | ||
428 | ret = 0; | ||
429 | /* Change the printer status to show that it's on-line. */ | ||
430 | dev->printer_status |= PRINTER_SELECTED; | ||
431 | } | ||
432 | |||
433 | spin_unlock_irqrestore(&dev->lock, flags); | ||
434 | |||
435 | DBG(dev, "printer_open returned %x\n", ret); | ||
436 | mutex_unlock(&printer_mutex); | ||
437 | return ret; | ||
438 | } | ||
439 | |||
440 | static int | ||
441 | printer_close(struct inode *inode, struct file *fd) | ||
442 | { | ||
443 | struct printer_dev *dev = fd->private_data; | ||
444 | unsigned long flags; | ||
445 | |||
446 | spin_lock_irqsave(&dev->lock, flags); | ||
447 | dev->printer_cdev_open = 0; | ||
448 | fd->private_data = NULL; | ||
449 | /* Change printer status to show that the printer is off-line. */ | ||
450 | dev->printer_status &= ~PRINTER_SELECTED; | ||
451 | spin_unlock_irqrestore(&dev->lock, flags); | ||
452 | |||
453 | DBG(dev, "printer_close\n"); | ||
454 | |||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | /* This function must be called with interrupts turned off. */ | ||
459 | static void | ||
460 | setup_rx_reqs(struct printer_dev *dev) | ||
461 | { | ||
462 | struct usb_request *req; | ||
463 | |||
464 | while (likely(!list_empty(&dev->rx_reqs))) { | ||
465 | int error; | ||
466 | |||
467 | req = container_of(dev->rx_reqs.next, | ||
468 | struct usb_request, list); | ||
469 | list_del_init(&req->list); | ||
470 | |||
471 | /* The USB Host sends us whatever amount of data it wants to | ||
472 | * so we always set the length field to the full USB_BUFSIZE. | ||
473 | * If the amount of data is more than the read() caller asked | ||
474 | * for it will be stored in the request buffer until it is | ||
475 | * asked for by read(). | ||
476 | */ | ||
477 | req->length = USB_BUFSIZE; | ||
478 | req->complete = rx_complete; | ||
479 | |||
480 | /* here, we unlock, and only unlock, to avoid deadlock. */ | ||
481 | spin_unlock(&dev->lock); | ||
482 | error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC); | ||
483 | spin_lock(&dev->lock); | ||
484 | if (error) { | ||
485 | DBG(dev, "rx submit --> %d\n", error); | ||
486 | list_add(&req->list, &dev->rx_reqs); | ||
487 | break; | ||
488 | } | ||
489 | /* if the req is empty, then add it into dev->rx_reqs_active. */ | ||
490 | else if (list_empty(&req->list)) { | ||
491 | list_add(&req->list, &dev->rx_reqs_active); | ||
492 | } | ||
493 | } | ||
494 | } | ||
495 | |||
496 | static ssize_t | ||
497 | printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) | ||
498 | { | ||
499 | struct printer_dev *dev = fd->private_data; | ||
500 | unsigned long flags; | ||
501 | size_t size; | ||
502 | size_t bytes_copied; | ||
503 | struct usb_request *req; | ||
504 | /* This is a pointer to the current USB rx request. */ | ||
505 | struct usb_request *current_rx_req; | ||
506 | /* This is the number of bytes in the current rx buffer. */ | ||
507 | size_t current_rx_bytes; | ||
508 | /* This is a pointer to the current rx buffer. */ | ||
509 | u8 *current_rx_buf; | ||
510 | |||
511 | if (len == 0) | ||
512 | return -EINVAL; | ||
513 | |||
514 | DBG(dev, "printer_read trying to read %d bytes\n", (int)len); | ||
515 | |||
516 | mutex_lock(&dev->lock_printer_io); | ||
517 | spin_lock_irqsave(&dev->lock, flags); | ||
518 | |||
519 | /* We will use this flag later to check if a printer reset happened | ||
520 | * after we turn interrupts back on. | ||
521 | */ | ||
522 | dev->reset_printer = 0; | ||
523 | |||
524 | setup_rx_reqs(dev); | ||
525 | |||
526 | bytes_copied = 0; | ||
527 | current_rx_req = dev->current_rx_req; | ||
528 | current_rx_bytes = dev->current_rx_bytes; | ||
529 | current_rx_buf = dev->current_rx_buf; | ||
530 | dev->current_rx_req = NULL; | ||
531 | dev->current_rx_bytes = 0; | ||
532 | dev->current_rx_buf = NULL; | ||
533 | |||
534 | /* Check if there is any data in the read buffers. Please note that | ||
535 | * current_rx_bytes is the number of bytes in the current rx buffer. | ||
536 | * If it is zero then check if there are any other rx_buffers that | ||
537 | * are on the completed list. We are only out of data if all rx | ||
538 | * buffers are empty. | ||
539 | */ | ||
540 | if ((current_rx_bytes == 0) && | ||
541 | (likely(list_empty(&dev->rx_buffers)))) { | ||
542 | /* Turn interrupts back on before sleeping. */ | ||
543 | spin_unlock_irqrestore(&dev->lock, flags); | ||
544 | |||
545 | /* | ||
546 | * If no data is available check if this is a NON-Blocking | ||
547 | * call or not. | ||
548 | */ | ||
549 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { | ||
550 | mutex_unlock(&dev->lock_printer_io); | ||
551 | return -EAGAIN; | ||
552 | } | ||
553 | |||
554 | /* Sleep until data is available */ | ||
555 | wait_event_interruptible(dev->rx_wait, | ||
556 | (likely(!list_empty(&dev->rx_buffers)))); | ||
557 | spin_lock_irqsave(&dev->lock, flags); | ||
558 | } | ||
559 | |||
560 | /* We have data to return then copy it to the caller's buffer.*/ | ||
561 | while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers))) | ||
562 | && len) { | ||
563 | if (current_rx_bytes == 0) { | ||
564 | req = container_of(dev->rx_buffers.next, | ||
565 | struct usb_request, list); | ||
566 | list_del_init(&req->list); | ||
567 | |||
568 | if (req->actual && req->buf) { | ||
569 | current_rx_req = req; | ||
570 | current_rx_bytes = req->actual; | ||
571 | current_rx_buf = req->buf; | ||
572 | } else { | ||
573 | list_add(&req->list, &dev->rx_reqs); | ||
574 | continue; | ||
575 | } | ||
576 | } | ||
577 | |||
578 | /* Don't leave irqs off while doing memory copies */ | ||
579 | spin_unlock_irqrestore(&dev->lock, flags); | ||
580 | |||
581 | if (len > current_rx_bytes) | ||
582 | size = current_rx_bytes; | ||
583 | else | ||
584 | size = len; | ||
585 | |||
586 | size -= copy_to_user(buf, current_rx_buf, size); | ||
587 | bytes_copied += size; | ||
588 | len -= size; | ||
589 | buf += size; | ||
590 | |||
591 | spin_lock_irqsave(&dev->lock, flags); | ||
592 | |||
593 | /* We've disconnected or reset so return. */ | ||
594 | if (dev->reset_printer) { | ||
595 | list_add(¤t_rx_req->list, &dev->rx_reqs); | ||
596 | spin_unlock_irqrestore(&dev->lock, flags); | ||
597 | mutex_unlock(&dev->lock_printer_io); | ||
598 | return -EAGAIN; | ||
599 | } | ||
600 | |||
601 | /* If we not returning all the data left in this RX request | ||
602 | * buffer then adjust the amount of data left in the buffer. | ||
603 | * Othewise if we are done with this RX request buffer then | ||
604 | * requeue it to get any incoming data from the USB host. | ||
605 | */ | ||
606 | if (size < current_rx_bytes) { | ||
607 | current_rx_bytes -= size; | ||
608 | current_rx_buf += size; | ||
609 | } else { | ||
610 | list_add(¤t_rx_req->list, &dev->rx_reqs); | ||
611 | current_rx_bytes = 0; | ||
612 | current_rx_buf = NULL; | ||
613 | current_rx_req = NULL; | ||
614 | } | ||
615 | } | ||
616 | |||
617 | dev->current_rx_req = current_rx_req; | ||
618 | dev->current_rx_bytes = current_rx_bytes; | ||
619 | dev->current_rx_buf = current_rx_buf; | ||
620 | |||
621 | spin_unlock_irqrestore(&dev->lock, flags); | ||
622 | mutex_unlock(&dev->lock_printer_io); | ||
623 | |||
624 | DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); | ||
625 | |||
626 | if (bytes_copied) | ||
627 | return bytes_copied; | ||
628 | else | ||
629 | return -EAGAIN; | ||
630 | } | ||
631 | |||
632 | static ssize_t | ||
633 | printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | ||
634 | { | ||
635 | struct printer_dev *dev = fd->private_data; | ||
636 | unsigned long flags; | ||
637 | size_t size; /* Amount of data in a TX request. */ | ||
638 | size_t bytes_copied = 0; | ||
639 | struct usb_request *req; | ||
640 | |||
641 | DBG(dev, "printer_write trying to send %d bytes\n", (int)len); | ||
642 | |||
643 | if (len == 0) | ||
644 | return -EINVAL; | ||
645 | |||
646 | mutex_lock(&dev->lock_printer_io); | ||
647 | spin_lock_irqsave(&dev->lock, flags); | ||
648 | |||
649 | /* Check if a printer reset happens while we have interrupts on */ | ||
650 | dev->reset_printer = 0; | ||
651 | |||
652 | /* Check if there is any available write buffers */ | ||
653 | if (likely(list_empty(&dev->tx_reqs))) { | ||
654 | /* Turn interrupts back on before sleeping. */ | ||
655 | spin_unlock_irqrestore(&dev->lock, flags); | ||
656 | |||
657 | /* | ||
658 | * If write buffers are available check if this is | ||
659 | * a NON-Blocking call or not. | ||
660 | */ | ||
661 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { | ||
662 | mutex_unlock(&dev->lock_printer_io); | ||
663 | return -EAGAIN; | ||
664 | } | ||
665 | |||
666 | /* Sleep until a write buffer is available */ | ||
667 | wait_event_interruptible(dev->tx_wait, | ||
668 | (likely(!list_empty(&dev->tx_reqs)))); | ||
669 | spin_lock_irqsave(&dev->lock, flags); | ||
670 | } | ||
671 | |||
672 | while (likely(!list_empty(&dev->tx_reqs)) && len) { | ||
673 | |||
674 | if (len > USB_BUFSIZE) | ||
675 | size = USB_BUFSIZE; | ||
676 | else | ||
677 | size = len; | ||
678 | |||
679 | req = container_of(dev->tx_reqs.next, struct usb_request, | ||
680 | list); | ||
681 | list_del_init(&req->list); | ||
682 | |||
683 | req->complete = tx_complete; | ||
684 | req->length = size; | ||
685 | |||
686 | /* Check if we need to send a zero length packet. */ | ||
687 | if (len > size) | ||
688 | /* They will be more TX requests so no yet. */ | ||
689 | req->zero = 0; | ||
690 | else | ||
691 | /* If the data amount is not a multple of the | ||
692 | * maxpacket size then send a zero length packet. | ||
693 | */ | ||
694 | req->zero = ((len % dev->in_ep->maxpacket) == 0); | ||
695 | |||
696 | /* Don't leave irqs off while doing memory copies */ | ||
697 | spin_unlock_irqrestore(&dev->lock, flags); | ||
698 | |||
699 | if (copy_from_user(req->buf, buf, size)) { | ||
700 | list_add(&req->list, &dev->tx_reqs); | ||
701 | mutex_unlock(&dev->lock_printer_io); | ||
702 | return bytes_copied; | ||
703 | } | ||
704 | |||
705 | bytes_copied += size; | ||
706 | len -= size; | ||
707 | buf += size; | ||
708 | |||
709 | spin_lock_irqsave(&dev->lock, flags); | ||
710 | |||
711 | /* We've disconnected or reset so free the req and buffer */ | ||
712 | if (dev->reset_printer) { | ||
713 | list_add(&req->list, &dev->tx_reqs); | ||
714 | spin_unlock_irqrestore(&dev->lock, flags); | ||
715 | mutex_unlock(&dev->lock_printer_io); | ||
716 | return -EAGAIN; | ||
717 | } | ||
718 | |||
719 | if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { | ||
720 | list_add(&req->list, &dev->tx_reqs); | ||
721 | spin_unlock_irqrestore(&dev->lock, flags); | ||
722 | mutex_unlock(&dev->lock_printer_io); | ||
723 | return -EAGAIN; | ||
724 | } | ||
725 | |||
726 | list_add(&req->list, &dev->tx_reqs_active); | ||
727 | |||
728 | } | ||
729 | |||
730 | spin_unlock_irqrestore(&dev->lock, flags); | ||
731 | mutex_unlock(&dev->lock_printer_io); | ||
732 | |||
733 | DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); | ||
734 | |||
735 | if (bytes_copied) { | ||
736 | return bytes_copied; | ||
737 | } else { | ||
738 | return -EAGAIN; | ||
739 | } | ||
740 | } | ||
741 | |||
742 | static int | ||
743 | printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync) | ||
744 | { | ||
745 | struct printer_dev *dev = fd->private_data; | ||
746 | struct inode *inode = file_inode(fd); | ||
747 | unsigned long flags; | ||
748 | int tx_list_empty; | ||
749 | |||
750 | mutex_lock(&inode->i_mutex); | ||
751 | spin_lock_irqsave(&dev->lock, flags); | ||
752 | tx_list_empty = (likely(list_empty(&dev->tx_reqs))); | ||
753 | spin_unlock_irqrestore(&dev->lock, flags); | ||
754 | |||
755 | if (!tx_list_empty) { | ||
756 | /* Sleep until all data has been sent */ | ||
757 | wait_event_interruptible(dev->tx_flush_wait, | ||
758 | (likely(list_empty(&dev->tx_reqs_active)))); | ||
759 | } | ||
760 | mutex_unlock(&inode->i_mutex); | ||
761 | |||
762 | return 0; | ||
763 | } | ||
764 | |||
765 | static unsigned int | ||
766 | printer_poll(struct file *fd, poll_table *wait) | ||
767 | { | ||
768 | struct printer_dev *dev = fd->private_data; | ||
769 | unsigned long flags; | ||
770 | int status = 0; | ||
771 | |||
772 | mutex_lock(&dev->lock_printer_io); | ||
773 | spin_lock_irqsave(&dev->lock, flags); | ||
774 | setup_rx_reqs(dev); | ||
775 | spin_unlock_irqrestore(&dev->lock, flags); | ||
776 | mutex_unlock(&dev->lock_printer_io); | ||
777 | |||
778 | poll_wait(fd, &dev->rx_wait, wait); | ||
779 | poll_wait(fd, &dev->tx_wait, wait); | ||
780 | |||
781 | spin_lock_irqsave(&dev->lock, flags); | ||
782 | if (likely(!list_empty(&dev->tx_reqs))) | ||
783 | status |= POLLOUT | POLLWRNORM; | ||
784 | |||
785 | if (likely(dev->current_rx_bytes) || | ||
786 | likely(!list_empty(&dev->rx_buffers))) | ||
787 | status |= POLLIN | POLLRDNORM; | ||
788 | |||
789 | spin_unlock_irqrestore(&dev->lock, flags); | ||
790 | |||
791 | return status; | ||
792 | } | ||
793 | |||
794 | static long | ||
795 | printer_ioctl(struct file *fd, unsigned int code, unsigned long arg) | ||
796 | { | ||
797 | struct printer_dev *dev = fd->private_data; | ||
798 | unsigned long flags; | ||
799 | int status = 0; | ||
800 | |||
801 | DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg); | ||
802 | |||
803 | /* handle ioctls */ | ||
804 | |||
805 | spin_lock_irqsave(&dev->lock, flags); | ||
806 | |||
807 | switch (code) { | ||
808 | case GADGET_GET_PRINTER_STATUS: | ||
809 | status = (int)dev->printer_status; | ||
810 | break; | ||
811 | case GADGET_SET_PRINTER_STATUS: | ||
812 | dev->printer_status = (u8)arg; | ||
813 | break; | ||
814 | default: | ||
815 | /* could not handle ioctl */ | ||
816 | DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n", | ||
817 | code); | ||
818 | status = -ENOTTY; | ||
819 | } | ||
820 | |||
821 | spin_unlock_irqrestore(&dev->lock, flags); | ||
822 | |||
823 | return status; | ||
824 | } | ||
825 | |||
826 | /* used after endpoint configuration */ | ||
827 | static const struct file_operations printer_io_operations = { | ||
828 | .owner = THIS_MODULE, | ||
829 | .open = printer_open, | ||
830 | .read = printer_read, | ||
831 | .write = printer_write, | ||
832 | .fsync = printer_fsync, | ||
833 | .poll = printer_poll, | ||
834 | .unlocked_ioctl = printer_ioctl, | ||
835 | .release = printer_close, | ||
836 | .llseek = noop_llseek, | ||
837 | }; | ||
838 | |||
839 | /*-------------------------------------------------------------------------*/ | ||
840 | |||
841 | static int | ||
842 | set_printer_interface(struct printer_dev *dev) | ||
843 | { | ||
844 | int result = 0; | ||
845 | |||
846 | dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc, | ||
847 | &ss_ep_in_desc); | ||
848 | dev->in_ep->driver_data = dev; | ||
849 | |||
850 | dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc, | ||
851 | &hs_ep_out_desc, &ss_ep_out_desc); | ||
852 | dev->out_ep->driver_data = dev; | ||
853 | |||
854 | result = usb_ep_enable(dev->in_ep); | ||
855 | if (result != 0) { | ||
856 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); | ||
857 | goto done; | ||
858 | } | ||
859 | |||
860 | result = usb_ep_enable(dev->out_ep); | ||
861 | if (result != 0) { | ||
862 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); | ||
863 | goto done; | ||
864 | } | ||
865 | |||
866 | done: | ||
867 | /* on error, disable any endpoints */ | ||
868 | if (result != 0) { | ||
869 | (void) usb_ep_disable(dev->in_ep); | ||
870 | (void) usb_ep_disable(dev->out_ep); | ||
871 | dev->in_ep->desc = NULL; | ||
872 | dev->out_ep->desc = NULL; | ||
873 | } | ||
874 | |||
875 | /* caller is responsible for cleanup on error */ | ||
876 | return result; | ||
877 | } | ||
878 | |||
879 | static void printer_reset_interface(struct printer_dev *dev) | ||
880 | { | ||
881 | if (dev->interface < 0) | ||
882 | return; | ||
883 | |||
884 | DBG(dev, "%s\n", __func__); | ||
885 | |||
886 | if (dev->in_ep->desc) | ||
887 | usb_ep_disable(dev->in_ep); | ||
888 | |||
889 | if (dev->out_ep->desc) | ||
890 | usb_ep_disable(dev->out_ep); | ||
891 | |||
892 | dev->in_ep->desc = NULL; | ||
893 | dev->out_ep->desc = NULL; | ||
894 | dev->interface = -1; | ||
895 | } | ||
896 | |||
897 | /* Change our operational Interface. */ | ||
898 | static int set_interface(struct printer_dev *dev, unsigned number) | ||
899 | { | ||
900 | int result = 0; | ||
901 | |||
902 | /* Free the current interface */ | ||
903 | printer_reset_interface(dev); | ||
904 | |||
905 | result = set_printer_interface(dev); | ||
906 | if (result) | ||
907 | printer_reset_interface(dev); | ||
908 | else | ||
909 | dev->interface = number; | ||
910 | |||
911 | if (!result) | ||
912 | INFO(dev, "Using interface %x\n", number); | ||
913 | |||
914 | return result; | ||
915 | } | ||
916 | |||
917 | static void printer_soft_reset(struct printer_dev *dev) | ||
918 | { | ||
919 | struct usb_request *req; | ||
920 | |||
921 | INFO(dev, "Received Printer Reset Request\n"); | ||
922 | |||
923 | if (usb_ep_disable(dev->in_ep)) | ||
924 | DBG(dev, "Failed to disable USB in_ep\n"); | ||
925 | if (usb_ep_disable(dev->out_ep)) | ||
926 | DBG(dev, "Failed to disable USB out_ep\n"); | ||
927 | |||
928 | if (dev->current_rx_req != NULL) { | ||
929 | list_add(&dev->current_rx_req->list, &dev->rx_reqs); | ||
930 | dev->current_rx_req = NULL; | ||
931 | } | ||
932 | dev->current_rx_bytes = 0; | ||
933 | dev->current_rx_buf = NULL; | ||
934 | dev->reset_printer = 1; | ||
935 | |||
936 | while (likely(!(list_empty(&dev->rx_buffers)))) { | ||
937 | req = container_of(dev->rx_buffers.next, struct usb_request, | ||
938 | list); | ||
939 | list_del_init(&req->list); | ||
940 | list_add(&req->list, &dev->rx_reqs); | ||
941 | } | ||
942 | |||
943 | while (likely(!(list_empty(&dev->rx_reqs_active)))) { | ||
944 | req = container_of(dev->rx_buffers.next, struct usb_request, | ||
945 | list); | ||
946 | list_del_init(&req->list); | ||
947 | list_add(&req->list, &dev->rx_reqs); | ||
948 | } | ||
949 | |||
950 | while (likely(!(list_empty(&dev->tx_reqs_active)))) { | ||
951 | req = container_of(dev->tx_reqs_active.next, | ||
952 | struct usb_request, list); | ||
953 | list_del_init(&req->list); | ||
954 | list_add(&req->list, &dev->tx_reqs); | ||
955 | } | ||
956 | |||
957 | if (usb_ep_enable(dev->in_ep)) | ||
958 | DBG(dev, "Failed to enable USB in_ep\n"); | ||
959 | if (usb_ep_enable(dev->out_ep)) | ||
960 | DBG(dev, "Failed to enable USB out_ep\n"); | ||
961 | |||
962 | wake_up_interruptible(&dev->rx_wait); | ||
963 | wake_up_interruptible(&dev->tx_wait); | ||
964 | wake_up_interruptible(&dev->tx_flush_wait); | ||
965 | } | ||
966 | |||
967 | /*-------------------------------------------------------------------------*/ | ||
968 | |||
969 | /* | ||
970 | * The setup() callback implements all the ep0 functionality that's not | ||
971 | * handled lower down. | ||
972 | */ | ||
973 | static int printer_func_setup(struct usb_function *f, | ||
974 | const struct usb_ctrlrequest *ctrl) | ||
975 | { | ||
976 | struct printer_dev *dev = container_of(f, struct printer_dev, function); | ||
977 | struct usb_composite_dev *cdev = f->config->cdev; | ||
978 | struct usb_request *req = cdev->req; | ||
979 | int value = -EOPNOTSUPP; | ||
980 | u16 wIndex = le16_to_cpu(ctrl->wIndex); | ||
981 | u16 wValue = le16_to_cpu(ctrl->wValue); | ||
982 | u16 wLength = le16_to_cpu(ctrl->wLength); | ||
983 | |||
984 | DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", | ||
985 | ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); | ||
986 | |||
987 | switch (ctrl->bRequestType&USB_TYPE_MASK) { | ||
988 | case USB_TYPE_CLASS: | ||
989 | switch (ctrl->bRequest) { | ||
990 | case 0: /* Get the IEEE-1284 PNP String */ | ||
991 | /* Only one printer interface is supported. */ | ||
992 | if ((wIndex>>8) != dev->interface) | ||
993 | break; | ||
994 | |||
995 | value = (pnp_string[0]<<8)|pnp_string[1]; | ||
996 | memcpy(req->buf, pnp_string, value); | ||
997 | DBG(dev, "1284 PNP String: %x %s\n", value, | ||
998 | &pnp_string[2]); | ||
999 | break; | ||
1000 | |||
1001 | case 1: /* Get Port Status */ | ||
1002 | /* Only one printer interface is supported. */ | ||
1003 | if (wIndex != dev->interface) | ||
1004 | break; | ||
1005 | |||
1006 | *(u8 *)req->buf = dev->printer_status; | ||
1007 | value = min(wLength, (u16) 1); | ||
1008 | break; | ||
1009 | |||
1010 | case 2: /* Soft Reset */ | ||
1011 | /* Only one printer interface is supported. */ | ||
1012 | if (wIndex != dev->interface) | ||
1013 | break; | ||
1014 | |||
1015 | printer_soft_reset(dev); | ||
1016 | |||
1017 | value = 0; | ||
1018 | break; | ||
1019 | |||
1020 | default: | ||
1021 | goto unknown; | ||
1022 | } | ||
1023 | break; | ||
1024 | |||
1025 | default: | ||
1026 | unknown: | ||
1027 | VDBG(dev, | ||
1028 | "unknown ctrl req%02x.%02x v%04x i%04x l%d\n", | ||
1029 | ctrl->bRequestType, ctrl->bRequest, | ||
1030 | wValue, wIndex, wLength); | ||
1031 | break; | ||
1032 | } | ||
1033 | /* host either stalls (value < 0) or reports success */ | ||
1034 | return value; | ||
1035 | } | ||
1036 | |||
1037 | static int __init printer_func_bind(struct usb_configuration *c, | ||
1038 | struct usb_function *f) | ||
1039 | { | ||
1040 | struct printer_dev *dev = container_of(f, struct printer_dev, function); | ||
1041 | struct usb_composite_dev *cdev = c->cdev; | ||
1042 | struct usb_ep *in_ep; | ||
1043 | struct usb_ep *out_ep = NULL; | ||
1044 | int id; | ||
1045 | int ret; | ||
1046 | |||
1047 | id = usb_interface_id(c, f); | ||
1048 | if (id < 0) | ||
1049 | return id; | ||
1050 | intf_desc.bInterfaceNumber = id; | ||
1051 | |||
1052 | /* all we really need is bulk IN/OUT */ | ||
1053 | in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc); | ||
1054 | if (!in_ep) { | ||
1055 | autoconf_fail: | ||
1056 | dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n", | ||
1057 | cdev->gadget->name); | ||
1058 | return -ENODEV; | ||
1059 | } | ||
1060 | in_ep->driver_data = in_ep; /* claim */ | ||
1061 | |||
1062 | out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc); | ||
1063 | if (!out_ep) | ||
1064 | goto autoconf_fail; | ||
1065 | out_ep->driver_data = out_ep; /* claim */ | ||
1066 | |||
1067 | /* assumes that all endpoints are dual-speed */ | ||
1068 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | ||
1069 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | ||
1070 | ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | ||
1071 | ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | ||
1072 | |||
1073 | ret = usb_assign_descriptors(f, fs_printer_function, | ||
1074 | hs_printer_function, ss_printer_function); | ||
1075 | if (ret) | ||
1076 | return ret; | ||
1077 | |||
1078 | dev->in_ep = in_ep; | ||
1079 | dev->out_ep = out_ep; | ||
1080 | return 0; | ||
1081 | } | ||
1082 | |||
1083 | static void printer_func_unbind(struct usb_configuration *c, | ||
1084 | struct usb_function *f) | ||
1085 | { | ||
1086 | usb_free_all_descriptors(f); | ||
1087 | } | ||
1088 | |||
1089 | static int printer_func_set_alt(struct usb_function *f, | ||
1090 | unsigned intf, unsigned alt) | ||
1091 | { | ||
1092 | struct printer_dev *dev = container_of(f, struct printer_dev, function); | ||
1093 | int ret = -ENOTSUPP; | ||
1094 | |||
1095 | if (!alt) | ||
1096 | ret = set_interface(dev, intf); | ||
1097 | |||
1098 | return ret; | ||
1099 | } | ||
1100 | |||
1101 | static void printer_func_disable(struct usb_function *f) | ||
1102 | { | ||
1103 | struct printer_dev *dev = container_of(f, struct printer_dev, function); | ||
1104 | unsigned long flags; | ||
1105 | |||
1106 | DBG(dev, "%s\n", __func__); | ||
1107 | |||
1108 | spin_lock_irqsave(&dev->lock, flags); | ||
1109 | printer_reset_interface(dev); | ||
1110 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1111 | } | ||
1112 | |||
1113 | static void printer_cfg_unbind(struct usb_configuration *c) | ||
1114 | { | ||
1115 | struct printer_dev *dev; | ||
1116 | struct usb_request *req; | ||
1117 | |||
1118 | dev = &usb_printer_gadget; | ||
1119 | |||
1120 | DBG(dev, "%s\n", __func__); | ||
1121 | |||
1122 | /* Remove sysfs files */ | ||
1123 | device_destroy(usb_gadget_class, g_printer_devno); | ||
1124 | |||
1125 | /* Remove Character Device */ | ||
1126 | cdev_del(&dev->printer_cdev); | ||
1127 | |||
1128 | /* we must already have been disconnected ... no i/o may be active */ | ||
1129 | WARN_ON(!list_empty(&dev->tx_reqs_active)); | ||
1130 | WARN_ON(!list_empty(&dev->rx_reqs_active)); | ||
1131 | |||
1132 | /* Free all memory for this driver. */ | ||
1133 | while (!list_empty(&dev->tx_reqs)) { | ||
1134 | req = container_of(dev->tx_reqs.next, struct usb_request, | ||
1135 | list); | ||
1136 | list_del(&req->list); | ||
1137 | printer_req_free(dev->in_ep, req); | ||
1138 | } | ||
1139 | |||
1140 | if (dev->current_rx_req != NULL) | ||
1141 | printer_req_free(dev->out_ep, dev->current_rx_req); | ||
1142 | |||
1143 | while (!list_empty(&dev->rx_reqs)) { | ||
1144 | req = container_of(dev->rx_reqs.next, | ||
1145 | struct usb_request, list); | ||
1146 | list_del(&req->list); | ||
1147 | printer_req_free(dev->out_ep, req); | ||
1148 | } | ||
1149 | |||
1150 | while (!list_empty(&dev->rx_buffers)) { | ||
1151 | req = container_of(dev->rx_buffers.next, | ||
1152 | struct usb_request, list); | ||
1153 | list_del(&req->list); | ||
1154 | printer_req_free(dev->out_ep, req); | ||
1155 | } | ||
1156 | } | ||
1157 | |||
1158 | static struct usb_configuration printer_cfg_driver = { | 123 | static struct usb_configuration printer_cfg_driver = { |
1159 | .label = "printer", | 124 | .label = "printer", |
1160 | .unbind = printer_cfg_unbind, | ||
1161 | .bConfigurationValue = 1, | 125 | .bConfigurationValue = 1, |
1162 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | 126 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
1163 | }; | 127 | }; |
1164 | 128 | ||
1165 | static int __init printer_bind_config(struct usb_configuration *c) | 129 | static int __init printer_do_config(struct usb_configuration *c) |
1166 | { | 130 | { |
1167 | struct usb_gadget *gadget = c->cdev->gadget; | 131 | struct usb_gadget *gadget = c->cdev->gadget; |
1168 | struct printer_dev *dev; | 132 | int status = 0; |
1169 | int status = -ENOMEM; | ||
1170 | size_t len; | ||
1171 | u32 i; | ||
1172 | struct usb_request *req; | ||
1173 | 133 | ||
1174 | usb_ep_autoconfig_reset(gadget); | 134 | usb_ep_autoconfig_reset(gadget); |
1175 | 135 | ||
1176 | dev = &usb_printer_gadget; | ||
1177 | |||
1178 | dev->function.name = shortname; | ||
1179 | dev->function.bind = printer_func_bind; | ||
1180 | dev->function.setup = printer_func_setup; | ||
1181 | dev->function.unbind = printer_func_unbind; | ||
1182 | dev->function.set_alt = printer_func_set_alt; | ||
1183 | dev->function.disable = printer_func_disable; | ||
1184 | |||
1185 | status = usb_add_function(c, &dev->function); | ||
1186 | if (status) | ||
1187 | return status; | ||
1188 | |||
1189 | /* Setup the sysfs files for the printer gadget. */ | ||
1190 | dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, | ||
1191 | NULL, "g_printer"); | ||
1192 | if (IS_ERR(dev->pdev)) { | ||
1193 | ERROR(dev, "Failed to create device: g_printer\n"); | ||
1194 | status = PTR_ERR(dev->pdev); | ||
1195 | goto fail; | ||
1196 | } | ||
1197 | |||
1198 | /* | ||
1199 | * Register a character device as an interface to a user mode | ||
1200 | * program that handles the printer specific functionality. | ||
1201 | */ | ||
1202 | cdev_init(&dev->printer_cdev, &printer_io_operations); | ||
1203 | dev->printer_cdev.owner = THIS_MODULE; | ||
1204 | status = cdev_add(&dev->printer_cdev, g_printer_devno, 1); | ||
1205 | if (status) { | ||
1206 | ERROR(dev, "Failed to open char device\n"); | ||
1207 | goto fail; | ||
1208 | } | ||
1209 | |||
1210 | if (iPNPstring) | ||
1211 | strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2); | ||
1212 | |||
1213 | len = strlen(pnp_string); | ||
1214 | pnp_string[0] = (len >> 8) & 0xFF; | ||
1215 | pnp_string[1] = len & 0xFF; | ||
1216 | |||
1217 | usb_gadget_set_selfpowered(gadget); | 136 | usb_gadget_set_selfpowered(gadget); |
1218 | 137 | ||
1219 | if (gadget_is_otg(gadget)) { | 138 | if (gadget_is_otg(gadget)) { |
@@ -1222,86 +141,64 @@ static int __init printer_bind_config(struct usb_configuration *c) | |||
1222 | printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 141 | printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
1223 | } | 142 | } |
1224 | 143 | ||
1225 | spin_lock_init(&dev->lock); | 144 | f_printer = usb_get_function(fi_printer); |
1226 | mutex_init(&dev->lock_printer_io); | 145 | if (IS_ERR(f_printer)) |
1227 | INIT_LIST_HEAD(&dev->tx_reqs); | 146 | return PTR_ERR(f_printer); |
1228 | INIT_LIST_HEAD(&dev->tx_reqs_active); | ||
1229 | INIT_LIST_HEAD(&dev->rx_reqs); | ||
1230 | INIT_LIST_HEAD(&dev->rx_reqs_active); | ||
1231 | INIT_LIST_HEAD(&dev->rx_buffers); | ||
1232 | init_waitqueue_head(&dev->rx_wait); | ||
1233 | init_waitqueue_head(&dev->tx_wait); | ||
1234 | init_waitqueue_head(&dev->tx_flush_wait); | ||
1235 | |||
1236 | dev->interface = -1; | ||
1237 | dev->printer_cdev_open = 0; | ||
1238 | dev->printer_status = PRINTER_NOT_ERROR; | ||
1239 | dev->current_rx_req = NULL; | ||
1240 | dev->current_rx_bytes = 0; | ||
1241 | dev->current_rx_buf = NULL; | ||
1242 | |||
1243 | for (i = 0; i < QLEN; i++) { | ||
1244 | req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); | ||
1245 | if (!req) { | ||
1246 | while (!list_empty(&dev->tx_reqs)) { | ||
1247 | req = container_of(dev->tx_reqs.next, | ||
1248 | struct usb_request, list); | ||
1249 | list_del(&req->list); | ||
1250 | printer_req_free(dev->in_ep, req); | ||
1251 | } | ||
1252 | return -ENOMEM; | ||
1253 | } | ||
1254 | list_add(&req->list, &dev->tx_reqs); | ||
1255 | } | ||
1256 | |||
1257 | for (i = 0; i < QLEN; i++) { | ||
1258 | req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); | ||
1259 | if (!req) { | ||
1260 | while (!list_empty(&dev->rx_reqs)) { | ||
1261 | req = container_of(dev->rx_reqs.next, | ||
1262 | struct usb_request, list); | ||
1263 | list_del(&req->list); | ||
1264 | printer_req_free(dev->out_ep, req); | ||
1265 | } | ||
1266 | return -ENOMEM; | ||
1267 | } | ||
1268 | list_add(&req->list, &dev->rx_reqs); | ||
1269 | } | ||
1270 | |||
1271 | /* finish hookup to lower layer ... */ | ||
1272 | dev->gadget = gadget; | ||
1273 | 147 | ||
1274 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); | 148 | status = usb_add_function(c, f_printer); |
1275 | return 0; | 149 | if (status < 0) |
150 | usb_put_function(f_printer); | ||
1276 | 151 | ||
1277 | fail: | ||
1278 | printer_cfg_unbind(c); | ||
1279 | return status; | 152 | return status; |
1280 | } | 153 | } |
1281 | 154 | ||
1282 | static int printer_unbind(struct usb_composite_dev *cdev) | ||
1283 | { | ||
1284 | return 0; | ||
1285 | } | ||
1286 | |||
1287 | static int __init printer_bind(struct usb_composite_dev *cdev) | 155 | static int __init printer_bind(struct usb_composite_dev *cdev) |
1288 | { | 156 | { |
1289 | int ret; | 157 | struct f_printer_opts *opts; |
158 | int ret, len; | ||
159 | |||
160 | fi_printer = usb_get_function_instance("printer"); | ||
161 | if (IS_ERR(fi_printer)) | ||
162 | return PTR_ERR(fi_printer); | ||
163 | |||
164 | if (iPNPstring) | ||
165 | strlcpy(&pnp_string[2], iPNPstring, PNP_STRING_LEN - 2); | ||
166 | |||
167 | len = strlen(pnp_string); | ||
168 | pnp_string[0] = (len >> 8) & 0xFF; | ||
169 | pnp_string[1] = len & 0xFF; | ||
170 | |||
171 | opts = container_of(fi_printer, struct f_printer_opts, func_inst); | ||
172 | opts->minor = 0; | ||
173 | memcpy(opts->pnp_string, pnp_string, PNP_STRING_LEN); | ||
174 | opts->q_len = QLEN; | ||
1290 | 175 | ||
1291 | ret = usb_string_ids_tab(cdev, strings); | 176 | ret = usb_string_ids_tab(cdev, strings); |
1292 | if (ret < 0) | 177 | if (ret < 0) { |
178 | usb_put_function_instance(fi_printer); | ||
1293 | return ret; | 179 | return ret; |
180 | } | ||
1294 | device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id; | 181 | device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id; |
1295 | device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id; | 182 | device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id; |
1296 | device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id; | 183 | device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id; |
1297 | 184 | ||
1298 | ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); | 185 | ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config); |
1299 | if (ret) | 186 | if (ret) { |
187 | usb_put_function_instance(fi_printer); | ||
1300 | return ret; | 188 | return ret; |
189 | } | ||
1301 | usb_composite_overwrite_options(cdev, &coverwrite); | 190 | usb_composite_overwrite_options(cdev, &coverwrite); |
1302 | return ret; | 191 | return ret; |
1303 | } | 192 | } |
1304 | 193 | ||
194 | static int __exit printer_unbind(struct usb_composite_dev *cdev) | ||
195 | { | ||
196 | usb_put_function(f_printer); | ||
197 | usb_put_function_instance(fi_printer); | ||
198 | |||
199 | return 0; | ||
200 | } | ||
201 | |||
1305 | static __refdata struct usb_composite_driver printer_driver = { | 202 | static __refdata struct usb_composite_driver printer_driver = { |
1306 | .name = shortname, | 203 | .name = shortname, |
1307 | .dev = &device_desc, | 204 | .dev = &device_desc, |
@@ -1311,47 +208,7 @@ static __refdata struct usb_composite_driver printer_driver = { | |||
1311 | .unbind = printer_unbind, | 208 | .unbind = printer_unbind, |
1312 | }; | 209 | }; |
1313 | 210 | ||
1314 | static int __init | 211 | module_usb_composite_driver(printer_driver); |
1315 | init(void) | ||
1316 | { | ||
1317 | int status; | ||
1318 | |||
1319 | usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); | ||
1320 | if (IS_ERR(usb_gadget_class)) { | ||
1321 | status = PTR_ERR(usb_gadget_class); | ||
1322 | pr_err("unable to create usb_gadget class %d\n", status); | ||
1323 | return status; | ||
1324 | } | ||
1325 | |||
1326 | status = alloc_chrdev_region(&g_printer_devno, 0, 1, | ||
1327 | "USB printer gadget"); | ||
1328 | if (status) { | ||
1329 | pr_err("alloc_chrdev_region %d\n", status); | ||
1330 | class_destroy(usb_gadget_class); | ||
1331 | return status; | ||
1332 | } | ||
1333 | |||
1334 | status = usb_composite_probe(&printer_driver); | ||
1335 | if (status) { | ||
1336 | class_destroy(usb_gadget_class); | ||
1337 | unregister_chrdev_region(g_printer_devno, 1); | ||
1338 | pr_err("usb_gadget_probe_driver %x\n", status); | ||
1339 | } | ||
1340 | |||
1341 | return status; | ||
1342 | } | ||
1343 | module_init(init); | ||
1344 | |||
1345 | static void __exit | ||
1346 | cleanup(void) | ||
1347 | { | ||
1348 | mutex_lock(&usb_printer_gadget.lock_printer_io); | ||
1349 | usb_composite_unregister(&printer_driver); | ||
1350 | unregister_chrdev_region(g_printer_devno, 1); | ||
1351 | class_destroy(usb_gadget_class); | ||
1352 | mutex_unlock(&usb_printer_gadget.lock_printer_io); | ||
1353 | } | ||
1354 | module_exit(cleanup); | ||
1355 | 212 | ||
1356 | MODULE_DESCRIPTION(DRIVER_DESC); | 213 | MODULE_DESCRIPTION(DRIVER_DESC); |
1357 | MODULE_AUTHOR("Craig Nadler"); | 214 | MODULE_AUTHOR("Craig Nadler"); |
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index d79cb35dbf8a..4c01953a0869 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c | |||
@@ -152,7 +152,7 @@ static int regs_dbg_open(struct inode *inode, struct file *file) | |||
152 | 152 | ||
153 | spin_lock_irq(&udc->lock); | 153 | spin_lock_irq(&udc->lock); |
154 | for (i = 0; i < inode->i_size / 4; i++) | 154 | for (i = 0; i < inode->i_size / 4; i++) |
155 | data[i] = __raw_readl(udc->regs + i * 4); | 155 | data[i] = usba_io_readl(udc->regs + i * 4); |
156 | spin_unlock_irq(&udc->lock); | 156 | spin_unlock_irq(&udc->lock); |
157 | 157 | ||
158 | file->private_data = data; | 158 | file->private_data = data; |
@@ -1249,7 +1249,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep, | |||
1249 | if (crq->wLength != cpu_to_le16(sizeof(status))) | 1249 | if (crq->wLength != cpu_to_le16(sizeof(status))) |
1250 | goto stall; | 1250 | goto stall; |
1251 | ep->state = DATA_STAGE_IN; | 1251 | ep->state = DATA_STAGE_IN; |
1252 | __raw_writew(status, ep->fifo); | 1252 | usba_io_writew(status, ep->fifo); |
1253 | usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY); | 1253 | usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY); |
1254 | break; | 1254 | break; |
1255 | } | 1255 | } |
@@ -1739,7 +1739,72 @@ static irqreturn_t usba_udc_irq(int irq, void *devid) | |||
1739 | return IRQ_HANDLED; | 1739 | return IRQ_HANDLED; |
1740 | } | 1740 | } |
1741 | 1741 | ||
1742 | static irqreturn_t usba_vbus_irq(int irq, void *devid) | 1742 | static int start_clock(struct usba_udc *udc) |
1743 | { | ||
1744 | int ret; | ||
1745 | |||
1746 | if (udc->clocked) | ||
1747 | return 0; | ||
1748 | |||
1749 | ret = clk_prepare_enable(udc->pclk); | ||
1750 | if (ret) | ||
1751 | return ret; | ||
1752 | ret = clk_prepare_enable(udc->hclk); | ||
1753 | if (ret) { | ||
1754 | clk_disable_unprepare(udc->pclk); | ||
1755 | return ret; | ||
1756 | } | ||
1757 | |||
1758 | udc->clocked = true; | ||
1759 | return 0; | ||
1760 | } | ||
1761 | |||
1762 | static void stop_clock(struct usba_udc *udc) | ||
1763 | { | ||
1764 | if (!udc->clocked) | ||
1765 | return; | ||
1766 | |||
1767 | clk_disable_unprepare(udc->hclk); | ||
1768 | clk_disable_unprepare(udc->pclk); | ||
1769 | |||
1770 | udc->clocked = false; | ||
1771 | } | ||
1772 | |||
1773 | static int usba_start(struct usba_udc *udc) | ||
1774 | { | ||
1775 | unsigned long flags; | ||
1776 | int ret; | ||
1777 | |||
1778 | ret = start_clock(udc); | ||
1779 | if (ret) | ||
1780 | return ret; | ||
1781 | |||
1782 | spin_lock_irqsave(&udc->lock, flags); | ||
1783 | toggle_bias(udc, 1); | ||
1784 | usba_writel(udc, CTRL, USBA_ENABLE_MASK); | ||
1785 | usba_int_enb_set(udc, USBA_END_OF_RESET); | ||
1786 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1787 | |||
1788 | return 0; | ||
1789 | } | ||
1790 | |||
1791 | static void usba_stop(struct usba_udc *udc) | ||
1792 | { | ||
1793 | unsigned long flags; | ||
1794 | |||
1795 | spin_lock_irqsave(&udc->lock, flags); | ||
1796 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1797 | reset_all_endpoints(udc); | ||
1798 | |||
1799 | /* This will also disable the DP pullup */ | ||
1800 | toggle_bias(udc, 0); | ||
1801 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | ||
1802 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1803 | |||
1804 | stop_clock(udc); | ||
1805 | } | ||
1806 | |||
1807 | static irqreturn_t usba_vbus_irq_thread(int irq, void *devid) | ||
1743 | { | 1808 | { |
1744 | struct usba_udc *udc = devid; | 1809 | struct usba_udc *udc = devid; |
1745 | int vbus; | 1810 | int vbus; |
@@ -1747,35 +1812,22 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid) | |||
1747 | /* debounce */ | 1812 | /* debounce */ |
1748 | udelay(10); | 1813 | udelay(10); |
1749 | 1814 | ||
1750 | spin_lock(&udc->lock); | 1815 | mutex_lock(&udc->vbus_mutex); |
1751 | |||
1752 | /* May happen if Vbus pin toggles during probe() */ | ||
1753 | if (!udc->driver) | ||
1754 | goto out; | ||
1755 | 1816 | ||
1756 | vbus = vbus_is_present(udc); | 1817 | vbus = vbus_is_present(udc); |
1757 | if (vbus != udc->vbus_prev) { | 1818 | if (vbus != udc->vbus_prev) { |
1758 | if (vbus) { | 1819 | if (vbus) { |
1759 | toggle_bias(udc, 1); | 1820 | usba_start(udc); |
1760 | usba_writel(udc, CTRL, USBA_ENABLE_MASK); | ||
1761 | usba_int_enb_set(udc, USBA_END_OF_RESET); | ||
1762 | } else { | 1821 | } else { |
1763 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1822 | usba_stop(udc); |
1764 | reset_all_endpoints(udc); | 1823 | |
1765 | toggle_bias(udc, 0); | 1824 | if (udc->driver->disconnect) |
1766 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | ||
1767 | if (udc->driver->disconnect) { | ||
1768 | spin_unlock(&udc->lock); | ||
1769 | udc->driver->disconnect(&udc->gadget); | 1825 | udc->driver->disconnect(&udc->gadget); |
1770 | spin_lock(&udc->lock); | ||
1771 | } | ||
1772 | } | 1826 | } |
1773 | udc->vbus_prev = vbus; | 1827 | udc->vbus_prev = vbus; |
1774 | } | 1828 | } |
1775 | 1829 | ||
1776 | out: | 1830 | mutex_unlock(&udc->vbus_mutex); |
1777 | spin_unlock(&udc->lock); | ||
1778 | |||
1779 | return IRQ_HANDLED; | 1831 | return IRQ_HANDLED; |
1780 | } | 1832 | } |
1781 | 1833 | ||
@@ -1787,55 +1839,47 @@ static int atmel_usba_start(struct usb_gadget *gadget, | |||
1787 | unsigned long flags; | 1839 | unsigned long flags; |
1788 | 1840 | ||
1789 | spin_lock_irqsave(&udc->lock, flags); | 1841 | spin_lock_irqsave(&udc->lock, flags); |
1790 | |||
1791 | udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; | 1842 | udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; |
1792 | udc->driver = driver; | 1843 | udc->driver = driver; |
1793 | spin_unlock_irqrestore(&udc->lock, flags); | 1844 | spin_unlock_irqrestore(&udc->lock, flags); |
1794 | 1845 | ||
1795 | ret = clk_prepare_enable(udc->pclk); | 1846 | mutex_lock(&udc->vbus_mutex); |
1796 | if (ret) | ||
1797 | return ret; | ||
1798 | ret = clk_prepare_enable(udc->hclk); | ||
1799 | if (ret) { | ||
1800 | clk_disable_unprepare(udc->pclk); | ||
1801 | return ret; | ||
1802 | } | ||
1803 | 1847 | ||
1804 | udc->vbus_prev = 0; | ||
1805 | if (gpio_is_valid(udc->vbus_pin)) | 1848 | if (gpio_is_valid(udc->vbus_pin)) |
1806 | enable_irq(gpio_to_irq(udc->vbus_pin)); | 1849 | enable_irq(gpio_to_irq(udc->vbus_pin)); |
1807 | 1850 | ||
1808 | /* If Vbus is present, enable the controller and wait for reset */ | 1851 | /* If Vbus is present, enable the controller and wait for reset */ |
1809 | spin_lock_irqsave(&udc->lock, flags); | 1852 | udc->vbus_prev = vbus_is_present(udc); |
1810 | if (vbus_is_present(udc) && udc->vbus_prev == 0) { | 1853 | if (udc->vbus_prev) { |
1811 | toggle_bias(udc, 1); | 1854 | ret = usba_start(udc); |
1812 | usba_writel(udc, CTRL, USBA_ENABLE_MASK); | 1855 | if (ret) |
1813 | usba_int_enb_set(udc, USBA_END_OF_RESET); | 1856 | goto err; |
1814 | } | 1857 | } |
1815 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1816 | 1858 | ||
1859 | mutex_unlock(&udc->vbus_mutex); | ||
1817 | return 0; | 1860 | return 0; |
1861 | |||
1862 | err: | ||
1863 | if (gpio_is_valid(udc->vbus_pin)) | ||
1864 | disable_irq(gpio_to_irq(udc->vbus_pin)); | ||
1865 | |||
1866 | mutex_unlock(&udc->vbus_mutex); | ||
1867 | |||
1868 | spin_lock_irqsave(&udc->lock, flags); | ||
1869 | udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); | ||
1870 | udc->driver = NULL; | ||
1871 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1872 | return ret; | ||
1818 | } | 1873 | } |
1819 | 1874 | ||
1820 | static int atmel_usba_stop(struct usb_gadget *gadget) | 1875 | static int atmel_usba_stop(struct usb_gadget *gadget) |
1821 | { | 1876 | { |
1822 | struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); | 1877 | struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); |
1823 | unsigned long flags; | ||
1824 | 1878 | ||
1825 | if (gpio_is_valid(udc->vbus_pin)) | 1879 | if (gpio_is_valid(udc->vbus_pin)) |
1826 | disable_irq(gpio_to_irq(udc->vbus_pin)); | 1880 | disable_irq(gpio_to_irq(udc->vbus_pin)); |
1827 | 1881 | ||
1828 | spin_lock_irqsave(&udc->lock, flags); | 1882 | usba_stop(udc); |
1829 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1830 | reset_all_endpoints(udc); | ||
1831 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1832 | |||
1833 | /* This will also disable the DP pullup */ | ||
1834 | toggle_bias(udc, 0); | ||
1835 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | ||
1836 | |||
1837 | clk_disable_unprepare(udc->hclk); | ||
1838 | clk_disable_unprepare(udc->pclk); | ||
1839 | 1883 | ||
1840 | udc->driver = NULL; | 1884 | udc->driver = NULL; |
1841 | 1885 | ||
@@ -2057,6 +2101,7 @@ static int usba_udc_probe(struct platform_device *pdev) | |||
2057 | return PTR_ERR(hclk); | 2101 | return PTR_ERR(hclk); |
2058 | 2102 | ||
2059 | spin_lock_init(&udc->lock); | 2103 | spin_lock_init(&udc->lock); |
2104 | mutex_init(&udc->vbus_mutex); | ||
2060 | udc->pdev = pdev; | 2105 | udc->pdev = pdev; |
2061 | udc->pclk = pclk; | 2106 | udc->pclk = pclk; |
2062 | udc->hclk = hclk; | 2107 | udc->hclk = hclk; |
@@ -2111,17 +2156,17 @@ static int usba_udc_probe(struct platform_device *pdev) | |||
2111 | 2156 | ||
2112 | if (gpio_is_valid(udc->vbus_pin)) { | 2157 | if (gpio_is_valid(udc->vbus_pin)) { |
2113 | if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { | 2158 | if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { |
2114 | ret = devm_request_irq(&pdev->dev, | 2159 | irq_set_status_flags(gpio_to_irq(udc->vbus_pin), |
2115 | gpio_to_irq(udc->vbus_pin), | 2160 | IRQ_NOAUTOEN); |
2116 | usba_vbus_irq, 0, | 2161 | ret = devm_request_threaded_irq(&pdev->dev, |
2162 | gpio_to_irq(udc->vbus_pin), NULL, | ||
2163 | usba_vbus_irq_thread, IRQF_ONESHOT, | ||
2117 | "atmel_usba_udc", udc); | 2164 | "atmel_usba_udc", udc); |
2118 | if (ret) { | 2165 | if (ret) { |
2119 | udc->vbus_pin = -ENODEV; | 2166 | udc->vbus_pin = -ENODEV; |
2120 | dev_warn(&udc->pdev->dev, | 2167 | dev_warn(&udc->pdev->dev, |
2121 | "failed to request vbus irq; " | 2168 | "failed to request vbus irq; " |
2122 | "assuming always on\n"); | 2169 | "assuming always on\n"); |
2123 | } else { | ||
2124 | disable_irq(gpio_to_irq(udc->vbus_pin)); | ||
2125 | } | 2170 | } |
2126 | } else { | 2171 | } else { |
2127 | /* gpio_request fail so use -EINVAL for gpio_is_valid */ | 2172 | /* gpio_request fail so use -EINVAL for gpio_is_valid */ |
@@ -2132,6 +2177,7 @@ static int usba_udc_probe(struct platform_device *pdev) | |||
2132 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2177 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); |
2133 | if (ret) | 2178 | if (ret) |
2134 | return ret; | 2179 | return ret; |
2180 | device_init_wakeup(&pdev->dev, 1); | ||
2135 | 2181 | ||
2136 | usba_init_debugfs(udc); | 2182 | usba_init_debugfs(udc); |
2137 | for (i = 1; i < udc->num_ep; i++) | 2183 | for (i = 1; i < udc->num_ep; i++) |
@@ -2147,6 +2193,7 @@ static int __exit usba_udc_remove(struct platform_device *pdev) | |||
2147 | 2193 | ||
2148 | udc = platform_get_drvdata(pdev); | 2194 | udc = platform_get_drvdata(pdev); |
2149 | 2195 | ||
2196 | device_init_wakeup(&pdev->dev, 0); | ||
2150 | usb_del_gadget_udc(&udc->gadget); | 2197 | usb_del_gadget_udc(&udc->gadget); |
2151 | 2198 | ||
2152 | for (i = 1; i < udc->num_ep; i++) | 2199 | for (i = 1; i < udc->num_ep; i++) |
@@ -2156,10 +2203,65 @@ static int __exit usba_udc_remove(struct platform_device *pdev) | |||
2156 | return 0; | 2203 | return 0; |
2157 | } | 2204 | } |
2158 | 2205 | ||
2206 | #ifdef CONFIG_PM | ||
2207 | static int usba_udc_suspend(struct device *dev) | ||
2208 | { | ||
2209 | struct usba_udc *udc = dev_get_drvdata(dev); | ||
2210 | |||
2211 | /* Not started */ | ||
2212 | if (!udc->driver) | ||
2213 | return 0; | ||
2214 | |||
2215 | mutex_lock(&udc->vbus_mutex); | ||
2216 | |||
2217 | if (!device_may_wakeup(dev)) { | ||
2218 | usba_stop(udc); | ||
2219 | goto out; | ||
2220 | } | ||
2221 | |||
2222 | /* | ||
2223 | * Device may wake up. We stay clocked if we failed | ||
2224 | * to request vbus irq, assuming always on. | ||
2225 | */ | ||
2226 | if (gpio_is_valid(udc->vbus_pin)) { | ||
2227 | usba_stop(udc); | ||
2228 | enable_irq_wake(gpio_to_irq(udc->vbus_pin)); | ||
2229 | } | ||
2230 | |||
2231 | out: | ||
2232 | mutex_unlock(&udc->vbus_mutex); | ||
2233 | return 0; | ||
2234 | } | ||
2235 | |||
2236 | static int usba_udc_resume(struct device *dev) | ||
2237 | { | ||
2238 | struct usba_udc *udc = dev_get_drvdata(dev); | ||
2239 | |||
2240 | /* Not started */ | ||
2241 | if (!udc->driver) | ||
2242 | return 0; | ||
2243 | |||
2244 | if (device_may_wakeup(dev) && gpio_is_valid(udc->vbus_pin)) | ||
2245 | disable_irq_wake(gpio_to_irq(udc->vbus_pin)); | ||
2246 | |||
2247 | /* If Vbus is present, enable the controller and wait for reset */ | ||
2248 | mutex_lock(&udc->vbus_mutex); | ||
2249 | udc->vbus_prev = vbus_is_present(udc); | ||
2250 | if (udc->vbus_prev) | ||
2251 | usba_start(udc); | ||
2252 | mutex_unlock(&udc->vbus_mutex); | ||
2253 | |||
2254 | return 0; | ||
2255 | } | ||
2256 | #endif | ||
2257 | |||
2258 | static SIMPLE_DEV_PM_OPS(usba_udc_pm_ops, usba_udc_suspend, usba_udc_resume); | ||
2259 | |||
2159 | static struct platform_driver udc_driver = { | 2260 | static struct platform_driver udc_driver = { |
2160 | .remove = __exit_p(usba_udc_remove), | 2261 | .remove = __exit_p(usba_udc_remove), |
2161 | .driver = { | 2262 | .driver = { |
2162 | .name = "atmel_usba_udc", | 2263 | .name = "atmel_usba_udc", |
2264 | .pm = &usba_udc_pm_ops, | ||
2163 | .of_match_table = of_match_ptr(atmel_udc_dt_ids), | 2265 | .of_match_table = of_match_ptr(atmel_udc_dt_ids), |
2164 | }, | 2266 | }, |
2165 | }; | 2267 | }; |
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h b/drivers/usb/gadget/udc/atmel_usba_udc.h index 497cd18836f3..ea448a344767 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.h +++ b/drivers/usb/gadget/udc/atmel_usba_udc.h | |||
@@ -191,18 +191,28 @@ | |||
191 | | USBA_BF(name, value)) | 191 | | USBA_BF(name, value)) |
192 | 192 | ||
193 | /* Register access macros */ | 193 | /* Register access macros */ |
194 | #ifdef CONFIG_AVR32 | ||
195 | #define usba_io_readl __raw_readl | ||
196 | #define usba_io_writel __raw_writel | ||
197 | #define usba_io_writew __raw_writew | ||
198 | #else | ||
199 | #define usba_io_readl readl_relaxed | ||
200 | #define usba_io_writel writel_relaxed | ||
201 | #define usba_io_writew writew_relaxed | ||
202 | #endif | ||
203 | |||
194 | #define usba_readl(udc, reg) \ | 204 | #define usba_readl(udc, reg) \ |
195 | __raw_readl((udc)->regs + USBA_##reg) | 205 | usba_io_readl((udc)->regs + USBA_##reg) |
196 | #define usba_writel(udc, reg, value) \ | 206 | #define usba_writel(udc, reg, value) \ |
197 | __raw_writel((value), (udc)->regs + USBA_##reg) | 207 | usba_io_writel((value), (udc)->regs + USBA_##reg) |
198 | #define usba_ep_readl(ep, reg) \ | 208 | #define usba_ep_readl(ep, reg) \ |
199 | __raw_readl((ep)->ep_regs + USBA_EPT_##reg) | 209 | usba_io_readl((ep)->ep_regs + USBA_EPT_##reg) |
200 | #define usba_ep_writel(ep, reg, value) \ | 210 | #define usba_ep_writel(ep, reg, value) \ |
201 | __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg) | 211 | usba_io_writel((value), (ep)->ep_regs + USBA_EPT_##reg) |
202 | #define usba_dma_readl(ep, reg) \ | 212 | #define usba_dma_readl(ep, reg) \ |
203 | __raw_readl((ep)->dma_regs + USBA_DMA_##reg) | 213 | usba_io_readl((ep)->dma_regs + USBA_DMA_##reg) |
204 | #define usba_dma_writel(ep, reg, value) \ | 214 | #define usba_dma_writel(ep, reg, value) \ |
205 | __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg) | 215 | usba_io_writel((value), (ep)->dma_regs + USBA_DMA_##reg) |
206 | 216 | ||
207 | /* Calculate base address for a given endpoint or DMA controller */ | 217 | /* Calculate base address for a given endpoint or DMA controller */ |
208 | #define USBA_EPT_BASE(x) (0x100 + (x) * 0x20) | 218 | #define USBA_EPT_BASE(x) (0x100 + (x) * 0x20) |
@@ -313,6 +323,9 @@ struct usba_udc { | |||
313 | /* Protect hw registers from concurrent modifications */ | 323 | /* Protect hw registers from concurrent modifications */ |
314 | spinlock_t lock; | 324 | spinlock_t lock; |
315 | 325 | ||
326 | /* Mutex to prevent concurrent start or stop */ | ||
327 | struct mutex vbus_mutex; | ||
328 | |||
316 | void __iomem *regs; | 329 | void __iomem *regs; |
317 | void __iomem *fifo; | 330 | void __iomem *fifo; |
318 | 331 | ||
@@ -328,6 +341,7 @@ struct usba_udc { | |||
328 | struct clk *hclk; | 341 | struct clk *hclk; |
329 | struct usba_ep *usba_ep; | 342 | struct usba_ep *usba_ep; |
330 | bool bias_pulse_needed; | 343 | bool bias_pulse_needed; |
344 | bool clocked; | ||
331 | 345 | ||
332 | u16 devstatus; | 346 | u16 devstatus; |
333 | 347 | ||
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index 8dda48445f6f..7592db7824c6 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c | |||
@@ -2631,7 +2631,7 @@ static int __init init(void) | |||
2631 | return -EINVAL; | 2631 | return -EINVAL; |
2632 | 2632 | ||
2633 | if (mod_data.num < 1 || mod_data.num > MAX_NUM_UDC) { | 2633 | if (mod_data.num < 1 || mod_data.num > MAX_NUM_UDC) { |
2634 | pr_err("Number of emulated UDC must be in range of 1…%d\n", | 2634 | pr_err("Number of emulated UDC must be in range of 1...%d\n", |
2635 | MAX_NUM_UDC); | 2635 | MAX_NUM_UDC); |
2636 | return -EINVAL; | 2636 | return -EINVAL; |
2637 | } | 2637 | } |
diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index 5b9176e7202a..9e8d842e8c08 100644 --- a/drivers/usb/gadget/udc/goku_udc.c +++ b/drivers/usb/gadget/udc/goku_udc.c | |||
@@ -1024,35 +1024,79 @@ static const char proc_node_name [] = "driver/udc"; | |||
1024 | static void dump_intmask(struct seq_file *m, const char *label, u32 mask) | 1024 | static void dump_intmask(struct seq_file *m, const char *label, u32 mask) |
1025 | { | 1025 | { |
1026 | /* int_status is the same format ... */ | 1026 | /* int_status is the same format ... */ |
1027 | seq_printf(m, | 1027 | seq_printf(m, "%s %05X =" FOURBITS EIGHTBITS EIGHTBITS "\n", |
1028 | "%s %05X =" FOURBITS EIGHTBITS EIGHTBITS "\n", | 1028 | label, mask, |
1029 | label, mask, | 1029 | (mask & INT_PWRDETECT) ? " power" : "", |
1030 | (mask & INT_PWRDETECT) ? " power" : "", | 1030 | (mask & INT_SYSERROR) ? " sys" : "", |
1031 | (mask & INT_SYSERROR) ? " sys" : "", | 1031 | (mask & INT_MSTRDEND) ? " in-dma" : "", |
1032 | (mask & INT_MSTRDEND) ? " in-dma" : "", | 1032 | (mask & INT_MSTWRTMOUT) ? " wrtmo" : "", |
1033 | (mask & INT_MSTWRTMOUT) ? " wrtmo" : "", | 1033 | |
1034 | 1034 | (mask & INT_MSTWREND) ? " out-dma" : "", | |
1035 | (mask & INT_MSTWREND) ? " out-dma" : "", | 1035 | (mask & INT_MSTWRSET) ? " wrset" : "", |
1036 | (mask & INT_MSTWRSET) ? " wrset" : "", | 1036 | (mask & INT_ERR) ? " err" : "", |
1037 | (mask & INT_ERR) ? " err" : "", | 1037 | (mask & INT_SOF) ? " sof" : "", |
1038 | (mask & INT_SOF) ? " sof" : "", | 1038 | |
1039 | 1039 | (mask & INT_EP3NAK) ? " ep3nak" : "", | |
1040 | (mask & INT_EP3NAK) ? " ep3nak" : "", | 1040 | (mask & INT_EP2NAK) ? " ep2nak" : "", |
1041 | (mask & INT_EP2NAK) ? " ep2nak" : "", | 1041 | (mask & INT_EP1NAK) ? " ep1nak" : "", |
1042 | (mask & INT_EP1NAK) ? " ep1nak" : "", | 1042 | (mask & INT_EP3DATASET) ? " ep3" : "", |
1043 | (mask & INT_EP3DATASET) ? " ep3" : "", | 1043 | |
1044 | 1044 | (mask & INT_EP2DATASET) ? " ep2" : "", | |
1045 | (mask & INT_EP2DATASET) ? " ep2" : "", | 1045 | (mask & INT_EP1DATASET) ? " ep1" : "", |
1046 | (mask & INT_EP1DATASET) ? " ep1" : "", | 1046 | (mask & INT_STATUSNAK) ? " ep0snak" : "", |
1047 | (mask & INT_STATUSNAK) ? " ep0snak" : "", | 1047 | (mask & INT_STATUS) ? " ep0status" : "", |
1048 | (mask & INT_STATUS) ? " ep0status" : "", | 1048 | |
1049 | 1049 | (mask & INT_SETUP) ? " setup" : "", | |
1050 | (mask & INT_SETUP) ? " setup" : "", | 1050 | (mask & INT_ENDPOINT0) ? " ep0" : "", |
1051 | (mask & INT_ENDPOINT0) ? " ep0" : "", | 1051 | (mask & INT_USBRESET) ? " reset" : "", |
1052 | (mask & INT_USBRESET) ? " reset" : "", | 1052 | (mask & INT_SUSPEND) ? " suspend" : ""); |
1053 | (mask & INT_SUSPEND) ? " suspend" : ""); | 1053 | } |
1054 | |||
1055 | static const char *udc_ep_state(enum ep0state state) | ||
1056 | { | ||
1057 | switch (state) { | ||
1058 | case EP0_DISCONNECT: | ||
1059 | return "ep0_disconnect"; | ||
1060 | case EP0_IDLE: | ||
1061 | return "ep0_idle"; | ||
1062 | case EP0_IN: | ||
1063 | return "ep0_in"; | ||
1064 | case EP0_OUT: | ||
1065 | return "ep0_out"; | ||
1066 | case EP0_STATUS: | ||
1067 | return "ep0_status"; | ||
1068 | case EP0_STALL: | ||
1069 | return "ep0_stall"; | ||
1070 | case EP0_SUSPEND: | ||
1071 | return "ep0_suspend"; | ||
1072 | } | ||
1073 | |||
1074 | return "ep0_?"; | ||
1054 | } | 1075 | } |
1055 | 1076 | ||
1077 | static const char *udc_ep_status(u32 status) | ||
1078 | { | ||
1079 | switch (status & EPxSTATUS_EP_MASK) { | ||
1080 | case EPxSTATUS_EP_READY: | ||
1081 | return "ready"; | ||
1082 | case EPxSTATUS_EP_DATAIN: | ||
1083 | return "packet"; | ||
1084 | case EPxSTATUS_EP_FULL: | ||
1085 | return "full"; | ||
1086 | case EPxSTATUS_EP_TX_ERR: /* host will retry */ | ||
1087 | return "tx_err"; | ||
1088 | case EPxSTATUS_EP_RX_ERR: | ||
1089 | return "rx_err"; | ||
1090 | case EPxSTATUS_EP_BUSY: /* ep0 only */ | ||
1091 | return "busy"; | ||
1092 | case EPxSTATUS_EP_STALL: | ||
1093 | return "stall"; | ||
1094 | case EPxSTATUS_EP_INVALID: /* these "can't happen" */ | ||
1095 | return "invalid"; | ||
1096 | } | ||
1097 | |||
1098 | return "?"; | ||
1099 | } | ||
1056 | 1100 | ||
1057 | static int udc_proc_read(struct seq_file *m, void *v) | 1101 | static int udc_proc_read(struct seq_file *m, void *v) |
1058 | { | 1102 | { |
@@ -1068,29 +1112,18 @@ static int udc_proc_read(struct seq_file *m, void *v) | |||
1068 | tmp = readl(®s->power_detect); | 1112 | tmp = readl(®s->power_detect); |
1069 | is_usb_connected = tmp & PW_DETECT; | 1113 | is_usb_connected = tmp & PW_DETECT; |
1070 | seq_printf(m, | 1114 | seq_printf(m, |
1071 | "%s - %s\n" | 1115 | "%s - %s\n" |
1072 | "%s version: %s %s\n" | 1116 | "%s version: %s %s\n" |
1073 | "Gadget driver: %s\n" | 1117 | "Gadget driver: %s\n" |
1074 | "Host %s, %s\n" | 1118 | "Host %s, %s\n" |
1075 | "\n", | 1119 | "\n", |
1076 | pci_name(dev->pdev), driver_desc, | 1120 | pci_name(dev->pdev), driver_desc, |
1077 | driver_name, DRIVER_VERSION, dmastr(), | 1121 | driver_name, DRIVER_VERSION, dmastr(), |
1078 | dev->driver ? dev->driver->driver.name : "(none)", | 1122 | dev->driver ? dev->driver->driver.name : "(none)", |
1079 | is_usb_connected | 1123 | is_usb_connected |
1080 | ? ((tmp & PW_PULLUP) ? "full speed" : "powered") | 1124 | ? ((tmp & PW_PULLUP) ? "full speed" : "powered") |
1081 | : "disconnected", | 1125 | : "disconnected", |
1082 | ({const char *state; | 1126 | udc_ep_state(dev->ep0state)); |
1083 | switch(dev->ep0state){ | ||
1084 | case EP0_DISCONNECT: state = "ep0_disconnect"; break; | ||
1085 | case EP0_IDLE: state = "ep0_idle"; break; | ||
1086 | case EP0_IN: state = "ep0_in"; break; | ||
1087 | case EP0_OUT: state = "ep0_out"; break; | ||
1088 | case EP0_STATUS: state = "ep0_status"; break; | ||
1089 | case EP0_STALL: state = "ep0_stall"; break; | ||
1090 | case EP0_SUSPEND: state = "ep0_suspend"; break; | ||
1091 | default: state = "ep0_?"; break; | ||
1092 | } state; }) | ||
1093 | ); | ||
1094 | 1127 | ||
1095 | dump_intmask(m, "int_status", readl(®s->int_status)); | 1128 | dump_intmask(m, "int_status", readl(®s->int_status)); |
1096 | dump_intmask(m, "int_enable", readl(®s->int_enable)); | 1129 | dump_intmask(m, "int_enable", readl(®s->int_enable)); |
@@ -1099,31 +1132,30 @@ static int udc_proc_read(struct seq_file *m, void *v) | |||
1099 | goto done; | 1132 | goto done; |
1100 | 1133 | ||
1101 | /* registers for (active) device and ep0 */ | 1134 | /* registers for (active) device and ep0 */ |
1102 | if (seq_printf(m, "\nirqs %lu\ndataset %02x " | 1135 | seq_printf(m, "\nirqs %lu\ndataset %02x single.bcs %02x.%02x state %x addr %u\n", |
1103 | "single.bcs %02x.%02x state %x addr %u\n", | 1136 | dev->irqs, readl(®s->DataSet), |
1104 | dev->irqs, readl(®s->DataSet), | 1137 | readl(®s->EPxSingle), readl(®s->EPxBCS), |
1105 | readl(®s->EPxSingle), readl(®s->EPxBCS), | 1138 | readl(®s->UsbState), |
1106 | readl(®s->UsbState), | 1139 | readl(®s->address)); |
1107 | readl(®s->address)) < 0) | 1140 | if (seq_has_overflowed(m)) |
1108 | goto done; | 1141 | goto done; |
1109 | 1142 | ||
1110 | tmp = readl(®s->dma_master); | 1143 | tmp = readl(®s->dma_master); |
1111 | if (seq_printf(m, | 1144 | seq_printf(m, "dma %03X =" EIGHTBITS "%s %s\n", |
1112 | "dma %03X =" EIGHTBITS "%s %s\n", tmp, | 1145 | tmp, |
1113 | (tmp & MST_EOPB_DIS) ? " eopb-" : "", | 1146 | (tmp & MST_EOPB_DIS) ? " eopb-" : "", |
1114 | (tmp & MST_EOPB_ENA) ? " eopb+" : "", | 1147 | (tmp & MST_EOPB_ENA) ? " eopb+" : "", |
1115 | (tmp & MST_TIMEOUT_DIS) ? " tmo-" : "", | 1148 | (tmp & MST_TIMEOUT_DIS) ? " tmo-" : "", |
1116 | (tmp & MST_TIMEOUT_ENA) ? " tmo+" : "", | 1149 | (tmp & MST_TIMEOUT_ENA) ? " tmo+" : "", |
1117 | 1150 | ||
1118 | (tmp & MST_RD_EOPB) ? " eopb" : "", | 1151 | (tmp & MST_RD_EOPB) ? " eopb" : "", |
1119 | (tmp & MST_RD_RESET) ? " in_reset" : "", | 1152 | (tmp & MST_RD_RESET) ? " in_reset" : "", |
1120 | (tmp & MST_WR_RESET) ? " out_reset" : "", | 1153 | (tmp & MST_WR_RESET) ? " out_reset" : "", |
1121 | (tmp & MST_RD_ENA) ? " IN" : "", | 1154 | (tmp & MST_RD_ENA) ? " IN" : "", |
1122 | 1155 | ||
1123 | (tmp & MST_WR_ENA) ? " OUT" : "", | 1156 | (tmp & MST_WR_ENA) ? " OUT" : "", |
1124 | (tmp & MST_CONNECTION) | 1157 | (tmp & MST_CONNECTION) ? "ep1in/ep2out" : "ep1out/ep2in"); |
1125 | ? "ep1in/ep2out" | 1158 | if (seq_has_overflowed(m)) |
1126 | : "ep1out/ep2in") < 0) | ||
1127 | goto done; | 1159 | goto done; |
1128 | 1160 | ||
1129 | /* dump endpoint queues */ | 1161 | /* dump endpoint queues */ |
@@ -1135,44 +1167,23 @@ static int udc_proc_read(struct seq_file *m, void *v) | |||
1135 | continue; | 1167 | continue; |
1136 | 1168 | ||
1137 | tmp = readl(ep->reg_status); | 1169 | tmp = readl(ep->reg_status); |
1138 | if (seq_printf(m, | 1170 | seq_printf(m, "%s %s max %u %s, irqs %lu, status %02x (%s) " FOURBITS "\n", |
1139 | "%s %s max %u %s, irqs %lu, " | 1171 | ep->ep.name, |
1140 | "status %02x (%s) " FOURBITS "\n", | 1172 | ep->is_in ? "in" : "out", |
1141 | ep->ep.name, | 1173 | ep->ep.maxpacket, |
1142 | ep->is_in ? "in" : "out", | 1174 | ep->dma ? "dma" : "pio", |
1143 | ep->ep.maxpacket, | 1175 | ep->irqs, |
1144 | ep->dma ? "dma" : "pio", | 1176 | tmp, udc_ep_status(tmp), |
1145 | ep->irqs, | 1177 | (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", |
1146 | tmp, ({ char *s; | 1178 | (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", |
1147 | switch (tmp & EPxSTATUS_EP_MASK) { | 1179 | (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", |
1148 | case EPxSTATUS_EP_READY: | 1180 | (tmp & EPxSTATUS_STAGE_ERROR) ? " ep0stat" : ""); |
1149 | s = "ready"; break; | 1181 | if (seq_has_overflowed(m)) |
1150 | case EPxSTATUS_EP_DATAIN: | ||
1151 | s = "packet"; break; | ||
1152 | case EPxSTATUS_EP_FULL: | ||
1153 | s = "full"; break; | ||
1154 | case EPxSTATUS_EP_TX_ERR: // host will retry | ||
1155 | s = "tx_err"; break; | ||
1156 | case EPxSTATUS_EP_RX_ERR: | ||
1157 | s = "rx_err"; break; | ||
1158 | case EPxSTATUS_EP_BUSY: /* ep0 only */ | ||
1159 | s = "busy"; break; | ||
1160 | case EPxSTATUS_EP_STALL: | ||
1161 | s = "stall"; break; | ||
1162 | case EPxSTATUS_EP_INVALID: // these "can't happen" | ||
1163 | s = "invalid"; break; | ||
1164 | default: | ||
1165 | s = "?"; break; | ||
1166 | } s; }), | ||
1167 | (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", | ||
1168 | (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", | ||
1169 | (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", | ||
1170 | (tmp & EPxSTATUS_STAGE_ERROR) ? " ep0stat" : "" | ||
1171 | ) < 0) | ||
1172 | goto done; | 1182 | goto done; |
1173 | 1183 | ||
1174 | if (list_empty(&ep->queue)) { | 1184 | if (list_empty(&ep->queue)) { |
1175 | if (seq_puts(m, "\t(nothing queued)\n") < 0) | 1185 | seq_puts(m, "\t(nothing queued)\n"); |
1186 | if (seq_has_overflowed(m)) | ||
1176 | goto done; | 1187 | goto done; |
1177 | continue; | 1188 | continue; |
1178 | } | 1189 | } |
@@ -1187,10 +1198,10 @@ static int udc_proc_read(struct seq_file *m, void *v) | |||
1187 | } else | 1198 | } else |
1188 | tmp = req->req.actual; | 1199 | tmp = req->req.actual; |
1189 | 1200 | ||
1190 | if (seq_printf(m, | 1201 | seq_printf(m, "\treq %p len %u/%u buf %p\n", |
1191 | "\treq %p len %u/%u buf %p\n", | 1202 | &req->req, tmp, req->req.length, |
1192 | &req->req, tmp, req->req.length, | 1203 | req->req.buf); |
1193 | req->req.buf) < 0) | 1204 | if (seq_has_overflowed(m)) |
1194 | goto done; | 1205 | goto done; |
1195 | } | 1206 | } |
1196 | } | 1207 | } |
diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index 27fd41333f71..3b6a7852822d 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c | |||
@@ -1803,23 +1803,14 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep, | |||
1803 | req = container_of(_req, struct lpc32xx_request, req); | 1803 | req = container_of(_req, struct lpc32xx_request, req); |
1804 | ep = container_of(_ep, struct lpc32xx_ep, ep); | 1804 | ep = container_of(_ep, struct lpc32xx_ep, ep); |
1805 | 1805 | ||
1806 | if (!_req || !_req->complete || !_req->buf || | 1806 | if (!_ep || !_req || !_req->complete || !_req->buf || |
1807 | !list_empty(&req->queue)) | 1807 | !list_empty(&req->queue)) |
1808 | return -EINVAL; | 1808 | return -EINVAL; |
1809 | 1809 | ||
1810 | udc = ep->udc; | 1810 | udc = ep->udc; |
1811 | 1811 | ||
1812 | if (!_ep) { | 1812 | if (udc->gadget.speed == USB_SPEED_UNKNOWN) |
1813 | dev_dbg(udc->dev, "invalid ep\n"); | 1813 | return -EPIPE; |
1814 | return -EINVAL; | ||
1815 | } | ||
1816 | |||
1817 | |||
1818 | if ((!udc) || (!udc->driver) || | ||
1819 | (udc->gadget.speed == USB_SPEED_UNKNOWN)) { | ||
1820 | dev_dbg(udc->dev, "invalid device\n"); | ||
1821 | return -EINVAL; | ||
1822 | } | ||
1823 | 1814 | ||
1824 | if (ep->lep) { | 1815 | if (ep->lep) { |
1825 | struct lpc32xx_usbd_dd_gad *dd; | 1816 | struct lpc32xx_usbd_dd_gad *dd; |
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index d2c0bf65e345..9871b90195ad 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c | |||
@@ -80,6 +80,13 @@ static const char *const ep_name[] = { | |||
80 | "ep-e", "ep-f", "ep-g", "ep-h", | 80 | "ep-e", "ep-f", "ep-g", "ep-h", |
81 | }; | 81 | }; |
82 | 82 | ||
83 | /* Endpoint names for usb3380 advance mode */ | ||
84 | static const char *const ep_name_adv[] = { | ||
85 | ep0name, | ||
86 | "ep1in", "ep2out", "ep3in", "ep4out", | ||
87 | "ep1out", "ep2in", "ep3out", "ep4in", | ||
88 | }; | ||
89 | |||
83 | /* mode 0 == ep-{a,b,c,d} 1K fifo each | 90 | /* mode 0 == ep-{a,b,c,d} 1K fifo each |
84 | * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable | 91 | * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable |
85 | * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable | 92 | * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable |
@@ -138,31 +145,44 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
138 | u32 max, tmp; | 145 | u32 max, tmp; |
139 | unsigned long flags; | 146 | unsigned long flags; |
140 | static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 }; | 147 | static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 }; |
148 | int ret = 0; | ||
141 | 149 | ||
142 | ep = container_of(_ep, struct net2280_ep, ep); | 150 | ep = container_of(_ep, struct net2280_ep, ep); |
143 | if (!_ep || !desc || ep->desc || _ep->name == ep0name || | 151 | if (!_ep || !desc || ep->desc || _ep->name == ep0name || |
144 | desc->bDescriptorType != USB_DT_ENDPOINT) | 152 | desc->bDescriptorType != USB_DT_ENDPOINT) { |
153 | pr_err("%s: failed at line=%d\n", __func__, __LINE__); | ||
145 | return -EINVAL; | 154 | return -EINVAL; |
155 | } | ||
146 | dev = ep->dev; | 156 | dev = ep->dev; |
147 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | 157 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { |
148 | return -ESHUTDOWN; | 158 | ret = -ESHUTDOWN; |
159 | goto print_err; | ||
160 | } | ||
149 | 161 | ||
150 | /* erratum 0119 workaround ties up an endpoint number */ | 162 | /* erratum 0119 workaround ties up an endpoint number */ |
151 | if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) | 163 | if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) { |
152 | return -EDOM; | 164 | ret = -EDOM; |
165 | goto print_err; | ||
166 | } | ||
153 | 167 | ||
154 | if (dev->quirks & PLX_SUPERSPEED) { | 168 | if (dev->quirks & PLX_SUPERSPEED) { |
155 | if ((desc->bEndpointAddress & 0x0f) >= 0x0c) | 169 | if ((desc->bEndpointAddress & 0x0f) >= 0x0c) { |
156 | return -EDOM; | 170 | ret = -EDOM; |
171 | goto print_err; | ||
172 | } | ||
157 | ep->is_in = !!usb_endpoint_dir_in(desc); | 173 | ep->is_in = !!usb_endpoint_dir_in(desc); |
158 | if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) | 174 | if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) { |
159 | return -EINVAL; | 175 | ret = -EINVAL; |
176 | goto print_err; | ||
177 | } | ||
160 | } | 178 | } |
161 | 179 | ||
162 | /* sanity check ep-e/ep-f since their fifos are small */ | 180 | /* sanity check ep-e/ep-f since their fifos are small */ |
163 | max = usb_endpoint_maxp(desc) & 0x1fff; | 181 | max = usb_endpoint_maxp(desc) & 0x1fff; |
164 | if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) | 182 | if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) { |
165 | return -ERANGE; | 183 | ret = -ERANGE; |
184 | goto print_err; | ||
185 | } | ||
166 | 186 | ||
167 | spin_lock_irqsave(&dev->lock, flags); | 187 | spin_lock_irqsave(&dev->lock, flags); |
168 | _ep->maxpacket = max & 0x7ff; | 188 | _ep->maxpacket = max & 0x7ff; |
@@ -192,7 +212,8 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
192 | (dev->gadget.speed == USB_SPEED_HIGH && max != 512) || | 212 | (dev->gadget.speed == USB_SPEED_HIGH && max != 512) || |
193 | (dev->gadget.speed == USB_SPEED_FULL && max > 64)) { | 213 | (dev->gadget.speed == USB_SPEED_FULL && max > 64)) { |
194 | spin_unlock_irqrestore(&dev->lock, flags); | 214 | spin_unlock_irqrestore(&dev->lock, flags); |
195 | return -ERANGE; | 215 | ret = -ERANGE; |
216 | goto print_err; | ||
196 | } | 217 | } |
197 | } | 218 | } |
198 | ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); | 219 | ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); |
@@ -271,7 +292,11 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
271 | 292 | ||
272 | /* pci writes may still be posted */ | 293 | /* pci writes may still be posted */ |
273 | spin_unlock_irqrestore(&dev->lock, flags); | 294 | spin_unlock_irqrestore(&dev->lock, flags); |
274 | return 0; | 295 | return ret; |
296 | |||
297 | print_err: | ||
298 | dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret); | ||
299 | return ret; | ||
275 | } | 300 | } |
276 | 301 | ||
277 | static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) | 302 | static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) |
@@ -426,9 +451,10 @@ static int net2280_disable(struct usb_ep *_ep) | |||
426 | unsigned long flags; | 451 | unsigned long flags; |
427 | 452 | ||
428 | ep = container_of(_ep, struct net2280_ep, ep); | 453 | ep = container_of(_ep, struct net2280_ep, ep); |
429 | if (!_ep || !ep->desc || _ep->name == ep0name) | 454 | if (!_ep || !ep->desc || _ep->name == ep0name) { |
455 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); | ||
430 | return -EINVAL; | 456 | return -EINVAL; |
431 | 457 | } | |
432 | spin_lock_irqsave(&ep->dev->lock, flags); | 458 | spin_lock_irqsave(&ep->dev->lock, flags); |
433 | nuke(ep); | 459 | nuke(ep); |
434 | 460 | ||
@@ -458,8 +484,10 @@ static struct usb_request | |||
458 | struct net2280_ep *ep; | 484 | struct net2280_ep *ep; |
459 | struct net2280_request *req; | 485 | struct net2280_request *req; |
460 | 486 | ||
461 | if (!_ep) | 487 | if (!_ep) { |
488 | pr_err("%s: Invalid ep\n", __func__); | ||
462 | return NULL; | 489 | return NULL; |
490 | } | ||
463 | ep = container_of(_ep, struct net2280_ep, ep); | 491 | ep = container_of(_ep, struct net2280_ep, ep); |
464 | 492 | ||
465 | req = kzalloc(sizeof(*req), gfp_flags); | 493 | req = kzalloc(sizeof(*req), gfp_flags); |
@@ -491,8 +519,11 @@ static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req) | |||
491 | struct net2280_request *req; | 519 | struct net2280_request *req; |
492 | 520 | ||
493 | ep = container_of(_ep, struct net2280_ep, ep); | 521 | ep = container_of(_ep, struct net2280_ep, ep); |
494 | if (!_ep || !_req) | 522 | if (!_ep || !_req) { |
523 | dev_err(&ep->dev->pdev->dev, "%s: Inavlid ep=%p or req=%p\n", | ||
524 | __func__, _ep, _req); | ||
495 | return; | 525 | return; |
526 | } | ||
496 | 527 | ||
497 | req = container_of(_req, struct net2280_request, req); | 528 | req = container_of(_req, struct net2280_request, req); |
498 | WARN_ON(!list_empty(&req->queue)); | 529 | WARN_ON(!list_empty(&req->queue)); |
@@ -896,35 +927,44 @@ net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
896 | struct net2280_ep *ep; | 927 | struct net2280_ep *ep; |
897 | struct net2280 *dev; | 928 | struct net2280 *dev; |
898 | unsigned long flags; | 929 | unsigned long flags; |
930 | int ret = 0; | ||
899 | 931 | ||
900 | /* we always require a cpu-view buffer, so that we can | 932 | /* we always require a cpu-view buffer, so that we can |
901 | * always use pio (as fallback or whatever). | 933 | * always use pio (as fallback or whatever). |
902 | */ | 934 | */ |
903 | req = container_of(_req, struct net2280_request, req); | ||
904 | if (!_req || !_req->complete || !_req->buf || | ||
905 | !list_empty(&req->queue)) | ||
906 | return -EINVAL; | ||
907 | if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) | ||
908 | return -EDOM; | ||
909 | ep = container_of(_ep, struct net2280_ep, ep); | 935 | ep = container_of(_ep, struct net2280_ep, ep); |
910 | if (!_ep || (!ep->desc && ep->num != 0)) | 936 | if (!_ep || (!ep->desc && ep->num != 0)) { |
937 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); | ||
911 | return -EINVAL; | 938 | return -EINVAL; |
939 | } | ||
940 | req = container_of(_req, struct net2280_request, req); | ||
941 | if (!_req || !_req->complete || !_req->buf || | ||
942 | !list_empty(&req->queue)) { | ||
943 | ret = -EINVAL; | ||
944 | goto print_err; | ||
945 | } | ||
946 | if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) { | ||
947 | ret = -EDOM; | ||
948 | goto print_err; | ||
949 | } | ||
912 | dev = ep->dev; | 950 | dev = ep->dev; |
913 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | 951 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { |
914 | return -ESHUTDOWN; | 952 | ret = -ESHUTDOWN; |
953 | goto print_err; | ||
954 | } | ||
915 | 955 | ||
916 | /* FIXME implement PIO fallback for ZLPs with DMA */ | 956 | /* FIXME implement PIO fallback for ZLPs with DMA */ |
917 | if (ep->dma && _req->length == 0) | 957 | if (ep->dma && _req->length == 0) { |
918 | return -EOPNOTSUPP; | 958 | ret = -EOPNOTSUPP; |
959 | goto print_err; | ||
960 | } | ||
919 | 961 | ||
920 | /* set up dma mapping in case the caller didn't */ | 962 | /* set up dma mapping in case the caller didn't */ |
921 | if (ep->dma) { | 963 | if (ep->dma) { |
922 | int ret; | ||
923 | |||
924 | ret = usb_gadget_map_request(&dev->gadget, _req, | 964 | ret = usb_gadget_map_request(&dev->gadget, _req, |
925 | ep->is_in); | 965 | ep->is_in); |
926 | if (ret) | 966 | if (ret) |
927 | return ret; | 967 | goto print_err; |
928 | } | 968 | } |
929 | 969 | ||
930 | ep_vdbg(dev, "%s queue req %p, len %d buf %p\n", | 970 | ep_vdbg(dev, "%s queue req %p, len %d buf %p\n", |
@@ -1013,7 +1053,11 @@ done: | |||
1013 | spin_unlock_irqrestore(&dev->lock, flags); | 1053 | spin_unlock_irqrestore(&dev->lock, flags); |
1014 | 1054 | ||
1015 | /* pci writes may still be posted */ | 1055 | /* pci writes may still be posted */ |
1016 | return 0; | 1056 | return ret; |
1057 | |||
1058 | print_err: | ||
1059 | dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret); | ||
1060 | return ret; | ||
1017 | } | 1061 | } |
1018 | 1062 | ||
1019 | static inline void | 1063 | static inline void |
@@ -1134,8 +1178,11 @@ static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
1134 | int stopped; | 1178 | int stopped; |
1135 | 1179 | ||
1136 | ep = container_of(_ep, struct net2280_ep, ep); | 1180 | ep = container_of(_ep, struct net2280_ep, ep); |
1137 | if (!_ep || (!ep->desc && ep->num != 0) || !_req) | 1181 | if (!_ep || (!ep->desc && ep->num != 0) || !_req) { |
1182 | pr_err("%s: Invalid ep=%p or ep->desc or req=%p\n", | ||
1183 | __func__, _ep, _req); | ||
1138 | return -EINVAL; | 1184 | return -EINVAL; |
1185 | } | ||
1139 | 1186 | ||
1140 | spin_lock_irqsave(&ep->dev->lock, flags); | 1187 | spin_lock_irqsave(&ep->dev->lock, flags); |
1141 | stopped = ep->stopped; | 1188 | stopped = ep->stopped; |
@@ -1157,6 +1204,8 @@ static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
1157 | } | 1204 | } |
1158 | if (&req->req != _req) { | 1205 | if (&req->req != _req) { |
1159 | spin_unlock_irqrestore(&ep->dev->lock, flags); | 1206 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
1207 | dev_err(&ep->dev->pdev->dev, "%s: Request mismatch\n", | ||
1208 | __func__); | ||
1160 | return -EINVAL; | 1209 | return -EINVAL; |
1161 | } | 1210 | } |
1162 | 1211 | ||
@@ -1214,20 +1263,28 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) | |||
1214 | int retval = 0; | 1263 | int retval = 0; |
1215 | 1264 | ||
1216 | ep = container_of(_ep, struct net2280_ep, ep); | 1265 | ep = container_of(_ep, struct net2280_ep, ep); |
1217 | if (!_ep || (!ep->desc && ep->num != 0)) | 1266 | if (!_ep || (!ep->desc && ep->num != 0)) { |
1267 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); | ||
1218 | return -EINVAL; | 1268 | return -EINVAL; |
1219 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | 1269 | } |
1220 | return -ESHUTDOWN; | 1270 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { |
1271 | retval = -ESHUTDOWN; | ||
1272 | goto print_err; | ||
1273 | } | ||
1221 | if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03) | 1274 | if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03) |
1222 | == USB_ENDPOINT_XFER_ISOC) | 1275 | == USB_ENDPOINT_XFER_ISOC) { |
1223 | return -EINVAL; | 1276 | retval = -EINVAL; |
1277 | goto print_err; | ||
1278 | } | ||
1224 | 1279 | ||
1225 | spin_lock_irqsave(&ep->dev->lock, flags); | 1280 | spin_lock_irqsave(&ep->dev->lock, flags); |
1226 | if (!list_empty(&ep->queue)) | 1281 | if (!list_empty(&ep->queue)) { |
1227 | retval = -EAGAIN; | 1282 | retval = -EAGAIN; |
1228 | else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) | 1283 | goto print_unlock; |
1284 | } else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) { | ||
1229 | retval = -EAGAIN; | 1285 | retval = -EAGAIN; |
1230 | else { | 1286 | goto print_unlock; |
1287 | } else { | ||
1231 | ep_vdbg(ep->dev, "%s %s %s\n", _ep->name, | 1288 | ep_vdbg(ep->dev, "%s %s %s\n", _ep->name, |
1232 | value ? "set" : "clear", | 1289 | value ? "set" : "clear", |
1233 | wedged ? "wedge" : "halt"); | 1290 | wedged ? "wedge" : "halt"); |
@@ -1251,6 +1308,12 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) | |||
1251 | spin_unlock_irqrestore(&ep->dev->lock, flags); | 1308 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
1252 | 1309 | ||
1253 | return retval; | 1310 | return retval; |
1311 | |||
1312 | print_unlock: | ||
1313 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
1314 | print_err: | ||
1315 | dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, retval); | ||
1316 | return retval; | ||
1254 | } | 1317 | } |
1255 | 1318 | ||
1256 | static int net2280_set_halt(struct usb_ep *_ep, int value) | 1319 | static int net2280_set_halt(struct usb_ep *_ep, int value) |
@@ -1260,8 +1323,10 @@ static int net2280_set_halt(struct usb_ep *_ep, int value) | |||
1260 | 1323 | ||
1261 | static int net2280_set_wedge(struct usb_ep *_ep) | 1324 | static int net2280_set_wedge(struct usb_ep *_ep) |
1262 | { | 1325 | { |
1263 | if (!_ep || _ep->name == ep0name) | 1326 | if (!_ep || _ep->name == ep0name) { |
1327 | pr_err("%s: Invalid ep=%p or ep0\n", __func__, _ep); | ||
1264 | return -EINVAL; | 1328 | return -EINVAL; |
1329 | } | ||
1265 | return net2280_set_halt_and_wedge(_ep, 1, 1); | 1330 | return net2280_set_halt_and_wedge(_ep, 1, 1); |
1266 | } | 1331 | } |
1267 | 1332 | ||
@@ -1271,14 +1336,22 @@ static int net2280_fifo_status(struct usb_ep *_ep) | |||
1271 | u32 avail; | 1336 | u32 avail; |
1272 | 1337 | ||
1273 | ep = container_of(_ep, struct net2280_ep, ep); | 1338 | ep = container_of(_ep, struct net2280_ep, ep); |
1274 | if (!_ep || (!ep->desc && ep->num != 0)) | 1339 | if (!_ep || (!ep->desc && ep->num != 0)) { |
1340 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); | ||
1275 | return -ENODEV; | 1341 | return -ENODEV; |
1276 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | 1342 | } |
1343 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { | ||
1344 | dev_err(&ep->dev->pdev->dev, | ||
1345 | "%s: Invalid driver=%p or speed=%d\n", | ||
1346 | __func__, ep->dev->driver, ep->dev->gadget.speed); | ||
1277 | return -ESHUTDOWN; | 1347 | return -ESHUTDOWN; |
1348 | } | ||
1278 | 1349 | ||
1279 | avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1); | 1350 | avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1); |
1280 | if (avail > ep->fifo_size) | 1351 | if (avail > ep->fifo_size) { |
1352 | dev_err(&ep->dev->pdev->dev, "%s: Fifo overflow\n", __func__); | ||
1281 | return -EOVERFLOW; | 1353 | return -EOVERFLOW; |
1354 | } | ||
1282 | if (ep->is_in) | 1355 | if (ep->is_in) |
1283 | avail = ep->fifo_size - avail; | 1356 | avail = ep->fifo_size - avail; |
1284 | return avail; | 1357 | return avail; |
@@ -1289,10 +1362,16 @@ static void net2280_fifo_flush(struct usb_ep *_ep) | |||
1289 | struct net2280_ep *ep; | 1362 | struct net2280_ep *ep; |
1290 | 1363 | ||
1291 | ep = container_of(_ep, struct net2280_ep, ep); | 1364 | ep = container_of(_ep, struct net2280_ep, ep); |
1292 | if (!_ep || (!ep->desc && ep->num != 0)) | 1365 | if (!_ep || (!ep->desc && ep->num != 0)) { |
1366 | pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); | ||
1293 | return; | 1367 | return; |
1294 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | 1368 | } |
1369 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { | ||
1370 | dev_err(&ep->dev->pdev->dev, | ||
1371 | "%s: Invalid driver=%p or speed=%d\n", | ||
1372 | __func__, ep->dev->driver, ep->dev->gadget.speed); | ||
1295 | return; | 1373 | return; |
1374 | } | ||
1296 | 1375 | ||
1297 | writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); | 1376 | writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); |
1298 | (void) readl(&ep->regs->ep_rsp); | 1377 | (void) readl(&ep->regs->ep_rsp); |
@@ -1977,7 +2056,7 @@ static void usb_reinit_338x(struct net2280 *dev) | |||
1977 | for (i = 0; i < dev->n_ep; i++) { | 2056 | for (i = 0; i < dev->n_ep; i++) { |
1978 | struct net2280_ep *ep = &dev->ep[i]; | 2057 | struct net2280_ep *ep = &dev->ep[i]; |
1979 | 2058 | ||
1980 | ep->ep.name = ep_name[i]; | 2059 | ep->ep.name = dev->enhanced_mode ? ep_name_adv[i] : ep_name[i]; |
1981 | ep->dev = dev; | 2060 | ep->dev = dev; |
1982 | ep->num = i; | 2061 | ep->num = i; |
1983 | 2062 | ||
@@ -1989,11 +2068,9 @@ static void usb_reinit_338x(struct net2280 *dev) | |||
1989 | ep->regs = (struct net2280_ep_regs __iomem *) | 2068 | ep->regs = (struct net2280_ep_regs __iomem *) |
1990 | (((void __iomem *)&dev->epregs[ne[i]]) + | 2069 | (((void __iomem *)&dev->epregs[ne[i]]) + |
1991 | ep_reg_addr[i]); | 2070 | ep_reg_addr[i]); |
1992 | ep->fiforegs = &dev->fiforegs[i]; | ||
1993 | } else { | 2071 | } else { |
1994 | ep->cfg = &dev->epregs[i]; | 2072 | ep->cfg = &dev->epregs[i]; |
1995 | ep->regs = &dev->epregs[i]; | 2073 | ep->regs = &dev->epregs[i]; |
1996 | ep->fiforegs = &dev->fiforegs[i]; | ||
1997 | } | 2074 | } |
1998 | 2075 | ||
1999 | ep->fifo_size = (i != 0) ? 2048 : 512; | 2076 | ep->fifo_size = (i != 0) ? 2048 : 512; |
@@ -2186,7 +2263,6 @@ static int net2280_start(struct usb_gadget *_gadget, | |||
2186 | dev->ep[i].irqs = 0; | 2263 | dev->ep[i].irqs = 0; |
2187 | 2264 | ||
2188 | /* hook up the driver ... */ | 2265 | /* hook up the driver ... */ |
2189 | dev->softconnect = 1; | ||
2190 | driver->driver.bus = NULL; | 2266 | driver->driver.bus = NULL; |
2191 | dev->driver = driver; | 2267 | dev->driver = driver; |
2192 | 2268 | ||
@@ -3052,6 +3128,8 @@ next_endpoints: | |||
3052 | BIT(PCI_RETRY_ABORT_INTERRUPT)) | 3128 | BIT(PCI_RETRY_ABORT_INTERRUPT)) |
3053 | 3129 | ||
3054 | static void handle_stat1_irqs(struct net2280 *dev, u32 stat) | 3130 | static void handle_stat1_irqs(struct net2280 *dev, u32 stat) |
3131 | __releases(dev->lock) | ||
3132 | __acquires(dev->lock) | ||
3055 | { | 3133 | { |
3056 | struct net2280_ep *ep; | 3134 | struct net2280_ep *ep; |
3057 | u32 tmp, num, mask, scratch; | 3135 | u32 tmp, num, mask, scratch; |
@@ -3373,8 +3451,6 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
3373 | u32 usbstat; | 3451 | u32 usbstat; |
3374 | dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *) | 3452 | dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *) |
3375 | (base + 0x00b4); | 3453 | (base + 0x00b4); |
3376 | dev->fiforegs = (struct usb338x_fifo_regs __iomem *) | ||
3377 | (base + 0x0500); | ||
3378 | dev->llregs = (struct usb338x_ll_regs __iomem *) | 3454 | dev->llregs = (struct usb338x_ll_regs __iomem *) |
3379 | (base + 0x0700); | 3455 | (base + 0x0700); |
3380 | dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *) | 3456 | dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *) |
diff --git a/drivers/usb/gadget/udc/net2280.h b/drivers/usb/gadget/udc/net2280.h index ac8d5a20a378..4dff60d34f73 100644 --- a/drivers/usb/gadget/udc/net2280.h +++ b/drivers/usb/gadget/udc/net2280.h | |||
@@ -96,7 +96,6 @@ struct net2280_ep { | |||
96 | struct net2280_ep_regs __iomem *regs; | 96 | struct net2280_ep_regs __iomem *regs; |
97 | struct net2280_dma_regs __iomem *dma; | 97 | struct net2280_dma_regs __iomem *dma; |
98 | struct net2280_dma *dummy; | 98 | struct net2280_dma *dummy; |
99 | struct usb338x_fifo_regs __iomem *fiforegs; | ||
100 | dma_addr_t td_dma; /* of dummy */ | 99 | dma_addr_t td_dma; /* of dummy */ |
101 | struct net2280 *dev; | 100 | struct net2280 *dev; |
102 | unsigned long irqs; | 101 | unsigned long irqs; |
@@ -181,7 +180,6 @@ struct net2280 { | |||
181 | struct net2280_dma_regs __iomem *dma; | 180 | struct net2280_dma_regs __iomem *dma; |
182 | struct net2280_dep_regs __iomem *dep; | 181 | struct net2280_dep_regs __iomem *dep; |
183 | struct net2280_ep_regs __iomem *epregs; | 182 | struct net2280_ep_regs __iomem *epregs; |
184 | struct usb338x_fifo_regs __iomem *fiforegs; | ||
185 | struct usb338x_ll_regs __iomem *llregs; | 183 | struct usb338x_ll_regs __iomem *llregs; |
186 | struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs; | 184 | struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs; |
187 | struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs; | 185 | struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs; |
diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index f0ae143dab6d..b51226abade6 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c | |||
@@ -93,50 +93,46 @@ static void handle_ep(struct pxa_ep *ep); | |||
93 | static int state_dbg_show(struct seq_file *s, void *p) | 93 | static int state_dbg_show(struct seq_file *s, void *p) |
94 | { | 94 | { |
95 | struct pxa_udc *udc = s->private; | 95 | struct pxa_udc *udc = s->private; |
96 | int pos = 0, ret; | ||
97 | u32 tmp; | 96 | u32 tmp; |
98 | 97 | ||
99 | ret = -ENODEV; | ||
100 | if (!udc->driver) | 98 | if (!udc->driver) |
101 | goto out; | 99 | return -ENODEV; |
102 | 100 | ||
103 | /* basic device status */ | 101 | /* basic device status */ |
104 | pos += seq_printf(s, DRIVER_DESC "\n" | 102 | seq_printf(s, DRIVER_DESC "\n" |
105 | "%s version: %s\nGadget driver: %s\n", | 103 | "%s version: %s\n" |
106 | driver_name, DRIVER_VERSION, | 104 | "Gadget driver: %s\n", |
107 | udc->driver ? udc->driver->driver.name : "(none)"); | 105 | driver_name, DRIVER_VERSION, |
106 | udc->driver ? udc->driver->driver.name : "(none)"); | ||
108 | 107 | ||
109 | tmp = udc_readl(udc, UDCCR); | 108 | tmp = udc_readl(udc, UDCCR); |
110 | pos += seq_printf(s, | 109 | seq_printf(s, |
111 | "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), " | 110 | "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), con=%d,inter=%d,altinter=%d\n", |
112 | "con=%d,inter=%d,altinter=%d\n", tmp, | 111 | tmp, |
113 | (tmp & UDCCR_OEN) ? " oen":"", | 112 | (tmp & UDCCR_OEN) ? " oen":"", |
114 | (tmp & UDCCR_AALTHNP) ? " aalthnp":"", | 113 | (tmp & UDCCR_AALTHNP) ? " aalthnp":"", |
115 | (tmp & UDCCR_AHNP) ? " rem" : "", | 114 | (tmp & UDCCR_AHNP) ? " rem" : "", |
116 | (tmp & UDCCR_BHNP) ? " rstir" : "", | 115 | (tmp & UDCCR_BHNP) ? " rstir" : "", |
117 | (tmp & UDCCR_DWRE) ? " dwre" : "", | 116 | (tmp & UDCCR_DWRE) ? " dwre" : "", |
118 | (tmp & UDCCR_SMAC) ? " smac" : "", | 117 | (tmp & UDCCR_SMAC) ? " smac" : "", |
119 | (tmp & UDCCR_EMCE) ? " emce" : "", | 118 | (tmp & UDCCR_EMCE) ? " emce" : "", |
120 | (tmp & UDCCR_UDR) ? " udr" : "", | 119 | (tmp & UDCCR_UDR) ? " udr" : "", |
121 | (tmp & UDCCR_UDA) ? " uda" : "", | 120 | (tmp & UDCCR_UDA) ? " uda" : "", |
122 | (tmp & UDCCR_UDE) ? " ude" : "", | 121 | (tmp & UDCCR_UDE) ? " ude" : "", |
123 | (tmp & UDCCR_ACN) >> UDCCR_ACN_S, | 122 | (tmp & UDCCR_ACN) >> UDCCR_ACN_S, |
124 | (tmp & UDCCR_AIN) >> UDCCR_AIN_S, | 123 | (tmp & UDCCR_AIN) >> UDCCR_AIN_S, |
125 | (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S); | 124 | (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S); |
126 | /* registers for device and ep0 */ | 125 | /* registers for device and ep0 */ |
127 | pos += seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n", | 126 | seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n", |
128 | udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1)); | 127 | udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1)); |
129 | pos += seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n", | 128 | seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n", |
130 | udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1)); | 129 | udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1)); |
131 | pos += seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR)); | 130 | seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR)); |
132 | pos += seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, " | 131 | seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, reconfig=%lu\n", |
133 | "reconfig=%lu\n", | 132 | udc->stats.irqs_reset, udc->stats.irqs_suspend, |
134 | udc->stats.irqs_reset, udc->stats.irqs_suspend, | 133 | udc->stats.irqs_resume, udc->stats.irqs_reconfig); |
135 | udc->stats.irqs_resume, udc->stats.irqs_reconfig); | 134 | |
136 | 135 | return 0; | |
137 | ret = 0; | ||
138 | out: | ||
139 | return ret; | ||
140 | } | 136 | } |
141 | 137 | ||
142 | static int queues_dbg_show(struct seq_file *s, void *p) | 138 | static int queues_dbg_show(struct seq_file *s, void *p) |
@@ -144,75 +140,67 @@ static int queues_dbg_show(struct seq_file *s, void *p) | |||
144 | struct pxa_udc *udc = s->private; | 140 | struct pxa_udc *udc = s->private; |
145 | struct pxa_ep *ep; | 141 | struct pxa_ep *ep; |
146 | struct pxa27x_request *req; | 142 | struct pxa27x_request *req; |
147 | int pos = 0, i, maxpkt, ret; | 143 | int i, maxpkt; |
148 | 144 | ||
149 | ret = -ENODEV; | ||
150 | if (!udc->driver) | 145 | if (!udc->driver) |
151 | goto out; | 146 | return -ENODEV; |
152 | 147 | ||
153 | /* dump endpoint queues */ | 148 | /* dump endpoint queues */ |
154 | for (i = 0; i < NR_PXA_ENDPOINTS; i++) { | 149 | for (i = 0; i < NR_PXA_ENDPOINTS; i++) { |
155 | ep = &udc->pxa_ep[i]; | 150 | ep = &udc->pxa_ep[i]; |
156 | maxpkt = ep->fifo_size; | 151 | maxpkt = ep->fifo_size; |
157 | pos += seq_printf(s, "%-12s max_pkt=%d %s\n", | 152 | seq_printf(s, "%-12s max_pkt=%d %s\n", |
158 | EPNAME(ep), maxpkt, "pio"); | 153 | EPNAME(ep), maxpkt, "pio"); |
159 | 154 | ||
160 | if (list_empty(&ep->queue)) { | 155 | if (list_empty(&ep->queue)) { |
161 | pos += seq_printf(s, "\t(nothing queued)\n"); | 156 | seq_puts(s, "\t(nothing queued)\n"); |
162 | continue; | 157 | continue; |
163 | } | 158 | } |
164 | 159 | ||
165 | list_for_each_entry(req, &ep->queue, queue) { | 160 | list_for_each_entry(req, &ep->queue, queue) { |
166 | pos += seq_printf(s, "\treq %p len %d/%d buf %p\n", | 161 | seq_printf(s, "\treq %p len %d/%d buf %p\n", |
167 | &req->req, req->req.actual, | 162 | &req->req, req->req.actual, |
168 | req->req.length, req->req.buf); | 163 | req->req.length, req->req.buf); |
169 | } | 164 | } |
170 | } | 165 | } |
171 | 166 | ||
172 | ret = 0; | 167 | return 0; |
173 | out: | ||
174 | return ret; | ||
175 | } | 168 | } |
176 | 169 | ||
177 | static int eps_dbg_show(struct seq_file *s, void *p) | 170 | static int eps_dbg_show(struct seq_file *s, void *p) |
178 | { | 171 | { |
179 | struct pxa_udc *udc = s->private; | 172 | struct pxa_udc *udc = s->private; |
180 | struct pxa_ep *ep; | 173 | struct pxa_ep *ep; |
181 | int pos = 0, i, ret; | 174 | int i; |
182 | u32 tmp; | 175 | u32 tmp; |
183 | 176 | ||
184 | ret = -ENODEV; | ||
185 | if (!udc->driver) | 177 | if (!udc->driver) |
186 | goto out; | 178 | return -ENODEV; |
187 | 179 | ||
188 | ep = &udc->pxa_ep[0]; | 180 | ep = &udc->pxa_ep[0]; |
189 | tmp = udc_ep_readl(ep, UDCCSR); | 181 | tmp = udc_ep_readl(ep, UDCCSR); |
190 | pos += seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n", tmp, | 182 | seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n", |
191 | (tmp & UDCCSR0_SA) ? " sa" : "", | 183 | tmp, |
192 | (tmp & UDCCSR0_RNE) ? " rne" : "", | 184 | (tmp & UDCCSR0_SA) ? " sa" : "", |
193 | (tmp & UDCCSR0_FST) ? " fst" : "", | 185 | (tmp & UDCCSR0_RNE) ? " rne" : "", |
194 | (tmp & UDCCSR0_SST) ? " sst" : "", | 186 | (tmp & UDCCSR0_FST) ? " fst" : "", |
195 | (tmp & UDCCSR0_DME) ? " dme" : "", | 187 | (tmp & UDCCSR0_SST) ? " sst" : "", |
196 | (tmp & UDCCSR0_IPR) ? " ipr" : "", | 188 | (tmp & UDCCSR0_DME) ? " dme" : "", |
197 | (tmp & UDCCSR0_OPC) ? " opc" : ""); | 189 | (tmp & UDCCSR0_IPR) ? " ipr" : "", |
190 | (tmp & UDCCSR0_OPC) ? " opc" : ""); | ||
198 | for (i = 0; i < NR_PXA_ENDPOINTS; i++) { | 191 | for (i = 0; i < NR_PXA_ENDPOINTS; i++) { |
199 | ep = &udc->pxa_ep[i]; | 192 | ep = &udc->pxa_ep[i]; |
200 | tmp = i? udc_ep_readl(ep, UDCCR) : udc_readl(udc, UDCCR); | 193 | tmp = i? udc_ep_readl(ep, UDCCR) : udc_readl(udc, UDCCR); |
201 | pos += seq_printf(s, "%-12s: " | 194 | seq_printf(s, "%-12s: IN %lu(%lu reqs), OUT %lu(%lu reqs), irqs=%lu, udccr=0x%08x, udccsr=0x%03x, udcbcr=%d\n", |
202 | "IN %lu(%lu reqs), OUT %lu(%lu reqs), " | 195 | EPNAME(ep), |
203 | "irqs=%lu, udccr=0x%08x, udccsr=0x%03x, " | 196 | ep->stats.in_bytes, ep->stats.in_ops, |
204 | "udcbcr=%d\n", | 197 | ep->stats.out_bytes, ep->stats.out_ops, |
205 | EPNAME(ep), | 198 | ep->stats.irqs, |
206 | ep->stats.in_bytes, ep->stats.in_ops, | 199 | tmp, udc_ep_readl(ep, UDCCSR), |
207 | ep->stats.out_bytes, ep->stats.out_ops, | 200 | udc_ep_readl(ep, UDCBCR)); |
208 | ep->stats.irqs, | ||
209 | tmp, udc_ep_readl(ep, UDCCSR), | ||
210 | udc_ep_readl(ep, UDCBCR)); | ||
211 | } | 201 | } |
212 | 202 | ||
213 | ret = 0; | 203 | return 0; |
214 | out: | ||
215 | return ret; | ||
216 | } | 204 | } |
217 | 205 | ||
218 | static int eps_dbg_open(struct inode *inode, struct file *file) | 206 | static int eps_dbg_open(struct inode *inode, struct file *file) |
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index 5a81cb086b99..d69c35558f68 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c | |||
@@ -35,6 +35,8 @@ | |||
35 | * @dev - the child device to the actual controller | 35 | * @dev - the child device to the actual controller |
36 | * @gadget - the gadget. For use by the class code | 36 | * @gadget - the gadget. For use by the class code |
37 | * @list - for use by the udc class driver | 37 | * @list - for use by the udc class driver |
38 | * @vbus - for udcs who care about vbus status, this value is real vbus status; | ||
39 | * for udcs who do not care about vbus status, this value is always true | ||
38 | * | 40 | * |
39 | * This represents the internal data structure which is used by the UDC-class | 41 | * This represents the internal data structure which is used by the UDC-class |
40 | * to hold information about udc driver and gadget together. | 42 | * to hold information about udc driver and gadget together. |
@@ -44,6 +46,7 @@ struct usb_udc { | |||
44 | struct usb_gadget *gadget; | 46 | struct usb_gadget *gadget; |
45 | struct device dev; | 47 | struct device dev; |
46 | struct list_head list; | 48 | struct list_head list; |
49 | bool vbus; | ||
47 | }; | 50 | }; |
48 | 51 | ||
49 | static struct class *udc_class; | 52 | static struct class *udc_class; |
@@ -128,21 +131,11 @@ EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); | |||
128 | 131 | ||
129 | static void usb_gadget_state_work(struct work_struct *work) | 132 | static void usb_gadget_state_work(struct work_struct *work) |
130 | { | 133 | { |
131 | struct usb_gadget *gadget = work_to_gadget(work); | 134 | struct usb_gadget *gadget = work_to_gadget(work); |
132 | struct usb_udc *udc = NULL; | 135 | struct usb_udc *udc = gadget->udc; |
133 | |||
134 | mutex_lock(&udc_lock); | ||
135 | list_for_each_entry(udc, &udc_list, list) | ||
136 | if (udc->gadget == gadget) | ||
137 | goto found; | ||
138 | mutex_unlock(&udc_lock); | ||
139 | |||
140 | return; | ||
141 | |||
142 | found: | ||
143 | mutex_unlock(&udc_lock); | ||
144 | 136 | ||
145 | sysfs_notify(&udc->dev.kobj, NULL, "state"); | 137 | if (udc) |
138 | sysfs_notify(&udc->dev.kobj, NULL, "state"); | ||
146 | } | 139 | } |
147 | 140 | ||
148 | void usb_gadget_set_state(struct usb_gadget *gadget, | 141 | void usb_gadget_set_state(struct usb_gadget *gadget, |
@@ -155,6 +148,34 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state); | |||
155 | 148 | ||
156 | /* ------------------------------------------------------------------------- */ | 149 | /* ------------------------------------------------------------------------- */ |
157 | 150 | ||
151 | static void usb_udc_connect_control(struct usb_udc *udc) | ||
152 | { | ||
153 | if (udc->vbus) | ||
154 | usb_gadget_connect(udc->gadget); | ||
155 | else | ||
156 | usb_gadget_disconnect(udc->gadget); | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * usb_udc_vbus_handler - updates the udc core vbus status, and try to | ||
161 | * connect or disconnect gadget | ||
162 | * @gadget: The gadget which vbus change occurs | ||
163 | * @status: The vbus status | ||
164 | * | ||
165 | * The udc driver calls it when it wants to connect or disconnect gadget | ||
166 | * according to vbus status. | ||
167 | */ | ||
168 | void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) | ||
169 | { | ||
170 | struct usb_udc *udc = gadget->udc; | ||
171 | |||
172 | if (udc) { | ||
173 | udc->vbus = status; | ||
174 | usb_udc_connect_control(udc); | ||
175 | } | ||
176 | } | ||
177 | EXPORT_SYMBOL_GPL(usb_udc_vbus_handler); | ||
178 | |||
158 | /** | 179 | /** |
159 | * usb_gadget_udc_reset - notifies the udc core that bus reset occurs | 180 | * usb_gadget_udc_reset - notifies the udc core that bus reset occurs |
160 | * @gadget: The gadget which bus reset occurs | 181 | * @gadget: The gadget which bus reset occurs |
@@ -278,6 +299,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, | |||
278 | goto err3; | 299 | goto err3; |
279 | 300 | ||
280 | udc->gadget = gadget; | 301 | udc->gadget = gadget; |
302 | gadget->udc = udc; | ||
281 | 303 | ||
282 | mutex_lock(&udc_lock); | 304 | mutex_lock(&udc_lock); |
283 | list_add_tail(&udc->list, &udc_list); | 305 | list_add_tail(&udc->list, &udc_list); |
@@ -287,6 +309,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, | |||
287 | goto err4; | 309 | goto err4; |
288 | 310 | ||
289 | usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); | 311 | usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); |
312 | udc->vbus = true; | ||
290 | 313 | ||
291 | mutex_unlock(&udc_lock); | 314 | mutex_unlock(&udc_lock); |
292 | 315 | ||
@@ -348,21 +371,14 @@ static void usb_gadget_remove_driver(struct usb_udc *udc) | |||
348 | */ | 371 | */ |
349 | void usb_del_gadget_udc(struct usb_gadget *gadget) | 372 | void usb_del_gadget_udc(struct usb_gadget *gadget) |
350 | { | 373 | { |
351 | struct usb_udc *udc = NULL; | 374 | struct usb_udc *udc = gadget->udc; |
352 | 375 | ||
353 | mutex_lock(&udc_lock); | 376 | if (!udc) |
354 | list_for_each_entry(udc, &udc_list, list) | 377 | return; |
355 | if (udc->gadget == gadget) | ||
356 | goto found; | ||
357 | |||
358 | dev_err(gadget->dev.parent, "gadget not registered.\n"); | ||
359 | mutex_unlock(&udc_lock); | ||
360 | |||
361 | return; | ||
362 | 378 | ||
363 | found: | ||
364 | dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); | 379 | dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); |
365 | 380 | ||
381 | mutex_lock(&udc_lock); | ||
366 | list_del(&udc->list); | 382 | list_del(&udc->list); |
367 | mutex_unlock(&udc_lock); | 383 | mutex_unlock(&udc_lock); |
368 | 384 | ||
@@ -397,7 +413,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri | |||
397 | driver->unbind(udc->gadget); | 413 | driver->unbind(udc->gadget); |
398 | goto err1; | 414 | goto err1; |
399 | } | 415 | } |
400 | usb_gadget_connect(udc->gadget); | 416 | usb_udc_connect_control(udc); |
401 | 417 | ||
402 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); | 418 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
403 | return 0; | 419 | return 0; |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 067920f2d570..a48b5a9c6c47 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -507,7 +507,8 @@ void musb_hnp_stop(struct musb *musb) | |||
507 | musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); | 507 | musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); |
508 | } | 508 | } |
509 | 509 | ||
510 | static void musb_generic_disable(struct musb *musb); | 510 | static void musb_recover_from_babble(struct musb *musb); |
511 | |||
511 | /* | 512 | /* |
512 | * Interrupt Service Routine to record USB "global" interrupts. | 513 | * Interrupt Service Routine to record USB "global" interrupts. |
513 | * Since these do not happen often and signify things of | 514 | * Since these do not happen often and signify things of |
@@ -534,30 +535,16 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
534 | */ | 535 | */ |
535 | if (int_usb & MUSB_INTR_RESUME) { | 536 | if (int_usb & MUSB_INTR_RESUME) { |
536 | handled = IRQ_HANDLED; | 537 | handled = IRQ_HANDLED; |
537 | dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->otg->state)); | 538 | dev_dbg(musb->controller, "RESUME (%s)\n", |
539 | usb_otg_state_string(musb->xceiv->otg->state)); | ||
538 | 540 | ||
539 | if (devctl & MUSB_DEVCTL_HM) { | 541 | if (devctl & MUSB_DEVCTL_HM) { |
540 | void __iomem *mbase = musb->mregs; | ||
541 | u8 power; | ||
542 | |||
543 | switch (musb->xceiv->otg->state) { | 542 | switch (musb->xceiv->otg->state) { |
544 | case OTG_STATE_A_SUSPEND: | 543 | case OTG_STATE_A_SUSPEND: |
545 | /* remote wakeup? later, GetPortStatus | 544 | /* remote wakeup? later, GetPortStatus |
546 | * will stop RESUME signaling | 545 | * will stop RESUME signaling |
547 | */ | 546 | */ |
548 | 547 | ||
549 | power = musb_readb(musb->mregs, MUSB_POWER); | ||
550 | if (power & MUSB_POWER_SUSPENDM) { | ||
551 | /* spurious */ | ||
552 | musb->int_usb &= ~MUSB_INTR_SUSPEND; | ||
553 | dev_dbg(musb->controller, "Spurious SUSPENDM\n"); | ||
554 | break; | ||
555 | } | ||
556 | |||
557 | power &= ~MUSB_POWER_SUSPENDM; | ||
558 | musb_writeb(mbase, MUSB_POWER, | ||
559 | power | MUSB_POWER_RESUME); | ||
560 | |||
561 | musb->port1_status |= | 548 | musb->port1_status |= |
562 | (USB_PORT_STAT_C_SUSPEND << 16) | 549 | (USB_PORT_STAT_C_SUSPEND << 16) |
563 | | MUSB_PORT_STAT_RESUME; | 550 | | MUSB_PORT_STAT_RESUME; |
@@ -775,10 +762,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
775 | 762 | ||
776 | musb->ep0_stage = MUSB_EP0_START; | 763 | musb->ep0_stage = MUSB_EP0_START; |
777 | 764 | ||
778 | /* flush endpoints when transitioning from Device Mode */ | ||
779 | if (is_peripheral_active(musb)) { | ||
780 | /* REVISIT HNP; just force disconnect */ | ||
781 | } | ||
782 | musb->intrtxe = musb->epmask; | 765 | musb->intrtxe = musb->epmask; |
783 | musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe); | 766 | musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe); |
784 | musb->intrrxe = musb->epmask & 0xfffe; | 767 | musb->intrrxe = musb->epmask & 0xfffe; |
@@ -879,20 +862,19 @@ b_host: | |||
879 | */ | 862 | */ |
880 | if (int_usb & MUSB_INTR_RESET) { | 863 | if (int_usb & MUSB_INTR_RESET) { |
881 | handled = IRQ_HANDLED; | 864 | handled = IRQ_HANDLED; |
882 | if ((devctl & MUSB_DEVCTL_HM) != 0) { | 865 | if (devctl & MUSB_DEVCTL_HM) { |
883 | /* | 866 | /* |
884 | * Looks like non-HS BABBLE can be ignored, but | 867 | * When BABBLE happens what we can depends on which |
885 | * HS BABBLE is an error condition. For HS the solution | 868 | * platform MUSB is running, because some platforms |
886 | * is to avoid babble in the first place and fix what | 869 | * implemented proprietary means for 'recovering' from |
887 | * caused BABBLE. When HS BABBLE happens we can only | 870 | * Babble conditions. One such platform is AM335x. In |
888 | * stop the session. | 871 | * most cases, however, the only thing we can do is |
872 | * drop the session. | ||
889 | */ | 873 | */ |
890 | if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV)) | 874 | dev_err(musb->controller, "Babble\n"); |
891 | dev_dbg(musb->controller, "BABBLE devctl: %02x\n", devctl); | 875 | |
892 | else { | 876 | if (is_host_active(musb)) |
893 | ERR("Stopping host session -- babble\n"); | 877 | musb_recover_from_babble(musb); |
894 | musb_writeb(musb->mregs, MUSB_DEVCTL, 0); | ||
895 | } | ||
896 | } else { | 878 | } else { |
897 | dev_dbg(musb->controller, "BUS RESET as %s\n", | 879 | dev_dbg(musb->controller, "BUS RESET as %s\n", |
898 | usb_otg_state_string(musb->xceiv->otg->state)); | 880 | usb_otg_state_string(musb->xceiv->otg->state)); |
@@ -931,13 +913,6 @@ b_host: | |||
931 | } | 913 | } |
932 | } | 914 | } |
933 | 915 | ||
934 | /* handle babble condition */ | ||
935 | if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb)) { | ||
936 | musb_generic_disable(musb); | ||
937 | schedule_delayed_work(&musb->recover_work, | ||
938 | msecs_to_jiffies(100)); | ||
939 | } | ||
940 | |||
941 | #if 0 | 916 | #if 0 |
942 | /* REVISIT ... this would be for multiplexing periodic endpoints, or | 917 | /* REVISIT ... this would be for multiplexing periodic endpoints, or |
943 | * supporting transfer phasing to prevent exceeding ISO bandwidth | 918 | * supporting transfer phasing to prevent exceeding ISO bandwidth |
@@ -990,7 +965,7 @@ b_host: | |||
990 | 965 | ||
991 | /*-------------------------------------------------------------------------*/ | 966 | /*-------------------------------------------------------------------------*/ |
992 | 967 | ||
993 | static void musb_generic_disable(struct musb *musb) | 968 | static void musb_disable_interrupts(struct musb *musb) |
994 | { | 969 | { |
995 | void __iomem *mbase = musb->mregs; | 970 | void __iomem *mbase = musb->mregs; |
996 | u16 temp; | 971 | u16 temp; |
@@ -1002,14 +977,33 @@ static void musb_generic_disable(struct musb *musb) | |||
1002 | musb->intrrxe = 0; | 977 | musb->intrrxe = 0; |
1003 | musb_writew(mbase, MUSB_INTRRXE, 0); | 978 | musb_writew(mbase, MUSB_INTRRXE, 0); |
1004 | 979 | ||
1005 | /* off */ | ||
1006 | musb_writeb(mbase, MUSB_DEVCTL, 0); | ||
1007 | |||
1008 | /* flush pending interrupts */ | 980 | /* flush pending interrupts */ |
1009 | temp = musb_readb(mbase, MUSB_INTRUSB); | 981 | temp = musb_readb(mbase, MUSB_INTRUSB); |
1010 | temp = musb_readw(mbase, MUSB_INTRTX); | 982 | temp = musb_readw(mbase, MUSB_INTRTX); |
1011 | temp = musb_readw(mbase, MUSB_INTRRX); | 983 | temp = musb_readw(mbase, MUSB_INTRRX); |
984 | } | ||
985 | |||
986 | static void musb_enable_interrupts(struct musb *musb) | ||
987 | { | ||
988 | void __iomem *regs = musb->mregs; | ||
989 | |||
990 | /* Set INT enable registers, enable interrupts */ | ||
991 | musb->intrtxe = musb->epmask; | ||
992 | musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); | ||
993 | musb->intrrxe = musb->epmask & 0xfffe; | ||
994 | musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); | ||
995 | musb_writeb(regs, MUSB_INTRUSBE, 0xf7); | ||
996 | |||
997 | } | ||
998 | |||
999 | static void musb_generic_disable(struct musb *musb) | ||
1000 | { | ||
1001 | void __iomem *mbase = musb->mregs; | ||
1012 | 1002 | ||
1003 | musb_disable_interrupts(musb); | ||
1004 | |||
1005 | /* off */ | ||
1006 | musb_writeb(mbase, MUSB_DEVCTL, 0); | ||
1013 | } | 1007 | } |
1014 | 1008 | ||
1015 | /* | 1009 | /* |
@@ -1022,13 +1016,7 @@ void musb_start(struct musb *musb) | |||
1022 | 1016 | ||
1023 | dev_dbg(musb->controller, "<== devctl %02x\n", devctl); | 1017 | dev_dbg(musb->controller, "<== devctl %02x\n", devctl); |
1024 | 1018 | ||
1025 | /* Set INT enable registers, enable interrupts */ | 1019 | musb_enable_interrupts(musb); |
1026 | musb->intrtxe = musb->epmask; | ||
1027 | musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); | ||
1028 | musb->intrrxe = musb->epmask & 0xfffe; | ||
1029 | musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); | ||
1030 | musb_writeb(regs, MUSB_INTRUSBE, 0xf7); | ||
1031 | |||
1032 | musb_writeb(regs, MUSB_TESTMODE, 0); | 1020 | musb_writeb(regs, MUSB_TESTMODE, 0); |
1033 | 1021 | ||
1034 | /* put into basic highspeed mode and start session */ | 1022 | /* put into basic highspeed mode and start session */ |
@@ -1587,9 +1575,12 @@ static int musb_core_init(u16 musb_type, struct musb *musb) | |||
1587 | irqreturn_t musb_interrupt(struct musb *musb) | 1575 | irqreturn_t musb_interrupt(struct musb *musb) |
1588 | { | 1576 | { |
1589 | irqreturn_t retval = IRQ_NONE; | 1577 | irqreturn_t retval = IRQ_NONE; |
1578 | unsigned long status; | ||
1579 | unsigned long epnum; | ||
1590 | u8 devctl; | 1580 | u8 devctl; |
1591 | int ep_num; | 1581 | |
1592 | u32 reg; | 1582 | if (!musb->int_usb && !musb->int_tx && !musb->int_rx) |
1583 | return IRQ_NONE; | ||
1593 | 1584 | ||
1594 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 1585 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
1595 | 1586 | ||
@@ -1597,56 +1588,57 @@ irqreturn_t musb_interrupt(struct musb *musb) | |||
1597 | is_host_active(musb) ? "host" : "peripheral", | 1588 | is_host_active(musb) ? "host" : "peripheral", |
1598 | musb->int_usb, musb->int_tx, musb->int_rx); | 1589 | musb->int_usb, musb->int_tx, musb->int_rx); |
1599 | 1590 | ||
1600 | /* the core can interrupt us for multiple reasons; docs have | 1591 | /** |
1601 | * a generic interrupt flowchart to follow | 1592 | * According to Mentor Graphics' documentation, flowchart on page 98, |
1593 | * IRQ should be handled as follows: | ||
1594 | * | ||
1595 | * . Resume IRQ | ||
1596 | * . Session Request IRQ | ||
1597 | * . VBUS Error IRQ | ||
1598 | * . Suspend IRQ | ||
1599 | * . Connect IRQ | ||
1600 | * . Disconnect IRQ | ||
1601 | * . Reset/Babble IRQ | ||
1602 | * . SOF IRQ (we're not using this one) | ||
1603 | * . Endpoint 0 IRQ | ||
1604 | * . TX Endpoints | ||
1605 | * . RX Endpoints | ||
1606 | * | ||
1607 | * We will be following that flowchart in order to avoid any problems | ||
1608 | * that might arise with internal Finite State Machine. | ||
1602 | */ | 1609 | */ |
1603 | if (musb->int_usb) | ||
1604 | retval |= musb_stage0_irq(musb, musb->int_usb, | ||
1605 | devctl); | ||
1606 | 1610 | ||
1607 | /* "stage 1" is handling endpoint irqs */ | 1611 | if (musb->int_usb) |
1612 | retval |= musb_stage0_irq(musb, musb->int_usb, devctl); | ||
1608 | 1613 | ||
1609 | /* handle endpoint 0 first */ | ||
1610 | if (musb->int_tx & 1) { | 1614 | if (musb->int_tx & 1) { |
1611 | if (is_host_active(musb)) | 1615 | if (is_host_active(musb)) |
1612 | retval |= musb_h_ep0_irq(musb); | 1616 | retval |= musb_h_ep0_irq(musb); |
1613 | else | 1617 | else |
1614 | retval |= musb_g_ep0_irq(musb); | 1618 | retval |= musb_g_ep0_irq(musb); |
1619 | |||
1620 | /* we have just handled endpoint 0 IRQ, clear it */ | ||
1621 | musb->int_tx &= ~BIT(0); | ||
1615 | } | 1622 | } |
1616 | 1623 | ||
1617 | /* RX on endpoints 1-15 */ | 1624 | status = musb->int_tx; |
1618 | reg = musb->int_rx >> 1; | ||
1619 | ep_num = 1; | ||
1620 | while (reg) { | ||
1621 | if (reg & 1) { | ||
1622 | /* musb_ep_select(musb->mregs, ep_num); */ | ||
1623 | /* REVISIT just retval = ep->rx_irq(...) */ | ||
1624 | retval = IRQ_HANDLED; | ||
1625 | if (is_host_active(musb)) | ||
1626 | musb_host_rx(musb, ep_num); | ||
1627 | else | ||
1628 | musb_g_rx(musb, ep_num); | ||
1629 | } | ||
1630 | 1625 | ||
1631 | reg >>= 1; | 1626 | for_each_set_bit(epnum, &status, 16) { |
1632 | ep_num++; | 1627 | retval = IRQ_HANDLED; |
1628 | if (is_host_active(musb)) | ||
1629 | musb_host_tx(musb, epnum); | ||
1630 | else | ||
1631 | musb_g_tx(musb, epnum); | ||
1633 | } | 1632 | } |
1634 | 1633 | ||
1635 | /* TX on endpoints 1-15 */ | 1634 | status = musb->int_rx; |
1636 | reg = musb->int_tx >> 1; | 1635 | |
1637 | ep_num = 1; | 1636 | for_each_set_bit(epnum, &status, 16) { |
1638 | while (reg) { | 1637 | retval = IRQ_HANDLED; |
1639 | if (reg & 1) { | 1638 | if (is_host_active(musb)) |
1640 | /* musb_ep_select(musb->mregs, ep_num); */ | 1639 | musb_host_rx(musb, epnum); |
1641 | /* REVISIT just retval |= ep->tx_irq(...) */ | 1640 | else |
1642 | retval = IRQ_HANDLED; | 1641 | musb_g_rx(musb, epnum); |
1643 | if (is_host_active(musb)) | ||
1644 | musb_host_tx(musb, ep_num); | ||
1645 | else | ||
1646 | musb_g_tx(musb, ep_num); | ||
1647 | } | ||
1648 | reg >>= 1; | ||
1649 | ep_num++; | ||
1650 | } | 1642 | } |
1651 | 1643 | ||
1652 | return retval; | 1644 | return retval; |
@@ -1825,33 +1817,44 @@ static void musb_irq_work(struct work_struct *data) | |||
1825 | } | 1817 | } |
1826 | } | 1818 | } |
1827 | 1819 | ||
1828 | /* Recover from babble interrupt conditions */ | 1820 | static void musb_recover_from_babble(struct musb *musb) |
1829 | static void musb_recover_work(struct work_struct *data) | ||
1830 | { | 1821 | { |
1831 | struct musb *musb = container_of(data, struct musb, recover_work.work); | 1822 | int ret; |
1832 | int status, ret; | 1823 | u8 devctl; |
1833 | 1824 | ||
1834 | ret = musb_platform_reset(musb); | 1825 | musb_disable_interrupts(musb); |
1835 | if (ret) | 1826 | |
1827 | /* | ||
1828 | * wait at least 320 cycles of 60MHz clock. That's 5.3us, we will give | ||
1829 | * it some slack and wait for 10us. | ||
1830 | */ | ||
1831 | udelay(10); | ||
1832 | |||
1833 | ret = musb_platform_recover(musb); | ||
1834 | if (ret) { | ||
1835 | musb_enable_interrupts(musb); | ||
1836 | return; | 1836 | return; |
1837 | } | ||
1837 | 1838 | ||
1838 | usb_phy_vbus_off(musb->xceiv); | 1839 | /* drop session bit */ |
1839 | usleep_range(100, 200); | 1840 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
1841 | devctl &= ~MUSB_DEVCTL_SESSION; | ||
1842 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | ||
1840 | 1843 | ||
1841 | usb_phy_vbus_on(musb->xceiv); | 1844 | /* tell usbcore about it */ |
1842 | usleep_range(100, 200); | 1845 | musb_root_disconnect(musb); |
1843 | 1846 | ||
1844 | /* | 1847 | /* |
1845 | * When a babble condition occurs, the musb controller | 1848 | * When a babble condition occurs, the musb controller |
1846 | * removes the session bit and the endpoint config is lost. | 1849 | * removes the session bit and the endpoint config is lost. |
1847 | */ | 1850 | */ |
1848 | if (musb->dyn_fifo) | 1851 | if (musb->dyn_fifo) |
1849 | status = ep_config_from_table(musb); | 1852 | ret = ep_config_from_table(musb); |
1850 | else | 1853 | else |
1851 | status = ep_config_from_hw(musb); | 1854 | ret = ep_config_from_hw(musb); |
1852 | 1855 | ||
1853 | /* start the session again */ | 1856 | /* restart session */ |
1854 | if (status == 0) | 1857 | if (ret == 0) |
1855 | musb_start(musb); | 1858 | musb_start(musb); |
1856 | } | 1859 | } |
1857 | 1860 | ||
@@ -2087,7 +2090,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
2087 | 2090 | ||
2088 | /* Init IRQ workqueue before request_irq */ | 2091 | /* Init IRQ workqueue before request_irq */ |
2089 | INIT_WORK(&musb->irq_work, musb_irq_work); | 2092 | INIT_WORK(&musb->irq_work, musb_irq_work); |
2090 | INIT_DELAYED_WORK(&musb->recover_work, musb_recover_work); | ||
2091 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); | 2093 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); |
2092 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); | 2094 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); |
2093 | 2095 | ||
@@ -2183,7 +2185,6 @@ fail4: | |||
2183 | 2185 | ||
2184 | fail3: | 2186 | fail3: |
2185 | cancel_work_sync(&musb->irq_work); | 2187 | cancel_work_sync(&musb->irq_work); |
2186 | cancel_delayed_work_sync(&musb->recover_work); | ||
2187 | cancel_delayed_work_sync(&musb->finish_resume_work); | 2188 | cancel_delayed_work_sync(&musb->finish_resume_work); |
2188 | cancel_delayed_work_sync(&musb->deassert_reset_work); | 2189 | cancel_delayed_work_sync(&musb->deassert_reset_work); |
2189 | if (musb->dma_controller) | 2190 | if (musb->dma_controller) |
@@ -2249,7 +2250,6 @@ static int musb_remove(struct platform_device *pdev) | |||
2249 | dma_controller_destroy(musb->dma_controller); | 2250 | dma_controller_destroy(musb->dma_controller); |
2250 | 2251 | ||
2251 | cancel_work_sync(&musb->irq_work); | 2252 | cancel_work_sync(&musb->irq_work); |
2252 | cancel_delayed_work_sync(&musb->recover_work); | ||
2253 | cancel_delayed_work_sync(&musb->finish_resume_work); | 2253 | cancel_delayed_work_sync(&musb->finish_resume_work); |
2254 | cancel_delayed_work_sync(&musb->deassert_reset_work); | 2254 | cancel_delayed_work_sync(&musb->deassert_reset_work); |
2255 | musb_free(musb); | 2255 | musb_free(musb); |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 5e65958f7915..3877249a8b2d 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -160,7 +160,8 @@ struct musb_io; | |||
160 | * @init: turns on clocks, sets up platform-specific registers, etc | 160 | * @init: turns on clocks, sets up platform-specific registers, etc |
161 | * @exit: undoes @init | 161 | * @exit: undoes @init |
162 | * @set_mode: forcefully changes operating mode | 162 | * @set_mode: forcefully changes operating mode |
163 | * @try_ilde: tries to idle the IP | 163 | * @try_idle: tries to idle the IP |
164 | * @recover: platform-specific babble recovery | ||
164 | * @vbus_status: returns vbus status if possible | 165 | * @vbus_status: returns vbus status if possible |
165 | * @set_vbus: forces vbus status | 166 | * @set_vbus: forces vbus status |
166 | * @adjust_channel_params: pre check for standard dma channel_program func | 167 | * @adjust_channel_params: pre check for standard dma channel_program func |
@@ -196,7 +197,7 @@ struct musb_platform_ops { | |||
196 | void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); | 197 | void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); |
197 | int (*set_mode)(struct musb *musb, u8 mode); | 198 | int (*set_mode)(struct musb *musb, u8 mode); |
198 | void (*try_idle)(struct musb *musb, unsigned long timeout); | 199 | void (*try_idle)(struct musb *musb, unsigned long timeout); |
199 | int (*reset)(struct musb *musb); | 200 | int (*recover)(struct musb *musb); |
200 | 201 | ||
201 | int (*vbus_status)(struct musb *musb); | 202 | int (*vbus_status)(struct musb *musb); |
202 | void (*set_vbus)(struct musb *musb, int on); | 203 | void (*set_vbus)(struct musb *musb, int on); |
@@ -300,7 +301,6 @@ struct musb { | |||
300 | 301 | ||
301 | irqreturn_t (*isr)(int, void *); | 302 | irqreturn_t (*isr)(int, void *); |
302 | struct work_struct irq_work; | 303 | struct work_struct irq_work; |
303 | struct delayed_work recover_work; | ||
304 | struct delayed_work deassert_reset_work; | 304 | struct delayed_work deassert_reset_work; |
305 | struct delayed_work finish_resume_work; | 305 | struct delayed_work finish_resume_work; |
306 | u16 hwvers; | 306 | u16 hwvers; |
@@ -558,12 +558,12 @@ static inline void musb_platform_try_idle(struct musb *musb, | |||
558 | musb->ops->try_idle(musb, timeout); | 558 | musb->ops->try_idle(musb, timeout); |
559 | } | 559 | } |
560 | 560 | ||
561 | static inline int musb_platform_reset(struct musb *musb) | 561 | static inline int musb_platform_recover(struct musb *musb) |
562 | { | 562 | { |
563 | if (!musb->ops->reset) | 563 | if (!musb->ops->recover) |
564 | return -EINVAL; | 564 | return 0; |
565 | 565 | ||
566 | return musb->ops->reset(musb); | 566 | return musb->ops->recover(musb); |
567 | } | 567 | } |
568 | 568 | ||
569 | static inline int musb_platform_get_vbus_status(struct musb *musb) | 569 | static inline int musb_platform_get_vbus_status(struct musb *musb) |
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index be84562d021b..8bd8c5e26921 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c | |||
@@ -225,10 +225,12 @@ static void cppi41_dma_callback(void *private_data) | |||
225 | struct dma_channel *channel = private_data; | 225 | struct dma_channel *channel = private_data; |
226 | struct cppi41_dma_channel *cppi41_channel = channel->private_data; | 226 | struct cppi41_dma_channel *cppi41_channel = channel->private_data; |
227 | struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; | 227 | struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; |
228 | struct cppi41_dma_controller *controller; | ||
228 | struct musb *musb = hw_ep->musb; | 229 | struct musb *musb = hw_ep->musb; |
229 | unsigned long flags; | 230 | unsigned long flags; |
230 | struct dma_tx_state txstate; | 231 | struct dma_tx_state txstate; |
231 | u32 transferred; | 232 | u32 transferred; |
233 | int is_hs = 0; | ||
232 | bool empty; | 234 | bool empty; |
233 | 235 | ||
234 | spin_lock_irqsave(&musb->lock, flags); | 236 | spin_lock_irqsave(&musb->lock, flags); |
@@ -248,61 +250,59 @@ static void cppi41_dma_callback(void *private_data) | |||
248 | transferred < cppi41_channel->packet_sz) | 250 | transferred < cppi41_channel->packet_sz) |
249 | cppi41_channel->prog_len = 0; | 251 | cppi41_channel->prog_len = 0; |
250 | 252 | ||
251 | empty = musb_is_tx_fifo_empty(hw_ep); | 253 | if (cppi41_channel->is_tx) |
252 | if (empty) { | 254 | empty = musb_is_tx_fifo_empty(hw_ep); |
255 | |||
256 | if (!cppi41_channel->is_tx || empty) { | ||
253 | cppi41_trans_done(cppi41_channel); | 257 | cppi41_trans_done(cppi41_channel); |
254 | } else { | 258 | goto out; |
255 | struct cppi41_dma_controller *controller; | 259 | } |
256 | int is_hs = 0; | ||
257 | /* | ||
258 | * On AM335x it has been observed that the TX interrupt fires | ||
259 | * too early that means the TXFIFO is not yet empty but the DMA | ||
260 | * engine says that it is done with the transfer. We don't | ||
261 | * receive a FIFO empty interrupt so the only thing we can do is | ||
262 | * to poll for the bit. On HS it usually takes 2us, on FS around | ||
263 | * 110us - 150us depending on the transfer size. | ||
264 | * We spin on HS (no longer than than 25us and setup a timer on | ||
265 | * FS to check for the bit and complete the transfer. | ||
266 | */ | ||
267 | controller = cppi41_channel->controller; | ||
268 | 260 | ||
269 | if (is_host_active(musb)) { | 261 | /* |
270 | if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED) | 262 | * On AM335x it has been observed that the TX interrupt fires |
271 | is_hs = 1; | 263 | * too early that means the TXFIFO is not yet empty but the DMA |
272 | } else { | 264 | * engine says that it is done with the transfer. We don't |
273 | if (musb->g.speed == USB_SPEED_HIGH) | 265 | * receive a FIFO empty interrupt so the only thing we can do is |
274 | is_hs = 1; | 266 | * to poll for the bit. On HS it usually takes 2us, on FS around |
275 | } | 267 | * 110us - 150us depending on the transfer size. |
276 | if (is_hs) { | 268 | * We spin on HS (no longer than than 25us and setup a timer on |
277 | unsigned wait = 25; | 269 | * FS to check for the bit and complete the transfer. |
278 | 270 | */ | |
279 | do { | 271 | controller = cppi41_channel->controller; |
280 | empty = musb_is_tx_fifo_empty(hw_ep); | 272 | |
281 | if (empty) | 273 | if (is_host_active(musb)) { |
282 | break; | 274 | if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED) |
283 | wait--; | 275 | is_hs = 1; |
284 | if (!wait) | 276 | } else { |
285 | break; | 277 | if (musb->g.speed == USB_SPEED_HIGH) |
286 | udelay(1); | 278 | is_hs = 1; |
287 | } while (1); | 279 | } |
280 | if (is_hs) { | ||
281 | unsigned wait = 25; | ||
288 | 282 | ||
283 | do { | ||
289 | empty = musb_is_tx_fifo_empty(hw_ep); | 284 | empty = musb_is_tx_fifo_empty(hw_ep); |
290 | if (empty) { | 285 | if (empty) { |
291 | cppi41_trans_done(cppi41_channel); | 286 | cppi41_trans_done(cppi41_channel); |
292 | goto out; | 287 | goto out; |
293 | } | 288 | } |
294 | } | 289 | wait--; |
295 | list_add_tail(&cppi41_channel->tx_check, | 290 | if (!wait) |
296 | &controller->early_tx_list); | 291 | break; |
297 | if (!hrtimer_is_queued(&controller->early_tx)) { | 292 | cpu_relax(); |
298 | unsigned long usecs = cppi41_channel->total_len / 10; | 293 | } while (1); |
294 | } | ||
295 | list_add_tail(&cppi41_channel->tx_check, | ||
296 | &controller->early_tx_list); | ||
297 | if (!hrtimer_is_queued(&controller->early_tx)) { | ||
298 | unsigned long usecs = cppi41_channel->total_len / 10; | ||
299 | 299 | ||
300 | hrtimer_start_range_ns(&controller->early_tx, | 300 | hrtimer_start_range_ns(&controller->early_tx, |
301 | ktime_set(0, usecs * NSEC_PER_USEC), | 301 | ktime_set(0, usecs * NSEC_PER_USEC), |
302 | 20 * NSEC_PER_USEC, | 302 | 20 * NSEC_PER_USEC, |
303 | HRTIMER_MODE_REL); | 303 | HRTIMER_MODE_REL); |
304 | } | ||
305 | } | 304 | } |
305 | |||
306 | out: | 306 | out: |
307 | spin_unlock_irqrestore(&musb->lock, flags); | 307 | spin_unlock_irqrestore(&musb->lock, flags); |
308 | } | 308 | } |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index a900c9877195..b23ad150a165 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -119,7 +119,7 @@ struct dsps_musb_wrapper { | |||
119 | unsigned iddig:5; | 119 | unsigned iddig:5; |
120 | unsigned iddig_mux:5; | 120 | unsigned iddig_mux:5; |
121 | /* miscellaneous stuff */ | 121 | /* miscellaneous stuff */ |
122 | u8 poll_seconds; | 122 | unsigned poll_timeout; |
123 | }; | 123 | }; |
124 | 124 | ||
125 | /* | 125 | /* |
@@ -225,9 +225,8 @@ static void dsps_musb_enable(struct musb *musb) | |||
225 | 225 | ||
226 | dsps_writel(reg_base, wrp->epintr_set, epmask); | 226 | dsps_writel(reg_base, wrp->epintr_set, epmask); |
227 | dsps_writel(reg_base, wrp->coreintr_set, coremask); | 227 | dsps_writel(reg_base, wrp->coreintr_set, coremask); |
228 | /* Force the DRVVBUS IRQ so we can start polling for ID change. */ | 228 | /* start polling for ID change. */ |
229 | dsps_writel(reg_base, wrp->coreintr_set, | 229 | mod_timer(&glue->timer, jiffies + msecs_to_jiffies(wrp->poll_timeout)); |
230 | (1 << wrp->drvvbus) << wrp->usb_shift); | ||
231 | dsps_musb_try_idle(musb, 0); | 230 | dsps_musb_try_idle(musb, 0); |
232 | } | 231 | } |
233 | 232 | ||
@@ -285,7 +284,8 @@ static void otg_timer(unsigned long _musb) | |||
285 | } | 284 | } |
286 | if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) | 285 | if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) |
287 | dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); | 286 | dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); |
288 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 287 | mod_timer(&glue->timer, jiffies + |
288 | msecs_to_jiffies(wrp->poll_timeout)); | ||
289 | break; | 289 | break; |
290 | case OTG_STATE_A_WAIT_VFALL: | 290 | case OTG_STATE_A_WAIT_VFALL: |
291 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; | 291 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
@@ -330,28 +330,6 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
330 | 330 | ||
331 | dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n", | 331 | dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n", |
332 | usbintr, epintr); | 332 | usbintr, epintr); |
333 | /* | ||
334 | * DRVVBUS IRQs are the only proxy we have (a very poor one!) for | ||
335 | * DSPS IP's missing ID change IRQ. We need an ID change IRQ to | ||
336 | * switch appropriately between halves of the OTG state machine. | ||
337 | * Managing DEVCTL.SESSION per Mentor docs requires that we know its | ||
338 | * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. | ||
339 | * Also, DRVVBUS pulses for SRP (but not at 5V) ... | ||
340 | */ | ||
341 | if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) { | ||
342 | pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); | ||
343 | |||
344 | /* | ||
345 | * When a babble condition occurs, the musb controller removes | ||
346 | * the session and is no longer in host mode. Hence, all | ||
347 | * devices connected to its root hub get disconnected. | ||
348 | * | ||
349 | * Hand this error down to the musb core isr, so it can | ||
350 | * recover. | ||
351 | */ | ||
352 | musb->int_usb = MUSB_INTR_BABBLE | MUSB_INTR_DISCONNECT; | ||
353 | musb->int_tx = musb->int_rx = 0; | ||
354 | } | ||
355 | 333 | ||
356 | if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { | 334 | if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { |
357 | int drvvbus = dsps_readl(reg_base, wrp->status); | 335 | int drvvbus = dsps_readl(reg_base, wrp->status); |
@@ -374,8 +352,8 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
374 | */ | 352 | */ |
375 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; | 353 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; |
376 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; | 354 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
377 | mod_timer(&glue->timer, | 355 | mod_timer(&glue->timer, jiffies + |
378 | jiffies + wrp->poll_seconds * HZ); | 356 | msecs_to_jiffies(wrp->poll_timeout)); |
379 | WARNING("VBUS error workaround (delay coming)\n"); | 357 | WARNING("VBUS error workaround (delay coming)\n"); |
380 | } else if (drvvbus) { | 358 | } else if (drvvbus) { |
381 | MUSB_HST_MODE(musb); | 359 | MUSB_HST_MODE(musb); |
@@ -404,7 +382,8 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
404 | /* Poll for ID change in OTG port mode */ | 382 | /* Poll for ID change in OTG port mode */ |
405 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && | 383 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && |
406 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) | 384 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) |
407 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 385 | mod_timer(&glue->timer, jiffies + |
386 | msecs_to_jiffies(wrp->poll_timeout)); | ||
408 | out: | 387 | out: |
409 | spin_unlock_irqrestore(&musb->lock, flags); | 388 | spin_unlock_irqrestore(&musb->lock, flags); |
410 | 389 | ||
@@ -453,7 +432,7 @@ static int dsps_musb_init(struct musb *musb) | |||
453 | musb->ctrl_base = reg_base; | 432 | musb->ctrl_base = reg_base; |
454 | 433 | ||
455 | /* NOP driver needs change if supporting dual instance */ | 434 | /* NOP driver needs change if supporting dual instance */ |
456 | musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0); | 435 | musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, "phys", 0); |
457 | if (IS_ERR(musb->xceiv)) | 436 | if (IS_ERR(musb->xceiv)) |
458 | return PTR_ERR(musb->xceiv); | 437 | return PTR_ERR(musb->xceiv); |
459 | 438 | ||
@@ -497,7 +476,7 @@ static int dsps_musb_init(struct musb *musb) | |||
497 | * logic enabled. | 476 | * logic enabled. |
498 | */ | 477 | */ |
499 | val = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); | 478 | val = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); |
500 | if (val == MUSB_BABBLE_RCV_DISABLE) { | 479 | if (val & MUSB_BABBLE_RCV_DISABLE) { |
501 | glue->sw_babble_enabled = true; | 480 | glue->sw_babble_enabled = true; |
502 | val |= MUSB_BABBLE_SW_SESSION_CTRL; | 481 | val |= MUSB_BABBLE_SW_SESSION_CTRL; |
503 | dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, val); | 482 | dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, val); |
@@ -571,7 +550,7 @@ static int dsps_musb_set_mode(struct musb *musb, u8 mode) | |||
571 | return 0; | 550 | return 0; |
572 | } | 551 | } |
573 | 552 | ||
574 | static bool sw_babble_control(struct musb *musb) | 553 | static bool dsps_sw_babble_control(struct musb *musb) |
575 | { | 554 | { |
576 | u8 babble_ctl; | 555 | u8 babble_ctl; |
577 | bool session_restart = false; | 556 | bool session_restart = false; |
@@ -622,37 +601,36 @@ static bool sw_babble_control(struct musb *musb) | |||
622 | return session_restart; | 601 | return session_restart; |
623 | } | 602 | } |
624 | 603 | ||
625 | static int dsps_musb_reset(struct musb *musb) | 604 | static int dsps_musb_recover(struct musb *musb) |
626 | { | 605 | { |
627 | struct device *dev = musb->controller; | 606 | struct device *dev = musb->controller; |
628 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); | 607 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); |
629 | const struct dsps_musb_wrapper *wrp = glue->wrp; | 608 | int session_restart = 0; |
630 | int session_restart = 0, error; | ||
631 | 609 | ||
632 | if (glue->sw_babble_enabled) | 610 | if (glue->sw_babble_enabled) |
633 | session_restart = sw_babble_control(musb); | 611 | session_restart = dsps_sw_babble_control(musb); |
634 | /* | 612 | else |
635 | * In case of new silicon version babble condition can be recovered | ||
636 | * without resetting the MUSB. But for older silicon versions, MUSB | ||
637 | * reset is needed | ||
638 | */ | ||
639 | if (session_restart || !glue->sw_babble_enabled) { | ||
640 | dev_info(musb->controller, "Restarting MUSB to recover from Babble\n"); | ||
641 | dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset)); | ||
642 | usleep_range(100, 200); | ||
643 | usb_phy_shutdown(musb->xceiv); | ||
644 | error = phy_power_off(musb->phy); | ||
645 | if (error) | ||
646 | dev_err(dev, "phy shutdown failed: %i\n", error); | ||
647 | usleep_range(100, 200); | ||
648 | usb_phy_init(musb->xceiv); | ||
649 | error = phy_power_on(musb->phy); | ||
650 | if (error) | ||
651 | dev_err(dev, "phy powerup failed: %i\n", error); | ||
652 | session_restart = 1; | 613 | session_restart = 1; |
614 | |||
615 | return session_restart ? 0 : -EPIPE; | ||
616 | } | ||
617 | |||
618 | /* Similar to am35x, dm81xx support only 32-bit read operation */ | ||
619 | static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | ||
620 | { | ||
621 | void __iomem *fifo = hw_ep->fifo; | ||
622 | |||
623 | if (len >= 4) { | ||
624 | readsl(fifo, dst, len >> 2); | ||
625 | dst += len & ~0x03; | ||
626 | len &= 0x03; | ||
653 | } | 627 | } |
654 | 628 | ||
655 | return !session_restart; | 629 | /* Read any remaining 1 to 3 bytes */ |
630 | if (len > 0) { | ||
631 | u32 val = musb_readl(fifo, 0); | ||
632 | memcpy(dst, &val, len); | ||
633 | } | ||
656 | } | 634 | } |
657 | 635 | ||
658 | static struct musb_platform_ops dsps_ops = { | 636 | static struct musb_platform_ops dsps_ops = { |
@@ -665,7 +643,7 @@ static struct musb_platform_ops dsps_ops = { | |||
665 | 643 | ||
666 | .try_idle = dsps_musb_try_idle, | 644 | .try_idle = dsps_musb_try_idle, |
667 | .set_mode = dsps_musb_set_mode, | 645 | .set_mode = dsps_musb_set_mode, |
668 | .reset = dsps_musb_reset, | 646 | .recover = dsps_musb_recover, |
669 | }; | 647 | }; |
670 | 648 | ||
671 | static u64 musb_dmamask = DMA_BIT_MASK(32); | 649 | static u64 musb_dmamask = DMA_BIT_MASK(32); |
@@ -737,7 +715,6 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue, | |||
737 | musb->dev.parent = dev; | 715 | musb->dev.parent = dev; |
738 | musb->dev.dma_mask = &musb_dmamask; | 716 | musb->dev.dma_mask = &musb_dmamask; |
739 | musb->dev.coherent_dma_mask = musb_dmamask; | 717 | musb->dev.coherent_dma_mask = musb_dmamask; |
740 | musb->dev.of_node = of_node_get(dn); | ||
741 | 718 | ||
742 | glue->musb = musb; | 719 | glue->musb = musb; |
743 | 720 | ||
@@ -802,6 +779,9 @@ static int dsps_probe(struct platform_device *pdev) | |||
802 | } | 779 | } |
803 | wrp = match->data; | 780 | wrp = match->data; |
804 | 781 | ||
782 | if (of_device_is_compatible(pdev->dev.of_node, "ti,musb-dm816")) | ||
783 | dsps_ops.read_fifo = dsps_read_fifo32; | ||
784 | |||
805 | /* allocate glue */ | 785 | /* allocate glue */ |
806 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 786 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
807 | if (!glue) | 787 | if (!glue) |
@@ -873,12 +853,14 @@ static const struct dsps_musb_wrapper am33xx_driver_data = { | |||
873 | .rxep_shift = 16, | 853 | .rxep_shift = 16, |
874 | .rxep_mask = 0xfffe, | 854 | .rxep_mask = 0xfffe, |
875 | .rxep_bitmap = (0xfffe << 16), | 855 | .rxep_bitmap = (0xfffe << 16), |
876 | .poll_seconds = 2, | 856 | .poll_timeout = 2000, /* ms */ |
877 | }; | 857 | }; |
878 | 858 | ||
879 | static const struct of_device_id musb_dsps_of_match[] = { | 859 | static const struct of_device_id musb_dsps_of_match[] = { |
880 | { .compatible = "ti,musb-am33xx", | 860 | { .compatible = "ti,musb-am33xx", |
881 | .data = (void *) &am33xx_driver_data, }, | 861 | .data = &am33xx_driver_data, }, |
862 | { .compatible = "ti,musb-dm816", | ||
863 | .data = &am33xx_driver_data, }, | ||
882 | { }, | 864 | { }, |
883 | }; | 865 | }; |
884 | MODULE_DEVICE_TABLE(of, musb_dsps_of_match); | 866 | MODULE_DEVICE_TABLE(of, musb_dsps_of_match); |
@@ -929,7 +911,8 @@ static int dsps_resume(struct device *dev) | |||
929 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); | 911 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); |
930 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && | 912 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && |
931 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) | 913 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) |
932 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 914 | mod_timer(&glue->timer, jiffies + |
915 | msecs_to_jiffies(wrp->poll_timeout)); | ||
933 | 916 | ||
934 | return 0; | 917 | return 0; |
935 | } | 918 | } |
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index b2d9040c7685..4c481cd66c77 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -1876,44 +1876,6 @@ err: | |||
1876 | return retval; | 1876 | return retval; |
1877 | } | 1877 | } |
1878 | 1878 | ||
1879 | static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) | ||
1880 | { | ||
1881 | int i; | ||
1882 | struct musb_hw_ep *hw_ep; | ||
1883 | |||
1884 | /* don't disconnect if it's not connected */ | ||
1885 | if (musb->g.speed == USB_SPEED_UNKNOWN) | ||
1886 | driver = NULL; | ||
1887 | else | ||
1888 | musb->g.speed = USB_SPEED_UNKNOWN; | ||
1889 | |||
1890 | /* deactivate the hardware */ | ||
1891 | if (musb->softconnect) { | ||
1892 | musb->softconnect = 0; | ||
1893 | musb_pullup(musb, 0); | ||
1894 | } | ||
1895 | musb_stop(musb); | ||
1896 | |||
1897 | /* killing any outstanding requests will quiesce the driver; | ||
1898 | * then report disconnect | ||
1899 | */ | ||
1900 | if (driver) { | ||
1901 | for (i = 0, hw_ep = musb->endpoints; | ||
1902 | i < musb->nr_endpoints; | ||
1903 | i++, hw_ep++) { | ||
1904 | musb_ep_select(musb->mregs, i); | ||
1905 | if (hw_ep->is_shared_fifo /* || !epnum */) { | ||
1906 | nuke(&hw_ep->ep_in, -ESHUTDOWN); | ||
1907 | } else { | ||
1908 | if (hw_ep->max_packet_sz_tx) | ||
1909 | nuke(&hw_ep->ep_in, -ESHUTDOWN); | ||
1910 | if (hw_ep->max_packet_sz_rx) | ||
1911 | nuke(&hw_ep->ep_out, -ESHUTDOWN); | ||
1912 | } | ||
1913 | } | ||
1914 | } | ||
1915 | } | ||
1916 | |||
1917 | /* | 1879 | /* |
1918 | * Unregister the gadget driver. Used by gadget drivers when | 1880 | * Unregister the gadget driver. Used by gadget drivers when |
1919 | * unregistering themselves from the controller. | 1881 | * unregistering themselves from the controller. |
@@ -1940,7 +1902,7 @@ static int musb_gadget_stop(struct usb_gadget *g) | |||
1940 | (void) musb_gadget_vbus_draw(&musb->g, 0); | 1902 | (void) musb_gadget_vbus_draw(&musb->g, 0); |
1941 | 1903 | ||
1942 | musb->xceiv->otg->state = OTG_STATE_UNDEFINED; | 1904 | musb->xceiv->otg->state = OTG_STATE_UNDEFINED; |
1943 | stop_activity(musb, NULL); | 1905 | musb_stop(musb); |
1944 | otg_set_peripheral(musb->xceiv->otg, NULL); | 1906 | otg_set_peripheral(musb->xceiv->otg, NULL); |
1945 | 1907 | ||
1946 | musb->is_active = 0; | 1908 | musb->is_active = 0; |
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 2fb3828b5089..2175678e674e 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig | |||
@@ -202,13 +202,13 @@ config USB_RCAR_GEN2_PHY | |||
202 | config USB_ULPI | 202 | config USB_ULPI |
203 | bool "Generic ULPI Transceiver Driver" | 203 | bool "Generic ULPI Transceiver Driver" |
204 | depends on ARM || ARM64 | 204 | depends on ARM || ARM64 |
205 | select USB_ULPI_VIEWPORT | ||
205 | help | 206 | help |
206 | Enable this to support ULPI connected USB OTG transceivers which | 207 | Enable this to support ULPI connected USB OTG transceivers which |
207 | are likely found on embedded boards. | 208 | are likely found on embedded boards. |
208 | 209 | ||
209 | config USB_ULPI_VIEWPORT | 210 | config USB_ULPI_VIEWPORT |
210 | bool | 211 | bool |
211 | depends on USB_ULPI | ||
212 | help | 212 | help |
213 | Provides read/write operations to the ULPI phy register set for | 213 | Provides read/write operations to the ULPI phy register set for |
214 | controllers with a viewport register (e.g. Chipidea/ARC controllers). | 214 | controllers with a viewport register (e.g. Chipidea/ARC controllers). |
diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c index 7ea0154da9d5..66ffa82457a8 100644 --- a/drivers/usb/phy/of.c +++ b/drivers/usb/phy/of.c | |||
@@ -27,7 +27,7 @@ static const char *const usbphy_modes[] = { | |||
27 | * @np: Pointer to the given device_node | 27 | * @np: Pointer to the given device_node |
28 | * | 28 | * |
29 | * The function gets phy interface string from property 'phy_type', | 29 | * The function gets phy interface string from property 'phy_type', |
30 | * and returns the correspondig enum usb_phy_interface | 30 | * and returns the corresponding enum usb_phy_interface |
31 | */ | 31 | */ |
32 | enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np) | 32 | enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np) |
33 | { | 33 | { |
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 0b1bd2369293..59cccfadae96 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c | |||
@@ -893,7 +893,7 @@ static int abx500_usb_link_status_update(struct ab8500_usb *ab) | |||
893 | 893 | ||
894 | /* | 894 | /* |
895 | * Disconnection Sequence: | 895 | * Disconnection Sequence: |
896 | * 1. Disconect Interrupt | 896 | * 1. Disconnect Interrupt |
897 | * 2. Disable regulators | 897 | * 2. Disable regulators |
898 | * 3. Disable AB clock | 898 | * 3. Disable AB clock |
899 | * 4. Disable the Phy | 899 | * 4. Disable the Phy |
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index 70be50b734b2..deee68eafb72 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c | |||
@@ -62,14 +62,14 @@ static int nop_set_suspend(struct usb_phy *x, int suspend) | |||
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | static void nop_reset_set(struct usb_phy_generic *nop, int asserted) | 65 | static void nop_reset(struct usb_phy_generic *nop) |
66 | { | 66 | { |
67 | if (!nop->gpiod_reset) | 67 | if (!nop->gpiod_reset) |
68 | return; | 68 | return; |
69 | 69 | ||
70 | gpiod_direction_output(nop->gpiod_reset, !asserted); | 70 | gpiod_set_value(nop->gpiod_reset, 1); |
71 | usleep_range(10000, 20000); | 71 | usleep_range(10000, 20000); |
72 | gpiod_set_value(nop->gpiod_reset, asserted); | 72 | gpiod_set_value(nop->gpiod_reset, 0); |
73 | } | 73 | } |
74 | 74 | ||
75 | /* interface to regulator framework */ | 75 | /* interface to regulator framework */ |
@@ -151,8 +151,7 @@ int usb_gen_phy_init(struct usb_phy *phy) | |||
151 | if (!IS_ERR(nop->clk)) | 151 | if (!IS_ERR(nop->clk)) |
152 | clk_prepare_enable(nop->clk); | 152 | clk_prepare_enable(nop->clk); |
153 | 153 | ||
154 | /* De-assert RESET */ | 154 | nop_reset(nop); |
155 | nop_reset_set(nop, 0); | ||
156 | 155 | ||
157 | return 0; | 156 | return 0; |
158 | } | 157 | } |
@@ -162,8 +161,7 @@ void usb_gen_phy_shutdown(struct usb_phy *phy) | |||
162 | { | 161 | { |
163 | struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); | 162 | struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); |
164 | 163 | ||
165 | /* Assert RESET */ | 164 | gpiod_set_value(nop->gpiod_reset, 1); |
166 | nop_reset_set(nop, 1); | ||
167 | 165 | ||
168 | if (!IS_ERR(nop->clk)) | 166 | if (!IS_ERR(nop->clk)) |
169 | clk_disable_unprepare(nop->clk); | 167 | clk_disable_unprepare(nop->clk); |
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 2f9735b35338..d1cd6b50f520 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c | |||
@@ -81,7 +81,9 @@ static void devm_usb_phy_release(struct device *dev, void *res) | |||
81 | 81 | ||
82 | static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) | 82 | static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) |
83 | { | 83 | { |
84 | return res == match_data; | 84 | struct usb_phy **phy = res; |
85 | |||
86 | return *phy == match_data; | ||
85 | } | 87 | } |
86 | 88 | ||
87 | /** | 89 | /** |
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 4cf77d3c3bd2..0f7e850fd4aa 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c | |||
@@ -276,6 +276,16 @@ int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, | |||
276 | } | 276 | } |
277 | 277 | ||
278 | /* | 278 | /* |
279 | * interrupt functions | ||
280 | */ | ||
281 | void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit) | ||
282 | { | ||
283 | u16 pipe_mask = (u16)GENMASK(usbhs_get_dparam(priv, pipe_size), 0); | ||
284 | |||
285 | usbhs_write(priv, sts_reg, ~(1 << bit) & pipe_mask); | ||
286 | } | ||
287 | |||
288 | /* | ||
279 | * local functions | 289 | * local functions |
280 | */ | 290 | */ |
281 | static void usbhsc_set_buswait(struct usbhs_priv *priv) | 291 | static void usbhsc_set_buswait(struct usbhs_priv *priv) |
@@ -487,6 +497,15 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) | |||
487 | if (gpio > 0) | 497 | if (gpio > 0) |
488 | dparam->enable_gpio = gpio; | 498 | dparam->enable_gpio = gpio; |
489 | 499 | ||
500 | switch (dparam->type) { | ||
501 | case USBHS_TYPE_R8A7790: | ||
502 | case USBHS_TYPE_R8A7791: | ||
503 | dparam->has_usb_dmac = 1; | ||
504 | break; | ||
505 | default: | ||
506 | break; | ||
507 | } | ||
508 | |||
490 | return info; | 509 | return info; |
491 | } | 510 | } |
492 | 511 | ||
diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index fc96e924edc4..8c5fc12ad778 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h | |||
@@ -193,6 +193,7 @@ struct usbhs_priv; | |||
193 | #define TYPE_BULK (1 << 14) | 193 | #define TYPE_BULK (1 << 14) |
194 | #define TYPE_INT (2 << 14) | 194 | #define TYPE_INT (2 << 14) |
195 | #define TYPE_ISO (3 << 14) | 195 | #define TYPE_ISO (3 << 14) |
196 | #define BFRE (1 << 10) /* BRDY Interrupt Operation Spec. */ | ||
196 | #define DBLB (1 << 9) /* Double Buffer Mode */ | 197 | #define DBLB (1 << 9) /* Double Buffer Mode */ |
197 | #define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */ | 198 | #define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */ |
198 | #define DIR_OUT (1 << 4) /* Transfer Direction */ | 199 | #define DIR_OUT (1 << 4) /* Transfer Direction */ |
@@ -216,6 +217,7 @@ struct usbhs_priv; | |||
216 | #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */ | 217 | #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */ |
217 | #define SQCLR (1 << 8) /* Toggle Bit Clear */ | 218 | #define SQCLR (1 << 8) /* Toggle Bit Clear */ |
218 | #define SQSET (1 << 7) /* Toggle Bit Set */ | 219 | #define SQSET (1 << 7) /* Toggle Bit Set */ |
220 | #define SQMON (1 << 6) /* Toggle Bit Check */ | ||
219 | #define PBUSY (1 << 5) /* Pipe Busy */ | 221 | #define PBUSY (1 << 5) /* Pipe Busy */ |
220 | #define PID_MASK (0x3) /* Response PID */ | 222 | #define PID_MASK (0x3) /* Response PID */ |
221 | #define PID_NAK 0 | 223 | #define PID_NAK 0 |
@@ -324,6 +326,11 @@ int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, u16 upphub, | |||
324 | u16 hubport, u16 speed); | 326 | u16 hubport, u16 speed); |
325 | 327 | ||
326 | /* | 328 | /* |
329 | * interrupt functions | ||
330 | */ | ||
331 | void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit); | ||
332 | |||
333 | /* | ||
327 | * data | 334 | * data |
328 | */ | 335 | */ |
329 | struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev); | 336 | struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev); |
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index d891bff39d66..8597cf9cfceb 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c | |||
@@ -813,7 +813,8 @@ static void xfer_work(struct work_struct *work) | |||
813 | desc->callback = usbhsf_dma_complete; | 813 | desc->callback = usbhsf_dma_complete; |
814 | desc->callback_param = pipe; | 814 | desc->callback_param = pipe; |
815 | 815 | ||
816 | if (dmaengine_submit(desc) < 0) { | 816 | pkt->cookie = dmaengine_submit(desc); |
817 | if (pkt->cookie < 0) { | ||
817 | dev_err(dev, "Failed to submit dma descriptor\n"); | 818 | dev_err(dev, "Failed to submit dma descriptor\n"); |
818 | return; | 819 | return; |
819 | } | 820 | } |
@@ -822,10 +823,10 @@ static void xfer_work(struct work_struct *work) | |||
822 | fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero); | 823 | fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero); |
823 | 824 | ||
824 | usbhs_pipe_running(pipe, 1); | 825 | usbhs_pipe_running(pipe, 1); |
825 | usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->trans); | ||
826 | usbhs_pipe_enable(pipe); | ||
827 | usbhsf_dma_start(pipe, fifo); | 826 | usbhsf_dma_start(pipe, fifo); |
827 | usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->trans); | ||
828 | dma_async_issue_pending(chan); | 828 | dma_async_issue_pending(chan); |
829 | usbhs_pipe_enable(pipe); | ||
829 | } | 830 | } |
830 | 831 | ||
831 | /* | 832 | /* |
@@ -838,6 +839,7 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done) | |||
838 | struct usbhs_fifo *fifo; | 839 | struct usbhs_fifo *fifo; |
839 | int len = pkt->length - pkt->actual; | 840 | int len = pkt->length - pkt->actual; |
840 | int ret; | 841 | int ret; |
842 | uintptr_t align_mask; | ||
841 | 843 | ||
842 | if (usbhs_pipe_is_busy(pipe)) | 844 | if (usbhs_pipe_is_busy(pipe)) |
843 | return 0; | 845 | return 0; |
@@ -847,10 +849,14 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done) | |||
847 | usbhs_pipe_is_dcp(pipe)) | 849 | usbhs_pipe_is_dcp(pipe)) |
848 | goto usbhsf_pio_prepare_push; | 850 | goto usbhsf_pio_prepare_push; |
849 | 851 | ||
850 | if (len & 0x7) /* 8byte alignment */ | 852 | /* check data length if this driver don't use USB-DMAC */ |
853 | if (!usbhs_get_dparam(priv, has_usb_dmac) && len & 0x7) | ||
851 | goto usbhsf_pio_prepare_push; | 854 | goto usbhsf_pio_prepare_push; |
852 | 855 | ||
853 | if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */ | 856 | /* check buffer alignment */ |
857 | align_mask = usbhs_get_dparam(priv, has_usb_dmac) ? | ||
858 | USBHS_USB_DMAC_XFER_SIZE - 1 : 0x7; | ||
859 | if ((uintptr_t)(pkt->buf + pkt->actual) & align_mask) | ||
854 | goto usbhsf_pio_prepare_push; | 860 | goto usbhsf_pio_prepare_push; |
855 | 861 | ||
856 | /* return at this time if the pipe is running */ | 862 | /* return at this time if the pipe is running */ |
@@ -924,7 +930,85 @@ struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = { | |||
924 | /* | 930 | /* |
925 | * DMA pop handler | 931 | * DMA pop handler |
926 | */ | 932 | */ |
927 | static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done) | 933 | |
934 | static int usbhsf_dma_prepare_pop_with_rx_irq(struct usbhs_pkt *pkt, | ||
935 | int *is_done) | ||
936 | { | ||
937 | return usbhsf_prepare_pop(pkt, is_done); | ||
938 | } | ||
939 | |||
940 | static int usbhsf_dma_prepare_pop_with_usb_dmac(struct usbhs_pkt *pkt, | ||
941 | int *is_done) | ||
942 | { | ||
943 | struct usbhs_pipe *pipe = pkt->pipe; | ||
944 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); | ||
945 | struct usbhs_fifo *fifo; | ||
946 | int ret; | ||
947 | |||
948 | if (usbhs_pipe_is_busy(pipe)) | ||
949 | return 0; | ||
950 | |||
951 | /* use PIO if packet is less than pio_dma_border or pipe is DCP */ | ||
952 | if ((pkt->length < usbhs_get_dparam(priv, pio_dma_border)) || | ||
953 | usbhs_pipe_is_dcp(pipe)) | ||
954 | goto usbhsf_pio_prepare_pop; | ||
955 | |||
956 | fifo = usbhsf_get_dma_fifo(priv, pkt); | ||
957 | if (!fifo) | ||
958 | goto usbhsf_pio_prepare_pop; | ||
959 | |||
960 | if ((uintptr_t)pkt->buf & (USBHS_USB_DMAC_XFER_SIZE - 1)) | ||
961 | goto usbhsf_pio_prepare_pop; | ||
962 | |||
963 | usbhs_pipe_config_change_bfre(pipe, 1); | ||
964 | |||
965 | ret = usbhsf_fifo_select(pipe, fifo, 0); | ||
966 | if (ret < 0) | ||
967 | goto usbhsf_pio_prepare_pop; | ||
968 | |||
969 | if (usbhsf_dma_map(pkt) < 0) | ||
970 | goto usbhsf_pio_prepare_pop_unselect; | ||
971 | |||
972 | /* DMA */ | ||
973 | |||
974 | /* | ||
975 | * usbhs_fifo_dma_pop_handler :: prepare | ||
976 | * enabled irq to come here. | ||
977 | * but it is no longer needed for DMA. disable it. | ||
978 | */ | ||
979 | usbhsf_rx_irq_ctrl(pipe, 0); | ||
980 | |||
981 | pkt->trans = pkt->length; | ||
982 | |||
983 | INIT_WORK(&pkt->work, xfer_work); | ||
984 | schedule_work(&pkt->work); | ||
985 | |||
986 | return 0; | ||
987 | |||
988 | usbhsf_pio_prepare_pop_unselect: | ||
989 | usbhsf_fifo_unselect(pipe, fifo); | ||
990 | usbhsf_pio_prepare_pop: | ||
991 | |||
992 | /* | ||
993 | * change handler to PIO | ||
994 | */ | ||
995 | pkt->handler = &usbhs_fifo_pio_pop_handler; | ||
996 | usbhs_pipe_config_change_bfre(pipe, 0); | ||
997 | |||
998 | return pkt->handler->prepare(pkt, is_done); | ||
999 | } | ||
1000 | |||
1001 | static int usbhsf_dma_prepare_pop(struct usbhs_pkt *pkt, int *is_done) | ||
1002 | { | ||
1003 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); | ||
1004 | |||
1005 | if (usbhs_get_dparam(priv, has_usb_dmac)) | ||
1006 | return usbhsf_dma_prepare_pop_with_usb_dmac(pkt, is_done); | ||
1007 | else | ||
1008 | return usbhsf_dma_prepare_pop_with_rx_irq(pkt, is_done); | ||
1009 | } | ||
1010 | |||
1011 | static int usbhsf_dma_try_pop_with_rx_irq(struct usbhs_pkt *pkt, int *is_done) | ||
928 | { | 1012 | { |
929 | struct usbhs_pipe *pipe = pkt->pipe; | 1013 | struct usbhs_pipe *pipe = pkt->pipe; |
930 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); | 1014 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); |
@@ -993,7 +1077,16 @@ usbhsf_pio_prepare_pop: | |||
993 | return pkt->handler->try_run(pkt, is_done); | 1077 | return pkt->handler->try_run(pkt, is_done); |
994 | } | 1078 | } |
995 | 1079 | ||
996 | static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done) | 1080 | static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done) |
1081 | { | ||
1082 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); | ||
1083 | |||
1084 | BUG_ON(usbhs_get_dparam(priv, has_usb_dmac)); | ||
1085 | |||
1086 | return usbhsf_dma_try_pop_with_rx_irq(pkt, is_done); | ||
1087 | } | ||
1088 | |||
1089 | static int usbhsf_dma_pop_done_with_rx_irq(struct usbhs_pkt *pkt, int *is_done) | ||
997 | { | 1090 | { |
998 | struct usbhs_pipe *pipe = pkt->pipe; | 1091 | struct usbhs_pipe *pipe = pkt->pipe; |
999 | int maxp = usbhs_pipe_get_maxpacket(pipe); | 1092 | int maxp = usbhs_pipe_get_maxpacket(pipe); |
@@ -1017,8 +1110,68 @@ static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done) | |||
1017 | return 0; | 1110 | return 0; |
1018 | } | 1111 | } |
1019 | 1112 | ||
1113 | static size_t usbhs_dma_calc_received_size(struct usbhs_pkt *pkt, | ||
1114 | struct dma_chan *chan, int dtln) | ||
1115 | { | ||
1116 | struct usbhs_pipe *pipe = pkt->pipe; | ||
1117 | struct dma_tx_state state; | ||
1118 | size_t received_size; | ||
1119 | int maxp = usbhs_pipe_get_maxpacket(pipe); | ||
1120 | |||
1121 | dmaengine_tx_status(chan, pkt->cookie, &state); | ||
1122 | received_size = pkt->length - state.residue; | ||
1123 | |||
1124 | if (dtln) { | ||
1125 | received_size -= USBHS_USB_DMAC_XFER_SIZE; | ||
1126 | received_size &= ~(maxp - 1); | ||
1127 | received_size += dtln; | ||
1128 | } | ||
1129 | |||
1130 | return received_size; | ||
1131 | } | ||
1132 | |||
1133 | static int usbhsf_dma_pop_done_with_usb_dmac(struct usbhs_pkt *pkt, | ||
1134 | int *is_done) | ||
1135 | { | ||
1136 | struct usbhs_pipe *pipe = pkt->pipe; | ||
1137 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); | ||
1138 | struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe); | ||
1139 | struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt); | ||
1140 | int rcv_len; | ||
1141 | |||
1142 | /* | ||
1143 | * Since the driver disables rx_irq in DMA mode, the interrupt handler | ||
1144 | * cannot the BRDYSTS. So, the function clears it here because the | ||
1145 | * driver may use PIO mode next time. | ||
1146 | */ | ||
1147 | usbhs_xxxsts_clear(priv, BRDYSTS, usbhs_pipe_number(pipe)); | ||
1148 | |||
1149 | rcv_len = usbhsf_fifo_rcv_len(priv, fifo); | ||
1150 | usbhsf_fifo_clear(pipe, fifo); | ||
1151 | pkt->actual = usbhs_dma_calc_received_size(pkt, chan, rcv_len); | ||
1152 | |||
1153 | usbhsf_dma_stop(pipe, fifo); | ||
1154 | usbhsf_dma_unmap(pkt); | ||
1155 | usbhsf_fifo_unselect(pipe, pipe->fifo); | ||
1156 | |||
1157 | /* The driver can assume the rx transaction is always "done" */ | ||
1158 | *is_done = 1; | ||
1159 | |||
1160 | return 0; | ||
1161 | } | ||
1162 | |||
1163 | static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done) | ||
1164 | { | ||
1165 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); | ||
1166 | |||
1167 | if (usbhs_get_dparam(priv, has_usb_dmac)) | ||
1168 | return usbhsf_dma_pop_done_with_usb_dmac(pkt, is_done); | ||
1169 | else | ||
1170 | return usbhsf_dma_pop_done_with_rx_irq(pkt, is_done); | ||
1171 | } | ||
1172 | |||
1020 | struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = { | 1173 | struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = { |
1021 | .prepare = usbhsf_prepare_pop, | 1174 | .prepare = usbhsf_dma_prepare_pop, |
1022 | .try_run = usbhsf_dma_try_pop, | 1175 | .try_run = usbhsf_dma_try_pop, |
1023 | .dma_done = usbhsf_dma_pop_done | 1176 | .dma_done = usbhsf_dma_pop_done |
1024 | }; | 1177 | }; |
@@ -1069,23 +1222,29 @@ static void usbhsf_dma_init_pdev(struct usbhs_fifo *fifo) | |||
1069 | &fifo->rx_slave); | 1222 | &fifo->rx_slave); |
1070 | } | 1223 | } |
1071 | 1224 | ||
1072 | static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo) | 1225 | static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo, |
1226 | int channel) | ||
1073 | { | 1227 | { |
1074 | fifo->tx_chan = dma_request_slave_channel_reason(dev, "tx"); | 1228 | char name[16]; |
1229 | |||
1230 | snprintf(name, sizeof(name), "tx%d", channel); | ||
1231 | fifo->tx_chan = dma_request_slave_channel_reason(dev, name); | ||
1075 | if (IS_ERR(fifo->tx_chan)) | 1232 | if (IS_ERR(fifo->tx_chan)) |
1076 | fifo->tx_chan = NULL; | 1233 | fifo->tx_chan = NULL; |
1077 | fifo->rx_chan = dma_request_slave_channel_reason(dev, "rx"); | 1234 | |
1235 | snprintf(name, sizeof(name), "rx%d", channel); | ||
1236 | fifo->rx_chan = dma_request_slave_channel_reason(dev, name); | ||
1078 | if (IS_ERR(fifo->rx_chan)) | 1237 | if (IS_ERR(fifo->rx_chan)) |
1079 | fifo->rx_chan = NULL; | 1238 | fifo->rx_chan = NULL; |
1080 | } | 1239 | } |
1081 | 1240 | ||
1082 | static void usbhsf_dma_init(struct usbhs_priv *priv, | 1241 | static void usbhsf_dma_init(struct usbhs_priv *priv, struct usbhs_fifo *fifo, |
1083 | struct usbhs_fifo *fifo) | 1242 | int channel) |
1084 | { | 1243 | { |
1085 | struct device *dev = usbhs_priv_to_dev(priv); | 1244 | struct device *dev = usbhs_priv_to_dev(priv); |
1086 | 1245 | ||
1087 | if (dev->of_node) | 1246 | if (dev->of_node) |
1088 | usbhsf_dma_init_dt(dev, fifo); | 1247 | usbhsf_dma_init_dt(dev, fifo, channel); |
1089 | else | 1248 | else |
1090 | usbhsf_dma_init_pdev(fifo); | 1249 | usbhsf_dma_init_pdev(fifo); |
1091 | 1250 | ||
@@ -1231,7 +1390,7 @@ do { \ | |||
1231 | usbhs_get_dparam(priv, d##channel##_tx_id); \ | 1390 | usbhs_get_dparam(priv, d##channel##_tx_id); \ |
1232 | fifo->rx_slave.shdma_slave.slave_id = \ | 1391 | fifo->rx_slave.shdma_slave.slave_id = \ |
1233 | usbhs_get_dparam(priv, d##channel##_rx_id); \ | 1392 | usbhs_get_dparam(priv, d##channel##_rx_id); \ |
1234 | usbhsf_dma_init(priv, fifo); \ | 1393 | usbhsf_dma_init(priv, fifo, channel); \ |
1235 | } while (0) | 1394 | } while (0) |
1236 | 1395 | ||
1237 | #define USBHS_DFIFO_INIT(priv, fifo, channel) \ | 1396 | #define USBHS_DFIFO_INIT(priv, fifo, channel) \ |
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h index f07037c1185f..04d3f8abad9e 100644 --- a/drivers/usb/renesas_usbhs/fifo.h +++ b/drivers/usb/renesas_usbhs/fifo.h | |||
@@ -58,6 +58,7 @@ struct usbhs_pkt { | |||
58 | struct usbhs_pkt *pkt); | 58 | struct usbhs_pkt *pkt); |
59 | struct work_struct work; | 59 | struct work_struct work; |
60 | dma_addr_t dma; | 60 | dma_addr_t dma; |
61 | dma_cookie_t cookie; | ||
61 | void *buf; | 62 | void *buf; |
62 | int length; | 63 | int length; |
63 | int trans; | 64 | int trans; |
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index e0384af77e56..dc2aa3261202 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c | |||
@@ -119,18 +119,34 @@ struct usbhsg_recip_handle { | |||
119 | /* | 119 | /* |
120 | * queue push/pop | 120 | * queue push/pop |
121 | */ | 121 | */ |
122 | static void usbhsg_queue_pop(struct usbhsg_uep *uep, | 122 | static void __usbhsg_queue_pop(struct usbhsg_uep *uep, |
123 | struct usbhsg_request *ureq, | 123 | struct usbhsg_request *ureq, |
124 | int status) | 124 | int status) |
125 | { | 125 | { |
126 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); | 126 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
127 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); | 127 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
128 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); | 128 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
129 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); | ||
129 | 130 | ||
130 | dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); | 131 | dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); |
131 | 132 | ||
132 | ureq->req.status = status; | 133 | ureq->req.status = status; |
134 | spin_unlock(usbhs_priv_to_lock(priv)); | ||
133 | usb_gadget_giveback_request(&uep->ep, &ureq->req); | 135 | usb_gadget_giveback_request(&uep->ep, &ureq->req); |
136 | spin_lock(usbhs_priv_to_lock(priv)); | ||
137 | } | ||
138 | |||
139 | static void usbhsg_queue_pop(struct usbhsg_uep *uep, | ||
140 | struct usbhsg_request *ureq, | ||
141 | int status) | ||
142 | { | ||
143 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); | ||
144 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); | ||
145 | unsigned long flags; | ||
146 | |||
147 | usbhs_lock(priv, flags); | ||
148 | __usbhsg_queue_pop(uep, ureq, status); | ||
149 | usbhs_unlock(priv, flags); | ||
134 | } | 150 | } |
135 | 151 | ||
136 | static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) | 152 | static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) |
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c index 007f45abe96c..4f9c3356127a 100644 --- a/drivers/usb/renesas_usbhs/pipe.c +++ b/drivers/usb/renesas_usbhs/pipe.c | |||
@@ -84,6 +84,17 @@ static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe, | |||
84 | usbhs_bset(priv, pipe_reg, mask, val); | 84 | usbhs_bset(priv, pipe_reg, mask, val); |
85 | } | 85 | } |
86 | 86 | ||
87 | static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe, | ||
88 | u16 dcp_reg, u16 pipe_reg) | ||
89 | { | ||
90 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); | ||
91 | |||
92 | if (usbhs_pipe_is_dcp(pipe)) | ||
93 | return usbhs_read(priv, dcp_reg); | ||
94 | else | ||
95 | return usbhs_read(priv, pipe_reg); | ||
96 | } | ||
97 | |||
87 | /* | 98 | /* |
88 | * DCPCFG/PIPECFG functions | 99 | * DCPCFG/PIPECFG functions |
89 | */ | 100 | */ |
@@ -92,6 +103,11 @@ static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val) | |||
92 | __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val); | 103 | __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val); |
93 | } | 104 | } |
94 | 105 | ||
106 | static u16 usbhsp_pipe_cfg_get(struct usbhs_pipe *pipe) | ||
107 | { | ||
108 | return __usbhsp_pipe_xxx_get(pipe, DCPCFG, PIPECFG); | ||
109 | } | ||
110 | |||
95 | /* | 111 | /* |
96 | * PIPEnTRN/PIPEnTRE functions | 112 | * PIPEnTRN/PIPEnTRE functions |
97 | */ | 113 | */ |
@@ -616,6 +632,11 @@ void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int sequence) | |||
616 | usbhsp_pipectrl_set(pipe, mask, val); | 632 | usbhsp_pipectrl_set(pipe, mask, val); |
617 | } | 633 | } |
618 | 634 | ||
635 | static int usbhs_pipe_get_data_sequence(struct usbhs_pipe *pipe) | ||
636 | { | ||
637 | return !!(usbhsp_pipectrl_get(pipe) & SQMON); | ||
638 | } | ||
639 | |||
619 | void usbhs_pipe_clear(struct usbhs_pipe *pipe) | 640 | void usbhs_pipe_clear(struct usbhs_pipe *pipe) |
620 | { | 641 | { |
621 | if (usbhs_pipe_is_dcp(pipe)) { | 642 | if (usbhs_pipe_is_dcp(pipe)) { |
@@ -626,6 +647,24 @@ void usbhs_pipe_clear(struct usbhs_pipe *pipe) | |||
626 | } | 647 | } |
627 | } | 648 | } |
628 | 649 | ||
650 | void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable) | ||
651 | { | ||
652 | int sequence; | ||
653 | |||
654 | if (usbhs_pipe_is_dcp(pipe)) | ||
655 | return; | ||
656 | |||
657 | usbhsp_pipe_select(pipe); | ||
658 | /* check if the driver needs to change the BFRE value */ | ||
659 | if (!(enable ^ !!(usbhsp_pipe_cfg_get(pipe) & BFRE))) | ||
660 | return; | ||
661 | |||
662 | sequence = usbhs_pipe_get_data_sequence(pipe); | ||
663 | usbhsp_pipe_cfg_set(pipe, BFRE, enable ? BFRE : 0); | ||
664 | usbhs_pipe_clear(pipe); | ||
665 | usbhs_pipe_data_sequence(pipe, sequence); | ||
666 | } | ||
667 | |||
629 | static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type) | 668 | static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type) |
630 | { | 669 | { |
631 | struct usbhs_pipe *pos, *pipe; | 670 | struct usbhs_pipe *pos, *pipe; |
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h index d24a05972370..b0bc7b603016 100644 --- a/drivers/usb/renesas_usbhs/pipe.h +++ b/drivers/usb/renesas_usbhs/pipe.h | |||
@@ -97,6 +97,7 @@ void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe *pipe, int len); | |||
97 | void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo); | 97 | void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo); |
98 | void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel, | 98 | void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel, |
99 | u16 epnum, u16 maxp); | 99 | u16 epnum, u16 maxp); |
100 | void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable); | ||
100 | 101 | ||
101 | #define usbhs_pipe_sequence_data0(pipe) usbhs_pipe_data_sequence(pipe, 0) | 102 | #define usbhs_pipe_sequence_data0(pipe) usbhs_pipe_data_sequence(pipe, 0) |
102 | #define usbhs_pipe_sequence_data1(pipe) usbhs_pipe_data_sequence(pipe, 1) | 103 | #define usbhs_pipe_sequence_data1(pipe) usbhs_pipe_data_sequence(pipe, 1) |
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index e63c02a93f6b..38cff8f6716d 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h | |||
@@ -2315,6 +2315,8 @@ | |||
2315 | #define PCI_VENDOR_ID_CENATEK 0x16CA | 2315 | #define PCI_VENDOR_ID_CENATEK 0x16CA |
2316 | #define PCI_DEVICE_ID_CENATEK_IDE 0x0001 | 2316 | #define PCI_DEVICE_ID_CENATEK_IDE 0x0001 |
2317 | 2317 | ||
2318 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 | ||
2319 | |||
2318 | #define PCI_VENDOR_ID_VITESSE 0x1725 | 2320 | #define PCI_VENDOR_ID_VITESSE 0x1725 |
2319 | #define PCI_DEVICE_ID_VITESSE_VSC7174 0x7174 | 2321 | #define PCI_DEVICE_ID_VITESSE_VSC7174 0x7174 |
2320 | 2322 | ||
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index 3d87defcc527..2511469a9904 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h | |||
@@ -148,6 +148,7 @@ struct usb_os_desc_table { | |||
148 | * @disable: (REQUIRED) Indicates the function should be disabled. Reasons | 148 | * @disable: (REQUIRED) Indicates the function should be disabled. Reasons |
149 | * include host resetting or reconfiguring the gadget, and disconnection. | 149 | * include host resetting or reconfiguring the gadget, and disconnection. |
150 | * @setup: Used for interface-specific control requests. | 150 | * @setup: Used for interface-specific control requests. |
151 | * @req_match: Tests if a given class request can be handled by this function. | ||
151 | * @suspend: Notifies functions when the host stops sending USB traffic. | 152 | * @suspend: Notifies functions when the host stops sending USB traffic. |
152 | * @resume: Notifies functions when the host restarts USB traffic. | 153 | * @resume: Notifies functions when the host restarts USB traffic. |
153 | * @get_status: Returns function status as a reply to | 154 | * @get_status: Returns function status as a reply to |
@@ -213,6 +214,8 @@ struct usb_function { | |||
213 | void (*disable)(struct usb_function *); | 214 | void (*disable)(struct usb_function *); |
214 | int (*setup)(struct usb_function *, | 215 | int (*setup)(struct usb_function *, |
215 | const struct usb_ctrlrequest *); | 216 | const struct usb_ctrlrequest *); |
217 | bool (*req_match)(struct usb_function *, | ||
218 | const struct usb_ctrlrequest *); | ||
216 | void (*suspend)(struct usb_function *); | 219 | void (*suspend)(struct usb_function *); |
217 | void (*resume)(struct usb_function *); | 220 | void (*resume)(struct usb_function *); |
218 | 221 | ||
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index e2f00fd8cd47..4f3dfb7d0654 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h | |||
@@ -190,7 +190,7 @@ struct usb_ep { | |||
190 | * @ep:the endpoint being configured | 190 | * @ep:the endpoint being configured |
191 | * @maxpacket_limit:value of maximum packet size limit | 191 | * @maxpacket_limit:value of maximum packet size limit |
192 | * | 192 | * |
193 | * This function shoud be used only in UDC drivers to initialize endpoint | 193 | * This function should be used only in UDC drivers to initialize endpoint |
194 | * (usually in probe function). | 194 | * (usually in probe function). |
195 | */ | 195 | */ |
196 | static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, | 196 | static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, |
@@ -474,6 +474,7 @@ struct usb_dcd_config_params { | |||
474 | 474 | ||
475 | struct usb_gadget; | 475 | struct usb_gadget; |
476 | struct usb_gadget_driver; | 476 | struct usb_gadget_driver; |
477 | struct usb_udc; | ||
477 | 478 | ||
478 | /* the rest of the api to the controller hardware: device operations, | 479 | /* the rest of the api to the controller hardware: device operations, |
479 | * which don't involve endpoints (or i/o). | 480 | * which don't involve endpoints (or i/o). |
@@ -496,6 +497,7 @@ struct usb_gadget_ops { | |||
496 | /** | 497 | /** |
497 | * struct usb_gadget - represents a usb slave device | 498 | * struct usb_gadget - represents a usb slave device |
498 | * @work: (internal use) Workqueue to be used for sysfs_notify() | 499 | * @work: (internal use) Workqueue to be used for sysfs_notify() |
500 | * @udc: struct usb_udc pointer for this gadget | ||
499 | * @ops: Function pointers used to access hardware-specific operations. | 501 | * @ops: Function pointers used to access hardware-specific operations. |
500 | * @ep0: Endpoint zero, used when reading or writing responses to | 502 | * @ep0: Endpoint zero, used when reading or writing responses to |
501 | * driver setup() requests | 503 | * driver setup() requests |
@@ -545,6 +547,7 @@ struct usb_gadget_ops { | |||
545 | */ | 547 | */ |
546 | struct usb_gadget { | 548 | struct usb_gadget { |
547 | struct work_struct work; | 549 | struct work_struct work; |
550 | struct usb_udc *udc; | ||
548 | /* readonly to gadget driver */ | 551 | /* readonly to gadget driver */ |
549 | const struct usb_gadget_ops *ops; | 552 | const struct usb_gadget_ops *ops; |
550 | struct usb_ep *ep0; | 553 | struct usb_ep *ep0; |
@@ -1029,6 +1032,10 @@ extern void usb_gadget_udc_reset(struct usb_gadget *gadget, | |||
1029 | extern void usb_gadget_giveback_request(struct usb_ep *ep, | 1032 | extern void usb_gadget_giveback_request(struct usb_ep *ep, |
1030 | struct usb_request *req); | 1033 | struct usb_request *req); |
1031 | 1034 | ||
1035 | /*-------------------------------------------------------------------------*/ | ||
1036 | |||
1037 | /* utility to update vbus status for udc core, it may be scheduled */ | ||
1038 | extern void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status); | ||
1032 | 1039 | ||
1033 | /*-------------------------------------------------------------------------*/ | 1040 | /*-------------------------------------------------------------------------*/ |
1034 | 1041 | ||
diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 9fd9e481ea98..f06529c14141 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h | |||
@@ -165,6 +165,8 @@ struct renesas_usbhs_driver_param { | |||
165 | */ | 165 | */ |
166 | u32 has_otg:1; /* for controlling PWEN/EXTLP */ | 166 | u32 has_otg:1; /* for controlling PWEN/EXTLP */ |
167 | u32 has_sudmac:1; /* for SUDMAC */ | 167 | u32 has_sudmac:1; /* for SUDMAC */ |
168 | u32 has_usb_dmac:1; /* for USB-DMAC */ | ||
169 | #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ | ||
168 | }; | 170 | }; |
169 | 171 | ||
170 | #define USBHS_TYPE_R8A7790 1 | 172 | #define USBHS_TYPE_R8A7790 1 |