diff options
217 files changed, 9032 insertions, 4950 deletions
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-mass-storage b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage new file mode 100644 index 000000000000..ad72a37ee9ff --- /dev/null +++ b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage | |||
@@ -0,0 +1,31 @@ | |||
1 | What: /config/usb-gadget/gadget/functions/mass_storage.name | ||
2 | Date: Oct 2013 | ||
3 | KenelVersion: 3.13 | ||
4 | Description: | ||
5 | The attributes: | ||
6 | |||
7 | stall - Set to permit function to halt bulk endpoints. | ||
8 | Disabled on some USB devices known not to work | ||
9 | correctly. You should set it to true. | ||
10 | num_buffers - Number of pipeline buffers. Valid numbers | ||
11 | are 2..4. Available only if | ||
12 | CONFIG_USB_GADGET_DEBUG_FILES is set. | ||
13 | |||
14 | What: /config/usb-gadget/gadget/functions/mass_storage.name/lun.name | ||
15 | Date: Oct 2013 | ||
16 | KenelVersion: 3.13 | ||
17 | Description: | ||
18 | The attributes: | ||
19 | |||
20 | file - The path to the backing file for the LUN. | ||
21 | Required if LUN is not marked as removable. | ||
22 | ro - Flag specifying access to the LUN shall be | ||
23 | read-only. This is implied if CD-ROM emulation | ||
24 | is enabled as well as when it was impossible | ||
25 | to open "filename" in R/W mode. | ||
26 | removable - Flag specifying that LUN shall be indicated as | ||
27 | being removable. | ||
28 | cdrom - Flag specifying that LUN shall be reported as | ||
29 | being a CD-ROM. | ||
30 | nofua - Flag specifying that FUA flag | ||
31 | in SCSI WRITE(10,12) | ||
diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt b/Documentation/devicetree/bindings/phy/phy-bindings.txt new file mode 100644 index 000000000000..8ae844fc0c60 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt | |||
@@ -0,0 +1,66 @@ | |||
1 | This document explains only the device tree data binding. For general | ||
2 | information about PHY subsystem refer to Documentation/phy.txt | ||
3 | |||
4 | PHY device node | ||
5 | =============== | ||
6 | |||
7 | Required Properties: | ||
8 | #phy-cells: Number of cells in a PHY specifier; The meaning of all those | ||
9 | cells is defined by the binding for the phy node. The PHY | ||
10 | provider can use the values in cells to find the appropriate | ||
11 | PHY. | ||
12 | |||
13 | For example: | ||
14 | |||
15 | phys: phy { | ||
16 | compatible = "xxx"; | ||
17 | reg = <...>; | ||
18 | . | ||
19 | . | ||
20 | #phy-cells = <1>; | ||
21 | . | ||
22 | . | ||
23 | }; | ||
24 | |||
25 | That node describes an IP block (PHY provider) that implements 2 different PHYs. | ||
26 | In order to differentiate between these 2 PHYs, an additonal specifier should be | ||
27 | given while trying to get a reference to it. | ||
28 | |||
29 | PHY user node | ||
30 | ============= | ||
31 | |||
32 | Required Properties: | ||
33 | phys : the phandle for the PHY device (used by the PHY subsystem) | ||
34 | phy-names : the names of the PHY corresponding to the PHYs present in the | ||
35 | *phys* phandle | ||
36 | |||
37 | Example 1: | ||
38 | usb1: usb_otg_ss@xxx { | ||
39 | compatible = "xxx"; | ||
40 | reg = <xxx>; | ||
41 | . | ||
42 | . | ||
43 | phys = <&usb2_phy>, <&usb3_phy>; | ||
44 | phy-names = "usb2phy", "usb3phy"; | ||
45 | . | ||
46 | . | ||
47 | }; | ||
48 | |||
49 | This node represents a controller that uses two PHYs, one for usb2 and one for | ||
50 | usb3. | ||
51 | |||
52 | Example 2: | ||
53 | usb2: usb_otg_ss@xxx { | ||
54 | compatible = "xxx"; | ||
55 | reg = <xxx>; | ||
56 | . | ||
57 | . | ||
58 | phys = <&phys 1>; | ||
59 | phy-names = "usbphy"; | ||
60 | . | ||
61 | . | ||
62 | }; | ||
63 | |||
64 | This node represents a controller that uses one of the PHYs of the PHY provider | ||
65 | device defined previously. Note that the phy handle has an additional specifier | ||
66 | "1" to differentiate between the two PHYs. | ||
diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt b/Documentation/devicetree/bindings/phy/samsung-phy.txt new file mode 100644 index 000000000000..c0fccaa1671e --- /dev/null +++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt | |||
@@ -0,0 +1,22 @@ | |||
1 | Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY | ||
2 | ------------------------------------------------- | ||
3 | |||
4 | Required properties: | ||
5 | - compatible : should be "samsung,s5pv210-mipi-video-phy"; | ||
6 | - reg : offset and length of the MIPI DPHY register set; | ||
7 | - #phy-cells : from the generic phy bindings, must be 1; | ||
8 | |||
9 | For "samsung,s5pv210-mipi-video-phy" compatible PHYs the second cell in | ||
10 | the PHY specifier identifies the PHY and its meaning is as follows: | ||
11 | 0 - MIPI CSIS 0, | ||
12 | 1 - MIPI DSIM 0, | ||
13 | 2 - MIPI CSIS 1, | ||
14 | 3 - MIPI DSIM 1. | ||
15 | |||
16 | Samsung EXYNOS SoC series Display Port PHY | ||
17 | ------------------------------------------------- | ||
18 | |||
19 | Required properties: | ||
20 | - compatible : should be "samsung,exynos5250-dp-video-phy"; | ||
21 | - reg : offset and length of the Display Port PHY register set; | ||
22 | - #phy-cells : from the generic PHY bindings, must be 0; | ||
diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt b/Documentation/devicetree/bindings/usb/msm-hsusb.txt new file mode 100644 index 000000000000..5ea26c631e3a --- /dev/null +++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt | |||
@@ -0,0 +1,17 @@ | |||
1 | MSM SoC HSUSB controllers | ||
2 | |||
3 | EHCI | ||
4 | |||
5 | Required properties: | ||
6 | - compatible: Should contain "qcom,ehci-host" | ||
7 | - regs: offset and length of the register set in the memory map | ||
8 | - usb-phy: phandle for the PHY device | ||
9 | |||
10 | Example EHCI controller device node: | ||
11 | |||
12 | ehci: ehci@f9a55000 { | ||
13 | compatible = "qcom,ehci-host"; | ||
14 | reg = <0xf9a55000 0x400>; | ||
15 | usb-phy = <&usb_otg>; | ||
16 | }; | ||
17 | |||
diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt index 9088ab09e200..090e5e22bd2b 100644 --- a/Documentation/devicetree/bindings/usb/omap-usb.txt +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt | |||
@@ -3,9 +3,6 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS | |||
3 | OMAP MUSB GLUE | 3 | OMAP MUSB GLUE |
4 | - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" | 4 | - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" |
5 | - ti,hwmods : must be "usb_otg_hs" | 5 | - ti,hwmods : must be "usb_otg_hs" |
6 | - ti,has-mailbox : to specify that omap uses an external mailbox | ||
7 | (in control module) to communicate with the musb core during device connect | ||
8 | and disconnect. | ||
9 | - multipoint : Should be "1" indicating the musb controller supports | 6 | - multipoint : Should be "1" indicating the musb controller supports |
10 | multipoint. This is a MUSB configuration-specific setting. | 7 | multipoint. This is a MUSB configuration-specific setting. |
11 | - num-eps : Specifies the number of endpoints. This is also a | 8 | - num-eps : Specifies the number of endpoints. This is also a |
@@ -19,6 +16,9 @@ OMAP MUSB GLUE | |||
19 | - power : Should be "50". This signifies the controller can supply up to | 16 | - power : Should be "50". This signifies the controller can supply up to |
20 | 100mA when operating in host mode. | 17 | 100mA when operating in host mode. |
21 | - usb-phy : the phandle for the PHY device | 18 | - usb-phy : the phandle for the PHY device |
19 | - phys : the phandle for the PHY device (used by generic PHY framework) | ||
20 | - phy-names : the names of the PHY corresponding to the PHYs present in the | ||
21 | *phy* phandle. | ||
22 | 22 | ||
23 | Optional properties: | 23 | Optional properties: |
24 | - ctrl-module : phandle of the control module this glue uses to write to | 24 | - ctrl-module : phandle of the control module this glue uses to write to |
@@ -28,11 +28,12 @@ SOC specific device node entry | |||
28 | usb_otg_hs: usb_otg_hs@4a0ab000 { | 28 | usb_otg_hs: usb_otg_hs@4a0ab000 { |
29 | compatible = "ti,omap4-musb"; | 29 | compatible = "ti,omap4-musb"; |
30 | ti,hwmods = "usb_otg_hs"; | 30 | ti,hwmods = "usb_otg_hs"; |
31 | ti,has-mailbox; | ||
32 | multipoint = <1>; | 31 | multipoint = <1>; |
33 | num-eps = <16>; | 32 | num-eps = <16>; |
34 | ram-bits = <12>; | 33 | ram-bits = <12>; |
35 | ctrl-module = <&omap_control_usb>; | 34 | ctrl-module = <&omap_control_usb>; |
35 | phys = <&usb2_phy>; | ||
36 | phy-names = "usb2-phy"; | ||
36 | }; | 37 | }; |
37 | 38 | ||
38 | Board specific device node entry | 39 | Board specific device node entry |
@@ -78,22 +79,22 @@ omap_dwc3 { | |||
78 | OMAP CONTROL USB | 79 | OMAP CONTROL USB |
79 | 80 | ||
80 | Required properties: | 81 | Required properties: |
81 | - compatible: Should be "ti,omap-control-usb" | 82 | - compatible: Should be one of |
83 | "ti,control-phy-otghs" - if it has otghs_control mailbox register as on OMAP4. | ||
84 | "ti,control-phy-usb2" - if it has Power down bit in control_dev_conf register | ||
85 | e.g. USB2_PHY on OMAP5. | ||
86 | "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power control | ||
87 | e.g. USB3 PHY and SATA PHY on OMAP5. | ||
88 | "ti,control-phy-dra7usb2" - if it has power down register like USB2 PHY on | ||
89 | DRA7 platform. | ||
82 | - reg : Address and length of the register set for the device. It contains | 90 | - reg : Address and length of the register set for the device. It contains |
83 | the address of "control_dev_conf" and "otghs_control" or "phy_power_usb" | 91 | the address of "otghs_control" for control-phy-otghs or "power" register |
84 | depending upon omap4 or omap5. | 92 | for other types. |
85 | - reg-names: The names of the register addresses corresponding to the registers | 93 | - reg-names: should be "otghs_control" control-phy-otghs and "power" for |
86 | filled in "reg". | 94 | other types. |
87 | - ti,type: This is used to differentiate whether the control module has | ||
88 | usb mailbox or usb3 phy power. omap4 has usb mailbox in control module to | ||
89 | notify events to the musb core and omap5 has usb3 phy power register to | ||
90 | power on usb3 phy. Should be "1" if it has mailbox and "2" if it has usb3 | ||
91 | phy power. | ||
92 | 95 | ||
93 | omap_control_usb: omap-control-usb@4a002300 { | 96 | omap_control_usb: omap-control-usb@4a002300 { |
94 | compatible = "ti,omap-control-usb"; | 97 | compatible = "ti,control-phy-otghs"; |
95 | reg = <0x4a002300 0x4>, | 98 | reg = <0x4a00233c 0x4>; |
96 | <0x4a00233c 0x4>; | 99 | reg-names = "otghs_control"; |
97 | reg-names = "control_dev_conf", "otghs_control"; | ||
98 | ti,type = <1>; | ||
99 | }; | 100 | }; |
diff --git a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt index d7e272671c7e..1bd37faba05b 100644 --- a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt +++ b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt | |||
@@ -15,7 +15,7 @@ Optional properties: | |||
15 | 15 | ||
16 | - vcc-supply: phandle to the regulator that provides RESET to the PHY. | 16 | - vcc-supply: phandle to the regulator that provides RESET to the PHY. |
17 | 17 | ||
18 | - reset-supply: phandle to the regulator that provides power to the PHY. | 18 | - reset-gpios: Should specify the GPIO for reset. |
19 | 19 | ||
20 | Example: | 20 | Example: |
21 | 21 | ||
@@ -25,10 +25,9 @@ Example: | |||
25 | clocks = <&osc 0>; | 25 | clocks = <&osc 0>; |
26 | clock-names = "main_clk"; | 26 | clock-names = "main_clk"; |
27 | vcc-supply = <&hsusb1_vcc_regulator>; | 27 | vcc-supply = <&hsusb1_vcc_regulator>; |
28 | reset-supply = <&hsusb1_reset_regulator>; | 28 | reset-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>; |
29 | }; | 29 | }; |
30 | 30 | ||
31 | hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator | 31 | hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator |
32 | and expects that clock to be configured to 19.2MHz by the NOP PHY driver. | 32 | and expects that clock to be configured to 19.2MHz by the NOP PHY driver. |
33 | hsusb1_vcc_regulator provides power to the PHY and hsusb1_reset_regulator | 33 | hsusb1_vcc_regulator provides power to the PHY and GPIO 7 controls RESET. |
34 | controls RESET. | ||
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt index 61496f5cb095..c0245c888982 100644 --- a/Documentation/devicetree/bindings/usb/usb-phy.txt +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt | |||
@@ -5,6 +5,8 @@ OMAP USB2 PHY | |||
5 | Required properties: | 5 | Required properties: |
6 | - compatible: Should be "ti,omap-usb2" | 6 | - compatible: Should be "ti,omap-usb2" |
7 | - reg : Address and length of the register set for the device. | 7 | - reg : Address and length of the register set for the device. |
8 | - #phy-cells: determine the number of cells that should be given in the | ||
9 | phandle while referencing this phy. | ||
8 | 10 | ||
9 | Optional properties: | 11 | Optional properties: |
10 | - ctrl-module : phandle of the control module used by PHY driver to power on | 12 | - ctrl-module : phandle of the control module used by PHY driver to power on |
@@ -16,6 +18,7 @@ usb2phy@4a0ad080 { | |||
16 | compatible = "ti,omap-usb2"; | 18 | compatible = "ti,omap-usb2"; |
17 | reg = <0x4a0ad080 0x58>; | 19 | reg = <0x4a0ad080 0x58>; |
18 | ctrl-module = <&omap_control_usb>; | 20 | ctrl-module = <&omap_control_usb>; |
21 | #phy-cells = <0>; | ||
19 | }; | 22 | }; |
20 | 23 | ||
21 | OMAP USB3 PHY | 24 | OMAP USB3 PHY |
@@ -25,6 +28,8 @@ Required properties: | |||
25 | - reg : Address and length of the register set for the device. | 28 | - reg : Address and length of the register set for the device. |
26 | - reg-names: The names of the register addresses corresponding to the registers | 29 | - reg-names: The names of the register addresses corresponding to the registers |
27 | filled in "reg". | 30 | filled in "reg". |
31 | - #phy-cells: determine the number of cells that should be given in the | ||
32 | phandle while referencing this phy. | ||
28 | 33 | ||
29 | Optional properties: | 34 | Optional properties: |
30 | - ctrl-module : phandle of the control module used by PHY driver to power on | 35 | - ctrl-module : phandle of the control module used by PHY driver to power on |
@@ -39,4 +44,5 @@ usb3phy@4a084400 { | |||
39 | <0x4a084c00 0x40>; | 44 | <0x4a084c00 0x40>; |
40 | reg-names = "phy_rx", "phy_tx", "pll_ctrl"; | 45 | reg-names = "phy_rx", "phy_tx", "pll_ctrl"; |
41 | ctrl-module = <&omap_control_usb>; | 46 | ctrl-module = <&omap_control_usb>; |
47 | #phy-cells = <0>; | ||
42 | }; | 48 | }; |
diff --git a/Documentation/devicetree/bindings/video/exynos_dp.txt b/Documentation/devicetree/bindings/video/exynos_dp.txt index 84f10c16cb38..3289d76a21d0 100644 --- a/Documentation/devicetree/bindings/video/exynos_dp.txt +++ b/Documentation/devicetree/bindings/video/exynos_dp.txt | |||
@@ -6,10 +6,10 @@ We use two nodes: | |||
6 | -dptx-phy node(defined inside dp-controller node) | 6 | -dptx-phy node(defined inside dp-controller node) |
7 | 7 | ||
8 | For the DP-PHY initialization, we use the dptx-phy node. | 8 | For the DP-PHY initialization, we use the dptx-phy node. |
9 | Required properties for dptx-phy: | 9 | Required properties for dptx-phy: deprecated, use phys and phy-names |
10 | -reg: | 10 | -reg: deprecated |
11 | Base address of DP PHY register. | 11 | Base address of DP PHY register. |
12 | -samsung,enable-mask: | 12 | -samsung,enable-mask: deprecated |
13 | The bit-mask used to enable/disable DP PHY. | 13 | The bit-mask used to enable/disable DP PHY. |
14 | 14 | ||
15 | For the Panel initialization, we read data from dp-controller node. | 15 | For the Panel initialization, we read data from dp-controller node. |
@@ -27,6 +27,10 @@ Required properties for dp-controller: | |||
27 | from common clock binding: Shall be "dp". | 27 | from common clock binding: Shall be "dp". |
28 | -interrupt-parent: | 28 | -interrupt-parent: |
29 | phandle to Interrupt combiner node. | 29 | phandle to Interrupt combiner node. |
30 | -phys: | ||
31 | from general PHY binding: the phandle for the PHY device. | ||
32 | -phy-names: | ||
33 | from general PHY binding: Should be "dp". | ||
30 | -samsung,color-space: | 34 | -samsung,color-space: |
31 | input video data format. | 35 | input video data format. |
32 | COLOR_RGB = 0, COLOR_YCBCR422 = 1, COLOR_YCBCR444 = 2 | 36 | COLOR_RGB = 0, COLOR_YCBCR422 = 1, COLOR_YCBCR444 = 2 |
@@ -68,11 +72,8 @@ SOC specific portion: | |||
68 | clocks = <&clock 342>; | 72 | clocks = <&clock 342>; |
69 | clock-names = "dp"; | 73 | clock-names = "dp"; |
70 | 74 | ||
71 | dptx-phy { | 75 | phys = <&dp_phy>; |
72 | reg = <0x10040720>; | 76 | phy-names = "dp"; |
73 | samsung,enable-mask = <1>; | ||
74 | }; | ||
75 | |||
76 | }; | 77 | }; |
77 | 78 | ||
78 | Board Specific portion: | 79 | Board Specific portion: |
diff --git a/Documentation/phy.txt b/Documentation/phy.txt new file mode 100644 index 000000000000..0103e4b15b0e --- /dev/null +++ b/Documentation/phy.txt | |||
@@ -0,0 +1,166 @@ | |||
1 | PHY SUBSYSTEM | ||
2 | Kishon Vijay Abraham I <kishon@ti.com> | ||
3 | |||
4 | This document explains the Generic PHY Framework along with the APIs provided, | ||
5 | and how-to-use. | ||
6 | |||
7 | 1. Introduction | ||
8 | |||
9 | *PHY* is the abbreviation for physical layer. It is used to connect a device | ||
10 | to the physical medium e.g., the USB controller has a PHY to provide functions | ||
11 | such as serialization, de-serialization, encoding, decoding and is responsible | ||
12 | for obtaining the required data transmission rate. Note that some USB | ||
13 | controllers have PHY functionality embedded into it and others use an external | ||
14 | PHY. Other peripherals that use PHY include Wireless LAN, Ethernet, | ||
15 | SATA etc. | ||
16 | |||
17 | The intention of creating this framework is to bring the PHY drivers spread | ||
18 | all over the Linux kernel to drivers/phy to increase code re-use and for | ||
19 | better code maintainability. | ||
20 | |||
21 | This framework will be of use only to devices that use external PHY (PHY | ||
22 | functionality is not embedded within the controller). | ||
23 | |||
24 | 2. Registering/Unregistering the PHY provider | ||
25 | |||
26 | PHY provider refers to an entity that implements one or more PHY instances. | ||
27 | For the simple case where the PHY provider implements only a single instance of | ||
28 | the PHY, the framework provides its own implementation of of_xlate in | ||
29 | of_phy_simple_xlate. If the PHY provider implements multiple instances, it | ||
30 | should provide its own implementation of of_xlate. of_xlate is used only for | ||
31 | dt boot case. | ||
32 | |||
33 | #define of_phy_provider_register(dev, xlate) \ | ||
34 | __of_phy_provider_register((dev), THIS_MODULE, (xlate)) | ||
35 | |||
36 | #define devm_of_phy_provider_register(dev, xlate) \ | ||
37 | __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) | ||
38 | |||
39 | of_phy_provider_register and devm_of_phy_provider_register macros can be used to | ||
40 | register the phy_provider and it takes device and of_xlate as | ||
41 | arguments. For the dt boot case, all PHY providers should use one of the above | ||
42 | 2 macros to register the PHY provider. | ||
43 | |||
44 | void devm_of_phy_provider_unregister(struct device *dev, | ||
45 | struct phy_provider *phy_provider); | ||
46 | void of_phy_provider_unregister(struct phy_provider *phy_provider); | ||
47 | |||
48 | devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to | ||
49 | unregister the PHY. | ||
50 | |||
51 | 3. Creating the PHY | ||
52 | |||
53 | The PHY driver should create the PHY in order for other peripheral controllers | ||
54 | to make use of it. The PHY framework provides 2 APIs to create the PHY. | ||
55 | |||
56 | struct phy *phy_create(struct device *dev, const struct phy_ops *ops, | ||
57 | struct phy_init_data *init_data); | ||
58 | struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops, | ||
59 | struct phy_init_data *init_data); | ||
60 | |||
61 | The PHY drivers can use one of the above 2 APIs to create the PHY by passing | ||
62 | the device pointer, phy ops and init_data. | ||
63 | phy_ops is a set of function pointers for performing PHY operations such as | ||
64 | init, exit, power_on and power_off. *init_data* is mandatory to get a reference | ||
65 | to the PHY in the case of non-dt boot. See section *Board File Initialization* | ||
66 | on how init_data should be used. | ||
67 | |||
68 | Inorder to dereference the private data (in phy_ops), the phy provider driver | ||
69 | can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in | ||
70 | phy_ops to get back the private data. | ||
71 | |||
72 | 4. Getting a reference to the PHY | ||
73 | |||
74 | Before the controller can make use of the PHY, it has to get a reference to | ||
75 | it. This framework provides the following APIs to get a reference to the PHY. | ||
76 | |||
77 | struct phy *phy_get(struct device *dev, const char *string); | ||
78 | struct phy *devm_phy_get(struct device *dev, const char *string); | ||
79 | |||
80 | phy_get and devm_phy_get can be used to get the PHY. In the case of dt boot, | ||
81 | the string arguments should contain the phy name as given in the dt data and | ||
82 | in the case of non-dt boot, it should contain the label of the PHY. | ||
83 | The only difference between the two APIs is that devm_phy_get associates the | ||
84 | device with the PHY using devres on successful PHY get. On driver detach, | ||
85 | release function is invoked on the the devres data and devres data is freed. | ||
86 | |||
87 | 5. Releasing a reference to the PHY | ||
88 | |||
89 | When the controller no longer needs the PHY, it has to release the reference | ||
90 | to the PHY it has obtained using the APIs mentioned in the above section. The | ||
91 | PHY framework provides 2 APIs to release a reference to the PHY. | ||
92 | |||
93 | void phy_put(struct phy *phy); | ||
94 | void devm_phy_put(struct device *dev, struct phy *phy); | ||
95 | |||
96 | Both these APIs are used to release a reference to the PHY and devm_phy_put | ||
97 | destroys the devres associated with this PHY. | ||
98 | |||
99 | 6. Destroying the PHY | ||
100 | |||
101 | When the driver that created the PHY is unloaded, it should destroy the PHY it | ||
102 | created using one of the following 2 APIs. | ||
103 | |||
104 | void phy_destroy(struct phy *phy); | ||
105 | void devm_phy_destroy(struct device *dev, struct phy *phy); | ||
106 | |||
107 | Both these APIs destroy the PHY and devm_phy_destroy destroys the devres | ||
108 | associated with this PHY. | ||
109 | |||
110 | 7. PM Runtime | ||
111 | |||
112 | This subsystem is pm runtime enabled. So while creating the PHY, | ||
113 | pm_runtime_enable of the phy device created by this subsystem is called and | ||
114 | while destroying the PHY, pm_runtime_disable is called. Note that the phy | ||
115 | device created by this subsystem will be a child of the device that calls | ||
116 | phy_create (PHY provider device). | ||
117 | |||
118 | So pm_runtime_get_sync of the phy_device created by this subsystem will invoke | ||
119 | pm_runtime_get_sync of PHY provider device because of parent-child relationship. | ||
120 | It should also be noted that phy_power_on and phy_power_off performs | ||
121 | phy_pm_runtime_get_sync and phy_pm_runtime_put respectively. | ||
122 | There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync, | ||
123 | phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and | ||
124 | phy_pm_runtime_forbid for performing PM operations. | ||
125 | |||
126 | 8. Board File Initialization | ||
127 | |||
128 | Certain board file initialization is necessary in order to get a reference | ||
129 | to the PHY in the case of non-dt boot. | ||
130 | Say we have a single device that implements 3 PHYs that of USB, SATA and PCIe, | ||
131 | then in the board file the following initialization should be done. | ||
132 | |||
133 | struct phy_consumer consumers[] = { | ||
134 | PHY_CONSUMER("dwc3.0", "usb"), | ||
135 | PHY_CONSUMER("pcie.0", "pcie"), | ||
136 | PHY_CONSUMER("sata.0", "sata"), | ||
137 | }; | ||
138 | PHY_CONSUMER takes 2 parameters, first is the device name of the controller | ||
139 | (PHY consumer) and second is the port name. | ||
140 | |||
141 | struct phy_init_data init_data = { | ||
142 | .consumers = consumers, | ||
143 | .num_consumers = ARRAY_SIZE(consumers), | ||
144 | }; | ||
145 | |||
146 | static const struct platform_device pipe3_phy_dev = { | ||
147 | .name = "pipe3-phy", | ||
148 | .id = -1, | ||
149 | .dev = { | ||
150 | .platform_data = { | ||
151 | .init_data = &init_data, | ||
152 | }, | ||
153 | }, | ||
154 | }; | ||
155 | |||
156 | then, while doing phy_create, the PHY driver should pass this init_data | ||
157 | phy_create(dev, ops, pdata->init_data); | ||
158 | |||
159 | and the controller driver (phy consumer) should pass the port name along with | ||
160 | the device to get a reference to the PHY | ||
161 | phy_get(dev, "pcie"); | ||
162 | |||
163 | 9. DeviceTree Binding | ||
164 | |||
165 | The documentation for PHY dt binding can be found @ | ||
166 | Documentation/devicetree/bindings/phy/phy-bindings.txt | ||
diff --git a/Documentation/pps/pps.txt b/Documentation/pps/pps.txt index d35dcdd82ff6..c03b1be5eb15 100644 --- a/Documentation/pps/pps.txt +++ b/Documentation/pps/pps.txt | |||
@@ -66,6 +66,21 @@ In LinuxPPS the PPS sources are simply char devices usually mapped | |||
66 | into files /dev/pps0, /dev/pps1, etc.. | 66 | into files /dev/pps0, /dev/pps1, etc.. |
67 | 67 | ||
68 | 68 | ||
69 | PPS with USB to serial devices | ||
70 | ------------------------------ | ||
71 | |||
72 | It is possible to grab the PPS from an USB to serial device. However, | ||
73 | you should take into account the latencies and jitter introduced by | ||
74 | the USB stack. Users has reported clock instability around +-1ms when | ||
75 | synchronized with PPS through USB. This isn't suited for time server | ||
76 | synchronization. | ||
77 | |||
78 | If your device doesn't report PPS, you can check that the feature is | ||
79 | supported by its driver. Most of the time, you only need to add a call | ||
80 | to usb_serial_handle_dcd_change after checking the DCD status (see | ||
81 | ch341 and pl2303 examples). | ||
82 | |||
83 | |||
69 | Coding example | 84 | Coding example |
70 | -------------- | 85 | -------------- |
71 | 86 | ||
diff --git a/MAINTAINERS b/MAINTAINERS index ffcaf975bed7..64a4ab154af8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -3691,6 +3691,14 @@ S: Maintained | |||
3691 | F: include/asm-generic/ | 3691 | F: include/asm-generic/ |
3692 | F: include/uapi/asm-generic/ | 3692 | F: include/uapi/asm-generic/ |
3693 | 3693 | ||
3694 | GENERIC PHY FRAMEWORK | ||
3695 | M: Kishon Vijay Abraham I <kishon@ti.com> | ||
3696 | L: linux-kernel@vger.kernel.org | ||
3697 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git | ||
3698 | S: Supported | ||
3699 | F: drivers/phy/ | ||
3700 | F: include/linux/phy/ | ||
3701 | |||
3694 | GENERIC UIO DRIVER FOR PCI DEVICES | 3702 | GENERIC UIO DRIVER FOR PCI DEVICES |
3695 | M: "Michael S. Tsirkin" <mst@redhat.com> | 3703 | M: "Michael S. Tsirkin" <mst@redhat.com> |
3696 | L: kvm@vger.kernel.org | 3704 | L: kvm@vger.kernel.org |
diff --git a/arch/arm/boot/dts/omap3-beagle-xm.dts b/arch/arm/boot/dts/omap3-beagle-xm.dts index 2816bf612672..ba4dcfc6b721 100644 --- a/arch/arm/boot/dts/omap3-beagle-xm.dts +++ b/arch/arm/boot/dts/omap3-beagle-xm.dts | |||
@@ -144,6 +144,8 @@ | |||
144 | &usb_otg_hs { | 144 | &usb_otg_hs { |
145 | interface-type = <0>; | 145 | interface-type = <0>; |
146 | usb-phy = <&usb2_phy>; | 146 | usb-phy = <&usb2_phy>; |
147 | phys = <&usb2_phy>; | ||
148 | phy-names = "usb2-phy"; | ||
147 | mode = <3>; | 149 | mode = <3>; |
148 | power = <50>; | 150 | power = <50>; |
149 | }; | 151 | }; |
diff --git a/arch/arm/boot/dts/omap3-evm.dts b/arch/arm/boot/dts/omap3-evm.dts index 7d4329d179c4..4134dd05c3a4 100644 --- a/arch/arm/boot/dts/omap3-evm.dts +++ b/arch/arm/boot/dts/omap3-evm.dts | |||
@@ -70,6 +70,8 @@ | |||
70 | &usb_otg_hs { | 70 | &usb_otg_hs { |
71 | interface-type = <0>; | 71 | interface-type = <0>; |
72 | usb-phy = <&usb2_phy>; | 72 | usb-phy = <&usb2_phy>; |
73 | phys = <&usb2_phy>; | ||
74 | phy-names = "usb2-phy"; | ||
73 | mode = <3>; | 75 | mode = <3>; |
74 | power = <50>; | 76 | power = <50>; |
75 | }; | 77 | }; |
diff --git a/arch/arm/boot/dts/omap3-overo.dtsi b/arch/arm/boot/dts/omap3-overo.dtsi index 8f1abec78275..a461d2fd1fb0 100644 --- a/arch/arm/boot/dts/omap3-overo.dtsi +++ b/arch/arm/boot/dts/omap3-overo.dtsi | |||
@@ -76,6 +76,8 @@ | |||
76 | &usb_otg_hs { | 76 | &usb_otg_hs { |
77 | interface-type = <0>; | 77 | interface-type = <0>; |
78 | usb-phy = <&usb2_phy>; | 78 | usb-phy = <&usb2_phy>; |
79 | phys = <&usb2_phy>; | ||
80 | phy-names = "usb2-phy"; | ||
79 | mode = <3>; | 81 | mode = <3>; |
80 | power = <50>; | 82 | power = <50>; |
81 | }; | 83 | }; |
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi index 22d9f2b593d4..ea4054bfdfd4 100644 --- a/arch/arm/boot/dts/omap4.dtsi +++ b/arch/arm/boot/dts/omap4.dtsi | |||
@@ -519,7 +519,8 @@ | |||
519 | usb2_phy: usb2phy@4a0ad080 { | 519 | usb2_phy: usb2phy@4a0ad080 { |
520 | compatible = "ti,omap-usb2"; | 520 | compatible = "ti,omap-usb2"; |
521 | reg = <0x4a0ad080 0x58>; | 521 | reg = <0x4a0ad080 0x58>; |
522 | ctrl-module = <&omap_control_usb>; | 522 | ctrl-module = <&omap_control_usb2phy>; |
523 | #phy-cells = <0>; | ||
523 | }; | 524 | }; |
524 | }; | 525 | }; |
525 | 526 | ||
@@ -643,12 +644,16 @@ | |||
643 | }; | 644 | }; |
644 | }; | 645 | }; |
645 | 646 | ||
646 | omap_control_usb: omap-control-usb@4a002300 { | 647 | omap_control_usb2phy: control-phy@4a002300 { |
647 | compatible = "ti,omap-control-usb"; | 648 | compatible = "ti,control-phy-usb2"; |
648 | reg = <0x4a002300 0x4>, | 649 | reg = <0x4a002300 0x4>; |
649 | <0x4a00233c 0x4>; | 650 | reg-names = "power"; |
650 | reg-names = "control_dev_conf", "otghs_control"; | 651 | }; |
651 | ti,type = <1>; | 652 | |
653 | omap_control_usbotg: control-phy@4a00233c { | ||
654 | compatible = "ti,control-phy-otghs"; | ||
655 | reg = <0x4a00233c 0x4>; | ||
656 | reg-names = "otghs_control"; | ||
652 | }; | 657 | }; |
653 | 658 | ||
654 | usb_otg_hs: usb_otg_hs@4a0ab000 { | 659 | usb_otg_hs: usb_otg_hs@4a0ab000 { |
@@ -658,10 +663,12 @@ | |||
658 | interrupt-names = "mc", "dma"; | 663 | interrupt-names = "mc", "dma"; |
659 | ti,hwmods = "usb_otg_hs"; | 664 | ti,hwmods = "usb_otg_hs"; |
660 | usb-phy = <&usb2_phy>; | 665 | usb-phy = <&usb2_phy>; |
666 | phys = <&usb2_phy>; | ||
667 | phy-names = "usb2-phy"; | ||
661 | multipoint = <1>; | 668 | multipoint = <1>; |
662 | num-eps = <16>; | 669 | num-eps = <16>; |
663 | ram-bits = <12>; | 670 | ram-bits = <12>; |
664 | ti,has-mailbox; | 671 | ctrl-module = <&omap_control_usbotg>; |
665 | }; | 672 | }; |
666 | }; | 673 | }; |
667 | }; | 674 | }; |
diff --git a/arch/arm/boot/dts/omap5.dtsi b/arch/arm/boot/dts/omap5.dtsi index 7cdea1bfea09..c0ec6dce30fe 100644 --- a/arch/arm/boot/dts/omap5.dtsi +++ b/arch/arm/boot/dts/omap5.dtsi | |||
@@ -626,12 +626,16 @@ | |||
626 | hw-caps-temp-alert; | 626 | hw-caps-temp-alert; |
627 | }; | 627 | }; |
628 | 628 | ||
629 | omap_control_usb: omap-control-usb@4a002300 { | 629 | omap_control_usb2phy: control-phy@4a002300 { |
630 | compatible = "ti,omap-control-usb"; | 630 | compatible = "ti,control-phy-usb2"; |
631 | reg = <0x4a002300 0x4>, | 631 | reg = <0x4a002300 0x4>; |
632 | <0x4a002370 0x4>; | 632 | reg-names = "power"; |
633 | reg-names = "control_dev_conf", "phy_power_usb"; | 633 | }; |
634 | ti,type = <2>; | 634 | |
635 | omap_control_usb3phy: control-phy@4a002370 { | ||
636 | compatible = "ti,control-phy-pipe3"; | ||
637 | reg = <0x4a002370 0x4>; | ||
638 | reg-names = "power"; | ||
635 | }; | 639 | }; |
636 | 640 | ||
637 | omap_dwc3@4a020000 { | 641 | omap_dwc3@4a020000 { |
@@ -662,7 +666,7 @@ | |||
662 | usb2_phy: usb2phy@4a084000 { | 666 | usb2_phy: usb2phy@4a084000 { |
663 | compatible = "ti,omap-usb2"; | 667 | compatible = "ti,omap-usb2"; |
664 | reg = <0x4a084000 0x7c>; | 668 | reg = <0x4a084000 0x7c>; |
665 | ctrl-module = <&omap_control_usb>; | 669 | ctrl-module = <&omap_control_usb2phy>; |
666 | }; | 670 | }; |
667 | 671 | ||
668 | usb3_phy: usb3phy@4a084400 { | 672 | usb3_phy: usb3phy@4a084400 { |
@@ -671,7 +675,7 @@ | |||
671 | <0x4a084800 0x64>, | 675 | <0x4a084800 0x64>, |
672 | <0x4a084c00 0x40>; | 676 | <0x4a084c00 0x40>; |
673 | reg-names = "phy_rx", "phy_tx", "pll_ctrl"; | 677 | reg-names = "phy_rx", "phy_tx", "pll_ctrl"; |
674 | ctrl-module = <&omap_control_usb>; | 678 | ctrl-module = <&omap_control_usb3phy>; |
675 | }; | 679 | }; |
676 | }; | 680 | }; |
677 | 681 | ||
diff --git a/arch/arm/boot/dts/twl4030.dtsi b/arch/arm/boot/dts/twl4030.dtsi index ae6a17aed9ee..5aba238d1f1e 100644 --- a/arch/arm/boot/dts/twl4030.dtsi +++ b/arch/arm/boot/dts/twl4030.dtsi | |||
@@ -86,6 +86,7 @@ | |||
86 | usb1v8-supply = <&vusb1v8>; | 86 | usb1v8-supply = <&vusb1v8>; |
87 | usb3v1-supply = <&vusb3v1>; | 87 | usb3v1-supply = <&vusb3v1>; |
88 | usb_mode = <1>; | 88 | usb_mode = <1>; |
89 | #phy-cells = <0>; | ||
89 | }; | 90 | }; |
90 | 91 | ||
91 | twl_pwm: pwm { | 92 | twl_pwm: pwm { |
diff --git a/arch/arm/configs/ep93xx_defconfig b/arch/arm/configs/ep93xx_defconfig index 806005a4c4c1..6ac5ea73bd0a 100644 --- a/arch/arm/configs/ep93xx_defconfig +++ b/arch/arm/configs/ep93xx_defconfig | |||
@@ -1,15 +1,14 @@ | |||
1 | CONFIG_EXPERIMENTAL=y | ||
2 | CONFIG_SYSVIPC=y | 1 | CONFIG_SYSVIPC=y |
3 | CONFIG_IKCONFIG=y | 2 | CONFIG_IKCONFIG=y |
4 | CONFIG_IKCONFIG_PROC=y | 3 | CONFIG_IKCONFIG_PROC=y |
5 | CONFIG_LOG_BUF_SHIFT=14 | 4 | CONFIG_LOG_BUF_SHIFT=14 |
6 | CONFIG_SYSFS_DEPRECATED_V2=y | ||
7 | CONFIG_EXPERT=y | 5 | CONFIG_EXPERT=y |
8 | CONFIG_SLAB=y | 6 | CONFIG_SLAB=y |
9 | CONFIG_MODULES=y | 7 | CONFIG_MODULES=y |
10 | CONFIG_MODULE_UNLOAD=y | 8 | CONFIG_MODULE_UNLOAD=y |
11 | CONFIG_MODULE_FORCE_UNLOAD=y | 9 | CONFIG_MODULE_FORCE_UNLOAD=y |
12 | # CONFIG_BLK_DEV_BSG is not set | 10 | # CONFIG_BLK_DEV_BSG is not set |
11 | CONFIG_PARTITION_ADVANCED=y | ||
13 | # CONFIG_IOSCHED_CFQ is not set | 12 | # CONFIG_IOSCHED_CFQ is not set |
14 | CONFIG_ARCH_EP93XX=y | 13 | CONFIG_ARCH_EP93XX=y |
15 | CONFIG_CRUNCH=y | 14 | CONFIG_CRUNCH=y |
@@ -47,11 +46,8 @@ CONFIG_IPV6=y | |||
47 | CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" | 46 | CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" |
48 | # CONFIG_FW_LOADER is not set | 47 | # CONFIG_FW_LOADER is not set |
49 | CONFIG_MTD=y | 48 | CONFIG_MTD=y |
50 | CONFIG_MTD_CONCAT=y | ||
51 | CONFIG_MTD_PARTITIONS=y | ||
52 | CONFIG_MTD_REDBOOT_PARTS=y | 49 | CONFIG_MTD_REDBOOT_PARTS=y |
53 | CONFIG_MTD_CMDLINE_PARTS=y | 50 | CONFIG_MTD_CMDLINE_PARTS=y |
54 | CONFIG_MTD_CHAR=y | ||
55 | CONFIG_MTD_BLOCK=y | 51 | CONFIG_MTD_BLOCK=y |
56 | CONFIG_MTD_CFI=y | 52 | CONFIG_MTD_CFI=y |
57 | CONFIG_MTD_CFI_ADV_OPTIONS=y | 53 | CONFIG_MTD_CFI_ADV_OPTIONS=y |
@@ -67,15 +63,14 @@ CONFIG_SCSI=y | |||
67 | # CONFIG_SCSI_PROC_FS is not set | 63 | # CONFIG_SCSI_PROC_FS is not set |
68 | CONFIG_BLK_DEV_SD=y | 64 | CONFIG_BLK_DEV_SD=y |
69 | CONFIG_NETDEVICES=y | 65 | CONFIG_NETDEVICES=y |
70 | CONFIG_NET_ETHERNET=y | ||
71 | CONFIG_EP93XX_ETH=y | 66 | CONFIG_EP93XX_ETH=y |
72 | CONFIG_USB_RTL8150=y | 67 | CONFIG_USB_RTL8150=y |
73 | # CONFIG_INPUT is not set | 68 | # CONFIG_INPUT is not set |
74 | # CONFIG_SERIO is not set | 69 | # CONFIG_SERIO is not set |
75 | # CONFIG_VT is not set | 70 | # CONFIG_VT is not set |
71 | # CONFIG_LEGACY_PTYS is not set | ||
76 | CONFIG_SERIAL_AMBA_PL010=y | 72 | CONFIG_SERIAL_AMBA_PL010=y |
77 | CONFIG_SERIAL_AMBA_PL010_CONSOLE=y | 73 | CONFIG_SERIAL_AMBA_PL010_CONSOLE=y |
78 | # CONFIG_LEGACY_PTYS is not set | ||
79 | # CONFIG_HW_RANDOM is not set | 74 | # CONFIG_HW_RANDOM is not set |
80 | CONFIG_I2C=y | 75 | CONFIG_I2C=y |
81 | CONFIG_I2C_CHARDEV=y | 76 | CONFIG_I2C_CHARDEV=y |
@@ -86,9 +81,9 @@ CONFIG_WATCHDOG=y | |||
86 | CONFIG_EP93XX_WATCHDOG=y | 81 | CONFIG_EP93XX_WATCHDOG=y |
87 | CONFIG_USB=y | 82 | CONFIG_USB=y |
88 | CONFIG_USB_DEBUG=y | 83 | CONFIG_USB_DEBUG=y |
89 | CONFIG_USB_DEVICEFS=y | ||
90 | CONFIG_USB_DYNAMIC_MINORS=y | 84 | CONFIG_USB_DYNAMIC_MINORS=y |
91 | CONFIG_USB_OHCI_HCD=y | 85 | CONFIG_USB_OHCI_HCD=y |
86 | CONFIG_USB_OHCI_HCD_PLATFORM=y | ||
92 | CONFIG_USB_STORAGE=y | 87 | CONFIG_USB_STORAGE=y |
93 | CONFIG_USB_SERIAL=y | 88 | CONFIG_USB_SERIAL=y |
94 | CONFIG_USB_SERIAL_CONSOLE=y | 89 | CONFIG_USB_SERIAL_CONSOLE=y |
@@ -100,24 +95,18 @@ CONFIG_RTC_DRV_EP93XX=y | |||
100 | CONFIG_EXT2_FS=y | 95 | CONFIG_EXT2_FS=y |
101 | CONFIG_EXT3_FS=y | 96 | CONFIG_EXT3_FS=y |
102 | # CONFIG_EXT3_FS_XATTR is not set | 97 | # CONFIG_EXT3_FS_XATTR is not set |
103 | CONFIG_INOTIFY=y | ||
104 | CONFIG_VFAT_FS=y | 98 | CONFIG_VFAT_FS=y |
105 | CONFIG_TMPFS=y | 99 | CONFIG_TMPFS=y |
106 | CONFIG_JFFS2_FS=y | 100 | CONFIG_JFFS2_FS=y |
107 | CONFIG_NFS_FS=y | 101 | CONFIG_NFS_FS=y |
108 | CONFIG_NFS_V3=y | ||
109 | CONFIG_ROOT_NFS=y | 102 | CONFIG_ROOT_NFS=y |
110 | CONFIG_PARTITION_ADVANCED=y | ||
111 | CONFIG_NLS_CODEPAGE_437=y | 103 | CONFIG_NLS_CODEPAGE_437=y |
112 | CONFIG_NLS_ISO8859_1=y | 104 | CONFIG_NLS_ISO8859_1=y |
113 | CONFIG_MAGIC_SYSRQ=y | 105 | CONFIG_MAGIC_SYSRQ=y |
114 | CONFIG_DEBUG_KERNEL=y | ||
115 | CONFIG_DEBUG_SLAB=y | 106 | CONFIG_DEBUG_SLAB=y |
116 | CONFIG_DEBUG_SPINLOCK=y | 107 | CONFIG_DEBUG_SPINLOCK=y |
117 | CONFIG_DEBUG_MUTEXES=y | 108 | CONFIG_DEBUG_MUTEXES=y |
118 | # CONFIG_RCU_CPU_STALL_DETECTOR is not set | ||
119 | CONFIG_DEBUG_USER=y | 109 | CONFIG_DEBUG_USER=y |
120 | CONFIG_DEBUG_ERRORS=y | ||
121 | CONFIG_DEBUG_LL=y | 110 | CONFIG_DEBUG_LL=y |
122 | # CONFIG_CRYPTO_ANSI_CPRNG is not set | 111 | # CONFIG_CRYPTO_ANSI_CPRNG is not set |
123 | CONFIG_LIBCRC32C=y | 112 | CONFIG_LIBCRC32C=y |
diff --git a/arch/arm/mach-ep93xx/clock.c b/arch/arm/mach-ep93xx/clock.c index c95dbce2468e..39ef3b613912 100644 --- a/arch/arm/mach-ep93xx/clock.c +++ b/arch/arm/mach-ep93xx/clock.c | |||
@@ -212,7 +212,7 @@ static struct clk_lookup clocks[] = { | |||
212 | INIT_CK(NULL, "hclk", &clk_h), | 212 | INIT_CK(NULL, "hclk", &clk_h), |
213 | INIT_CK(NULL, "apb_pclk", &clk_p), | 213 | INIT_CK(NULL, "apb_pclk", &clk_p), |
214 | INIT_CK(NULL, "pll2", &clk_pll2), | 214 | INIT_CK(NULL, "pll2", &clk_pll2), |
215 | INIT_CK("ep93xx-ohci", NULL, &clk_usb_host), | 215 | INIT_CK("ohci-platform", NULL, &clk_usb_host), |
216 | INIT_CK("ep93xx-keypad", NULL, &clk_keypad), | 216 | INIT_CK("ep93xx-keypad", NULL, &clk_keypad), |
217 | INIT_CK("ep93xx-fb", NULL, &clk_video), | 217 | INIT_CK("ep93xx-fb", NULL, &clk_video), |
218 | INIT_CK("ep93xx-spi.0", NULL, &clk_spi), | 218 | INIT_CK("ep93xx-spi.0", NULL, &clk_spi), |
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c index 3f12b885c083..d95ee28a616a 100644 --- a/arch/arm/mach-ep93xx/core.c +++ b/arch/arm/mach-ep93xx/core.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/export.h> | 36 | #include <linux/export.h> |
37 | #include <linux/irqchip/arm-vic.h> | 37 | #include <linux/irqchip/arm-vic.h> |
38 | #include <linux/reboot.h> | 38 | #include <linux/reboot.h> |
39 | #include <linux/usb/ohci_pdriver.h> | ||
39 | 40 | ||
40 | #include <mach/hardware.h> | 41 | #include <mach/hardware.h> |
41 | #include <linux/platform_data/video-ep93xx.h> | 42 | #include <linux/platform_data/video-ep93xx.h> |
@@ -297,25 +298,53 @@ static struct platform_device ep93xx_rtc_device = { | |||
297 | .resource = ep93xx_rtc_resource, | 298 | .resource = ep93xx_rtc_resource, |
298 | }; | 299 | }; |
299 | 300 | ||
301 | /************************************************************************* | ||
302 | * EP93xx OHCI USB Host | ||
303 | *************************************************************************/ | ||
304 | |||
305 | static struct clk *ep93xx_ohci_host_clock; | ||
306 | |||
307 | static int ep93xx_ohci_power_on(struct platform_device *pdev) | ||
308 | { | ||
309 | if (!ep93xx_ohci_host_clock) { | ||
310 | ep93xx_ohci_host_clock = devm_clk_get(&pdev->dev, NULL); | ||
311 | if (IS_ERR(ep93xx_ohci_host_clock)) | ||
312 | return PTR_ERR(ep93xx_ohci_host_clock); | ||
313 | } | ||
314 | |||
315 | return clk_enable(ep93xx_ohci_host_clock); | ||
316 | } | ||
317 | |||
318 | static void ep93xx_ohci_power_off(struct platform_device *pdev) | ||
319 | { | ||
320 | clk_disable(ep93xx_ohci_host_clock); | ||
321 | } | ||
322 | |||
323 | static struct usb_ohci_pdata ep93xx_ohci_pdata = { | ||
324 | .power_on = ep93xx_ohci_power_on, | ||
325 | .power_off = ep93xx_ohci_power_off, | ||
326 | .power_suspend = ep93xx_ohci_power_off, | ||
327 | }; | ||
300 | 328 | ||
301 | static struct resource ep93xx_ohci_resources[] = { | 329 | static struct resource ep93xx_ohci_resources[] = { |
302 | DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000), | 330 | DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000), |
303 | DEFINE_RES_IRQ(IRQ_EP93XX_USB), | 331 | DEFINE_RES_IRQ(IRQ_EP93XX_USB), |
304 | }; | 332 | }; |
305 | 333 | ||
334 | static u64 ep93xx_ohci_dma_mask = DMA_BIT_MASK(32); | ||
306 | 335 | ||
307 | static struct platform_device ep93xx_ohci_device = { | 336 | static struct platform_device ep93xx_ohci_device = { |
308 | .name = "ep93xx-ohci", | 337 | .name = "ohci-platform", |
309 | .id = -1, | 338 | .id = -1, |
339 | .num_resources = ARRAY_SIZE(ep93xx_ohci_resources), | ||
340 | .resource = ep93xx_ohci_resources, | ||
310 | .dev = { | 341 | .dev = { |
311 | .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask, | 342 | .dma_mask = &ep93xx_ohci_dma_mask, |
312 | .coherent_dma_mask = DMA_BIT_MASK(32), | 343 | .coherent_dma_mask = DMA_BIT_MASK(32), |
344 | .platform_data = &ep93xx_ohci_pdata, | ||
313 | }, | 345 | }, |
314 | .num_resources = ARRAY_SIZE(ep93xx_ohci_resources), | ||
315 | .resource = ep93xx_ohci_resources, | ||
316 | }; | 346 | }; |
317 | 347 | ||
318 | |||
319 | /************************************************************************* | 348 | /************************************************************************* |
320 | * EP93xx physmap'ed flash | 349 | * EP93xx physmap'ed flash |
321 | *************************************************************************/ | 350 | *************************************************************************/ |
diff --git a/arch/arm/mach-exynos/include/mach/regs-pmu.h b/arch/arm/mach-exynos/include/mach/regs-pmu.h index 57344b7e98ce..2cdb63e8ce5c 100644 --- a/arch/arm/mach-exynos/include/mach/regs-pmu.h +++ b/arch/arm/mach-exynos/include/mach/regs-pmu.h | |||
@@ -44,11 +44,6 @@ | |||
44 | #define S5P_DAC_PHY_CONTROL S5P_PMUREG(0x070C) | 44 | #define S5P_DAC_PHY_CONTROL S5P_PMUREG(0x070C) |
45 | #define S5P_DAC_PHY_ENABLE (1 << 0) | 45 | #define S5P_DAC_PHY_ENABLE (1 << 0) |
46 | 46 | ||
47 | #define S5P_MIPI_DPHY_CONTROL(n) S5P_PMUREG(0x0710 + (n) * 4) | ||
48 | #define S5P_MIPI_DPHY_ENABLE (1 << 0) | ||
49 | #define S5P_MIPI_DPHY_SRESETN (1 << 1) | ||
50 | #define S5P_MIPI_DPHY_MRESETN (1 << 2) | ||
51 | |||
52 | #define S5P_INFORM0 S5P_PMUREG(0x0800) | 47 | #define S5P_INFORM0 S5P_PMUREG(0x0800) |
53 | #define S5P_INFORM1 S5P_PMUREG(0x0804) | 48 | #define S5P_INFORM1 S5P_PMUREG(0x0804) |
54 | #define S5P_INFORM2 S5P_PMUREG(0x0808) | 49 | #define S5P_INFORM2 S5P_PMUREG(0x0808) |
diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c index f26918467efc..8b9cd0690ce7 100644 --- a/arch/arm/mach-omap2/board-omap3beagle.c +++ b/arch/arm/mach-omap2/board-omap3beagle.c | |||
@@ -289,18 +289,12 @@ static struct regulator_consumer_supply beagle_vsim_supply[] = { | |||
289 | 289 | ||
290 | static struct gpio_led gpio_leds[]; | 290 | static struct gpio_led gpio_leds[]; |
291 | 291 | ||
292 | /* PHY's VCC regulator might be added later, so flag that we need it */ | ||
293 | static struct usb_phy_gen_xceiv_platform_data hsusb2_phy_data = { | ||
294 | .needs_vcc = true, | ||
295 | }; | ||
296 | |||
297 | static struct usbhs_phy_data phy_data[] = { | 292 | static struct usbhs_phy_data phy_data[] = { |
298 | { | 293 | { |
299 | .port = 2, | 294 | .port = 2, |
300 | .reset_gpio = 147, | 295 | .reset_gpio = 147, |
301 | .vcc_gpio = -1, /* updated in beagle_twl_gpio_setup */ | 296 | .vcc_gpio = -1, /* updated in beagle_twl_gpio_setup */ |
302 | .vcc_polarity = 1, /* updated in beagle_twl_gpio_setup */ | 297 | .vcc_polarity = 1, /* updated in beagle_twl_gpio_setup */ |
303 | .platform_data = &hsusb2_phy_data, | ||
304 | }, | 298 | }, |
305 | }; | 299 | }; |
306 | 300 | ||
diff --git a/arch/arm/mach-omap2/twl-common.c b/arch/arm/mach-omap2/twl-common.c index c05898fbd634..b0d54dae1bcb 100644 --- a/arch/arm/mach-omap2/twl-common.c +++ b/arch/arm/mach-omap2/twl-common.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/i2c/twl.h> | 24 | #include <linux/i2c/twl.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/string.h> | 26 | #include <linux/string.h> |
27 | #include <linux/phy/phy.h> | ||
27 | #include <linux/regulator/machine.h> | 28 | #include <linux/regulator/machine.h> |
28 | #include <linux/regulator/fixed.h> | 29 | #include <linux/regulator/fixed.h> |
29 | 30 | ||
@@ -90,8 +91,18 @@ void __init omap_pmic_late_init(void) | |||
90 | } | 91 | } |
91 | 92 | ||
92 | #if defined(CONFIG_ARCH_OMAP3) | 93 | #if defined(CONFIG_ARCH_OMAP3) |
94 | struct phy_consumer consumers[] = { | ||
95 | PHY_CONSUMER("musb-hdrc.0", "usb"), | ||
96 | }; | ||
97 | |||
98 | struct phy_init_data init_data = { | ||
99 | .consumers = consumers, | ||
100 | .num_consumers = ARRAY_SIZE(consumers), | ||
101 | }; | ||
102 | |||
93 | static struct twl4030_usb_data omap3_usb_pdata = { | 103 | static struct twl4030_usb_data omap3_usb_pdata = { |
94 | .usb_mode = T2_USB_MODE_ULPI, | 104 | .usb_mode = T2_USB_MODE_ULPI, |
105 | .init_data = &init_data, | ||
95 | }; | 106 | }; |
96 | 107 | ||
97 | static int omap3_batt_table[] = { | 108 | static int omap3_batt_table[] = { |
diff --git a/arch/arm/mach-omap2/usb-host.c b/arch/arm/mach-omap2/usb-host.c index e83a6a4b184a..10855eb4ccc1 100644 --- a/arch/arm/mach-omap2/usb-host.c +++ b/arch/arm/mach-omap2/usb-host.c | |||
@@ -435,6 +435,7 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys) | |||
435 | struct platform_device *pdev; | 435 | struct platform_device *pdev; |
436 | char *phy_id; | 436 | char *phy_id; |
437 | struct platform_device_info pdevinfo; | 437 | struct platform_device_info pdevinfo; |
438 | struct usb_phy_gen_xceiv_platform_data nop_pdata; | ||
438 | 439 | ||
439 | for (i = 0; i < num_phys; i++) { | 440 | for (i = 0; i < num_phys; i++) { |
440 | 441 | ||
@@ -455,11 +456,18 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys) | |||
455 | return -ENOMEM; | 456 | return -ENOMEM; |
456 | } | 457 | } |
457 | 458 | ||
459 | /* set platform data */ | ||
460 | memset(&nop_pdata, 0, sizeof(nop_pdata)); | ||
461 | if (gpio_is_valid(phy->vcc_gpio)) | ||
462 | nop_pdata.needs_vcc = true; | ||
463 | nop_pdata.gpio_reset = phy->reset_gpio; | ||
464 | nop_pdata.type = USB_PHY_TYPE_USB2; | ||
465 | |||
458 | /* create a NOP PHY device */ | 466 | /* create a NOP PHY device */ |
459 | memset(&pdevinfo, 0, sizeof(pdevinfo)); | 467 | memset(&pdevinfo, 0, sizeof(pdevinfo)); |
460 | pdevinfo.name = nop_name; | 468 | pdevinfo.name = nop_name; |
461 | pdevinfo.id = phy->port; | 469 | pdevinfo.id = phy->port; |
462 | pdevinfo.data = phy->platform_data; | 470 | pdevinfo.data = &nop_pdata; |
463 | pdevinfo.size_data = | 471 | pdevinfo.size_data = |
464 | sizeof(struct usb_phy_gen_xceiv_platform_data); | 472 | sizeof(struct usb_phy_gen_xceiv_platform_data); |
465 | scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d", | 473 | scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d", |
@@ -474,14 +482,6 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys) | |||
474 | 482 | ||
475 | usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id); | 483 | usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id); |
476 | 484 | ||
477 | /* Do we need RESET regulator ? */ | ||
478 | if (gpio_is_valid(phy->reset_gpio)) { | ||
479 | scnprintf(rail_name, MAX_STR, | ||
480 | "hsusb%d_reset", phy->port); | ||
481 | usbhs_add_regulator(rail_name, phy_id, "reset", | ||
482 | phy->reset_gpio, 1); | ||
483 | } | ||
484 | |||
485 | /* Do we need VCC regulator ? */ | 485 | /* Do we need VCC regulator ? */ |
486 | if (gpio_is_valid(phy->vcc_gpio)) { | 486 | if (gpio_is_valid(phy->vcc_gpio)) { |
487 | scnprintf(rail_name, MAX_STR, "hsusb%d_vcc", phy->port); | 487 | scnprintf(rail_name, MAX_STR, "hsusb%d_vcc", phy->port); |
diff --git a/arch/arm/mach-omap2/usb.h b/arch/arm/mach-omap2/usb.h index e7261ebcf7b0..4ba2ae759895 100644 --- a/arch/arm/mach-omap2/usb.h +++ b/arch/arm/mach-omap2/usb.h | |||
@@ -58,7 +58,6 @@ struct usbhs_phy_data { | |||
58 | int reset_gpio; | 58 | int reset_gpio; |
59 | int vcc_gpio; | 59 | int vcc_gpio; |
60 | bool vcc_polarity; /* 1 active high, 0 active low */ | 60 | bool vcc_polarity; /* 1 active high, 0 active low */ |
61 | void *platform_data; | ||
62 | }; | 61 | }; |
63 | 62 | ||
64 | extern void usb_musb_init(struct omap_musb_board_data *board_data); | 63 | extern void usb_musb_init(struct omap_musb_board_data *board_data); |
diff --git a/arch/arm/mach-s5pv210/include/mach/regs-clock.h b/arch/arm/mach-s5pv210/include/mach/regs-clock.h index 032de66fb8be..e345584d4c34 100644 --- a/arch/arm/mach-s5pv210/include/mach/regs-clock.h +++ b/arch/arm/mach-s5pv210/include/mach/regs-clock.h | |||
@@ -147,10 +147,6 @@ | |||
147 | #define S5P_HDMI_PHY_CONTROL S5P_CLKREG(0xE804) | 147 | #define S5P_HDMI_PHY_CONTROL S5P_CLKREG(0xE804) |
148 | #define S5P_USB_PHY_CONTROL S5P_CLKREG(0xE80C) | 148 | #define S5P_USB_PHY_CONTROL S5P_CLKREG(0xE80C) |
149 | #define S5P_DAC_PHY_CONTROL S5P_CLKREG(0xE810) | 149 | #define S5P_DAC_PHY_CONTROL S5P_CLKREG(0xE810) |
150 | #define S5P_MIPI_DPHY_CONTROL(x) S5P_CLKREG(0xE814) | ||
151 | #define S5P_MIPI_DPHY_ENABLE (1 << 0) | ||
152 | #define S5P_MIPI_DPHY_SRESETN (1 << 1) | ||
153 | #define S5P_MIPI_DPHY_MRESETN (1 << 2) | ||
154 | 150 | ||
155 | #define S5P_INFORM0 S5P_CLKREG(0xF000) | 151 | #define S5P_INFORM0 S5P_CLKREG(0xF000) |
156 | #define S5P_INFORM1 S5P_CLKREG(0xF004) | 152 | #define S5P_INFORM1 S5P_CLKREG(0xF004) |
diff --git a/arch/arm/plat-samsung/Kconfig b/arch/arm/plat-samsung/Kconfig index 7dfba937d8fc..6d95d60276d6 100644 --- a/arch/arm/plat-samsung/Kconfig +++ b/arch/arm/plat-samsung/Kconfig | |||
@@ -382,11 +382,6 @@ config S5P_DEV_TV | |||
382 | help | 382 | help |
383 | Compile in platform device definition for TV interface | 383 | Compile in platform device definition for TV interface |
384 | 384 | ||
385 | config S5P_DEV_USB_EHCI | ||
386 | bool | ||
387 | help | ||
388 | Compile in platform device definition for USB EHCI | ||
389 | |||
390 | config S3C24XX_PWM | 385 | config S3C24XX_PWM |
391 | bool "PWM device support" | 386 | bool "PWM device support" |
392 | select PWM | 387 | select PWM |
@@ -395,11 +390,6 @@ config S3C24XX_PWM | |||
395 | Support for exporting the PWM timer blocks via the pwm device | 390 | Support for exporting the PWM timer blocks via the pwm device |
396 | system | 391 | system |
397 | 392 | ||
398 | config S5P_SETUP_MIPIPHY | ||
399 | bool | ||
400 | help | ||
401 | Compile in common setup code for MIPI-CSIS and MIPI-DSIM devices | ||
402 | |||
403 | config S3C_SETUP_CAMIF | 393 | config S3C_SETUP_CAMIF |
404 | bool | 394 | bool |
405 | help | 395 | help |
diff --git a/arch/arm/plat-samsung/Makefile b/arch/arm/plat-samsung/Makefile index 498c7c23e9f4..9267d29549b4 100644 --- a/arch/arm/plat-samsung/Makefile +++ b/arch/arm/plat-samsung/Makefile | |||
@@ -38,7 +38,6 @@ obj-$(CONFIG_S5P_DEV_UART) += s5p-dev-uart.o | |||
38 | obj-$(CONFIG_SAMSUNG_DEV_BACKLIGHT) += dev-backlight.o | 38 | obj-$(CONFIG_SAMSUNG_DEV_BACKLIGHT) += dev-backlight.o |
39 | 39 | ||
40 | obj-$(CONFIG_S3C_SETUP_CAMIF) += setup-camif.o | 40 | obj-$(CONFIG_S3C_SETUP_CAMIF) += setup-camif.o |
41 | obj-$(CONFIG_S5P_SETUP_MIPIPHY) += setup-mipiphy.o | ||
42 | 41 | ||
43 | # DMA support | 42 | # DMA support |
44 | 43 | ||
diff --git a/arch/arm/plat-samsung/devs.c b/arch/arm/plat-samsung/devs.c index 8ce0ac007eb9..25f40c9b7f62 100644 --- a/arch/arm/plat-samsung/devs.c +++ b/arch/arm/plat-samsung/devs.c | |||
@@ -49,7 +49,6 @@ | |||
49 | #include <plat/devs.h> | 49 | #include <plat/devs.h> |
50 | #include <plat/adc.h> | 50 | #include <plat/adc.h> |
51 | #include <linux/platform_data/ata-samsung_cf.h> | 51 | #include <linux/platform_data/ata-samsung_cf.h> |
52 | #include <linux/platform_data/usb-ehci-s5p.h> | ||
53 | #include <plat/fb.h> | 52 | #include <plat/fb.h> |
54 | #include <plat/fb-s3c2410.h> | 53 | #include <plat/fb-s3c2410.h> |
55 | #include <plat/hdmi.h> | 54 | #include <plat/hdmi.h> |
@@ -1359,39 +1358,6 @@ void __init s3c24xx_udc_set_platdata(struct s3c2410_udc_mach_info *pd) | |||
1359 | } | 1358 | } |
1360 | #endif /* CONFIG_PLAT_S3C24XX */ | 1359 | #endif /* CONFIG_PLAT_S3C24XX */ |
1361 | 1360 | ||
1362 | /* USB EHCI Host Controller */ | ||
1363 | |||
1364 | #ifdef CONFIG_S5P_DEV_USB_EHCI | ||
1365 | static struct resource s5p_ehci_resource[] = { | ||
1366 | [0] = DEFINE_RES_MEM(S5P_PA_EHCI, SZ_256), | ||
1367 | [1] = DEFINE_RES_IRQ(IRQ_USB_HOST), | ||
1368 | }; | ||
1369 | |||
1370 | struct platform_device s5p_device_ehci = { | ||
1371 | .name = "s5p-ehci", | ||
1372 | .id = -1, | ||
1373 | .num_resources = ARRAY_SIZE(s5p_ehci_resource), | ||
1374 | .resource = s5p_ehci_resource, | ||
1375 | .dev = { | ||
1376 | .dma_mask = &samsung_device_dma_mask, | ||
1377 | .coherent_dma_mask = DMA_BIT_MASK(32), | ||
1378 | } | ||
1379 | }; | ||
1380 | |||
1381 | void __init s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd) | ||
1382 | { | ||
1383 | struct s5p_ehci_platdata *npd; | ||
1384 | |||
1385 | npd = s3c_set_platdata(pd, sizeof(struct s5p_ehci_platdata), | ||
1386 | &s5p_device_ehci); | ||
1387 | |||
1388 | if (!npd->phy_init) | ||
1389 | npd->phy_init = s5p_usb_phy_init; | ||
1390 | if (!npd->phy_exit) | ||
1391 | npd->phy_exit = s5p_usb_phy_exit; | ||
1392 | } | ||
1393 | #endif /* CONFIG_S5P_DEV_USB_EHCI */ | ||
1394 | |||
1395 | /* USB HSOTG */ | 1361 | /* USB HSOTG */ |
1396 | 1362 | ||
1397 | #ifdef CONFIG_S3C_DEV_USB_HSOTG | 1363 | #ifdef CONFIG_S3C_DEV_USB_HSOTG |
diff --git a/arch/arm/plat-samsung/include/plat/devs.h b/arch/arm/plat-samsung/include/plat/devs.h index 0dc4ac4909b0..eece188ed188 100644 --- a/arch/arm/plat-samsung/include/plat/devs.h +++ b/arch/arm/plat-samsung/include/plat/devs.h | |||
@@ -75,7 +75,6 @@ extern struct platform_device s3c_device_usb_hsotg; | |||
75 | extern struct platform_device s3c_device_usb_hsudc; | 75 | extern struct platform_device s3c_device_usb_hsudc; |
76 | extern struct platform_device s3c_device_wdt; | 76 | extern struct platform_device s3c_device_wdt; |
77 | 77 | ||
78 | extern struct platform_device s5p_device_ehci; | ||
79 | extern struct platform_device s5p_device_fimc0; | 78 | extern struct platform_device s5p_device_fimc0; |
80 | extern struct platform_device s5p_device_fimc1; | 79 | extern struct platform_device s5p_device_fimc1; |
81 | extern struct platform_device s5p_device_fimc2; | 80 | extern struct platform_device s5p_device_fimc2; |
diff --git a/arch/arm/plat-samsung/setup-mipiphy.c b/arch/arm/plat-samsung/setup-mipiphy.c deleted file mode 100644 index 66df315990a7..000000000000 --- a/arch/arm/plat-samsung/setup-mipiphy.c +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Samsung Electronics Co., Ltd. | ||
3 | * | ||
4 | * S5P - Helper functions for MIPI-CSIS and MIPI-DSIM D-PHY control | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <linux/export.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | #include <mach/regs-clock.h> | ||
17 | |||
18 | static int __s5p_mipi_phy_control(int id, bool on, u32 reset) | ||
19 | { | ||
20 | static DEFINE_SPINLOCK(lock); | ||
21 | void __iomem *addr; | ||
22 | unsigned long flags; | ||
23 | u32 cfg; | ||
24 | |||
25 | id = max(0, id); | ||
26 | if (id > 1) | ||
27 | return -EINVAL; | ||
28 | |||
29 | addr = S5P_MIPI_DPHY_CONTROL(id); | ||
30 | |||
31 | spin_lock_irqsave(&lock, flags); | ||
32 | |||
33 | cfg = __raw_readl(addr); | ||
34 | cfg = on ? (cfg | reset) : (cfg & ~reset); | ||
35 | __raw_writel(cfg, addr); | ||
36 | |||
37 | if (on) { | ||
38 | cfg |= S5P_MIPI_DPHY_ENABLE; | ||
39 | } else if (!(cfg & (S5P_MIPI_DPHY_SRESETN | | ||
40 | S5P_MIPI_DPHY_MRESETN) & ~reset)) { | ||
41 | cfg &= ~S5P_MIPI_DPHY_ENABLE; | ||
42 | } | ||
43 | |||
44 | __raw_writel(cfg, addr); | ||
45 | spin_unlock_irqrestore(&lock, flags); | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | int s5p_csis_phy_enable(int id, bool on) | ||
51 | { | ||
52 | return __s5p_mipi_phy_control(id, on, S5P_MIPI_DPHY_SRESETN); | ||
53 | } | ||
54 | EXPORT_SYMBOL(s5p_csis_phy_enable); | ||
55 | |||
56 | int s5p_dsim_phy_enable(struct platform_device *pdev, bool on) | ||
57 | { | ||
58 | return __s5p_mipi_phy_control(pdev->id, on, S5P_MIPI_DPHY_MRESETN); | ||
59 | } | ||
60 | EXPORT_SYMBOL(s5p_dsim_phy_enable); | ||
diff --git a/drivers/Kconfig b/drivers/Kconfig index aa43b911ccef..8f451449abd3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig | |||
@@ -166,4 +166,6 @@ source "drivers/reset/Kconfig" | |||
166 | 166 | ||
167 | source "drivers/fmc/Kconfig" | 167 | source "drivers/fmc/Kconfig" |
168 | 168 | ||
169 | source "drivers/phy/Kconfig" | ||
170 | |||
169 | endmenu | 171 | endmenu |
diff --git a/drivers/Makefile b/drivers/Makefile index ab93de8297f1..687da899cadb 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
@@ -8,6 +8,8 @@ | |||
8 | obj-y += irqchip/ | 8 | obj-y += irqchip/ |
9 | obj-y += bus/ | 9 | obj-y += bus/ |
10 | 10 | ||
11 | obj-$(CONFIG_GENERIC_PHY) += phy/ | ||
12 | |||
11 | # GPIO must come after pinctrl as gpios may need to mux pins etc | 13 | # GPIO must come after pinctrl as gpios may need to mux pins etc |
12 | obj-y += pinctrl/ | 14 | obj-y += pinctrl/ |
13 | obj-y += gpio/ | 15 | obj-y += gpio/ |
diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig index 53ad0f080179..d2d3b4b61435 100644 --- a/drivers/media/platform/exynos4-is/Kconfig +++ b/drivers/media/platform/exynos4-is/Kconfig | |||
@@ -29,7 +29,7 @@ config VIDEO_S5P_FIMC | |||
29 | config VIDEO_S5P_MIPI_CSIS | 29 | config VIDEO_S5P_MIPI_CSIS |
30 | tristate "S5P/EXYNOS MIPI-CSI2 receiver (MIPI-CSIS) driver" | 30 | tristate "S5P/EXYNOS MIPI-CSI2 receiver (MIPI-CSIS) driver" |
31 | depends on REGULATOR | 31 | depends on REGULATOR |
32 | select S5P_SETUP_MIPIPHY | 32 | select GENERIC_PHY |
33 | help | 33 | help |
34 | This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC MIPI-CSI2 | 34 | This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC MIPI-CSI2 |
35 | receiver (MIPI-CSIS) devices. | 35 | receiver (MIPI-CSIS) devices. |
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c index 0914230b42de..9fc2af6a0446 100644 --- a/drivers/media/platform/exynos4-is/mipi-csis.c +++ b/drivers/media/platform/exynos4-is/mipi-csis.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/memory.h> | 20 | #include <linux/memory.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/of.h> | 22 | #include <linux/of.h> |
23 | #include <linux/phy/phy.h> | ||
23 | #include <linux/platform_data/mipi-csis.h> | 24 | #include <linux/platform_data/mipi-csis.h> |
24 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
25 | #include <linux/pm_runtime.h> | 26 | #include <linux/pm_runtime.h> |
@@ -180,6 +181,7 @@ struct csis_drvdata { | |||
180 | * @sd: v4l2_subdev associated with CSIS device instance | 181 | * @sd: v4l2_subdev associated with CSIS device instance |
181 | * @index: the hardware instance index | 182 | * @index: the hardware instance index |
182 | * @pdev: CSIS platform device | 183 | * @pdev: CSIS platform device |
184 | * @phy: pointer to the CSIS generic PHY | ||
183 | * @regs: mmaped I/O registers memory | 185 | * @regs: mmaped I/O registers memory |
184 | * @supplies: CSIS regulator supplies | 186 | * @supplies: CSIS regulator supplies |
185 | * @clock: CSIS clocks | 187 | * @clock: CSIS clocks |
@@ -203,6 +205,7 @@ struct csis_state { | |||
203 | struct v4l2_subdev sd; | 205 | struct v4l2_subdev sd; |
204 | u8 index; | 206 | u8 index; |
205 | struct platform_device *pdev; | 207 | struct platform_device *pdev; |
208 | struct phy *phy; | ||
206 | void __iomem *regs; | 209 | void __iomem *regs; |
207 | struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES]; | 210 | struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES]; |
208 | struct clk *clock[NUM_CSIS_CLOCKS]; | 211 | struct clk *clock[NUM_CSIS_CLOCKS]; |
@@ -779,8 +782,8 @@ static int s5pcsis_parse_dt(struct platform_device *pdev, | |||
779 | "samsung,csis-wclk"); | 782 | "samsung,csis-wclk"); |
780 | 783 | ||
781 | state->num_lanes = endpoint.bus.mipi_csi2.num_data_lanes; | 784 | state->num_lanes = endpoint.bus.mipi_csi2.num_data_lanes; |
782 | |||
783 | of_node_put(node); | 785 | of_node_put(node); |
786 | |||
784 | return 0; | 787 | return 0; |
785 | } | 788 | } |
786 | #else | 789 | #else |
@@ -829,6 +832,10 @@ static int s5pcsis_probe(struct platform_device *pdev) | |||
829 | return -EINVAL; | 832 | return -EINVAL; |
830 | } | 833 | } |
831 | 834 | ||
835 | state->phy = devm_phy_get(dev, "csis"); | ||
836 | if (IS_ERR(state->phy)) | ||
837 | return PTR_ERR(state->phy); | ||
838 | |||
832 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 839 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
833 | state->regs = devm_ioremap_resource(dev, mem_res); | 840 | state->regs = devm_ioremap_resource(dev, mem_res); |
834 | if (IS_ERR(state->regs)) | 841 | if (IS_ERR(state->regs)) |
@@ -922,7 +929,7 @@ static int s5pcsis_pm_suspend(struct device *dev, bool runtime) | |||
922 | mutex_lock(&state->lock); | 929 | mutex_lock(&state->lock); |
923 | if (state->flags & ST_POWERED) { | 930 | if (state->flags & ST_POWERED) { |
924 | s5pcsis_stop_stream(state); | 931 | s5pcsis_stop_stream(state); |
925 | ret = s5p_csis_phy_enable(state->index, false); | 932 | ret = phy_power_off(state->phy); |
926 | if (ret) | 933 | if (ret) |
927 | goto unlock; | 934 | goto unlock; |
928 | ret = regulator_bulk_disable(CSIS_NUM_SUPPLIES, | 935 | ret = regulator_bulk_disable(CSIS_NUM_SUPPLIES, |
@@ -958,7 +965,7 @@ static int s5pcsis_pm_resume(struct device *dev, bool runtime) | |||
958 | state->supplies); | 965 | state->supplies); |
959 | if (ret) | 966 | if (ret) |
960 | goto unlock; | 967 | goto unlock; |
961 | ret = s5p_csis_phy_enable(state->index, true); | 968 | ret = phy_power_on(state->phy); |
962 | if (!ret) { | 969 | if (!ret) { |
963 | state->flags |= ST_POWERED; | 970 | state->flags |= ST_POWERED; |
964 | } else { | 971 | } else { |
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig new file mode 100644 index 000000000000..a344f3d52361 --- /dev/null +++ b/drivers/phy/Kconfig | |||
@@ -0,0 +1,54 @@ | |||
1 | # | ||
2 | # PHY | ||
3 | # | ||
4 | |||
5 | menu "PHY Subsystem" | ||
6 | |||
7 | config GENERIC_PHY | ||
8 | tristate "PHY Core" | ||
9 | help | ||
10 | Generic PHY support. | ||
11 | |||
12 | This framework is designed to provide a generic interface for PHY | ||
13 | devices present in the kernel. This layer will have the generic | ||
14 | API by which phy drivers can create PHY using the phy framework and | ||
15 | phy users can obtain reference to the PHY. All the users of this | ||
16 | framework should select this config. | ||
17 | |||
18 | config PHY_EXYNOS_MIPI_VIDEO | ||
19 | tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver" | ||
20 | help | ||
21 | Support for MIPI CSI-2 and MIPI DSI DPHY found on Samsung S5P | ||
22 | and EXYNOS SoCs. | ||
23 | |||
24 | config OMAP_USB2 | ||
25 | tristate "OMAP USB2 PHY Driver" | ||
26 | depends on ARCH_OMAP2PLUS | ||
27 | select GENERIC_PHY | ||
28 | select USB_PHY | ||
29 | select OMAP_CONTROL_USB | ||
30 | help | ||
31 | Enable this to support the transceiver that is part of SOC. This | ||
32 | driver takes care of all the PHY functionality apart from comparator. | ||
33 | The USB OTG controller communicates with the comparator using this | ||
34 | driver. | ||
35 | |||
36 | config TWL4030_USB | ||
37 | tristate "TWL4030 USB Transceiver Driver" | ||
38 | depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS | ||
39 | select GENERIC_PHY | ||
40 | select USB_PHY | ||
41 | help | ||
42 | Enable this to support the USB OTG transceiver on TWL4030 | ||
43 | family chips (including the TWL5030 and TPS659x0 devices). | ||
44 | This transceiver supports high and full speed devices plus, | ||
45 | in host mode, low speed. | ||
46 | |||
47 | config PHY_EXYNOS_DP_VIDEO | ||
48 | tristate "EXYNOS SoC series Display Port PHY driver" | ||
49 | depends on OF | ||
50 | select GENERIC_PHY | ||
51 | help | ||
52 | Support for Display Port PHY found on Samsung EXYNOS SoCs. | ||
53 | |||
54 | endmenu | ||
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile new file mode 100644 index 000000000000..d0caae9cfb83 --- /dev/null +++ b/drivers/phy/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # | ||
2 | # Makefile for the phy drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_GENERIC_PHY) += phy-core.o | ||
6 | obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o | ||
7 | obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o | ||
8 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o | ||
9 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o | ||
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c new file mode 100644 index 000000000000..03cf8fb81554 --- /dev/null +++ b/drivers/phy/phy-core.c | |||
@@ -0,0 +1,698 @@ | |||
1 | /* | ||
2 | * phy-core.c -- Generic Phy framework. | ||
3 | * | ||
4 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * | ||
6 | * Author: Kishon Vijay Abraham I <kishon@ti.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/export.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/err.h> | ||
18 | #include <linux/device.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/phy/phy.h> | ||
22 | #include <linux/idr.h> | ||
23 | #include <linux/pm_runtime.h> | ||
24 | |||
25 | static struct class *phy_class; | ||
26 | static DEFINE_MUTEX(phy_provider_mutex); | ||
27 | static LIST_HEAD(phy_provider_list); | ||
28 | static DEFINE_IDA(phy_ida); | ||
29 | |||
30 | static void devm_phy_release(struct device *dev, void *res) | ||
31 | { | ||
32 | struct phy *phy = *(struct phy **)res; | ||
33 | |||
34 | phy_put(phy); | ||
35 | } | ||
36 | |||
37 | static void devm_phy_provider_release(struct device *dev, void *res) | ||
38 | { | ||
39 | struct phy_provider *phy_provider = *(struct phy_provider **)res; | ||
40 | |||
41 | of_phy_provider_unregister(phy_provider); | ||
42 | } | ||
43 | |||
44 | static void devm_phy_consume(struct device *dev, void *res) | ||
45 | { | ||
46 | struct phy *phy = *(struct phy **)res; | ||
47 | |||
48 | phy_destroy(phy); | ||
49 | } | ||
50 | |||
51 | static int devm_phy_match(struct device *dev, void *res, void *match_data) | ||
52 | { | ||
53 | return res == match_data; | ||
54 | } | ||
55 | |||
56 | static struct phy *phy_lookup(struct device *device, const char *port) | ||
57 | { | ||
58 | unsigned int count; | ||
59 | struct phy *phy; | ||
60 | struct device *dev; | ||
61 | struct phy_consumer *consumers; | ||
62 | struct class_dev_iter iter; | ||
63 | |||
64 | class_dev_iter_init(&iter, phy_class, NULL, NULL); | ||
65 | while ((dev = class_dev_iter_next(&iter))) { | ||
66 | phy = to_phy(dev); | ||
67 | count = phy->init_data->num_consumers; | ||
68 | consumers = phy->init_data->consumers; | ||
69 | while (count--) { | ||
70 | if (!strcmp(consumers->dev_name, dev_name(device)) && | ||
71 | !strcmp(consumers->port, port)) { | ||
72 | class_dev_iter_exit(&iter); | ||
73 | return phy; | ||
74 | } | ||
75 | consumers++; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | class_dev_iter_exit(&iter); | ||
80 | return ERR_PTR(-ENODEV); | ||
81 | } | ||
82 | |||
83 | static struct phy_provider *of_phy_provider_lookup(struct device_node *node) | ||
84 | { | ||
85 | struct phy_provider *phy_provider; | ||
86 | |||
87 | list_for_each_entry(phy_provider, &phy_provider_list, list) { | ||
88 | if (phy_provider->dev->of_node == node) | ||
89 | return phy_provider; | ||
90 | } | ||
91 | |||
92 | return ERR_PTR(-EPROBE_DEFER); | ||
93 | } | ||
94 | |||
95 | int phy_pm_runtime_get(struct phy *phy) | ||
96 | { | ||
97 | if (!pm_runtime_enabled(&phy->dev)) | ||
98 | return -ENOTSUPP; | ||
99 | |||
100 | return pm_runtime_get(&phy->dev); | ||
101 | } | ||
102 | EXPORT_SYMBOL_GPL(phy_pm_runtime_get); | ||
103 | |||
104 | int phy_pm_runtime_get_sync(struct phy *phy) | ||
105 | { | ||
106 | if (!pm_runtime_enabled(&phy->dev)) | ||
107 | return -ENOTSUPP; | ||
108 | |||
109 | return pm_runtime_get_sync(&phy->dev); | ||
110 | } | ||
111 | EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync); | ||
112 | |||
113 | int phy_pm_runtime_put(struct phy *phy) | ||
114 | { | ||
115 | if (!pm_runtime_enabled(&phy->dev)) | ||
116 | return -ENOTSUPP; | ||
117 | |||
118 | return pm_runtime_put(&phy->dev); | ||
119 | } | ||
120 | EXPORT_SYMBOL_GPL(phy_pm_runtime_put); | ||
121 | |||
122 | int phy_pm_runtime_put_sync(struct phy *phy) | ||
123 | { | ||
124 | if (!pm_runtime_enabled(&phy->dev)) | ||
125 | return -ENOTSUPP; | ||
126 | |||
127 | return pm_runtime_put_sync(&phy->dev); | ||
128 | } | ||
129 | EXPORT_SYMBOL_GPL(phy_pm_runtime_put_sync); | ||
130 | |||
131 | void phy_pm_runtime_allow(struct phy *phy) | ||
132 | { | ||
133 | if (!pm_runtime_enabled(&phy->dev)) | ||
134 | return; | ||
135 | |||
136 | pm_runtime_allow(&phy->dev); | ||
137 | } | ||
138 | EXPORT_SYMBOL_GPL(phy_pm_runtime_allow); | ||
139 | |||
140 | void phy_pm_runtime_forbid(struct phy *phy) | ||
141 | { | ||
142 | if (!pm_runtime_enabled(&phy->dev)) | ||
143 | return; | ||
144 | |||
145 | pm_runtime_forbid(&phy->dev); | ||
146 | } | ||
147 | EXPORT_SYMBOL_GPL(phy_pm_runtime_forbid); | ||
148 | |||
149 | int phy_init(struct phy *phy) | ||
150 | { | ||
151 | int ret; | ||
152 | |||
153 | ret = phy_pm_runtime_get_sync(phy); | ||
154 | if (ret < 0 && ret != -ENOTSUPP) | ||
155 | return ret; | ||
156 | |||
157 | mutex_lock(&phy->mutex); | ||
158 | if (phy->init_count++ == 0 && phy->ops->init) { | ||
159 | ret = phy->ops->init(phy); | ||
160 | if (ret < 0) { | ||
161 | dev_err(&phy->dev, "phy init failed --> %d\n", ret); | ||
162 | goto out; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | out: | ||
167 | mutex_unlock(&phy->mutex); | ||
168 | phy_pm_runtime_put(phy); | ||
169 | return ret; | ||
170 | } | ||
171 | EXPORT_SYMBOL_GPL(phy_init); | ||
172 | |||
173 | int phy_exit(struct phy *phy) | ||
174 | { | ||
175 | int ret; | ||
176 | |||
177 | ret = phy_pm_runtime_get_sync(phy); | ||
178 | if (ret < 0 && ret != -ENOTSUPP) | ||
179 | return ret; | ||
180 | |||
181 | mutex_lock(&phy->mutex); | ||
182 | if (--phy->init_count == 0 && phy->ops->exit) { | ||
183 | ret = phy->ops->exit(phy); | ||
184 | if (ret < 0) { | ||
185 | dev_err(&phy->dev, "phy exit failed --> %d\n", ret); | ||
186 | goto out; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | out: | ||
191 | mutex_unlock(&phy->mutex); | ||
192 | phy_pm_runtime_put(phy); | ||
193 | return ret; | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(phy_exit); | ||
196 | |||
197 | int phy_power_on(struct phy *phy) | ||
198 | { | ||
199 | int ret = -ENOTSUPP; | ||
200 | |||
201 | ret = phy_pm_runtime_get_sync(phy); | ||
202 | if (ret < 0 && ret != -ENOTSUPP) | ||
203 | return ret; | ||
204 | |||
205 | mutex_lock(&phy->mutex); | ||
206 | if (phy->power_count++ == 0 && phy->ops->power_on) { | ||
207 | ret = phy->ops->power_on(phy); | ||
208 | if (ret < 0) { | ||
209 | dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); | ||
210 | goto out; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | out: | ||
215 | mutex_unlock(&phy->mutex); | ||
216 | |||
217 | return ret; | ||
218 | } | ||
219 | EXPORT_SYMBOL_GPL(phy_power_on); | ||
220 | |||
221 | int phy_power_off(struct phy *phy) | ||
222 | { | ||
223 | int ret = -ENOTSUPP; | ||
224 | |||
225 | mutex_lock(&phy->mutex); | ||
226 | if (--phy->power_count == 0 && phy->ops->power_off) { | ||
227 | ret = phy->ops->power_off(phy); | ||
228 | if (ret < 0) { | ||
229 | dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); | ||
230 | goto out; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | out: | ||
235 | mutex_unlock(&phy->mutex); | ||
236 | phy_pm_runtime_put(phy); | ||
237 | |||
238 | return ret; | ||
239 | } | ||
240 | EXPORT_SYMBOL_GPL(phy_power_off); | ||
241 | |||
242 | /** | ||
243 | * of_phy_get() - lookup and obtain a reference to a phy by phandle | ||
244 | * @dev: device that requests this phy | ||
245 | * @index: the index of the phy | ||
246 | * | ||
247 | * Returns the phy associated with the given phandle value, | ||
248 | * after getting a refcount to it or -ENODEV if there is no such phy or | ||
249 | * -EPROBE_DEFER if there is a phandle to the phy, but the device is | ||
250 | * not yet loaded. This function uses of_xlate call back function provided | ||
251 | * while registering the phy_provider to find the phy instance. | ||
252 | */ | ||
253 | static struct phy *of_phy_get(struct device *dev, int index) | ||
254 | { | ||
255 | int ret; | ||
256 | struct phy_provider *phy_provider; | ||
257 | struct phy *phy = NULL; | ||
258 | struct of_phandle_args args; | ||
259 | |||
260 | ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells", | ||
261 | index, &args); | ||
262 | if (ret) { | ||
263 | dev_dbg(dev, "failed to get phy in %s node\n", | ||
264 | dev->of_node->full_name); | ||
265 | return ERR_PTR(-ENODEV); | ||
266 | } | ||
267 | |||
268 | mutex_lock(&phy_provider_mutex); | ||
269 | phy_provider = of_phy_provider_lookup(args.np); | ||
270 | if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { | ||
271 | phy = ERR_PTR(-EPROBE_DEFER); | ||
272 | goto err0; | ||
273 | } | ||
274 | |||
275 | phy = phy_provider->of_xlate(phy_provider->dev, &args); | ||
276 | module_put(phy_provider->owner); | ||
277 | |||
278 | err0: | ||
279 | mutex_unlock(&phy_provider_mutex); | ||
280 | of_node_put(args.np); | ||
281 | |||
282 | return phy; | ||
283 | } | ||
284 | |||
285 | /** | ||
286 | * phy_put() - release the PHY | ||
287 | * @phy: the phy returned by phy_get() | ||
288 | * | ||
289 | * Releases a refcount the caller received from phy_get(). | ||
290 | */ | ||
291 | void phy_put(struct phy *phy) | ||
292 | { | ||
293 | if (IS_ERR(phy)) | ||
294 | return; | ||
295 | |||
296 | module_put(phy->ops->owner); | ||
297 | put_device(&phy->dev); | ||
298 | } | ||
299 | EXPORT_SYMBOL_GPL(phy_put); | ||
300 | |||
301 | /** | ||
302 | * devm_phy_put() - release the PHY | ||
303 | * @dev: device that wants to release this phy | ||
304 | * @phy: the phy returned by devm_phy_get() | ||
305 | * | ||
306 | * destroys the devres associated with this phy and invokes phy_put | ||
307 | * to release the phy. | ||
308 | */ | ||
309 | void devm_phy_put(struct device *dev, struct phy *phy) | ||
310 | { | ||
311 | int r; | ||
312 | |||
313 | r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy); | ||
314 | dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); | ||
315 | } | ||
316 | EXPORT_SYMBOL_GPL(devm_phy_put); | ||
317 | |||
318 | /** | ||
319 | * of_phy_simple_xlate() - returns the phy instance from phy provider | ||
320 | * @dev: the PHY provider device | ||
321 | * @args: of_phandle_args (not used here) | ||
322 | * | ||
323 | * Intended to be used by phy provider for the common case where #phy-cells is | ||
324 | * 0. For other cases where #phy-cells is greater than '0', the phy provider | ||
325 | * should provide a custom of_xlate function that reads the *args* and returns | ||
326 | * the appropriate phy. | ||
327 | */ | ||
328 | struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args | ||
329 | *args) | ||
330 | { | ||
331 | struct phy *phy; | ||
332 | struct class_dev_iter iter; | ||
333 | struct device_node *node = dev->of_node; | ||
334 | |||
335 | class_dev_iter_init(&iter, phy_class, NULL, NULL); | ||
336 | while ((dev = class_dev_iter_next(&iter))) { | ||
337 | phy = to_phy(dev); | ||
338 | if (node != phy->dev.of_node) | ||
339 | continue; | ||
340 | |||
341 | class_dev_iter_exit(&iter); | ||
342 | return phy; | ||
343 | } | ||
344 | |||
345 | class_dev_iter_exit(&iter); | ||
346 | return ERR_PTR(-ENODEV); | ||
347 | } | ||
348 | EXPORT_SYMBOL_GPL(of_phy_simple_xlate); | ||
349 | |||
350 | /** | ||
351 | * phy_get() - lookup and obtain a reference to a phy. | ||
352 | * @dev: device that requests this phy | ||
353 | * @string: the phy name as given in the dt data or the name of the controller | ||
354 | * port for non-dt case | ||
355 | * | ||
356 | * Returns the phy driver, after getting a refcount to it; or | ||
357 | * -ENODEV if there is no such phy. The caller is responsible for | ||
358 | * calling phy_put() to release that count. | ||
359 | */ | ||
360 | struct phy *phy_get(struct device *dev, const char *string) | ||
361 | { | ||
362 | int index = 0; | ||
363 | struct phy *phy = NULL; | ||
364 | |||
365 | if (string == NULL) { | ||
366 | dev_WARN(dev, "missing string\n"); | ||
367 | return ERR_PTR(-EINVAL); | ||
368 | } | ||
369 | |||
370 | if (dev->of_node) { | ||
371 | index = of_property_match_string(dev->of_node, "phy-names", | ||
372 | string); | ||
373 | phy = of_phy_get(dev, index); | ||
374 | if (IS_ERR(phy)) { | ||
375 | dev_err(dev, "unable to find phy\n"); | ||
376 | return phy; | ||
377 | } | ||
378 | } else { | ||
379 | phy = phy_lookup(dev, string); | ||
380 | if (IS_ERR(phy)) { | ||
381 | dev_err(dev, "unable to find phy\n"); | ||
382 | return phy; | ||
383 | } | ||
384 | } | ||
385 | |||
386 | if (!try_module_get(phy->ops->owner)) | ||
387 | return ERR_PTR(-EPROBE_DEFER); | ||
388 | |||
389 | get_device(&phy->dev); | ||
390 | |||
391 | return phy; | ||
392 | } | ||
393 | EXPORT_SYMBOL_GPL(phy_get); | ||
394 | |||
395 | /** | ||
396 | * devm_phy_get() - lookup and obtain a reference to a phy. | ||
397 | * @dev: device that requests this phy | ||
398 | * @string: the phy name as given in the dt data or phy device name | ||
399 | * for non-dt case | ||
400 | * | ||
401 | * Gets the phy using phy_get(), and associates a device with it using | ||
402 | * devres. On driver detach, release function is invoked on the devres data, | ||
403 | * then, devres data is freed. | ||
404 | */ | ||
405 | struct phy *devm_phy_get(struct device *dev, const char *string) | ||
406 | { | ||
407 | struct phy **ptr, *phy; | ||
408 | |||
409 | ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL); | ||
410 | if (!ptr) | ||
411 | return ERR_PTR(-ENOMEM); | ||
412 | |||
413 | phy = phy_get(dev, string); | ||
414 | if (!IS_ERR(phy)) { | ||
415 | *ptr = phy; | ||
416 | devres_add(dev, ptr); | ||
417 | } else { | ||
418 | devres_free(ptr); | ||
419 | } | ||
420 | |||
421 | return phy; | ||
422 | } | ||
423 | EXPORT_SYMBOL_GPL(devm_phy_get); | ||
424 | |||
425 | /** | ||
426 | * phy_create() - create a new phy | ||
427 | * @dev: device that is creating the new phy | ||
428 | * @ops: function pointers for performing phy operations | ||
429 | * @init_data: contains the list of PHY consumers or NULL | ||
430 | * | ||
431 | * Called to create a phy using phy framework. | ||
432 | */ | ||
433 | struct phy *phy_create(struct device *dev, const struct phy_ops *ops, | ||
434 | struct phy_init_data *init_data) | ||
435 | { | ||
436 | int ret; | ||
437 | int id; | ||
438 | struct phy *phy; | ||
439 | |||
440 | if (!dev) { | ||
441 | dev_WARN(dev, "no device provided for PHY\n"); | ||
442 | ret = -EINVAL; | ||
443 | goto err0; | ||
444 | } | ||
445 | |||
446 | phy = kzalloc(sizeof(*phy), GFP_KERNEL); | ||
447 | if (!phy) { | ||
448 | ret = -ENOMEM; | ||
449 | goto err0; | ||
450 | } | ||
451 | |||
452 | id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL); | ||
453 | if (id < 0) { | ||
454 | dev_err(dev, "unable to get id\n"); | ||
455 | ret = id; | ||
456 | goto err0; | ||
457 | } | ||
458 | |||
459 | device_initialize(&phy->dev); | ||
460 | mutex_init(&phy->mutex); | ||
461 | |||
462 | phy->dev.class = phy_class; | ||
463 | phy->dev.parent = dev; | ||
464 | phy->dev.of_node = dev->of_node; | ||
465 | phy->id = id; | ||
466 | phy->ops = ops; | ||
467 | phy->init_data = init_data; | ||
468 | |||
469 | ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id); | ||
470 | if (ret) | ||
471 | goto err1; | ||
472 | |||
473 | ret = device_add(&phy->dev); | ||
474 | if (ret) | ||
475 | goto err1; | ||
476 | |||
477 | if (pm_runtime_enabled(dev)) { | ||
478 | pm_runtime_enable(&phy->dev); | ||
479 | pm_runtime_no_callbacks(&phy->dev); | ||
480 | } | ||
481 | |||
482 | return phy; | ||
483 | |||
484 | err1: | ||
485 | ida_remove(&phy_ida, phy->id); | ||
486 | put_device(&phy->dev); | ||
487 | kfree(phy); | ||
488 | |||
489 | err0: | ||
490 | return ERR_PTR(ret); | ||
491 | } | ||
492 | EXPORT_SYMBOL_GPL(phy_create); | ||
493 | |||
494 | /** | ||
495 | * devm_phy_create() - create a new phy | ||
496 | * @dev: device that is creating the new phy | ||
497 | * @ops: function pointers for performing phy operations | ||
498 | * @init_data: contains the list of PHY consumers or NULL | ||
499 | * | ||
500 | * Creates a new PHY device adding it to the PHY class. | ||
501 | * While at that, it also associates the device with the phy using devres. | ||
502 | * On driver detach, release function is invoked on the devres data, | ||
503 | * then, devres data is freed. | ||
504 | */ | ||
505 | struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops, | ||
506 | struct phy_init_data *init_data) | ||
507 | { | ||
508 | struct phy **ptr, *phy; | ||
509 | |||
510 | ptr = devres_alloc(devm_phy_consume, sizeof(*ptr), GFP_KERNEL); | ||
511 | if (!ptr) | ||
512 | return ERR_PTR(-ENOMEM); | ||
513 | |||
514 | phy = phy_create(dev, ops, init_data); | ||
515 | if (!IS_ERR(phy)) { | ||
516 | *ptr = phy; | ||
517 | devres_add(dev, ptr); | ||
518 | } else { | ||
519 | devres_free(ptr); | ||
520 | } | ||
521 | |||
522 | return phy; | ||
523 | } | ||
524 | EXPORT_SYMBOL_GPL(devm_phy_create); | ||
525 | |||
526 | /** | ||
527 | * phy_destroy() - destroy the phy | ||
528 | * @phy: the phy to be destroyed | ||
529 | * | ||
530 | * Called to destroy the phy. | ||
531 | */ | ||
532 | void phy_destroy(struct phy *phy) | ||
533 | { | ||
534 | pm_runtime_disable(&phy->dev); | ||
535 | device_unregister(&phy->dev); | ||
536 | } | ||
537 | EXPORT_SYMBOL_GPL(phy_destroy); | ||
538 | |||
539 | /** | ||
540 | * devm_phy_destroy() - destroy the PHY | ||
541 | * @dev: device that wants to release this phy | ||
542 | * @phy: the phy returned by devm_phy_get() | ||
543 | * | ||
544 | * destroys the devres associated with this phy and invokes phy_destroy | ||
545 | * to destroy the phy. | ||
546 | */ | ||
547 | void devm_phy_destroy(struct device *dev, struct phy *phy) | ||
548 | { | ||
549 | int r; | ||
550 | |||
551 | r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy); | ||
552 | dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); | ||
553 | } | ||
554 | EXPORT_SYMBOL_GPL(devm_phy_destroy); | ||
555 | |||
556 | /** | ||
557 | * __of_phy_provider_register() - create/register phy provider with the framework | ||
558 | * @dev: struct device of the phy provider | ||
559 | * @owner: the module owner containing of_xlate | ||
560 | * @of_xlate: function pointer to obtain phy instance from phy provider | ||
561 | * | ||
562 | * Creates struct phy_provider from dev and of_xlate function pointer. | ||
563 | * This is used in the case of dt boot for finding the phy instance from | ||
564 | * phy provider. | ||
565 | */ | ||
566 | struct phy_provider *__of_phy_provider_register(struct device *dev, | ||
567 | struct module *owner, struct phy * (*of_xlate)(struct device *dev, | ||
568 | struct of_phandle_args *args)) | ||
569 | { | ||
570 | struct phy_provider *phy_provider; | ||
571 | |||
572 | phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL); | ||
573 | if (!phy_provider) | ||
574 | return ERR_PTR(-ENOMEM); | ||
575 | |||
576 | phy_provider->dev = dev; | ||
577 | phy_provider->owner = owner; | ||
578 | phy_provider->of_xlate = of_xlate; | ||
579 | |||
580 | mutex_lock(&phy_provider_mutex); | ||
581 | list_add_tail(&phy_provider->list, &phy_provider_list); | ||
582 | mutex_unlock(&phy_provider_mutex); | ||
583 | |||
584 | return phy_provider; | ||
585 | } | ||
586 | EXPORT_SYMBOL_GPL(__of_phy_provider_register); | ||
587 | |||
588 | /** | ||
589 | * __devm_of_phy_provider_register() - create/register phy provider with the | ||
590 | * framework | ||
591 | * @dev: struct device of the phy provider | ||
592 | * @owner: the module owner containing of_xlate | ||
593 | * @of_xlate: function pointer to obtain phy instance from phy provider | ||
594 | * | ||
595 | * Creates struct phy_provider from dev and of_xlate function pointer. | ||
596 | * This is used in the case of dt boot for finding the phy instance from | ||
597 | * phy provider. While at that, it also associates the device with the | ||
598 | * phy provider using devres. On driver detach, release function is invoked | ||
599 | * on the devres data, then, devres data is freed. | ||
600 | */ | ||
601 | struct phy_provider *__devm_of_phy_provider_register(struct device *dev, | ||
602 | struct module *owner, struct phy * (*of_xlate)(struct device *dev, | ||
603 | struct of_phandle_args *args)) | ||
604 | { | ||
605 | struct phy_provider **ptr, *phy_provider; | ||
606 | |||
607 | ptr = devres_alloc(devm_phy_provider_release, sizeof(*ptr), GFP_KERNEL); | ||
608 | if (!ptr) | ||
609 | return ERR_PTR(-ENOMEM); | ||
610 | |||
611 | phy_provider = __of_phy_provider_register(dev, owner, of_xlate); | ||
612 | if (!IS_ERR(phy_provider)) { | ||
613 | *ptr = phy_provider; | ||
614 | devres_add(dev, ptr); | ||
615 | } else { | ||
616 | devres_free(ptr); | ||
617 | } | ||
618 | |||
619 | return phy_provider; | ||
620 | } | ||
621 | EXPORT_SYMBOL_GPL(__devm_of_phy_provider_register); | ||
622 | |||
623 | /** | ||
624 | * of_phy_provider_unregister() - unregister phy provider from the framework | ||
625 | * @phy_provider: phy provider returned by of_phy_provider_register() | ||
626 | * | ||
627 | * Removes the phy_provider created using of_phy_provider_register(). | ||
628 | */ | ||
629 | void of_phy_provider_unregister(struct phy_provider *phy_provider) | ||
630 | { | ||
631 | if (IS_ERR(phy_provider)) | ||
632 | return; | ||
633 | |||
634 | mutex_lock(&phy_provider_mutex); | ||
635 | list_del(&phy_provider->list); | ||
636 | kfree(phy_provider); | ||
637 | mutex_unlock(&phy_provider_mutex); | ||
638 | } | ||
639 | EXPORT_SYMBOL_GPL(of_phy_provider_unregister); | ||
640 | |||
641 | /** | ||
642 | * devm_of_phy_provider_unregister() - remove phy provider from the framework | ||
643 | * @dev: struct device of the phy provider | ||
644 | * | ||
645 | * destroys the devres associated with this phy provider and invokes | ||
646 | * of_phy_provider_unregister to unregister the phy provider. | ||
647 | */ | ||
648 | void devm_of_phy_provider_unregister(struct device *dev, | ||
649 | struct phy_provider *phy_provider) { | ||
650 | int r; | ||
651 | |||
652 | r = devres_destroy(dev, devm_phy_provider_release, devm_phy_match, | ||
653 | phy_provider); | ||
654 | dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n"); | ||
655 | } | ||
656 | EXPORT_SYMBOL_GPL(devm_of_phy_provider_unregister); | ||
657 | |||
658 | /** | ||
659 | * phy_release() - release the phy | ||
660 | * @dev: the dev member within phy | ||
661 | * | ||
662 | * When the last reference to the device is removed, it is called | ||
663 | * from the embedded kobject as release method. | ||
664 | */ | ||
665 | static void phy_release(struct device *dev) | ||
666 | { | ||
667 | struct phy *phy; | ||
668 | |||
669 | phy = to_phy(dev); | ||
670 | dev_vdbg(dev, "releasing '%s'\n", dev_name(dev)); | ||
671 | ida_remove(&phy_ida, phy->id); | ||
672 | kfree(phy); | ||
673 | } | ||
674 | |||
675 | static int __init phy_core_init(void) | ||
676 | { | ||
677 | phy_class = class_create(THIS_MODULE, "phy"); | ||
678 | if (IS_ERR(phy_class)) { | ||
679 | pr_err("failed to create phy class --> %ld\n", | ||
680 | PTR_ERR(phy_class)); | ||
681 | return PTR_ERR(phy_class); | ||
682 | } | ||
683 | |||
684 | phy_class->dev_release = phy_release; | ||
685 | |||
686 | return 0; | ||
687 | } | ||
688 | module_init(phy_core_init); | ||
689 | |||
690 | static void __exit phy_core_exit(void) | ||
691 | { | ||
692 | class_destroy(phy_class); | ||
693 | } | ||
694 | module_exit(phy_core_exit); | ||
695 | |||
696 | MODULE_DESCRIPTION("Generic PHY Framework"); | ||
697 | MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>"); | ||
698 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/phy/phy-exynos-dp-video.c b/drivers/phy/phy-exynos-dp-video.c new file mode 100644 index 000000000000..1dbe6ce7b2ce --- /dev/null +++ b/drivers/phy/phy-exynos-dp-video.c | |||
@@ -0,0 +1,111 @@ | |||
1 | /* | ||
2 | * Samsung EXYNOS SoC series Display Port PHY driver | ||
3 | * | ||
4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. | ||
5 | * Author: Jingoo Han <jg1.han@samsung.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/io.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_address.h> | ||
17 | #include <linux/phy/phy.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | |||
20 | /* DPTX_PHY_CONTROL register */ | ||
21 | #define EXYNOS_DPTX_PHY_ENABLE (1 << 0) | ||
22 | |||
23 | struct exynos_dp_video_phy { | ||
24 | void __iomem *regs; | ||
25 | }; | ||
26 | |||
27 | static int __set_phy_state(struct exynos_dp_video_phy *state, unsigned int on) | ||
28 | { | ||
29 | u32 reg; | ||
30 | |||
31 | reg = readl(state->regs); | ||
32 | if (on) | ||
33 | reg |= EXYNOS_DPTX_PHY_ENABLE; | ||
34 | else | ||
35 | reg &= ~EXYNOS_DPTX_PHY_ENABLE; | ||
36 | writel(reg, state->regs); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static int exynos_dp_video_phy_power_on(struct phy *phy) | ||
42 | { | ||
43 | struct exynos_dp_video_phy *state = phy_get_drvdata(phy); | ||
44 | |||
45 | return __set_phy_state(state, 1); | ||
46 | } | ||
47 | |||
48 | static int exynos_dp_video_phy_power_off(struct phy *phy) | ||
49 | { | ||
50 | struct exynos_dp_video_phy *state = phy_get_drvdata(phy); | ||
51 | |||
52 | return __set_phy_state(state, 0); | ||
53 | } | ||
54 | |||
55 | static struct phy_ops exynos_dp_video_phy_ops = { | ||
56 | .power_on = exynos_dp_video_phy_power_on, | ||
57 | .power_off = exynos_dp_video_phy_power_off, | ||
58 | .owner = THIS_MODULE, | ||
59 | }; | ||
60 | |||
61 | static int exynos_dp_video_phy_probe(struct platform_device *pdev) | ||
62 | { | ||
63 | struct exynos_dp_video_phy *state; | ||
64 | struct device *dev = &pdev->dev; | ||
65 | struct resource *res; | ||
66 | struct phy_provider *phy_provider; | ||
67 | struct phy *phy; | ||
68 | |||
69 | state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); | ||
70 | if (!state) | ||
71 | return -ENOMEM; | ||
72 | |||
73 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
74 | |||
75 | state->regs = devm_ioremap_resource(dev, res); | ||
76 | if (IS_ERR(state->regs)) | ||
77 | return PTR_ERR(state->regs); | ||
78 | |||
79 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
80 | if (IS_ERR(phy_provider)) | ||
81 | return PTR_ERR(phy_provider); | ||
82 | |||
83 | phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL); | ||
84 | if (IS_ERR(phy)) { | ||
85 | dev_err(dev, "failed to create Display Port PHY\n"); | ||
86 | return PTR_ERR(phy); | ||
87 | } | ||
88 | phy_set_drvdata(phy, state); | ||
89 | |||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static const struct of_device_id exynos_dp_video_phy_of_match[] = { | ||
94 | { .compatible = "samsung,exynos5250-dp-video-phy" }, | ||
95 | { }, | ||
96 | }; | ||
97 | MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match); | ||
98 | |||
99 | static struct platform_driver exynos_dp_video_phy_driver = { | ||
100 | .probe = exynos_dp_video_phy_probe, | ||
101 | .driver = { | ||
102 | .name = "exynos-dp-video-phy", | ||
103 | .owner = THIS_MODULE, | ||
104 | .of_match_table = exynos_dp_video_phy_of_match, | ||
105 | } | ||
106 | }; | ||
107 | module_platform_driver(exynos_dp_video_phy_driver); | ||
108 | |||
109 | MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); | ||
110 | MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver"); | ||
111 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/phy/phy-exynos-mipi-video.c b/drivers/phy/phy-exynos-mipi-video.c new file mode 100644 index 000000000000..0c5efab11af1 --- /dev/null +++ b/drivers/phy/phy-exynos-mipi-video.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY driver | ||
3 | * | ||
4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. | ||
5 | * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/io.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_address.h> | ||
17 | #include <linux/phy/phy.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | |||
21 | /* MIPI_PHYn_CONTROL register offset: n = 0..1 */ | ||
22 | #define EXYNOS_MIPI_PHY_CONTROL(n) ((n) * 4) | ||
23 | #define EXYNOS_MIPI_PHY_ENABLE (1 << 0) | ||
24 | #define EXYNOS_MIPI_PHY_SRESETN (1 << 1) | ||
25 | #define EXYNOS_MIPI_PHY_MRESETN (1 << 2) | ||
26 | #define EXYNOS_MIPI_PHY_RESET_MASK (3 << 1) | ||
27 | |||
28 | enum exynos_mipi_phy_id { | ||
29 | EXYNOS_MIPI_PHY_ID_CSIS0, | ||
30 | EXYNOS_MIPI_PHY_ID_DSIM0, | ||
31 | EXYNOS_MIPI_PHY_ID_CSIS1, | ||
32 | EXYNOS_MIPI_PHY_ID_DSIM1, | ||
33 | EXYNOS_MIPI_PHYS_NUM | ||
34 | }; | ||
35 | |||
36 | #define is_mipi_dsim_phy_id(id) \ | ||
37 | ((id) == EXYNOS_MIPI_PHY_ID_DSIM0 || (id) == EXYNOS_MIPI_PHY_ID_DSIM1) | ||
38 | |||
39 | struct exynos_mipi_video_phy { | ||
40 | spinlock_t slock; | ||
41 | struct video_phy_desc { | ||
42 | struct phy *phy; | ||
43 | unsigned int index; | ||
44 | } phys[EXYNOS_MIPI_PHYS_NUM]; | ||
45 | void __iomem *regs; | ||
46 | }; | ||
47 | |||
48 | static int __set_phy_state(struct exynos_mipi_video_phy *state, | ||
49 | enum exynos_mipi_phy_id id, unsigned int on) | ||
50 | { | ||
51 | void __iomem *addr; | ||
52 | u32 reg, reset; | ||
53 | |||
54 | addr = state->regs + EXYNOS_MIPI_PHY_CONTROL(id / 2); | ||
55 | |||
56 | if (is_mipi_dsim_phy_id(id)) | ||
57 | reset = EXYNOS_MIPI_PHY_MRESETN; | ||
58 | else | ||
59 | reset = EXYNOS_MIPI_PHY_SRESETN; | ||
60 | |||
61 | spin_lock(&state->slock); | ||
62 | reg = readl(addr); | ||
63 | if (on) | ||
64 | reg |= reset; | ||
65 | else | ||
66 | reg &= ~reset; | ||
67 | writel(reg, addr); | ||
68 | |||
69 | /* Clear ENABLE bit only if MRESETN, SRESETN bits are not set. */ | ||
70 | if (on) | ||
71 | reg |= EXYNOS_MIPI_PHY_ENABLE; | ||
72 | else if (!(reg & EXYNOS_MIPI_PHY_RESET_MASK)) | ||
73 | reg &= ~EXYNOS_MIPI_PHY_ENABLE; | ||
74 | |||
75 | writel(reg, addr); | ||
76 | spin_unlock(&state->slock); | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | #define to_mipi_video_phy(desc) \ | ||
81 | container_of((desc), struct exynos_mipi_video_phy, phys[(desc)->index]); | ||
82 | |||
83 | static int exynos_mipi_video_phy_power_on(struct phy *phy) | ||
84 | { | ||
85 | struct video_phy_desc *phy_desc = phy_get_drvdata(phy); | ||
86 | struct exynos_mipi_video_phy *state = to_mipi_video_phy(phy_desc); | ||
87 | |||
88 | return __set_phy_state(state, phy_desc->index, 1); | ||
89 | } | ||
90 | |||
91 | static int exynos_mipi_video_phy_power_off(struct phy *phy) | ||
92 | { | ||
93 | struct video_phy_desc *phy_desc = phy_get_drvdata(phy); | ||
94 | struct exynos_mipi_video_phy *state = to_mipi_video_phy(phy_desc); | ||
95 | |||
96 | return __set_phy_state(state, phy_desc->index, 0); | ||
97 | } | ||
98 | |||
99 | static struct phy *exynos_mipi_video_phy_xlate(struct device *dev, | ||
100 | struct of_phandle_args *args) | ||
101 | { | ||
102 | struct exynos_mipi_video_phy *state = dev_get_drvdata(dev); | ||
103 | |||
104 | if (WARN_ON(args->args[0] > EXYNOS_MIPI_PHYS_NUM)) | ||
105 | return ERR_PTR(-ENODEV); | ||
106 | |||
107 | return state->phys[args->args[0]].phy; | ||
108 | } | ||
109 | |||
110 | static struct phy_ops exynos_mipi_video_phy_ops = { | ||
111 | .power_on = exynos_mipi_video_phy_power_on, | ||
112 | .power_off = exynos_mipi_video_phy_power_off, | ||
113 | .owner = THIS_MODULE, | ||
114 | }; | ||
115 | |||
116 | static int exynos_mipi_video_phy_probe(struct platform_device *pdev) | ||
117 | { | ||
118 | struct exynos_mipi_video_phy *state; | ||
119 | struct device *dev = &pdev->dev; | ||
120 | struct resource *res; | ||
121 | struct phy_provider *phy_provider; | ||
122 | unsigned int i; | ||
123 | |||
124 | state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); | ||
125 | if (!state) | ||
126 | return -ENOMEM; | ||
127 | |||
128 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
129 | |||
130 | state->regs = devm_ioremap_resource(dev, res); | ||
131 | if (IS_ERR(state->regs)) | ||
132 | return PTR_ERR(state->regs); | ||
133 | |||
134 | dev_set_drvdata(dev, state); | ||
135 | spin_lock_init(&state->slock); | ||
136 | |||
137 | phy_provider = devm_of_phy_provider_register(dev, | ||
138 | exynos_mipi_video_phy_xlate); | ||
139 | if (IS_ERR(phy_provider)) | ||
140 | return PTR_ERR(phy_provider); | ||
141 | |||
142 | for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) { | ||
143 | struct phy *phy = devm_phy_create(dev, | ||
144 | &exynos_mipi_video_phy_ops, NULL); | ||
145 | if (IS_ERR(phy)) { | ||
146 | dev_err(dev, "failed to create PHY %d\n", i); | ||
147 | return PTR_ERR(phy); | ||
148 | } | ||
149 | |||
150 | state->phys[i].phy = phy; | ||
151 | state->phys[i].index = i; | ||
152 | phy_set_drvdata(phy, &state->phys[i]); | ||
153 | } | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static const struct of_device_id exynos_mipi_video_phy_of_match[] = { | ||
159 | { .compatible = "samsung,s5pv210-mipi-video-phy" }, | ||
160 | { }, | ||
161 | }; | ||
162 | MODULE_DEVICE_TABLE(of, exynos_mipi_video_phy_of_match); | ||
163 | |||
164 | static struct platform_driver exynos_mipi_video_phy_driver = { | ||
165 | .probe = exynos_mipi_video_phy_probe, | ||
166 | .driver = { | ||
167 | .of_match_table = exynos_mipi_video_phy_of_match, | ||
168 | .name = "exynos-mipi-video-phy", | ||
169 | .owner = THIS_MODULE, | ||
170 | } | ||
171 | }; | ||
172 | module_platform_driver(exynos_mipi_video_phy_driver); | ||
173 | |||
174 | MODULE_DESCRIPTION("Samsung S5P/EXYNOS SoC MIPI CSI-2/DSI PHY driver"); | ||
175 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); | ||
176 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c index d266861d24f7..bfc5c337f99a 100644 --- a/drivers/usb/phy/phy-omap-usb2.c +++ b/drivers/phy/phy-omap-usb2.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #include <linux/pm_runtime.h> | 28 | #include <linux/pm_runtime.h> |
29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
30 | #include <linux/usb/omap_control_usb.h> | 30 | #include <linux/usb/omap_control_usb.h> |
31 | #include <linux/phy/phy.h> | ||
32 | #include <linux/of_platform.h> | ||
31 | 33 | ||
32 | /** | 34 | /** |
33 | * omap_usb2_set_comparator - links the comparator present in the sytem with | 35 | * omap_usb2_set_comparator - links the comparator present in the sytem with |
@@ -118,10 +120,42 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend) | |||
118 | return 0; | 120 | return 0; |
119 | } | 121 | } |
120 | 122 | ||
123 | static int omap_usb_power_off(struct phy *x) | ||
124 | { | ||
125 | struct omap_usb *phy = phy_get_drvdata(x); | ||
126 | |||
127 | omap_control_usb_phy_power(phy->control_dev, 0); | ||
128 | |||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | static int omap_usb_power_on(struct phy *x) | ||
133 | { | ||
134 | struct omap_usb *phy = phy_get_drvdata(x); | ||
135 | |||
136 | omap_control_usb_phy_power(phy->control_dev, 1); | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | static struct phy_ops ops = { | ||
142 | .power_on = omap_usb_power_on, | ||
143 | .power_off = omap_usb_power_off, | ||
144 | .owner = THIS_MODULE, | ||
145 | }; | ||
146 | |||
121 | static int omap_usb2_probe(struct platform_device *pdev) | 147 | static int omap_usb2_probe(struct platform_device *pdev) |
122 | { | 148 | { |
123 | struct omap_usb *phy; | 149 | struct omap_usb *phy; |
124 | struct usb_otg *otg; | 150 | struct phy *generic_phy; |
151 | struct phy_provider *phy_provider; | ||
152 | struct usb_otg *otg; | ||
153 | struct device_node *node = pdev->dev.of_node; | ||
154 | struct device_node *control_node; | ||
155 | struct platform_device *control_pdev; | ||
156 | |||
157 | if (!node) | ||
158 | return -EINVAL; | ||
125 | 159 | ||
126 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); | 160 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); |
127 | if (!phy) { | 161 | if (!phy) { |
@@ -143,12 +177,25 @@ static int omap_usb2_probe(struct platform_device *pdev) | |||
143 | phy->phy.otg = otg; | 177 | phy->phy.otg = otg; |
144 | phy->phy.type = USB_PHY_TYPE_USB2; | 178 | phy->phy.type = USB_PHY_TYPE_USB2; |
145 | 179 | ||
146 | phy->control_dev = omap_get_control_dev(); | 180 | phy_provider = devm_of_phy_provider_register(phy->dev, |
147 | if (IS_ERR(phy->control_dev)) { | 181 | of_phy_simple_xlate); |
148 | dev_dbg(&pdev->dev, "Failed to get control device\n"); | 182 | if (IS_ERR(phy_provider)) |
149 | return -ENODEV; | 183 | return PTR_ERR(phy_provider); |
184 | |||
185 | control_node = of_parse_phandle(node, "ctrl-module", 0); | ||
186 | if (!control_node) { | ||
187 | dev_err(&pdev->dev, "Failed to get control device phandle\n"); | ||
188 | return -EINVAL; | ||
189 | } | ||
190 | |||
191 | control_pdev = of_find_device_by_node(control_node); | ||
192 | if (!control_pdev) { | ||
193 | dev_err(&pdev->dev, "Failed to get control device\n"); | ||
194 | return -EINVAL; | ||
150 | } | 195 | } |
151 | 196 | ||
197 | phy->control_dev = &control_pdev->dev; | ||
198 | |||
152 | phy->is_suspended = 1; | 199 | phy->is_suspended = 1; |
153 | omap_control_usb_phy_power(phy->control_dev, 0); | 200 | omap_control_usb_phy_power(phy->control_dev, 0); |
154 | 201 | ||
@@ -158,6 +205,15 @@ static int omap_usb2_probe(struct platform_device *pdev) | |||
158 | otg->start_srp = omap_usb_start_srp; | 205 | otg->start_srp = omap_usb_start_srp; |
159 | otg->phy = &phy->phy; | 206 | otg->phy = &phy->phy; |
160 | 207 | ||
208 | platform_set_drvdata(pdev, phy); | ||
209 | pm_runtime_enable(phy->dev); | ||
210 | |||
211 | generic_phy = devm_phy_create(phy->dev, &ops, NULL); | ||
212 | if (IS_ERR(generic_phy)) | ||
213 | return PTR_ERR(generic_phy); | ||
214 | |||
215 | phy_set_drvdata(generic_phy, phy); | ||
216 | |||
161 | phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); | 217 | phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); |
162 | if (IS_ERR(phy->wkupclk)) { | 218 | if (IS_ERR(phy->wkupclk)) { |
163 | dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); | 219 | dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); |
@@ -173,10 +229,6 @@ static int omap_usb2_probe(struct platform_device *pdev) | |||
173 | 229 | ||
174 | usb_add_phy_dev(&phy->phy); | 230 | usb_add_phy_dev(&phy->phy); |
175 | 231 | ||
176 | platform_set_drvdata(pdev, phy); | ||
177 | |||
178 | pm_runtime_enable(phy->dev); | ||
179 | |||
180 | return 0; | 232 | return 0; |
181 | } | 233 | } |
182 | 234 | ||
diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c index 90730c8762b8..daf65e68aaab 100644 --- a/drivers/usb/phy/phy-twl4030-usb.c +++ b/drivers/phy/phy-twl4030-usb.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/io.h> | 33 | #include <linux/io.h> |
34 | #include <linux/delay.h> | 34 | #include <linux/delay.h> |
35 | #include <linux/usb/otg.h> | 35 | #include <linux/usb/otg.h> |
36 | #include <linux/phy/phy.h> | ||
36 | #include <linux/usb/musb-omap.h> | 37 | #include <linux/usb/musb-omap.h> |
37 | #include <linux/usb/ulpi.h> | 38 | #include <linux/usb/ulpi.h> |
38 | #include <linux/i2c/twl.h> | 39 | #include <linux/i2c/twl.h> |
@@ -421,17 +422,20 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on) | |||
421 | } | 422 | } |
422 | } | 423 | } |
423 | 424 | ||
424 | static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off) | 425 | static int twl4030_phy_power_off(struct phy *phy) |
425 | { | 426 | { |
427 | struct twl4030_usb *twl = phy_get_drvdata(phy); | ||
428 | |||
426 | if (twl->asleep) | 429 | if (twl->asleep) |
427 | return; | 430 | return 0; |
428 | 431 | ||
429 | twl4030_phy_power(twl, 0); | 432 | twl4030_phy_power(twl, 0); |
430 | twl->asleep = 1; | 433 | twl->asleep = 1; |
431 | dev_dbg(twl->dev, "%s\n", __func__); | 434 | dev_dbg(twl->dev, "%s\n", __func__); |
435 | return 0; | ||
432 | } | 436 | } |
433 | 437 | ||
434 | static void __twl4030_phy_resume(struct twl4030_usb *twl) | 438 | static void __twl4030_phy_power_on(struct twl4030_usb *twl) |
435 | { | 439 | { |
436 | twl4030_phy_power(twl, 1); | 440 | twl4030_phy_power(twl, 1); |
437 | twl4030_i2c_access(twl, 1); | 441 | twl4030_i2c_access(twl, 1); |
@@ -440,11 +444,13 @@ static void __twl4030_phy_resume(struct twl4030_usb *twl) | |||
440 | twl4030_i2c_access(twl, 0); | 444 | twl4030_i2c_access(twl, 0); |
441 | } | 445 | } |
442 | 446 | ||
443 | static void twl4030_phy_resume(struct twl4030_usb *twl) | 447 | static int twl4030_phy_power_on(struct phy *phy) |
444 | { | 448 | { |
449 | struct twl4030_usb *twl = phy_get_drvdata(phy); | ||
450 | |||
445 | if (!twl->asleep) | 451 | if (!twl->asleep) |
446 | return; | 452 | return 0; |
447 | __twl4030_phy_resume(twl); | 453 | __twl4030_phy_power_on(twl); |
448 | twl->asleep = 0; | 454 | twl->asleep = 0; |
449 | dev_dbg(twl->dev, "%s\n", __func__); | 455 | dev_dbg(twl->dev, "%s\n", __func__); |
450 | 456 | ||
@@ -457,6 +463,7 @@ static void twl4030_phy_resume(struct twl4030_usb *twl) | |||
457 | cancel_delayed_work(&twl->id_workaround_work); | 463 | cancel_delayed_work(&twl->id_workaround_work); |
458 | schedule_delayed_work(&twl->id_workaround_work, HZ); | 464 | schedule_delayed_work(&twl->id_workaround_work, HZ); |
459 | } | 465 | } |
466 | return 0; | ||
460 | } | 467 | } |
461 | 468 | ||
462 | static int twl4030_usb_ldo_init(struct twl4030_usb *twl) | 469 | static int twl4030_usb_ldo_init(struct twl4030_usb *twl) |
@@ -587,9 +594,9 @@ static void twl4030_id_workaround_work(struct work_struct *work) | |||
587 | } | 594 | } |
588 | } | 595 | } |
589 | 596 | ||
590 | static int twl4030_usb_phy_init(struct usb_phy *phy) | 597 | static int twl4030_phy_init(struct phy *phy) |
591 | { | 598 | { |
592 | struct twl4030_usb *twl = phy_to_twl(phy); | 599 | struct twl4030_usb *twl = phy_get_drvdata(phy); |
593 | enum omap_musb_vbus_id_status status; | 600 | enum omap_musb_vbus_id_status status; |
594 | 601 | ||
595 | /* | 602 | /* |
@@ -602,25 +609,15 @@ static int twl4030_usb_phy_init(struct usb_phy *phy) | |||
602 | status = twl4030_usb_linkstat(twl); | 609 | status = twl4030_usb_linkstat(twl); |
603 | twl->linkstat = status; | 610 | twl->linkstat = status; |
604 | 611 | ||
605 | if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) | 612 | if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) { |
606 | omap_musb_mailbox(twl->linkstat); | 613 | omap_musb_mailbox(twl->linkstat); |
614 | twl4030_phy_power_on(phy); | ||
615 | } | ||
607 | 616 | ||
608 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | 617 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); |
609 | return 0; | 618 | return 0; |
610 | } | 619 | } |
611 | 620 | ||
612 | static int twl4030_set_suspend(struct usb_phy *x, int suspend) | ||
613 | { | ||
614 | struct twl4030_usb *twl = phy_to_twl(x); | ||
615 | |||
616 | if (suspend) | ||
617 | twl4030_phy_suspend(twl, 1); | ||
618 | else | ||
619 | twl4030_phy_resume(twl); | ||
620 | |||
621 | return 0; | ||
622 | } | ||
623 | |||
624 | static int twl4030_set_peripheral(struct usb_otg *otg, | 621 | static int twl4030_set_peripheral(struct usb_otg *otg, |
625 | struct usb_gadget *gadget) | 622 | struct usb_gadget *gadget) |
626 | { | 623 | { |
@@ -646,13 +643,23 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
646 | return 0; | 643 | return 0; |
647 | } | 644 | } |
648 | 645 | ||
646 | static const struct phy_ops ops = { | ||
647 | .init = twl4030_phy_init, | ||
648 | .power_on = twl4030_phy_power_on, | ||
649 | .power_off = twl4030_phy_power_off, | ||
650 | .owner = THIS_MODULE, | ||
651 | }; | ||
652 | |||
649 | static int twl4030_usb_probe(struct platform_device *pdev) | 653 | static int twl4030_usb_probe(struct platform_device *pdev) |
650 | { | 654 | { |
651 | struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev); | 655 | struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev); |
652 | struct twl4030_usb *twl; | 656 | struct twl4030_usb *twl; |
657 | struct phy *phy; | ||
653 | int status, err; | 658 | int status, err; |
654 | struct usb_otg *otg; | 659 | struct usb_otg *otg; |
655 | struct device_node *np = pdev->dev.of_node; | 660 | struct device_node *np = pdev->dev.of_node; |
661 | struct phy_provider *phy_provider; | ||
662 | struct phy_init_data *init_data = NULL; | ||
656 | 663 | ||
657 | twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL); | 664 | twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL); |
658 | if (!twl) | 665 | if (!twl) |
@@ -661,9 +668,10 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
661 | if (np) | 668 | if (np) |
662 | of_property_read_u32(np, "usb_mode", | 669 | of_property_read_u32(np, "usb_mode", |
663 | (enum twl4030_usb_mode *)&twl->usb_mode); | 670 | (enum twl4030_usb_mode *)&twl->usb_mode); |
664 | else if (pdata) | 671 | else if (pdata) { |
665 | twl->usb_mode = pdata->usb_mode; | 672 | twl->usb_mode = pdata->usb_mode; |
666 | else { | 673 | init_data = pdata->init_data; |
674 | } else { | ||
667 | dev_err(&pdev->dev, "twl4030 initialized without pdata\n"); | 675 | dev_err(&pdev->dev, "twl4030 initialized without pdata\n"); |
668 | return -EINVAL; | 676 | return -EINVAL; |
669 | } | 677 | } |
@@ -682,13 +690,24 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
682 | twl->phy.label = "twl4030"; | 690 | twl->phy.label = "twl4030"; |
683 | twl->phy.otg = otg; | 691 | twl->phy.otg = otg; |
684 | twl->phy.type = USB_PHY_TYPE_USB2; | 692 | twl->phy.type = USB_PHY_TYPE_USB2; |
685 | twl->phy.set_suspend = twl4030_set_suspend; | ||
686 | twl->phy.init = twl4030_usb_phy_init; | ||
687 | 693 | ||
688 | otg->phy = &twl->phy; | 694 | otg->phy = &twl->phy; |
689 | otg->set_host = twl4030_set_host; | 695 | otg->set_host = twl4030_set_host; |
690 | otg->set_peripheral = twl4030_set_peripheral; | 696 | otg->set_peripheral = twl4030_set_peripheral; |
691 | 697 | ||
698 | phy_provider = devm_of_phy_provider_register(twl->dev, | ||
699 | of_phy_simple_xlate); | ||
700 | if (IS_ERR(phy_provider)) | ||
701 | return PTR_ERR(phy_provider); | ||
702 | |||
703 | phy = devm_phy_create(twl->dev, &ops, init_data); | ||
704 | if (IS_ERR(phy)) { | ||
705 | dev_dbg(&pdev->dev, "Failed to create PHY\n"); | ||
706 | return PTR_ERR(phy); | ||
707 | } | ||
708 | |||
709 | phy_set_drvdata(phy, twl); | ||
710 | |||
692 | /* init spinlock for workqueue */ | 711 | /* init spinlock for workqueue */ |
693 | spin_lock_init(&twl->lock); | 712 | spin_lock_init(&twl->lock); |
694 | 713 | ||
@@ -705,6 +724,8 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
705 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) | 724 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) |
706 | dev_warn(&pdev->dev, "could not create sysfs file\n"); | 725 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
707 | 726 | ||
727 | ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); | ||
728 | |||
708 | /* Our job is to use irqs and status from the power module | 729 | /* Our job is to use irqs and status from the power module |
709 | * to keep the transceiver disabled when nothing's connected. | 730 | * to keep the transceiver disabled when nothing's connected. |
710 | * | 731 | * |
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h index 5651231a7437..f3eecd967a8a 100644 --- a/drivers/usb/atm/usbatm.h +++ b/drivers/usb/atm/usbatm.h | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/stringify.h> | 34 | #include <linux/stringify.h> |
35 | #include <linux/usb.h> | 35 | #include <linux/usb.h> |
36 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
37 | #include <linux/ratelimit.h> | ||
37 | 38 | ||
38 | /* | 39 | /* |
39 | #define VERBOSE_DEBUG | 40 | #define VERBOSE_DEBUG |
@@ -59,13 +60,12 @@ | |||
59 | atm_printk(KERN_INFO, instance , format , ## arg) | 60 | atm_printk(KERN_INFO, instance , format , ## arg) |
60 | #define atm_warn(instance, format, arg...) \ | 61 | #define atm_warn(instance, format, arg...) \ |
61 | atm_printk(KERN_WARNING, instance , format , ## arg) | 62 | atm_printk(KERN_WARNING, instance , format , ## arg) |
62 | #define atm_dbg(instance, format, arg...) \ | 63 | #define atm_dbg(instance, format, ...) \ |
63 | dynamic_pr_debug("ATM dev %d: " format , \ | 64 | pr_debug("ATM dev %d: " format, \ |
64 | (instance)->atm_dev->number , ## arg) | 65 | (instance)->atm_dev->number, ##__VA_ARGS__) |
65 | #define atm_rldbg(instance, format, arg...) \ | 66 | #define atm_rldbg(instance, format, ...) \ |
66 | if (printk_ratelimit()) \ | 67 | pr_debug_ratelimited("ATM dev %d: " format, \ |
67 | atm_dbg(instance , format , ## arg) | 68 | (instance)->atm_dev->number, ##__VA_ARGS__) |
68 | |||
69 | 69 | ||
70 | /* flags, set by mini-driver in bind() */ | 70 | /* flags, set by mini-driver in bind() */ |
71 | 71 | ||
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index 464584c6ccae..a85713165688 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h | |||
@@ -48,6 +48,7 @@ | |||
48 | #define PORTSC_SUSP BIT(7) | 48 | #define PORTSC_SUSP BIT(7) |
49 | #define PORTSC_HSP BIT(9) | 49 | #define PORTSC_HSP BIT(9) |
50 | #define PORTSC_PTC (0x0FUL << 16) | 50 | #define PORTSC_PTC (0x0FUL << 16) |
51 | #define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23)) | ||
51 | /* PTS and PTW for non lpm version only */ | 52 | /* PTS and PTW for non lpm version only */ |
52 | #define PORTSC_PTS(d) \ | 53 | #define PORTSC_PTS(d) \ |
53 | (u32)((((d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 0)) | 54 | (u32)((((d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 0)) |
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index be822a2c1776..023d3cb6aa0a 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c | |||
@@ -108,14 +108,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
108 | } | 108 | } |
109 | 109 | ||
110 | data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); | 110 | data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); |
111 | if (!IS_ERR(data->phy)) { | 111 | if (IS_ERR(data->phy)) { |
112 | ret = usb_phy_init(data->phy); | 112 | ret = PTR_ERR(data->phy); |
113 | if (ret) { | ||
114 | dev_err(&pdev->dev, "unable to init phy: %d\n", ret); | ||
115 | goto err_clk; | ||
116 | } | ||
117 | } else if (PTR_ERR(data->phy) == -EPROBE_DEFER) { | ||
118 | ret = -EPROBE_DEFER; | ||
119 | goto err_clk; | 113 | goto err_clk; |
120 | } | 114 | } |
121 | 115 | ||
@@ -131,7 +125,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
131 | if (ret) { | 125 | if (ret) { |
132 | dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", | 126 | dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", |
133 | ret); | 127 | ret); |
134 | goto err_phy; | 128 | goto err_clk; |
135 | } | 129 | } |
136 | } | 130 | } |
137 | 131 | ||
@@ -143,7 +137,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
143 | dev_err(&pdev->dev, | 137 | dev_err(&pdev->dev, |
144 | "Can't register ci_hdrc platform device, err=%d\n", | 138 | "Can't register ci_hdrc platform device, err=%d\n", |
145 | ret); | 139 | ret); |
146 | goto err_phy; | 140 | goto err_clk; |
147 | } | 141 | } |
148 | 142 | ||
149 | if (data->usbmisc_data) { | 143 | if (data->usbmisc_data) { |
@@ -164,9 +158,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
164 | 158 | ||
165 | disable_device: | 159 | disable_device: |
166 | ci_hdrc_remove_device(data->ci_pdev); | 160 | ci_hdrc_remove_device(data->ci_pdev); |
167 | err_phy: | ||
168 | if (data->phy) | ||
169 | usb_phy_shutdown(data->phy); | ||
170 | err_clk: | 161 | err_clk: |
171 | clk_disable_unprepare(data->clk); | 162 | clk_disable_unprepare(data->clk); |
172 | return ret; | 163 | return ret; |
@@ -178,10 +169,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev) | |||
178 | 169 | ||
179 | pm_runtime_disable(&pdev->dev); | 170 | pm_runtime_disable(&pdev->dev); |
180 | ci_hdrc_remove_device(data->ci_pdev); | 171 | ci_hdrc_remove_device(data->ci_pdev); |
181 | |||
182 | if (data->phy) | ||
183 | usb_phy_shutdown(data->phy); | ||
184 | |||
185 | clk_disable_unprepare(data->clk); | 172 | clk_disable_unprepare(data->clk); |
186 | 173 | ||
187 | return 0; | 174 | return 0; |
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 23763dcec069..5d8981c5235e 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -172,6 +172,27 @@ u8 hw_port_test_get(struct ci_hdrc *ci) | |||
172 | return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); | 172 | return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); |
173 | } | 173 | } |
174 | 174 | ||
175 | /* The PHY enters/leaves low power mode */ | ||
176 | static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) | ||
177 | { | ||
178 | enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC; | ||
179 | bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm))); | ||
180 | |||
181 | if (enable && !lpm) { | ||
182 | hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), | ||
183 | PORTSC_PHCD(ci->hw_bank.lpm)); | ||
184 | } else if (!enable && lpm) { | ||
185 | hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), | ||
186 | 0); | ||
187 | /* | ||
188 | * The controller needs at least 1ms to reflect | ||
189 | * PHY's status, the PHY also needs some time (less | ||
190 | * than 1ms) to leave low power mode. | ||
191 | */ | ||
192 | usleep_range(1500, 2000); | ||
193 | } | ||
194 | } | ||
195 | |||
175 | static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) | 196 | static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) |
176 | { | 197 | { |
177 | u32 reg; | 198 | u32 reg; |
@@ -199,6 +220,8 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) | |||
199 | if (ci->hw_ep_max > ENDPT_MAX) | 220 | if (ci->hw_ep_max > ENDPT_MAX) |
200 | return -ENODEV; | 221 | return -ENODEV; |
201 | 222 | ||
223 | ci_hdrc_enter_lpm(ci, false); | ||
224 | |||
202 | /* Disable all interrupts bits */ | 225 | /* Disable all interrupts bits */ |
203 | hw_write(ci, OP_USBINTR, 0xffffffff, 0); | 226 | hw_write(ci, OP_USBINTR, 0xffffffff, 0); |
204 | 227 | ||
@@ -369,16 +392,28 @@ static irqreturn_t ci_irq(int irq, void *data) | |||
369 | static int ci_get_platdata(struct device *dev, | 392 | static int ci_get_platdata(struct device *dev, |
370 | struct ci_hdrc_platform_data *platdata) | 393 | struct ci_hdrc_platform_data *platdata) |
371 | { | 394 | { |
372 | /* Get the vbus regulator */ | 395 | if (!platdata->phy_mode) |
373 | platdata->reg_vbus = devm_regulator_get(dev, "vbus"); | 396 | platdata->phy_mode = of_usb_get_phy_mode(dev->of_node); |
374 | if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) { | 397 | |
375 | return -EPROBE_DEFER; | 398 | if (!platdata->dr_mode) |
376 | } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) { | 399 | platdata->dr_mode = of_usb_get_dr_mode(dev->of_node); |
377 | platdata->reg_vbus = NULL; /* no vbus regualator is needed */ | 400 | |
378 | } else if (IS_ERR(platdata->reg_vbus)) { | 401 | if (platdata->dr_mode == USB_DR_MODE_UNKNOWN) |
379 | dev_err(dev, "Getting regulator error: %ld\n", | 402 | platdata->dr_mode = USB_DR_MODE_OTG; |
380 | PTR_ERR(platdata->reg_vbus)); | 403 | |
381 | return PTR_ERR(platdata->reg_vbus); | 404 | if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) { |
405 | /* Get the vbus regulator */ | ||
406 | platdata->reg_vbus = devm_regulator_get(dev, "vbus"); | ||
407 | if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) { | ||
408 | return -EPROBE_DEFER; | ||
409 | } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) { | ||
410 | /* no vbus regualator is needed */ | ||
411 | platdata->reg_vbus = NULL; | ||
412 | } else if (IS_ERR(platdata->reg_vbus)) { | ||
413 | dev_err(dev, "Getting regulator error: %ld\n", | ||
414 | PTR_ERR(platdata->reg_vbus)); | ||
415 | return PTR_ERR(platdata->reg_vbus); | ||
416 | } | ||
382 | } | 417 | } |
383 | 418 | ||
384 | return 0; | 419 | return 0; |
@@ -465,6 +500,33 @@ static void ci_get_otg_capable(struct ci_hdrc *ci) | |||
465 | } | 500 | } |
466 | } | 501 | } |
467 | 502 | ||
503 | static int ci_usb_phy_init(struct ci_hdrc *ci) | ||
504 | { | ||
505 | if (ci->platdata->phy) { | ||
506 | ci->transceiver = ci->platdata->phy; | ||
507 | return usb_phy_init(ci->transceiver); | ||
508 | } else { | ||
509 | ci->global_phy = true; | ||
510 | ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); | ||
511 | if (IS_ERR(ci->transceiver)) | ||
512 | ci->transceiver = NULL; | ||
513 | |||
514 | return 0; | ||
515 | } | ||
516 | } | ||
517 | |||
518 | static void ci_usb_phy_destroy(struct ci_hdrc *ci) | ||
519 | { | ||
520 | if (!ci->transceiver) | ||
521 | return; | ||
522 | |||
523 | otg_set_peripheral(ci->transceiver->otg, NULL); | ||
524 | if (ci->global_phy) | ||
525 | usb_put_phy(ci->transceiver); | ||
526 | else | ||
527 | usb_phy_shutdown(ci->transceiver); | ||
528 | } | ||
529 | |||
468 | static int ci_hdrc_probe(struct platform_device *pdev) | 530 | static int ci_hdrc_probe(struct platform_device *pdev) |
469 | { | 531 | { |
470 | struct device *dev = &pdev->dev; | 532 | struct device *dev = &pdev->dev; |
@@ -473,7 +535,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
473 | void __iomem *base; | 535 | void __iomem *base; |
474 | int ret; | 536 | int ret; |
475 | enum usb_dr_mode dr_mode; | 537 | enum usb_dr_mode dr_mode; |
476 | struct device_node *of_node = dev->of_node ?: dev->parent->of_node; | ||
477 | 538 | ||
478 | if (!dev->platform_data) { | 539 | if (!dev->platform_data) { |
479 | dev_err(dev, "platform data missing\n"); | 540 | dev_err(dev, "platform data missing\n"); |
@@ -493,10 +554,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
493 | 554 | ||
494 | ci->dev = dev; | 555 | ci->dev = dev; |
495 | ci->platdata = dev->platform_data; | 556 | ci->platdata = dev->platform_data; |
496 | if (ci->platdata->phy) | ||
497 | ci->transceiver = ci->platdata->phy; | ||
498 | else | ||
499 | ci->global_phy = true; | ||
500 | 557 | ||
501 | ret = hw_device_init(ci, base); | 558 | ret = hw_device_init(ci, base); |
502 | if (ret < 0) { | 559 | if (ret < 0) { |
@@ -504,27 +561,25 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
504 | return -ENODEV; | 561 | return -ENODEV; |
505 | } | 562 | } |
506 | 563 | ||
564 | ret = ci_usb_phy_init(ci); | ||
565 | if (ret) { | ||
566 | dev_err(dev, "unable to init phy: %d\n", ret); | ||
567 | return ret; | ||
568 | } | ||
569 | |||
507 | ci->hw_bank.phys = res->start; | 570 | ci->hw_bank.phys = res->start; |
508 | 571 | ||
509 | ci->irq = platform_get_irq(pdev, 0); | 572 | ci->irq = platform_get_irq(pdev, 0); |
510 | if (ci->irq < 0) { | 573 | if (ci->irq < 0) { |
511 | dev_err(dev, "missing IRQ\n"); | 574 | dev_err(dev, "missing IRQ\n"); |
512 | return -ENODEV; | 575 | ret = -ENODEV; |
576 | goto destroy_phy; | ||
513 | } | 577 | } |
514 | 578 | ||
515 | ci_get_otg_capable(ci); | 579 | ci_get_otg_capable(ci); |
516 | 580 | ||
517 | if (!ci->platdata->phy_mode) | ||
518 | ci->platdata->phy_mode = of_usb_get_phy_mode(of_node); | ||
519 | |||
520 | hw_phymode_configure(ci); | 581 | hw_phymode_configure(ci); |
521 | 582 | ||
522 | if (!ci->platdata->dr_mode) | ||
523 | ci->platdata->dr_mode = of_usb_get_dr_mode(of_node); | ||
524 | |||
525 | if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN) | ||
526 | ci->platdata->dr_mode = USB_DR_MODE_OTG; | ||
527 | |||
528 | dr_mode = ci->platdata->dr_mode; | 583 | dr_mode = ci->platdata->dr_mode; |
529 | /* initialize role(s) before the interrupt is requested */ | 584 | /* initialize role(s) before the interrupt is requested */ |
530 | if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { | 585 | if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { |
@@ -537,11 +592,23 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
537 | ret = ci_hdrc_gadget_init(ci); | 592 | ret = ci_hdrc_gadget_init(ci); |
538 | if (ret) | 593 | if (ret) |
539 | dev_info(dev, "doesn't support gadget\n"); | 594 | dev_info(dev, "doesn't support gadget\n"); |
595 | if (!ret && ci->transceiver) { | ||
596 | ret = otg_set_peripheral(ci->transceiver->otg, | ||
597 | &ci->gadget); | ||
598 | /* | ||
599 | * If we implement all USB functions using chipidea drivers, | ||
600 | * it doesn't need to call above API, meanwhile, if we only | ||
601 | * use gadget function, calling above API is useless. | ||
602 | */ | ||
603 | if (ret && ret != -ENOTSUPP) | ||
604 | goto destroy_phy; | ||
605 | } | ||
540 | } | 606 | } |
541 | 607 | ||
542 | if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { | 608 | if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { |
543 | dev_err(dev, "no supported roles\n"); | 609 | dev_err(dev, "no supported roles\n"); |
544 | return -ENODEV; | 610 | ret = -ENODEV; |
611 | goto destroy_phy; | ||
545 | } | 612 | } |
546 | 613 | ||
547 | if (ci->is_otg) { | 614 | if (ci->is_otg) { |
@@ -594,6 +661,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
594 | free_irq(ci->irq, ci); | 661 | free_irq(ci->irq, ci); |
595 | stop: | 662 | stop: |
596 | ci_role_destroy(ci); | 663 | ci_role_destroy(ci); |
664 | destroy_phy: | ||
665 | ci_usb_phy_destroy(ci); | ||
597 | 666 | ||
598 | return ret; | 667 | return ret; |
599 | } | 668 | } |
@@ -605,6 +674,8 @@ static int ci_hdrc_remove(struct platform_device *pdev) | |||
605 | dbg_remove_files(ci); | 674 | dbg_remove_files(ci); |
606 | free_irq(ci->irq, ci); | 675 | free_irq(ci->irq, ci); |
607 | ci_role_destroy(ci); | 676 | ci_role_destroy(ci); |
677 | ci_hdrc_enter_lpm(ci, true); | ||
678 | ci_usb_phy_destroy(ci); | ||
608 | kfree(ci->hw_bank.regmap); | 679 | kfree(ci->hw_bank.regmap); |
609 | 680 | ||
610 | return 0; | 681 | return 0; |
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 64d7a6d9a1ad..59e6020ea753 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c | |||
@@ -103,15 +103,15 @@ static void host_stop(struct ci_hdrc *ci) | |||
103 | if (hcd) { | 103 | if (hcd) { |
104 | usb_remove_hcd(hcd); | 104 | usb_remove_hcd(hcd); |
105 | usb_put_hcd(hcd); | 105 | usb_put_hcd(hcd); |
106 | if (ci->platdata->reg_vbus) | ||
107 | regulator_disable(ci->platdata->reg_vbus); | ||
106 | } | 108 | } |
107 | if (ci->platdata->reg_vbus) | ||
108 | regulator_disable(ci->platdata->reg_vbus); | ||
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | void ci_hdrc_host_destroy(struct ci_hdrc *ci) | 112 | void ci_hdrc_host_destroy(struct ci_hdrc *ci) |
113 | { | 113 | { |
114 | if (ci->role == CI_ROLE_HOST) | 114 | if (ci->role == CI_ROLE_HOST && ci->hcd) |
115 | host_stop(ci); | 115 | host_stop(ci); |
116 | } | 116 | } |
117 | 117 | ||
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 9333083dd111..b34c81969cba 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/pm_runtime.h> | 20 | #include <linux/pm_runtime.h> |
21 | #include <linux/usb/ch9.h> | 21 | #include <linux/usb/ch9.h> |
22 | #include <linux/usb/gadget.h> | 22 | #include <linux/usb/gadget.h> |
23 | #include <linux/usb/otg.h> | ||
24 | #include <linux/usb/chipidea.h> | 23 | #include <linux/usb/chipidea.h> |
25 | 24 | ||
26 | #include "ci.h" | 25 | #include "ci.h" |
@@ -686,9 +685,6 @@ static int _gadget_stop_activity(struct usb_gadget *gadget) | |||
686 | usb_ep_fifo_flush(&ci->ep0out->ep); | 685 | usb_ep_fifo_flush(&ci->ep0out->ep); |
687 | usb_ep_fifo_flush(&ci->ep0in->ep); | 686 | usb_ep_fifo_flush(&ci->ep0in->ep); |
688 | 687 | ||
689 | if (ci->driver) | ||
690 | ci->driver->disconnect(gadget); | ||
691 | |||
692 | /* make sure to disable all endpoints */ | 688 | /* make sure to disable all endpoints */ |
693 | gadget_for_each_ep(ep, gadget) { | 689 | gadget_for_each_ep(ep, gadget) { |
694 | usb_ep_disable(ep); | 690 | usb_ep_disable(ep); |
@@ -718,6 +714,11 @@ __acquires(ci->lock) | |||
718 | int retval; | 714 | int retval; |
719 | 715 | ||
720 | spin_unlock(&ci->lock); | 716 | spin_unlock(&ci->lock); |
717 | if (ci->gadget.speed != USB_SPEED_UNKNOWN) { | ||
718 | if (ci->driver) | ||
719 | ci->driver->disconnect(&ci->gadget); | ||
720 | } | ||
721 | |||
721 | retval = _gadget_stop_activity(&ci->gadget); | 722 | retval = _gadget_stop_activity(&ci->gadget); |
722 | if (retval) | 723 | if (retval) |
723 | goto done; | 724 | goto done; |
@@ -1461,6 +1462,8 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) | |||
1461 | hw_device_state(ci, ci->ep0out->qh.dma); | 1462 | hw_device_state(ci, ci->ep0out->qh.dma); |
1462 | dev_dbg(ci->dev, "Connected to host\n"); | 1463 | dev_dbg(ci->dev, "Connected to host\n"); |
1463 | } else { | 1464 | } else { |
1465 | if (ci->driver) | ||
1466 | ci->driver->disconnect(&ci->gadget); | ||
1464 | hw_device_state(ci, 0); | 1467 | hw_device_state(ci, 0); |
1465 | if (ci->platdata->notify_event) | 1468 | if (ci->platdata->notify_event) |
1466 | ci->platdata->notify_event(ci, | 1469 | ci->platdata->notify_event(ci, |
@@ -1633,23 +1636,22 @@ static int ci_udc_start(struct usb_gadget *gadget, | |||
1633 | retval = usb_ep_enable(&ci->ep0in->ep); | 1636 | retval = usb_ep_enable(&ci->ep0in->ep); |
1634 | if (retval) | 1637 | if (retval) |
1635 | return retval; | 1638 | return retval; |
1636 | spin_lock_irqsave(&ci->lock, flags); | ||
1637 | 1639 | ||
1638 | ci->driver = driver; | 1640 | ci->driver = driver; |
1639 | pm_runtime_get_sync(&ci->gadget.dev); | 1641 | pm_runtime_get_sync(&ci->gadget.dev); |
1640 | if (ci->vbus_active) { | 1642 | if (ci->vbus_active) { |
1643 | spin_lock_irqsave(&ci->lock, flags); | ||
1641 | hw_device_reset(ci, USBMODE_CM_DC); | 1644 | hw_device_reset(ci, USBMODE_CM_DC); |
1642 | } else { | 1645 | } else { |
1643 | pm_runtime_put_sync(&ci->gadget.dev); | 1646 | pm_runtime_put_sync(&ci->gadget.dev); |
1644 | goto done; | 1647 | return retval; |
1645 | } | 1648 | } |
1646 | 1649 | ||
1647 | retval = hw_device_state(ci, ci->ep0out->qh.dma); | 1650 | retval = hw_device_state(ci, ci->ep0out->qh.dma); |
1651 | spin_unlock_irqrestore(&ci->lock, flags); | ||
1648 | if (retval) | 1652 | if (retval) |
1649 | pm_runtime_put_sync(&ci->gadget.dev); | 1653 | pm_runtime_put_sync(&ci->gadget.dev); |
1650 | 1654 | ||
1651 | done: | ||
1652 | spin_unlock_irqrestore(&ci->lock, flags); | ||
1653 | return retval; | 1655 | return retval; |
1654 | } | 1656 | } |
1655 | 1657 | ||
@@ -1786,34 +1788,9 @@ static int udc_start(struct ci_hdrc *ci) | |||
1786 | 1788 | ||
1787 | ci->gadget.ep0 = &ci->ep0in->ep; | 1789 | ci->gadget.ep0 = &ci->ep0in->ep; |
1788 | 1790 | ||
1789 | if (ci->global_phy) { | ||
1790 | ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); | ||
1791 | if (IS_ERR(ci->transceiver)) | ||
1792 | ci->transceiver = NULL; | ||
1793 | } | ||
1794 | |||
1795 | if (ci->platdata->flags & CI_HDRC_REQUIRE_TRANSCEIVER) { | ||
1796 | if (ci->transceiver == NULL) { | ||
1797 | retval = -ENODEV; | ||
1798 | goto destroy_eps; | ||
1799 | } | ||
1800 | } | ||
1801 | |||
1802 | if (ci->transceiver) { | ||
1803 | retval = otg_set_peripheral(ci->transceiver->otg, | ||
1804 | &ci->gadget); | ||
1805 | /* | ||
1806 | * If we implement all USB functions using chipidea drivers, | ||
1807 | * it doesn't need to call above API, meanwhile, if we only | ||
1808 | * use gadget function, calling above API is useless. | ||
1809 | */ | ||
1810 | if (retval && retval != -ENOTSUPP) | ||
1811 | goto put_transceiver; | ||
1812 | } | ||
1813 | |||
1814 | retval = usb_add_gadget_udc(dev, &ci->gadget); | 1791 | retval = usb_add_gadget_udc(dev, &ci->gadget); |
1815 | if (retval) | 1792 | if (retval) |
1816 | goto remove_trans; | 1793 | goto destroy_eps; |
1817 | 1794 | ||
1818 | pm_runtime_no_callbacks(&ci->gadget.dev); | 1795 | pm_runtime_no_callbacks(&ci->gadget.dev); |
1819 | pm_runtime_enable(&ci->gadget.dev); | 1796 | pm_runtime_enable(&ci->gadget.dev); |
@@ -1823,17 +1800,6 @@ static int udc_start(struct ci_hdrc *ci) | |||
1823 | 1800 | ||
1824 | return retval; | 1801 | return retval; |
1825 | 1802 | ||
1826 | remove_trans: | ||
1827 | if (ci->transceiver) { | ||
1828 | otg_set_peripheral(ci->transceiver->otg, NULL); | ||
1829 | if (ci->global_phy) | ||
1830 | usb_put_phy(ci->transceiver); | ||
1831 | } | ||
1832 | |||
1833 | dev_err(dev, "error = %i\n", retval); | ||
1834 | put_transceiver: | ||
1835 | if (ci->transceiver && ci->global_phy) | ||
1836 | usb_put_phy(ci->transceiver); | ||
1837 | destroy_eps: | 1803 | destroy_eps: |
1838 | destroy_eps(ci); | 1804 | destroy_eps(ci); |
1839 | free_pools: | 1805 | free_pools: |
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index d3318a0df8ee..4d387596f3f0 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c | |||
@@ -101,6 +101,7 @@ struct wdm_device { | |||
101 | struct work_struct rxwork; | 101 | struct work_struct rxwork; |
102 | int werr; | 102 | int werr; |
103 | int rerr; | 103 | int rerr; |
104 | int resp_count; | ||
104 | 105 | ||
105 | struct list_head device_list; | 106 | struct list_head device_list; |
106 | int (*manage_power)(struct usb_interface *, int); | 107 | int (*manage_power)(struct usb_interface *, int); |
@@ -253,6 +254,10 @@ static void wdm_int_callback(struct urb *urb) | |||
253 | "NOTIFY_NETWORK_CONNECTION %s network", | 254 | "NOTIFY_NETWORK_CONNECTION %s network", |
254 | dr->wValue ? "connected to" : "disconnected from"); | 255 | dr->wValue ? "connected to" : "disconnected from"); |
255 | goto exit; | 256 | goto exit; |
257 | case USB_CDC_NOTIFY_SPEED_CHANGE: | ||
258 | dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)", | ||
259 | urb->actual_length); | ||
260 | goto exit; | ||
256 | default: | 261 | default: |
257 | clear_bit(WDM_POLL_RUNNING, &desc->flags); | 262 | clear_bit(WDM_POLL_RUNNING, &desc->flags); |
258 | dev_err(&desc->intf->dev, | 263 | dev_err(&desc->intf->dev, |
@@ -262,9 +267,9 @@ static void wdm_int_callback(struct urb *urb) | |||
262 | } | 267 | } |
263 | 268 | ||
264 | spin_lock(&desc->iuspin); | 269 | spin_lock(&desc->iuspin); |
265 | clear_bit(WDM_READ, &desc->flags); | ||
266 | responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); | 270 | responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); |
267 | if (!responding && !test_bit(WDM_DISCONNECTING, &desc->flags) | 271 | if (!desc->resp_count++ && !responding |
272 | && !test_bit(WDM_DISCONNECTING, &desc->flags) | ||
268 | && !test_bit(WDM_SUSPENDING, &desc->flags)) { | 273 | && !test_bit(WDM_SUSPENDING, &desc->flags)) { |
269 | rv = usb_submit_urb(desc->response, GFP_ATOMIC); | 274 | rv = usb_submit_urb(desc->response, GFP_ATOMIC); |
270 | dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", | 275 | dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", |
@@ -521,10 +526,36 @@ retry: | |||
521 | 526 | ||
522 | desc->length -= cntr; | 527 | desc->length -= cntr; |
523 | /* in case we had outstanding data */ | 528 | /* in case we had outstanding data */ |
524 | if (!desc->length) | 529 | if (!desc->length) { |
525 | clear_bit(WDM_READ, &desc->flags); | 530 | clear_bit(WDM_READ, &desc->flags); |
526 | 531 | ||
527 | spin_unlock_irq(&desc->iuspin); | 532 | if (--desc->resp_count) { |
533 | set_bit(WDM_RESPONDING, &desc->flags); | ||
534 | spin_unlock_irq(&desc->iuspin); | ||
535 | |||
536 | rv = usb_submit_urb(desc->response, GFP_KERNEL); | ||
537 | if (rv) { | ||
538 | dev_err(&desc->intf->dev, | ||
539 | "%s: usb_submit_urb failed with result %d\n", | ||
540 | __func__, rv); | ||
541 | spin_lock_irq(&desc->iuspin); | ||
542 | clear_bit(WDM_RESPONDING, &desc->flags); | ||
543 | spin_unlock_irq(&desc->iuspin); | ||
544 | |||
545 | if (rv == -ENOMEM) { | ||
546 | rv = schedule_work(&desc->rxwork); | ||
547 | if (rv) | ||
548 | dev_err(&desc->intf->dev, "Cannot schedule work\n"); | ||
549 | } else { | ||
550 | spin_lock_irq(&desc->iuspin); | ||
551 | desc->resp_count = 0; | ||
552 | spin_unlock_irq(&desc->iuspin); | ||
553 | } | ||
554 | } | ||
555 | } else | ||
556 | spin_unlock_irq(&desc->iuspin); | ||
557 | } else | ||
558 | spin_unlock_irq(&desc->iuspin); | ||
528 | 559 | ||
529 | rv = cntr; | 560 | rv = cntr; |
530 | 561 | ||
@@ -635,6 +666,9 @@ static int wdm_release(struct inode *inode, struct file *file) | |||
635 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { | 666 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { |
636 | dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); | 667 | dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); |
637 | kill_urbs(desc); | 668 | kill_urbs(desc); |
669 | spin_lock_irq(&desc->iuspin); | ||
670 | desc->resp_count = 0; | ||
671 | spin_unlock_irq(&desc->iuspin); | ||
638 | desc->manage_power(desc->intf, 0); | 672 | desc->manage_power(desc->intf, 0); |
639 | } else { | 673 | } else { |
640 | /* must avoid dev_printk here as desc->intf is invalid */ | 674 | /* must avoid dev_printk here as desc->intf is invalid */ |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 71dc5d768fa5..967152a63bd3 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -914,10 +914,8 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
914 | snoop(&dev->dev, "control urb: bRequestType=%02x " | 914 | snoop(&dev->dev, "control urb: bRequestType=%02x " |
915 | "bRequest=%02x wValue=%04x " | 915 | "bRequest=%02x wValue=%04x " |
916 | "wIndex=%04x wLength=%04x\n", | 916 | "wIndex=%04x wLength=%04x\n", |
917 | ctrl.bRequestType, ctrl.bRequest, | 917 | ctrl.bRequestType, ctrl.bRequest, ctrl.wValue, |
918 | __le16_to_cpup(&ctrl.wValue), | 918 | ctrl.wIndex, ctrl.wLength); |
919 | __le16_to_cpup(&ctrl.wIndex), | ||
920 | __le16_to_cpup(&ctrl.wLength)); | ||
921 | if (ctrl.bRequestType & 0x80) { | 919 | if (ctrl.bRequestType & 0x80) { |
922 | if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, | 920 | if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, |
923 | ctrl.wLength)) { | 921 | ctrl.wLength)) { |
@@ -1636,32 +1634,32 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg) | |||
1636 | static int proc_control_compat(struct dev_state *ps, | 1634 | static int proc_control_compat(struct dev_state *ps, |
1637 | struct usbdevfs_ctrltransfer32 __user *p32) | 1635 | struct usbdevfs_ctrltransfer32 __user *p32) |
1638 | { | 1636 | { |
1639 | struct usbdevfs_ctrltransfer __user *p; | 1637 | struct usbdevfs_ctrltransfer __user *p; |
1640 | __u32 udata; | 1638 | __u32 udata; |
1641 | p = compat_alloc_user_space(sizeof(*p)); | 1639 | p = compat_alloc_user_space(sizeof(*p)); |
1642 | if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || | 1640 | if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || |
1643 | get_user(udata, &p32->data) || | 1641 | get_user(udata, &p32->data) || |
1644 | put_user(compat_ptr(udata), &p->data)) | 1642 | put_user(compat_ptr(udata), &p->data)) |
1645 | return -EFAULT; | 1643 | return -EFAULT; |
1646 | return proc_control(ps, p); | 1644 | return proc_control(ps, p); |
1647 | } | 1645 | } |
1648 | 1646 | ||
1649 | static int proc_bulk_compat(struct dev_state *ps, | 1647 | static int proc_bulk_compat(struct dev_state *ps, |
1650 | struct usbdevfs_bulktransfer32 __user *p32) | 1648 | struct usbdevfs_bulktransfer32 __user *p32) |
1651 | { | 1649 | { |
1652 | struct usbdevfs_bulktransfer __user *p; | 1650 | struct usbdevfs_bulktransfer __user *p; |
1653 | compat_uint_t n; | 1651 | compat_uint_t n; |
1654 | compat_caddr_t addr; | 1652 | compat_caddr_t addr; |
1655 | 1653 | ||
1656 | p = compat_alloc_user_space(sizeof(*p)); | 1654 | p = compat_alloc_user_space(sizeof(*p)); |
1657 | 1655 | ||
1658 | if (get_user(n, &p32->ep) || put_user(n, &p->ep) || | 1656 | if (get_user(n, &p32->ep) || put_user(n, &p->ep) || |
1659 | get_user(n, &p32->len) || put_user(n, &p->len) || | 1657 | get_user(n, &p32->len) || put_user(n, &p->len) || |
1660 | get_user(n, &p32->timeout) || put_user(n, &p->timeout) || | 1658 | get_user(n, &p32->timeout) || put_user(n, &p->timeout) || |
1661 | get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) | 1659 | get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) |
1662 | return -EFAULT; | 1660 | return -EFAULT; |
1663 | 1661 | ||
1664 | return proc_bulk(ps, p); | 1662 | return proc_bulk(ps, p); |
1665 | } | 1663 | } |
1666 | static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg) | 1664 | static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg) |
1667 | { | 1665 | { |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index f7841d44feda..47aade2a5e74 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -1179,8 +1179,8 @@ static int usb_resume_interface(struct usb_device *udev, | |||
1179 | "reset_resume", status); | 1179 | "reset_resume", status); |
1180 | } else { | 1180 | } else { |
1181 | intf->needs_binding = 1; | 1181 | intf->needs_binding = 1; |
1182 | dev_warn(&intf->dev, "no %s for driver %s?\n", | 1182 | dev_dbg(&intf->dev, "no reset_resume for driver %s?\n", |
1183 | "reset_resume", driver->name); | 1183 | driver->name); |
1184 | } | 1184 | } |
1185 | } else { | 1185 | } else { |
1186 | status = driver->resume(intf); | 1186 | status = driver->resume(intf); |
@@ -1790,6 +1790,9 @@ int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) | |||
1790 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 1790 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1791 | int ret = -EPERM; | 1791 | int ret = -EPERM; |
1792 | 1792 | ||
1793 | if (enable && !udev->usb2_hw_lpm_allowed) | ||
1794 | return 0; | ||
1795 | |||
1793 | if (hcd->driver->set_usb2_hw_lpm) { | 1796 | if (hcd->driver->set_usb2_hw_lpm) { |
1794 | ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); | 1797 | ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); |
1795 | if (!ret) | 1798 | if (!ret) |
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c index 7421888087a3..3bdfbf88a0ae 100644 --- a/drivers/usb/core/file.c +++ b/drivers/usb/core/file.c | |||
@@ -8,7 +8,7 @@ | |||
8 | * (C) Copyright Deti Fliegl 1999 (new USB architecture) | 8 | * (C) Copyright Deti Fliegl 1999 (new USB architecture) |
9 | * (C) Copyright Randy Dunlap 2000 | 9 | * (C) Copyright Randy Dunlap 2000 |
10 | * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id, | 10 | * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id, |
11 | more docs, etc) | 11 | * more docs, etc) |
12 | * (C) Copyright Yggdrasil Computing, Inc. 2000 | 12 | * (C) Copyright Yggdrasil Computing, Inc. 2000 |
13 | * (usb_device_id matching changes by Adam J. Richter) | 13 | * (usb_device_id matching changes by Adam J. Richter) |
14 | * (C) Copyright Greg Kroah-Hartman 2002-2003 | 14 | * (C) Copyright Greg Kroah-Hartman 2002-2003 |
@@ -27,7 +27,7 @@ | |||
27 | static const struct file_operations *usb_minors[MAX_USB_MINORS]; | 27 | static const struct file_operations *usb_minors[MAX_USB_MINORS]; |
28 | static DECLARE_RWSEM(minor_rwsem); | 28 | static DECLARE_RWSEM(minor_rwsem); |
29 | 29 | ||
30 | static int usb_open(struct inode * inode, struct file * file) | 30 | static int usb_open(struct inode *inode, struct file *file) |
31 | { | 31 | { |
32 | int minor = iminor(inode); | 32 | int minor = iminor(inode); |
33 | const struct file_operations *c; | 33 | const struct file_operations *c; |
@@ -44,7 +44,7 @@ static int usb_open(struct inode * inode, struct file * file) | |||
44 | file->f_op = new_fops; | 44 | file->f_op = new_fops; |
45 | /* Curiouser and curiouser... NULL ->open() as "no device" ? */ | 45 | /* Curiouser and curiouser... NULL ->open() as "no device" ? */ |
46 | if (file->f_op->open) | 46 | if (file->f_op->open) |
47 | err = file->f_op->open(inode,file); | 47 | err = file->f_op->open(inode, file); |
48 | if (err) { | 48 | if (err) { |
49 | fops_put(file->f_op); | 49 | fops_put(file->f_op); |
50 | file->f_op = fops_get(old_fops); | 50 | file->f_op = fops_get(old_fops); |
@@ -166,7 +166,7 @@ int usb_register_dev(struct usb_interface *intf, | |||
166 | char *temp; | 166 | char *temp; |
167 | 167 | ||
168 | #ifdef CONFIG_USB_DYNAMIC_MINORS | 168 | #ifdef CONFIG_USB_DYNAMIC_MINORS |
169 | /* | 169 | /* |
170 | * We don't care what the device tries to start at, we want to start | 170 | * We don't care what the device tries to start at, we want to start |
171 | * at zero to pack the devices into the smallest available space with | 171 | * at zero to pack the devices into the smallest available space with |
172 | * no holes in the minor range. | 172 | * no holes in the minor range. |
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index b9d3c43e3859..dfe9d0f22978 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -215,6 +215,9 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
215 | goto disable_pci; | 215 | goto disable_pci; |
216 | } | 216 | } |
217 | 217 | ||
218 | hcd->amd_resume_bug = (usb_hcd_amd_remote_wakeup_quirk(dev) && | ||
219 | driver->flags & (HCD_USB11 | HCD_USB3)) ? 1 : 0; | ||
220 | |||
218 | if (driver->flags & HCD_MEMORY) { | 221 | if (driver->flags & HCD_MEMORY) { |
219 | /* EHCI, OHCI */ | 222 | /* EHCI, OHCI */ |
220 | hcd->rsrc_start = pci_resource_start(dev, 0); | 223 | hcd->rsrc_start = pci_resource_start(dev, 0); |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index d6a8d23f047b..6bffb8c87bc9 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * (C) Copyright Deti Fliegl 1999 | 6 | * (C) Copyright Deti Fliegl 1999 |
7 | * (C) Copyright Randy Dunlap 2000 | 7 | * (C) Copyright Randy Dunlap 2000 |
8 | * (C) Copyright David Brownell 2000-2002 | 8 | * (C) Copyright David Brownell 2000-2002 |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify it | 10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public License as published by the | 11 | * under the terms of the GNU General Public License as published by the |
12 | * Free Software Foundation; either version 2 of the License, or (at your | 12 | * Free Software Foundation; either version 2 of the License, or (at your |
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/platform_device.h> | 40 | #include <linux/platform_device.h> |
41 | #include <linux/workqueue.h> | 41 | #include <linux/workqueue.h> |
42 | #include <linux/pm_runtime.h> | 42 | #include <linux/pm_runtime.h> |
43 | #include <linux/types.h> | ||
43 | 44 | ||
44 | #include <linux/usb.h> | 45 | #include <linux/usb.h> |
45 | #include <linux/usb/hcd.h> | 46 | #include <linux/usb/hcd.h> |
@@ -92,10 +93,7 @@ EXPORT_SYMBOL_GPL (usb_bus_list); | |||
92 | 93 | ||
93 | /* used when allocating bus numbers */ | 94 | /* used when allocating bus numbers */ |
94 | #define USB_MAXBUS 64 | 95 | #define USB_MAXBUS 64 |
95 | struct usb_busmap { | 96 | static DECLARE_BITMAP(busmap, USB_MAXBUS); |
96 | unsigned long busmap [USB_MAXBUS / (8*sizeof (unsigned long))]; | ||
97 | }; | ||
98 | static struct usb_busmap busmap; | ||
99 | 97 | ||
100 | /* used when updating list of hcds */ | 98 | /* used when updating list of hcds */ |
101 | DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */ | 99 | DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */ |
@@ -171,7 +169,7 @@ static const u8 usb25_rh_dev_descriptor[18] = { | |||
171 | }; | 169 | }; |
172 | 170 | ||
173 | /* usb 2.0 root hub device descriptor */ | 171 | /* usb 2.0 root hub device descriptor */ |
174 | static const u8 usb2_rh_dev_descriptor [18] = { | 172 | static const u8 usb2_rh_dev_descriptor[18] = { |
175 | 0x12, /* __u8 bLength; */ | 173 | 0x12, /* __u8 bLength; */ |
176 | 0x01, /* __u8 bDescriptorType; Device */ | 174 | 0x01, /* __u8 bDescriptorType; Device */ |
177 | 0x00, 0x02, /* __le16 bcdUSB; v2.0 */ | 175 | 0x00, 0x02, /* __le16 bcdUSB; v2.0 */ |
@@ -194,7 +192,7 @@ static const u8 usb2_rh_dev_descriptor [18] = { | |||
194 | /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */ | 192 | /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */ |
195 | 193 | ||
196 | /* usb 1.1 root hub device descriptor */ | 194 | /* usb 1.1 root hub device descriptor */ |
197 | static const u8 usb11_rh_dev_descriptor [18] = { | 195 | static const u8 usb11_rh_dev_descriptor[18] = { |
198 | 0x12, /* __u8 bLength; */ | 196 | 0x12, /* __u8 bLength; */ |
199 | 0x01, /* __u8 bDescriptorType; Device */ | 197 | 0x01, /* __u8 bDescriptorType; Device */ |
200 | 0x10, 0x01, /* __le16 bcdUSB; v1.1 */ | 198 | 0x10, 0x01, /* __le16 bcdUSB; v1.1 */ |
@@ -219,7 +217,7 @@ static const u8 usb11_rh_dev_descriptor [18] = { | |||
219 | 217 | ||
220 | /* Configuration descriptors for our root hubs */ | 218 | /* Configuration descriptors for our root hubs */ |
221 | 219 | ||
222 | static const u8 fs_rh_config_descriptor [] = { | 220 | static const u8 fs_rh_config_descriptor[] = { |
223 | 221 | ||
224 | /* one configuration */ | 222 | /* one configuration */ |
225 | 0x09, /* __u8 bLength; */ | 223 | 0x09, /* __u8 bLength; */ |
@@ -228,13 +226,13 @@ static const u8 fs_rh_config_descriptor [] = { | |||
228 | 0x01, /* __u8 bNumInterfaces; (1) */ | 226 | 0x01, /* __u8 bNumInterfaces; (1) */ |
229 | 0x01, /* __u8 bConfigurationValue; */ | 227 | 0x01, /* __u8 bConfigurationValue; */ |
230 | 0x00, /* __u8 iConfiguration; */ | 228 | 0x00, /* __u8 iConfiguration; */ |
231 | 0xc0, /* __u8 bmAttributes; | 229 | 0xc0, /* __u8 bmAttributes; |
232 | Bit 7: must be set, | 230 | Bit 7: must be set, |
233 | 6: Self-powered, | 231 | 6: Self-powered, |
234 | 5: Remote wakeup, | 232 | 5: Remote wakeup, |
235 | 4..0: resvd */ | 233 | 4..0: resvd */ |
236 | 0x00, /* __u8 MaxPower; */ | 234 | 0x00, /* __u8 MaxPower; */ |
237 | 235 | ||
238 | /* USB 1.1: | 236 | /* USB 1.1: |
239 | * USB 2.0, single TT organization (mandatory): | 237 | * USB 2.0, single TT organization (mandatory): |
240 | * one interface, protocol 0 | 238 | * one interface, protocol 0 |
@@ -256,17 +254,17 @@ static const u8 fs_rh_config_descriptor [] = { | |||
256 | 0x00, /* __u8 if_bInterfaceSubClass; */ | 254 | 0x00, /* __u8 if_bInterfaceSubClass; */ |
257 | 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ | 255 | 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ |
258 | 0x00, /* __u8 if_iInterface; */ | 256 | 0x00, /* __u8 if_iInterface; */ |
259 | 257 | ||
260 | /* one endpoint (status change endpoint) */ | 258 | /* one endpoint (status change endpoint) */ |
261 | 0x07, /* __u8 ep_bLength; */ | 259 | 0x07, /* __u8 ep_bLength; */ |
262 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ | 260 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ |
263 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ | 261 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ |
264 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ | 262 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ |
265 | 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */ | 263 | 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */ |
266 | 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */ | 264 | 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
267 | }; | 265 | }; |
268 | 266 | ||
269 | static const u8 hs_rh_config_descriptor [] = { | 267 | static const u8 hs_rh_config_descriptor[] = { |
270 | 268 | ||
271 | /* one configuration */ | 269 | /* one configuration */ |
272 | 0x09, /* __u8 bLength; */ | 270 | 0x09, /* __u8 bLength; */ |
@@ -275,13 +273,13 @@ static const u8 hs_rh_config_descriptor [] = { | |||
275 | 0x01, /* __u8 bNumInterfaces; (1) */ | 273 | 0x01, /* __u8 bNumInterfaces; (1) */ |
276 | 0x01, /* __u8 bConfigurationValue; */ | 274 | 0x01, /* __u8 bConfigurationValue; */ |
277 | 0x00, /* __u8 iConfiguration; */ | 275 | 0x00, /* __u8 iConfiguration; */ |
278 | 0xc0, /* __u8 bmAttributes; | 276 | 0xc0, /* __u8 bmAttributes; |
279 | Bit 7: must be set, | 277 | Bit 7: must be set, |
280 | 6: Self-powered, | 278 | 6: Self-powered, |
281 | 5: Remote wakeup, | 279 | 5: Remote wakeup, |
282 | 4..0: resvd */ | 280 | 4..0: resvd */ |
283 | 0x00, /* __u8 MaxPower; */ | 281 | 0x00, /* __u8 MaxPower; */ |
284 | 282 | ||
285 | /* USB 1.1: | 283 | /* USB 1.1: |
286 | * USB 2.0, single TT organization (mandatory): | 284 | * USB 2.0, single TT organization (mandatory): |
287 | * one interface, protocol 0 | 285 | * one interface, protocol 0 |
@@ -303,12 +301,12 @@ static const u8 hs_rh_config_descriptor [] = { | |||
303 | 0x00, /* __u8 if_bInterfaceSubClass; */ | 301 | 0x00, /* __u8 if_bInterfaceSubClass; */ |
304 | 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ | 302 | 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ |
305 | 0x00, /* __u8 if_iInterface; */ | 303 | 0x00, /* __u8 if_iInterface; */ |
306 | 304 | ||
307 | /* one endpoint (status change endpoint) */ | 305 | /* one endpoint (status change endpoint) */ |
308 | 0x07, /* __u8 ep_bLength; */ | 306 | 0x07, /* __u8 ep_bLength; */ |
309 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ | 307 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ |
310 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ | 308 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ |
311 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ | 309 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ |
312 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) | 310 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) |
313 | * see hub.c:hub_configure() for details. */ | 311 | * see hub.c:hub_configure() for details. */ |
314 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, | 312 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, |
@@ -428,7 +426,7 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) | |||
428 | char const *s; | 426 | char const *s; |
429 | static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04}; | 427 | static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04}; |
430 | 428 | ||
431 | // language ids | 429 | /* language ids */ |
432 | switch (id) { | 430 | switch (id) { |
433 | case 0: | 431 | case 0: |
434 | /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ | 432 | /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ |
@@ -464,7 +462,7 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) | |||
464 | static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | 462 | static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) |
465 | { | 463 | { |
466 | struct usb_ctrlrequest *cmd; | 464 | struct usb_ctrlrequest *cmd; |
467 | u16 typeReq, wValue, wIndex, wLength; | 465 | u16 typeReq, wValue, wIndex, wLength; |
468 | u8 *ubuf = urb->transfer_buffer; | 466 | u8 *ubuf = urb->transfer_buffer; |
469 | unsigned len = 0; | 467 | unsigned len = 0; |
470 | int status; | 468 | int status; |
@@ -526,10 +524,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
526 | */ | 524 | */ |
527 | 525 | ||
528 | case DeviceRequest | USB_REQ_GET_STATUS: | 526 | case DeviceRequest | USB_REQ_GET_STATUS: |
529 | tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev) | 527 | tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev) |
530 | << USB_DEVICE_REMOTE_WAKEUP) | 528 | << USB_DEVICE_REMOTE_WAKEUP) |
531 | | (1 << USB_DEVICE_SELF_POWERED); | 529 | | (1 << USB_DEVICE_SELF_POWERED); |
532 | tbuf [1] = 0; | 530 | tbuf[1] = 0; |
533 | len = 2; | 531 | len = 2; |
534 | break; | 532 | break; |
535 | case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: | 533 | case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: |
@@ -546,7 +544,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
546 | goto error; | 544 | goto error; |
547 | break; | 545 | break; |
548 | case DeviceRequest | USB_REQ_GET_CONFIGURATION: | 546 | case DeviceRequest | USB_REQ_GET_CONFIGURATION: |
549 | tbuf [0] = 1; | 547 | tbuf[0] = 1; |
550 | len = 1; | 548 | len = 1; |
551 | /* FALLTHROUGH */ | 549 | /* FALLTHROUGH */ |
552 | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: | 550 | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: |
@@ -609,13 +607,13 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
609 | } | 607 | } |
610 | break; | 608 | break; |
611 | case DeviceRequest | USB_REQ_GET_INTERFACE: | 609 | case DeviceRequest | USB_REQ_GET_INTERFACE: |
612 | tbuf [0] = 0; | 610 | tbuf[0] = 0; |
613 | len = 1; | 611 | len = 1; |
614 | /* FALLTHROUGH */ | 612 | /* FALLTHROUGH */ |
615 | case DeviceOutRequest | USB_REQ_SET_INTERFACE: | 613 | case DeviceOutRequest | USB_REQ_SET_INTERFACE: |
616 | break; | 614 | break; |
617 | case DeviceOutRequest | USB_REQ_SET_ADDRESS: | 615 | case DeviceOutRequest | USB_REQ_SET_ADDRESS: |
618 | // wValue == urb->dev->devaddr | 616 | /* wValue == urb->dev->devaddr */ |
619 | dev_dbg (hcd->self.controller, "root hub device address %d\n", | 617 | dev_dbg (hcd->self.controller, "root hub device address %d\n", |
620 | wValue); | 618 | wValue); |
621 | break; | 619 | break; |
@@ -625,9 +623,9 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
625 | /* ENDPOINT REQUESTS */ | 623 | /* ENDPOINT REQUESTS */ |
626 | 624 | ||
627 | case EndpointRequest | USB_REQ_GET_STATUS: | 625 | case EndpointRequest | USB_REQ_GET_STATUS: |
628 | // ENDPOINT_HALT flag | 626 | /* ENDPOINT_HALT flag */ |
629 | tbuf [0] = 0; | 627 | tbuf[0] = 0; |
630 | tbuf [1] = 0; | 628 | tbuf[1] = 0; |
631 | len = 2; | 629 | len = 2; |
632 | /* FALLTHROUGH */ | 630 | /* FALLTHROUGH */ |
633 | case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: | 631 | case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: |
@@ -683,7 +681,7 @@ error: | |||
683 | if (urb->transfer_buffer_length < len) | 681 | if (urb->transfer_buffer_length < len) |
684 | len = urb->transfer_buffer_length; | 682 | len = urb->transfer_buffer_length; |
685 | urb->actual_length = len; | 683 | urb->actual_length = len; |
686 | // always USB_DIR_IN, toward host | 684 | /* always USB_DIR_IN, toward host */ |
687 | memcpy (ubuf, bufp, len); | 685 | memcpy (ubuf, bufp, len); |
688 | 686 | ||
689 | /* report whether RH hardware supports remote wakeup */ | 687 | /* report whether RH hardware supports remote wakeup */ |
@@ -877,11 +875,11 @@ static ssize_t authorized_default_store(struct device *dev, | |||
877 | usb_hcd = bus_to_hcd(usb_bus); | 875 | usb_hcd = bus_to_hcd(usb_bus); |
878 | result = sscanf(buf, "%u\n", &val); | 876 | result = sscanf(buf, "%u\n", &val); |
879 | if (result == 1) { | 877 | if (result == 1) { |
880 | usb_hcd->authorized_default = val? 1 : 0; | 878 | usb_hcd->authorized_default = val ? 1 : 0; |
881 | result = size; | 879 | result = size; |
882 | } | 880 | } else { |
883 | else | ||
884 | result = -EINVAL; | 881 | result = -EINVAL; |
882 | } | ||
885 | return result; | 883 | return result; |
886 | } | 884 | } |
887 | static DEVICE_ATTR_RW(authorized_default); | 885 | static DEVICE_ATTR_RW(authorized_default); |
@@ -941,12 +939,12 @@ static int usb_register_bus(struct usb_bus *bus) | |||
941 | int busnum; | 939 | int busnum; |
942 | 940 | ||
943 | mutex_lock(&usb_bus_list_lock); | 941 | mutex_lock(&usb_bus_list_lock); |
944 | busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); | 942 | busnum = find_next_zero_bit(busmap, USB_MAXBUS, 1); |
945 | if (busnum >= USB_MAXBUS) { | 943 | if (busnum >= USB_MAXBUS) { |
946 | printk (KERN_ERR "%s: too many buses\n", usbcore_name); | 944 | printk (KERN_ERR "%s: too many buses\n", usbcore_name); |
947 | goto error_find_busnum; | 945 | goto error_find_busnum; |
948 | } | 946 | } |
949 | set_bit (busnum, busmap.busmap); | 947 | set_bit(busnum, busmap); |
950 | bus->busnum = busnum; | 948 | bus->busnum = busnum; |
951 | 949 | ||
952 | /* Add it to the local list of buses */ | 950 | /* Add it to the local list of buses */ |
@@ -987,7 +985,7 @@ static void usb_deregister_bus (struct usb_bus *bus) | |||
987 | 985 | ||
988 | usb_notify_remove_bus(bus); | 986 | usb_notify_remove_bus(bus); |
989 | 987 | ||
990 | clear_bit (bus->busnum, busmap.busmap); | 988 | clear_bit(bus->busnum, busmap); |
991 | } | 989 | } |
992 | 990 | ||
993 | /** | 991 | /** |
@@ -1033,6 +1031,7 @@ static int register_root_hub(struct usb_hcd *hcd) | |||
1033 | dev_name(&usb_dev->dev), retval); | 1031 | dev_name(&usb_dev->dev), retval); |
1034 | return retval; | 1032 | return retval; |
1035 | } | 1033 | } |
1034 | usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev); | ||
1036 | } | 1035 | } |
1037 | 1036 | ||
1038 | retval = usb_new_device (usb_dev); | 1037 | retval = usb_new_device (usb_dev); |
@@ -1120,21 +1119,21 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount) | |||
1120 | case USB_SPEED_LOW: /* INTR only */ | 1119 | case USB_SPEED_LOW: /* INTR only */ |
1121 | if (is_input) { | 1120 | if (is_input) { |
1122 | tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L; | 1121 | tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L; |
1123 | return (64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp); | 1122 | return 64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp; |
1124 | } else { | 1123 | } else { |
1125 | tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L; | 1124 | tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L; |
1126 | return (64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp); | 1125 | return 64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp; |
1127 | } | 1126 | } |
1128 | case USB_SPEED_FULL: /* ISOC or INTR */ | 1127 | case USB_SPEED_FULL: /* ISOC or INTR */ |
1129 | if (isoc) { | 1128 | if (isoc) { |
1130 | tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; | 1129 | tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; |
1131 | return (((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp); | 1130 | return ((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp; |
1132 | } else { | 1131 | } else { |
1133 | tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; | 1132 | tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; |
1134 | return (9107L + BW_HOST_DELAY + tmp); | 1133 | return 9107L + BW_HOST_DELAY + tmp; |
1135 | } | 1134 | } |
1136 | case USB_SPEED_HIGH: /* ISOC or INTR */ | 1135 | case USB_SPEED_HIGH: /* ISOC or INTR */ |
1137 | // FIXME adjust for input vs output | 1136 | /* FIXME adjust for input vs output */ |
1138 | if (isoc) | 1137 | if (isoc) |
1139 | tmp = HS_NSECS_ISO (bytecount); | 1138 | tmp = HS_NSECS_ISO (bytecount); |
1140 | else | 1139 | else |
@@ -1651,6 +1650,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1651 | static void __usb_hcd_giveback_urb(struct urb *urb) | 1650 | static void __usb_hcd_giveback_urb(struct urb *urb) |
1652 | { | 1651 | { |
1653 | struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); | 1652 | struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); |
1653 | struct usb_anchor *anchor = urb->anchor; | ||
1654 | int status = urb->unlinked; | 1654 | int status = urb->unlinked; |
1655 | unsigned long flags; | 1655 | unsigned long flags; |
1656 | 1656 | ||
@@ -1662,6 +1662,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb) | |||
1662 | 1662 | ||
1663 | unmap_urb_for_dma(hcd, urb); | 1663 | unmap_urb_for_dma(hcd, urb); |
1664 | usbmon_urb_complete(&hcd->self, urb, status); | 1664 | usbmon_urb_complete(&hcd->self, urb, status); |
1665 | usb_anchor_suspend_wakeups(anchor); | ||
1665 | usb_unanchor_urb(urb); | 1666 | usb_unanchor_urb(urb); |
1666 | 1667 | ||
1667 | /* pass ownership to the completion handler */ | 1668 | /* pass ownership to the completion handler */ |
@@ -1681,6 +1682,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb) | |||
1681 | urb->complete(urb); | 1682 | urb->complete(urb); |
1682 | local_irq_restore(flags); | 1683 | local_irq_restore(flags); |
1683 | 1684 | ||
1685 | usb_anchor_resume_wakeups(anchor); | ||
1684 | atomic_dec(&urb->use_count); | 1686 | atomic_dec(&urb->use_count); |
1685 | if (unlikely(atomic_read(&urb->reject))) | 1687 | if (unlikely(atomic_read(&urb->reject))) |
1686 | wake_up(&usb_kill_urb_queue); | 1688 | wake_up(&usb_kill_urb_queue); |
@@ -1703,7 +1705,9 @@ static void usb_giveback_urb_bh(unsigned long param) | |||
1703 | 1705 | ||
1704 | urb = list_entry(local_list.next, struct urb, urb_list); | 1706 | urb = list_entry(local_list.next, struct urb, urb_list); |
1705 | list_del_init(&urb->urb_list); | 1707 | list_del_init(&urb->urb_list); |
1708 | bh->completing_ep = urb->ep; | ||
1706 | __usb_hcd_giveback_urb(urb); | 1709 | __usb_hcd_giveback_urb(urb); |
1710 | bh->completing_ep = NULL; | ||
1707 | } | 1711 | } |
1708 | 1712 | ||
1709 | /* check if there are new URBs to giveback */ | 1713 | /* check if there are new URBs to giveback */ |
@@ -1812,7 +1816,7 @@ rescan: | |||
1812 | case USB_ENDPOINT_XFER_INT: | 1816 | case USB_ENDPOINT_XFER_INT: |
1813 | s = "-intr"; break; | 1817 | s = "-intr"; break; |
1814 | default: | 1818 | default: |
1815 | s = "-iso"; break; | 1819 | s = "-iso"; break; |
1816 | }; | 1820 | }; |
1817 | s; | 1821 | s; |
1818 | })); | 1822 | })); |
@@ -2073,8 +2077,11 @@ EXPORT_SYMBOL_GPL(usb_alloc_streams); | |||
2073 | * | 2077 | * |
2074 | * Reverts a group of bulk endpoints back to not using stream IDs. | 2078 | * Reverts a group of bulk endpoints back to not using stream IDs. |
2075 | * Can fail if we are given bad arguments, or HCD is broken. | 2079 | * Can fail if we are given bad arguments, or HCD is broken. |
2080 | * | ||
2081 | * Return: On success, the number of allocated streams. On failure, a negative | ||
2082 | * error code. | ||
2076 | */ | 2083 | */ |
2077 | void usb_free_streams(struct usb_interface *interface, | 2084 | int usb_free_streams(struct usb_interface *interface, |
2078 | struct usb_host_endpoint **eps, unsigned int num_eps, | 2085 | struct usb_host_endpoint **eps, unsigned int num_eps, |
2079 | gfp_t mem_flags) | 2086 | gfp_t mem_flags) |
2080 | { | 2087 | { |
@@ -2085,14 +2092,14 @@ void usb_free_streams(struct usb_interface *interface, | |||
2085 | dev = interface_to_usbdev(interface); | 2092 | dev = interface_to_usbdev(interface); |
2086 | hcd = bus_to_hcd(dev->bus); | 2093 | hcd = bus_to_hcd(dev->bus); |
2087 | if (dev->speed != USB_SPEED_SUPER) | 2094 | if (dev->speed != USB_SPEED_SUPER) |
2088 | return; | 2095 | return -EINVAL; |
2089 | 2096 | ||
2090 | /* Streams only apply to bulk endpoints. */ | 2097 | /* Streams only apply to bulk endpoints. */ |
2091 | for (i = 0; i < num_eps; i++) | 2098 | for (i = 0; i < num_eps; i++) |
2092 | if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc)) | 2099 | if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc)) |
2093 | return; | 2100 | return -EINVAL; |
2094 | 2101 | ||
2095 | hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); | 2102 | return hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); |
2096 | } | 2103 | } |
2097 | EXPORT_SYMBOL_GPL(usb_free_streams); | 2104 | EXPORT_SYMBOL_GPL(usb_free_streams); |
2098 | 2105 | ||
@@ -2245,7 +2252,7 @@ static void hcd_resume_work(struct work_struct *work) | |||
2245 | } | 2252 | } |
2246 | 2253 | ||
2247 | /** | 2254 | /** |
2248 | * usb_hcd_resume_root_hub - called by HCD to resume its root hub | 2255 | * usb_hcd_resume_root_hub - called by HCD to resume its root hub |
2249 | * @hcd: host controller for this root hub | 2256 | * @hcd: host controller for this root hub |
2250 | * | 2257 | * |
2251 | * The USB host controller calls this function when its root hub is | 2258 | * The USB host controller calls this function when its root hub is |
@@ -2324,15 +2331,8 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum); | |||
2324 | irqreturn_t usb_hcd_irq (int irq, void *__hcd) | 2331 | irqreturn_t usb_hcd_irq (int irq, void *__hcd) |
2325 | { | 2332 | { |
2326 | struct usb_hcd *hcd = __hcd; | 2333 | struct usb_hcd *hcd = __hcd; |
2327 | unsigned long flags; | ||
2328 | irqreturn_t rc; | 2334 | irqreturn_t rc; |
2329 | 2335 | ||
2330 | /* IRQF_DISABLED doesn't work correctly with shared IRQs | ||
2331 | * when the first handler doesn't use it. So let's just | ||
2332 | * assume it's never used. | ||
2333 | */ | ||
2334 | local_irq_save(flags); | ||
2335 | |||
2336 | if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) | 2336 | if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) |
2337 | rc = IRQ_NONE; | 2337 | rc = IRQ_NONE; |
2338 | else if (hcd->driver->irq(hcd) == IRQ_NONE) | 2338 | else if (hcd->driver->irq(hcd) == IRQ_NONE) |
@@ -2340,7 +2340,6 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd) | |||
2340 | else | 2340 | else |
2341 | rc = IRQ_HANDLED; | 2341 | rc = IRQ_HANDLED; |
2342 | 2342 | ||
2343 | local_irq_restore(flags); | ||
2344 | return rc; | 2343 | return rc; |
2345 | } | 2344 | } |
2346 | EXPORT_SYMBOL_GPL(usb_hcd_irq); | 2345 | EXPORT_SYMBOL_GPL(usb_hcd_irq); |
@@ -2547,13 +2546,6 @@ static int usb_hcd_request_irqs(struct usb_hcd *hcd, | |||
2547 | 2546 | ||
2548 | if (hcd->driver->irq) { | 2547 | if (hcd->driver->irq) { |
2549 | 2548 | ||
2550 | /* IRQF_DISABLED doesn't work as advertised when used together | ||
2551 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2552 | * interrupts we can remove it here. | ||
2553 | */ | ||
2554 | if (irqflags & IRQF_SHARED) | ||
2555 | irqflags &= ~IRQF_DISABLED; | ||
2556 | |||
2557 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | 2549 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", |
2558 | hcd->driver->description, hcd->self.busnum); | 2550 | hcd->driver->description, hcd->self.busnum); |
2559 | retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | 2551 | retval = request_irq(irqnum, &usb_hcd_irq, irqflags, |
@@ -2600,7 +2592,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2600 | 2592 | ||
2601 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ | 2593 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ |
2602 | if (authorized_default < 0 || authorized_default > 1) | 2594 | if (authorized_default < 0 || authorized_default > 1) |
2603 | hcd->authorized_default = hcd->wireless? 0 : 1; | 2595 | hcd->authorized_default = hcd->wireless ? 0 : 1; |
2604 | else | 2596 | else |
2605 | hcd->authorized_default = authorized_default; | 2597 | hcd->authorized_default = authorized_default; |
2606 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 2598 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
@@ -2743,7 +2735,7 @@ err_allocate_root_hub: | |||
2743 | err_register_bus: | 2735 | err_register_bus: |
2744 | hcd_buffer_destroy(hcd); | 2736 | hcd_buffer_destroy(hcd); |
2745 | return retval; | 2737 | return retval; |
2746 | } | 2738 | } |
2747 | EXPORT_SYMBOL_GPL(usb_add_hcd); | 2739 | EXPORT_SYMBOL_GPL(usb_add_hcd); |
2748 | 2740 | ||
2749 | /** | 2741 | /** |
@@ -2818,7 +2810,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2818 | EXPORT_SYMBOL_GPL(usb_remove_hcd); | 2810 | EXPORT_SYMBOL_GPL(usb_remove_hcd); |
2819 | 2811 | ||
2820 | void | 2812 | void |
2821 | usb_hcd_platform_shutdown(struct platform_device* dev) | 2813 | usb_hcd_platform_shutdown(struct platform_device *dev) |
2822 | { | 2814 | { |
2823 | struct usb_hcd *hcd = platform_get_drvdata(dev); | 2815 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
2824 | 2816 | ||
@@ -2840,7 +2832,7 @@ struct usb_mon_operations *mon_ops; | |||
2840 | * Notice that the code is minimally error-proof. Because usbmon needs | 2832 | * Notice that the code is minimally error-proof. Because usbmon needs |
2841 | * symbols from usbcore, usbcore gets referenced and cannot be unloaded first. | 2833 | * symbols from usbcore, usbcore gets referenced and cannot be unloaded first. |
2842 | */ | 2834 | */ |
2843 | 2835 | ||
2844 | int usb_mon_register (struct usb_mon_operations *ops) | 2836 | int usb_mon_register (struct usb_mon_operations *ops) |
2845 | { | 2837 | { |
2846 | 2838 | ||
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index e6b682c6c236..06cec635e703 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -120,7 +120,7 @@ static inline char *portspeed(struct usb_hub *hub, int portstatus) | |||
120 | if (hub_is_superspeed(hub->hdev)) | 120 | if (hub_is_superspeed(hub->hdev)) |
121 | return "5.0 Gb/s"; | 121 | return "5.0 Gb/s"; |
122 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 122 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
123 | return "480 Mb/s"; | 123 | return "480 Mb/s"; |
124 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) | 124 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) |
125 | return "1.5 Mb/s"; | 125 | return "1.5 Mb/s"; |
126 | else | 126 | else |
@@ -135,7 +135,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev) | |||
135 | return usb_get_intfdata(hdev->actconfig->interface[0]); | 135 | return usb_get_intfdata(hdev->actconfig->interface[0]); |
136 | } | 136 | } |
137 | 137 | ||
138 | static int usb_device_supports_lpm(struct usb_device *udev) | 138 | int usb_device_supports_lpm(struct usb_device *udev) |
139 | { | 139 | { |
140 | /* USB 2.1 (and greater) devices indicate LPM support through | 140 | /* USB 2.1 (and greater) devices indicate LPM support through |
141 | * their USB 2.0 Extended Capabilities BOS descriptor. | 141 | * their USB 2.0 Extended Capabilities BOS descriptor. |
@@ -156,6 +156,11 @@ static int usb_device_supports_lpm(struct usb_device *udev) | |||
156 | "Power management will be impacted.\n"); | 156 | "Power management will be impacted.\n"); |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | |||
160 | /* udev is root hub */ | ||
161 | if (!udev->parent) | ||
162 | return 1; | ||
163 | |||
159 | if (udev->parent->lpm_capable) | 164 | if (udev->parent->lpm_capable) |
160 | return 1; | 165 | return 1; |
161 | 166 | ||
@@ -310,9 +315,9 @@ static void usb_set_lpm_parameters(struct usb_device *udev) | |||
310 | return; | 315 | return; |
311 | 316 | ||
312 | udev_u1_del = udev->bos->ss_cap->bU1devExitLat; | 317 | udev_u1_del = udev->bos->ss_cap->bU1devExitLat; |
313 | udev_u2_del = udev->bos->ss_cap->bU2DevExitLat; | 318 | udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); |
314 | hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; | 319 | hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; |
315 | hub_u2_del = udev->parent->bos->ss_cap->bU2DevExitLat; | 320 | hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); |
316 | 321 | ||
317 | usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, | 322 | usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, |
318 | hub, &udev->parent->u1_params, hub_u1_del); | 323 | hub, &udev->parent->u1_params, hub_u1_del); |
@@ -433,7 +438,7 @@ static void set_port_led( | |||
433 | case HUB_LED_OFF: s = "off"; break; | 438 | case HUB_LED_OFF: s = "off"; break; |
434 | case HUB_LED_AUTO: s = "auto"; break; | 439 | case HUB_LED_AUTO: s = "auto"; break; |
435 | default: s = "??"; break; | 440 | default: s = "??"; break; |
436 | }; s; }), | 441 | } s; }), |
437 | status); | 442 | status); |
438 | } | 443 | } |
439 | 444 | ||
@@ -857,7 +862,7 @@ static int hub_hub_status(struct usb_hub *hub, | |||
857 | "%s failed (err = %d)\n", __func__, ret); | 862 | "%s failed (err = %d)\n", __func__, ret); |
858 | } else { | 863 | } else { |
859 | *status = le16_to_cpu(hub->status->hub.wHubStatus); | 864 | *status = le16_to_cpu(hub->status->hub.wHubStatus); |
860 | *change = le16_to_cpu(hub->status->hub.wHubChange); | 865 | *change = le16_to_cpu(hub->status->hub.wHubChange); |
861 | ret = 0; | 866 | ret = 0; |
862 | } | 867 | } |
863 | mutex_unlock(&hub->status_mutex); | 868 | mutex_unlock(&hub->status_mutex); |
@@ -956,7 +961,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | |||
956 | */ | 961 | */ |
957 | 962 | ||
958 | set_bit(port1, hub->change_bits); | 963 | set_bit(port1, hub->change_bits); |
959 | kick_khubd(hub); | 964 | kick_khubd(hub); |
960 | } | 965 | } |
961 | 966 | ||
962 | /** | 967 | /** |
@@ -1107,16 +1112,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1107 | /* | 1112 | /* |
1108 | * USB3 protocol ports will automatically transition | 1113 | * USB3 protocol ports will automatically transition |
1109 | * to Enabled state when detect an USB3.0 device attach. | 1114 | * to Enabled state when detect an USB3.0 device attach. |
1110 | * Do not disable USB3 protocol ports. | 1115 | * Do not disable USB3 protocol ports, just pretend |
1116 | * power was lost | ||
1111 | */ | 1117 | */ |
1112 | if (!hub_is_superspeed(hdev)) { | 1118 | portstatus &= ~USB_PORT_STAT_ENABLE; |
1119 | if (!hub_is_superspeed(hdev)) | ||
1113 | usb_clear_port_feature(hdev, port1, | 1120 | usb_clear_port_feature(hdev, port1, |
1114 | USB_PORT_FEAT_ENABLE); | 1121 | USB_PORT_FEAT_ENABLE); |
1115 | portstatus &= ~USB_PORT_STAT_ENABLE; | ||
1116 | } else { | ||
1117 | /* Pretend that power was lost for USB3 devs */ | ||
1118 | portstatus &= ~USB_PORT_STAT_ENABLE; | ||
1119 | } | ||
1120 | } | 1122 | } |
1121 | 1123 | ||
1122 | /* Clear status-change flags; we'll debounce later */ | 1124 | /* Clear status-change flags; we'll debounce later */ |
@@ -1130,6 +1132,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1130 | usb_clear_port_feature(hub->hdev, port1, | 1132 | usb_clear_port_feature(hub->hdev, port1, |
1131 | USB_PORT_FEAT_C_ENABLE); | 1133 | USB_PORT_FEAT_C_ENABLE); |
1132 | } | 1134 | } |
1135 | if (portchange & USB_PORT_STAT_C_RESET) { | ||
1136 | need_debounce_delay = true; | ||
1137 | usb_clear_port_feature(hub->hdev, port1, | ||
1138 | USB_PORT_FEAT_C_RESET); | ||
1139 | } | ||
1133 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && | 1140 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && |
1134 | hub_is_superspeed(hub->hdev)) { | 1141 | hub_is_superspeed(hub->hdev)) { |
1135 | need_debounce_delay = true; | 1142 | need_debounce_delay = true; |
@@ -1361,7 +1368,7 @@ static int hub_configure(struct usb_hub *hub, | |||
1361 | if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && | 1368 | if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && |
1362 | !(hub_is_superspeed(hdev))) { | 1369 | !(hub_is_superspeed(hdev))) { |
1363 | int i; | 1370 | int i; |
1364 | char portstr [USB_MAXCHILDREN + 1]; | 1371 | char portstr[USB_MAXCHILDREN + 1]; |
1365 | 1372 | ||
1366 | for (i = 0; i < hdev->maxchild; i++) | 1373 | for (i = 0; i < hdev->maxchild; i++) |
1367 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable | 1374 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable |
@@ -1429,32 +1436,32 @@ static int hub_configure(struct usb_hub *hub, | |||
1429 | 1436 | ||
1430 | /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */ | 1437 | /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */ |
1431 | switch (wHubCharacteristics & HUB_CHAR_TTTT) { | 1438 | switch (wHubCharacteristics & HUB_CHAR_TTTT) { |
1432 | case HUB_TTTT_8_BITS: | 1439 | case HUB_TTTT_8_BITS: |
1433 | if (hdev->descriptor.bDeviceProtocol != 0) { | 1440 | if (hdev->descriptor.bDeviceProtocol != 0) { |
1434 | hub->tt.think_time = 666; | 1441 | hub->tt.think_time = 666; |
1435 | dev_dbg(hub_dev, "TT requires at most %d " | ||
1436 | "FS bit times (%d ns)\n", | ||
1437 | 8, hub->tt.think_time); | ||
1438 | } | ||
1439 | break; | ||
1440 | case HUB_TTTT_16_BITS: | ||
1441 | hub->tt.think_time = 666 * 2; | ||
1442 | dev_dbg(hub_dev, "TT requires at most %d " | ||
1443 | "FS bit times (%d ns)\n", | ||
1444 | 16, hub->tt.think_time); | ||
1445 | break; | ||
1446 | case HUB_TTTT_24_BITS: | ||
1447 | hub->tt.think_time = 666 * 3; | ||
1448 | dev_dbg(hub_dev, "TT requires at most %d " | 1442 | dev_dbg(hub_dev, "TT requires at most %d " |
1449 | "FS bit times (%d ns)\n", | 1443 | "FS bit times (%d ns)\n", |
1450 | 24, hub->tt.think_time); | 1444 | 8, hub->tt.think_time); |
1451 | break; | 1445 | } |
1452 | case HUB_TTTT_32_BITS: | 1446 | break; |
1453 | hub->tt.think_time = 666 * 4; | 1447 | case HUB_TTTT_16_BITS: |
1454 | dev_dbg(hub_dev, "TT requires at most %d " | 1448 | hub->tt.think_time = 666 * 2; |
1455 | "FS bit times (%d ns)\n", | 1449 | dev_dbg(hub_dev, "TT requires at most %d " |
1456 | 32, hub->tt.think_time); | 1450 | "FS bit times (%d ns)\n", |
1457 | break; | 1451 | 16, hub->tt.think_time); |
1452 | break; | ||
1453 | case HUB_TTTT_24_BITS: | ||
1454 | hub->tt.think_time = 666 * 3; | ||
1455 | dev_dbg(hub_dev, "TT requires at most %d " | ||
1456 | "FS bit times (%d ns)\n", | ||
1457 | 24, hub->tt.think_time); | ||
1458 | break; | ||
1459 | case HUB_TTTT_32_BITS: | ||
1460 | hub->tt.think_time = 666 * 4; | ||
1461 | dev_dbg(hub_dev, "TT requires at most %d " | ||
1462 | "FS bit times (%d ns)\n", | ||
1463 | 32, hub->tt.think_time); | ||
1464 | break; | ||
1458 | } | 1465 | } |
1459 | 1466 | ||
1460 | /* probe() zeroes hub->indicator[] */ | 1467 | /* probe() zeroes hub->indicator[] */ |
@@ -1560,7 +1567,7 @@ static int hub_configure(struct usb_hub *hub, | |||
1560 | 1567 | ||
1561 | /* maybe cycle the hub leds */ | 1568 | /* maybe cycle the hub leds */ |
1562 | if (hub->has_indicators && blinkenlights) | 1569 | if (hub->has_indicators && blinkenlights) |
1563 | hub->indicator [0] = INDICATOR_CYCLE; | 1570 | hub->indicator[0] = INDICATOR_CYCLE; |
1564 | 1571 | ||
1565 | for (i = 0; i < hdev->maxchild; i++) { | 1572 | for (i = 0; i < hdev->maxchild; i++) { |
1566 | ret = usb_hub_create_port_device(hub, i + 1); | 1573 | ret = usb_hub_create_port_device(hub, i + 1); |
@@ -1978,7 +1985,7 @@ static void choose_devnum(struct usb_device *udev) | |||
1978 | if (devnum >= 128) | 1985 | if (devnum >= 128) |
1979 | devnum = find_next_zero_bit(bus->devmap.devicemap, | 1986 | devnum = find_next_zero_bit(bus->devmap.devicemap, |
1980 | 128, 1); | 1987 | 128, 1); |
1981 | bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1); | 1988 | bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); |
1982 | } | 1989 | } |
1983 | if (devnum < 128) { | 1990 | if (devnum < 128) { |
1984 | set_bit(devnum, bus->devmap.devicemap); | 1991 | set_bit(devnum, bus->devmap.devicemap); |
@@ -2018,8 +2025,8 @@ static void hub_free_dev(struct usb_device *udev) | |||
2018 | * Something got disconnected. Get rid of it and all of its children. | 2025 | * Something got disconnected. Get rid of it and all of its children. |
2019 | * | 2026 | * |
2020 | * If *pdev is a normal device then the parent hub must already be locked. | 2027 | * If *pdev is a normal device then the parent hub must already be locked. |
2021 | * If *pdev is a root hub then this routine will acquire the | 2028 | * If *pdev is a root hub then the caller must hold the usb_bus_list_lock, |
2022 | * usb_bus_list_lock on behalf of the caller. | 2029 | * which protects the set of root hubs as well as the list of buses. |
2023 | * | 2030 | * |
2024 | * Only hub drivers (including virtual root hub drivers for host | 2031 | * Only hub drivers (including virtual root hub drivers for host |
2025 | * controllers) should ever call this. | 2032 | * controllers) should ever call this. |
@@ -2232,8 +2239,7 @@ static int usb_enumerate_device(struct usb_device *udev) | |||
2232 | udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 2239 | udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); |
2233 | udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 2240 | udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); |
2234 | udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 2241 | udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); |
2235 | } | 2242 | } else { |
2236 | else { | ||
2237 | /* read the standard strings and cache them if present */ | 2243 | /* read the standard strings and cache them if present */ |
2238 | udev->product = usb_cache_string(udev, udev->descriptor.iProduct); | 2244 | udev->product = usb_cache_string(udev, udev->descriptor.iProduct); |
2239 | udev->manufacturer = usb_cache_string(udev, | 2245 | udev->manufacturer = usb_cache_string(udev, |
@@ -2489,7 +2495,7 @@ error_device_descriptor: | |||
2489 | usb_autosuspend_device(usb_dev); | 2495 | usb_autosuspend_device(usb_dev); |
2490 | error_autoresume: | 2496 | error_autoresume: |
2491 | out_authorized: | 2497 | out_authorized: |
2492 | usb_unlock_device(usb_dev); // complements locktree | 2498 | usb_unlock_device(usb_dev); /* complements locktree */ |
2493 | return result; | 2499 | return result; |
2494 | } | 2500 | } |
2495 | 2501 | ||
@@ -3108,8 +3114,8 @@ static int finish_port_resume(struct usb_device *udev) | |||
3108 | retry_reset_resume: | 3114 | retry_reset_resume: |
3109 | status = usb_reset_and_verify_device(udev); | 3115 | status = usb_reset_and_verify_device(udev); |
3110 | 3116 | ||
3111 | /* 10.5.4.5 says be sure devices in the tree are still there. | 3117 | /* 10.5.4.5 says be sure devices in the tree are still there. |
3112 | * For now let's assume the device didn't go crazy on resume, | 3118 | * For now let's assume the device didn't go crazy on resume, |
3113 | * and device drivers will know about any resume quirks. | 3119 | * and device drivers will know about any resume quirks. |
3114 | */ | 3120 | */ |
3115 | if (status == 0) { | 3121 | if (status == 0) { |
@@ -3211,7 +3217,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3211 | if (status == 0 && !port_is_suspended(hub, portstatus)) | 3217 | if (status == 0 && !port_is_suspended(hub, portstatus)) |
3212 | goto SuspendCleared; | 3218 | goto SuspendCleared; |
3213 | 3219 | ||
3214 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); | 3220 | /* dev_dbg(hub->intfdev, "resume port %d\n", port1); */ |
3215 | 3221 | ||
3216 | set_bit(port1, hub->busy_bits); | 3222 | set_bit(port1, hub->busy_bits); |
3217 | 3223 | ||
@@ -3855,7 +3861,7 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm); | |||
3855 | * Between connect detection and reset signaling there must be a delay | 3861 | * Between connect detection and reset signaling there must be a delay |
3856 | * of 100ms at least for debounce and power-settling. The corresponding | 3862 | * of 100ms at least for debounce and power-settling. The corresponding |
3857 | * timer shall restart whenever the downstream port detects a disconnect. | 3863 | * timer shall restart whenever the downstream port detects a disconnect. |
3858 | * | 3864 | * |
3859 | * Apparently there are some bluetooth and irda-dongles and a number of | 3865 | * Apparently there are some bluetooth and irda-dongles and a number of |
3860 | * low-speed devices for which this debounce period may last over a second. | 3866 | * low-speed devices for which this debounce period may last over a second. |
3861 | * Not covered by the spec - but easy to deal with. | 3867 | * Not covered by the spec - but easy to deal with. |
@@ -3949,6 +3955,32 @@ static int hub_set_address(struct usb_device *udev, int devnum) | |||
3949 | return retval; | 3955 | return retval; |
3950 | } | 3956 | } |
3951 | 3957 | ||
3958 | /* | ||
3959 | * There are reports of USB 3.0 devices that say they support USB 2.0 Link PM | ||
3960 | * when they're plugged into a USB 2.0 port, but they don't work when LPM is | ||
3961 | * enabled. | ||
3962 | * | ||
3963 | * Only enable USB 2.0 Link PM if the port is internal (hardwired), or the | ||
3964 | * device says it supports the new USB 2.0 Link PM errata by setting the BESL | ||
3965 | * support bit in the BOS descriptor. | ||
3966 | */ | ||
3967 | static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) | ||
3968 | { | ||
3969 | int connect_type; | ||
3970 | |||
3971 | if (!udev->usb2_hw_lpm_capable) | ||
3972 | return; | ||
3973 | |||
3974 | connect_type = usb_get_hub_port_connect_type(udev->parent, | ||
3975 | udev->portnum); | ||
3976 | |||
3977 | if ((udev->bos->ext_cap->bmAttributes & USB_BESL_SUPPORT) || | ||
3978 | connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | ||
3979 | udev->usb2_hw_lpm_allowed = 1; | ||
3980 | usb_set_usb2_hardware_lpm(udev, 1); | ||
3981 | } | ||
3982 | } | ||
3983 | |||
3952 | /* Reset device, (re)assign address, get device descriptor. | 3984 | /* Reset device, (re)assign address, get device descriptor. |
3953 | * Device connection must be stable, no more debouncing needed. | 3985 | * Device connection must be stable, no more debouncing needed. |
3954 | * Returns device in USB_STATE_ADDRESS, except on error. | 3986 | * Returns device in USB_STATE_ADDRESS, except on error. |
@@ -4055,7 +4087,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4055 | udev->tt = &hub->tt; | 4087 | udev->tt = &hub->tt; |
4056 | udev->ttport = port1; | 4088 | udev->ttport = port1; |
4057 | } | 4089 | } |
4058 | 4090 | ||
4059 | /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? | 4091 | /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? |
4060 | * Because device hardware and firmware is sometimes buggy in | 4092 | * Because device hardware and firmware is sometimes buggy in |
4061 | * this area, and this is how Linux has done it for ages. | 4093 | * this area, and this is how Linux has done it for ages. |
@@ -4130,11 +4162,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4130 | #undef GET_DESCRIPTOR_BUFSIZE | 4162 | #undef GET_DESCRIPTOR_BUFSIZE |
4131 | } | 4163 | } |
4132 | 4164 | ||
4133 | /* | 4165 | /* |
4134 | * If device is WUSB, we already assigned an | 4166 | * If device is WUSB, we already assigned an |
4135 | * unauthorized address in the Connect Ack sequence; | 4167 | * unauthorized address in the Connect Ack sequence; |
4136 | * authorization will assign the final address. | 4168 | * authorization will assign the final address. |
4137 | */ | 4169 | */ |
4138 | if (udev->wusb == 0) { | 4170 | if (udev->wusb == 0) { |
4139 | for (j = 0; j < SET_ADDRESS_TRIES; ++j) { | 4171 | for (j = 0; j < SET_ADDRESS_TRIES; ++j) { |
4140 | retval = hub_set_address(udev, devnum); | 4172 | retval = hub_set_address(udev, devnum); |
@@ -4163,7 +4195,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4163 | msleep(10); | 4195 | msleep(10); |
4164 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) | 4196 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) |
4165 | break; | 4197 | break; |
4166 | } | 4198 | } |
4167 | 4199 | ||
4168 | retval = usb_get_device_descriptor(udev, 8); | 4200 | retval = usb_get_device_descriptor(udev, 8); |
4169 | if (retval < 8) { | 4201 | if (retval < 8) { |
@@ -4219,7 +4251,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4219 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); | 4251 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); |
4220 | usb_ep0_reinit(udev); | 4252 | usb_ep0_reinit(udev); |
4221 | } | 4253 | } |
4222 | 4254 | ||
4223 | retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); | 4255 | retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); |
4224 | if (retval < (signed)sizeof(udev->descriptor)) { | 4256 | if (retval < (signed)sizeof(udev->descriptor)) { |
4225 | if (retval != -ENODEV) | 4257 | if (retval != -ENODEV) |
@@ -4242,6 +4274,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4242 | /* notify HCD that we have a device connected and addressed */ | 4274 | /* notify HCD that we have a device connected and addressed */ |
4243 | if (hcd->driver->update_device) | 4275 | if (hcd->driver->update_device) |
4244 | hcd->driver->update_device(hcd, udev); | 4276 | hcd->driver->update_device(hcd, udev); |
4277 | hub_set_initial_usb2_lpm_policy(udev); | ||
4245 | fail: | 4278 | fail: |
4246 | if (retval) { | 4279 | if (retval) { |
4247 | hub_port_disable(hub, port1, 0); | 4280 | hub_port_disable(hub, port1, 0); |
@@ -4316,7 +4349,7 @@ hub_power_remaining (struct usb_hub *hub) | |||
4316 | } | 4349 | } |
4317 | if (remaining < 0) { | 4350 | if (remaining < 0) { |
4318 | dev_warn(hub->intfdev, "%dmA over power budget!\n", | 4351 | dev_warn(hub->intfdev, "%dmA over power budget!\n", |
4319 | - remaining); | 4352 | -remaining); |
4320 | remaining = 0; | 4353 | remaining = 0; |
4321 | } | 4354 | } |
4322 | return remaining; | 4355 | return remaining; |
@@ -4427,7 +4460,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4427 | set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); | 4460 | set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); |
4428 | 4461 | ||
4429 | if (portstatus & USB_PORT_STAT_ENABLE) | 4462 | if (portstatus & USB_PORT_STAT_ENABLE) |
4430 | goto done; | 4463 | goto done; |
4431 | return; | 4464 | return; |
4432 | } | 4465 | } |
4433 | if (hub_is_superspeed(hub->hdev)) | 4466 | if (hub_is_superspeed(hub->hdev)) |
@@ -4450,7 +4483,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4450 | } | 4483 | } |
4451 | 4484 | ||
4452 | usb_set_device_state(udev, USB_STATE_POWERED); | 4485 | usb_set_device_state(udev, USB_STATE_POWERED); |
4453 | udev->bus_mA = hub->mA_per_port; | 4486 | udev->bus_mA = hub->mA_per_port; |
4454 | udev->level = hdev->level + 1; | 4487 | udev->level = hdev->level + 1; |
4455 | udev->wusb = hub_is_wusb(hub); | 4488 | udev->wusb = hub_is_wusb(hub); |
4456 | 4489 | ||
@@ -4504,7 +4537,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4504 | goto loop_disable; | 4537 | goto loop_disable; |
4505 | } | 4538 | } |
4506 | } | 4539 | } |
4507 | 4540 | ||
4508 | /* check for devices running slower than they could */ | 4541 | /* check for devices running slower than they could */ |
4509 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 | 4542 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 |
4510 | && udev->speed == USB_SPEED_FULL | 4543 | && udev->speed == USB_SPEED_FULL |
@@ -4564,7 +4597,7 @@ loop: | |||
4564 | dev_err(hub_dev, "unable to enumerate USB device on port %d\n", | 4597 | dev_err(hub_dev, "unable to enumerate USB device on port %d\n", |
4565 | port1); | 4598 | port1); |
4566 | } | 4599 | } |
4567 | 4600 | ||
4568 | done: | 4601 | done: |
4569 | hub_port_disable(hub, port1, 1); | 4602 | hub_port_disable(hub, port1, 1); |
4570 | if (hcd->driver->relinquish_port && !hub->hdev->parent) | 4603 | if (hcd->driver->relinquish_port && !hub->hdev->parent) |
@@ -4729,7 +4762,7 @@ static void hub_events(void) | |||
4729 | * EM interference sometimes causes badly | 4762 | * EM interference sometimes causes badly |
4730 | * shielded USB devices to be shutdown by | 4763 | * shielded USB devices to be shutdown by |
4731 | * the hub, this hack enables them again. | 4764 | * the hub, this hack enables them again. |
4732 | * Works at least with mouse driver. | 4765 | * Works at least with mouse driver. |
4733 | */ | 4766 | */ |
4734 | if (!(portstatus & USB_PORT_STAT_ENABLE) | 4767 | if (!(portstatus & USB_PORT_STAT_ENABLE) |
4735 | && !connect_change | 4768 | && !connect_change |
@@ -4841,7 +4874,7 @@ static void hub_events(void) | |||
4841 | dev_dbg(hub_dev, "over-current change\n"); | 4874 | dev_dbg(hub_dev, "over-current change\n"); |
4842 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); | 4875 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); |
4843 | msleep(500); /* Cool down */ | 4876 | msleep(500); /* Cool down */ |
4844 | hub_power_on(hub, true); | 4877 | hub_power_on(hub, true); |
4845 | hub_hub_status(hub, &status, &unused); | 4878 | hub_hub_status(hub, &status, &unused); |
4846 | if (status & HUB_STATUS_OVERCURRENT) | 4879 | if (status & HUB_STATUS_OVERCURRENT) |
4847 | dev_err(hub_dev, "over-current " | 4880 | dev_err(hub_dev, "over-current " |
@@ -4861,7 +4894,7 @@ static void hub_events(void) | |||
4861 | usb_unlock_device(hdev); | 4894 | usb_unlock_device(hdev); |
4862 | kref_put(&hub->kref, hub_release); | 4895 | kref_put(&hub->kref, hub_release); |
4863 | 4896 | ||
4864 | } /* end while (1) */ | 4897 | } /* end while (1) */ |
4865 | } | 4898 | } |
4866 | 4899 | ||
4867 | static int hub_thread(void *__unused) | 4900 | static int hub_thread(void *__unused) |
@@ -4886,7 +4919,7 @@ static int hub_thread(void *__unused) | |||
4886 | 4919 | ||
4887 | static const struct usb_device_id hub_id_table[] = { | 4920 | static const struct usb_device_id hub_id_table[] = { |
4888 | { .match_flags = USB_DEVICE_ID_MATCH_VENDOR | 4921 | { .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
4889 | | USB_DEVICE_ID_MATCH_INT_CLASS, | 4922 | | USB_DEVICE_ID_MATCH_INT_CLASS, |
4890 | .idVendor = USB_VENDOR_GENESYS_LOGIC, | 4923 | .idVendor = USB_VENDOR_GENESYS_LOGIC, |
4891 | .bInterfaceClass = USB_CLASS_HUB, | 4924 | .bInterfaceClass = USB_CLASS_HUB, |
4892 | .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND}, | 4925 | .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND}, |
@@ -5086,6 +5119,12 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5086 | } | 5119 | } |
5087 | parent_hub = usb_hub_to_struct_hub(parent_hdev); | 5120 | parent_hub = usb_hub_to_struct_hub(parent_hdev); |
5088 | 5121 | ||
5122 | /* Disable USB2 hardware LPM. | ||
5123 | * It will be re-enabled by the enumeration process. | ||
5124 | */ | ||
5125 | if (udev->usb2_hw_lpm_enabled == 1) | ||
5126 | usb_set_usb2_hardware_lpm(udev, 0); | ||
5127 | |||
5089 | bos = udev->bos; | 5128 | bos = udev->bos; |
5090 | udev->bos = NULL; | 5129 | udev->bos = NULL; |
5091 | 5130 | ||
@@ -5120,13 +5159,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5120 | 5159 | ||
5121 | if (ret < 0) | 5160 | if (ret < 0) |
5122 | goto re_enumerate; | 5161 | goto re_enumerate; |
5123 | 5162 | ||
5124 | /* Device might have changed firmware (DFU or similar) */ | 5163 | /* Device might have changed firmware (DFU or similar) */ |
5125 | if (descriptors_changed(udev, &descriptor, bos)) { | 5164 | if (descriptors_changed(udev, &descriptor, bos)) { |
5126 | dev_info(&udev->dev, "device firmware changed\n"); | 5165 | dev_info(&udev->dev, "device firmware changed\n"); |
5127 | udev->descriptor = descriptor; /* for disconnect() calls */ | 5166 | udev->descriptor = descriptor; /* for disconnect() calls */ |
5128 | goto re_enumerate; | 5167 | goto re_enumerate; |
5129 | } | 5168 | } |
5130 | 5169 | ||
5131 | /* Restore the device's previous configuration */ | 5170 | /* Restore the device's previous configuration */ |
5132 | if (!udev->actconfig) | 5171 | if (!udev->actconfig) |
@@ -5151,7 +5190,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5151 | udev->actconfig->desc.bConfigurationValue, ret); | 5190 | udev->actconfig->desc.bConfigurationValue, ret); |
5152 | mutex_unlock(hcd->bandwidth_mutex); | 5191 | mutex_unlock(hcd->bandwidth_mutex); |
5153 | goto re_enumerate; | 5192 | goto re_enumerate; |
5154 | } | 5193 | } |
5155 | mutex_unlock(hcd->bandwidth_mutex); | 5194 | mutex_unlock(hcd->bandwidth_mutex); |
5156 | usb_set_device_state(udev, USB_STATE_CONFIGURED); | 5195 | usb_set_device_state(udev, USB_STATE_CONFIGURED); |
5157 | 5196 | ||
@@ -5193,12 +5232,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5193 | 5232 | ||
5194 | done: | 5233 | done: |
5195 | /* Now that the alt settings are re-installed, enable LTM and LPM. */ | 5234 | /* Now that the alt settings are re-installed, enable LTM and LPM. */ |
5235 | usb_set_usb2_hardware_lpm(udev, 1); | ||
5196 | usb_unlocked_enable_lpm(udev); | 5236 | usb_unlocked_enable_lpm(udev); |
5197 | usb_enable_ltm(udev); | 5237 | usb_enable_ltm(udev); |
5198 | usb_release_bos_descriptor(udev); | 5238 | usb_release_bos_descriptor(udev); |
5199 | udev->bos = bos; | 5239 | udev->bos = bos; |
5200 | return 0; | 5240 | return 0; |
5201 | 5241 | ||
5202 | re_enumerate: | 5242 | re_enumerate: |
5203 | /* LPM state doesn't matter when we're about to destroy the device. */ | 5243 | /* LPM state doesn't matter when we're about to destroy the device. */ |
5204 | hub_port_logical_disconnect(parent_hub, port1); | 5244 | hub_port_logical_disconnect(parent_hub, port1); |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 82927e1ed27d..bb315970e475 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -1182,8 +1182,12 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) | |||
1182 | put_device(&dev->actconfig->interface[i]->dev); | 1182 | put_device(&dev->actconfig->interface[i]->dev); |
1183 | dev->actconfig->interface[i] = NULL; | 1183 | dev->actconfig->interface[i] = NULL; |
1184 | } | 1184 | } |
1185 | |||
1186 | if (dev->usb2_hw_lpm_enabled == 1) | ||
1187 | usb_set_usb2_hardware_lpm(dev, 0); | ||
1185 | usb_unlocked_disable_lpm(dev); | 1188 | usb_unlocked_disable_lpm(dev); |
1186 | usb_disable_ltm(dev); | 1189 | usb_disable_ltm(dev); |
1190 | |||
1187 | dev->actconfig = NULL; | 1191 | dev->actconfig = NULL; |
1188 | if (dev->state == USB_STATE_CONFIGURED) | 1192 | if (dev->state == USB_STATE_CONFIGURED) |
1189 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1193 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index 01fe36273f3b..12924dbfdc2c 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
15 | #include <linux/usb/quirks.h> | 15 | #include <linux/usb/quirks.h> |
16 | #include <linux/usb/hcd.h> | ||
16 | #include "usb.h" | 17 | #include "usb.h" |
17 | 18 | ||
18 | /* Lists of quirky USB devices, split in device quirks and interface quirks. | 19 | /* Lists of quirky USB devices, split in device quirks and interface quirks. |
@@ -161,6 +162,21 @@ static const struct usb_device_id usb_interface_quirk_list[] = { | |||
161 | { } /* terminating entry must be last */ | 162 | { } /* terminating entry must be last */ |
162 | }; | 163 | }; |
163 | 164 | ||
165 | static const struct usb_device_id usb_amd_resume_quirk_list[] = { | ||
166 | /* Lenovo Mouse with Pixart controller */ | ||
167 | { USB_DEVICE(0x17ef, 0x602e), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
168 | |||
169 | /* Pixart Mouse */ | ||
170 | { USB_DEVICE(0x093a, 0x2500), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
171 | { USB_DEVICE(0x093a, 0x2510), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
172 | { USB_DEVICE(0x093a, 0x2521), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
173 | |||
174 | /* Logitech Optical Mouse M90/M100 */ | ||
175 | { USB_DEVICE(0x046d, 0xc05a), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
176 | |||
177 | { } /* terminating entry must be last */ | ||
178 | }; | ||
179 | |||
164 | static bool usb_match_any_interface(struct usb_device *udev, | 180 | static bool usb_match_any_interface(struct usb_device *udev, |
165 | const struct usb_device_id *id) | 181 | const struct usb_device_id *id) |
166 | { | 182 | { |
@@ -187,6 +203,18 @@ static bool usb_match_any_interface(struct usb_device *udev, | |||
187 | return false; | 203 | return false; |
188 | } | 204 | } |
189 | 205 | ||
206 | static int usb_amd_resume_quirk(struct usb_device *udev) | ||
207 | { | ||
208 | struct usb_hcd *hcd; | ||
209 | |||
210 | hcd = bus_to_hcd(udev->bus); | ||
211 | /* The device should be attached directly to root hub */ | ||
212 | if (udev->level == 1 && hcd->amd_resume_bug == 1) | ||
213 | return 1; | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
190 | static u32 __usb_detect_quirks(struct usb_device *udev, | 218 | static u32 __usb_detect_quirks(struct usb_device *udev, |
191 | const struct usb_device_id *id) | 219 | const struct usb_device_id *id) |
192 | { | 220 | { |
@@ -212,6 +240,15 @@ static u32 __usb_detect_quirks(struct usb_device *udev, | |||
212 | void usb_detect_quirks(struct usb_device *udev) | 240 | void usb_detect_quirks(struct usb_device *udev) |
213 | { | 241 | { |
214 | udev->quirks = __usb_detect_quirks(udev, usb_quirk_list); | 242 | udev->quirks = __usb_detect_quirks(udev, usb_quirk_list); |
243 | |||
244 | /* | ||
245 | * Pixart-based mice would trigger remote wakeup issue on AMD | ||
246 | * Yangtze chipset, so set them as RESET_RESUME flag. | ||
247 | */ | ||
248 | if (usb_amd_resume_quirk(udev)) | ||
249 | udev->quirks |= __usb_detect_quirks(udev, | ||
250 | usb_amd_resume_quirk_list); | ||
251 | |||
215 | if (udev->quirks) | 252 | if (udev->quirks) |
216 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", | 253 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", |
217 | udev->quirks); | 254 | udev->quirks); |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 6d2c8edb1ffe..52a97adf02a0 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -23,14 +23,16 @@ static ssize_t field##_show(struct device *dev, \ | |||
23 | { \ | 23 | { \ |
24 | struct usb_device *udev; \ | 24 | struct usb_device *udev; \ |
25 | struct usb_host_config *actconfig; \ | 25 | struct usb_host_config *actconfig; \ |
26 | ssize_t rc = 0; \ | ||
26 | \ | 27 | \ |
27 | udev = to_usb_device(dev); \ | 28 | udev = to_usb_device(dev); \ |
29 | usb_lock_device(udev); \ | ||
28 | actconfig = udev->actconfig; \ | 30 | actconfig = udev->actconfig; \ |
29 | if (actconfig) \ | 31 | if (actconfig) \ |
30 | return sprintf(buf, format_string, \ | 32 | rc = sprintf(buf, format_string, \ |
31 | actconfig->desc.field); \ | 33 | actconfig->desc.field); \ |
32 | else \ | 34 | usb_unlock_device(udev); \ |
33 | return 0; \ | 35 | return rc; \ |
34 | } \ | 36 | } \ |
35 | 37 | ||
36 | #define usb_actconfig_attr(field, format_string) \ | 38 | #define usb_actconfig_attr(field, format_string) \ |
@@ -45,12 +47,15 @@ static ssize_t bMaxPower_show(struct device *dev, | |||
45 | { | 47 | { |
46 | struct usb_device *udev; | 48 | struct usb_device *udev; |
47 | struct usb_host_config *actconfig; | 49 | struct usb_host_config *actconfig; |
50 | ssize_t rc = 0; | ||
48 | 51 | ||
49 | udev = to_usb_device(dev); | 52 | udev = to_usb_device(dev); |
53 | usb_lock_device(udev); | ||
50 | actconfig = udev->actconfig; | 54 | actconfig = udev->actconfig; |
51 | if (!actconfig) | 55 | if (actconfig) |
52 | return 0; | 56 | rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); |
53 | return sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); | 57 | usb_unlock_device(udev); |
58 | return rc; | ||
54 | } | 59 | } |
55 | static DEVICE_ATTR_RO(bMaxPower); | 60 | static DEVICE_ATTR_RO(bMaxPower); |
56 | 61 | ||
@@ -59,12 +64,15 @@ static ssize_t configuration_show(struct device *dev, | |||
59 | { | 64 | { |
60 | struct usb_device *udev; | 65 | struct usb_device *udev; |
61 | struct usb_host_config *actconfig; | 66 | struct usb_host_config *actconfig; |
67 | ssize_t rc = 0; | ||
62 | 68 | ||
63 | udev = to_usb_device(dev); | 69 | udev = to_usb_device(dev); |
70 | usb_lock_device(udev); | ||
64 | actconfig = udev->actconfig; | 71 | actconfig = udev->actconfig; |
65 | if ((!actconfig) || (!actconfig->string)) | 72 | if (actconfig && actconfig->string) |
66 | return 0; | 73 | rc = sprintf(buf, "%s\n", actconfig->string); |
67 | return sprintf(buf, "%s\n", actconfig->string); | 74 | usb_unlock_device(udev); |
75 | return rc; | ||
68 | } | 76 | } |
69 | static DEVICE_ATTR_RO(configuration); | 77 | static DEVICE_ATTR_RO(configuration); |
70 | 78 | ||
@@ -390,7 +398,8 @@ static DEVICE_ATTR_RW(autosuspend); | |||
390 | static const char on_string[] = "on"; | 398 | static const char on_string[] = "on"; |
391 | static const char auto_string[] = "auto"; | 399 | static const char auto_string[] = "auto"; |
392 | 400 | ||
393 | static void warn_level(void) { | 401 | static void warn_level(void) |
402 | { | ||
394 | static int level_warned; | 403 | static int level_warned; |
395 | 404 | ||
396 | if (!level_warned) { | 405 | if (!level_warned) { |
@@ -449,7 +458,7 @@ static ssize_t usb2_hardware_lpm_show(struct device *dev, | |||
449 | struct usb_device *udev = to_usb_device(dev); | 458 | struct usb_device *udev = to_usb_device(dev); |
450 | const char *p; | 459 | const char *p; |
451 | 460 | ||
452 | if (udev->usb2_hw_lpm_enabled == 1) | 461 | if (udev->usb2_hw_lpm_allowed == 1) |
453 | p = "enabled"; | 462 | p = "enabled"; |
454 | else | 463 | else |
455 | p = "disabled"; | 464 | p = "disabled"; |
@@ -469,8 +478,10 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev, | |||
469 | 478 | ||
470 | ret = strtobool(buf, &value); | 479 | ret = strtobool(buf, &value); |
471 | 480 | ||
472 | if (!ret) | 481 | if (!ret) { |
482 | udev->usb2_hw_lpm_allowed = value; | ||
473 | ret = usb_set_usb2_hardware_lpm(udev, value); | 483 | ret = usb_set_usb2_hardware_lpm(udev, value); |
484 | } | ||
474 | 485 | ||
475 | usb_unlock_device(udev); | 486 | usb_unlock_device(udev); |
476 | 487 | ||
@@ -644,7 +655,7 @@ static ssize_t authorized_store(struct device *dev, | |||
644 | result = usb_deauthorize_device(usb_dev); | 655 | result = usb_deauthorize_device(usb_dev); |
645 | else | 656 | else |
646 | result = usb_authorize_device(usb_dev); | 657 | result = usb_authorize_device(usb_dev); |
647 | return result < 0? result : size; | 658 | return result < 0 ? result : size; |
648 | } | 659 | } |
649 | static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, | 660 | static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, |
650 | authorized_show, authorized_store); | 661 | authorized_show, authorized_store); |
@@ -764,6 +775,7 @@ read_descriptors(struct file *filp, struct kobject *kobj, | |||
764 | * Following that are the raw descriptor entries for all the | 775 | * Following that are the raw descriptor entries for all the |
765 | * configurations (config plus subsidiary descriptors). | 776 | * configurations (config plus subsidiary descriptors). |
766 | */ | 777 | */ |
778 | usb_lock_device(udev); | ||
767 | for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && | 779 | for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && |
768 | nleft > 0; ++cfgno) { | 780 | nleft > 0; ++cfgno) { |
769 | if (cfgno < 0) { | 781 | if (cfgno < 0) { |
@@ -784,6 +796,7 @@ read_descriptors(struct file *filp, struct kobject *kobj, | |||
784 | off -= srclen; | 796 | off -= srclen; |
785 | } | 797 | } |
786 | } | 798 | } |
799 | usb_unlock_device(udev); | ||
787 | return count - nleft; | 800 | return count - nleft; |
788 | } | 801 | } |
789 | 802 | ||
@@ -870,9 +883,7 @@ static ssize_t interface_show(struct device *dev, struct device_attribute *attr, | |||
870 | char *string; | 883 | char *string; |
871 | 884 | ||
872 | intf = to_usb_interface(dev); | 885 | intf = to_usb_interface(dev); |
873 | string = intf->cur_altsetting->string; | 886 | string = ACCESS_ONCE(intf->cur_altsetting->string); |
874 | barrier(); /* The altsetting might change! */ | ||
875 | |||
876 | if (!string) | 887 | if (!string) |
877 | return 0; | 888 | return 0; |
878 | return sprintf(buf, "%s\n", string); | 889 | return sprintf(buf, "%s\n", string); |
@@ -888,7 +899,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | |||
888 | 899 | ||
889 | intf = to_usb_interface(dev); | 900 | intf = to_usb_interface(dev); |
890 | udev = interface_to_usbdev(intf); | 901 | udev = interface_to_usbdev(intf); |
891 | alt = intf->cur_altsetting; | 902 | alt = ACCESS_ONCE(intf->cur_altsetting); |
892 | 903 | ||
893 | return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" | 904 | return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" |
894 | "ic%02Xisc%02Xip%02Xin%02X\n", | 905 | "ic%02Xisc%02Xip%02Xin%02X\n", |
@@ -909,23 +920,14 @@ static ssize_t supports_autosuspend_show(struct device *dev, | |||
909 | struct device_attribute *attr, | 920 | struct device_attribute *attr, |
910 | char *buf) | 921 | char *buf) |
911 | { | 922 | { |
912 | struct usb_interface *intf; | 923 | int s; |
913 | struct usb_device *udev; | ||
914 | int ret; | ||
915 | 924 | ||
916 | intf = to_usb_interface(dev); | 925 | device_lock(dev); |
917 | udev = interface_to_usbdev(intf); | ||
918 | |||
919 | usb_lock_device(udev); | ||
920 | /* Devices will be autosuspended even when an interface isn't claimed */ | 926 | /* Devices will be autosuspended even when an interface isn't claimed */ |
921 | if (!intf->dev.driver || | 927 | s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend); |
922 | to_usb_driver(intf->dev.driver)->supports_autosuspend) | 928 | device_unlock(dev); |
923 | ret = sprintf(buf, "%u\n", 1); | ||
924 | else | ||
925 | ret = sprintf(buf, "%u\n", 0); | ||
926 | usb_unlock_device(udev); | ||
927 | 929 | ||
928 | return ret; | 930 | return sprintf(buf, "%u\n", s); |
929 | } | 931 | } |
930 | static DEVICE_ATTR_RO(supports_autosuspend); | 932 | static DEVICE_ATTR_RO(supports_autosuspend); |
931 | 933 | ||
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index c12bc790a6a7..e62208356c89 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -138,13 +138,19 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor) | |||
138 | } | 138 | } |
139 | EXPORT_SYMBOL_GPL(usb_anchor_urb); | 139 | EXPORT_SYMBOL_GPL(usb_anchor_urb); |
140 | 140 | ||
141 | static int usb_anchor_check_wakeup(struct usb_anchor *anchor) | ||
142 | { | ||
143 | return atomic_read(&anchor->suspend_wakeups) == 0 && | ||
144 | list_empty(&anchor->urb_list); | ||
145 | } | ||
146 | |||
141 | /* Callers must hold anchor->lock */ | 147 | /* Callers must hold anchor->lock */ |
142 | static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor) | 148 | static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor) |
143 | { | 149 | { |
144 | urb->anchor = NULL; | 150 | urb->anchor = NULL; |
145 | list_del(&urb->anchor_list); | 151 | list_del(&urb->anchor_list); |
146 | usb_put_urb(urb); | 152 | usb_put_urb(urb); |
147 | if (list_empty(&anchor->urb_list)) | 153 | if (usb_anchor_check_wakeup(anchor)) |
148 | wake_up(&anchor->wait); | 154 | wake_up(&anchor->wait); |
149 | } | 155 | } |
150 | 156 | ||
@@ -846,6 +852,39 @@ void usb_unlink_anchored_urbs(struct usb_anchor *anchor) | |||
846 | EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); | 852 | EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); |
847 | 853 | ||
848 | /** | 854 | /** |
855 | * usb_anchor_suspend_wakeups | ||
856 | * @anchor: the anchor you want to suspend wakeups on | ||
857 | * | ||
858 | * Call this to stop the last urb being unanchored from waking up any | ||
859 | * usb_wait_anchor_empty_timeout waiters. This is used in the hcd urb give- | ||
860 | * back path to delay waking up until after the completion handler has run. | ||
861 | */ | ||
862 | void usb_anchor_suspend_wakeups(struct usb_anchor *anchor) | ||
863 | { | ||
864 | if (anchor) | ||
865 | atomic_inc(&anchor->suspend_wakeups); | ||
866 | } | ||
867 | EXPORT_SYMBOL_GPL(usb_anchor_suspend_wakeups); | ||
868 | |||
869 | /** | ||
870 | * usb_anchor_resume_wakeups | ||
871 | * @anchor: the anchor you want to resume wakeups on | ||
872 | * | ||
873 | * Allow usb_wait_anchor_empty_timeout waiters to be woken up again, and | ||
874 | * wake up any current waiters if the anchor is empty. | ||
875 | */ | ||
876 | void usb_anchor_resume_wakeups(struct usb_anchor *anchor) | ||
877 | { | ||
878 | if (!anchor) | ||
879 | return; | ||
880 | |||
881 | atomic_dec(&anchor->suspend_wakeups); | ||
882 | if (usb_anchor_check_wakeup(anchor)) | ||
883 | wake_up(&anchor->wait); | ||
884 | } | ||
885 | EXPORT_SYMBOL_GPL(usb_anchor_resume_wakeups); | ||
886 | |||
887 | /** | ||
849 | * usb_wait_anchor_empty_timeout - wait for an anchor to be unused | 888 | * usb_wait_anchor_empty_timeout - wait for an anchor to be unused |
850 | * @anchor: the anchor you want to become unused | 889 | * @anchor: the anchor you want to become unused |
851 | * @timeout: how long you are willing to wait in milliseconds | 890 | * @timeout: how long you are willing to wait in milliseconds |
@@ -858,7 +897,8 @@ EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); | |||
858 | int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, | 897 | int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, |
859 | unsigned int timeout) | 898 | unsigned int timeout) |
860 | { | 899 | { |
861 | return wait_event_timeout(anchor->wait, list_empty(&anchor->urb_list), | 900 | return wait_event_timeout(anchor->wait, |
901 | usb_anchor_check_wakeup(anchor), | ||
862 | msecs_to_jiffies(timeout)); | 902 | msecs_to_jiffies(timeout)); |
863 | } | 903 | } |
864 | EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); | 904 | EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 0a6ee2e70b25..4d1144990d4c 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -497,7 +497,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
497 | dev->authorized = 1; | 497 | dev->authorized = 1; |
498 | else { | 498 | else { |
499 | dev->authorized = usb_hcd->authorized_default; | 499 | dev->authorized = usb_hcd->authorized_default; |
500 | dev->wusb = usb_bus_is_wusb(bus)? 1 : 0; | 500 | dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; |
501 | } | 501 | } |
502 | return dev; | 502 | return dev; |
503 | } | 503 | } |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 823857767a16..c49383669cd8 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -35,6 +35,7 @@ extern int usb_get_device_descriptor(struct usb_device *dev, | |||
35 | unsigned int size); | 35 | unsigned int size); |
36 | extern int usb_get_bos_descriptor(struct usb_device *dev); | 36 | extern int usb_get_bos_descriptor(struct usb_device *dev); |
37 | extern void usb_release_bos_descriptor(struct usb_device *dev); | 37 | extern void usb_release_bos_descriptor(struct usb_device *dev); |
38 | extern int usb_device_supports_lpm(struct usb_device *udev); | ||
38 | extern char *usb_cache_string(struct usb_device *udev, int index); | 39 | extern char *usb_cache_string(struct usb_device *udev, int index); |
39 | extern int usb_set_configuration(struct usb_device *dev, int configuration); | 40 | extern int usb_set_configuration(struct usb_device *dev, int configuration); |
40 | extern int usb_choose_configuration(struct usb_device *udev); | 41 | extern int usb_choose_configuration(struct usb_device *udev); |
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 474162e9d01d..74f9cf02da07 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -584,7 +584,7 @@ static int dwc3_remove(struct platform_device *pdev) | |||
584 | usb_phy_set_suspend(dwc->usb2_phy, 1); | 584 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
585 | usb_phy_set_suspend(dwc->usb3_phy, 1); | 585 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
586 | 586 | ||
587 | pm_runtime_put(&pdev->dev); | 587 | pm_runtime_put_sync(&pdev->dev); |
588 | pm_runtime_disable(&pdev->dev); | 588 | pm_runtime_disable(&pdev->dev); |
589 | 589 | ||
590 | dwc3_debugfs_exit(dwc); | 590 | dwc3_debugfs_exit(dwc); |
@@ -691,7 +691,6 @@ static int dwc3_resume(struct device *dev) | |||
691 | 691 | ||
692 | usb_phy_init(dwc->usb3_phy); | 692 | usb_phy_init(dwc->usb3_phy); |
693 | usb_phy_init(dwc->usb2_phy); | 693 | usb_phy_init(dwc->usb2_phy); |
694 | msleep(100); | ||
695 | 694 | ||
696 | spin_lock_irqsave(&dwc->lock, flags); | 695 | spin_lock_irqsave(&dwc->lock, flags); |
697 | 696 | ||
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index 2e252aae51ca..31443aeedcdb 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -165,7 +165,6 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
165 | return 0; | 165 | return 0; |
166 | 166 | ||
167 | err3: | 167 | err3: |
168 | pci_set_drvdata(pci, NULL); | ||
169 | platform_device_put(dwc3); | 168 | platform_device_put(dwc3); |
170 | err1: | 169 | err1: |
171 | pci_disable_device(pci); | 170 | pci_disable_device(pci); |
@@ -180,7 +179,6 @@ static void dwc3_pci_remove(struct pci_dev *pci) | |||
180 | platform_device_unregister(glue->dwc3); | 179 | platform_device_unregister(glue->dwc3); |
181 | platform_device_unregister(glue->usb2_phy); | 180 | platform_device_unregister(glue->usb2_phy); |
182 | platform_device_unregister(glue->usb3_phy); | 181 | platform_device_unregister(glue->usb3_phy); |
183 | pci_set_drvdata(pci, NULL); | ||
184 | pci_disable_device(pci); | 182 | pci_disable_device(pci); |
185 | } | 183 | } |
186 | 184 | ||
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 7fa93f4bc507..95f7649c71a7 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c | |||
@@ -352,7 +352,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc, | |||
352 | break; | 352 | break; |
353 | default: | 353 | default: |
354 | return -EINVAL; | 354 | return -EINVAL; |
355 | }; | 355 | } |
356 | 356 | ||
357 | response_pkt = (__le16 *) dwc->setup_buf; | 357 | response_pkt = (__le16 *) dwc->setup_buf; |
358 | *response_pkt = cpu_to_le16(usb_status); | 358 | *response_pkt = cpu_to_le16(usb_status); |
@@ -470,7 +470,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, | |||
470 | 470 | ||
471 | default: | 471 | default: |
472 | return -EINVAL; | 472 | return -EINVAL; |
473 | }; | 473 | } |
474 | 474 | ||
475 | return 0; | 475 | return 0; |
476 | } | 476 | } |
@@ -709,7 +709,7 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
709 | dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); | 709 | dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); |
710 | ret = dwc3_ep0_delegate_req(dwc, ctrl); | 710 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
711 | break; | 711 | break; |
712 | }; | 712 | } |
713 | 713 | ||
714 | return ret; | 714 | return ret; |
715 | } | 715 | } |
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c index 5e29ddeb4d33..8cfc3191be50 100644 --- a/drivers/usb/early/ehci-dbgp.c +++ b/drivers/usb/early/ehci-dbgp.c | |||
@@ -568,10 +568,6 @@ try_again: | |||
568 | dbgp_printk("Could not find attached debug device\n"); | 568 | dbgp_printk("Could not find attached debug device\n"); |
569 | goto err; | 569 | goto err; |
570 | } | 570 | } |
571 | if (ret < 0) { | ||
572 | dbgp_printk("Attached device is not a debug device\n"); | ||
573 | goto err; | ||
574 | } | ||
575 | dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; | 571 | dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; |
576 | dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint; | 572 | dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint; |
577 | 573 | ||
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 48cddf3cd6b8..a91e6422f930 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -58,6 +58,20 @@ config USB_GADGET_DEBUG | |||
58 | trying to track down. Never enable these messages for a | 58 | trying to track down. Never enable these messages for a |
59 | production build. | 59 | production build. |
60 | 60 | ||
61 | config USB_GADGET_VERBOSE | ||
62 | bool "Verbose debugging Messages (DEVELOPMENT)" | ||
63 | depends on USB_GADGET_DEBUG | ||
64 | help | ||
65 | Many controller and gadget drivers will print verbose debugging | ||
66 | messages if you use this option to ask for those messages. | ||
67 | |||
68 | Avoid enabling these messages, even if you're actively | ||
69 | debugging such a driver. Many drivers will emit so many | ||
70 | messages that the driver timings are affected, which will | ||
71 | either create new failure modes or remove the one you're | ||
72 | trying to track down. Never enable these messages for a | ||
73 | production build. | ||
74 | |||
61 | config USB_GADGET_DEBUG_FILES | 75 | config USB_GADGET_DEBUG_FILES |
62 | boolean "Debugging information files (DEVELOPMENT)" | 76 | boolean "Debugging information files (DEVELOPMENT)" |
63 | depends on PROC_FS | 77 | depends on PROC_FS |
@@ -525,6 +539,9 @@ config USB_F_SUBSET | |||
525 | config USB_F_RNDIS | 539 | config USB_F_RNDIS |
526 | tristate | 540 | tristate |
527 | 541 | ||
542 | config USB_F_MASS_STORAGE | ||
543 | tristate | ||
544 | |||
528 | choice | 545 | choice |
529 | tristate "USB Gadget Drivers" | 546 | tristate "USB Gadget Drivers" |
530 | default USB_ETH | 547 | default USB_ETH |
@@ -662,6 +679,16 @@ config USB_CONFIGFS_PHONET | |||
662 | help | 679 | help |
663 | The Phonet protocol implementation for USB device. | 680 | The Phonet protocol implementation for USB device. |
664 | 681 | ||
682 | config USB_CONFIGFS_MASS_STORAGE | ||
683 | boolean "Mass storage" | ||
684 | depends on USB_CONFIGFS | ||
685 | select USB_F_MASS_STORAGE | ||
686 | help | ||
687 | The Mass Storage Gadget acts as a USB Mass Storage disk drive. | ||
688 | As its storage repository it can use a regular file or a block | ||
689 | device (in much the same way as the "loop" device driver), | ||
690 | specified as a module parameter or sysfs option. | ||
691 | |||
665 | config USB_ZERO | 692 | config USB_ZERO |
666 | tristate "Gadget Zero (DEVELOPMENT)" | 693 | tristate "Gadget Zero (DEVELOPMENT)" |
667 | select USB_LIBCOMPOSITE | 694 | select USB_LIBCOMPOSITE |
@@ -878,6 +905,7 @@ config USB_MASS_STORAGE | |||
878 | tristate "Mass Storage Gadget" | 905 | tristate "Mass Storage Gadget" |
879 | depends on BLOCK | 906 | depends on BLOCK |
880 | select USB_LIBCOMPOSITE | 907 | select USB_LIBCOMPOSITE |
908 | select USB_F_MASS_STORAGE | ||
881 | help | 909 | help |
882 | The Mass Storage Gadget acts as a USB Mass Storage disk drive. | 910 | The Mass Storage Gadget acts as a USB Mass Storage disk drive. |
883 | As its storage repository it can use a regular file or a block | 911 | As its storage repository it can use a regular file or a block |
@@ -1001,6 +1029,7 @@ config USB_G_ACM_MS | |||
1001 | select USB_LIBCOMPOSITE | 1029 | select USB_LIBCOMPOSITE |
1002 | select USB_U_SERIAL | 1030 | select USB_U_SERIAL |
1003 | select USB_F_ACM | 1031 | select USB_F_ACM |
1032 | select USB_F_MASS_STORAGE | ||
1004 | help | 1033 | help |
1005 | This driver provides two functions in one configuration: | 1034 | This driver provides two functions in one configuration: |
1006 | a mass storage, and a CDC ACM (serial port) link. | 1035 | a mass storage, and a CDC ACM (serial port) link. |
@@ -1015,8 +1044,8 @@ config USB_G_MULTI | |||
1015 | select USB_LIBCOMPOSITE | 1044 | select USB_LIBCOMPOSITE |
1016 | select USB_U_SERIAL | 1045 | select USB_U_SERIAL |
1017 | select USB_U_ETHER | 1046 | select USB_U_ETHER |
1018 | select USB_U_RNDIS | ||
1019 | select USB_F_ACM | 1047 | select USB_F_ACM |
1048 | select USB_F_MASS_STORAGE | ||
1020 | help | 1049 | help |
1021 | The Multifunction Composite Gadget provides Ethernet (RNDIS | 1050 | The Multifunction Composite Gadget provides Ethernet (RNDIS |
1022 | and/or CDC Ethernet), mass storage and ACM serial link | 1051 | and/or CDC Ethernet), mass storage and ACM serial link |
@@ -1035,6 +1064,8 @@ config USB_G_MULTI | |||
1035 | config USB_G_MULTI_RNDIS | 1064 | config USB_G_MULTI_RNDIS |
1036 | bool "RNDIS + CDC Serial + Storage configuration" | 1065 | bool "RNDIS + CDC Serial + Storage configuration" |
1037 | depends on USB_G_MULTI | 1066 | depends on USB_G_MULTI |
1067 | select USB_U_RNDIS | ||
1068 | select USB_F_RNDIS | ||
1038 | default y | 1069 | default y |
1039 | help | 1070 | help |
1040 | This option enables a configuration with RNDIS, CDC Serial and | 1071 | This option enables a configuration with RNDIS, CDC Serial and |
@@ -1048,6 +1079,7 @@ config USB_G_MULTI_CDC | |||
1048 | bool "CDC Ethernet + CDC Serial + Storage configuration" | 1079 | bool "CDC Ethernet + CDC Serial + Storage configuration" |
1049 | depends on USB_G_MULTI | 1080 | depends on USB_G_MULTI |
1050 | default n | 1081 | default n |
1082 | select USB_F_ECM | ||
1051 | help | 1083 | help |
1052 | This option enables a configuration with CDC Ethernet (ECM), CDC | 1084 | This option enables a configuration with CDC Ethernet (ECM), CDC |
1053 | Serial and Mass Storage functions available in the Multifunction | 1085 | Serial and Mass Storage functions available in the Multifunction |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 386db9daf1d9..f1af39603d4d 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -1,7 +1,8 @@ | |||
1 | # | 1 | # |
2 | # USB peripheral controller drivers | 2 | # USB peripheral controller drivers |
3 | # | 3 | # |
4 | ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG | 4 | ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG |
5 | ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG | ||
5 | 6 | ||
6 | obj-$(CONFIG_USB_GADGET) += udc-core.o | 7 | obj-$(CONFIG_USB_GADGET) += udc-core.o |
7 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o | 8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o |
@@ -60,6 +61,8 @@ usb_f_ecm_subset-y := f_subset.o | |||
60 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o | 61 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o |
61 | usb_f_rndis-y := f_rndis.o | 62 | usb_f_rndis-y := f_rndis.o |
62 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o | 63 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o |
64 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o | ||
65 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | ||
63 | 66 | ||
64 | # | 67 | # |
65 | # USB gadget drivers | 68 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 4b947bb50f62..7bfa134fe0e3 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c | |||
@@ -31,16 +31,7 @@ | |||
31 | #define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ | 31 | #define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ |
32 | #define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ | 32 | #define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ |
33 | 33 | ||
34 | /*-------------------------------------------------------------------------*/ | 34 | #include "f_mass_storage.h" |
35 | |||
36 | /* | ||
37 | * Kbuild is not very cooperative with respect to linking separately | ||
38 | * compiled library objects into one module. So for now we won't use | ||
39 | * separate compilation ... ensuring init/exit sections work to shrink | ||
40 | * the runtime footprint, and giving us at least some parts of what | ||
41 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
42 | */ | ||
43 | #include "f_mass_storage.c" | ||
44 | 35 | ||
45 | /*-------------------------------------------------------------------------*/ | 36 | /*-------------------------------------------------------------------------*/ |
46 | USB_GADGET_COMPOSITE_OPTIONS(); | 37 | USB_GADGET_COMPOSITE_OPTIONS(); |
@@ -104,18 +95,35 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
104 | /****************************** Configurations ******************************/ | 95 | /****************************** Configurations ******************************/ |
105 | 96 | ||
106 | static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; | 97 | static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; |
107 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | 98 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
108 | 99 | ||
109 | static struct fsg_common fsg_common; | 100 | static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; |
101 | |||
102 | #else | ||
103 | |||
104 | /* | ||
105 | * Number of buffers we will use. | ||
106 | * 2 is usually enough for good buffering pipeline | ||
107 | */ | ||
108 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | ||
109 | |||
110 | #endif /* CONFIG_USB_DEBUG */ | ||
111 | |||
112 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | ||
110 | 113 | ||
111 | /*-------------------------------------------------------------------------*/ | 114 | /*-------------------------------------------------------------------------*/ |
112 | static struct usb_function *f_acm; | 115 | static struct usb_function *f_acm; |
113 | static struct usb_function_instance *f_acm_inst; | 116 | static struct usb_function_instance *f_acm_inst; |
117 | |||
118 | static struct usb_function_instance *fi_msg; | ||
119 | static struct usb_function *f_msg; | ||
120 | |||
114 | /* | 121 | /* |
115 | * We _always_ have both ACM and mass storage functions. | 122 | * We _always_ have both ACM and mass storage functions. |
116 | */ | 123 | */ |
117 | static int __init acm_ms_do_config(struct usb_configuration *c) | 124 | static int __init acm_ms_do_config(struct usb_configuration *c) |
118 | { | 125 | { |
126 | struct fsg_opts *opts; | ||
119 | int status; | 127 | int status; |
120 | 128 | ||
121 | if (gadget_is_otg(c->cdev->gadget)) { | 129 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -123,31 +131,37 @@ static int __init acm_ms_do_config(struct usb_configuration *c) | |||
123 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 131 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
124 | } | 132 | } |
125 | 133 | ||
126 | f_acm_inst = usb_get_function_instance("acm"); | 134 | opts = fsg_opts_from_func_inst(fi_msg); |
127 | if (IS_ERR(f_acm_inst)) | ||
128 | return PTR_ERR(f_acm_inst); | ||
129 | 135 | ||
130 | f_acm = usb_get_function(f_acm_inst); | 136 | f_acm = usb_get_function(f_acm_inst); |
131 | if (IS_ERR(f_acm)) { | 137 | if (IS_ERR(f_acm)) |
132 | status = PTR_ERR(f_acm); | 138 | return PTR_ERR(f_acm); |
133 | goto err_func; | 139 | |
140 | f_msg = usb_get_function(fi_msg); | ||
141 | if (IS_ERR(f_msg)) { | ||
142 | status = PTR_ERR(f_msg); | ||
143 | goto put_acm; | ||
134 | } | 144 | } |
135 | 145 | ||
136 | status = usb_add_function(c, f_acm); | 146 | status = usb_add_function(c, f_acm); |
137 | if (status < 0) | 147 | if (status < 0) |
138 | goto err_conf; | 148 | goto put_msg; |
139 | 149 | ||
140 | status = fsg_bind_config(c->cdev, c, &fsg_common); | 150 | status = fsg_common_run_thread(opts->common); |
141 | if (status < 0) | 151 | if (status) |
142 | goto err_fsg; | 152 | goto remove_acm; |
153 | |||
154 | status = usb_add_function(c, f_msg); | ||
155 | if (status) | ||
156 | goto remove_acm; | ||
143 | 157 | ||
144 | return 0; | 158 | return 0; |
145 | err_fsg: | 159 | remove_acm: |
146 | usb_remove_function(c, f_acm); | 160 | usb_remove_function(c, f_acm); |
147 | err_conf: | 161 | put_msg: |
162 | usb_put_function(f_msg); | ||
163 | put_acm: | ||
148 | usb_put_function(f_acm); | 164 | usb_put_function(f_acm); |
149 | err_func: | ||
150 | usb_put_function_instance(f_acm_inst); | ||
151 | return status; | 165 | return status; |
152 | } | 166 | } |
153 | 167 | ||
@@ -163,45 +177,82 @@ static struct usb_configuration acm_ms_config_driver = { | |||
163 | static int __init acm_ms_bind(struct usb_composite_dev *cdev) | 177 | static int __init acm_ms_bind(struct usb_composite_dev *cdev) |
164 | { | 178 | { |
165 | struct usb_gadget *gadget = cdev->gadget; | 179 | struct usb_gadget *gadget = cdev->gadget; |
180 | struct fsg_opts *opts; | ||
181 | struct fsg_config config; | ||
166 | int status; | 182 | int status; |
167 | void *retp; | ||
168 | 183 | ||
169 | /* set up mass storage function */ | 184 | f_acm_inst = usb_get_function_instance("acm"); |
170 | retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); | 185 | if (IS_ERR(f_acm_inst)) |
171 | if (IS_ERR(retp)) { | 186 | return PTR_ERR(f_acm_inst); |
172 | status = PTR_ERR(retp); | 187 | |
173 | return PTR_ERR(retp); | 188 | fi_msg = usb_get_function_instance("mass_storage"); |
189 | if (IS_ERR(fi_msg)) { | ||
190 | status = PTR_ERR(fi_msg); | ||
191 | goto fail_get_msg; | ||
174 | } | 192 | } |
175 | 193 | ||
194 | /* set up mass storage function */ | ||
195 | fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers); | ||
196 | opts = fsg_opts_from_func_inst(fi_msg); | ||
197 | |||
198 | opts->no_configfs = true; | ||
199 | status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers); | ||
200 | if (status) | ||
201 | goto fail; | ||
202 | |||
203 | status = fsg_common_set_nluns(opts->common, config.nluns); | ||
204 | if (status) | ||
205 | goto fail_set_nluns; | ||
206 | |||
207 | status = fsg_common_set_cdev(opts->common, cdev, config.can_stall); | ||
208 | if (status) | ||
209 | goto fail_set_cdev; | ||
210 | |||
211 | fsg_common_set_sysfs(opts->common, true); | ||
212 | status = fsg_common_create_luns(opts->common, &config); | ||
213 | if (status) | ||
214 | goto fail_set_cdev; | ||
215 | |||
216 | fsg_common_set_inquiry_string(opts->common, config.vendor_name, | ||
217 | config.product_name); | ||
176 | /* | 218 | /* |
177 | * Allocate string descriptor numbers ... note that string | 219 | * Allocate string descriptor numbers ... note that string |
178 | * contents can be overridden by the composite_dev glue. | 220 | * contents can be overridden by the composite_dev glue. |
179 | */ | 221 | */ |
180 | status = usb_string_ids_tab(cdev, strings_dev); | 222 | status = usb_string_ids_tab(cdev, strings_dev); |
181 | if (status < 0) | 223 | if (status < 0) |
182 | goto fail1; | 224 | goto fail_string_ids; |
183 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; | 225 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
184 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; | 226 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
185 | 227 | ||
186 | /* register our configuration */ | 228 | /* register our configuration */ |
187 | status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); | 229 | status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); |
188 | if (status < 0) | 230 | if (status < 0) |
189 | goto fail1; | 231 | goto fail_string_ids; |
190 | 232 | ||
191 | usb_composite_overwrite_options(cdev, &coverwrite); | 233 | usb_composite_overwrite_options(cdev, &coverwrite); |
192 | dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", | 234 | dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", |
193 | DRIVER_DESC); | 235 | DRIVER_DESC); |
194 | fsg_common_put(&fsg_common); | ||
195 | return 0; | 236 | return 0; |
196 | 237 | ||
197 | /* error recovery */ | 238 | /* error recovery */ |
198 | fail1: | 239 | fail_string_ids: |
199 | fsg_common_put(&fsg_common); | 240 | fsg_common_remove_luns(opts->common); |
241 | fail_set_cdev: | ||
242 | fsg_common_free_luns(opts->common); | ||
243 | fail_set_nluns: | ||
244 | fsg_common_free_buffers(opts->common); | ||
245 | fail: | ||
246 | usb_put_function_instance(fi_msg); | ||
247 | fail_get_msg: | ||
248 | usb_put_function_instance(f_acm_inst); | ||
200 | return status; | 249 | return status; |
201 | } | 250 | } |
202 | 251 | ||
203 | static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) | 252 | static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) |
204 | { | 253 | { |
254 | usb_put_function(f_msg); | ||
255 | usb_put_function_instance(fi_msg); | ||
205 | usb_put_function(f_acm); | 256 | usb_put_function(f_acm); |
206 | usb_put_function_instance(f_acm_inst); | 257 | usb_put_function_instance(f_acm_inst); |
207 | return 0; | 258 | return 0; |
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index a9a4346c83aa..54a1e2954cea 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -3078,8 +3078,6 @@ static void udc_pci_remove(struct pci_dev *pdev) | |||
3078 | if (dev->active) | 3078 | if (dev->active) |
3079 | pci_disable_device(pdev); | 3079 | pci_disable_device(pdev); |
3080 | 3080 | ||
3081 | pci_set_drvdata(pdev, NULL); | ||
3082 | |||
3083 | udc_remove(dev); | 3081 | udc_remove(dev); |
3084 | } | 3082 | } |
3085 | 3083 | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index d4f0f3305759..3e7ae707f691 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -354,7 +354,7 @@ static u8 encode_bMaxPower(enum usb_device_speed speed, | |||
354 | return DIV_ROUND_UP(val, 8); | 354 | return DIV_ROUND_UP(val, 8); |
355 | default: | 355 | default: |
356 | return DIV_ROUND_UP(val, 2); | 356 | return DIV_ROUND_UP(val, 2); |
357 | }; | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | static int config_buf(struct usb_configuration *config, | 360 | static int config_buf(struct usb_configuration *config, |
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 8f0d6141e5e6..25885112fa35 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c | |||
@@ -557,7 +557,7 @@ static struct config_group *function_make( | |||
557 | 557 | ||
558 | fi = usb_get_function_instance(func_name); | 558 | fi = usb_get_function_instance(func_name); |
559 | if (IS_ERR(fi)) | 559 | if (IS_ERR(fi)) |
560 | return ERR_PTR(PTR_ERR(fi)); | 560 | return ERR_CAST(fi); |
561 | 561 | ||
562 | ret = config_item_set_name(&fi->group.cg_item, name); | 562 | ret = config_item_set_name(&fi->group.cg_item, name); |
563 | if (ret) { | 563 | if (ret) { |
@@ -991,6 +991,14 @@ static struct configfs_subsystem gadget_subsys = { | |||
991 | .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex), | 991 | .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex), |
992 | }; | 992 | }; |
993 | 993 | ||
994 | void unregister_gadget_item(struct config_item *item) | ||
995 | { | ||
996 | struct gadget_info *gi = to_gadget_info(item); | ||
997 | |||
998 | unregister_gadget(gi); | ||
999 | } | ||
1000 | EXPORT_SYMBOL(unregister_gadget_item); | ||
1001 | |||
994 | static int __init gadget_cfs_init(void) | 1002 | static int __init gadget_cfs_init(void) |
995 | { | 1003 | { |
996 | int ret; | 1004 | int ret; |
diff --git a/drivers/usb/gadget/configfs.h b/drivers/usb/gadget/configfs.h new file mode 100644 index 000000000000..a7b564a913d1 --- /dev/null +++ b/drivers/usb/gadget/configfs.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef USB__GADGET__CONFIGFS__H | ||
2 | #define USB__GADGET__CONFIGFS__H | ||
3 | |||
4 | void unregister_gadget_item(struct config_item *item); | ||
5 | |||
6 | #endif /* USB__GADGET__CONFIGFS__H */ | ||
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index b8a2376971a4..8f4dae310923 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -544,7 +544,7 @@ static int dummy_enable(struct usb_ep *_ep, | |||
544 | default: | 544 | default: |
545 | val = "ctrl"; | 545 | val = "ctrl"; |
546 | break; | 546 | break; |
547 | }; val; }), | 547 | } val; }), |
548 | max, ep->stream_en ? "enabled" : "disabled"); | 548 | max, ep->stream_en ? "enabled" : "disabled"); |
549 | 549 | ||
550 | /* at this point real hardware should be NAKing transfers | 550 | /* at this point real hardware should be NAKing transfers |
@@ -2271,7 +2271,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb) | |||
2271 | default: | 2271 | default: |
2272 | s = "?"; | 2272 | s = "?"; |
2273 | break; | 2273 | break; |
2274 | }; s; }), | 2274 | } s; }), |
2275 | ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "", | 2275 | ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "", |
2276 | ({ char *s; \ | 2276 | ({ char *s; \ |
2277 | switch (usb_pipetype(urb->pipe)) { \ | 2277 | switch (usb_pipetype(urb->pipe)) { \ |
@@ -2287,7 +2287,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb) | |||
2287 | default: \ | 2287 | default: \ |
2288 | s = "-iso"; \ | 2288 | s = "-iso"; \ |
2289 | break; \ | 2289 | break; \ |
2290 | }; s; }), | 2290 | } s; }), |
2291 | urb->actual_length, urb->transfer_buffer_length); | 2291 | urb->actual_length, urb->transfer_buffer_length); |
2292 | } | 2292 | } |
2293 | 2293 | ||
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index a01d7d38c016..a03ba2c83589 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -213,12 +213,14 @@ | |||
213 | #include <linux/spinlock.h> | 213 | #include <linux/spinlock.h> |
214 | #include <linux/string.h> | 214 | #include <linux/string.h> |
215 | #include <linux/freezer.h> | 215 | #include <linux/freezer.h> |
216 | #include <linux/module.h> | ||
216 | 217 | ||
217 | #include <linux/usb/ch9.h> | 218 | #include <linux/usb/ch9.h> |
218 | #include <linux/usb/gadget.h> | 219 | #include <linux/usb/gadget.h> |
219 | #include <linux/usb/composite.h> | 220 | #include <linux/usb/composite.h> |
220 | 221 | ||
221 | #include "gadget_chips.h" | 222 | #include "gadget_chips.h" |
223 | #include "configfs.h" | ||
222 | 224 | ||
223 | 225 | ||
224 | /*------------------------------------------------------------------------*/ | 226 | /*------------------------------------------------------------------------*/ |
@@ -228,26 +230,30 @@ | |||
228 | 230 | ||
229 | static const char fsg_string_interface[] = "Mass Storage"; | 231 | static const char fsg_string_interface[] = "Mass Storage"; |
230 | 232 | ||
231 | #include "storage_common.c" | 233 | #include "storage_common.h" |
234 | #include "f_mass_storage.h" | ||
232 | 235 | ||
236 | /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ | ||
237 | static struct usb_string fsg_strings[] = { | ||
238 | {FSG_STRING_INTERFACE, fsg_string_interface}, | ||
239 | {} | ||
240 | }; | ||
241 | |||
242 | static struct usb_gadget_strings fsg_stringtab = { | ||
243 | .language = 0x0409, /* en-us */ | ||
244 | .strings = fsg_strings, | ||
245 | }; | ||
246 | |||
247 | static struct usb_gadget_strings *fsg_strings_array[] = { | ||
248 | &fsg_stringtab, | ||
249 | NULL, | ||
250 | }; | ||
233 | 251 | ||
234 | /*-------------------------------------------------------------------------*/ | 252 | /*-------------------------------------------------------------------------*/ |
235 | 253 | ||
236 | struct fsg_dev; | 254 | struct fsg_dev; |
237 | struct fsg_common; | 255 | struct fsg_common; |
238 | 256 | ||
239 | /* FSF callback functions */ | ||
240 | struct fsg_operations { | ||
241 | /* | ||
242 | * Callback function to call when thread exits. If no | ||
243 | * callback is set or it returns value lower then zero MSF | ||
244 | * will force eject all LUNs it operates on (including those | ||
245 | * marked as non-removable or with prevent_medium_removal flag | ||
246 | * set). | ||
247 | */ | ||
248 | int (*thread_exits)(struct fsg_common *common); | ||
249 | }; | ||
250 | |||
251 | /* Data shared by all the FSG instances. */ | 257 | /* Data shared by all the FSG instances. */ |
252 | struct fsg_common { | 258 | struct fsg_common { |
253 | struct usb_gadget *gadget; | 259 | struct usb_gadget *gadget; |
@@ -268,13 +274,14 @@ struct fsg_common { | |||
268 | struct fsg_buffhd *next_buffhd_to_fill; | 274 | struct fsg_buffhd *next_buffhd_to_fill; |
269 | struct fsg_buffhd *next_buffhd_to_drain; | 275 | struct fsg_buffhd *next_buffhd_to_drain; |
270 | struct fsg_buffhd *buffhds; | 276 | struct fsg_buffhd *buffhds; |
277 | unsigned int fsg_num_buffers; | ||
271 | 278 | ||
272 | int cmnd_size; | 279 | int cmnd_size; |
273 | u8 cmnd[MAX_COMMAND_SIZE]; | 280 | u8 cmnd[MAX_COMMAND_SIZE]; |
274 | 281 | ||
275 | unsigned int nluns; | 282 | unsigned int nluns; |
276 | unsigned int lun; | 283 | unsigned int lun; |
277 | struct fsg_lun *luns; | 284 | struct fsg_lun **luns; |
278 | struct fsg_lun *curlun; | 285 | struct fsg_lun *curlun; |
279 | 286 | ||
280 | unsigned int bulk_out_maxpacket; | 287 | unsigned int bulk_out_maxpacket; |
@@ -294,6 +301,7 @@ struct fsg_common { | |||
294 | unsigned int short_packet_received:1; | 301 | unsigned int short_packet_received:1; |
295 | unsigned int bad_lun_okay:1; | 302 | unsigned int bad_lun_okay:1; |
296 | unsigned int running:1; | 303 | unsigned int running:1; |
304 | unsigned int sysfs:1; | ||
297 | 305 | ||
298 | int thread_wakeup_needed; | 306 | int thread_wakeup_needed; |
299 | struct completion thread_notifier; | 307 | struct completion thread_notifier; |
@@ -313,27 +321,6 @@ struct fsg_common { | |||
313 | struct kref ref; | 321 | struct kref ref; |
314 | }; | 322 | }; |
315 | 323 | ||
316 | struct fsg_config { | ||
317 | unsigned nluns; | ||
318 | struct fsg_lun_config { | ||
319 | const char *filename; | ||
320 | char ro; | ||
321 | char removable; | ||
322 | char cdrom; | ||
323 | char nofua; | ||
324 | } luns[FSG_MAX_LUNS]; | ||
325 | |||
326 | /* Callback functions. */ | ||
327 | const struct fsg_operations *ops; | ||
328 | /* Gadget's private data. */ | ||
329 | void *private_data; | ||
330 | |||
331 | const char *vendor_name; /* 8 characters or less */ | ||
332 | const char *product_name; /* 16 characters or less */ | ||
333 | |||
334 | char can_stall; | ||
335 | }; | ||
336 | |||
337 | struct fsg_dev { | 324 | struct fsg_dev { |
338 | struct usb_function function; | 325 | struct usb_function function; |
339 | struct usb_gadget *gadget; /* Copy of cdev->gadget */ | 326 | struct usb_gadget *gadget; /* Copy of cdev->gadget */ |
@@ -2172,7 +2159,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2172 | common->data_dir = DATA_DIR_NONE; | 2159 | common->data_dir = DATA_DIR_NONE; |
2173 | common->lun = cbw->Lun; | 2160 | common->lun = cbw->Lun; |
2174 | if (common->lun < common->nluns) | 2161 | if (common->lun < common->nluns) |
2175 | common->curlun = &common->luns[common->lun]; | 2162 | common->curlun = common->luns[common->lun]; |
2176 | else | 2163 | else |
2177 | common->curlun = NULL; | 2164 | common->curlun = NULL; |
2178 | common->tag = cbw->Tag; | 2165 | common->tag = cbw->Tag; |
@@ -2244,7 +2231,7 @@ reset: | |||
2244 | if (common->fsg) { | 2231 | if (common->fsg) { |
2245 | fsg = common->fsg; | 2232 | fsg = common->fsg; |
2246 | 2233 | ||
2247 | for (i = 0; i < fsg_num_buffers; ++i) { | 2234 | for (i = 0; i < common->fsg_num_buffers; ++i) { |
2248 | struct fsg_buffhd *bh = &common->buffhds[i]; | 2235 | struct fsg_buffhd *bh = &common->buffhds[i]; |
2249 | 2236 | ||
2250 | if (bh->inreq) { | 2237 | if (bh->inreq) { |
@@ -2303,7 +2290,7 @@ reset: | |||
2303 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | 2290 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); |
2304 | 2291 | ||
2305 | /* Allocate the requests */ | 2292 | /* Allocate the requests */ |
2306 | for (i = 0; i < fsg_num_buffers; ++i) { | 2293 | for (i = 0; i < common->fsg_num_buffers; ++i) { |
2307 | struct fsg_buffhd *bh = &common->buffhds[i]; | 2294 | struct fsg_buffhd *bh = &common->buffhds[i]; |
2308 | 2295 | ||
2309 | rc = alloc_request(common, fsg->bulk_in, &bh->inreq); | 2296 | rc = alloc_request(common, fsg->bulk_in, &bh->inreq); |
@@ -2320,7 +2307,9 @@ reset: | |||
2320 | 2307 | ||
2321 | common->running = 1; | 2308 | common->running = 1; |
2322 | for (i = 0; i < common->nluns; ++i) | 2309 | for (i = 0; i < common->nluns; ++i) |
2323 | common->luns[i].unit_attention_data = SS_RESET_OCCURRED; | 2310 | if (common->luns[i]) |
2311 | common->luns[i]->unit_attention_data = | ||
2312 | SS_RESET_OCCURRED; | ||
2324 | return rc; | 2313 | return rc; |
2325 | } | 2314 | } |
2326 | 2315 | ||
@@ -2372,7 +2361,7 @@ static void handle_exception(struct fsg_common *common) | |||
2372 | 2361 | ||
2373 | /* Cancel all the pending transfers */ | 2362 | /* Cancel all the pending transfers */ |
2374 | if (likely(common->fsg)) { | 2363 | if (likely(common->fsg)) { |
2375 | for (i = 0; i < fsg_num_buffers; ++i) { | 2364 | for (i = 0; i < common->fsg_num_buffers; ++i) { |
2376 | bh = &common->buffhds[i]; | 2365 | bh = &common->buffhds[i]; |
2377 | if (bh->inreq_busy) | 2366 | if (bh->inreq_busy) |
2378 | usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); | 2367 | usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); |
@@ -2384,7 +2373,7 @@ static void handle_exception(struct fsg_common *common) | |||
2384 | /* Wait until everything is idle */ | 2373 | /* Wait until everything is idle */ |
2385 | for (;;) { | 2374 | for (;;) { |
2386 | int num_active = 0; | 2375 | int num_active = 0; |
2387 | for (i = 0; i < fsg_num_buffers; ++i) { | 2376 | for (i = 0; i < common->fsg_num_buffers; ++i) { |
2388 | bh = &common->buffhds[i]; | 2377 | bh = &common->buffhds[i]; |
2389 | num_active += bh->inreq_busy + bh->outreq_busy; | 2378 | num_active += bh->inreq_busy + bh->outreq_busy; |
2390 | } | 2379 | } |
@@ -2407,7 +2396,7 @@ static void handle_exception(struct fsg_common *common) | |||
2407 | */ | 2396 | */ |
2408 | spin_lock_irq(&common->lock); | 2397 | spin_lock_irq(&common->lock); |
2409 | 2398 | ||
2410 | for (i = 0; i < fsg_num_buffers; ++i) { | 2399 | for (i = 0; i < common->fsg_num_buffers; ++i) { |
2411 | bh = &common->buffhds[i]; | 2400 | bh = &common->buffhds[i]; |
2412 | bh->state = BUF_STATE_EMPTY; | 2401 | bh->state = BUF_STATE_EMPTY; |
2413 | } | 2402 | } |
@@ -2420,7 +2409,9 @@ static void handle_exception(struct fsg_common *common) | |||
2420 | common->state = FSG_STATE_STATUS_PHASE; | 2409 | common->state = FSG_STATE_STATUS_PHASE; |
2421 | else { | 2410 | else { |
2422 | for (i = 0; i < common->nluns; ++i) { | 2411 | for (i = 0; i < common->nluns; ++i) { |
2423 | curlun = &common->luns[i]; | 2412 | curlun = common->luns[i]; |
2413 | if (!curlun) | ||
2414 | continue; | ||
2424 | curlun->prevent_medium_removal = 0; | 2415 | curlun->prevent_medium_removal = 0; |
2425 | curlun->sense_data = SS_NO_SENSE; | 2416 | curlun->sense_data = SS_NO_SENSE; |
2426 | curlun->unit_attention_data = SS_NO_SENSE; | 2417 | curlun->unit_attention_data = SS_NO_SENSE; |
@@ -2462,8 +2453,9 @@ static void handle_exception(struct fsg_common *common) | |||
2462 | * CONFIG_CHANGE cases. | 2453 | * CONFIG_CHANGE cases. |
2463 | */ | 2454 | */ |
2464 | /* for (i = 0; i < common->nluns; ++i) */ | 2455 | /* for (i = 0; i < common->nluns; ++i) */ |
2465 | /* common->luns[i].unit_attention_data = */ | 2456 | /* if (common->luns[i]) */ |
2466 | /* SS_RESET_OCCURRED; */ | 2457 | /* common->luns[i]->unit_attention_data = */ |
2458 | /* SS_RESET_OCCURRED; */ | ||
2467 | break; | 2459 | break; |
2468 | 2460 | ||
2469 | case FSG_STATE_CONFIG_CHANGE: | 2461 | case FSG_STATE_CONFIG_CHANGE: |
@@ -2559,12 +2551,13 @@ static int fsg_main_thread(void *common_) | |||
2559 | 2551 | ||
2560 | if (!common->ops || !common->ops->thread_exits | 2552 | if (!common->ops || !common->ops->thread_exits |
2561 | || common->ops->thread_exits(common) < 0) { | 2553 | || common->ops->thread_exits(common) < 0) { |
2562 | struct fsg_lun *curlun = common->luns; | 2554 | struct fsg_lun **curlun_it = common->luns; |
2563 | unsigned i = common->nluns; | 2555 | unsigned i = common->nluns; |
2564 | 2556 | ||
2565 | down_write(&common->filesem); | 2557 | down_write(&common->filesem); |
2566 | for (; i--; ++curlun) { | 2558 | for (; i--; ++curlun_it) { |
2567 | if (!fsg_lun_is_open(curlun)) | 2559 | struct fsg_lun *curlun = *curlun_it; |
2560 | if (!curlun || !fsg_lun_is_open(curlun)) | ||
2568 | continue; | 2561 | continue; |
2569 | 2562 | ||
2570 | fsg_lun_close(curlun); | 2563 | fsg_lun_close(curlun); |
@@ -2580,6 +2573,56 @@ static int fsg_main_thread(void *common_) | |||
2580 | 2573 | ||
2581 | /*************************** DEVICE ATTRIBUTES ***************************/ | 2574 | /*************************** DEVICE ATTRIBUTES ***************************/ |
2582 | 2575 | ||
2576 | static ssize_t ro_show(struct device *dev, struct device_attribute *attr, char *buf) | ||
2577 | { | ||
2578 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
2579 | |||
2580 | return fsg_show_ro(curlun, buf); | ||
2581 | } | ||
2582 | |||
2583 | static ssize_t nofua_show(struct device *dev, struct device_attribute *attr, | ||
2584 | char *buf) | ||
2585 | { | ||
2586 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
2587 | |||
2588 | return fsg_show_nofua(curlun, buf); | ||
2589 | } | ||
2590 | |||
2591 | static ssize_t file_show(struct device *dev, struct device_attribute *attr, | ||
2592 | char *buf) | ||
2593 | { | ||
2594 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
2595 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | ||
2596 | |||
2597 | return fsg_show_file(curlun, filesem, buf); | ||
2598 | } | ||
2599 | |||
2600 | static ssize_t ro_store(struct device *dev, struct device_attribute *attr, | ||
2601 | const char *buf, size_t count) | ||
2602 | { | ||
2603 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
2604 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | ||
2605 | |||
2606 | return fsg_store_ro(curlun, filesem, buf, count); | ||
2607 | } | ||
2608 | |||
2609 | static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, | ||
2610 | const char *buf, size_t count) | ||
2611 | { | ||
2612 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
2613 | |||
2614 | return fsg_store_nofua(curlun, buf, count); | ||
2615 | } | ||
2616 | |||
2617 | static ssize_t file_store(struct device *dev, struct device_attribute *attr, | ||
2618 | const char *buf, size_t count) | ||
2619 | { | ||
2620 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
2621 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | ||
2622 | |||
2623 | return fsg_store_file(curlun, filesem, buf, count); | ||
2624 | } | ||
2625 | |||
2583 | static DEVICE_ATTR_RW(ro); | 2626 | static DEVICE_ATTR_RW(ro); |
2584 | static DEVICE_ATTR_RW(nofua); | 2627 | static DEVICE_ATTR_RW(nofua); |
2585 | static DEVICE_ATTR_RW(file); | 2628 | static DEVICE_ATTR_RW(file); |
@@ -2597,221 +2640,422 @@ static void fsg_lun_release(struct device *dev) | |||
2597 | /* Nothing needs to be done */ | 2640 | /* Nothing needs to be done */ |
2598 | } | 2641 | } |
2599 | 2642 | ||
2600 | static inline void fsg_common_get(struct fsg_common *common) | 2643 | void fsg_common_get(struct fsg_common *common) |
2601 | { | 2644 | { |
2602 | kref_get(&common->ref); | 2645 | kref_get(&common->ref); |
2603 | } | 2646 | } |
2647 | EXPORT_SYMBOL_GPL(fsg_common_get); | ||
2604 | 2648 | ||
2605 | static inline void fsg_common_put(struct fsg_common *common) | 2649 | void fsg_common_put(struct fsg_common *common) |
2606 | { | 2650 | { |
2607 | kref_put(&common->ref, fsg_common_release); | 2651 | kref_put(&common->ref, fsg_common_release); |
2608 | } | 2652 | } |
2653 | EXPORT_SYMBOL_GPL(fsg_common_put); | ||
2609 | 2654 | ||
2610 | static struct fsg_common *fsg_common_init(struct fsg_common *common, | 2655 | /* check if fsg_num_buffers is within a valid range */ |
2611 | struct usb_composite_dev *cdev, | 2656 | static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers) |
2612 | struct fsg_config *cfg) | ||
2613 | { | 2657 | { |
2614 | struct usb_gadget *gadget = cdev->gadget; | 2658 | if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4) |
2615 | struct fsg_buffhd *bh; | 2659 | return 0; |
2616 | struct fsg_lun *curlun; | 2660 | pr_err("fsg_num_buffers %u is out of range (%d to %d)\n", |
2617 | struct fsg_lun_config *lcfg; | 2661 | fsg_num_buffers, 2, 4); |
2618 | int nluns, i, rc; | 2662 | return -EINVAL; |
2619 | char *pathbuf; | 2663 | } |
2620 | |||
2621 | rc = fsg_num_buffers_validate(); | ||
2622 | if (rc != 0) | ||
2623 | return ERR_PTR(rc); | ||
2624 | |||
2625 | /* Find out how many LUNs there should be */ | ||
2626 | nluns = cfg->nluns; | ||
2627 | if (nluns < 1 || nluns > FSG_MAX_LUNS) { | ||
2628 | dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns); | ||
2629 | return ERR_PTR(-EINVAL); | ||
2630 | } | ||
2631 | 2664 | ||
2632 | /* Allocate? */ | 2665 | static struct fsg_common *fsg_common_setup(struct fsg_common *common) |
2666 | { | ||
2633 | if (!common) { | 2667 | if (!common) { |
2634 | common = kzalloc(sizeof *common, GFP_KERNEL); | 2668 | common = kzalloc(sizeof(*common), GFP_KERNEL); |
2635 | if (!common) | 2669 | if (!common) |
2636 | return ERR_PTR(-ENOMEM); | 2670 | return ERR_PTR(-ENOMEM); |
2637 | common->free_storage_on_release = 1; | 2671 | common->free_storage_on_release = 1; |
2638 | } else { | 2672 | } else { |
2639 | memset(common, 0, sizeof *common); | ||
2640 | common->free_storage_on_release = 0; | 2673 | common->free_storage_on_release = 0; |
2641 | } | 2674 | } |
2675 | init_rwsem(&common->filesem); | ||
2676 | spin_lock_init(&common->lock); | ||
2677 | kref_init(&common->ref); | ||
2678 | init_completion(&common->thread_notifier); | ||
2679 | init_waitqueue_head(&common->fsg_wait); | ||
2680 | common->state = FSG_STATE_TERMINATED; | ||
2642 | 2681 | ||
2643 | common->buffhds = kcalloc(fsg_num_buffers, | 2682 | return common; |
2644 | sizeof *(common->buffhds), GFP_KERNEL); | 2683 | } |
2645 | if (!common->buffhds) { | 2684 | |
2646 | if (common->free_storage_on_release) | 2685 | void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs) |
2647 | kfree(common); | 2686 | { |
2648 | return ERR_PTR(-ENOMEM); | 2687 | common->sysfs = sysfs; |
2688 | } | ||
2689 | EXPORT_SYMBOL_GPL(fsg_common_set_sysfs); | ||
2690 | |||
2691 | static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n) | ||
2692 | { | ||
2693 | if (buffhds) { | ||
2694 | struct fsg_buffhd *bh = buffhds; | ||
2695 | while (n--) { | ||
2696 | kfree(bh->buf); | ||
2697 | ++bh; | ||
2698 | } | ||
2699 | kfree(buffhds); | ||
2649 | } | 2700 | } |
2701 | } | ||
2650 | 2702 | ||
2651 | common->ops = cfg->ops; | 2703 | int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n) |
2652 | common->private_data = cfg->private_data; | 2704 | { |
2705 | struct fsg_buffhd *bh, *buffhds; | ||
2706 | int i, rc; | ||
2653 | 2707 | ||
2654 | common->gadget = gadget; | 2708 | rc = fsg_num_buffers_validate(n); |
2655 | common->ep0 = gadget->ep0; | 2709 | if (rc != 0) |
2656 | common->ep0req = cdev->req; | 2710 | return rc; |
2657 | common->cdev = cdev; | 2711 | |
2712 | buffhds = kcalloc(n, sizeof(*buffhds), GFP_KERNEL); | ||
2713 | if (!buffhds) | ||
2714 | return -ENOMEM; | ||
2658 | 2715 | ||
2659 | /* Maybe allocate device-global string IDs, and patch descriptors */ | 2716 | /* Data buffers cyclic list */ |
2660 | if (fsg_strings[FSG_STRING_INTERFACE].id == 0) { | 2717 | bh = buffhds; |
2661 | rc = usb_string_id(cdev); | 2718 | i = n; |
2662 | if (unlikely(rc < 0)) | 2719 | goto buffhds_first_it; |
2720 | do { | ||
2721 | bh->next = bh + 1; | ||
2722 | ++bh; | ||
2723 | buffhds_first_it: | ||
2724 | bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL); | ||
2725 | if (unlikely(!bh->buf)) | ||
2663 | goto error_release; | 2726 | goto error_release; |
2664 | fsg_strings[FSG_STRING_INTERFACE].id = rc; | 2727 | } while (--i); |
2665 | fsg_intf_desc.iInterface = rc; | 2728 | bh->next = buffhds; |
2666 | } | ||
2667 | 2729 | ||
2730 | _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); | ||
2731 | common->fsg_num_buffers = n; | ||
2732 | common->buffhds = buffhds; | ||
2733 | |||
2734 | return 0; | ||
2735 | |||
2736 | error_release: | ||
2668 | /* | 2737 | /* |
2669 | * Create the LUNs, open their backing files, and register the | 2738 | * "buf"s pointed to by heads after n - i are NULL |
2670 | * LUN devices in sysfs. | 2739 | * so releasing them won't hurt |
2671 | */ | 2740 | */ |
2672 | curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); | 2741 | _fsg_common_free_buffers(buffhds, n); |
2673 | if (unlikely(!curlun)) { | 2742 | |
2674 | rc = -ENOMEM; | 2743 | return -ENOMEM; |
2675 | goto error_release; | 2744 | } |
2745 | EXPORT_SYMBOL_GPL(fsg_common_set_num_buffers); | ||
2746 | |||
2747 | static inline void fsg_common_remove_sysfs(struct fsg_lun *lun) | ||
2748 | { | ||
2749 | device_remove_file(&lun->dev, &dev_attr_nofua); | ||
2750 | /* | ||
2751 | * device_remove_file() => | ||
2752 | * | ||
2753 | * here the attr (e.g. dev_attr_ro) is only used to be passed to: | ||
2754 | * | ||
2755 | * sysfs_remove_file() => | ||
2756 | * | ||
2757 | * here e.g. both dev_attr_ro_cdrom and dev_attr_ro are in | ||
2758 | * the same namespace and | ||
2759 | * from here only attr->name is passed to: | ||
2760 | * | ||
2761 | * sysfs_hash_and_remove() | ||
2762 | * | ||
2763 | * attr->name is the same for dev_attr_ro_cdrom and | ||
2764 | * dev_attr_ro | ||
2765 | * attr->name is the same for dev_attr_file and | ||
2766 | * dev_attr_file_nonremovable | ||
2767 | * | ||
2768 | * so we don't differentiate between removing e.g. dev_attr_ro_cdrom | ||
2769 | * and dev_attr_ro | ||
2770 | */ | ||
2771 | device_remove_file(&lun->dev, &dev_attr_ro); | ||
2772 | device_remove_file(&lun->dev, &dev_attr_file); | ||
2773 | } | ||
2774 | |||
2775 | void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs) | ||
2776 | { | ||
2777 | if (sysfs) { | ||
2778 | fsg_common_remove_sysfs(lun); | ||
2779 | device_unregister(&lun->dev); | ||
2676 | } | 2780 | } |
2677 | common->luns = curlun; | 2781 | fsg_lun_close(lun); |
2782 | kfree(lun); | ||
2783 | } | ||
2784 | EXPORT_SYMBOL_GPL(fsg_common_remove_lun); | ||
2678 | 2785 | ||
2679 | init_rwsem(&common->filesem); | 2786 | static void _fsg_common_remove_luns(struct fsg_common *common, int n) |
2787 | { | ||
2788 | int i; | ||
2680 | 2789 | ||
2681 | for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) { | 2790 | for (i = 0; i < n; ++i) |
2682 | curlun->cdrom = !!lcfg->cdrom; | 2791 | if (common->luns[i]) { |
2683 | curlun->ro = lcfg->cdrom || lcfg->ro; | 2792 | fsg_common_remove_lun(common->luns[i], common->sysfs); |
2684 | curlun->initially_ro = curlun->ro; | 2793 | common->luns[i] = NULL; |
2685 | curlun->removable = lcfg->removable; | ||
2686 | curlun->dev.release = fsg_lun_release; | ||
2687 | curlun->dev.parent = &gadget->dev; | ||
2688 | /* curlun->dev.driver = &fsg_driver.driver; XXX */ | ||
2689 | dev_set_drvdata(&curlun->dev, &common->filesem); | ||
2690 | dev_set_name(&curlun->dev, "lun%d", i); | ||
2691 | |||
2692 | rc = device_register(&curlun->dev); | ||
2693 | if (rc) { | ||
2694 | INFO(common, "failed to register LUN%d: %d\n", i, rc); | ||
2695 | common->nluns = i; | ||
2696 | put_device(&curlun->dev); | ||
2697 | goto error_release; | ||
2698 | } | 2794 | } |
2795 | } | ||
2796 | EXPORT_SYMBOL_GPL(fsg_common_remove_luns); | ||
2699 | 2797 | ||
2700 | rc = device_create_file(&curlun->dev, | 2798 | void fsg_common_remove_luns(struct fsg_common *common) |
2701 | curlun->cdrom | 2799 | { |
2702 | ? &dev_attr_ro_cdrom | 2800 | _fsg_common_remove_luns(common, common->nluns); |
2703 | : &dev_attr_ro); | 2801 | } |
2704 | if (rc) | ||
2705 | goto error_luns; | ||
2706 | rc = device_create_file(&curlun->dev, | ||
2707 | curlun->removable | ||
2708 | ? &dev_attr_file | ||
2709 | : &dev_attr_file_nonremovable); | ||
2710 | if (rc) | ||
2711 | goto error_luns; | ||
2712 | rc = device_create_file(&curlun->dev, &dev_attr_nofua); | ||
2713 | if (rc) | ||
2714 | goto error_luns; | ||
2715 | 2802 | ||
2716 | if (lcfg->filename) { | 2803 | void fsg_common_free_luns(struct fsg_common *common) |
2717 | rc = fsg_lun_open(curlun, lcfg->filename); | 2804 | { |
2718 | if (rc) | 2805 | fsg_common_remove_luns(common); |
2719 | goto error_luns; | 2806 | kfree(common->luns); |
2720 | } else if (!curlun->removable) { | 2807 | common->luns = NULL; |
2721 | ERROR(common, "no file given for LUN%d\n", i); | 2808 | } |
2722 | rc = -EINVAL; | 2809 | EXPORT_SYMBOL_GPL(fsg_common_free_luns); |
2723 | goto error_luns; | 2810 | |
2724 | } | 2811 | int fsg_common_set_nluns(struct fsg_common *common, int nluns) |
2812 | { | ||
2813 | struct fsg_lun **curlun; | ||
2814 | |||
2815 | /* Find out how many LUNs there should be */ | ||
2816 | if (nluns < 1 || nluns > FSG_MAX_LUNS) { | ||
2817 | pr_err("invalid number of LUNs: %u\n", nluns); | ||
2818 | return -EINVAL; | ||
2725 | } | 2819 | } |
2820 | |||
2821 | curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); | ||
2822 | if (unlikely(!curlun)) | ||
2823 | return -ENOMEM; | ||
2824 | |||
2825 | if (common->luns) | ||
2826 | fsg_common_free_luns(common); | ||
2827 | |||
2828 | common->luns = curlun; | ||
2726 | common->nluns = nluns; | 2829 | common->nluns = nluns; |
2727 | 2830 | ||
2728 | /* Data buffers cyclic list */ | 2831 | pr_info("Number of LUNs=%d\n", common->nluns); |
2729 | bh = common->buffhds; | ||
2730 | i = fsg_num_buffers; | ||
2731 | goto buffhds_first_it; | ||
2732 | do { | ||
2733 | bh->next = bh + 1; | ||
2734 | ++bh; | ||
2735 | buffhds_first_it: | ||
2736 | bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL); | ||
2737 | if (unlikely(!bh->buf)) { | ||
2738 | rc = -ENOMEM; | ||
2739 | goto error_release; | ||
2740 | } | ||
2741 | } while (--i); | ||
2742 | bh->next = common->buffhds; | ||
2743 | 2832 | ||
2744 | /* Prepare inquiryString */ | 2833 | return 0; |
2745 | i = get_default_bcdDevice(); | 2834 | } |
2746 | snprintf(common->inquiry_string, sizeof common->inquiry_string, | 2835 | EXPORT_SYMBOL_GPL(fsg_common_set_nluns); |
2747 | "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", | 2836 | |
2748 | /* Assume product name dependent on the first LUN */ | 2837 | void fsg_common_set_ops(struct fsg_common *common, |
2749 | cfg->product_name ?: (common->luns->cdrom | 2838 | const struct fsg_operations *ops) |
2750 | ? "File-CD Gadget" | 2839 | { |
2751 | : "File-Stor Gadget"), | 2840 | common->ops = ops; |
2752 | i); | 2841 | } |
2842 | EXPORT_SYMBOL_GPL(fsg_common_set_ops); | ||
2843 | |||
2844 | void fsg_common_free_buffers(struct fsg_common *common) | ||
2845 | { | ||
2846 | _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); | ||
2847 | common->buffhds = NULL; | ||
2848 | } | ||
2849 | EXPORT_SYMBOL_GPL(fsg_common_free_buffers); | ||
2850 | |||
2851 | int fsg_common_set_cdev(struct fsg_common *common, | ||
2852 | struct usb_composite_dev *cdev, bool can_stall) | ||
2853 | { | ||
2854 | struct usb_string *us; | ||
2855 | |||
2856 | common->gadget = cdev->gadget; | ||
2857 | common->ep0 = cdev->gadget->ep0; | ||
2858 | common->ep0req = cdev->req; | ||
2859 | common->cdev = cdev; | ||
2860 | |||
2861 | us = usb_gstrings_attach(cdev, fsg_strings_array, | ||
2862 | ARRAY_SIZE(fsg_strings)); | ||
2863 | if (IS_ERR(us)) | ||
2864 | return PTR_ERR(us); | ||
2865 | |||
2866 | fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id; | ||
2753 | 2867 | ||
2754 | /* | 2868 | /* |
2755 | * Some peripheral controllers are known not to be able to | 2869 | * Some peripheral controllers are known not to be able to |
2756 | * halt bulk endpoints correctly. If one of them is present, | 2870 | * halt bulk endpoints correctly. If one of them is present, |
2757 | * disable stalls. | 2871 | * disable stalls. |
2758 | */ | 2872 | */ |
2759 | common->can_stall = cfg->can_stall && | 2873 | common->can_stall = can_stall && !(gadget_is_at91(common->gadget)); |
2760 | !(gadget_is_at91(common->gadget)); | ||
2761 | 2874 | ||
2762 | spin_lock_init(&common->lock); | 2875 | return 0; |
2763 | kref_init(&common->ref); | 2876 | } |
2877 | EXPORT_SYMBOL_GPL(fsg_common_set_cdev); | ||
2764 | 2878 | ||
2765 | /* Tell the thread to start working */ | 2879 | static inline int fsg_common_add_sysfs(struct fsg_common *common, |
2766 | common->thread_task = | 2880 | struct fsg_lun *lun) |
2767 | kthread_create(fsg_main_thread, common, "file-storage"); | 2881 | { |
2768 | if (IS_ERR(common->thread_task)) { | 2882 | int rc; |
2769 | rc = PTR_ERR(common->thread_task); | 2883 | |
2770 | goto error_release; | 2884 | rc = device_register(&lun->dev); |
2885 | if (rc) { | ||
2886 | put_device(&lun->dev); | ||
2887 | return rc; | ||
2771 | } | 2888 | } |
2772 | init_completion(&common->thread_notifier); | ||
2773 | init_waitqueue_head(&common->fsg_wait); | ||
2774 | 2889 | ||
2775 | /* Information */ | 2890 | rc = device_create_file(&lun->dev, |
2776 | INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); | 2891 | lun->cdrom |
2777 | INFO(common, "Number of LUNs=%d\n", common->nluns); | 2892 | ? &dev_attr_ro_cdrom |
2893 | : &dev_attr_ro); | ||
2894 | if (rc) | ||
2895 | goto error; | ||
2896 | rc = device_create_file(&lun->dev, | ||
2897 | lun->removable | ||
2898 | ? &dev_attr_file | ||
2899 | : &dev_attr_file_nonremovable); | ||
2900 | if (rc) | ||
2901 | goto error; | ||
2902 | rc = device_create_file(&lun->dev, &dev_attr_nofua); | ||
2903 | if (rc) | ||
2904 | goto error; | ||
2905 | |||
2906 | return 0; | ||
2907 | |||
2908 | error: | ||
2909 | /* removing nonexistent files is a no-op */ | ||
2910 | fsg_common_remove_sysfs(lun); | ||
2911 | device_unregister(&lun->dev); | ||
2912 | return rc; | ||
2913 | } | ||
2914 | |||
2915 | int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, | ||
2916 | unsigned int id, const char *name, | ||
2917 | const char **name_pfx) | ||
2918 | { | ||
2919 | struct fsg_lun *lun; | ||
2920 | char *pathbuf, *p; | ||
2921 | int rc = -ENOMEM; | ||
2922 | |||
2923 | if (!common->nluns || !common->luns) | ||
2924 | return -ENODEV; | ||
2925 | |||
2926 | if (common->luns[id]) | ||
2927 | return -EBUSY; | ||
2928 | |||
2929 | if (!cfg->filename && !cfg->removable) { | ||
2930 | pr_err("no file given for LUN%d\n", id); | ||
2931 | return -EINVAL; | ||
2932 | } | ||
2933 | |||
2934 | lun = kzalloc(sizeof(*lun), GFP_KERNEL); | ||
2935 | if (!lun) | ||
2936 | return -ENOMEM; | ||
2937 | |||
2938 | lun->name_pfx = name_pfx; | ||
2939 | |||
2940 | lun->cdrom = !!cfg->cdrom; | ||
2941 | lun->ro = cfg->cdrom || cfg->ro; | ||
2942 | lun->initially_ro = lun->ro; | ||
2943 | lun->removable = !!cfg->removable; | ||
2944 | |||
2945 | if (!common->sysfs) { | ||
2946 | /* we DON'T own the name!*/ | ||
2947 | lun->name = name; | ||
2948 | } else { | ||
2949 | lun->dev.release = fsg_lun_release; | ||
2950 | lun->dev.parent = &common->gadget->dev; | ||
2951 | dev_set_drvdata(&lun->dev, &common->filesem); | ||
2952 | dev_set_name(&lun->dev, "%s", name); | ||
2953 | lun->name = dev_name(&lun->dev); | ||
2954 | |||
2955 | rc = fsg_common_add_sysfs(common, lun); | ||
2956 | if (rc) { | ||
2957 | pr_info("failed to register LUN%d: %d\n", id, rc); | ||
2958 | goto error_sysfs; | ||
2959 | } | ||
2960 | } | ||
2961 | |||
2962 | common->luns[id] = lun; | ||
2963 | |||
2964 | if (cfg->filename) { | ||
2965 | rc = fsg_lun_open(lun, cfg->filename); | ||
2966 | if (rc) | ||
2967 | goto error_lun; | ||
2968 | } | ||
2778 | 2969 | ||
2779 | pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); | 2970 | pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); |
2780 | for (i = 0, nluns = common->nluns, curlun = common->luns; | 2971 | p = "(no medium)"; |
2781 | i < nluns; | 2972 | if (fsg_lun_is_open(lun)) { |
2782 | ++curlun, ++i) { | 2973 | p = "(error)"; |
2783 | char *p = "(no medium)"; | 2974 | if (pathbuf) { |
2784 | if (fsg_lun_is_open(curlun)) { | 2975 | p = d_path(&lun->filp->f_path, pathbuf, PATH_MAX); |
2785 | p = "(error)"; | 2976 | if (IS_ERR(p)) |
2786 | if (pathbuf) { | 2977 | p = "(error)"; |
2787 | p = d_path(&curlun->filp->f_path, | ||
2788 | pathbuf, PATH_MAX); | ||
2789 | if (IS_ERR(p)) | ||
2790 | p = "(error)"; | ||
2791 | } | ||
2792 | } | 2978 | } |
2793 | LINFO(curlun, "LUN: %s%s%sfile: %s\n", | ||
2794 | curlun->removable ? "removable " : "", | ||
2795 | curlun->ro ? "read only " : "", | ||
2796 | curlun->cdrom ? "CD-ROM " : "", | ||
2797 | p); | ||
2798 | } | 2979 | } |
2980 | pr_info("LUN: %s%s%sfile: %s\n", | ||
2981 | lun->removable ? "removable " : "", | ||
2982 | lun->ro ? "read only " : "", | ||
2983 | lun->cdrom ? "CD-ROM " : "", | ||
2984 | p); | ||
2799 | kfree(pathbuf); | 2985 | kfree(pathbuf); |
2800 | 2986 | ||
2987 | return 0; | ||
2988 | |||
2989 | error_lun: | ||
2990 | if (common->sysfs) { | ||
2991 | fsg_common_remove_sysfs(lun); | ||
2992 | device_unregister(&lun->dev); | ||
2993 | } | ||
2994 | fsg_lun_close(lun); | ||
2995 | common->luns[id] = NULL; | ||
2996 | error_sysfs: | ||
2997 | kfree(lun); | ||
2998 | return rc; | ||
2999 | } | ||
3000 | EXPORT_SYMBOL_GPL(fsg_common_create_lun); | ||
3001 | |||
3002 | int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg) | ||
3003 | { | ||
3004 | char buf[8]; /* enough for 100000000 different numbers, decimal */ | ||
3005 | int i, rc; | ||
3006 | |||
3007 | for (i = 0; i < common->nluns; ++i) { | ||
3008 | snprintf(buf, sizeof(buf), "lun%d", i); | ||
3009 | rc = fsg_common_create_lun(common, &cfg->luns[i], i, buf, NULL); | ||
3010 | if (rc) | ||
3011 | goto fail; | ||
3012 | } | ||
3013 | |||
3014 | pr_info("Number of LUNs=%d\n", common->nluns); | ||
3015 | |||
3016 | return 0; | ||
3017 | |||
3018 | fail: | ||
3019 | _fsg_common_remove_luns(common, i); | ||
3020 | return rc; | ||
3021 | } | ||
3022 | EXPORT_SYMBOL_GPL(fsg_common_create_luns); | ||
3023 | |||
3024 | void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn, | ||
3025 | const char *pn) | ||
3026 | { | ||
3027 | int i; | ||
3028 | |||
3029 | /* Prepare inquiryString */ | ||
3030 | i = get_default_bcdDevice(); | ||
3031 | snprintf(common->inquiry_string, sizeof(common->inquiry_string), | ||
3032 | "%-8s%-16s%04x", vn ?: "Linux", | ||
3033 | /* Assume product name dependent on the first LUN */ | ||
3034 | pn ?: ((*common->luns)->cdrom | ||
3035 | ? "File-CD Gadget" | ||
3036 | : "File-Stor Gadget"), | ||
3037 | i); | ||
3038 | } | ||
3039 | EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string); | ||
3040 | |||
3041 | int fsg_common_run_thread(struct fsg_common *common) | ||
3042 | { | ||
3043 | common->state = FSG_STATE_IDLE; | ||
3044 | /* Tell the thread to start working */ | ||
3045 | common->thread_task = | ||
3046 | kthread_create(fsg_main_thread, common, "file-storage"); | ||
3047 | if (IS_ERR(common->thread_task)) { | ||
3048 | common->state = FSG_STATE_TERMINATED; | ||
3049 | return PTR_ERR(common->thread_task); | ||
3050 | } | ||
3051 | |||
2801 | DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task)); | 3052 | DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task)); |
2802 | 3053 | ||
2803 | wake_up_process(common->thread_task); | 3054 | wake_up_process(common->thread_task); |
2804 | 3055 | ||
2805 | return common; | 3056 | return 0; |
2806 | |||
2807 | error_luns: | ||
2808 | common->nluns = i + 1; | ||
2809 | error_release: | ||
2810 | common->state = FSG_STATE_TERMINATED; /* The thread is dead */ | ||
2811 | /* Call fsg_common_release() directly, ref might be not initialised. */ | ||
2812 | fsg_common_release(&common->ref); | ||
2813 | return ERR_PTR(rc); | ||
2814 | } | 3057 | } |
3058 | EXPORT_SYMBOL_GPL(fsg_common_run_thread); | ||
2815 | 3059 | ||
2816 | static void fsg_common_release(struct kref *ref) | 3060 | static void fsg_common_release(struct kref *ref) |
2817 | { | 3061 | { |
@@ -2824,36 +3068,26 @@ static void fsg_common_release(struct kref *ref) | |||
2824 | } | 3068 | } |
2825 | 3069 | ||
2826 | if (likely(common->luns)) { | 3070 | if (likely(common->luns)) { |
2827 | struct fsg_lun *lun = common->luns; | 3071 | struct fsg_lun **lun_it = common->luns; |
2828 | unsigned i = common->nluns; | 3072 | unsigned i = common->nluns; |
2829 | 3073 | ||
2830 | /* In error recovery common->nluns may be zero. */ | 3074 | /* In error recovery common->nluns may be zero. */ |
2831 | for (; i; --i, ++lun) { | 3075 | for (; i; --i, ++lun_it) { |
2832 | device_remove_file(&lun->dev, &dev_attr_nofua); | 3076 | struct fsg_lun *lun = *lun_it; |
2833 | device_remove_file(&lun->dev, | 3077 | if (!lun) |
2834 | lun->cdrom | 3078 | continue; |
2835 | ? &dev_attr_ro_cdrom | 3079 | if (common->sysfs) |
2836 | : &dev_attr_ro); | 3080 | fsg_common_remove_sysfs(lun); |
2837 | device_remove_file(&lun->dev, | ||
2838 | lun->removable | ||
2839 | ? &dev_attr_file | ||
2840 | : &dev_attr_file_nonremovable); | ||
2841 | fsg_lun_close(lun); | 3081 | fsg_lun_close(lun); |
2842 | device_unregister(&lun->dev); | 3082 | if (common->sysfs) |
3083 | device_unregister(&lun->dev); | ||
3084 | kfree(lun); | ||
2843 | } | 3085 | } |
2844 | 3086 | ||
2845 | kfree(common->luns); | 3087 | kfree(common->luns); |
2846 | } | 3088 | } |
2847 | 3089 | ||
2848 | { | 3090 | _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); |
2849 | struct fsg_buffhd *bh = common->buffhds; | ||
2850 | unsigned i = fsg_num_buffers; | ||
2851 | do { | ||
2852 | kfree(bh->buf); | ||
2853 | } while (++bh, --i); | ||
2854 | } | ||
2855 | |||
2856 | kfree(common->buffhds); | ||
2857 | if (common->free_storage_on_release) | 3091 | if (common->free_storage_on_release) |
2858 | kfree(common); | 3092 | kfree(common); |
2859 | } | 3093 | } |
@@ -2861,24 +3095,6 @@ static void fsg_common_release(struct kref *ref) | |||
2861 | 3095 | ||
2862 | /*-------------------------------------------------------------------------*/ | 3096 | /*-------------------------------------------------------------------------*/ |
2863 | 3097 | ||
2864 | static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) | ||
2865 | { | ||
2866 | struct fsg_dev *fsg = fsg_from_func(f); | ||
2867 | struct fsg_common *common = fsg->common; | ||
2868 | |||
2869 | DBG(fsg, "unbind\n"); | ||
2870 | if (fsg->common->fsg == fsg) { | ||
2871 | fsg->common->new_fsg = NULL; | ||
2872 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); | ||
2873 | /* FIXME: make interruptible or killable somehow? */ | ||
2874 | wait_event(common->fsg_wait, common->fsg != fsg); | ||
2875 | } | ||
2876 | |||
2877 | fsg_common_put(common); | ||
2878 | usb_free_all_descriptors(&fsg->function); | ||
2879 | kfree(fsg); | ||
2880 | } | ||
2881 | |||
2882 | static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | 3098 | static int fsg_bind(struct usb_configuration *c, struct usb_function *f) |
2883 | { | 3099 | { |
2884 | struct fsg_dev *fsg = fsg_from_func(f); | 3100 | struct fsg_dev *fsg = fsg_from_func(f); |
@@ -2887,6 +3103,19 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | |||
2887 | struct usb_ep *ep; | 3103 | struct usb_ep *ep; |
2888 | unsigned max_burst; | 3104 | unsigned max_burst; |
2889 | int ret; | 3105 | int ret; |
3106 | struct fsg_opts *opts; | ||
3107 | |||
3108 | opts = fsg_opts_from_func_inst(f->fi); | ||
3109 | if (!opts->no_configfs) { | ||
3110 | ret = fsg_common_set_cdev(fsg->common, c->cdev, | ||
3111 | fsg->common->can_stall); | ||
3112 | if (ret) | ||
3113 | return ret; | ||
3114 | fsg_common_set_inquiry_string(fsg->common, 0, 0); | ||
3115 | ret = fsg_common_run_thread(fsg->common); | ||
3116 | if (ret) | ||
3117 | return ret; | ||
3118 | } | ||
2890 | 3119 | ||
2891 | fsg->gadget = gadget; | 3120 | fsg->gadget = gadget; |
2892 | 3121 | ||
@@ -2939,95 +3168,472 @@ autoconf_fail: | |||
2939 | return -ENOTSUPP; | 3168 | return -ENOTSUPP; |
2940 | } | 3169 | } |
2941 | 3170 | ||
2942 | /****************************** ADD FUNCTION ******************************/ | 3171 | /****************************** ALLOCATE FUNCTION *************************/ |
2943 | 3172 | ||
2944 | static struct usb_gadget_strings *fsg_strings_array[] = { | 3173 | static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) |
2945 | &fsg_stringtab, | 3174 | { |
3175 | struct fsg_dev *fsg = fsg_from_func(f); | ||
3176 | struct fsg_common *common = fsg->common; | ||
3177 | |||
3178 | DBG(fsg, "unbind\n"); | ||
3179 | if (fsg->common->fsg == fsg) { | ||
3180 | fsg->common->new_fsg = NULL; | ||
3181 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); | ||
3182 | /* FIXME: make interruptible or killable somehow? */ | ||
3183 | wait_event(common->fsg_wait, common->fsg != fsg); | ||
3184 | } | ||
3185 | |||
3186 | usb_free_all_descriptors(&fsg->function); | ||
3187 | } | ||
3188 | |||
3189 | static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item) | ||
3190 | { | ||
3191 | return container_of(to_config_group(item), struct fsg_lun_opts, group); | ||
3192 | } | ||
3193 | |||
3194 | static inline struct fsg_opts *to_fsg_opts(struct config_item *item) | ||
3195 | { | ||
3196 | return container_of(to_config_group(item), struct fsg_opts, | ||
3197 | func_inst.group); | ||
3198 | } | ||
3199 | |||
3200 | CONFIGFS_ATTR_STRUCT(fsg_lun_opts); | ||
3201 | CONFIGFS_ATTR_OPS(fsg_lun_opts); | ||
3202 | |||
3203 | static void fsg_lun_attr_release(struct config_item *item) | ||
3204 | { | ||
3205 | struct fsg_lun_opts *lun_opts; | ||
3206 | |||
3207 | lun_opts = to_fsg_lun_opts(item); | ||
3208 | kfree(lun_opts); | ||
3209 | } | ||
3210 | |||
3211 | static struct configfs_item_operations fsg_lun_item_ops = { | ||
3212 | .release = fsg_lun_attr_release, | ||
3213 | .show_attribute = fsg_lun_opts_attr_show, | ||
3214 | .store_attribute = fsg_lun_opts_attr_store, | ||
3215 | }; | ||
3216 | |||
3217 | static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page) | ||
3218 | { | ||
3219 | struct fsg_opts *fsg_opts; | ||
3220 | |||
3221 | fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); | ||
3222 | |||
3223 | return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page); | ||
3224 | } | ||
3225 | |||
3226 | static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts, | ||
3227 | const char *page, size_t len) | ||
3228 | { | ||
3229 | struct fsg_opts *fsg_opts; | ||
3230 | |||
3231 | fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); | ||
3232 | |||
3233 | return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len); | ||
3234 | } | ||
3235 | |||
3236 | static struct fsg_lun_opts_attribute fsg_lun_opts_file = | ||
3237 | __CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show, | ||
3238 | fsg_lun_opts_file_store); | ||
3239 | |||
3240 | static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page) | ||
3241 | { | ||
3242 | return fsg_show_ro(opts->lun, page); | ||
3243 | } | ||
3244 | |||
3245 | static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts, | ||
3246 | const char *page, size_t len) | ||
3247 | { | ||
3248 | struct fsg_opts *fsg_opts; | ||
3249 | |||
3250 | fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); | ||
3251 | |||
3252 | return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len); | ||
3253 | } | ||
3254 | |||
3255 | static struct fsg_lun_opts_attribute fsg_lun_opts_ro = | ||
3256 | __CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show, | ||
3257 | fsg_lun_opts_ro_store); | ||
3258 | |||
3259 | static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts, | ||
3260 | char *page) | ||
3261 | { | ||
3262 | return fsg_show_removable(opts->lun, page); | ||
3263 | } | ||
3264 | |||
3265 | static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts, | ||
3266 | const char *page, size_t len) | ||
3267 | { | ||
3268 | return fsg_store_removable(opts->lun, page, len); | ||
3269 | } | ||
3270 | |||
3271 | static struct fsg_lun_opts_attribute fsg_lun_opts_removable = | ||
3272 | __CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR, | ||
3273 | fsg_lun_opts_removable_show, | ||
3274 | fsg_lun_opts_removable_store); | ||
3275 | |||
3276 | static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page) | ||
3277 | { | ||
3278 | return fsg_show_cdrom(opts->lun, page); | ||
3279 | } | ||
3280 | |||
3281 | static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts, | ||
3282 | const char *page, size_t len) | ||
3283 | { | ||
3284 | struct fsg_opts *fsg_opts; | ||
3285 | |||
3286 | fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); | ||
3287 | |||
3288 | return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page, | ||
3289 | len); | ||
3290 | } | ||
3291 | |||
3292 | static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom = | ||
3293 | __CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show, | ||
3294 | fsg_lun_opts_cdrom_store); | ||
3295 | |||
3296 | static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page) | ||
3297 | { | ||
3298 | return fsg_show_nofua(opts->lun, page); | ||
3299 | } | ||
3300 | |||
3301 | static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts, | ||
3302 | const char *page, size_t len) | ||
3303 | { | ||
3304 | return fsg_store_nofua(opts->lun, page, len); | ||
3305 | } | ||
3306 | |||
3307 | static struct fsg_lun_opts_attribute fsg_lun_opts_nofua = | ||
3308 | __CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show, | ||
3309 | fsg_lun_opts_nofua_store); | ||
3310 | |||
3311 | static struct configfs_attribute *fsg_lun_attrs[] = { | ||
3312 | &fsg_lun_opts_file.attr, | ||
3313 | &fsg_lun_opts_ro.attr, | ||
3314 | &fsg_lun_opts_removable.attr, | ||
3315 | &fsg_lun_opts_cdrom.attr, | ||
3316 | &fsg_lun_opts_nofua.attr, | ||
2946 | NULL, | 3317 | NULL, |
2947 | }; | 3318 | }; |
2948 | 3319 | ||
2949 | static int fsg_bind_config(struct usb_composite_dev *cdev, | 3320 | static struct config_item_type fsg_lun_type = { |
2950 | struct usb_configuration *c, | 3321 | .ct_item_ops = &fsg_lun_item_ops, |
2951 | struct fsg_common *common) | 3322 | .ct_attrs = fsg_lun_attrs, |
3323 | .ct_owner = THIS_MODULE, | ||
3324 | }; | ||
3325 | |||
3326 | static struct config_group *fsg_lun_make(struct config_group *group, | ||
3327 | const char *name) | ||
2952 | { | 3328 | { |
2953 | struct fsg_dev *fsg; | 3329 | struct fsg_lun_opts *opts; |
3330 | struct fsg_opts *fsg_opts; | ||
3331 | struct fsg_lun_config config; | ||
3332 | char *num_str; | ||
3333 | u8 num; | ||
3334 | int ret; | ||
3335 | |||
3336 | num_str = strchr(name, '.'); | ||
3337 | if (!num_str) { | ||
3338 | pr_err("Unable to locate . in LUN.NUMBER\n"); | ||
3339 | return ERR_PTR(-EINVAL); | ||
3340 | } | ||
3341 | num_str++; | ||
3342 | |||
3343 | ret = kstrtou8(num_str, 0, &num); | ||
3344 | if (ret) | ||
3345 | return ERR_PTR(ret); | ||
3346 | |||
3347 | fsg_opts = to_fsg_opts(&group->cg_item); | ||
3348 | if (num >= FSG_MAX_LUNS) | ||
3349 | return ERR_PTR(-ERANGE); | ||
3350 | |||
3351 | mutex_lock(&fsg_opts->lock); | ||
3352 | if (fsg_opts->refcnt || fsg_opts->common->luns[num]) { | ||
3353 | ret = -EBUSY; | ||
3354 | goto out; | ||
3355 | } | ||
3356 | |||
3357 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
3358 | if (!opts) { | ||
3359 | ret = -ENOMEM; | ||
3360 | goto out; | ||
3361 | } | ||
3362 | |||
3363 | memset(&config, 0, sizeof(config)); | ||
3364 | config.removable = true; | ||
3365 | |||
3366 | ret = fsg_common_create_lun(fsg_opts->common, &config, num, name, | ||
3367 | (const char **)&group->cg_item.ci_name); | ||
3368 | if (ret) { | ||
3369 | kfree(opts); | ||
3370 | goto out; | ||
3371 | } | ||
3372 | opts->lun = fsg_opts->common->luns[num]; | ||
3373 | opts->lun_id = num; | ||
3374 | mutex_unlock(&fsg_opts->lock); | ||
3375 | |||
3376 | config_group_init_type_name(&opts->group, name, &fsg_lun_type); | ||
3377 | |||
3378 | return &opts->group; | ||
3379 | out: | ||
3380 | mutex_unlock(&fsg_opts->lock); | ||
3381 | return ERR_PTR(ret); | ||
3382 | } | ||
3383 | |||
3384 | static void fsg_lun_drop(struct config_group *group, struct config_item *item) | ||
3385 | { | ||
3386 | struct fsg_lun_opts *lun_opts; | ||
3387 | struct fsg_opts *fsg_opts; | ||
3388 | |||
3389 | lun_opts = to_fsg_lun_opts(item); | ||
3390 | fsg_opts = to_fsg_opts(&group->cg_item); | ||
3391 | |||
3392 | mutex_lock(&fsg_opts->lock); | ||
3393 | if (fsg_opts->refcnt) { | ||
3394 | struct config_item *gadget; | ||
3395 | |||
3396 | gadget = group->cg_item.ci_parent->ci_parent; | ||
3397 | unregister_gadget_item(gadget); | ||
3398 | } | ||
3399 | |||
3400 | fsg_common_remove_lun(lun_opts->lun, fsg_opts->common->sysfs); | ||
3401 | fsg_opts->common->luns[lun_opts->lun_id] = NULL; | ||
3402 | lun_opts->lun_id = 0; | ||
3403 | mutex_unlock(&fsg_opts->lock); | ||
3404 | |||
3405 | config_item_put(item); | ||
3406 | } | ||
3407 | |||
3408 | CONFIGFS_ATTR_STRUCT(fsg_opts); | ||
3409 | CONFIGFS_ATTR_OPS(fsg_opts); | ||
3410 | |||
3411 | static void fsg_attr_release(struct config_item *item) | ||
3412 | { | ||
3413 | struct fsg_opts *opts = to_fsg_opts(item); | ||
3414 | |||
3415 | usb_put_function_instance(&opts->func_inst); | ||
3416 | } | ||
3417 | |||
3418 | static struct configfs_item_operations fsg_item_ops = { | ||
3419 | .release = fsg_attr_release, | ||
3420 | .show_attribute = fsg_opts_attr_show, | ||
3421 | .store_attribute = fsg_opts_attr_store, | ||
3422 | }; | ||
3423 | |||
3424 | static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page) | ||
3425 | { | ||
3426 | int result; | ||
3427 | |||
3428 | mutex_lock(&opts->lock); | ||
3429 | result = sprintf(page, "%d", opts->common->can_stall); | ||
3430 | mutex_unlock(&opts->lock); | ||
3431 | |||
3432 | return result; | ||
3433 | } | ||
3434 | |||
3435 | static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page, | ||
3436 | size_t len) | ||
3437 | { | ||
3438 | int ret; | ||
3439 | bool stall; | ||
3440 | |||
3441 | mutex_lock(&opts->lock); | ||
3442 | |||
3443 | if (opts->refcnt) { | ||
3444 | mutex_unlock(&opts->lock); | ||
3445 | return -EBUSY; | ||
3446 | } | ||
3447 | |||
3448 | ret = strtobool(page, &stall); | ||
3449 | if (!ret) { | ||
3450 | opts->common->can_stall = stall; | ||
3451 | ret = len; | ||
3452 | } | ||
3453 | |||
3454 | mutex_unlock(&opts->lock); | ||
3455 | |||
3456 | return ret; | ||
3457 | } | ||
3458 | |||
3459 | static struct fsg_opts_attribute fsg_opts_stall = | ||
3460 | __CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show, | ||
3461 | fsg_opts_stall_store); | ||
3462 | |||
3463 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
3464 | static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page) | ||
3465 | { | ||
3466 | int result; | ||
3467 | |||
3468 | mutex_lock(&opts->lock); | ||
3469 | result = sprintf(page, "%d", opts->common->fsg_num_buffers); | ||
3470 | mutex_unlock(&opts->lock); | ||
3471 | |||
3472 | return result; | ||
3473 | } | ||
3474 | |||
3475 | static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts, | ||
3476 | const char *page, size_t len) | ||
3477 | { | ||
3478 | int ret; | ||
3479 | u8 num; | ||
3480 | |||
3481 | mutex_lock(&opts->lock); | ||
3482 | if (opts->refcnt) { | ||
3483 | ret = -EBUSY; | ||
3484 | goto end; | ||
3485 | } | ||
3486 | ret = kstrtou8(page, 0, &num); | ||
3487 | if (ret) | ||
3488 | goto end; | ||
3489 | |||
3490 | ret = fsg_num_buffers_validate(num); | ||
3491 | if (ret) | ||
3492 | goto end; | ||
3493 | |||
3494 | fsg_common_set_num_buffers(opts->common, num); | ||
3495 | ret = len; | ||
3496 | |||
3497 | end: | ||
3498 | mutex_unlock(&opts->lock); | ||
3499 | return ret; | ||
3500 | } | ||
3501 | |||
3502 | static struct fsg_opts_attribute fsg_opts_num_buffers = | ||
3503 | __CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR, | ||
3504 | fsg_opts_num_buffers_show, | ||
3505 | fsg_opts_num_buffers_store); | ||
3506 | |||
3507 | #endif | ||
3508 | |||
3509 | static struct configfs_attribute *fsg_attrs[] = { | ||
3510 | &fsg_opts_stall.attr, | ||
3511 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
3512 | &fsg_opts_num_buffers.attr, | ||
3513 | #endif | ||
3514 | NULL, | ||
3515 | }; | ||
3516 | |||
3517 | static struct configfs_group_operations fsg_group_ops = { | ||
3518 | .make_group = fsg_lun_make, | ||
3519 | .drop_item = fsg_lun_drop, | ||
3520 | }; | ||
3521 | |||
3522 | static struct config_item_type fsg_func_type = { | ||
3523 | .ct_item_ops = &fsg_item_ops, | ||
3524 | .ct_group_ops = &fsg_group_ops, | ||
3525 | .ct_attrs = fsg_attrs, | ||
3526 | .ct_owner = THIS_MODULE, | ||
3527 | }; | ||
3528 | |||
3529 | static void fsg_free_inst(struct usb_function_instance *fi) | ||
3530 | { | ||
3531 | struct fsg_opts *opts; | ||
3532 | |||
3533 | opts = fsg_opts_from_func_inst(fi); | ||
3534 | fsg_common_put(opts->common); | ||
3535 | kfree(opts); | ||
3536 | } | ||
3537 | |||
3538 | static struct usb_function_instance *fsg_alloc_inst(void) | ||
3539 | { | ||
3540 | struct fsg_opts *opts; | ||
3541 | struct fsg_lun_config config; | ||
2954 | int rc; | 3542 | int rc; |
2955 | 3543 | ||
2956 | fsg = kzalloc(sizeof *fsg, GFP_KERNEL); | 3544 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); |
3545 | if (!opts) | ||
3546 | return ERR_PTR(-ENOMEM); | ||
3547 | mutex_init(&opts->lock); | ||
3548 | opts->func_inst.free_func_inst = fsg_free_inst; | ||
3549 | opts->common = fsg_common_setup(opts->common); | ||
3550 | if (IS_ERR(opts->common)) { | ||
3551 | rc = PTR_ERR(opts->common); | ||
3552 | goto release_opts; | ||
3553 | } | ||
3554 | rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS); | ||
3555 | if (rc) | ||
3556 | goto release_opts; | ||
3557 | |||
3558 | rc = fsg_common_set_num_buffers(opts->common, | ||
3559 | CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS); | ||
3560 | if (rc) | ||
3561 | goto release_luns; | ||
3562 | |||
3563 | pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); | ||
3564 | |||
3565 | memset(&config, 0, sizeof(config)); | ||
3566 | config.removable = true; | ||
3567 | rc = fsg_common_create_lun(opts->common, &config, 0, "lun.0", | ||
3568 | (const char **)&opts->func_inst.group.cg_item.ci_name); | ||
3569 | opts->lun0.lun = opts->common->luns[0]; | ||
3570 | opts->lun0.lun_id = 0; | ||
3571 | config_group_init_type_name(&opts->lun0.group, "lun.0", &fsg_lun_type); | ||
3572 | opts->default_groups[0] = &opts->lun0.group; | ||
3573 | opts->func_inst.group.default_groups = opts->default_groups; | ||
3574 | |||
3575 | config_group_init_type_name(&opts->func_inst.group, "", &fsg_func_type); | ||
3576 | |||
3577 | return &opts->func_inst; | ||
3578 | |||
3579 | release_luns: | ||
3580 | kfree(opts->common->luns); | ||
3581 | release_opts: | ||
3582 | kfree(opts); | ||
3583 | return ERR_PTR(rc); | ||
3584 | } | ||
3585 | |||
3586 | static void fsg_free(struct usb_function *f) | ||
3587 | { | ||
3588 | struct fsg_dev *fsg; | ||
3589 | struct fsg_opts *opts; | ||
3590 | |||
3591 | fsg = container_of(f, struct fsg_dev, function); | ||
3592 | opts = container_of(f->fi, struct fsg_opts, func_inst); | ||
3593 | |||
3594 | mutex_lock(&opts->lock); | ||
3595 | opts->refcnt--; | ||
3596 | mutex_unlock(&opts->lock); | ||
3597 | |||
3598 | kfree(fsg); | ||
3599 | } | ||
3600 | |||
3601 | static struct usb_function *fsg_alloc(struct usb_function_instance *fi) | ||
3602 | { | ||
3603 | struct fsg_opts *opts = fsg_opts_from_func_inst(fi); | ||
3604 | struct fsg_common *common = opts->common; | ||
3605 | struct fsg_dev *fsg; | ||
3606 | |||
3607 | fsg = kzalloc(sizeof(*fsg), GFP_KERNEL); | ||
2957 | if (unlikely(!fsg)) | 3608 | if (unlikely(!fsg)) |
2958 | return -ENOMEM; | 3609 | return ERR_PTR(-ENOMEM); |
2959 | 3610 | ||
2960 | fsg->function.name = FSG_DRIVER_DESC; | 3611 | mutex_lock(&opts->lock); |
2961 | fsg->function.strings = fsg_strings_array; | 3612 | opts->refcnt++; |
2962 | fsg->function.bind = fsg_bind; | 3613 | mutex_unlock(&opts->lock); |
2963 | fsg->function.unbind = fsg_unbind; | 3614 | fsg->function.name = FSG_DRIVER_DESC; |
2964 | fsg->function.setup = fsg_setup; | 3615 | fsg->function.bind = fsg_bind; |
2965 | fsg->function.set_alt = fsg_set_alt; | 3616 | fsg->function.unbind = fsg_unbind; |
2966 | fsg->function.disable = fsg_disable; | 3617 | fsg->function.setup = fsg_setup; |
3618 | fsg->function.set_alt = fsg_set_alt; | ||
3619 | fsg->function.disable = fsg_disable; | ||
3620 | fsg->function.free_func = fsg_free; | ||
2967 | 3621 | ||
2968 | fsg->common = common; | 3622 | fsg->common = common; |
2969 | /* | ||
2970 | * Our caller holds a reference to common structure so we | ||
2971 | * don't have to be worry about it being freed until we return | ||
2972 | * from this function. So instead of incrementing counter now | ||
2973 | * and decrement in error recovery we increment it only when | ||
2974 | * call to usb_add_function() was successful. | ||
2975 | */ | ||
2976 | 3623 | ||
2977 | rc = usb_add_function(c, &fsg->function); | 3624 | return &fsg->function; |
2978 | if (unlikely(rc)) | ||
2979 | kfree(fsg); | ||
2980 | else | ||
2981 | fsg_common_get(fsg->common); | ||
2982 | return rc; | ||
2983 | } | 3625 | } |
2984 | 3626 | ||
3627 | DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc); | ||
3628 | MODULE_LICENSE("GPL"); | ||
3629 | MODULE_AUTHOR("Michal Nazarewicz"); | ||
2985 | 3630 | ||
2986 | /************************* Module parameters *************************/ | 3631 | /************************* Module parameters *************************/ |
2987 | 3632 | ||
2988 | struct fsg_module_parameters { | ||
2989 | char *file[FSG_MAX_LUNS]; | ||
2990 | bool ro[FSG_MAX_LUNS]; | ||
2991 | bool removable[FSG_MAX_LUNS]; | ||
2992 | bool cdrom[FSG_MAX_LUNS]; | ||
2993 | bool nofua[FSG_MAX_LUNS]; | ||
2994 | |||
2995 | unsigned int file_count, ro_count, removable_count, cdrom_count; | ||
2996 | unsigned int nofua_count; | ||
2997 | unsigned int luns; /* nluns */ | ||
2998 | bool stall; /* can_stall */ | ||
2999 | }; | ||
3000 | 3633 | ||
3001 | #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ | 3634 | void fsg_config_from_params(struct fsg_config *cfg, |
3002 | module_param_array_named(prefix ## name, params.name, type, \ | 3635 | const struct fsg_module_parameters *params, |
3003 | &prefix ## params.name ## _count, \ | 3636 | unsigned int fsg_num_buffers) |
3004 | S_IRUGO); \ | ||
3005 | MODULE_PARM_DESC(prefix ## name, desc) | ||
3006 | |||
3007 | #define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \ | ||
3008 | module_param_named(prefix ## name, params.name, type, \ | ||
3009 | S_IRUGO); \ | ||
3010 | MODULE_PARM_DESC(prefix ## name, desc) | ||
3011 | |||
3012 | #define FSG_MODULE_PARAMETERS(prefix, params) \ | ||
3013 | _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \ | ||
3014 | "names of backing files or devices"); \ | ||
3015 | _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \ | ||
3016 | "true to force read-only"); \ | ||
3017 | _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \ | ||
3018 | "true to simulate removable media"); \ | ||
3019 | _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ | ||
3020 | "true to simulate CD-ROM instead of disk"); \ | ||
3021 | _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \ | ||
3022 | "true to ignore SCSI WRITE(10,12) FUA bit"); \ | ||
3023 | _FSG_MODULE_PARAM(prefix, params, luns, uint, \ | ||
3024 | "number of LUNs"); \ | ||
3025 | _FSG_MODULE_PARAM(prefix, params, stall, bool, \ | ||
3026 | "false to prevent bulk stalls") | ||
3027 | |||
3028 | static void | ||
3029 | fsg_config_from_params(struct fsg_config *cfg, | ||
3030 | const struct fsg_module_parameters *params) | ||
3031 | { | 3637 | { |
3032 | struct fsg_lun_config *lun; | 3638 | struct fsg_lun_config *lun; |
3033 | unsigned i; | 3639 | unsigned i; |
@@ -3055,19 +3661,7 @@ fsg_config_from_params(struct fsg_config *cfg, | |||
3055 | 3661 | ||
3056 | /* Finalise */ | 3662 | /* Finalise */ |
3057 | cfg->can_stall = params->stall; | 3663 | cfg->can_stall = params->stall; |
3664 | cfg->fsg_num_buffers = fsg_num_buffers; | ||
3058 | } | 3665 | } |
3666 | EXPORT_SYMBOL_GPL(fsg_config_from_params); | ||
3059 | 3667 | ||
3060 | static inline struct fsg_common * | ||
3061 | fsg_common_from_params(struct fsg_common *common, | ||
3062 | struct usb_composite_dev *cdev, | ||
3063 | const struct fsg_module_parameters *params) | ||
3064 | __attribute__((unused)); | ||
3065 | static inline struct fsg_common * | ||
3066 | fsg_common_from_params(struct fsg_common *common, | ||
3067 | struct usb_composite_dev *cdev, | ||
3068 | const struct fsg_module_parameters *params) | ||
3069 | { | ||
3070 | struct fsg_config cfg; | ||
3071 | fsg_config_from_params(&cfg, params); | ||
3072 | return fsg_common_init(common, cdev, &cfg); | ||
3073 | } | ||
diff --git a/drivers/usb/gadget/f_mass_storage.h b/drivers/usb/gadget/f_mass_storage.h new file mode 100644 index 000000000000..b4866fcef30b --- /dev/null +++ b/drivers/usb/gadget/f_mass_storage.h | |||
@@ -0,0 +1,166 @@ | |||
1 | #ifndef USB_F_MASS_STORAGE_H | ||
2 | #define USB_F_MASS_STORAGE_H | ||
3 | |||
4 | #include <linux/usb/composite.h> | ||
5 | #include "storage_common.h" | ||
6 | |||
7 | struct fsg_module_parameters { | ||
8 | char *file[FSG_MAX_LUNS]; | ||
9 | bool ro[FSG_MAX_LUNS]; | ||
10 | bool removable[FSG_MAX_LUNS]; | ||
11 | bool cdrom[FSG_MAX_LUNS]; | ||
12 | bool nofua[FSG_MAX_LUNS]; | ||
13 | |||
14 | unsigned int file_count, ro_count, removable_count, cdrom_count; | ||
15 | unsigned int nofua_count; | ||
16 | unsigned int luns; /* nluns */ | ||
17 | bool stall; /* can_stall */ | ||
18 | }; | ||
19 | |||
20 | #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ | ||
21 | module_param_array_named(prefix ## name, params.name, type, \ | ||
22 | &prefix ## params.name ## _count, \ | ||
23 | S_IRUGO); \ | ||
24 | MODULE_PARM_DESC(prefix ## name, desc) | ||
25 | |||
26 | #define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \ | ||
27 | module_param_named(prefix ## name, params.name, type, \ | ||
28 | S_IRUGO); \ | ||
29 | MODULE_PARM_DESC(prefix ## name, desc) | ||
30 | |||
31 | #define __FSG_MODULE_PARAMETERS(prefix, params) \ | ||
32 | _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \ | ||
33 | "names of backing files or devices"); \ | ||
34 | _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \ | ||
35 | "true to force read-only"); \ | ||
36 | _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \ | ||
37 | "true to simulate removable media"); \ | ||
38 | _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ | ||
39 | "true to simulate CD-ROM instead of disk"); \ | ||
40 | _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \ | ||
41 | "true to ignore SCSI WRITE(10,12) FUA bit"); \ | ||
42 | _FSG_MODULE_PARAM(prefix, params, luns, uint, \ | ||
43 | "number of LUNs"); \ | ||
44 | _FSG_MODULE_PARAM(prefix, params, stall, bool, \ | ||
45 | "false to prevent bulk stalls") | ||
46 | |||
47 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
48 | |||
49 | #define FSG_MODULE_PARAMETERS(prefix, params) \ | ||
50 | __FSG_MODULE_PARAMETERS(prefix, params); \ | ||
51 | module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\ | ||
52 | MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers") | ||
53 | #else | ||
54 | |||
55 | #define FSG_MODULE_PARAMETERS(prefix, params) \ | ||
56 | __FSG_MODULE_PARAMETERS(prefix, params) | ||
57 | |||
58 | #endif | ||
59 | |||
60 | struct fsg_common; | ||
61 | |||
62 | /* FSF callback functions */ | ||
63 | struct fsg_operations { | ||
64 | /* | ||
65 | * Callback function to call when thread exits. If no | ||
66 | * callback is set or it returns value lower then zero MSF | ||
67 | * will force eject all LUNs it operates on (including those | ||
68 | * marked as non-removable or with prevent_medium_removal flag | ||
69 | * set). | ||
70 | */ | ||
71 | int (*thread_exits)(struct fsg_common *common); | ||
72 | }; | ||
73 | |||
74 | struct fsg_lun_opts { | ||
75 | struct config_group group; | ||
76 | struct fsg_lun *lun; | ||
77 | int lun_id; | ||
78 | }; | ||
79 | |||
80 | struct fsg_opts { | ||
81 | struct fsg_common *common; | ||
82 | struct usb_function_instance func_inst; | ||
83 | struct fsg_lun_opts lun0; | ||
84 | struct config_group *default_groups[2]; | ||
85 | bool no_configfs; /* for legacy gadgets */ | ||
86 | |||
87 | /* | ||
88 | * Read/write access to configfs attributes is handled by configfs. | ||
89 | * | ||
90 | * This is to protect the data from concurrent access by read/write | ||
91 | * and create symlink/remove symlink. | ||
92 | */ | ||
93 | struct mutex lock; | ||
94 | int refcnt; | ||
95 | }; | ||
96 | |||
97 | struct fsg_lun_config { | ||
98 | const char *filename; | ||
99 | char ro; | ||
100 | char removable; | ||
101 | char cdrom; | ||
102 | char nofua; | ||
103 | }; | ||
104 | |||
105 | struct fsg_config { | ||
106 | unsigned nluns; | ||
107 | struct fsg_lun_config luns[FSG_MAX_LUNS]; | ||
108 | |||
109 | /* Callback functions. */ | ||
110 | const struct fsg_operations *ops; | ||
111 | /* Gadget's private data. */ | ||
112 | void *private_data; | ||
113 | |||
114 | const char *vendor_name; /* 8 characters or less */ | ||
115 | const char *product_name; /* 16 characters or less */ | ||
116 | |||
117 | char can_stall; | ||
118 | unsigned int fsg_num_buffers; | ||
119 | }; | ||
120 | |||
121 | static inline struct fsg_opts * | ||
122 | fsg_opts_from_func_inst(const struct usb_function_instance *fi) | ||
123 | { | ||
124 | return container_of(fi, struct fsg_opts, func_inst); | ||
125 | } | ||
126 | |||
127 | void fsg_common_get(struct fsg_common *common); | ||
128 | |||
129 | void fsg_common_put(struct fsg_common *common); | ||
130 | |||
131 | void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs); | ||
132 | |||
133 | int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n); | ||
134 | |||
135 | void fsg_common_free_buffers(struct fsg_common *common); | ||
136 | |||
137 | int fsg_common_set_cdev(struct fsg_common *common, | ||
138 | struct usb_composite_dev *cdev, bool can_stall); | ||
139 | |||
140 | void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs); | ||
141 | |||
142 | void fsg_common_remove_luns(struct fsg_common *common); | ||
143 | |||
144 | void fsg_common_free_luns(struct fsg_common *common); | ||
145 | |||
146 | int fsg_common_set_nluns(struct fsg_common *common, int nluns); | ||
147 | |||
148 | void fsg_common_set_ops(struct fsg_common *common, | ||
149 | const struct fsg_operations *ops); | ||
150 | |||
151 | int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, | ||
152 | unsigned int id, const char *name, | ||
153 | const char **name_pfx); | ||
154 | |||
155 | int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg); | ||
156 | |||
157 | void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn, | ||
158 | const char *pn); | ||
159 | |||
160 | int fsg_common_run_thread(struct fsg_common *common); | ||
161 | |||
162 | void fsg_config_from_params(struct fsg_config *cfg, | ||
163 | const struct fsg_module_parameters *params, | ||
164 | unsigned int fsg_num_buffers); | ||
165 | |||
166 | #endif /* USB_F_MASS_STORAGE_H */ | ||
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 5327c82472ed..2344efe4f4ce 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -76,7 +76,9 @@ struct gfs_ffs_obj { | |||
76 | 76 | ||
77 | USB_GADGET_COMPOSITE_OPTIONS(); | 77 | USB_GADGET_COMPOSITE_OPTIONS(); |
78 | 78 | ||
79 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | ||
79 | USB_ETHERNET_MODULE_PARAMETERS(); | 80 | USB_ETHERNET_MODULE_PARAMETERS(); |
81 | #endif | ||
80 | 82 | ||
81 | static struct usb_device_descriptor gfs_dev_desc = { | 83 | static struct usb_device_descriptor gfs_dev_desc = { |
82 | .bLength = sizeof gfs_dev_desc, | 84 | .bLength = sizeof gfs_dev_desc, |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index c64deb9e3d62..f82768015715 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -1165,7 +1165,7 @@ static int udc_proc_read(struct seq_file *m, void *v) | |||
1165 | s = "invalid"; break; | 1165 | s = "invalid"; break; |
1166 | default: | 1166 | default: |
1167 | s = "?"; break; | 1167 | s = "?"; break; |
1168 | }; s; }), | 1168 | } s; }), |
1169 | (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", | 1169 | (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", |
1170 | (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", | 1170 | (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", |
1171 | (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", | 1171 | (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", |
@@ -1701,7 +1701,6 @@ static void goku_remove(struct pci_dev *pdev) | |||
1701 | if (dev->enabled) | 1701 | if (dev->enabled) |
1702 | pci_disable_device(pdev); | 1702 | pci_disable_device(pdev); |
1703 | 1703 | ||
1704 | pci_set_drvdata(pdev, NULL); | ||
1705 | dev->regs = NULL; | 1704 | dev->regs = NULL; |
1706 | 1705 | ||
1707 | INFO(dev, "unbind\n"); | 1706 | INFO(dev, "unbind\n"); |
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index 080e577773d5..8e27a8c96444 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c | |||
@@ -37,16 +37,16 @@ | |||
37 | #define DRIVER_DESC "Mass Storage Gadget" | 37 | #define DRIVER_DESC "Mass Storage Gadget" |
38 | #define DRIVER_VERSION "2009/09/11" | 38 | #define DRIVER_VERSION "2009/09/11" |
39 | 39 | ||
40 | /*-------------------------------------------------------------------------*/ | ||
41 | |||
42 | /* | 40 | /* |
43 | * kbuild is not very cooperative with respect to linking separately | 41 | * Thanks to NetChip Technologies for donating this product ID. |
44 | * compiled library objects into one module. So for now we won't use | 42 | * |
45 | * separate compilation ... ensuring init/exit sections work to shrink | 43 | * DO NOT REUSE THESE IDs with any other driver!! Ever!! |
46 | * the runtime footprint, and giving us at least some parts of what | 44 | * Instead: allocate your own, using normal USB-IF procedures. |
47 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
48 | */ | 45 | */ |
49 | #include "f_mass_storage.c" | 46 | #define FSG_VENDOR_ID 0x0525 /* NetChip */ |
47 | #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ | ||
48 | |||
49 | #include "f_mass_storage.h" | ||
50 | 50 | ||
51 | /*-------------------------------------------------------------------------*/ | 51 | /*-------------------------------------------------------------------------*/ |
52 | USB_GADGET_COMPOSITE_OPTIONS(); | 52 | USB_GADGET_COMPOSITE_OPTIONS(); |
@@ -97,11 +97,28 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
97 | NULL, | 97 | NULL, |
98 | }; | 98 | }; |
99 | 99 | ||
100 | static struct usb_function_instance *fi_msg; | ||
101 | static struct usb_function *f_msg; | ||
102 | |||
100 | /****************************** Configurations ******************************/ | 103 | /****************************** Configurations ******************************/ |
101 | 104 | ||
102 | static struct fsg_module_parameters mod_data = { | 105 | static struct fsg_module_parameters mod_data = { |
103 | .stall = 1 | 106 | .stall = 1 |
104 | }; | 107 | }; |
108 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
109 | |||
110 | static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | ||
111 | |||
112 | #else | ||
113 | |||
114 | /* | ||
115 | * Number of buffers we will use. | ||
116 | * 2 is usually enough for good buffering pipeline | ||
117 | */ | ||
118 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | ||
119 | |||
120 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ | ||
121 | |||
105 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); | 122 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); |
106 | 123 | ||
107 | static unsigned long msg_registered; | 124 | static unsigned long msg_registered; |
@@ -115,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common) | |||
115 | 132 | ||
116 | static int __init msg_do_config(struct usb_configuration *c) | 133 | static int __init msg_do_config(struct usb_configuration *c) |
117 | { | 134 | { |
118 | static const struct fsg_operations ops = { | 135 | struct fsg_opts *opts; |
119 | .thread_exits = msg_thread_exits, | ||
120 | }; | ||
121 | static struct fsg_common common; | ||
122 | |||
123 | struct fsg_common *retp; | ||
124 | struct fsg_config config; | ||
125 | int ret; | 136 | int ret; |
126 | 137 | ||
127 | if (gadget_is_otg(c->cdev->gadget)) { | 138 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -129,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration *c) | |||
129 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 140 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
130 | } | 141 | } |
131 | 142 | ||
132 | fsg_config_from_params(&config, &mod_data); | 143 | opts = fsg_opts_from_func_inst(fi_msg); |
133 | config.ops = &ops; | 144 | |
145 | f_msg = usb_get_function(fi_msg); | ||
146 | if (IS_ERR(f_msg)) | ||
147 | return PTR_ERR(f_msg); | ||
148 | |||
149 | ret = fsg_common_run_thread(opts->common); | ||
150 | if (ret) | ||
151 | goto put_func; | ||
152 | |||
153 | ret = usb_add_function(c, f_msg); | ||
154 | if (ret) | ||
155 | goto put_func; | ||
134 | 156 | ||
135 | retp = fsg_common_init(&common, c->cdev, &config); | 157 | return 0; |
136 | if (IS_ERR(retp)) | ||
137 | return PTR_ERR(retp); | ||
138 | 158 | ||
139 | ret = fsg_bind_config(c->cdev, c, &common); | 159 | put_func: |
140 | fsg_common_put(&common); | 160 | usb_put_function(f_msg); |
141 | return ret; | 161 | return ret; |
142 | } | 162 | } |
143 | 163 | ||
@@ -152,23 +172,79 @@ static struct usb_configuration msg_config_driver = { | |||
152 | 172 | ||
153 | static int __init msg_bind(struct usb_composite_dev *cdev) | 173 | static int __init msg_bind(struct usb_composite_dev *cdev) |
154 | { | 174 | { |
175 | static const struct fsg_operations ops = { | ||
176 | .thread_exits = msg_thread_exits, | ||
177 | }; | ||
178 | struct fsg_opts *opts; | ||
179 | struct fsg_config config; | ||
155 | int status; | 180 | int status; |
156 | 181 | ||
182 | fi_msg = usb_get_function_instance("mass_storage"); | ||
183 | if (IS_ERR(fi_msg)) | ||
184 | return PTR_ERR(fi_msg); | ||
185 | |||
186 | fsg_config_from_params(&config, &mod_data, fsg_num_buffers); | ||
187 | opts = fsg_opts_from_func_inst(fi_msg); | ||
188 | |||
189 | opts->no_configfs = true; | ||
190 | status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers); | ||
191 | if (status) | ||
192 | goto fail; | ||
193 | |||
194 | status = fsg_common_set_nluns(opts->common, config.nluns); | ||
195 | if (status) | ||
196 | goto fail_set_nluns; | ||
197 | |||
198 | fsg_common_set_ops(opts->common, &ops); | ||
199 | |||
200 | status = fsg_common_set_cdev(opts->common, cdev, config.can_stall); | ||
201 | if (status) | ||
202 | goto fail_set_cdev; | ||
203 | |||
204 | fsg_common_set_sysfs(opts->common, true); | ||
205 | status = fsg_common_create_luns(opts->common, &config); | ||
206 | if (status) | ||
207 | goto fail_set_cdev; | ||
208 | |||
209 | fsg_common_set_inquiry_string(opts->common, config.vendor_name, | ||
210 | config.product_name); | ||
211 | |||
157 | status = usb_string_ids_tab(cdev, strings_dev); | 212 | status = usb_string_ids_tab(cdev, strings_dev); |
158 | if (status < 0) | 213 | if (status < 0) |
159 | return status; | 214 | goto fail_string_ids; |
160 | msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; | 215 | msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
161 | 216 | ||
162 | status = usb_add_config(cdev, &msg_config_driver, msg_do_config); | 217 | status = usb_add_config(cdev, &msg_config_driver, msg_do_config); |
163 | if (status < 0) | 218 | if (status < 0) |
164 | return status; | 219 | goto fail_string_ids; |
220 | |||
165 | usb_composite_overwrite_options(cdev, &coverwrite); | 221 | usb_composite_overwrite_options(cdev, &coverwrite); |
166 | dev_info(&cdev->gadget->dev, | 222 | dev_info(&cdev->gadget->dev, |
167 | DRIVER_DESC ", version: " DRIVER_VERSION "\n"); | 223 | DRIVER_DESC ", version: " DRIVER_VERSION "\n"); |
168 | set_bit(0, &msg_registered); | 224 | set_bit(0, &msg_registered); |
169 | return 0; | 225 | return 0; |
226 | |||
227 | fail_string_ids: | ||
228 | fsg_common_remove_luns(opts->common); | ||
229 | fail_set_cdev: | ||
230 | fsg_common_free_luns(opts->common); | ||
231 | fail_set_nluns: | ||
232 | fsg_common_free_buffers(opts->common); | ||
233 | fail: | ||
234 | usb_put_function_instance(fi_msg); | ||
235 | return status; | ||
170 | } | 236 | } |
171 | 237 | ||
238 | static int msg_unbind(struct usb_composite_dev *cdev) | ||
239 | { | ||
240 | if (!IS_ERR(f_msg)) | ||
241 | usb_put_function(f_msg); | ||
242 | |||
243 | if (!IS_ERR(fi_msg)) | ||
244 | usb_put_function_instance(fi_msg); | ||
245 | |||
246 | return 0; | ||
247 | } | ||
172 | 248 | ||
173 | /****************************** Some noise ******************************/ | 249 | /****************************** Some noise ******************************/ |
174 | 250 | ||
@@ -179,6 +255,7 @@ static __refdata struct usb_composite_driver msg_driver = { | |||
179 | .needs_serial = 1, | 255 | .needs_serial = 1, |
180 | .strings = dev_strings, | 256 | .strings = dev_strings, |
181 | .bind = msg_bind, | 257 | .bind = msg_bind, |
258 | .unbind = msg_unbind, | ||
182 | }; | 259 | }; |
183 | 260 | ||
184 | MODULE_DESCRIPTION(DRIVER_DESC); | 261 | MODULE_DESCRIPTION(DRIVER_DESC); |
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 23393254a8a3..4fdaa54a2a2a 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/netdevice.h> | ||
18 | 19 | ||
19 | #include "u_serial.h" | 20 | #include "u_serial.h" |
20 | #if defined USB_ETH_RNDIS | 21 | #if defined USB_ETH_RNDIS |
@@ -32,22 +33,11 @@ MODULE_AUTHOR("Michal Nazarewicz"); | |||
32 | MODULE_LICENSE("GPL"); | 33 | MODULE_LICENSE("GPL"); |
33 | 34 | ||
34 | 35 | ||
35 | /***************************** All the files... *****************************/ | 36 | #include "f_mass_storage.h" |
36 | 37 | ||
37 | /* | 38 | #include "u_ecm.h" |
38 | * kbuild is not very cooperative with respect to linking separately | ||
39 | * compiled library objects into one module. So for now we won't use | ||
40 | * separate compilation ... ensuring init/exit sections work to shrink | ||
41 | * the runtime footprint, and giving us at least some parts of what | ||
42 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
43 | */ | ||
44 | #include "f_mass_storage.c" | ||
45 | |||
46 | #define USBF_ECM_INCLUDED | ||
47 | #include "f_ecm.c" | ||
48 | #ifdef USB_ETH_RNDIS | 39 | #ifdef USB_ETH_RNDIS |
49 | # define USB_FRNDIS_INCLUDED | 40 | # include "u_rndis.h" |
50 | # include "f_rndis.c" | ||
51 | # include "rndis.h" | 41 | # include "rndis.h" |
52 | #endif | 42 | #endif |
53 | #include "u_ether.h" | 43 | #include "u_ether.h" |
@@ -132,22 +122,36 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
132 | /****************************** Configurations ******************************/ | 122 | /****************************** Configurations ******************************/ |
133 | 123 | ||
134 | static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; | 124 | static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; |
135 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | 125 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
126 | |||
127 | static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | ||
136 | 128 | ||
137 | static struct fsg_common fsg_common; | 129 | #else |
130 | |||
131 | /* | ||
132 | * Number of buffers we will use. | ||
133 | * 2 is usually enough for good buffering pipeline | ||
134 | */ | ||
135 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | ||
138 | 136 | ||
139 | static u8 host_mac[ETH_ALEN]; | 137 | #endif /* CONFIG_USB_DEBUG */ |
138 | |||
139 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | ||
140 | 140 | ||
141 | static struct usb_function_instance *fi_acm; | 141 | static struct usb_function_instance *fi_acm; |
142 | static struct eth_dev *the_dev; | 142 | static struct usb_function_instance *fi_msg; |
143 | 143 | ||
144 | /********** RNDIS **********/ | 144 | /********** RNDIS **********/ |
145 | 145 | ||
146 | #ifdef USB_ETH_RNDIS | 146 | #ifdef USB_ETH_RNDIS |
147 | static struct usb_function_instance *fi_rndis; | ||
147 | static struct usb_function *f_acm_rndis; | 148 | static struct usb_function *f_acm_rndis; |
149 | static struct usb_function *f_rndis; | ||
150 | static struct usb_function *f_msg_rndis; | ||
148 | 151 | ||
149 | static __init int rndis_do_config(struct usb_configuration *c) | 152 | static __init int rndis_do_config(struct usb_configuration *c) |
150 | { | 153 | { |
154 | struct fsg_opts *fsg_opts; | ||
151 | int ret; | 155 | int ret; |
152 | 156 | ||
153 | if (gadget_is_otg(c->cdev->gadget)) { | 157 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -155,27 +159,50 @@ static __init int rndis_do_config(struct usb_configuration *c) | |||
155 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 159 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
156 | } | 160 | } |
157 | 161 | ||
158 | ret = rndis_bind_config(c, host_mac, the_dev); | 162 | f_rndis = usb_get_function(fi_rndis); |
163 | if (IS_ERR(f_rndis)) | ||
164 | return PTR_ERR(f_rndis); | ||
165 | |||
166 | ret = usb_add_function(c, f_rndis); | ||
159 | if (ret < 0) | 167 | if (ret < 0) |
160 | return ret; | 168 | goto err_func_rndis; |
161 | 169 | ||
162 | f_acm_rndis = usb_get_function(fi_acm); | 170 | f_acm_rndis = usb_get_function(fi_acm); |
163 | if (IS_ERR(f_acm_rndis)) | 171 | if (IS_ERR(f_acm_rndis)) { |
164 | return PTR_ERR(f_acm_rndis); | 172 | ret = PTR_ERR(f_acm_rndis); |
173 | goto err_func_acm; | ||
174 | } | ||
165 | 175 | ||
166 | ret = usb_add_function(c, f_acm_rndis); | 176 | ret = usb_add_function(c, f_acm_rndis); |
167 | if (ret) | 177 | if (ret) |
168 | goto err_conf; | 178 | goto err_conf; |
169 | 179 | ||
170 | ret = fsg_bind_config(c->cdev, c, &fsg_common); | 180 | f_msg_rndis = usb_get_function(fi_msg); |
171 | if (ret < 0) | 181 | if (IS_ERR(f_msg_rndis)) { |
182 | ret = PTR_ERR(f_msg_rndis); | ||
172 | goto err_fsg; | 183 | goto err_fsg; |
184 | } | ||
185 | |||
186 | fsg_opts = fsg_opts_from_func_inst(fi_msg); | ||
187 | ret = fsg_common_run_thread(fsg_opts->common); | ||
188 | if (ret) | ||
189 | goto err_run; | ||
190 | |||
191 | ret = usb_add_function(c, f_msg_rndis); | ||
192 | if (ret) | ||
193 | goto err_run; | ||
173 | 194 | ||
174 | return 0; | 195 | return 0; |
196 | err_run: | ||
197 | usb_put_function(f_msg_rndis); | ||
175 | err_fsg: | 198 | err_fsg: |
176 | usb_remove_function(c, f_acm_rndis); | 199 | usb_remove_function(c, f_acm_rndis); |
177 | err_conf: | 200 | err_conf: |
178 | usb_put_function(f_acm_rndis); | 201 | usb_put_function(f_acm_rndis); |
202 | err_func_acm: | ||
203 | usb_remove_function(c, f_rndis); | ||
204 | err_func_rndis: | ||
205 | usb_put_function(f_rndis); | ||
179 | return ret; | 206 | return ret; |
180 | } | 207 | } |
181 | 208 | ||
@@ -205,10 +232,14 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev) | |||
205 | /********** CDC ECM **********/ | 232 | /********** CDC ECM **********/ |
206 | 233 | ||
207 | #ifdef CONFIG_USB_G_MULTI_CDC | 234 | #ifdef CONFIG_USB_G_MULTI_CDC |
235 | static struct usb_function_instance *fi_ecm; | ||
208 | static struct usb_function *f_acm_multi; | 236 | static struct usb_function *f_acm_multi; |
237 | static struct usb_function *f_ecm; | ||
238 | static struct usb_function *f_msg_multi; | ||
209 | 239 | ||
210 | static __init int cdc_do_config(struct usb_configuration *c) | 240 | static __init int cdc_do_config(struct usb_configuration *c) |
211 | { | 241 | { |
242 | struct fsg_opts *fsg_opts; | ||
212 | int ret; | 243 | int ret; |
213 | 244 | ||
214 | if (gadget_is_otg(c->cdev->gadget)) { | 245 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -216,28 +247,51 @@ static __init int cdc_do_config(struct usb_configuration *c) | |||
216 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 247 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
217 | } | 248 | } |
218 | 249 | ||
219 | ret = ecm_bind_config(c, host_mac, the_dev); | 250 | f_ecm = usb_get_function(fi_ecm); |
251 | if (IS_ERR(f_ecm)) | ||
252 | return PTR_ERR(f_ecm); | ||
253 | |||
254 | ret = usb_add_function(c, f_ecm); | ||
220 | if (ret < 0) | 255 | if (ret < 0) |
221 | return ret; | 256 | goto err_func_ecm; |
222 | 257 | ||
223 | /* implicit port_num is zero */ | 258 | /* implicit port_num is zero */ |
224 | f_acm_multi = usb_get_function(fi_acm); | 259 | f_acm_multi = usb_get_function(fi_acm); |
225 | if (IS_ERR(f_acm_multi)) | 260 | if (IS_ERR(f_acm_multi)) { |
226 | return PTR_ERR(f_acm_multi); | 261 | ret = PTR_ERR(f_acm_multi); |
262 | goto err_func_acm; | ||
263 | } | ||
227 | 264 | ||
228 | ret = usb_add_function(c, f_acm_multi); | 265 | ret = usb_add_function(c, f_acm_multi); |
229 | if (ret) | 266 | if (ret) |
230 | goto err_conf; | 267 | goto err_conf; |
231 | 268 | ||
232 | ret = fsg_bind_config(c->cdev, c, &fsg_common); | 269 | f_msg_multi = usb_get_function(fi_msg); |
233 | if (ret < 0) | 270 | if (IS_ERR(f_msg_multi)) { |
271 | ret = PTR_ERR(f_msg_multi); | ||
234 | goto err_fsg; | 272 | goto err_fsg; |
273 | } | ||
274 | |||
275 | fsg_opts = fsg_opts_from_func_inst(fi_msg); | ||
276 | ret = fsg_common_run_thread(fsg_opts->common); | ||
277 | if (ret) | ||
278 | goto err_run; | ||
279 | |||
280 | ret = usb_add_function(c, f_msg_multi); | ||
281 | if (ret) | ||
282 | goto err_run; | ||
235 | 283 | ||
236 | return 0; | 284 | return 0; |
285 | err_run: | ||
286 | usb_put_function(f_msg_multi); | ||
237 | err_fsg: | 287 | err_fsg: |
238 | usb_remove_function(c, f_acm_multi); | 288 | usb_remove_function(c, f_acm_multi); |
239 | err_conf: | 289 | err_conf: |
240 | usb_put_function(f_acm_multi); | 290 | usb_put_function(f_acm_multi); |
291 | err_func_acm: | ||
292 | usb_remove_function(c, f_ecm); | ||
293 | err_func_ecm: | ||
294 | usb_put_function(f_ecm); | ||
241 | return ret; | 295 | return ret; |
242 | } | 296 | } |
243 | 297 | ||
@@ -270,19 +324,67 @@ static __ref int cdc_config_register(struct usb_composite_dev *cdev) | |||
270 | static int __ref multi_bind(struct usb_composite_dev *cdev) | 324 | static int __ref multi_bind(struct usb_composite_dev *cdev) |
271 | { | 325 | { |
272 | struct usb_gadget *gadget = cdev->gadget; | 326 | struct usb_gadget *gadget = cdev->gadget; |
327 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
328 | struct f_ecm_opts *ecm_opts; | ||
329 | #endif | ||
330 | #ifdef USB_ETH_RNDIS | ||
331 | struct f_rndis_opts *rndis_opts; | ||
332 | #endif | ||
333 | struct fsg_opts *fsg_opts; | ||
334 | struct fsg_config config; | ||
273 | int status; | 335 | int status; |
274 | 336 | ||
275 | if (!can_support_ecm(cdev->gadget)) { | 337 | if (!can_support_ecm(cdev->gadget)) { |
276 | dev_err(&gadget->dev, "controller '%s' not usable\n", | 338 | dev_err(&gadget->dev, "controller '%s' not usable\n", |
277 | gadget->name); | 339 | gadget->name); |
278 | return -EINVAL; | 340 | return -EINVAL; |
279 | } | 341 | } |
280 | 342 | ||
281 | /* set up network link layer */ | 343 | #ifdef CONFIG_USB_G_MULTI_CDC |
282 | the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, | 344 | fi_ecm = usb_get_function_instance("ecm"); |
283 | qmult); | 345 | if (IS_ERR(fi_ecm)) |
284 | if (IS_ERR(the_dev)) | 346 | return PTR_ERR(fi_ecm); |
285 | return PTR_ERR(the_dev); | 347 | |
348 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); | ||
349 | |||
350 | gether_set_qmult(ecm_opts->net, qmult); | ||
351 | if (!gether_set_host_addr(ecm_opts->net, host_addr)) | ||
352 | pr_info("using host ethernet address: %s", host_addr); | ||
353 | if (!gether_set_dev_addr(ecm_opts->net, dev_addr)) | ||
354 | pr_info("using self ethernet address: %s", dev_addr); | ||
355 | #endif | ||
356 | |||
357 | #ifdef USB_ETH_RNDIS | ||
358 | fi_rndis = usb_get_function_instance("rndis"); | ||
359 | if (IS_ERR(fi_rndis)) { | ||
360 | status = PTR_ERR(fi_rndis); | ||
361 | goto fail; | ||
362 | } | ||
363 | |||
364 | rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst); | ||
365 | |||
366 | gether_set_qmult(rndis_opts->net, qmult); | ||
367 | if (!gether_set_host_addr(rndis_opts->net, host_addr)) | ||
368 | pr_info("using host ethernet address: %s", host_addr); | ||
369 | if (!gether_set_dev_addr(rndis_opts->net, dev_addr)) | ||
370 | pr_info("using self ethernet address: %s", dev_addr); | ||
371 | #endif | ||
372 | |||
373 | #if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS) | ||
374 | /* | ||
375 | * If both ecm and rndis are selected then: | ||
376 | * 1) rndis borrows the net interface from ecm | ||
377 | * 2) since the interface is shared it must not be bound | ||
378 | * twice - in ecm's _and_ rndis' binds, so do it here. | ||
379 | */ | ||
380 | gether_set_gadget(ecm_opts->net, cdev->gadget); | ||
381 | status = gether_register_netdev(ecm_opts->net); | ||
382 | if (status) | ||
383 | goto fail0; | ||
384 | |||
385 | rndis_borrow_net(fi_rndis, ecm_opts->net); | ||
386 | ecm_opts->bound = true; | ||
387 | #endif | ||
286 | 388 | ||
287 | /* set up serial link layer */ | 389 | /* set up serial link layer */ |
288 | fi_acm = usb_get_function_instance("acm"); | 390 | fi_acm = usb_get_function_instance("acm"); |
@@ -292,57 +394,102 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) | |||
292 | } | 394 | } |
293 | 395 | ||
294 | /* set up mass storage function */ | 396 | /* set up mass storage function */ |
295 | { | 397 | fi_msg = usb_get_function_instance("mass_storage"); |
296 | void *retp; | 398 | if (IS_ERR(fi_msg)) { |
297 | retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); | 399 | status = PTR_ERR(fi_msg); |
298 | if (IS_ERR(retp)) { | 400 | goto fail1; |
299 | status = PTR_ERR(retp); | ||
300 | goto fail1; | ||
301 | } | ||
302 | } | 401 | } |
402 | fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers); | ||
403 | fsg_opts = fsg_opts_from_func_inst(fi_msg); | ||
404 | |||
405 | fsg_opts->no_configfs = true; | ||
406 | status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers); | ||
407 | if (status) | ||
408 | goto fail2; | ||
409 | |||
410 | status = fsg_common_set_nluns(fsg_opts->common, config.nluns); | ||
411 | if (status) | ||
412 | goto fail_set_nluns; | ||
413 | |||
414 | status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall); | ||
415 | if (status) | ||
416 | goto fail_set_cdev; | ||
417 | |||
418 | fsg_common_set_sysfs(fsg_opts->common, true); | ||
419 | status = fsg_common_create_luns(fsg_opts->common, &config); | ||
420 | if (status) | ||
421 | goto fail_set_cdev; | ||
422 | |||
423 | fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name, | ||
424 | config.product_name); | ||
303 | 425 | ||
304 | /* allocate string IDs */ | 426 | /* allocate string IDs */ |
305 | status = usb_string_ids_tab(cdev, strings_dev); | 427 | status = usb_string_ids_tab(cdev, strings_dev); |
306 | if (unlikely(status < 0)) | 428 | if (unlikely(status < 0)) |
307 | goto fail2; | 429 | goto fail_string_ids; |
308 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; | 430 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
309 | 431 | ||
310 | /* register configurations */ | 432 | /* register configurations */ |
311 | status = rndis_config_register(cdev); | 433 | status = rndis_config_register(cdev); |
312 | if (unlikely(status < 0)) | 434 | if (unlikely(status < 0)) |
313 | goto fail2; | 435 | goto fail_string_ids; |
314 | 436 | ||
315 | status = cdc_config_register(cdev); | 437 | status = cdc_config_register(cdev); |
316 | if (unlikely(status < 0)) | 438 | if (unlikely(status < 0)) |
317 | goto fail2; | 439 | goto fail_string_ids; |
318 | usb_composite_overwrite_options(cdev, &coverwrite); | 440 | usb_composite_overwrite_options(cdev, &coverwrite); |
319 | 441 | ||
320 | /* we're done */ | 442 | /* we're done */ |
321 | dev_info(&gadget->dev, DRIVER_DESC "\n"); | 443 | dev_info(&gadget->dev, DRIVER_DESC "\n"); |
322 | fsg_common_put(&fsg_common); | ||
323 | return 0; | 444 | return 0; |
324 | 445 | ||
325 | 446 | ||
326 | /* error recovery */ | 447 | /* error recovery */ |
448 | fail_string_ids: | ||
449 | fsg_common_remove_luns(fsg_opts->common); | ||
450 | fail_set_cdev: | ||
451 | fsg_common_free_luns(fsg_opts->common); | ||
452 | fail_set_nluns: | ||
453 | fsg_common_free_buffers(fsg_opts->common); | ||
327 | fail2: | 454 | fail2: |
328 | fsg_common_put(&fsg_common); | 455 | usb_put_function_instance(fi_msg); |
329 | fail1: | 456 | fail1: |
330 | usb_put_function_instance(fi_acm); | 457 | usb_put_function_instance(fi_acm); |
331 | fail0: | 458 | fail0: |
332 | gether_cleanup(the_dev); | 459 | #ifdef USB_ETH_RNDIS |
460 | usb_put_function_instance(fi_rndis); | ||
461 | fail: | ||
462 | #endif | ||
463 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
464 | usb_put_function_instance(fi_ecm); | ||
465 | #endif | ||
333 | return status; | 466 | return status; |
334 | } | 467 | } |
335 | 468 | ||
336 | static int __exit multi_unbind(struct usb_composite_dev *cdev) | 469 | static int __exit multi_unbind(struct usb_composite_dev *cdev) |
337 | { | 470 | { |
338 | #ifdef CONFIG_USB_G_MULTI_CDC | 471 | #ifdef CONFIG_USB_G_MULTI_CDC |
472 | usb_put_function(f_msg_multi); | ||
473 | #endif | ||
474 | #ifdef USB_ETH_RNDIS | ||
475 | usb_put_function(f_msg_rndis); | ||
476 | #endif | ||
477 | usb_put_function_instance(fi_msg); | ||
478 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
339 | usb_put_function(f_acm_multi); | 479 | usb_put_function(f_acm_multi); |
340 | #endif | 480 | #endif |
341 | #ifdef USB_ETH_RNDIS | 481 | #ifdef USB_ETH_RNDIS |
342 | usb_put_function(f_acm_rndis); | 482 | usb_put_function(f_acm_rndis); |
343 | #endif | 483 | #endif |
344 | usb_put_function_instance(fi_acm); | 484 | usb_put_function_instance(fi_acm); |
345 | gether_cleanup(the_dev); | 485 | #ifdef USB_ETH_RNDIS |
486 | usb_put_function(f_rndis); | ||
487 | usb_put_function_instance(fi_rndis); | ||
488 | #endif | ||
489 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
490 | usb_put_function(f_ecm); | ||
491 | usb_put_function_instance(fi_ecm); | ||
492 | #endif | ||
346 | return 0; | 493 | return 0; |
347 | } | 494 | } |
348 | 495 | ||
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c index 561b30efb8ee..234711eabea1 100644 --- a/drivers/usb/gadget/mv_u3d_core.c +++ b/drivers/usb/gadget/mv_u3d_core.c | |||
@@ -310,6 +310,7 @@ static struct mv_u3d_trb *mv_u3d_build_trb_one(struct mv_u3d_req *req, | |||
310 | */ | 310 | */ |
311 | trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma); | 311 | trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma); |
312 | if (!trb_hw) { | 312 | if (!trb_hw) { |
313 | kfree(trb); | ||
313 | dev_err(u3d->dev, | 314 | dev_err(u3d->dev, |
314 | "%s, dma_pool_alloc fail\n", __func__); | 315 | "%s, dma_pool_alloc fail\n", __func__); |
315 | return NULL; | 316 | return NULL; |
@@ -454,6 +455,7 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req) | |||
454 | 455 | ||
455 | trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); | 456 | trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); |
456 | if (!trb_hw) { | 457 | if (!trb_hw) { |
458 | kfree(trb); | ||
457 | dev_err(u3d->dev, | 459 | dev_err(u3d->dev, |
458 | "%s, trb_hw alloc fail\n", __func__); | 460 | "%s, trb_hw alloc fail\n", __func__); |
459 | return -ENOMEM; | 461 | return -ENOMEM; |
@@ -1936,7 +1938,7 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1936 | } | 1938 | } |
1937 | u3d->irq = r->start; | 1939 | u3d->irq = r->start; |
1938 | if (request_irq(u3d->irq, mv_u3d_irq, | 1940 | if (request_irq(u3d->irq, mv_u3d_irq, |
1939 | IRQF_DISABLED | IRQF_SHARED, driver_name, u3d)) { | 1941 | IRQF_SHARED, driver_name, u3d)) { |
1940 | u3d->irq = 0; | 1942 | u3d->irq = 0; |
1941 | dev_err(&dev->dev, "Request irq %d for u3d failed\n", | 1943 | dev_err(&dev->dev, "Request irq %d for u3d failed\n", |
1942 | u3d->irq); | 1944 | u3d->irq); |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index 0781bff70015..fc852177c087 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -129,7 +129,7 @@ static char *type_string (u8 bmAttributes) | |||
129 | case USB_ENDPOINT_XFER_BULK: return "bulk"; | 129 | case USB_ENDPOINT_XFER_BULK: return "bulk"; |
130 | case USB_ENDPOINT_XFER_ISOC: return "iso"; | 130 | case USB_ENDPOINT_XFER_ISOC: return "iso"; |
131 | case USB_ENDPOINT_XFER_INT: return "intr"; | 131 | case USB_ENDPOINT_XFER_INT: return "intr"; |
132 | }; | 132 | } |
133 | return "control"; | 133 | return "control"; |
134 | } | 134 | } |
135 | #endif | 135 | #endif |
@@ -1630,7 +1630,7 @@ static ssize_t queues_show(struct device *_dev, struct device_attribute *attr, | |||
1630 | val = "intr"; break; | 1630 | val = "intr"; break; |
1631 | default: | 1631 | default: |
1632 | val = "iso"; break; | 1632 | val = "iso"; break; |
1633 | }; val; }), | 1633 | } val; }), |
1634 | usb_endpoint_maxp (d) & 0x1fff, | 1634 | usb_endpoint_maxp (d) & 0x1fff, |
1635 | ep->dma ? "dma" : "pio", ep->fifo_size | 1635 | ep->dma ? "dma" : "pio", ep->fifo_size |
1636 | ); | 1636 | ); |
@@ -2680,7 +2680,6 @@ static void net2280_remove (struct pci_dev *pdev) | |||
2680 | if (dev->enabled) | 2680 | if (dev->enabled) |
2681 | pci_disable_device (pdev); | 2681 | pci_disable_device (pdev); |
2682 | device_remove_file (&pdev->dev, &dev_attr_registers); | 2682 | device_remove_file (&pdev->dev, &dev_attr_registers); |
2683 | pci_set_drvdata (pdev, NULL); | ||
2684 | 2683 | ||
2685 | INFO (dev, "unbind\n"); | 2684 | INFO (dev, "unbind\n"); |
2686 | } | 2685 | } |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index 24174e1d1564..32d5e923750b 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -3080,7 +3080,6 @@ static void pch_udc_remove(struct pci_dev *pdev) | |||
3080 | if (dev->active) | 3080 | if (dev->active) |
3081 | pci_disable_device(pdev); | 3081 | pci_disable_device(pdev); |
3082 | kfree(dev); | 3082 | kfree(dev); |
3083 | pci_set_drvdata(pdev, NULL); | ||
3084 | } | 3083 | } |
3085 | 3084 | ||
3086 | #ifdef CONFIG_PM | 3085 | #ifdef CONFIG_PM |
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 9575085ded81..a3ad732bc812 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -1068,7 +1068,7 @@ static int rndis_proc_show(struct seq_file *m, void *v) | |||
1068 | s = "RNDIS_INITIALIZED"; break; | 1068 | s = "RNDIS_INITIALIZED"; break; |
1069 | case RNDIS_DATA_INITIALIZED: | 1069 | case RNDIS_DATA_INITIALIZED: |
1070 | s = "RNDIS_DATA_INITIALIZED"; break; | 1070 | s = "RNDIS_DATA_INITIALIZED"; break; |
1071 | }; s; }), | 1071 | } s; }), |
1072 | param->medium, | 1072 | param->medium, |
1073 | (param->media_state) ? 0 : param->speed*100, | 1073 | (param->media_state) ? 0 : param->speed*100, |
1074 | (param->media_state) ? "disconnected" : "connected", | 1074 | (param->media_state) ? "disconnected" : "connected", |
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index a8a99e4748d5..9875d9c0823f 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -83,9 +83,12 @@ struct s3c_hsotg_req; | |||
83 | * @dir_in: Set to true if this endpoint is of the IN direction, which | 83 | * @dir_in: Set to true if this endpoint is of the IN direction, which |
84 | * means that it is sending data to the Host. | 84 | * means that it is sending data to the Host. |
85 | * @index: The index for the endpoint registers. | 85 | * @index: The index for the endpoint registers. |
86 | * @mc: Multi Count - number of transactions per microframe | ||
87 | * @interval - Interval for periodic endpoints | ||
86 | * @name: The name array passed to the USB core. | 88 | * @name: The name array passed to the USB core. |
87 | * @halted: Set if the endpoint has been halted. | 89 | * @halted: Set if the endpoint has been halted. |
88 | * @periodic: Set if this is a periodic ep, such as Interrupt | 90 | * @periodic: Set if this is a periodic ep, such as Interrupt |
91 | * @isochronous: Set if this is a isochronous ep | ||
89 | * @sent_zlp: Set if we've sent a zero-length packet. | 92 | * @sent_zlp: Set if we've sent a zero-length packet. |
90 | * @total_data: The total number of data bytes done. | 93 | * @total_data: The total number of data bytes done. |
91 | * @fifo_size: The size of the FIFO (for periodic IN endpoints) | 94 | * @fifo_size: The size of the FIFO (for periodic IN endpoints) |
@@ -121,9 +124,12 @@ struct s3c_hsotg_ep { | |||
121 | 124 | ||
122 | unsigned char dir_in; | 125 | unsigned char dir_in; |
123 | unsigned char index; | 126 | unsigned char index; |
127 | unsigned char mc; | ||
128 | unsigned char interval; | ||
124 | 129 | ||
125 | unsigned int halted:1; | 130 | unsigned int halted:1; |
126 | unsigned int periodic:1; | 131 | unsigned int periodic:1; |
132 | unsigned int isochronous:1; | ||
127 | unsigned int sent_zlp:1; | 133 | unsigned int sent_zlp:1; |
128 | 134 | ||
129 | char name[10]; | 135 | char name[10]; |
@@ -468,6 +474,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
468 | void *data; | 474 | void *data; |
469 | int can_write; | 475 | int can_write; |
470 | int pkt_round; | 476 | int pkt_round; |
477 | int max_transfer; | ||
471 | 478 | ||
472 | to_write -= (buf_pos - hs_ep->last_load); | 479 | to_write -= (buf_pos - hs_ep->last_load); |
473 | 480 | ||
@@ -535,8 +542,10 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
535 | can_write *= 4; /* fifo size is in 32bit quantities. */ | 542 | can_write *= 4; /* fifo size is in 32bit quantities. */ |
536 | } | 543 | } |
537 | 544 | ||
538 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", | 545 | max_transfer = hs_ep->ep.maxpacket * hs_ep->mc; |
539 | __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); | 546 | |
547 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", | ||
548 | __func__, gnptxsts, can_write, to_write, max_transfer); | ||
540 | 549 | ||
541 | /* | 550 | /* |
542 | * limit to 512 bytes of data, it seems at least on the non-periodic | 551 | * limit to 512 bytes of data, it seems at least on the non-periodic |
@@ -551,19 +560,21 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
551 | * the transfer to return that it did not run out of fifo space | 560 | * the transfer to return that it did not run out of fifo space |
552 | * doing it. | 561 | * doing it. |
553 | */ | 562 | */ |
554 | if (to_write > hs_ep->ep.maxpacket) { | 563 | if (to_write > max_transfer) { |
555 | to_write = hs_ep->ep.maxpacket; | 564 | to_write = max_transfer; |
556 | 565 | ||
557 | s3c_hsotg_en_gsint(hsotg, | 566 | /* it's needed only when we do not use dedicated fifos */ |
558 | periodic ? GINTSTS_PTxFEmp : | 567 | if (!hsotg->dedicated_fifos) |
559 | GINTSTS_NPTxFEmp); | 568 | s3c_hsotg_en_gsint(hsotg, |
569 | periodic ? GINTSTS_PTxFEmp : | ||
570 | GINTSTS_NPTxFEmp); | ||
560 | } | 571 | } |
561 | 572 | ||
562 | /* see if we can write data */ | 573 | /* see if we can write data */ |
563 | 574 | ||
564 | if (to_write > can_write) { | 575 | if (to_write > can_write) { |
565 | to_write = can_write; | 576 | to_write = can_write; |
566 | pkt_round = to_write % hs_ep->ep.maxpacket; | 577 | pkt_round = to_write % max_transfer; |
567 | 578 | ||
568 | /* | 579 | /* |
569 | * Round the write down to an | 580 | * Round the write down to an |
@@ -581,9 +592,11 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
581 | * is more room left. | 592 | * is more room left. |
582 | */ | 593 | */ |
583 | 594 | ||
584 | s3c_hsotg_en_gsint(hsotg, | 595 | /* it's needed only when we do not use dedicated fifos */ |
585 | periodic ? GINTSTS_PTxFEmp : | 596 | if (!hsotg->dedicated_fifos) |
586 | GINTSTS_NPTxFEmp); | 597 | s3c_hsotg_en_gsint(hsotg, |
598 | periodic ? GINTSTS_PTxFEmp : | ||
599 | GINTSTS_NPTxFEmp); | ||
587 | } | 600 | } |
588 | 601 | ||
589 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", | 602 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", |
@@ -727,8 +740,16 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
727 | else | 740 | else |
728 | packets = 1; /* send one packet if length is zero. */ | 741 | packets = 1; /* send one packet if length is zero. */ |
729 | 742 | ||
743 | if (hs_ep->isochronous && length > (hs_ep->mc * hs_ep->ep.maxpacket)) { | ||
744 | dev_err(hsotg->dev, "req length > maxpacket*mc\n"); | ||
745 | return; | ||
746 | } | ||
747 | |||
730 | if (dir_in && index != 0) | 748 | if (dir_in && index != 0) |
731 | epsize = DxEPTSIZ_MC(1); | 749 | if (hs_ep->isochronous) |
750 | epsize = DxEPTSIZ_MC(packets); | ||
751 | else | ||
752 | epsize = DxEPTSIZ_MC(1); | ||
732 | else | 753 | else |
733 | epsize = 0; | 754 | epsize = 0; |
734 | 755 | ||
@@ -820,6 +841,9 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
820 | 841 | ||
821 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", | 842 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", |
822 | __func__, readl(hsotg->regs + epctrl_reg)); | 843 | __func__, readl(hsotg->regs + epctrl_reg)); |
844 | |||
845 | /* enable ep interrupts */ | ||
846 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); | ||
823 | } | 847 | } |
824 | 848 | ||
825 | /** | 849 | /** |
@@ -1091,6 +1115,7 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | |||
1091 | bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); | 1115 | bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); |
1092 | struct s3c_hsotg_ep *ep; | 1116 | struct s3c_hsotg_ep *ep; |
1093 | int ret; | 1117 | int ret; |
1118 | bool halted; | ||
1094 | 1119 | ||
1095 | dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", | 1120 | dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", |
1096 | __func__, set ? "SET" : "CLEAR"); | 1121 | __func__, set ? "SET" : "CLEAR"); |
@@ -1105,6 +1130,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | |||
1105 | 1130 | ||
1106 | switch (le16_to_cpu(ctrl->wValue)) { | 1131 | switch (le16_to_cpu(ctrl->wValue)) { |
1107 | case USB_ENDPOINT_HALT: | 1132 | case USB_ENDPOINT_HALT: |
1133 | halted = ep->halted; | ||
1134 | |||
1108 | s3c_hsotg_ep_sethalt(&ep->ep, set); | 1135 | s3c_hsotg_ep_sethalt(&ep->ep, set); |
1109 | 1136 | ||
1110 | ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); | 1137 | ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); |
@@ -1114,7 +1141,12 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | |||
1114 | return ret; | 1141 | return ret; |
1115 | } | 1142 | } |
1116 | 1143 | ||
1117 | if (!set) { | 1144 | /* |
1145 | * we have to complete all requests for ep if it was | ||
1146 | * halted, and the halt was cleared by CLEAR_FEATURE | ||
1147 | */ | ||
1148 | |||
1149 | if (!set && halted) { | ||
1118 | /* | 1150 | /* |
1119 | * If we have request in progress, | 1151 | * If we have request in progress, |
1120 | * then complete it | 1152 | * then complete it |
@@ -1147,6 +1179,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | |||
1147 | return 1; | 1179 | return 1; |
1148 | } | 1180 | } |
1149 | 1181 | ||
1182 | static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); | ||
1183 | |||
1150 | /** | 1184 | /** |
1151 | * s3c_hsotg_process_control - process a control request | 1185 | * s3c_hsotg_process_control - process a control request |
1152 | * @hsotg: The device state | 1186 | * @hsotg: The device state |
@@ -1246,11 +1280,15 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1246 | * don't believe we need to anything more to get the EP | 1280 | * don't believe we need to anything more to get the EP |
1247 | * to reply with a STALL packet | 1281 | * to reply with a STALL packet |
1248 | */ | 1282 | */ |
1283 | |||
1284 | /* | ||
1285 | * complete won't be called, so we enqueue | ||
1286 | * setup request here | ||
1287 | */ | ||
1288 | s3c_hsotg_enqueue_setup(hsotg); | ||
1249 | } | 1289 | } |
1250 | } | 1290 | } |
1251 | 1291 | ||
1252 | static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); | ||
1253 | |||
1254 | /** | 1292 | /** |
1255 | * s3c_hsotg_complete_setup - completion of a setup transfer | 1293 | * s3c_hsotg_complete_setup - completion of a setup transfer |
1256 | * @ep: The endpoint the request was on. | 1294 | * @ep: The endpoint the request was on. |
@@ -1698,6 +1736,7 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1698 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; | 1736 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; |
1699 | void __iomem *regs = hsotg->regs; | 1737 | void __iomem *regs = hsotg->regs; |
1700 | u32 mpsval; | 1738 | u32 mpsval; |
1739 | u32 mcval; | ||
1701 | u32 reg; | 1740 | u32 reg; |
1702 | 1741 | ||
1703 | if (ep == 0) { | 1742 | if (ep == 0) { |
@@ -1705,15 +1744,19 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1705 | mpsval = s3c_hsotg_ep0_mps(mps); | 1744 | mpsval = s3c_hsotg_ep0_mps(mps); |
1706 | if (mpsval > 3) | 1745 | if (mpsval > 3) |
1707 | goto bad_mps; | 1746 | goto bad_mps; |
1747 | hs_ep->ep.maxpacket = mps; | ||
1748 | hs_ep->mc = 1; | ||
1708 | } else { | 1749 | } else { |
1709 | if (mps >= DxEPCTL_MPS_LIMIT+1) | 1750 | mpsval = mps & DxEPCTL_MPS_MASK; |
1751 | if (mpsval > 1024) | ||
1710 | goto bad_mps; | 1752 | goto bad_mps; |
1711 | 1753 | mcval = ((mps >> 11) & 0x3) + 1; | |
1712 | mpsval = mps; | 1754 | hs_ep->mc = mcval; |
1755 | if (mcval > 3) | ||
1756 | goto bad_mps; | ||
1757 | hs_ep->ep.maxpacket = mpsval; | ||
1713 | } | 1758 | } |
1714 | 1759 | ||
1715 | hs_ep->ep.maxpacket = mps; | ||
1716 | |||
1717 | /* | 1760 | /* |
1718 | * update both the in and out endpoint controldir_ registers, even | 1761 | * update both the in and out endpoint controldir_ registers, even |
1719 | * if one of the directions may not be in use. | 1762 | * if one of the directions may not be in use. |
@@ -1782,8 +1825,16 @@ static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg, | |||
1782 | { | 1825 | { |
1783 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1826 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
1784 | 1827 | ||
1785 | if (!hs_ep->dir_in || !hs_req) | 1828 | if (!hs_ep->dir_in || !hs_req) { |
1829 | /** | ||
1830 | * if request is not enqueued, we disable interrupts | ||
1831 | * for endpoints, excepting ep0 | ||
1832 | */ | ||
1833 | if (hs_ep->index != 0) | ||
1834 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, | ||
1835 | hs_ep->dir_in, 0); | ||
1786 | return 0; | 1836 | return 0; |
1837 | } | ||
1787 | 1838 | ||
1788 | if (hs_req->req.actual < hs_req->req.length) { | 1839 | if (hs_req->req.actual < hs_req->req.length) { |
1789 | dev_dbg(hsotg->dev, "trying to write more for ep%d\n", | 1840 | dev_dbg(hsotg->dev, "trying to write more for ep%d\n", |
@@ -1887,8 +1938,10 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1887 | u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); | 1938 | u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); |
1888 | u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); | 1939 | u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); |
1889 | u32 ints; | 1940 | u32 ints; |
1941 | u32 ctrl; | ||
1890 | 1942 | ||
1891 | ints = readl(hsotg->regs + epint_reg); | 1943 | ints = readl(hsotg->regs + epint_reg); |
1944 | ctrl = readl(hsotg->regs + epctl_reg); | ||
1892 | 1945 | ||
1893 | /* Clear endpoint interrupts */ | 1946 | /* Clear endpoint interrupts */ |
1894 | writel(ints, hsotg->regs + epint_reg); | 1947 | writel(ints, hsotg->regs + epint_reg); |
@@ -1897,6 +1950,14 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1897 | __func__, idx, dir_in ? "in" : "out", ints); | 1950 | __func__, idx, dir_in ? "in" : "out", ints); |
1898 | 1951 | ||
1899 | if (ints & DxEPINT_XferCompl) { | 1952 | if (ints & DxEPINT_XferCompl) { |
1953 | if (hs_ep->isochronous && hs_ep->interval == 1) { | ||
1954 | if (ctrl & DxEPCTL_EOFrNum) | ||
1955 | ctrl |= DxEPCTL_SetEvenFr; | ||
1956 | else | ||
1957 | ctrl |= DxEPCTL_SetOddFr; | ||
1958 | writel(ctrl, hsotg->regs + epctl_reg); | ||
1959 | } | ||
1960 | |||
1900 | dev_dbg(hsotg->dev, | 1961 | dev_dbg(hsotg->dev, |
1901 | "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", | 1962 | "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", |
1902 | __func__, readl(hsotg->regs + epctl_reg), | 1963 | __func__, readl(hsotg->regs + epctl_reg), |
@@ -1963,7 +2024,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1963 | if (ints & DxEPINT_Back2BackSetup) | 2024 | if (ints & DxEPINT_Back2BackSetup) |
1964 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); | 2025 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); |
1965 | 2026 | ||
1966 | if (dir_in) { | 2027 | if (dir_in && !hs_ep->isochronous) { |
1967 | /* not sure if this is important, but we'll clear it anyway */ | 2028 | /* not sure if this is important, but we'll clear it anyway */ |
1968 | if (ints & DIEPMSK_INTknTXFEmpMsk) { | 2029 | if (ints & DIEPMSK_INTknTXFEmpMsk) { |
1969 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", | 2030 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", |
@@ -2092,12 +2153,14 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2092 | } | 2153 | } |
2093 | 2154 | ||
2094 | #define call_gadget(_hs, _entry) \ | 2155 | #define call_gadget(_hs, _entry) \ |
2156 | do { \ | ||
2095 | if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ | 2157 | if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ |
2096 | (_hs)->driver && (_hs)->driver->_entry) { \ | 2158 | (_hs)->driver && (_hs)->driver->_entry) { \ |
2097 | spin_unlock(&_hs->lock); \ | 2159 | spin_unlock(&_hs->lock); \ |
2098 | (_hs)->driver->_entry(&(_hs)->gadget); \ | 2160 | (_hs)->driver->_entry(&(_hs)->gadget); \ |
2099 | spin_lock(&_hs->lock); \ | 2161 | spin_lock(&_hs->lock); \ |
2100 | } | 2162 | } \ |
2163 | } while (0) | ||
2101 | 2164 | ||
2102 | /** | 2165 | /** |
2103 | * s3c_hsotg_disconnect - disconnect service | 2166 | * s3c_hsotg_disconnect - disconnect service |
@@ -2241,15 +2304,19 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2241 | GAHBCFG_HBstLen_Incr4, | 2304 | GAHBCFG_HBstLen_Incr4, |
2242 | hsotg->regs + GAHBCFG); | 2305 | hsotg->regs + GAHBCFG); |
2243 | else | 2306 | else |
2244 | writel(GAHBCFG_GlblIntrEn, hsotg->regs + GAHBCFG); | 2307 | writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NPTxFEmpLvl | |
2308 | GAHBCFG_PTxFEmpLvl) : 0) | | ||
2309 | GAHBCFG_GlblIntrEn, | ||
2310 | hsotg->regs + GAHBCFG); | ||
2245 | 2311 | ||
2246 | /* | 2312 | /* |
2247 | * Enabling INTknTXFEmpMsk here seems to be a big mistake, we end | 2313 | * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts |
2248 | * up being flooded with interrupts if the host is polling the | 2314 | * when we have no data to transfer. Otherwise we get being flooded by |
2249 | * endpoint to try and read data. | 2315 | * interrupts. |
2250 | */ | 2316 | */ |
2251 | 2317 | ||
2252 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty : 0) | | 2318 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty | |
2319 | DIEPMSK_INTknTXFEmpMsk : 0) | | ||
2253 | DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | | 2320 | DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | |
2254 | DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | | 2321 | DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | |
2255 | DIEPMSK_INTknEPMisMsk, | 2322 | DIEPMSK_INTknEPMisMsk, |
@@ -2378,10 +2445,14 @@ irq_retry: | |||
2378 | 2445 | ||
2379 | if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { | 2446 | if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { |
2380 | u32 daint = readl(hsotg->regs + DAINT); | 2447 | u32 daint = readl(hsotg->regs + DAINT); |
2381 | u32 daint_out = daint >> DAINT_OutEP_SHIFT; | 2448 | u32 daintmsk = readl(hsotg->regs + DAINTMSK); |
2382 | u32 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); | 2449 | u32 daint_out, daint_in; |
2383 | int ep; | 2450 | int ep; |
2384 | 2451 | ||
2452 | daint &= daintmsk; | ||
2453 | daint_out = daint >> DAINT_OutEP_SHIFT; | ||
2454 | daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); | ||
2455 | |||
2385 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); | 2456 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); |
2386 | 2457 | ||
2387 | for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { | 2458 | for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { |
@@ -2577,16 +2648,25 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2577 | epctrl |= DxEPCTL_SNAK; | 2648 | epctrl |= DxEPCTL_SNAK; |
2578 | 2649 | ||
2579 | /* update the endpoint state */ | 2650 | /* update the endpoint state */ |
2580 | hs_ep->ep.maxpacket = mps; | 2651 | s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); |
2581 | 2652 | ||
2582 | /* default, set to non-periodic */ | 2653 | /* default, set to non-periodic */ |
2654 | hs_ep->isochronous = 0; | ||
2583 | hs_ep->periodic = 0; | 2655 | hs_ep->periodic = 0; |
2656 | hs_ep->halted = 0; | ||
2657 | hs_ep->interval = desc->bInterval; | ||
2658 | |||
2659 | if (hs_ep->interval > 1 && hs_ep->mc > 1) | ||
2660 | dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); | ||
2584 | 2661 | ||
2585 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | 2662 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
2586 | case USB_ENDPOINT_XFER_ISOC: | 2663 | case USB_ENDPOINT_XFER_ISOC: |
2587 | dev_err(hsotg->dev, "no current ISOC support\n"); | 2664 | epctrl |= DxEPCTL_EPType_Iso; |
2588 | ret = -EINVAL; | 2665 | epctrl |= DxEPCTL_SetEvenFr; |
2589 | goto out; | 2666 | hs_ep->isochronous = 1; |
2667 | if (dir_in) | ||
2668 | hs_ep->periodic = 1; | ||
2669 | break; | ||
2590 | 2670 | ||
2591 | case USB_ENDPOINT_XFER_BULK: | 2671 | case USB_ENDPOINT_XFER_BULK: |
2592 | epctrl |= DxEPCTL_EPType_Bulk; | 2672 | epctrl |= DxEPCTL_EPType_Bulk; |
@@ -2634,7 +2714,6 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2634 | /* enable the endpoint interrupt */ | 2714 | /* enable the endpoint interrupt */ |
2635 | s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); | 2715 | s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); |
2636 | 2716 | ||
2637 | out: | ||
2638 | spin_unlock_irqrestore(&hsotg->lock, flags); | 2717 | spin_unlock_irqrestore(&hsotg->lock, flags); |
2639 | return ret; | 2718 | return ret; |
2640 | } | 2719 | } |
@@ -2776,6 +2855,8 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | |||
2776 | 2855 | ||
2777 | writel(epctl, hs->regs + epreg); | 2856 | writel(epctl, hs->regs + epreg); |
2778 | 2857 | ||
2858 | hs_ep->halted = value; | ||
2859 | |||
2779 | return 0; | 2860 | return 0; |
2780 | } | 2861 | } |
2781 | 2862 | ||
@@ -2903,7 +2984,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | |||
2903 | int ret; | 2984 | int ret; |
2904 | 2985 | ||
2905 | if (!hsotg) { | 2986 | if (!hsotg) { |
2906 | printk(KERN_ERR "%s: called with no device\n", __func__); | 2987 | pr_err("%s: called with no device\n", __func__); |
2907 | return -ENODEV; | 2988 | return -ENODEV; |
2908 | } | 2989 | } |
2909 | 2990 | ||
@@ -3066,7 +3147,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3066 | 3147 | ||
3067 | hs_ep->parent = hsotg; | 3148 | hs_ep->parent = hsotg; |
3068 | hs_ep->ep.name = hs_ep->name; | 3149 | hs_ep->ep.name = hs_ep->name; |
3069 | hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; | 3150 | hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT; |
3070 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; | 3151 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
3071 | 3152 | ||
3072 | /* | 3153 | /* |
@@ -3200,7 +3281,7 @@ static int state_show(struct seq_file *seq, void *v) | |||
3200 | readl(regs + GNPTXSTS), | 3281 | readl(regs + GNPTXSTS), |
3201 | readl(regs + GRXSTSR)); | 3282 | readl(regs + GRXSTSR)); |
3202 | 3283 | ||
3203 | seq_printf(seq, "\nEndpoint status:\n"); | 3284 | seq_puts(seq, "\nEndpoint status:\n"); |
3204 | 3285 | ||
3205 | for (idx = 0; idx < 15; idx++) { | 3286 | for (idx = 0; idx < 15; idx++) { |
3206 | u32 in, out; | 3287 | u32 in, out; |
@@ -3217,7 +3298,7 @@ static int state_show(struct seq_file *seq, void *v) | |||
3217 | seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", | 3298 | seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", |
3218 | in, out); | 3299 | in, out); |
3219 | 3300 | ||
3220 | seq_printf(seq, "\n"); | 3301 | seq_puts(seq, "\n"); |
3221 | } | 3302 | } |
3222 | 3303 | ||
3223 | return 0; | 3304 | return 0; |
@@ -3251,7 +3332,7 @@ static int fifo_show(struct seq_file *seq, void *v) | |||
3251 | u32 val; | 3332 | u32 val; |
3252 | int idx; | 3333 | int idx; |
3253 | 3334 | ||
3254 | seq_printf(seq, "Non-periodic FIFOs:\n"); | 3335 | seq_puts(seq, "Non-periodic FIFOs:\n"); |
3255 | seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); | 3336 | seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); |
3256 | 3337 | ||
3257 | val = readl(regs + GNPTXFSIZ); | 3338 | val = readl(regs + GNPTXFSIZ); |
@@ -3259,7 +3340,7 @@ static int fifo_show(struct seq_file *seq, void *v) | |||
3259 | val >> GNPTXFSIZ_NPTxFDep_SHIFT, | 3340 | val >> GNPTXFSIZ_NPTxFDep_SHIFT, |
3260 | val & GNPTXFSIZ_NPTxFStAddr_MASK); | 3341 | val & GNPTXFSIZ_NPTxFStAddr_MASK); |
3261 | 3342 | ||
3262 | seq_printf(seq, "\nPeriodic TXFIFOs:\n"); | 3343 | seq_puts(seq, "\nPeriodic TXFIFOs:\n"); |
3263 | 3344 | ||
3264 | for (idx = 1; idx <= 15; idx++) { | 3345 | for (idx = 1; idx <= 15; idx++) { |
3265 | val = readl(regs + DPTXFSIZn(idx)); | 3346 | val = readl(regs + DPTXFSIZn(idx)); |
@@ -3330,7 +3411,7 @@ static int ep_show(struct seq_file *seq, void *v) | |||
3330 | readl(regs + DIEPTSIZ(index)), | 3411 | readl(regs + DIEPTSIZ(index)), |
3331 | readl(regs + DOEPTSIZ(index))); | 3412 | readl(regs + DOEPTSIZ(index))); |
3332 | 3413 | ||
3333 | seq_printf(seq, "\n"); | 3414 | seq_puts(seq, "\n"); |
3334 | seq_printf(seq, "mps %d\n", ep->ep.maxpacket); | 3415 | seq_printf(seq, "mps %d\n", ep->ep.maxpacket); |
3335 | seq_printf(seq, "total_data=%ld\n", ep->total_data); | 3416 | seq_printf(seq, "total_data=%ld\n", ep->total_data); |
3336 | 3417 | ||
@@ -3341,7 +3422,7 @@ static int ep_show(struct seq_file *seq, void *v) | |||
3341 | 3422 | ||
3342 | list_for_each_entry(req, &ep->queue, queue) { | 3423 | list_for_each_entry(req, &ep->queue, queue) { |
3343 | if (--show_limit < 0) { | 3424 | if (--show_limit < 0) { |
3344 | seq_printf(seq, "not showing more requests...\n"); | 3425 | seq_puts(seq, "not showing more requests...\n"); |
3345 | break; | 3426 | break; |
3346 | } | 3427 | } |
3347 | 3428 | ||
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 08a1a3210a21..ec20a1f50c2d 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -23,242 +23,17 @@ | |||
23 | * The valid range of num_buffers is: num >= 2 && num <= 4. | 23 | * The valid range of num_buffers is: num >= 2 && num <= 4. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/blkdev.h> | ||
28 | #include <linux/file.h> | ||
29 | #include <linux/fs.h> | ||
30 | #include <linux/usb/composite.h> | ||
26 | 31 | ||
27 | #include <linux/usb/storage.h> | 32 | #include "storage_common.h" |
28 | #include <scsi/scsi.h> | ||
29 | #include <asm/unaligned.h> | ||
30 | |||
31 | |||
32 | /* | ||
33 | * Thanks to NetChip Technologies for donating this product ID. | ||
34 | * | ||
35 | * DO NOT REUSE THESE IDs with any other driver!! Ever!! | ||
36 | * Instead: allocate your own, using normal USB-IF procedures. | ||
37 | */ | ||
38 | #define FSG_VENDOR_ID 0x0525 /* NetChip */ | ||
39 | #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ | ||
40 | |||
41 | |||
42 | /*-------------------------------------------------------------------------*/ | ||
43 | |||
44 | |||
45 | #ifndef DEBUG | ||
46 | #undef VERBOSE_DEBUG | ||
47 | #undef DUMP_MSGS | ||
48 | #endif /* !DEBUG */ | ||
49 | |||
50 | #ifdef VERBOSE_DEBUG | ||
51 | #define VLDBG LDBG | ||
52 | #else | ||
53 | #define VLDBG(lun, fmt, args...) do { } while (0) | ||
54 | #endif /* VERBOSE_DEBUG */ | ||
55 | |||
56 | #define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args) | ||
57 | #define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args) | ||
58 | #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) | ||
59 | #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) | ||
60 | |||
61 | |||
62 | #ifdef DUMP_MSGS | ||
63 | |||
64 | # define dump_msg(fsg, /* const char * */ label, \ | ||
65 | /* const u8 * */ buf, /* unsigned */ length) do { \ | ||
66 | if (length < 512) { \ | ||
67 | DBG(fsg, "%s, length %u:\n", label, length); \ | ||
68 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ | ||
69 | 16, 1, buf, length, 0); \ | ||
70 | } \ | ||
71 | } while (0) | ||
72 | |||
73 | # define dump_cdb(fsg) do { } while (0) | ||
74 | |||
75 | #else | ||
76 | |||
77 | # define dump_msg(fsg, /* const char * */ label, \ | ||
78 | /* const u8 * */ buf, /* unsigned */ length) do { } while (0) | ||
79 | |||
80 | # ifdef VERBOSE_DEBUG | ||
81 | |||
82 | # define dump_cdb(fsg) \ | ||
83 | print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ | ||
84 | 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ | ||
85 | |||
86 | # else | ||
87 | |||
88 | # define dump_cdb(fsg) do { } while (0) | ||
89 | |||
90 | # endif /* VERBOSE_DEBUG */ | ||
91 | |||
92 | #endif /* DUMP_MSGS */ | ||
93 | |||
94 | /*-------------------------------------------------------------------------*/ | ||
95 | |||
96 | /* Length of a SCSI Command Data Block */ | ||
97 | #define MAX_COMMAND_SIZE 16 | ||
98 | |||
99 | /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ | ||
100 | #define SS_NO_SENSE 0 | ||
101 | #define SS_COMMUNICATION_FAILURE 0x040800 | ||
102 | #define SS_INVALID_COMMAND 0x052000 | ||
103 | #define SS_INVALID_FIELD_IN_CDB 0x052400 | ||
104 | #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 | ||
105 | #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 | ||
106 | #define SS_MEDIUM_NOT_PRESENT 0x023a00 | ||
107 | #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 | ||
108 | #define SS_NOT_READY_TO_READY_TRANSITION 0x062800 | ||
109 | #define SS_RESET_OCCURRED 0x062900 | ||
110 | #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 | ||
111 | #define SS_UNRECOVERED_READ_ERROR 0x031100 | ||
112 | #define SS_WRITE_ERROR 0x030c02 | ||
113 | #define SS_WRITE_PROTECTED 0x072700 | ||
114 | |||
115 | #define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ | ||
116 | #define ASC(x) ((u8) ((x) >> 8)) | ||
117 | #define ASCQ(x) ((u8) (x)) | ||
118 | |||
119 | |||
120 | /*-------------------------------------------------------------------------*/ | ||
121 | |||
122 | |||
123 | struct fsg_lun { | ||
124 | struct file *filp; | ||
125 | loff_t file_length; | ||
126 | loff_t num_sectors; | ||
127 | |||
128 | unsigned int initially_ro:1; | ||
129 | unsigned int ro:1; | ||
130 | unsigned int removable:1; | ||
131 | unsigned int cdrom:1; | ||
132 | unsigned int prevent_medium_removal:1; | ||
133 | unsigned int registered:1; | ||
134 | unsigned int info_valid:1; | ||
135 | unsigned int nofua:1; | ||
136 | |||
137 | u32 sense_data; | ||
138 | u32 sense_data_info; | ||
139 | u32 unit_attention_data; | ||
140 | |||
141 | unsigned int blkbits; /* Bits of logical block size of bound block device */ | ||
142 | unsigned int blksize; /* logical block size of bound block device */ | ||
143 | struct device dev; | ||
144 | }; | ||
145 | |||
146 | static inline bool fsg_lun_is_open(struct fsg_lun *curlun) | ||
147 | { | ||
148 | return curlun->filp != NULL; | ||
149 | } | ||
150 | |||
151 | static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) | ||
152 | { | ||
153 | return container_of(dev, struct fsg_lun, dev); | ||
154 | } | ||
155 | |||
156 | |||
157 | /* Big enough to hold our biggest descriptor */ | ||
158 | #define EP0_BUFSIZE 256 | ||
159 | #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ | ||
160 | |||
161 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
162 | |||
163 | static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | ||
164 | module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO); | ||
165 | MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers"); | ||
166 | |||
167 | #else | ||
168 | |||
169 | /* | ||
170 | * Number of buffers we will use. | ||
171 | * 2 is usually enough for good buffering pipeline | ||
172 | */ | ||
173 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | ||
174 | |||
175 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ | ||
176 | |||
177 | /* check if fsg_num_buffers is within a valid range */ | ||
178 | static inline int fsg_num_buffers_validate(void) | ||
179 | { | ||
180 | if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4) | ||
181 | return 0; | ||
182 | pr_err("fsg_num_buffers %u is out of range (%d to %d)\n", | ||
183 | fsg_num_buffers, 2 ,4); | ||
184 | return -EINVAL; | ||
185 | } | ||
186 | |||
187 | /* Default size of buffer length. */ | ||
188 | #define FSG_BUFLEN ((u32)16384) | ||
189 | |||
190 | /* Maximal number of LUNs supported in mass storage function */ | ||
191 | #define FSG_MAX_LUNS 8 | ||
192 | |||
193 | enum fsg_buffer_state { | ||
194 | BUF_STATE_EMPTY = 0, | ||
195 | BUF_STATE_FULL, | ||
196 | BUF_STATE_BUSY | ||
197 | }; | ||
198 | |||
199 | struct fsg_buffhd { | ||
200 | void *buf; | ||
201 | enum fsg_buffer_state state; | ||
202 | struct fsg_buffhd *next; | ||
203 | |||
204 | /* | ||
205 | * The NetChip 2280 is faster, and handles some protocol faults | ||
206 | * better, if we don't submit any short bulk-out read requests. | ||
207 | * So we will record the intended request length here. | ||
208 | */ | ||
209 | unsigned int bulk_out_intended_length; | ||
210 | |||
211 | struct usb_request *inreq; | ||
212 | int inreq_busy; | ||
213 | struct usb_request *outreq; | ||
214 | int outreq_busy; | ||
215 | }; | ||
216 | |||
217 | enum fsg_state { | ||
218 | /* This one isn't used anywhere */ | ||
219 | FSG_STATE_COMMAND_PHASE = -10, | ||
220 | FSG_STATE_DATA_PHASE, | ||
221 | FSG_STATE_STATUS_PHASE, | ||
222 | |||
223 | FSG_STATE_IDLE = 0, | ||
224 | FSG_STATE_ABORT_BULK_OUT, | ||
225 | FSG_STATE_RESET, | ||
226 | FSG_STATE_INTERFACE_CHANGE, | ||
227 | FSG_STATE_CONFIG_CHANGE, | ||
228 | FSG_STATE_DISCONNECT, | ||
229 | FSG_STATE_EXIT, | ||
230 | FSG_STATE_TERMINATED | ||
231 | }; | ||
232 | |||
233 | enum data_direction { | ||
234 | DATA_DIR_UNKNOWN = 0, | ||
235 | DATA_DIR_FROM_HOST, | ||
236 | DATA_DIR_TO_HOST, | ||
237 | DATA_DIR_NONE | ||
238 | }; | ||
239 | |||
240 | |||
241 | /*-------------------------------------------------------------------------*/ | ||
242 | |||
243 | |||
244 | static inline u32 get_unaligned_be24(u8 *buf) | ||
245 | { | ||
246 | return 0xffffff & (u32) get_unaligned_be32(buf - 1); | ||
247 | } | ||
248 | |||
249 | |||
250 | /*-------------------------------------------------------------------------*/ | ||
251 | |||
252 | |||
253 | enum { | ||
254 | FSG_STRING_INTERFACE | ||
255 | }; | ||
256 | |||
257 | 33 | ||
258 | /* There is only one interface. */ | 34 | /* There is only one interface. */ |
259 | 35 | ||
260 | static struct usb_interface_descriptor | 36 | struct usb_interface_descriptor fsg_intf_desc = { |
261 | fsg_intf_desc = { | ||
262 | .bLength = sizeof fsg_intf_desc, | 37 | .bLength = sizeof fsg_intf_desc, |
263 | .bDescriptorType = USB_DT_INTERFACE, | 38 | .bDescriptorType = USB_DT_INTERFACE, |
264 | 39 | ||
@@ -268,14 +43,14 @@ fsg_intf_desc = { | |||
268 | .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ | 43 | .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ |
269 | .iInterface = FSG_STRING_INTERFACE, | 44 | .iInterface = FSG_STRING_INTERFACE, |
270 | }; | 45 | }; |
46 | EXPORT_SYMBOL(fsg_intf_desc); | ||
271 | 47 | ||
272 | /* | 48 | /* |
273 | * Three full-speed endpoint descriptors: bulk-in, bulk-out, and | 49 | * Three full-speed endpoint descriptors: bulk-in, bulk-out, and |
274 | * interrupt-in. | 50 | * interrupt-in. |
275 | */ | 51 | */ |
276 | 52 | ||
277 | static struct usb_endpoint_descriptor | 53 | struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = { |
278 | fsg_fs_bulk_in_desc = { | ||
279 | .bLength = USB_DT_ENDPOINT_SIZE, | 54 | .bLength = USB_DT_ENDPOINT_SIZE, |
280 | .bDescriptorType = USB_DT_ENDPOINT, | 55 | .bDescriptorType = USB_DT_ENDPOINT, |
281 | 56 | ||
@@ -283,9 +58,9 @@ fsg_fs_bulk_in_desc = { | |||
283 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 58 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
284 | /* wMaxPacketSize set by autoconfiguration */ | 59 | /* wMaxPacketSize set by autoconfiguration */ |
285 | }; | 60 | }; |
61 | EXPORT_SYMBOL(fsg_fs_bulk_in_desc); | ||
286 | 62 | ||
287 | static struct usb_endpoint_descriptor | 63 | struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = { |
288 | fsg_fs_bulk_out_desc = { | ||
289 | .bLength = USB_DT_ENDPOINT_SIZE, | 64 | .bLength = USB_DT_ENDPOINT_SIZE, |
290 | .bDescriptorType = USB_DT_ENDPOINT, | 65 | .bDescriptorType = USB_DT_ENDPOINT, |
291 | 66 | ||
@@ -293,13 +68,15 @@ fsg_fs_bulk_out_desc = { | |||
293 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 68 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
294 | /* wMaxPacketSize set by autoconfiguration */ | 69 | /* wMaxPacketSize set by autoconfiguration */ |
295 | }; | 70 | }; |
71 | EXPORT_SYMBOL(fsg_fs_bulk_out_desc); | ||
296 | 72 | ||
297 | static struct usb_descriptor_header *fsg_fs_function[] = { | 73 | struct usb_descriptor_header *fsg_fs_function[] = { |
298 | (struct usb_descriptor_header *) &fsg_intf_desc, | 74 | (struct usb_descriptor_header *) &fsg_intf_desc, |
299 | (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, | 75 | (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, |
300 | (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, | 76 | (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, |
301 | NULL, | 77 | NULL, |
302 | }; | 78 | }; |
79 | EXPORT_SYMBOL(fsg_fs_function); | ||
303 | 80 | ||
304 | 81 | ||
305 | /* | 82 | /* |
@@ -310,8 +87,7 @@ static struct usb_descriptor_header *fsg_fs_function[] = { | |||
310 | * and a "device qualifier" ... plus more construction options | 87 | * and a "device qualifier" ... plus more construction options |
311 | * for the configuration descriptor. | 88 | * for the configuration descriptor. |
312 | */ | 89 | */ |
313 | static struct usb_endpoint_descriptor | 90 | struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = { |
314 | fsg_hs_bulk_in_desc = { | ||
315 | .bLength = USB_DT_ENDPOINT_SIZE, | 91 | .bLength = USB_DT_ENDPOINT_SIZE, |
316 | .bDescriptorType = USB_DT_ENDPOINT, | 92 | .bDescriptorType = USB_DT_ENDPOINT, |
317 | 93 | ||
@@ -319,9 +95,9 @@ fsg_hs_bulk_in_desc = { | |||
319 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 95 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
320 | .wMaxPacketSize = cpu_to_le16(512), | 96 | .wMaxPacketSize = cpu_to_le16(512), |
321 | }; | 97 | }; |
98 | EXPORT_SYMBOL(fsg_hs_bulk_in_desc); | ||
322 | 99 | ||
323 | static struct usb_endpoint_descriptor | 100 | struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = { |
324 | fsg_hs_bulk_out_desc = { | ||
325 | .bLength = USB_DT_ENDPOINT_SIZE, | 101 | .bLength = USB_DT_ENDPOINT_SIZE, |
326 | .bDescriptorType = USB_DT_ENDPOINT, | 102 | .bDescriptorType = USB_DT_ENDPOINT, |
327 | 103 | ||
@@ -330,17 +106,18 @@ fsg_hs_bulk_out_desc = { | |||
330 | .wMaxPacketSize = cpu_to_le16(512), | 106 | .wMaxPacketSize = cpu_to_le16(512), |
331 | .bInterval = 1, /* NAK every 1 uframe */ | 107 | .bInterval = 1, /* NAK every 1 uframe */ |
332 | }; | 108 | }; |
109 | EXPORT_SYMBOL(fsg_hs_bulk_out_desc); | ||
333 | 110 | ||
334 | 111 | ||
335 | static struct usb_descriptor_header *fsg_hs_function[] = { | 112 | struct usb_descriptor_header *fsg_hs_function[] = { |
336 | (struct usb_descriptor_header *) &fsg_intf_desc, | 113 | (struct usb_descriptor_header *) &fsg_intf_desc, |
337 | (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, | 114 | (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, |
338 | (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, | 115 | (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, |
339 | NULL, | 116 | NULL, |
340 | }; | 117 | }; |
118 | EXPORT_SYMBOL(fsg_hs_function); | ||
341 | 119 | ||
342 | static struct usb_endpoint_descriptor | 120 | struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = { |
343 | fsg_ss_bulk_in_desc = { | ||
344 | .bLength = USB_DT_ENDPOINT_SIZE, | 121 | .bLength = USB_DT_ENDPOINT_SIZE, |
345 | .bDescriptorType = USB_DT_ENDPOINT, | 122 | .bDescriptorType = USB_DT_ENDPOINT, |
346 | 123 | ||
@@ -348,16 +125,17 @@ fsg_ss_bulk_in_desc = { | |||
348 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 125 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
349 | .wMaxPacketSize = cpu_to_le16(1024), | 126 | .wMaxPacketSize = cpu_to_le16(1024), |
350 | }; | 127 | }; |
128 | EXPORT_SYMBOL(fsg_ss_bulk_in_desc); | ||
351 | 129 | ||
352 | static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { | 130 | struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { |
353 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | 131 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), |
354 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 132 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
355 | 133 | ||
356 | /*.bMaxBurst = DYNAMIC, */ | 134 | /*.bMaxBurst = DYNAMIC, */ |
357 | }; | 135 | }; |
136 | EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc); | ||
358 | 137 | ||
359 | static struct usb_endpoint_descriptor | 138 | struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = { |
360 | fsg_ss_bulk_out_desc = { | ||
361 | .bLength = USB_DT_ENDPOINT_SIZE, | 139 | .bLength = USB_DT_ENDPOINT_SIZE, |
362 | .bDescriptorType = USB_DT_ENDPOINT, | 140 | .bDescriptorType = USB_DT_ENDPOINT, |
363 | 141 | ||
@@ -365,15 +143,17 @@ fsg_ss_bulk_out_desc = { | |||
365 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 143 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
366 | .wMaxPacketSize = cpu_to_le16(1024), | 144 | .wMaxPacketSize = cpu_to_le16(1024), |
367 | }; | 145 | }; |
146 | EXPORT_SYMBOL(fsg_ss_bulk_out_desc); | ||
368 | 147 | ||
369 | static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { | 148 | struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { |
370 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | 149 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), |
371 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 150 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
372 | 151 | ||
373 | /*.bMaxBurst = DYNAMIC, */ | 152 | /*.bMaxBurst = DYNAMIC, */ |
374 | }; | 153 | }; |
154 | EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc); | ||
375 | 155 | ||
376 | static struct usb_descriptor_header *fsg_ss_function[] = { | 156 | struct usb_descriptor_header *fsg_ss_function[] = { |
377 | (struct usb_descriptor_header *) &fsg_intf_desc, | 157 | (struct usb_descriptor_header *) &fsg_intf_desc, |
378 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, | 158 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, |
379 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, | 159 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, |
@@ -381,17 +161,7 @@ static struct usb_descriptor_header *fsg_ss_function[] = { | |||
381 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, | 161 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, |
382 | NULL, | 162 | NULL, |
383 | }; | 163 | }; |
384 | 164 | EXPORT_SYMBOL(fsg_ss_function); | |
385 | /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ | ||
386 | static struct usb_string fsg_strings[] = { | ||
387 | {FSG_STRING_INTERFACE, fsg_string_interface}, | ||
388 | {} | ||
389 | }; | ||
390 | |||
391 | static struct usb_gadget_strings fsg_stringtab = { | ||
392 | .language = 0x0409, /* en-us */ | ||
393 | .strings = fsg_strings, | ||
394 | }; | ||
395 | 165 | ||
396 | 166 | ||
397 | /*-------------------------------------------------------------------------*/ | 167 | /*-------------------------------------------------------------------------*/ |
@@ -401,7 +171,7 @@ static struct usb_gadget_strings fsg_stringtab = { | |||
401 | * the caller must own fsg->filesem for writing. | 171 | * the caller must own fsg->filesem for writing. |
402 | */ | 172 | */ |
403 | 173 | ||
404 | static void fsg_lun_close(struct fsg_lun *curlun) | 174 | void fsg_lun_close(struct fsg_lun *curlun) |
405 | { | 175 | { |
406 | if (curlun->filp) { | 176 | if (curlun->filp) { |
407 | LDBG(curlun, "close backing file\n"); | 177 | LDBG(curlun, "close backing file\n"); |
@@ -409,9 +179,9 @@ static void fsg_lun_close(struct fsg_lun *curlun) | |||
409 | curlun->filp = NULL; | 179 | curlun->filp = NULL; |
410 | } | 180 | } |
411 | } | 181 | } |
182 | EXPORT_SYMBOL(fsg_lun_close); | ||
412 | 183 | ||
413 | 184 | int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |
414 | static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | ||
415 | { | 185 | { |
416 | int ro; | 186 | int ro; |
417 | struct file *filp = NULL; | 187 | struct file *filp = NULL; |
@@ -508,6 +278,7 @@ out: | |||
508 | fput(filp); | 278 | fput(filp); |
509 | return rc; | 279 | return rc; |
510 | } | 280 | } |
281 | EXPORT_SYMBOL(fsg_lun_open); | ||
511 | 282 | ||
512 | 283 | ||
513 | /*-------------------------------------------------------------------------*/ | 284 | /*-------------------------------------------------------------------------*/ |
@@ -516,7 +287,7 @@ out: | |||
516 | * Sync the file data, don't bother with the metadata. | 287 | * Sync the file data, don't bother with the metadata. |
517 | * This code was copied from fs/buffer.c:sys_fdatasync(). | 288 | * This code was copied from fs/buffer.c:sys_fdatasync(). |
518 | */ | 289 | */ |
519 | static int fsg_lun_fsync_sub(struct fsg_lun *curlun) | 290 | int fsg_lun_fsync_sub(struct fsg_lun *curlun) |
520 | { | 291 | { |
521 | struct file *filp = curlun->filp; | 292 | struct file *filp = curlun->filp; |
522 | 293 | ||
@@ -524,8 +295,9 @@ static int fsg_lun_fsync_sub(struct fsg_lun *curlun) | |||
524 | return 0; | 295 | return 0; |
525 | return vfs_fsync(filp, 1); | 296 | return vfs_fsync(filp, 1); |
526 | } | 297 | } |
298 | EXPORT_SYMBOL(fsg_lun_fsync_sub); | ||
527 | 299 | ||
528 | static void store_cdrom_address(u8 *dest, int msf, u32 addr) | 300 | void store_cdrom_address(u8 *dest, int msf, u32 addr) |
529 | { | 301 | { |
530 | if (msf) { | 302 | if (msf) { |
531 | /* Convert to Minutes-Seconds-Frames */ | 303 | /* Convert to Minutes-Seconds-Frames */ |
@@ -542,34 +314,28 @@ static void store_cdrom_address(u8 *dest, int msf, u32 addr) | |||
542 | put_unaligned_be32(addr, dest); | 314 | put_unaligned_be32(addr, dest); |
543 | } | 315 | } |
544 | } | 316 | } |
545 | 317 | EXPORT_SYMBOL(store_cdrom_address); | |
546 | 318 | ||
547 | /*-------------------------------------------------------------------------*/ | 319 | /*-------------------------------------------------------------------------*/ |
548 | 320 | ||
549 | 321 | ||
550 | static ssize_t ro_show(struct device *dev, struct device_attribute *attr, | 322 | ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf) |
551 | char *buf) | ||
552 | { | 323 | { |
553 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
554 | |||
555 | return sprintf(buf, "%d\n", fsg_lun_is_open(curlun) | 324 | return sprintf(buf, "%d\n", fsg_lun_is_open(curlun) |
556 | ? curlun->ro | 325 | ? curlun->ro |
557 | : curlun->initially_ro); | 326 | : curlun->initially_ro); |
558 | } | 327 | } |
328 | EXPORT_SYMBOL(fsg_show_ro); | ||
559 | 329 | ||
560 | static ssize_t nofua_show(struct device *dev, struct device_attribute *attr, | 330 | ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf) |
561 | char *buf) | ||
562 | { | 331 | { |
563 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
564 | |||
565 | return sprintf(buf, "%u\n", curlun->nofua); | 332 | return sprintf(buf, "%u\n", curlun->nofua); |
566 | } | 333 | } |
334 | EXPORT_SYMBOL(fsg_show_nofua); | ||
567 | 335 | ||
568 | static ssize_t file_show(struct device *dev, struct device_attribute *attr, | 336 | ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, |
569 | char *buf) | 337 | char *buf) |
570 | { | 338 | { |
571 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
572 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | ||
573 | char *p; | 339 | char *p; |
574 | ssize_t rc; | 340 | ssize_t rc; |
575 | 341 | ||
@@ -591,17 +357,44 @@ static ssize_t file_show(struct device *dev, struct device_attribute *attr, | |||
591 | up_read(filesem); | 357 | up_read(filesem); |
592 | return rc; | 358 | return rc; |
593 | } | 359 | } |
360 | EXPORT_SYMBOL(fsg_show_file); | ||
594 | 361 | ||
362 | ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf) | ||
363 | { | ||
364 | return sprintf(buf, "%u\n", curlun->cdrom); | ||
365 | } | ||
366 | EXPORT_SYMBOL(fsg_show_cdrom); | ||
595 | 367 | ||
596 | static ssize_t ro_store(struct device *dev, struct device_attribute *attr, | 368 | ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf) |
597 | const char *buf, size_t count) | 369 | { |
370 | return sprintf(buf, "%u\n", curlun->removable); | ||
371 | } | ||
372 | EXPORT_SYMBOL(fsg_show_removable); | ||
373 | |||
374 | /* | ||
375 | * The caller must hold fsg->filesem for reading when calling this function. | ||
376 | */ | ||
377 | static ssize_t _fsg_store_ro(struct fsg_lun *curlun, bool ro) | ||
378 | { | ||
379 | if (fsg_lun_is_open(curlun)) { | ||
380 | LDBG(curlun, "read-only status change prevented\n"); | ||
381 | return -EBUSY; | ||
382 | } | ||
383 | |||
384 | curlun->ro = ro; | ||
385 | curlun->initially_ro = ro; | ||
386 | LDBG(curlun, "read-only status set to %d\n", curlun->ro); | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, | ||
392 | const char *buf, size_t count) | ||
598 | { | 393 | { |
599 | ssize_t rc; | 394 | ssize_t rc; |
600 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | 395 | bool ro; |
601 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | ||
602 | unsigned ro; | ||
603 | 396 | ||
604 | rc = kstrtouint(buf, 2, &ro); | 397 | rc = strtobool(buf, &ro); |
605 | if (rc) | 398 | if (rc) |
606 | return rc; | 399 | return rc; |
607 | 400 | ||
@@ -610,27 +403,21 @@ static ssize_t ro_store(struct device *dev, struct device_attribute *attr, | |||
610 | * backing file is closed. | 403 | * backing file is closed. |
611 | */ | 404 | */ |
612 | down_read(filesem); | 405 | down_read(filesem); |
613 | if (fsg_lun_is_open(curlun)) { | 406 | rc = _fsg_store_ro(curlun, ro); |
614 | LDBG(curlun, "read-only status change prevented\n"); | 407 | if (!rc) |
615 | rc = -EBUSY; | ||
616 | } else { | ||
617 | curlun->ro = ro; | ||
618 | curlun->initially_ro = ro; | ||
619 | LDBG(curlun, "read-only status set to %d\n", curlun->ro); | ||
620 | rc = count; | 408 | rc = count; |
621 | } | ||
622 | up_read(filesem); | 409 | up_read(filesem); |
410 | |||
623 | return rc; | 411 | return rc; |
624 | } | 412 | } |
413 | EXPORT_SYMBOL(fsg_store_ro); | ||
625 | 414 | ||
626 | static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, | 415 | ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) |
627 | const char *buf, size_t count) | ||
628 | { | 416 | { |
629 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | 417 | bool nofua; |
630 | unsigned nofua; | ||
631 | int ret; | 418 | int ret; |
632 | 419 | ||
633 | ret = kstrtouint(buf, 2, &nofua); | 420 | ret = strtobool(buf, &nofua); |
634 | if (ret) | 421 | if (ret) |
635 | return ret; | 422 | return ret; |
636 | 423 | ||
@@ -642,12 +429,11 @@ static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, | |||
642 | 429 | ||
643 | return count; | 430 | return count; |
644 | } | 431 | } |
432 | EXPORT_SYMBOL(fsg_store_nofua); | ||
645 | 433 | ||
646 | static ssize_t file_store(struct device *dev, struct device_attribute *attr, | 434 | ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, |
647 | const char *buf, size_t count) | 435 | const char *buf, size_t count) |
648 | { | 436 | { |
649 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
650 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | ||
651 | int rc = 0; | 437 | int rc = 0; |
652 | 438 | ||
653 | if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) { | 439 | if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) { |
@@ -674,3 +460,45 @@ static ssize_t file_store(struct device *dev, struct device_attribute *attr, | |||
674 | up_write(filesem); | 460 | up_write(filesem); |
675 | return (rc < 0 ? rc : count); | 461 | return (rc < 0 ? rc : count); |
676 | } | 462 | } |
463 | EXPORT_SYMBOL(fsg_store_file); | ||
464 | |||
465 | ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, | ||
466 | const char *buf, size_t count) | ||
467 | { | ||
468 | bool cdrom; | ||
469 | int ret; | ||
470 | |||
471 | ret = strtobool(buf, &cdrom); | ||
472 | if (ret) | ||
473 | return ret; | ||
474 | |||
475 | down_read(filesem); | ||
476 | ret = cdrom ? _fsg_store_ro(curlun, true) : 0; | ||
477 | |||
478 | if (!ret) { | ||
479 | curlun->cdrom = cdrom; | ||
480 | ret = count; | ||
481 | } | ||
482 | up_read(filesem); | ||
483 | |||
484 | return ret; | ||
485 | } | ||
486 | EXPORT_SYMBOL(fsg_store_cdrom); | ||
487 | |||
488 | ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, | ||
489 | size_t count) | ||
490 | { | ||
491 | bool removable; | ||
492 | int ret; | ||
493 | |||
494 | ret = strtobool(buf, &removable); | ||
495 | if (ret) | ||
496 | return ret; | ||
497 | |||
498 | curlun->removable = removable; | ||
499 | |||
500 | return count; | ||
501 | } | ||
502 | EXPORT_SYMBOL(fsg_store_removable); | ||
503 | |||
504 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/storage_common.h b/drivers/usb/gadget/storage_common.h new file mode 100644 index 000000000000..c74c2fdbd56e --- /dev/null +++ b/drivers/usb/gadget/storage_common.h | |||
@@ -0,0 +1,229 @@ | |||
1 | #ifndef USB_STORAGE_COMMON_H | ||
2 | #define USB_STORAGE_COMMON_H | ||
3 | |||
4 | #include <linux/device.h> | ||
5 | #include <linux/usb/storage.h> | ||
6 | #include <scsi/scsi.h> | ||
7 | #include <asm/unaligned.h> | ||
8 | |||
9 | #ifndef DEBUG | ||
10 | #undef VERBOSE_DEBUG | ||
11 | #undef DUMP_MSGS | ||
12 | #endif /* !DEBUG */ | ||
13 | |||
14 | #ifdef VERBOSE_DEBUG | ||
15 | #define VLDBG LDBG | ||
16 | #else | ||
17 | #define VLDBG(lun, fmt, args...) do { } while (0) | ||
18 | #endif /* VERBOSE_DEBUG */ | ||
19 | |||
20 | #define _LMSG(func, lun, fmt, args...) \ | ||
21 | do { \ | ||
22 | if ((lun)->name_pfx && *(lun)->name_pfx) \ | ||
23 | func("%s/%s: " fmt, *(lun)->name_pfx, \ | ||
24 | (lun)->name, ## args); \ | ||
25 | else \ | ||
26 | func("%s: " fmt, (lun)->name, ## args); \ | ||
27 | } while (0) | ||
28 | |||
29 | #define LDBG(lun, fmt, args...) _LMSG(pr_debug, lun, fmt, ## args) | ||
30 | #define LERROR(lun, fmt, args...) _LMSG(pr_err, lun, fmt, ## args) | ||
31 | #define LWARN(lun, fmt, args...) _LMSG(pr_warn, lun, fmt, ## args) | ||
32 | #define LINFO(lun, fmt, args...) _LMSG(pr_info, lun, fmt, ## args) | ||
33 | |||
34 | |||
35 | #ifdef DUMP_MSGS | ||
36 | |||
37 | # define dump_msg(fsg, /* const char * */ label, \ | ||
38 | /* const u8 * */ buf, /* unsigned */ length) \ | ||
39 | do { \ | ||
40 | if (length < 512) { \ | ||
41 | DBG(fsg, "%s, length %u:\n", label, length); \ | ||
42 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ | ||
43 | 16, 1, buf, length, 0); \ | ||
44 | } \ | ||
45 | } while (0) | ||
46 | |||
47 | # define dump_cdb(fsg) do { } while (0) | ||
48 | |||
49 | #else | ||
50 | |||
51 | # define dump_msg(fsg, /* const char * */ label, \ | ||
52 | /* const u8 * */ buf, /* unsigned */ length) do { } while (0) | ||
53 | |||
54 | # ifdef VERBOSE_DEBUG | ||
55 | |||
56 | # define dump_cdb(fsg) \ | ||
57 | print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ | ||
58 | 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ | ||
59 | |||
60 | # else | ||
61 | |||
62 | # define dump_cdb(fsg) do { } while (0) | ||
63 | |||
64 | # endif /* VERBOSE_DEBUG */ | ||
65 | |||
66 | #endif /* DUMP_MSGS */ | ||
67 | |||
68 | /* Length of a SCSI Command Data Block */ | ||
69 | #define MAX_COMMAND_SIZE 16 | ||
70 | |||
71 | /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ | ||
72 | #define SS_NO_SENSE 0 | ||
73 | #define SS_COMMUNICATION_FAILURE 0x040800 | ||
74 | #define SS_INVALID_COMMAND 0x052000 | ||
75 | #define SS_INVALID_FIELD_IN_CDB 0x052400 | ||
76 | #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 | ||
77 | #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 | ||
78 | #define SS_MEDIUM_NOT_PRESENT 0x023a00 | ||
79 | #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 | ||
80 | #define SS_NOT_READY_TO_READY_TRANSITION 0x062800 | ||
81 | #define SS_RESET_OCCURRED 0x062900 | ||
82 | #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 | ||
83 | #define SS_UNRECOVERED_READ_ERROR 0x031100 | ||
84 | #define SS_WRITE_ERROR 0x030c02 | ||
85 | #define SS_WRITE_PROTECTED 0x072700 | ||
86 | |||
87 | #define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ | ||
88 | #define ASC(x) ((u8) ((x) >> 8)) | ||
89 | #define ASCQ(x) ((u8) (x)) | ||
90 | |||
91 | struct fsg_lun { | ||
92 | struct file *filp; | ||
93 | loff_t file_length; | ||
94 | loff_t num_sectors; | ||
95 | |||
96 | unsigned int initially_ro:1; | ||
97 | unsigned int ro:1; | ||
98 | unsigned int removable:1; | ||
99 | unsigned int cdrom:1; | ||
100 | unsigned int prevent_medium_removal:1; | ||
101 | unsigned int registered:1; | ||
102 | unsigned int info_valid:1; | ||
103 | unsigned int nofua:1; | ||
104 | |||
105 | u32 sense_data; | ||
106 | u32 sense_data_info; | ||
107 | u32 unit_attention_data; | ||
108 | |||
109 | unsigned int blkbits; /* Bits of logical block size | ||
110 | of bound block device */ | ||
111 | unsigned int blksize; /* logical block size of bound block device */ | ||
112 | struct device dev; | ||
113 | const char *name; /* "lun.name" */ | ||
114 | const char **name_pfx; /* "function.name" */ | ||
115 | }; | ||
116 | |||
117 | static inline bool fsg_lun_is_open(struct fsg_lun *curlun) | ||
118 | { | ||
119 | return curlun->filp != NULL; | ||
120 | } | ||
121 | |||
122 | /* Big enough to hold our biggest descriptor */ | ||
123 | #define EP0_BUFSIZE 256 | ||
124 | #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ | ||
125 | |||
126 | /* Default size of buffer length. */ | ||
127 | #define FSG_BUFLEN ((u32)16384) | ||
128 | |||
129 | /* Maximal number of LUNs supported in mass storage function */ | ||
130 | #define FSG_MAX_LUNS 8 | ||
131 | |||
132 | enum fsg_buffer_state { | ||
133 | BUF_STATE_EMPTY = 0, | ||
134 | BUF_STATE_FULL, | ||
135 | BUF_STATE_BUSY | ||
136 | }; | ||
137 | |||
138 | struct fsg_buffhd { | ||
139 | void *buf; | ||
140 | enum fsg_buffer_state state; | ||
141 | struct fsg_buffhd *next; | ||
142 | |||
143 | /* | ||
144 | * The NetChip 2280 is faster, and handles some protocol faults | ||
145 | * better, if we don't submit any short bulk-out read requests. | ||
146 | * So we will record the intended request length here. | ||
147 | */ | ||
148 | unsigned int bulk_out_intended_length; | ||
149 | |||
150 | struct usb_request *inreq; | ||
151 | int inreq_busy; | ||
152 | struct usb_request *outreq; | ||
153 | int outreq_busy; | ||
154 | }; | ||
155 | |||
156 | enum fsg_state { | ||
157 | /* This one isn't used anywhere */ | ||
158 | FSG_STATE_COMMAND_PHASE = -10, | ||
159 | FSG_STATE_DATA_PHASE, | ||
160 | FSG_STATE_STATUS_PHASE, | ||
161 | |||
162 | FSG_STATE_IDLE = 0, | ||
163 | FSG_STATE_ABORT_BULK_OUT, | ||
164 | FSG_STATE_RESET, | ||
165 | FSG_STATE_INTERFACE_CHANGE, | ||
166 | FSG_STATE_CONFIG_CHANGE, | ||
167 | FSG_STATE_DISCONNECT, | ||
168 | FSG_STATE_EXIT, | ||
169 | FSG_STATE_TERMINATED | ||
170 | }; | ||
171 | |||
172 | enum data_direction { | ||
173 | DATA_DIR_UNKNOWN = 0, | ||
174 | DATA_DIR_FROM_HOST, | ||
175 | DATA_DIR_TO_HOST, | ||
176 | DATA_DIR_NONE | ||
177 | }; | ||
178 | |||
179 | static inline u32 get_unaligned_be24(u8 *buf) | ||
180 | { | ||
181 | return 0xffffff & (u32) get_unaligned_be32(buf - 1); | ||
182 | } | ||
183 | |||
184 | static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) | ||
185 | { | ||
186 | return container_of(dev, struct fsg_lun, dev); | ||
187 | } | ||
188 | |||
189 | enum { | ||
190 | FSG_STRING_INTERFACE | ||
191 | }; | ||
192 | |||
193 | extern struct usb_interface_descriptor fsg_intf_desc; | ||
194 | |||
195 | extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc; | ||
196 | extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc; | ||
197 | extern struct usb_descriptor_header *fsg_fs_function[]; | ||
198 | |||
199 | extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc; | ||
200 | extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc; | ||
201 | extern struct usb_descriptor_header *fsg_hs_function[]; | ||
202 | |||
203 | extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc; | ||
204 | extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc; | ||
205 | extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc; | ||
206 | extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc; | ||
207 | extern struct usb_descriptor_header *fsg_ss_function[]; | ||
208 | |||
209 | void fsg_lun_close(struct fsg_lun *curlun); | ||
210 | int fsg_lun_open(struct fsg_lun *curlun, const char *filename); | ||
211 | int fsg_lun_fsync_sub(struct fsg_lun *curlun); | ||
212 | void store_cdrom_address(u8 *dest, int msf, u32 addr); | ||
213 | ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf); | ||
214 | ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf); | ||
215 | ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, | ||
216 | char *buf); | ||
217 | ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf); | ||
218 | ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf); | ||
219 | ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, | ||
220 | const char *buf, size_t count); | ||
221 | ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count); | ||
222 | ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, | ||
223 | const char *buf, size_t count); | ||
224 | ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, | ||
225 | const char *buf, size_t count); | ||
226 | ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, | ||
227 | size_t count); | ||
228 | |||
229 | #endif /* USB_STORAGE_COMMON_H */ | ||
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c index 0ff33396eef3..eccea1df702d 100644 --- a/drivers/usb/gadget/tcm_usb_gadget.c +++ b/drivers/usb/gadget/tcm_usb_gadget.c | |||
@@ -472,7 +472,7 @@ static int usbg_bot_setup(struct usb_function *f, | |||
472 | bot_enqueue_cmd_cbw(fu); | 472 | bot_enqueue_cmd_cbw(fu); |
473 | return 0; | 473 | return 0; |
474 | break; | 474 | break; |
475 | }; | 475 | } |
476 | return -ENOTSUPP; | 476 | return -ENOTSUPP; |
477 | } | 477 | } |
478 | 478 | ||
@@ -617,7 +617,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) | |||
617 | 617 | ||
618 | default: | 618 | default: |
619 | BUG(); | 619 | BUG(); |
620 | }; | 620 | } |
621 | return; | 621 | return; |
622 | 622 | ||
623 | cleanup: | 623 | cleanup: |
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index 59891b1c48fc..27768a7d986a 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -356,7 +356,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri | |||
356 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); | 356 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
357 | return 0; | 357 | return 0; |
358 | err1: | 358 | err1: |
359 | dev_err(&udc->dev, "failed to start %s: %d\n", | 359 | if (ret != -EISNAM) |
360 | dev_err(&udc->dev, "failed to start %s: %d\n", | ||
360 | udc->driver->function, ret); | 361 | udc->driver->function, ret); |
361 | udc->driver = NULL; | 362 | udc->driver = NULL; |
362 | udc->dev.driver = NULL; | 363 | udc->dev.driver = NULL; |
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 0deb9d6cde26..0dd07ae1555d 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -95,6 +95,18 @@ unsigned autoresume = DEFAULT_AUTORESUME; | |||
95 | module_param(autoresume, uint, S_IRUGO); | 95 | module_param(autoresume, uint, S_IRUGO); |
96 | MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup"); | 96 | MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup"); |
97 | 97 | ||
98 | /* Maximum Autoresume time */ | ||
99 | unsigned max_autoresume; | ||
100 | module_param(max_autoresume, uint, S_IRUGO); | ||
101 | MODULE_PARM_DESC(max_autoresume, "maximum seconds before remote wakeup"); | ||
102 | |||
103 | /* Interval between two remote wakeups */ | ||
104 | unsigned autoresume_interval_ms; | ||
105 | module_param(autoresume_interval_ms, uint, S_IRUGO); | ||
106 | MODULE_PARM_DESC(autoresume_interval_ms, | ||
107 | "milliseconds to increase successive wakeup delays"); | ||
108 | |||
109 | static unsigned autoresume_step_ms; | ||
98 | /*-------------------------------------------------------------------------*/ | 110 | /*-------------------------------------------------------------------------*/ |
99 | 111 | ||
100 | static struct usb_device_descriptor device_desc = { | 112 | static struct usb_device_descriptor device_desc = { |
@@ -183,8 +195,16 @@ static void zero_suspend(struct usb_composite_dev *cdev) | |||
183 | return; | 195 | return; |
184 | 196 | ||
185 | if (autoresume) { | 197 | if (autoresume) { |
186 | mod_timer(&autoresume_timer, jiffies + (HZ * autoresume)); | 198 | if (max_autoresume && |
187 | DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume); | 199 | (autoresume_step_ms > max_autoresume * 1000)) |
200 | autoresume_step_ms = autoresume * 1000; | ||
201 | |||
202 | mod_timer(&autoresume_timer, jiffies + | ||
203 | msecs_to_jiffies(autoresume_step_ms)); | ||
204 | DBG(cdev, "suspend, wakeup in %d milliseconds\n", | ||
205 | autoresume_step_ms); | ||
206 | |||
207 | autoresume_step_ms += autoresume_interval_ms; | ||
188 | } else | 208 | } else |
189 | DBG(cdev, "%s\n", __func__); | 209 | DBG(cdev, "%s\n", __func__); |
190 | } | 210 | } |
@@ -316,6 +336,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev) | |||
316 | if (autoresume) { | 336 | if (autoresume) { |
317 | sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 337 | sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
318 | loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 338 | loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
339 | autoresume_step_ms = autoresume * 1000; | ||
319 | } | 340 | } |
320 | 341 | ||
321 | /* support OTG systems */ | 342 | /* support OTG systems */ |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index b3f20d7f15de..a9707da7da0b 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -54,7 +54,7 @@ config USB_EHCI_HCD | |||
54 | 54 | ||
55 | config USB_EHCI_ROOT_HUB_TT | 55 | config USB_EHCI_ROOT_HUB_TT |
56 | bool "Root Hub Transaction Translators" | 56 | bool "Root Hub Transaction Translators" |
57 | depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST | 57 | depends on USB_EHCI_HCD |
58 | ---help--- | 58 | ---help--- |
59 | Some EHCI chips have vendor-specific extensions to integrate | 59 | Some EHCI chips have vendor-specific extensions to integrate |
60 | transaction translators, so that no OHCI or UHCI companion | 60 | transaction translators, so that no OHCI or UHCI companion |
@@ -66,7 +66,7 @@ config USB_EHCI_ROOT_HUB_TT | |||
66 | 66 | ||
67 | config USB_EHCI_TT_NEWSCHED | 67 | config USB_EHCI_TT_NEWSCHED |
68 | bool "Improved Transaction Translator scheduling" | 68 | bool "Improved Transaction Translator scheduling" |
69 | depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST | 69 | depends on USB_EHCI_HCD |
70 | default y | 70 | default y |
71 | ---help--- | 71 | ---help--- |
72 | This changes the periodic scheduling code to fill more of the low | 72 | This changes the periodic scheduling code to fill more of the low |
@@ -203,12 +203,11 @@ config USB_EHCI_SH | |||
203 | Enables support for the on-chip EHCI controller on the SuperH. | 203 | Enables support for the on-chip EHCI controller on the SuperH. |
204 | If you use the PCI EHCI controller, this option is not necessary. | 204 | If you use the PCI EHCI controller, this option is not necessary. |
205 | 205 | ||
206 | config USB_EHCI_S5P | 206 | config USB_EHCI_EXYNOS |
207 | tristate "EHCI support for Samsung S5P/EXYNOS SoC Series" | 207 | tristate "EHCI support for Samsung S5P/EXYNOS SoC Series" |
208 | depends on PLAT_S5P || ARCH_EXYNOS | 208 | depends on PLAT_S5P || ARCH_EXYNOS |
209 | help | 209 | help |
210 | Enable support for the Samsung S5Pxxxx and Exynos3/4/5 SOC's | 210 | Enable support for the Samsung Exynos SOC's on-chip EHCI controller. |
211 | on-chip EHCI controller. | ||
212 | 211 | ||
213 | config USB_EHCI_MV | 212 | config USB_EHCI_MV |
214 | bool "EHCI support for Marvell PXA/MMP USB controller" | 213 | bool "EHCI support for Marvell PXA/MMP USB controller" |
@@ -224,7 +223,7 @@ config USB_EHCI_MV | |||
224 | on-chip EHCI USB controller" for those. | 223 | on-chip EHCI USB controller" for those. |
225 | 224 | ||
226 | config USB_W90X900_EHCI | 225 | config USB_W90X900_EHCI |
227 | bool "W90X900(W90P910) EHCI support" | 226 | tristate "W90X900(W90P910) EHCI support" |
228 | depends on ARCH_W90X900 | 227 | depends on ARCH_W90X900 |
229 | ---help--- | 228 | ---help--- |
230 | Enables support for the W90X900 USB controller | 229 | Enables support for the W90X900 USB controller |
@@ -367,14 +366,54 @@ config USB_OHCI_HCD | |||
367 | if USB_OHCI_HCD | 366 | if USB_OHCI_HCD |
368 | 367 | ||
369 | config USB_OHCI_HCD_OMAP1 | 368 | config USB_OHCI_HCD_OMAP1 |
370 | bool "OHCI support for OMAP1/2 chips" | 369 | tristate "OHCI support for OMAP1/2 chips" |
371 | depends on ARCH_OMAP1 | 370 | depends on ARCH_OMAP1 |
372 | default y | 371 | default y |
373 | ---help--- | 372 | ---help--- |
374 | Enables support for the OHCI controller on OMAP1/2 chips. | 373 | Enables support for the OHCI controller on OMAP1/2 chips. |
375 | 374 | ||
375 | config USB_OHCI_HCD_SPEAR | ||
376 | tristate "Support for ST SPEAr on-chip OHCI USB controller" | ||
377 | depends on USB_OHCI_HCD && PLAT_SPEAR | ||
378 | default y | ||
379 | ---help--- | ||
380 | Enables support for the on-chip OHCI controller on | ||
381 | ST SPEAr chips. | ||
382 | |||
383 | config USB_OHCI_HCD_S3C2410 | ||
384 | tristate "OHCI support for Samsung S3C24xx/S3C64xx SoC series" | ||
385 | depends on USB_OHCI_HCD && (ARCH_S3C24XX || ARCH_S3C64XX) | ||
386 | default y | ||
387 | ---help--- | ||
388 | Enables support for the on-chip OHCI controller on | ||
389 | S3C24xx/S3C64xx chips. | ||
390 | |||
391 | config USB_OHCI_HCD_LPC32XX | ||
392 | tristate "Support for LPC on-chip OHCI USB controller" | ||
393 | depends on USB_OHCI_HCD && ARCH_LPC32XX | ||
394 | default y | ||
395 | ---help--- | ||
396 | Enables support for the on-chip OHCI controller on | ||
397 | NXP chips. | ||
398 | |||
399 | config USB_OHCI_HCD_PXA27X | ||
400 | tristate "Support for PXA27X/PXA3XX on-chip OHCI USB controller" | ||
401 | depends on USB_OHCI_HCD && (PXA27x || PXA3xx) | ||
402 | default y | ||
403 | ---help--- | ||
404 | Enables support for the on-chip OHCI controller on | ||
405 | PXA27x/PXA3xx chips. | ||
406 | |||
407 | config USB_OHCI_HCD_AT91 | ||
408 | tristate "Support for Atmel on-chip OHCI USB controller" | ||
409 | depends on USB_OHCI_HCD && ARCH_AT91 | ||
410 | default y | ||
411 | ---help--- | ||
412 | Enables support for the on-chip OHCI controller on | ||
413 | Atmel chips. | ||
414 | |||
376 | config USB_OHCI_HCD_OMAP3 | 415 | config USB_OHCI_HCD_OMAP3 |
377 | bool "OHCI support for OMAP3 and later chips" | 416 | tristate "OHCI support for OMAP3 and later chips" |
378 | depends on (ARCH_OMAP3 || ARCH_OMAP4) | 417 | depends on (ARCH_OMAP3 || ARCH_OMAP4) |
379 | default y | 418 | default y |
380 | ---help--- | 419 | ---help--- |
@@ -454,8 +493,8 @@ config USB_OHCI_SH | |||
454 | If you use the PCI OHCI controller, this option is not necessary. | 493 | If you use the PCI OHCI controller, this option is not necessary. |
455 | 494 | ||
456 | config USB_OHCI_EXYNOS | 495 | config USB_OHCI_EXYNOS |
457 | boolean "OHCI support for Samsung EXYNOS SoC Series" | 496 | tristate "OHCI support for Samsung S5P/EXYNOS SoC Series" |
458 | depends on ARCH_EXYNOS | 497 | depends on PLAT_S5P || ARCH_EXYNOS |
459 | help | 498 | help |
460 | Enable support for the Samsung Exynos SOC's on-chip OHCI controller. | 499 | Enable support for the Samsung Exynos SOC's on-chip OHCI controller. |
461 | 500 | ||
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 50b0041c09a9..01e879ef3654 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -34,10 +34,11 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o | |||
34 | obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o | 34 | obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o |
35 | obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o | 35 | obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o |
36 | obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o | 36 | obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o |
37 | obj-$(CONFIG_USB_EHCI_S5P) += ehci-s5p.o | 37 | obj-$(CONFIG_USB_EHCI_EXYNOS) += ehci-exynos.o |
38 | obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o | 38 | obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o |
39 | obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o | 39 | obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o |
40 | obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o | 40 | obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o |
41 | obj-$(CONFIG_USB_W90X900_EHCI) += ehci-w90x900.o | ||
41 | 42 | ||
42 | obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o | 43 | obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o |
43 | obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o | 44 | obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o |
@@ -46,6 +47,14 @@ obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o | |||
46 | obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o | 47 | obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o |
47 | obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o | 48 | obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o |
48 | obj-$(CONFIG_USB_OHCI_HCD_PLATFORM) += ohci-platform.o | 49 | obj-$(CONFIG_USB_OHCI_HCD_PLATFORM) += ohci-platform.o |
50 | obj-$(CONFIG_USB_OHCI_EXYNOS) += ohci-exynos.o | ||
51 | obj-$(CONFIG_USB_OHCI_HCD_OMAP1) += ohci-omap.o | ||
52 | obj-$(CONFIG_USB_OHCI_HCD_OMAP3) += ohci-omap3.o | ||
53 | obj-$(CONFIG_USB_OHCI_HCD_SPEAR) += ohci-spear.o | ||
54 | obj-$(CONFIG_USB_OHCI_HCD_AT91) += ohci-at91.o | ||
55 | obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o | ||
56 | obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o | ||
57 | obj-$(CONFIG_USB_OHCI_HCD_PXA27X) += ohci-pxa27x.o | ||
49 | 58 | ||
50 | obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o | 59 | obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o |
51 | obj-$(CONFIG_USB_FHCI_HCD) += fhci.o | 60 | obj-$(CONFIG_USB_FHCI_HCD) += fhci.o |
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c index 3b645ff46f7b..f417526fb1f4 100644 --- a/drivers/usb/host/ehci-atmel.c +++ b/drivers/usb/host/ehci-atmel.c | |||
@@ -30,13 +30,17 @@ static const char hcd_name[] = "ehci-atmel"; | |||
30 | static struct hc_driver __read_mostly ehci_atmel_hc_driver; | 30 | static struct hc_driver __read_mostly ehci_atmel_hc_driver; |
31 | 31 | ||
32 | /* interface and function clocks */ | 32 | /* interface and function clocks */ |
33 | static struct clk *iclk, *fclk; | 33 | static struct clk *iclk, *fclk, *uclk; |
34 | static int clocked; | 34 | static int clocked; |
35 | 35 | ||
36 | /*-------------------------------------------------------------------------*/ | 36 | /*-------------------------------------------------------------------------*/ |
37 | 37 | ||
38 | static void atmel_start_clock(void) | 38 | static void atmel_start_clock(void) |
39 | { | 39 | { |
40 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { | ||
41 | clk_set_rate(uclk, 48000000); | ||
42 | clk_prepare_enable(uclk); | ||
43 | } | ||
40 | clk_prepare_enable(iclk); | 44 | clk_prepare_enable(iclk); |
41 | clk_prepare_enable(fclk); | 45 | clk_prepare_enable(fclk); |
42 | clocked = 1; | 46 | clocked = 1; |
@@ -46,6 +50,8 @@ static void atmel_stop_clock(void) | |||
46 | { | 50 | { |
47 | clk_disable_unprepare(fclk); | 51 | clk_disable_unprepare(fclk); |
48 | clk_disable_unprepare(iclk); | 52 | clk_disable_unprepare(iclk); |
53 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
54 | clk_disable_unprepare(uclk); | ||
49 | clocked = 0; | 55 | clocked = 0; |
50 | } | 56 | } |
51 | 57 | ||
@@ -130,6 +136,14 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev) | |||
130 | retval = -ENOENT; | 136 | retval = -ENOENT; |
131 | goto fail_request_resource; | 137 | goto fail_request_resource; |
132 | } | 138 | } |
139 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { | ||
140 | uclk = devm_clk_get(&pdev->dev, "usb_clk"); | ||
141 | if (IS_ERR(uclk)) { | ||
142 | dev_err(&pdev->dev, "failed to get uclk\n"); | ||
143 | retval = PTR_ERR(uclk); | ||
144 | goto fail_request_resource; | ||
145 | } | ||
146 | } | ||
133 | 147 | ||
134 | ehci = hcd_to_ehci(hcd); | 148 | ehci = hcd_to_ehci(hcd); |
135 | /* registers start at offset 0x0 */ | 149 | /* registers start at offset 0x0 */ |
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index aa5b603f3933..4a9c2edbcb2b 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -334,6 +334,7 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { } | |||
334 | /* troubleshooting help: expose state in debugfs */ | 334 | /* troubleshooting help: expose state in debugfs */ |
335 | 335 | ||
336 | static int debug_async_open(struct inode *, struct file *); | 336 | static int debug_async_open(struct inode *, struct file *); |
337 | static int debug_bandwidth_open(struct inode *, struct file *); | ||
337 | static int debug_periodic_open(struct inode *, struct file *); | 338 | static int debug_periodic_open(struct inode *, struct file *); |
338 | static int debug_registers_open(struct inode *, struct file *); | 339 | static int debug_registers_open(struct inode *, struct file *); |
339 | 340 | ||
@@ -347,6 +348,13 @@ static const struct file_operations debug_async_fops = { | |||
347 | .release = debug_close, | 348 | .release = debug_close, |
348 | .llseek = default_llseek, | 349 | .llseek = default_llseek, |
349 | }; | 350 | }; |
351 | static const struct file_operations debug_bandwidth_fops = { | ||
352 | .owner = THIS_MODULE, | ||
353 | .open = debug_bandwidth_open, | ||
354 | .read = debug_output, | ||
355 | .release = debug_close, | ||
356 | .llseek = default_llseek, | ||
357 | }; | ||
350 | static const struct file_operations debug_periodic_fops = { | 358 | static const struct file_operations debug_periodic_fops = { |
351 | .owner = THIS_MODULE, | 359 | .owner = THIS_MODULE, |
352 | .open = debug_periodic_open, | 360 | .open = debug_periodic_open, |
@@ -379,7 +387,7 @@ struct debug_buffer { | |||
379 | case QH_LOW_SPEED: tmp = 'l'; break; \ | 387 | case QH_LOW_SPEED: tmp = 'l'; break; \ |
380 | case QH_HIGH_SPEED: tmp = 'h'; break; \ | 388 | case QH_HIGH_SPEED: tmp = 'h'; break; \ |
381 | default: tmp = '?'; break; \ | 389 | default: tmp = '?'; break; \ |
382 | }; tmp; }) | 390 | } tmp; }) |
383 | 391 | ||
384 | static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) | 392 | static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) |
385 | { | 393 | { |
@@ -525,6 +533,89 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf) | |||
525 | return strlen(buf->output_buf); | 533 | return strlen(buf->output_buf); |
526 | } | 534 | } |
527 | 535 | ||
536 | static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf) | ||
537 | { | ||
538 | struct ehci_hcd *ehci; | ||
539 | struct ehci_tt *tt; | ||
540 | struct ehci_per_sched *ps; | ||
541 | unsigned temp, size; | ||
542 | char *next; | ||
543 | unsigned i; | ||
544 | u8 *bw; | ||
545 | u16 *bf; | ||
546 | u8 budget[EHCI_BANDWIDTH_SIZE]; | ||
547 | |||
548 | ehci = hcd_to_ehci(bus_to_hcd(buf->bus)); | ||
549 | next = buf->output_buf; | ||
550 | size = buf->alloc_size; | ||
551 | |||
552 | *next = 0; | ||
553 | |||
554 | spin_lock_irq(&ehci->lock); | ||
555 | |||
556 | /* Dump the HS bandwidth table */ | ||
557 | temp = scnprintf(next, size, | ||
558 | "HS bandwidth allocation (us per microframe)\n"); | ||
559 | size -= temp; | ||
560 | next += temp; | ||
561 | for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) { | ||
562 | bw = &ehci->bandwidth[i]; | ||
563 | temp = scnprintf(next, size, | ||
564 | "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n", | ||
565 | i, bw[0], bw[1], bw[2], bw[3], | ||
566 | bw[4], bw[5], bw[6], bw[7]); | ||
567 | size -= temp; | ||
568 | next += temp; | ||
569 | } | ||
570 | |||
571 | /* Dump all the FS/LS tables */ | ||
572 | list_for_each_entry(tt, &ehci->tt_list, tt_list) { | ||
573 | temp = scnprintf(next, size, | ||
574 | "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n", | ||
575 | dev_name(&tt->usb_tt->hub->dev), | ||
576 | tt->tt_port + !!tt->usb_tt->multi); | ||
577 | size -= temp; | ||
578 | next += temp; | ||
579 | |||
580 | bf = tt->bandwidth; | ||
581 | temp = scnprintf(next, size, | ||
582 | " %5u%5u%5u%5u%5u%5u%5u%5u\n", | ||
583 | bf[0], bf[1], bf[2], bf[3], | ||
584 | bf[4], bf[5], bf[6], bf[7]); | ||
585 | size -= temp; | ||
586 | next += temp; | ||
587 | |||
588 | temp = scnprintf(next, size, | ||
589 | "FS/LS budget (us per microframe)\n"); | ||
590 | size -= temp; | ||
591 | next += temp; | ||
592 | compute_tt_budget(budget, tt); | ||
593 | for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) { | ||
594 | bw = &budget[i]; | ||
595 | temp = scnprintf(next, size, | ||
596 | "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n", | ||
597 | i, bw[0], bw[1], bw[2], bw[3], | ||
598 | bw[4], bw[5], bw[6], bw[7]); | ||
599 | size -= temp; | ||
600 | next += temp; | ||
601 | } | ||
602 | list_for_each_entry(ps, &tt->ps_list, ps_list) { | ||
603 | temp = scnprintf(next, size, | ||
604 | "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n", | ||
605 | dev_name(&ps->udev->dev), | ||
606 | ps->ep->desc.bEndpointAddress, | ||
607 | ps->tt_usecs, | ||
608 | ps->bw_phase, ps->phase_uf, | ||
609 | ps->bw_period, ps->cs_mask); | ||
610 | size -= temp; | ||
611 | next += temp; | ||
612 | } | ||
613 | } | ||
614 | spin_unlock_irq(&ehci->lock); | ||
615 | |||
616 | return next - buf->output_buf; | ||
617 | } | ||
618 | |||
528 | #define DBG_SCHED_LIMIT 64 | 619 | #define DBG_SCHED_LIMIT 64 |
529 | static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | 620 | static ssize_t fill_periodic_buffer(struct debug_buffer *buf) |
530 | { | 621 | { |
@@ -571,7 +662,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
571 | case Q_TYPE_QH: | 662 | case Q_TYPE_QH: |
572 | hw = p.qh->hw; | 663 | hw = p.qh->hw; |
573 | temp = scnprintf (next, size, " qh%d-%04x/%p", | 664 | temp = scnprintf (next, size, " qh%d-%04x/%p", |
574 | p.qh->period, | 665 | p.qh->ps.period, |
575 | hc32_to_cpup(ehci, | 666 | hc32_to_cpup(ehci, |
576 | &hw->hw_info2) | 667 | &hw->hw_info2) |
577 | /* uframe masks */ | 668 | /* uframe masks */ |
@@ -618,7 +709,8 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
618 | speed_char (scratch), | 709 | speed_char (scratch), |
619 | scratch & 0x007f, | 710 | scratch & 0x007f, |
620 | (scratch >> 8) & 0x000f, type, | 711 | (scratch >> 8) & 0x000f, type, |
621 | p.qh->usecs, p.qh->c_usecs, | 712 | p.qh->ps.usecs, |
713 | p.qh->ps.c_usecs, | ||
622 | temp, | 714 | temp, |
623 | 0x7ff & (scratch >> 16)); | 715 | 0x7ff & (scratch >> 16)); |
624 | 716 | ||
@@ -645,7 +737,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
645 | case Q_TYPE_SITD: | 737 | case Q_TYPE_SITD: |
646 | temp = scnprintf (next, size, | 738 | temp = scnprintf (next, size, |
647 | " sitd%d-%04x/%p", | 739 | " sitd%d-%04x/%p", |
648 | p.sitd->stream->interval, | 740 | p.sitd->stream->ps.period, |
649 | hc32_to_cpup(ehci, &p.sitd->hw_uframe) | 741 | hc32_to_cpup(ehci, &p.sitd->hw_uframe) |
650 | & 0x0000ffff, | 742 | & 0x0000ffff, |
651 | p.sitd); | 743 | p.sitd); |
@@ -918,6 +1010,7 @@ static int debug_close(struct inode *inode, struct file *file) | |||
918 | 1010 | ||
919 | return 0; | 1011 | return 0; |
920 | } | 1012 | } |
1013 | |||
921 | static int debug_async_open(struct inode *inode, struct file *file) | 1014 | static int debug_async_open(struct inode *inode, struct file *file) |
922 | { | 1015 | { |
923 | file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); | 1016 | file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); |
@@ -925,6 +1018,14 @@ static int debug_async_open(struct inode *inode, struct file *file) | |||
925 | return file->private_data ? 0 : -ENOMEM; | 1018 | return file->private_data ? 0 : -ENOMEM; |
926 | } | 1019 | } |
927 | 1020 | ||
1021 | static int debug_bandwidth_open(struct inode *inode, struct file *file) | ||
1022 | { | ||
1023 | file->private_data = alloc_buffer(inode->i_private, | ||
1024 | fill_bandwidth_buffer); | ||
1025 | |||
1026 | return file->private_data ? 0 : -ENOMEM; | ||
1027 | } | ||
1028 | |||
928 | static int debug_periodic_open(struct inode *inode, struct file *file) | 1029 | static int debug_periodic_open(struct inode *inode, struct file *file) |
929 | { | 1030 | { |
930 | struct debug_buffer *buf; | 1031 | struct debug_buffer *buf; |
@@ -957,6 +1058,10 @@ static inline void create_debug_files (struct ehci_hcd *ehci) | |||
957 | &debug_async_fops)) | 1058 | &debug_async_fops)) |
958 | goto file_error; | 1059 | goto file_error; |
959 | 1060 | ||
1061 | if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus, | ||
1062 | &debug_bandwidth_fops)) | ||
1063 | goto file_error; | ||
1064 | |||
960 | if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, | 1065 | if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, |
961 | &debug_periodic_fops)) | 1066 | &debug_periodic_fops)) |
962 | goto file_error; | 1067 | goto file_error; |
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-exynos.c index 7c3de95c7054..016352e0f5a7 100644 --- a/drivers/usb/host/ehci-s5p.c +++ b/drivers/usb/host/ehci-exynos.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SAMSUNG S5P USB HOST EHCI Controller | 2 | * SAMSUNG EXYNOS USB HOST EHCI Controller |
3 | * | 3 | * |
4 | * Copyright (C) 2011 Samsung Electronics Co.Ltd | 4 | * Copyright (C) 2011 Samsung Electronics Co.Ltd |
5 | * Author: Jingoo Han <jg1.han@samsung.com> | 5 | * Author: Jingoo Han <jg1.han@samsung.com> |
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/of.h> | 20 | #include <linux/of.h> |
21 | #include <linux/of_gpio.h> | 21 | #include <linux/of_gpio.h> |
22 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
23 | #include <linux/platform_data/usb-ehci-s5p.h> | ||
24 | #include <linux/usb/phy.h> | 23 | #include <linux/usb/phy.h> |
25 | #include <linux/usb/samsung_usb_phy.h> | 24 | #include <linux/usb/samsung_usb_phy.h> |
26 | #include <linux/usb.h> | 25 | #include <linux/usb.h> |
@@ -29,7 +28,7 @@ | |||
29 | 28 | ||
30 | #include "ehci.h" | 29 | #include "ehci.h" |
31 | 30 | ||
32 | #define DRIVER_DESC "EHCI s5p driver" | 31 | #define DRIVER_DESC "EHCI EXYNOS driver" |
33 | 32 | ||
34 | #define EHCI_INSNREG00(base) (base + 0x90) | 33 | #define EHCI_INSNREG00(base) (base + 0x90) |
35 | #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) | 34 | #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) |
@@ -40,21 +39,18 @@ | |||
40 | (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ | 39 | (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ |
41 | EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) | 40 | EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) |
42 | 41 | ||
43 | static const char hcd_name[] = "ehci-s5p"; | 42 | static const char hcd_name[] = "ehci-exynos"; |
44 | static struct hc_driver __read_mostly s5p_ehci_hc_driver; | 43 | static struct hc_driver __read_mostly exynos_ehci_hc_driver; |
45 | 44 | ||
46 | struct s5p_ehci_hcd { | 45 | struct exynos_ehci_hcd { |
47 | struct clk *clk; | 46 | struct clk *clk; |
48 | struct usb_phy *phy; | 47 | struct usb_phy *phy; |
49 | struct usb_otg *otg; | 48 | struct usb_otg *otg; |
50 | struct s5p_ehci_platdata *pdata; | ||
51 | }; | 49 | }; |
52 | 50 | ||
53 | static struct s5p_ehci_platdata empty_platdata; | 51 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) |
54 | 52 | ||
55 | #define to_s5p_ehci(hcd) (struct s5p_ehci_hcd *)(hcd_to_ehci(hcd)->priv) | 53 | static void exynos_setup_vbus_gpio(struct platform_device *pdev) |
56 | |||
57 | static void s5p_setup_vbus_gpio(struct platform_device *pdev) | ||
58 | { | 54 | { |
59 | struct device *dev = &pdev->dev; | 55 | struct device *dev = &pdev->dev; |
60 | int err; | 56 | int err; |
@@ -73,10 +69,9 @@ static void s5p_setup_vbus_gpio(struct platform_device *pdev) | |||
73 | dev_err(dev, "can't request ehci vbus gpio %d", gpio); | 69 | dev_err(dev, "can't request ehci vbus gpio %d", gpio); |
74 | } | 70 | } |
75 | 71 | ||
76 | static int s5p_ehci_probe(struct platform_device *pdev) | 72 | static int exynos_ehci_probe(struct platform_device *pdev) |
77 | { | 73 | { |
78 | struct s5p_ehci_platdata *pdata = dev_get_platdata(&pdev->dev); | 74 | struct exynos_ehci_hcd *exynos_ehci; |
79 | struct s5p_ehci_hcd *s5p_ehci; | ||
80 | struct usb_hcd *hcd; | 75 | struct usb_hcd *hcd; |
81 | struct ehci_hcd *ehci; | 76 | struct ehci_hcd *ehci; |
82 | struct resource *res; | 77 | struct resource *res; |
@@ -94,48 +89,41 @@ static int s5p_ehci_probe(struct platform_device *pdev) | |||
94 | if (!pdev->dev.coherent_dma_mask) | 89 | if (!pdev->dev.coherent_dma_mask) |
95 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); | 90 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
96 | 91 | ||
97 | s5p_setup_vbus_gpio(pdev); | 92 | exynos_setup_vbus_gpio(pdev); |
98 | 93 | ||
99 | hcd = usb_create_hcd(&s5p_ehci_hc_driver, | 94 | hcd = usb_create_hcd(&exynos_ehci_hc_driver, |
100 | &pdev->dev, dev_name(&pdev->dev)); | 95 | &pdev->dev, dev_name(&pdev->dev)); |
101 | if (!hcd) { | 96 | if (!hcd) { |
102 | dev_err(&pdev->dev, "Unable to create HCD\n"); | 97 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
103 | return -ENOMEM; | 98 | return -ENOMEM; |
104 | } | 99 | } |
105 | s5p_ehci = to_s5p_ehci(hcd); | 100 | exynos_ehci = to_exynos_ehci(hcd); |
106 | 101 | ||
107 | if (of_device_is_compatible(pdev->dev.of_node, | 102 | if (of_device_is_compatible(pdev->dev.of_node, |
108 | "samsung,exynos5440-ehci")) { | 103 | "samsung,exynos5440-ehci")) |
109 | s5p_ehci->pdata = &empty_platdata; | ||
110 | goto skip_phy; | 104 | goto skip_phy; |
111 | } | ||
112 | 105 | ||
113 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 106 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
114 | if (IS_ERR(phy)) { | 107 | if (IS_ERR(phy)) { |
115 | /* Fallback to pdata */ | 108 | usb_put_hcd(hcd); |
116 | if (!pdata) { | 109 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); |
117 | usb_put_hcd(hcd); | 110 | return -EPROBE_DEFER; |
118 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | ||
119 | return -EPROBE_DEFER; | ||
120 | } else { | ||
121 | s5p_ehci->pdata = pdata; | ||
122 | } | ||
123 | } else { | 111 | } else { |
124 | s5p_ehci->phy = phy; | 112 | exynos_ehci->phy = phy; |
125 | s5p_ehci->otg = phy->otg; | 113 | exynos_ehci->otg = phy->otg; |
126 | } | 114 | } |
127 | 115 | ||
128 | skip_phy: | 116 | skip_phy: |
129 | 117 | ||
130 | s5p_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); | 118 | exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); |
131 | 119 | ||
132 | if (IS_ERR(s5p_ehci->clk)) { | 120 | if (IS_ERR(exynos_ehci->clk)) { |
133 | dev_err(&pdev->dev, "Failed to get usbhost clock\n"); | 121 | dev_err(&pdev->dev, "Failed to get usbhost clock\n"); |
134 | err = PTR_ERR(s5p_ehci->clk); | 122 | err = PTR_ERR(exynos_ehci->clk); |
135 | goto fail_clk; | 123 | goto fail_clk; |
136 | } | 124 | } |
137 | 125 | ||
138 | err = clk_prepare_enable(s5p_ehci->clk); | 126 | err = clk_prepare_enable(exynos_ehci->clk); |
139 | if (err) | 127 | if (err) |
140 | goto fail_clk; | 128 | goto fail_clk; |
141 | 129 | ||
@@ -162,13 +150,11 @@ skip_phy: | |||
162 | goto fail_io; | 150 | goto fail_io; |
163 | } | 151 | } |
164 | 152 | ||
165 | if (s5p_ehci->otg) | 153 | if (exynos_ehci->otg) |
166 | s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); | 154 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
167 | 155 | ||
168 | if (s5p_ehci->phy) | 156 | if (exynos_ehci->phy) |
169 | usb_phy_init(s5p_ehci->phy); | 157 | usb_phy_init(exynos_ehci->phy); |
170 | else if (s5p_ehci->pdata->phy_init) | ||
171 | s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); | ||
172 | 158 | ||
173 | ehci = hcd_to_ehci(hcd); | 159 | ehci = hcd_to_ehci(hcd); |
174 | ehci->caps = hcd->regs; | 160 | ehci->caps = hcd->regs; |
@@ -187,33 +173,29 @@ skip_phy: | |||
187 | return 0; | 173 | return 0; |
188 | 174 | ||
189 | fail_add_hcd: | 175 | fail_add_hcd: |
190 | if (s5p_ehci->phy) | 176 | if (exynos_ehci->phy) |
191 | usb_phy_shutdown(s5p_ehci->phy); | 177 | usb_phy_shutdown(exynos_ehci->phy); |
192 | else if (s5p_ehci->pdata->phy_exit) | ||
193 | s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); | ||
194 | fail_io: | 178 | fail_io: |
195 | clk_disable_unprepare(s5p_ehci->clk); | 179 | clk_disable_unprepare(exynos_ehci->clk); |
196 | fail_clk: | 180 | fail_clk: |
197 | usb_put_hcd(hcd); | 181 | usb_put_hcd(hcd); |
198 | return err; | 182 | return err; |
199 | } | 183 | } |
200 | 184 | ||
201 | static int s5p_ehci_remove(struct platform_device *pdev) | 185 | static int exynos_ehci_remove(struct platform_device *pdev) |
202 | { | 186 | { |
203 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 187 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
204 | struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); | 188 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
205 | 189 | ||
206 | usb_remove_hcd(hcd); | 190 | usb_remove_hcd(hcd); |
207 | 191 | ||
208 | if (s5p_ehci->otg) | 192 | if (exynos_ehci->otg) |
209 | s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); | 193 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
210 | 194 | ||
211 | if (s5p_ehci->phy) | 195 | if (exynos_ehci->phy) |
212 | usb_phy_shutdown(s5p_ehci->phy); | 196 | usb_phy_shutdown(exynos_ehci->phy); |
213 | else if (s5p_ehci->pdata->phy_exit) | ||
214 | s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); | ||
215 | 197 | ||
216 | clk_disable_unprepare(s5p_ehci->clk); | 198 | clk_disable_unprepare(exynos_ehci->clk); |
217 | 199 | ||
218 | usb_put_hcd(hcd); | 200 | usb_put_hcd(hcd); |
219 | 201 | ||
@@ -221,45 +203,39 @@ static int s5p_ehci_remove(struct platform_device *pdev) | |||
221 | } | 203 | } |
222 | 204 | ||
223 | #ifdef CONFIG_PM | 205 | #ifdef CONFIG_PM |
224 | static int s5p_ehci_suspend(struct device *dev) | 206 | static int exynos_ehci_suspend(struct device *dev) |
225 | { | 207 | { |
226 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 208 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
227 | struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); | 209 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
228 | struct platform_device *pdev = to_platform_device(dev); | ||
229 | 210 | ||
230 | bool do_wakeup = device_may_wakeup(dev); | 211 | bool do_wakeup = device_may_wakeup(dev); |
231 | int rc; | 212 | int rc; |
232 | 213 | ||
233 | rc = ehci_suspend(hcd, do_wakeup); | 214 | rc = ehci_suspend(hcd, do_wakeup); |
234 | 215 | ||
235 | if (s5p_ehci->otg) | 216 | if (exynos_ehci->otg) |
236 | s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); | 217 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
237 | 218 | ||
238 | if (s5p_ehci->phy) | 219 | if (exynos_ehci->phy) |
239 | usb_phy_shutdown(s5p_ehci->phy); | 220 | usb_phy_shutdown(exynos_ehci->phy); |
240 | else if (s5p_ehci->pdata->phy_exit) | ||
241 | s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); | ||
242 | 221 | ||
243 | clk_disable_unprepare(s5p_ehci->clk); | 222 | clk_disable_unprepare(exynos_ehci->clk); |
244 | 223 | ||
245 | return rc; | 224 | return rc; |
246 | } | 225 | } |
247 | 226 | ||
248 | static int s5p_ehci_resume(struct device *dev) | 227 | static int exynos_ehci_resume(struct device *dev) |
249 | { | 228 | { |
250 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 229 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
251 | struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); | 230 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
252 | struct platform_device *pdev = to_platform_device(dev); | ||
253 | 231 | ||
254 | clk_prepare_enable(s5p_ehci->clk); | 232 | clk_prepare_enable(exynos_ehci->clk); |
255 | 233 | ||
256 | if (s5p_ehci->otg) | 234 | if (exynos_ehci->otg) |
257 | s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); | 235 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
258 | 236 | ||
259 | if (s5p_ehci->phy) | 237 | if (exynos_ehci->phy) |
260 | usb_phy_init(s5p_ehci->phy); | 238 | usb_phy_init(exynos_ehci->phy); |
261 | else if (s5p_ehci->pdata->phy_init) | ||
262 | s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); | ||
263 | 239 | ||
264 | /* DMA burst Enable */ | 240 | /* DMA burst Enable */ |
265 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); | 241 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); |
@@ -268,13 +244,13 @@ static int s5p_ehci_resume(struct device *dev) | |||
268 | return 0; | 244 | return 0; |
269 | } | 245 | } |
270 | #else | 246 | #else |
271 | #define s5p_ehci_suspend NULL | 247 | #define exynos_ehci_suspend NULL |
272 | #define s5p_ehci_resume NULL | 248 | #define exynos_ehci_resume NULL |
273 | #endif | 249 | #endif |
274 | 250 | ||
275 | static const struct dev_pm_ops s5p_ehci_pm_ops = { | 251 | static const struct dev_pm_ops exynos_ehci_pm_ops = { |
276 | .suspend = s5p_ehci_suspend, | 252 | .suspend = exynos_ehci_suspend, |
277 | .resume = s5p_ehci_resume, | 253 | .resume = exynos_ehci_resume, |
278 | }; | 254 | }; |
279 | 255 | ||
280 | #ifdef CONFIG_OF | 256 | #ifdef CONFIG_OF |
@@ -286,40 +262,40 @@ static const struct of_device_id exynos_ehci_match[] = { | |||
286 | MODULE_DEVICE_TABLE(of, exynos_ehci_match); | 262 | MODULE_DEVICE_TABLE(of, exynos_ehci_match); |
287 | #endif | 263 | #endif |
288 | 264 | ||
289 | static struct platform_driver s5p_ehci_driver = { | 265 | static struct platform_driver exynos_ehci_driver = { |
290 | .probe = s5p_ehci_probe, | 266 | .probe = exynos_ehci_probe, |
291 | .remove = s5p_ehci_remove, | 267 | .remove = exynos_ehci_remove, |
292 | .shutdown = usb_hcd_platform_shutdown, | 268 | .shutdown = usb_hcd_platform_shutdown, |
293 | .driver = { | 269 | .driver = { |
294 | .name = "s5p-ehci", | 270 | .name = "exynos-ehci", |
295 | .owner = THIS_MODULE, | 271 | .owner = THIS_MODULE, |
296 | .pm = &s5p_ehci_pm_ops, | 272 | .pm = &exynos_ehci_pm_ops, |
297 | .of_match_table = of_match_ptr(exynos_ehci_match), | 273 | .of_match_table = of_match_ptr(exynos_ehci_match), |
298 | } | 274 | } |
299 | }; | 275 | }; |
300 | static const struct ehci_driver_overrides s5p_overrides __initdata = { | 276 | static const struct ehci_driver_overrides exynos_overrides __initdata = { |
301 | .extra_priv_size = sizeof(struct s5p_ehci_hcd), | 277 | .extra_priv_size = sizeof(struct exynos_ehci_hcd), |
302 | }; | 278 | }; |
303 | 279 | ||
304 | static int __init ehci_s5p_init(void) | 280 | static int __init ehci_exynos_init(void) |
305 | { | 281 | { |
306 | if (usb_disabled()) | 282 | if (usb_disabled()) |
307 | return -ENODEV; | 283 | return -ENODEV; |
308 | 284 | ||
309 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | 285 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
310 | ehci_init_driver(&s5p_ehci_hc_driver, &s5p_overrides); | 286 | ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides); |
311 | return platform_driver_register(&s5p_ehci_driver); | 287 | return platform_driver_register(&exynos_ehci_driver); |
312 | } | 288 | } |
313 | module_init(ehci_s5p_init); | 289 | module_init(ehci_exynos_init); |
314 | 290 | ||
315 | static void __exit ehci_s5p_cleanup(void) | 291 | static void __exit ehci_exynos_cleanup(void) |
316 | { | 292 | { |
317 | platform_driver_unregister(&s5p_ehci_driver); | 293 | platform_driver_unregister(&exynos_ehci_driver); |
318 | } | 294 | } |
319 | module_exit(ehci_s5p_cleanup); | 295 | module_exit(ehci_exynos_cleanup); |
320 | 296 | ||
321 | MODULE_DESCRIPTION(DRIVER_DESC); | 297 | MODULE_DESCRIPTION(DRIVER_DESC); |
322 | MODULE_ALIAS("platform:s5p-ehci"); | 298 | MODULE_ALIAS("platform:exynos-ehci"); |
323 | MODULE_AUTHOR("Jingoo Han"); | 299 | MODULE_AUTHOR("Jingoo Han"); |
324 | MODULE_AUTHOR("Joonyoung Shim"); | 300 | MODULE_AUTHOR("Joonyoung Shim"); |
325 | MODULE_LICENSE("GPL v2"); | 301 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index f2407b2e8a99..a06d5012201f 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c | |||
@@ -57,7 +57,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
57 | pr_debug("initializing FSL-SOC USB Controller\n"); | 57 | pr_debug("initializing FSL-SOC USB Controller\n"); |
58 | 58 | ||
59 | /* Need platform data for setup */ | 59 | /* Need platform data for setup */ |
60 | pdata = (struct fsl_usb2_platform_data *)dev_get_platdata(&pdev->dev); | 60 | pdata = dev_get_platdata(&pdev->dev); |
61 | if (!pdata) { | 61 | if (!pdata) { |
62 | dev_err(&pdev->dev, | 62 | dev_err(&pdev->dev, |
63 | "No platform data for %s.\n", dev_name(&pdev->dev)); | 63 | "No platform data for %s.\n", dev_name(&pdev->dev)); |
@@ -664,7 +664,7 @@ static const struct hc_driver ehci_fsl_hc_driver = { | |||
664 | * generic hardware linkage | 664 | * generic hardware linkage |
665 | */ | 665 | */ |
666 | .irq = ehci_irq, | 666 | .irq = ehci_irq, |
667 | .flags = HCD_USB2 | HCD_MEMORY, | 667 | .flags = HCD_USB2 | HCD_MEMORY | HCD_BH, |
668 | 668 | ||
669 | /* | 669 | /* |
670 | * basic lifecycle operations | 670 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c index 83ab51af250f..b52a66ce92e8 100644 --- a/drivers/usb/host/ehci-grlib.c +++ b/drivers/usb/host/ehci-grlib.c | |||
@@ -43,7 +43,7 @@ static const struct hc_driver ehci_grlib_hc_driver = { | |||
43 | * generic hardware linkage | 43 | * generic hardware linkage |
44 | */ | 44 | */ |
45 | .irq = ehci_irq, | 45 | .irq = ehci_irq, |
46 | .flags = HCD_MEMORY | HCD_USB2, | 46 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
47 | 47 | ||
48 | /* | 48 | /* |
49 | * basic lifecycle operations | 49 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 86ab9fd9fe9e..e8ba4c44223a 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -110,6 +110,9 @@ MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); | |||
110 | #include "ehci.h" | 110 | #include "ehci.h" |
111 | #include "pci-quirks.h" | 111 | #include "pci-quirks.h" |
112 | 112 | ||
113 | static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE], | ||
114 | struct ehci_tt *tt); | ||
115 | |||
113 | /* | 116 | /* |
114 | * The MosChip MCS9990 controller updates its microframe counter | 117 | * The MosChip MCS9990 controller updates its microframe counter |
115 | * a little before the frame counter, and occasionally we will read | 118 | * a little before the frame counter, and occasionally we will read |
@@ -484,6 +487,7 @@ static int ehci_init(struct usb_hcd *hcd) | |||
484 | INIT_LIST_HEAD(&ehci->intr_qh_list); | 487 | INIT_LIST_HEAD(&ehci->intr_qh_list); |
485 | INIT_LIST_HEAD(&ehci->cached_itd_list); | 488 | INIT_LIST_HEAD(&ehci->cached_itd_list); |
486 | INIT_LIST_HEAD(&ehci->cached_sitd_list); | 489 | INIT_LIST_HEAD(&ehci->cached_sitd_list); |
490 | INIT_LIST_HEAD(&ehci->tt_list); | ||
487 | 491 | ||
488 | if (HCC_PGM_FRAMELISTLEN(hcc_params)) { | 492 | if (HCC_PGM_FRAMELISTLEN(hcc_params)) { |
489 | /* periodic schedule size can be smaller than default */ | 493 | /* periodic schedule size can be smaller than default */ |
@@ -956,6 +960,7 @@ rescan: | |||
956 | goto idle_timeout; | 960 | goto idle_timeout; |
957 | 961 | ||
958 | /* BUG_ON(!list_empty(&stream->free_list)); */ | 962 | /* BUG_ON(!list_empty(&stream->free_list)); */ |
963 | reserve_release_iso_bandwidth(ehci, stream, -1); | ||
959 | kfree(stream); | 964 | kfree(stream); |
960 | goto done; | 965 | goto done; |
961 | } | 966 | } |
@@ -982,6 +987,8 @@ idle_timeout: | |||
982 | if (qh->clearing_tt) | 987 | if (qh->clearing_tt) |
983 | goto idle_timeout; | 988 | goto idle_timeout; |
984 | if (list_empty (&qh->qtd_list)) { | 989 | if (list_empty (&qh->qtd_list)) { |
990 | if (qh->ps.bw_uperiod) | ||
991 | reserve_release_intr_bandwidth(ehci, qh, -1); | ||
985 | qh_destroy(ehci, qh); | 992 | qh_destroy(ehci, qh); |
986 | break; | 993 | break; |
987 | } | 994 | } |
@@ -1022,7 +1029,6 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) | |||
1022 | * the toggle bit in the QH. | 1029 | * the toggle bit in the QH. |
1023 | */ | 1030 | */ |
1024 | if (qh) { | 1031 | if (qh) { |
1025 | usb_settoggle(qh->dev, epnum, is_out, 0); | ||
1026 | if (!list_empty(&qh->qtd_list)) { | 1032 | if (!list_empty(&qh->qtd_list)) { |
1027 | WARN_ONCE(1, "clear_halt for a busy endpoint\n"); | 1033 | WARN_ONCE(1, "clear_halt for a busy endpoint\n"); |
1028 | } else { | 1034 | } else { |
@@ -1030,6 +1036,7 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) | |||
1030 | * while the QH is active. Unlink it now; | 1036 | * while the QH is active. Unlink it now; |
1031 | * re-linking will call qh_refresh(). | 1037 | * re-linking will call qh_refresh(). |
1032 | */ | 1038 | */ |
1039 | usb_settoggle(qh->ps.udev, epnum, is_out, 0); | ||
1033 | qh->exception = 1; | 1040 | qh->exception = 1; |
1034 | if (eptype == USB_ENDPOINT_XFER_BULK) | 1041 | if (eptype == USB_ENDPOINT_XFER_BULK) |
1035 | start_unlink_async(ehci, qh); | 1042 | start_unlink_async(ehci, qh); |
@@ -1048,6 +1055,19 @@ static int ehci_get_frame (struct usb_hcd *hcd) | |||
1048 | 1055 | ||
1049 | /*-------------------------------------------------------------------------*/ | 1056 | /*-------------------------------------------------------------------------*/ |
1050 | 1057 | ||
1058 | /* Device addition and removal */ | ||
1059 | |||
1060 | static void ehci_remove_device(struct usb_hcd *hcd, struct usb_device *udev) | ||
1061 | { | ||
1062 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
1063 | |||
1064 | spin_lock_irq(&ehci->lock); | ||
1065 | drop_tt(udev); | ||
1066 | spin_unlock_irq(&ehci->lock); | ||
1067 | } | ||
1068 | |||
1069 | /*-------------------------------------------------------------------------*/ | ||
1070 | |||
1051 | #ifdef CONFIG_PM | 1071 | #ifdef CONFIG_PM |
1052 | 1072 | ||
1053 | /* suspend/resume, section 4.3 */ | 1073 | /* suspend/resume, section 4.3 */ |
@@ -1075,6 +1095,14 @@ int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
1075 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 1095 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
1076 | spin_unlock_irq(&ehci->lock); | 1096 | spin_unlock_irq(&ehci->lock); |
1077 | 1097 | ||
1098 | synchronize_irq(hcd->irq); | ||
1099 | |||
1100 | /* Check for race with a wakeup request */ | ||
1101 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) { | ||
1102 | ehci_resume(hcd, false); | ||
1103 | return -EBUSY; | ||
1104 | } | ||
1105 | |||
1078 | return 0; | 1106 | return 0; |
1079 | } | 1107 | } |
1080 | EXPORT_SYMBOL_GPL(ehci_suspend); | 1108 | EXPORT_SYMBOL_GPL(ehci_suspend); |
@@ -1158,7 +1186,7 @@ static const struct hc_driver ehci_hc_driver = { | |||
1158 | * generic hardware linkage | 1186 | * generic hardware linkage |
1159 | */ | 1187 | */ |
1160 | .irq = ehci_irq, | 1188 | .irq = ehci_irq, |
1161 | .flags = HCD_MEMORY | HCD_USB2, | 1189 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
1162 | 1190 | ||
1163 | /* | 1191 | /* |
1164 | * basic lifecycle operations | 1192 | * basic lifecycle operations |
@@ -1191,6 +1219,11 @@ static const struct hc_driver ehci_hc_driver = { | |||
1191 | .bus_resume = ehci_bus_resume, | 1219 | .bus_resume = ehci_bus_resume, |
1192 | .relinquish_port = ehci_relinquish_port, | 1220 | .relinquish_port = ehci_relinquish_port, |
1193 | .port_handed_over = ehci_port_handed_over, | 1221 | .port_handed_over = ehci_port_handed_over, |
1222 | |||
1223 | /* | ||
1224 | * device support | ||
1225 | */ | ||
1226 | .free_dev = ehci_remove_device, | ||
1194 | }; | 1227 | }; |
1195 | 1228 | ||
1196 | void ehci_init_driver(struct hc_driver *drv, | 1229 | void ehci_init_driver(struct hc_driver *drv, |
@@ -1238,11 +1271,6 @@ MODULE_LICENSE ("GPL"); | |||
1238 | #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver | 1271 | #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver |
1239 | #endif | 1272 | #endif |
1240 | 1273 | ||
1241 | #ifdef CONFIG_USB_W90X900_EHCI | ||
1242 | #include "ehci-w90x900.c" | ||
1243 | #define PLATFORM_DRIVER ehci_hcd_w90x900_driver | ||
1244 | #endif | ||
1245 | |||
1246 | #ifdef CONFIG_USB_OCTEON_EHCI | 1274 | #ifdef CONFIG_USB_OCTEON_EHCI |
1247 | #include "ehci-octeon.c" | 1275 | #include "ehci-octeon.c" |
1248 | #define PLATFORM_DRIVER ehci_octeon_driver | 1276 | #define PLATFORM_DRIVER ehci_octeon_driver |
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c index 52a77734a225..c0fb6a8ae6a3 100644 --- a/drivers/usb/host/ehci-mem.c +++ b/drivers/usb/host/ehci-mem.c | |||
@@ -224,11 +224,11 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags) | |||
224 | hw->hw_next = EHCI_LIST_END(ehci); | 224 | hw->hw_next = EHCI_LIST_END(ehci); |
225 | hw->hw_qtd_next = EHCI_LIST_END(ehci); | 225 | hw->hw_qtd_next = EHCI_LIST_END(ehci); |
226 | hw->hw_alt_next = EHCI_LIST_END(ehci); | 226 | hw->hw_alt_next = EHCI_LIST_END(ehci); |
227 | hw->hw_token &= ~QTD_STS_ACTIVE; | ||
228 | ehci->dummy->hw = hw; | 227 | ehci->dummy->hw = hw; |
229 | 228 | ||
230 | for (i = 0; i < ehci->periodic_size; i++) | 229 | for (i = 0; i < ehci->periodic_size; i++) |
231 | ehci->periodic[i] = ehci->dummy->qh_dma; | 230 | ehci->periodic[i] = cpu_to_hc32(ehci, |
231 | ehci->dummy->qh_dma); | ||
232 | } else { | 232 | } else { |
233 | for (i = 0; i < ehci->periodic_size; i++) | 233 | for (i = 0; i < ehci->periodic_size; i++) |
234 | ehci->periodic[i] = EHCI_LIST_END(ehci); | 234 | ehci->periodic[i] = EHCI_LIST_END(ehci); |
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c index 0f717dc688b7..f341651d6f6c 100644 --- a/drivers/usb/host/ehci-msm.c +++ b/drivers/usb/host/ehci-msm.c | |||
@@ -42,7 +42,6 @@ | |||
42 | 42 | ||
43 | static const char hcd_name[] = "ehci-msm"; | 43 | static const char hcd_name[] = "ehci-msm"; |
44 | static struct hc_driver __read_mostly msm_hc_driver; | 44 | static struct hc_driver __read_mostly msm_hc_driver; |
45 | static struct usb_phy *phy; | ||
46 | 45 | ||
47 | static int ehci_msm_reset(struct usb_hcd *hcd) | 46 | static int ehci_msm_reset(struct usb_hcd *hcd) |
48 | { | 47 | { |
@@ -70,6 +69,7 @@ static int ehci_msm_probe(struct platform_device *pdev) | |||
70 | { | 69 | { |
71 | struct usb_hcd *hcd; | 70 | struct usb_hcd *hcd; |
72 | struct resource *res; | 71 | struct resource *res; |
72 | struct usb_phy *phy; | ||
73 | int ret; | 73 | int ret; |
74 | 74 | ||
75 | dev_dbg(&pdev->dev, "ehci_msm proble\n"); | 75 | dev_dbg(&pdev->dev, "ehci_msm proble\n"); |
@@ -108,10 +108,14 @@ static int ehci_msm_probe(struct platform_device *pdev) | |||
108 | * powering up VBUS, mapping of registers address space and power | 108 | * powering up VBUS, mapping of registers address space and power |
109 | * management. | 109 | * management. |
110 | */ | 110 | */ |
111 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 111 | if (pdev->dev.of_node) |
112 | phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); | ||
113 | else | ||
114 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | ||
115 | |||
112 | if (IS_ERR(phy)) { | 116 | if (IS_ERR(phy)) { |
113 | dev_err(&pdev->dev, "unable to find transceiver\n"); | 117 | dev_err(&pdev->dev, "unable to find transceiver\n"); |
114 | ret = -ENODEV; | 118 | ret = -EPROBE_DEFER; |
115 | goto put_hcd; | 119 | goto put_hcd; |
116 | } | 120 | } |
117 | 121 | ||
@@ -121,6 +125,7 @@ static int ehci_msm_probe(struct platform_device *pdev) | |||
121 | goto put_hcd; | 125 | goto put_hcd; |
122 | } | 126 | } |
123 | 127 | ||
128 | hcd->phy = phy; | ||
124 | device_init_wakeup(&pdev->dev, 1); | 129 | device_init_wakeup(&pdev->dev, 1); |
125 | /* | 130 | /* |
126 | * OTG device parent of HCD takes care of putting | 131 | * OTG device parent of HCD takes care of putting |
@@ -147,7 +152,7 @@ static int ehci_msm_remove(struct platform_device *pdev) | |||
147 | pm_runtime_disable(&pdev->dev); | 152 | pm_runtime_disable(&pdev->dev); |
148 | pm_runtime_set_suspended(&pdev->dev); | 153 | pm_runtime_set_suspended(&pdev->dev); |
149 | 154 | ||
150 | otg_set_host(phy->otg, NULL); | 155 | otg_set_host(hcd->phy->otg, NULL); |
151 | 156 | ||
152 | /* FIXME: need to call usb_remove_hcd() here? */ | 157 | /* FIXME: need to call usb_remove_hcd() here? */ |
153 | 158 | ||
@@ -186,12 +191,19 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = { | |||
186 | .resume = ehci_msm_pm_resume, | 191 | .resume = ehci_msm_pm_resume, |
187 | }; | 192 | }; |
188 | 193 | ||
194 | static struct of_device_id msm_ehci_dt_match[] = { | ||
195 | { .compatible = "qcom,ehci-host", }, | ||
196 | {} | ||
197 | }; | ||
198 | MODULE_DEVICE_TABLE(of, msm_ehci_dt_match); | ||
199 | |||
189 | static struct platform_driver ehci_msm_driver = { | 200 | static struct platform_driver ehci_msm_driver = { |
190 | .probe = ehci_msm_probe, | 201 | .probe = ehci_msm_probe, |
191 | .remove = ehci_msm_remove, | 202 | .remove = ehci_msm_remove, |
192 | .driver = { | 203 | .driver = { |
193 | .name = "msm_hsusb_host", | 204 | .name = "msm_hsusb_host", |
194 | .pm = &ehci_msm_dev_pm_ops, | 205 | .pm = &ehci_msm_dev_pm_ops, |
206 | .of_match_table = msm_ehci_dt_match, | ||
195 | }, | 207 | }, |
196 | }; | 208 | }; |
197 | 209 | ||
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c index 35cdbd88bbbe..417c10da9450 100644 --- a/drivers/usb/host/ehci-mv.c +++ b/drivers/usb/host/ehci-mv.c | |||
@@ -96,7 +96,7 @@ static const struct hc_driver mv_ehci_hc_driver = { | |||
96 | * generic hardware linkage | 96 | * generic hardware linkage |
97 | */ | 97 | */ |
98 | .irq = ehci_irq, | 98 | .irq = ehci_irq, |
99 | .flags = HCD_MEMORY | HCD_USB2, | 99 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
100 | 100 | ||
101 | /* | 101 | /* |
102 | * basic lifecycle operations | 102 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c index 45cc00158412..ab0397e4d8f3 100644 --- a/drivers/usb/host/ehci-octeon.c +++ b/drivers/usb/host/ehci-octeon.c | |||
@@ -51,7 +51,7 @@ static const struct hc_driver ehci_octeon_hc_driver = { | |||
51 | * generic hardware linkage | 51 | * generic hardware linkage |
52 | */ | 52 | */ |
53 | .irq = ehci_irq, | 53 | .irq = ehci_irq, |
54 | .flags = HCD_MEMORY | HCD_USB2, | 54 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
55 | 55 | ||
56 | /* | 56 | /* |
57 | * basic lifecycle operations | 57 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 854c2ec7b699..3e86bf4371b3 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -58,8 +58,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
58 | { | 58 | { |
59 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 59 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
60 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 60 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
61 | struct pci_dev *p_smbus; | ||
62 | u8 rev; | ||
63 | u32 temp; | 61 | u32 temp; |
64 | int retval; | 62 | int retval; |
65 | 63 | ||
@@ -175,22 +173,12 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
175 | /* SB600 and old version of SB700 have a bug in EHCI controller, | 173 | /* SB600 and old version of SB700 have a bug in EHCI controller, |
176 | * which causes usb devices lose response in some cases. | 174 | * which causes usb devices lose response in some cases. |
177 | */ | 175 | */ |
178 | if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) { | 176 | if ((pdev->device == 0x4386 || pdev->device == 0x4396) && |
179 | p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, | 177 | usb_amd_hang_symptom_quirk()) { |
180 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, | 178 | u8 tmp; |
181 | NULL); | 179 | ehci_info(ehci, "applying AMD SB600/SB700 USB freeze workaround\n"); |
182 | if (!p_smbus) | 180 | pci_read_config_byte(pdev, 0x53, &tmp); |
183 | break; | 181 | pci_write_config_byte(pdev, 0x53, tmp | (1<<3)); |
184 | rev = p_smbus->revision; | ||
185 | if ((pdev->device == 0x4386) || (rev == 0x3a) | ||
186 | || (rev == 0x3b)) { | ||
187 | u8 tmp; | ||
188 | ehci_info(ehci, "applying AMD SB600/SB700 USB " | ||
189 | "freeze workaround\n"); | ||
190 | pci_read_config_byte(pdev, 0x53, &tmp); | ||
191 | pci_write_config_byte(pdev, 0x53, tmp | (1<<3)); | ||
192 | } | ||
193 | pci_dev_put(p_smbus); | ||
194 | } | 182 | } |
195 | break; | 183 | break; |
196 | case PCI_VENDOR_ID_NETMOS: | 184 | case PCI_VENDOR_ID_NETMOS: |
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c index 601e208bd782..893b707f0000 100644 --- a/drivers/usb/host/ehci-pmcmsp.c +++ b/drivers/usb/host/ehci-pmcmsp.c | |||
@@ -286,7 +286,7 @@ static const struct hc_driver ehci_msp_hc_driver = { | |||
286 | #else | 286 | #else |
287 | .irq = ehci_irq, | 287 | .irq = ehci_irq, |
288 | #endif | 288 | #endif |
289 | .flags = HCD_MEMORY | HCD_USB2, | 289 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
290 | 290 | ||
291 | /* | 291 | /* |
292 | * basic lifecycle operations | 292 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c index 932293fa32de..6cc5567bf9c8 100644 --- a/drivers/usb/host/ehci-ppc-of.c +++ b/drivers/usb/host/ehci-ppc-of.c | |||
@@ -28,7 +28,7 @@ static const struct hc_driver ehci_ppc_of_hc_driver = { | |||
28 | * generic hardware linkage | 28 | * generic hardware linkage |
29 | */ | 29 | */ |
30 | .irq = ehci_irq, | 30 | .irq = ehci_irq, |
31 | .flags = HCD_MEMORY | HCD_USB2, | 31 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * basic lifecycle operations | 34 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c index fd983771b025..8188542ba17e 100644 --- a/drivers/usb/host/ehci-ps3.c +++ b/drivers/usb/host/ehci-ps3.c | |||
@@ -71,7 +71,7 @@ static const struct hc_driver ps3_ehci_hc_driver = { | |||
71 | .product_desc = "PS3 EHCI Host Controller", | 71 | .product_desc = "PS3 EHCI Host Controller", |
72 | .hcd_priv_size = sizeof(struct ehci_hcd), | 72 | .hcd_priv_size = sizeof(struct ehci_hcd), |
73 | .irq = ehci_irq, | 73 | .irq = ehci_irq, |
74 | .flags = HCD_MEMORY | HCD_USB2, | 74 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
75 | .reset = ps3_ehci_hc_reset, | 75 | .reset = ps3_ehci_hc_reset, |
76 | .start = ehci_run, | 76 | .start = ehci_run, |
77 | .stop = ehci_stop, | 77 | .stop = ehci_stop, |
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index a7f776a13eb1..db05bd8ee9d5 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
@@ -105,9 +105,9 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd) | |||
105 | 105 | ||
106 | is_out = qh->is_out; | 106 | is_out = qh->is_out; |
107 | epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f; | 107 | epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f; |
108 | if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { | 108 | if (unlikely(!usb_gettoggle(qh->ps.udev, epnum, is_out))) { |
109 | hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); | 109 | hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); |
110 | usb_settoggle (qh->dev, epnum, is_out, 1); | 110 | usb_settoggle(qh->ps.udev, epnum, is_out, 1); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
@@ -247,8 +247,6 @@ static int qtd_copy_status ( | |||
247 | 247 | ||
248 | static void | 248 | static void |
249 | ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status) | 249 | ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status) |
250 | __releases(ehci->lock) | ||
251 | __acquires(ehci->lock) | ||
252 | { | 250 | { |
253 | if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | 251 | if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { |
254 | /* ... update hc-wide periodic stats */ | 252 | /* ... update hc-wide periodic stats */ |
@@ -274,11 +272,8 @@ __acquires(ehci->lock) | |||
274 | urb->actual_length, urb->transfer_buffer_length); | 272 | urb->actual_length, urb->transfer_buffer_length); |
275 | #endif | 273 | #endif |
276 | 274 | ||
277 | /* complete() can reenter this HCD */ | ||
278 | usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); | 275 | usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); |
279 | spin_unlock (&ehci->lock); | ||
280 | usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status); | 276 | usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status); |
281 | spin_lock (&ehci->lock); | ||
282 | } | 277 | } |
283 | 278 | ||
284 | static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); | 279 | static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); |
@@ -802,26 +797,35 @@ qh_make ( | |||
802 | * For control/bulk requests, the HC or TT handles these. | 797 | * For control/bulk requests, the HC or TT handles these. |
803 | */ | 798 | */ |
804 | if (type == PIPE_INTERRUPT) { | 799 | if (type == PIPE_INTERRUPT) { |
805 | qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, | 800 | unsigned tmp; |
801 | |||
802 | qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, | ||
806 | is_input, 0, | 803 | is_input, 0, |
807 | hb_mult(maxp) * max_packet(maxp))); | 804 | hb_mult(maxp) * max_packet(maxp))); |
808 | qh->start = NO_FRAME; | 805 | qh->ps.phase = NO_FRAME; |
809 | 806 | ||
810 | if (urb->dev->speed == USB_SPEED_HIGH) { | 807 | if (urb->dev->speed == USB_SPEED_HIGH) { |
811 | qh->c_usecs = 0; | 808 | qh->ps.c_usecs = 0; |
812 | qh->gap_uf = 0; | 809 | qh->gap_uf = 0; |
813 | 810 | ||
814 | qh->period = urb->interval >> 3; | 811 | if (urb->interval > 1 && urb->interval < 8) { |
815 | if (qh->period == 0 && urb->interval != 1) { | ||
816 | /* NOTE interval 2 or 4 uframes could work. | 812 | /* NOTE interval 2 or 4 uframes could work. |
817 | * But interval 1 scheduling is simpler, and | 813 | * But interval 1 scheduling is simpler, and |
818 | * includes high bandwidth. | 814 | * includes high bandwidth. |
819 | */ | 815 | */ |
820 | urb->interval = 1; | 816 | urb->interval = 1; |
821 | } else if (qh->period > ehci->periodic_size) { | 817 | } else if (urb->interval > ehci->periodic_size << 3) { |
822 | qh->period = ehci->periodic_size; | 818 | urb->interval = ehci->periodic_size << 3; |
823 | urb->interval = qh->period << 3; | ||
824 | } | 819 | } |
820 | qh->ps.period = urb->interval >> 3; | ||
821 | |||
822 | /* period for bandwidth allocation */ | ||
823 | tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE, | ||
824 | 1 << (urb->ep->desc.bInterval - 1)); | ||
825 | |||
826 | /* Allow urb->interval to override */ | ||
827 | qh->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval); | ||
828 | qh->ps.bw_period = qh->ps.bw_uperiod >> 3; | ||
825 | } else { | 829 | } else { |
826 | int think_time; | 830 | int think_time; |
827 | 831 | ||
@@ -831,27 +835,35 @@ qh_make ( | |||
831 | 835 | ||
832 | /* FIXME this just approximates SPLIT/CSPLIT times */ | 836 | /* FIXME this just approximates SPLIT/CSPLIT times */ |
833 | if (is_input) { // SPLIT, gap, CSPLIT+DATA | 837 | if (is_input) { // SPLIT, gap, CSPLIT+DATA |
834 | qh->c_usecs = qh->usecs + HS_USECS (0); | 838 | qh->ps.c_usecs = qh->ps.usecs + HS_USECS(0); |
835 | qh->usecs = HS_USECS (1); | 839 | qh->ps.usecs = HS_USECS(1); |
836 | } else { // SPLIT+DATA, gap, CSPLIT | 840 | } else { // SPLIT+DATA, gap, CSPLIT |
837 | qh->usecs += HS_USECS (1); | 841 | qh->ps.usecs += HS_USECS(1); |
838 | qh->c_usecs = HS_USECS (0); | 842 | qh->ps.c_usecs = HS_USECS(0); |
839 | } | 843 | } |
840 | 844 | ||
841 | think_time = tt ? tt->think_time : 0; | 845 | think_time = tt ? tt->think_time : 0; |
842 | qh->tt_usecs = NS_TO_US (think_time + | 846 | qh->ps.tt_usecs = NS_TO_US(think_time + |
843 | usb_calc_bus_time (urb->dev->speed, | 847 | usb_calc_bus_time (urb->dev->speed, |
844 | is_input, 0, max_packet (maxp))); | 848 | is_input, 0, max_packet (maxp))); |
845 | qh->period = urb->interval; | 849 | if (urb->interval > ehci->periodic_size) |
846 | if (qh->period > ehci->periodic_size) { | 850 | urb->interval = ehci->periodic_size; |
847 | qh->period = ehci->periodic_size; | 851 | qh->ps.period = urb->interval; |
848 | urb->interval = qh->period; | 852 | |
849 | } | 853 | /* period for bandwidth allocation */ |
854 | tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES, | ||
855 | urb->ep->desc.bInterval); | ||
856 | tmp = rounddown_pow_of_two(tmp); | ||
857 | |||
858 | /* Allow urb->interval to override */ | ||
859 | qh->ps.bw_period = min_t(unsigned, tmp, urb->interval); | ||
860 | qh->ps.bw_uperiod = qh->ps.bw_period << 3; | ||
850 | } | 861 | } |
851 | } | 862 | } |
852 | 863 | ||
853 | /* support for tt scheduling, and access to toggles */ | 864 | /* support for tt scheduling, and access to toggles */ |
854 | qh->dev = urb->dev; | 865 | qh->ps.udev = urb->dev; |
866 | qh->ps.ep = urb->ep; | ||
855 | 867 | ||
856 | /* using TT? */ | 868 | /* using TT? */ |
857 | switch (urb->dev->speed) { | 869 | switch (urb->dev->speed) { |
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 85dd24ed97a6..e113fd73aeae 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -103,83 +103,210 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | |||
103 | *hw_p = *shadow_next_periodic(ehci, &here, | 103 | *hw_p = *shadow_next_periodic(ehci, &here, |
104 | Q_NEXT_TYPE(ehci, *hw_p)); | 104 | Q_NEXT_TYPE(ehci, *hw_p)); |
105 | else | 105 | else |
106 | *hw_p = ehci->dummy->qh_dma; | 106 | *hw_p = cpu_to_hc32(ehci, ehci->dummy->qh_dma); |
107 | } | 107 | } |
108 | 108 | ||
109 | /* how many of the uframe's 125 usecs are allocated? */ | 109 | /*-------------------------------------------------------------------------*/ |
110 | static unsigned short | 110 | |
111 | periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | 111 | /* Bandwidth and TT management */ |
112 | |||
113 | /* Find the TT data structure for this device; create it if necessary */ | ||
114 | static struct ehci_tt *find_tt(struct usb_device *udev) | ||
112 | { | 115 | { |
113 | __hc32 *hw_p = &ehci->periodic [frame]; | 116 | struct usb_tt *utt = udev->tt; |
114 | union ehci_shadow *q = &ehci->pshadow [frame]; | 117 | struct ehci_tt *tt, **tt_index, **ptt; |
115 | unsigned usecs = 0; | 118 | unsigned port; |
116 | struct ehci_qh_hw *hw; | 119 | bool allocated_index = false; |
117 | 120 | ||
118 | while (q->ptr) { | 121 | if (!utt) |
119 | switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { | 122 | return NULL; /* Not below a TT */ |
120 | case Q_TYPE_QH: | 123 | |
121 | hw = q->qh->hw; | 124 | /* |
122 | /* is it in the S-mask? */ | 125 | * Find/create our data structure. |
123 | if (hw->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) | 126 | * For hubs with a single TT, we get it directly. |
124 | usecs += q->qh->usecs; | 127 | * For hubs with multiple TTs, there's an extra level of pointers. |
125 | /* ... or C-mask? */ | 128 | */ |
126 | if (hw->hw_info2 & cpu_to_hc32(ehci, | 129 | tt_index = NULL; |
127 | 1 << (8 + uframe))) | 130 | if (utt->multi) { |
128 | usecs += q->qh->c_usecs; | 131 | tt_index = utt->hcpriv; |
129 | hw_p = &hw->hw_next; | 132 | if (!tt_index) { /* Create the index array */ |
130 | q = &q->qh->qh_next; | 133 | tt_index = kzalloc(utt->hub->maxchild * |
131 | break; | 134 | sizeof(*tt_index), GFP_ATOMIC); |
132 | // case Q_TYPE_FSTN: | 135 | if (!tt_index) |
133 | default: | 136 | return ERR_PTR(-ENOMEM); |
134 | /* for "save place" FSTNs, count the relevant INTR | 137 | utt->hcpriv = tt_index; |
135 | * bandwidth from the previous frame | 138 | allocated_index = true; |
136 | */ | 139 | } |
137 | if (q->fstn->hw_prev != EHCI_LIST_END(ehci)) { | 140 | port = udev->ttport - 1; |
138 | ehci_dbg (ehci, "ignoring FSTN cost ...\n"); | 141 | ptt = &tt_index[port]; |
139 | } | 142 | } else { |
140 | hw_p = &q->fstn->hw_next; | 143 | port = 0; |
141 | q = &q->fstn->fstn_next; | 144 | ptt = (struct ehci_tt **) &utt->hcpriv; |
142 | break; | 145 | } |
143 | case Q_TYPE_ITD: | 146 | |
144 | if (q->itd->hw_transaction[uframe]) | 147 | tt = *ptt; |
145 | usecs += q->itd->stream->usecs; | 148 | if (!tt) { /* Create the ehci_tt */ |
146 | hw_p = &q->itd->hw_next; | 149 | struct ehci_hcd *ehci = |
147 | q = &q->itd->itd_next; | 150 | hcd_to_ehci(bus_to_hcd(udev->bus)); |
148 | break; | ||
149 | case Q_TYPE_SITD: | ||
150 | /* is it in the S-mask? (count SPLIT, DATA) */ | ||
151 | if (q->sitd->hw_uframe & cpu_to_hc32(ehci, | ||
152 | 1 << uframe)) { | ||
153 | if (q->sitd->hw_fullspeed_ep & | ||
154 | cpu_to_hc32(ehci, 1<<31)) | ||
155 | usecs += q->sitd->stream->usecs; | ||
156 | else /* worst case for OUT start-split */ | ||
157 | usecs += HS_USECS_ISO (188); | ||
158 | } | ||
159 | 151 | ||
160 | /* ... C-mask? (count CSPLIT, DATA) */ | 152 | tt = kzalloc(sizeof(*tt), GFP_ATOMIC); |
161 | if (q->sitd->hw_uframe & | 153 | if (!tt) { |
162 | cpu_to_hc32(ehci, 1 << (8 + uframe))) { | 154 | if (allocated_index) { |
163 | /* worst case for IN complete-split */ | 155 | utt->hcpriv = NULL; |
164 | usecs += q->sitd->stream->c_usecs; | 156 | kfree(tt_index); |
165 | } | 157 | } |
158 | return ERR_PTR(-ENOMEM); | ||
159 | } | ||
160 | list_add_tail(&tt->tt_list, &ehci->tt_list); | ||
161 | INIT_LIST_HEAD(&tt->ps_list); | ||
162 | tt->usb_tt = utt; | ||
163 | tt->tt_port = port; | ||
164 | *ptt = tt; | ||
165 | } | ||
166 | 166 | ||
167 | hw_p = &q->sitd->hw_next; | 167 | return tt; |
168 | q = &q->sitd->sitd_next; | 168 | } |
169 | break; | 169 | |
170 | /* Release the TT above udev, if it's not in use */ | ||
171 | static void drop_tt(struct usb_device *udev) | ||
172 | { | ||
173 | struct usb_tt *utt = udev->tt; | ||
174 | struct ehci_tt *tt, **tt_index, **ptt; | ||
175 | int cnt, i; | ||
176 | |||
177 | if (!utt || !utt->hcpriv) | ||
178 | return; /* Not below a TT, or never allocated */ | ||
179 | |||
180 | cnt = 0; | ||
181 | if (utt->multi) { | ||
182 | tt_index = utt->hcpriv; | ||
183 | ptt = &tt_index[udev->ttport - 1]; | ||
184 | |||
185 | /* How many entries are left in tt_index? */ | ||
186 | for (i = 0; i < utt->hub->maxchild; ++i) | ||
187 | cnt += !!tt_index[i]; | ||
188 | } else { | ||
189 | tt_index = NULL; | ||
190 | ptt = (struct ehci_tt **) &utt->hcpriv; | ||
191 | } | ||
192 | |||
193 | tt = *ptt; | ||
194 | if (!tt || !list_empty(&tt->ps_list)) | ||
195 | return; /* never allocated, or still in use */ | ||
196 | |||
197 | list_del(&tt->tt_list); | ||
198 | *ptt = NULL; | ||
199 | kfree(tt); | ||
200 | if (cnt == 1) { | ||
201 | utt->hcpriv = NULL; | ||
202 | kfree(tt_index); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | static void bandwidth_dbg(struct ehci_hcd *ehci, int sign, char *type, | ||
207 | struct ehci_per_sched *ps) | ||
208 | { | ||
209 | dev_dbg(&ps->udev->dev, | ||
210 | "ep %02x: %s %s @ %u+%u (%u.%u+%u) [%u/%u us] mask %04x\n", | ||
211 | ps->ep->desc.bEndpointAddress, | ||
212 | (sign >= 0 ? "reserve" : "release"), type, | ||
213 | (ps->bw_phase << 3) + ps->phase_uf, ps->bw_uperiod, | ||
214 | ps->phase, ps->phase_uf, ps->period, | ||
215 | ps->usecs, ps->c_usecs, ps->cs_mask); | ||
216 | } | ||
217 | |||
218 | static void reserve_release_intr_bandwidth(struct ehci_hcd *ehci, | ||
219 | struct ehci_qh *qh, int sign) | ||
220 | { | ||
221 | unsigned start_uf; | ||
222 | unsigned i, j, m; | ||
223 | int usecs = qh->ps.usecs; | ||
224 | int c_usecs = qh->ps.c_usecs; | ||
225 | int tt_usecs = qh->ps.tt_usecs; | ||
226 | struct ehci_tt *tt; | ||
227 | |||
228 | if (qh->ps.phase == NO_FRAME) /* Bandwidth wasn't reserved */ | ||
229 | return; | ||
230 | start_uf = qh->ps.bw_phase << 3; | ||
231 | |||
232 | bandwidth_dbg(ehci, sign, "intr", &qh->ps); | ||
233 | |||
234 | if (sign < 0) { /* Release bandwidth */ | ||
235 | usecs = -usecs; | ||
236 | c_usecs = -c_usecs; | ||
237 | tt_usecs = -tt_usecs; | ||
238 | } | ||
239 | |||
240 | /* Entire transaction (high speed) or start-split (full/low speed) */ | ||
241 | for (i = start_uf + qh->ps.phase_uf; i < EHCI_BANDWIDTH_SIZE; | ||
242 | i += qh->ps.bw_uperiod) | ||
243 | ehci->bandwidth[i] += usecs; | ||
244 | |||
245 | /* Complete-split (full/low speed) */ | ||
246 | if (qh->ps.c_usecs) { | ||
247 | /* NOTE: adjustments needed for FSTN */ | ||
248 | for (i = start_uf; i < EHCI_BANDWIDTH_SIZE; | ||
249 | i += qh->ps.bw_uperiod) { | ||
250 | for ((j = 2, m = 1 << (j+8)); j < 8; (++j, m <<= 1)) { | ||
251 | if (qh->ps.cs_mask & m) | ||
252 | ehci->bandwidth[i+j] += c_usecs; | ||
253 | } | ||
170 | } | 254 | } |
171 | } | 255 | } |
172 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 256 | |
173 | if (usecs > ehci->uframe_periodic_max) | 257 | /* FS/LS bus bandwidth */ |
174 | ehci_err (ehci, "uframe %d sched overrun: %d usecs\n", | 258 | if (tt_usecs) { |
175 | frame * 8 + uframe, usecs); | 259 | tt = find_tt(qh->ps.udev); |
176 | #endif | 260 | if (sign > 0) |
177 | return usecs; | 261 | list_add_tail(&qh->ps.ps_list, &tt->ps_list); |
262 | else | ||
263 | list_del(&qh->ps.ps_list); | ||
264 | |||
265 | for (i = start_uf >> 3; i < EHCI_BANDWIDTH_FRAMES; | ||
266 | i += qh->ps.bw_period) | ||
267 | tt->bandwidth[i] += tt_usecs; | ||
268 | } | ||
178 | } | 269 | } |
179 | 270 | ||
180 | /*-------------------------------------------------------------------------*/ | 271 | /*-------------------------------------------------------------------------*/ |
181 | 272 | ||
182 | static int same_tt (struct usb_device *dev1, struct usb_device *dev2) | 273 | static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE], |
274 | struct ehci_tt *tt) | ||
275 | { | ||
276 | struct ehci_per_sched *ps; | ||
277 | unsigned uframe, uf, x; | ||
278 | u8 *budget_line; | ||
279 | |||
280 | if (!tt) | ||
281 | return; | ||
282 | memset(budget_table, 0, EHCI_BANDWIDTH_SIZE); | ||
283 | |||
284 | /* Add up the contributions from all the endpoints using this TT */ | ||
285 | list_for_each_entry(ps, &tt->ps_list, ps_list) { | ||
286 | for (uframe = ps->bw_phase << 3; uframe < EHCI_BANDWIDTH_SIZE; | ||
287 | uframe += ps->bw_uperiod) { | ||
288 | budget_line = &budget_table[uframe]; | ||
289 | x = ps->tt_usecs; | ||
290 | |||
291 | /* propagate the time forward */ | ||
292 | for (uf = ps->phase_uf; uf < 8; ++uf) { | ||
293 | x += budget_line[uf]; | ||
294 | |||
295 | /* Each microframe lasts 125 us */ | ||
296 | if (x <= 125) { | ||
297 | budget_line[uf] = x; | ||
298 | break; | ||
299 | } else { | ||
300 | budget_line[uf] = 125; | ||
301 | x -= 125; | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | |||
308 | static int __maybe_unused same_tt(struct usb_device *dev1, | ||
309 | struct usb_device *dev2) | ||
183 | { | 310 | { |
184 | if (!dev1->tt || !dev2->tt) | 311 | if (!dev1->tt || !dev2->tt) |
185 | return 0; | 312 | return 0; |
@@ -227,68 +354,6 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8]) | |||
227 | } | 354 | } |
228 | } | 355 | } |
229 | 356 | ||
230 | /* How many of the tt's periodic downstream 1000 usecs are allocated? | ||
231 | * | ||
232 | * While this measures the bandwidth in terms of usecs/uframe, | ||
233 | * the low/fullspeed bus has no notion of uframes, so any particular | ||
234 | * low/fullspeed transfer can "carry over" from one uframe to the next, | ||
235 | * since the TT just performs downstream transfers in sequence. | ||
236 | * | ||
237 | * For example two separate 100 usec transfers can start in the same uframe, | ||
238 | * and the second one would "carry over" 75 usecs into the next uframe. | ||
239 | */ | ||
240 | static void | ||
241 | periodic_tt_usecs ( | ||
242 | struct ehci_hcd *ehci, | ||
243 | struct usb_device *dev, | ||
244 | unsigned frame, | ||
245 | unsigned short tt_usecs[8] | ||
246 | ) | ||
247 | { | ||
248 | __hc32 *hw_p = &ehci->periodic [frame]; | ||
249 | union ehci_shadow *q = &ehci->pshadow [frame]; | ||
250 | unsigned char uf; | ||
251 | |||
252 | memset(tt_usecs, 0, 16); | ||
253 | |||
254 | while (q->ptr) { | ||
255 | switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { | ||
256 | case Q_TYPE_ITD: | ||
257 | hw_p = &q->itd->hw_next; | ||
258 | q = &q->itd->itd_next; | ||
259 | continue; | ||
260 | case Q_TYPE_QH: | ||
261 | if (same_tt(dev, q->qh->dev)) { | ||
262 | uf = tt_start_uframe(ehci, q->qh->hw->hw_info2); | ||
263 | tt_usecs[uf] += q->qh->tt_usecs; | ||
264 | } | ||
265 | hw_p = &q->qh->hw->hw_next; | ||
266 | q = &q->qh->qh_next; | ||
267 | continue; | ||
268 | case Q_TYPE_SITD: | ||
269 | if (same_tt(dev, q->sitd->urb->dev)) { | ||
270 | uf = tt_start_uframe(ehci, q->sitd->hw_uframe); | ||
271 | tt_usecs[uf] += q->sitd->stream->tt_usecs; | ||
272 | } | ||
273 | hw_p = &q->sitd->hw_next; | ||
274 | q = &q->sitd->sitd_next; | ||
275 | continue; | ||
276 | // case Q_TYPE_FSTN: | ||
277 | default: | ||
278 | ehci_dbg(ehci, "ignoring periodic frame %d FSTN\n", | ||
279 | frame); | ||
280 | hw_p = &q->fstn->hw_next; | ||
281 | q = &q->fstn->fstn_next; | ||
282 | } | ||
283 | } | ||
284 | |||
285 | carryover_tt_bandwidth(tt_usecs); | ||
286 | |||
287 | if (max_tt_usecs[7] < tt_usecs[7]) | ||
288 | ehci_err(ehci, "frame %d tt sched overrun: %d usecs\n", | ||
289 | frame, tt_usecs[7] - max_tt_usecs[7]); | ||
290 | } | ||
291 | |||
292 | /* | 357 | /* |
293 | * Return true if the device's tt's downstream bus is available for a | 358 | * Return true if the device's tt's downstream bus is available for a |
294 | * periodic transfer of the specified length (usecs), starting at the | 359 | * periodic transfer of the specified length (usecs), starting at the |
@@ -312,20 +377,29 @@ periodic_tt_usecs ( | |||
312 | */ | 377 | */ |
313 | static int tt_available ( | 378 | static int tt_available ( |
314 | struct ehci_hcd *ehci, | 379 | struct ehci_hcd *ehci, |
315 | unsigned period, | 380 | struct ehci_per_sched *ps, |
316 | struct usb_device *dev, | 381 | struct ehci_tt *tt, |
317 | unsigned frame, | 382 | unsigned frame, |
318 | unsigned uframe, | 383 | unsigned uframe |
319 | u16 usecs | ||
320 | ) | 384 | ) |
321 | { | 385 | { |
386 | unsigned period = ps->bw_period; | ||
387 | unsigned usecs = ps->tt_usecs; | ||
388 | |||
322 | if ((period == 0) || (uframe >= 7)) /* error */ | 389 | if ((period == 0) || (uframe >= 7)) /* error */ |
323 | return 0; | 390 | return 0; |
324 | 391 | ||
325 | for (; frame < ehci->periodic_size; frame += period) { | 392 | for (frame &= period - 1; frame < EHCI_BANDWIDTH_FRAMES; |
326 | unsigned short tt_usecs[8]; | 393 | frame += period) { |
394 | unsigned i, uf; | ||
395 | unsigned short tt_usecs[8]; | ||
327 | 396 | ||
328 | periodic_tt_usecs (ehci, dev, frame, tt_usecs); | 397 | if (tt->bandwidth[frame] + usecs > 900) |
398 | return 0; | ||
399 | |||
400 | uf = frame << 3; | ||
401 | for (i = 0; i < 8; (++i, ++uf)) | ||
402 | tt_usecs[i] = ehci->tt_budget[uf]; | ||
329 | 403 | ||
330 | if (max_tt_usecs[uframe] <= tt_usecs[uframe]) | 404 | if (max_tt_usecs[uframe] <= tt_usecs[uframe]) |
331 | return 0; | 405 | return 0; |
@@ -337,7 +411,7 @@ static int tt_available ( | |||
337 | */ | 411 | */ |
338 | if (125 < usecs) { | 412 | if (125 < usecs) { |
339 | int ufs = (usecs / 125); | 413 | int ufs = (usecs / 125); |
340 | int i; | 414 | |
341 | for (i = uframe; i < (uframe + ufs) && i < 8; i++) | 415 | for (i = uframe; i < (uframe + ufs) && i < 8; i++) |
342 | if (0 < tt_usecs[i]) | 416 | if (0 < tt_usecs[i]) |
343 | return 0; | 417 | return 0; |
@@ -391,7 +465,7 @@ static int tt_no_collision ( | |||
391 | continue; | 465 | continue; |
392 | case Q_TYPE_QH: | 466 | case Q_TYPE_QH: |
393 | hw = here.qh->hw; | 467 | hw = here.qh->hw; |
394 | if (same_tt (dev, here.qh->dev)) { | 468 | if (same_tt(dev, here.qh->ps.udev)) { |
395 | u32 mask; | 469 | u32 mask; |
396 | 470 | ||
397 | mask = hc32_to_cpu(ehci, | 471 | mask = hc32_to_cpu(ehci, |
@@ -471,19 +545,19 @@ static void disable_periodic(struct ehci_hcd *ehci) | |||
471 | static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) | 545 | static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) |
472 | { | 546 | { |
473 | unsigned i; | 547 | unsigned i; |
474 | unsigned period = qh->period; | 548 | unsigned period = qh->ps.period; |
475 | 549 | ||
476 | dev_dbg (&qh->dev->dev, | 550 | dev_dbg(&qh->ps.udev->dev, |
477 | "link qh%d-%04x/%p start %d [%d/%d us]\n", | 551 | "link qh%d-%04x/%p start %d [%d/%d us]\n", |
478 | period, hc32_to_cpup(ehci, &qh->hw->hw_info2) | 552 | period, hc32_to_cpup(ehci, &qh->hw->hw_info2) |
479 | & (QH_CMASK | QH_SMASK), | 553 | & (QH_CMASK | QH_SMASK), |
480 | qh, qh->start, qh->usecs, qh->c_usecs); | 554 | qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs); |
481 | 555 | ||
482 | /* high bandwidth, or otherwise every microframe */ | 556 | /* high bandwidth, or otherwise every microframe */ |
483 | if (period == 0) | 557 | if (period == 0) |
484 | period = 1; | 558 | period = 1; |
485 | 559 | ||
486 | for (i = qh->start; i < ehci->periodic_size; i += period) { | 560 | for (i = qh->ps.phase; i < ehci->periodic_size; i += period) { |
487 | union ehci_shadow *prev = &ehci->pshadow[i]; | 561 | union ehci_shadow *prev = &ehci->pshadow[i]; |
488 | __hc32 *hw_p = &ehci->periodic[i]; | 562 | __hc32 *hw_p = &ehci->periodic[i]; |
489 | union ehci_shadow here = *prev; | 563 | union ehci_shadow here = *prev; |
@@ -503,7 +577,7 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
503 | * enables sharing interior tree nodes | 577 | * enables sharing interior tree nodes |
504 | */ | 578 | */ |
505 | while (here.ptr && qh != here.qh) { | 579 | while (here.ptr && qh != here.qh) { |
506 | if (qh->period > here.qh->period) | 580 | if (qh->ps.period > here.qh->ps.period) |
507 | break; | 581 | break; |
508 | prev = &here.qh->qh_next; | 582 | prev = &here.qh->qh_next; |
509 | hw_p = &here.qh->hw->hw_next; | 583 | hw_p = &here.qh->hw->hw_next; |
@@ -523,10 +597,10 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
523 | qh->xacterrs = 0; | 597 | qh->xacterrs = 0; |
524 | qh->exception = 0; | 598 | qh->exception = 0; |
525 | 599 | ||
526 | /* update per-qh bandwidth for usbfs */ | 600 | /* update per-qh bandwidth for debugfs */ |
527 | ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period | 601 | ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->ps.bw_period |
528 | ? ((qh->usecs + qh->c_usecs) / qh->period) | 602 | ? ((qh->ps.usecs + qh->ps.c_usecs) / qh->ps.bw_period) |
529 | : (qh->usecs * 8); | 603 | : (qh->ps.usecs * 8); |
530 | 604 | ||
531 | list_add(&qh->intr_node, &ehci->intr_qh_list); | 605 | list_add(&qh->intr_node, &ehci->intr_qh_list); |
532 | 606 | ||
@@ -556,22 +630,21 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
556 | */ | 630 | */ |
557 | 631 | ||
558 | /* high bandwidth, or otherwise part of every microframe */ | 632 | /* high bandwidth, or otherwise part of every microframe */ |
559 | if ((period = qh->period) == 0) | 633 | period = qh->ps.period ? : 1; |
560 | period = 1; | ||
561 | 634 | ||
562 | for (i = qh->start; i < ehci->periodic_size; i += period) | 635 | for (i = qh->ps.phase; i < ehci->periodic_size; i += period) |
563 | periodic_unlink (ehci, i, qh); | 636 | periodic_unlink (ehci, i, qh); |
564 | 637 | ||
565 | /* update per-qh bandwidth for usbfs */ | 638 | /* update per-qh bandwidth for debugfs */ |
566 | ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->period | 639 | ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->ps.bw_period |
567 | ? ((qh->usecs + qh->c_usecs) / qh->period) | 640 | ? ((qh->ps.usecs + qh->ps.c_usecs) / qh->ps.bw_period) |
568 | : (qh->usecs * 8); | 641 | : (qh->ps.usecs * 8); |
569 | 642 | ||
570 | dev_dbg (&qh->dev->dev, | 643 | dev_dbg(&qh->ps.udev->dev, |
571 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", | 644 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", |
572 | qh->period, | 645 | qh->ps.period, |
573 | hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK), | 646 | hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK), |
574 | qh, qh->start, qh->usecs, qh->c_usecs); | 647 | qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs); |
575 | 648 | ||
576 | /* qh->qh_next still "live" to HC */ | 649 | /* qh->qh_next still "live" to HC */ |
577 | qh->qh_state = QH_STATE_UNLINK; | 650 | qh->qh_state = QH_STATE_UNLINK; |
@@ -694,11 +767,9 @@ static int check_period ( | |||
694 | struct ehci_hcd *ehci, | 767 | struct ehci_hcd *ehci, |
695 | unsigned frame, | 768 | unsigned frame, |
696 | unsigned uframe, | 769 | unsigned uframe, |
697 | unsigned period, | 770 | unsigned uperiod, |
698 | unsigned usecs | 771 | unsigned usecs |
699 | ) { | 772 | ) { |
700 | int claimed; | ||
701 | |||
702 | /* complete split running into next frame? | 773 | /* complete split running into next frame? |
703 | * given FSTN support, we could sometimes check... | 774 | * given FSTN support, we could sometimes check... |
704 | */ | 775 | */ |
@@ -708,25 +779,10 @@ static int check_period ( | |||
708 | /* convert "usecs we need" to "max already claimed" */ | 779 | /* convert "usecs we need" to "max already claimed" */ |
709 | usecs = ehci->uframe_periodic_max - usecs; | 780 | usecs = ehci->uframe_periodic_max - usecs; |
710 | 781 | ||
711 | /* we "know" 2 and 4 uframe intervals were rejected; so | 782 | for (uframe += frame << 3; uframe < EHCI_BANDWIDTH_SIZE; |
712 | * for period 0, check _every_ microframe in the schedule. | 783 | uframe += uperiod) { |
713 | */ | 784 | if (ehci->bandwidth[uframe] > usecs) |
714 | if (unlikely (period == 0)) { | 785 | return 0; |
715 | do { | ||
716 | for (uframe = 0; uframe < 7; uframe++) { | ||
717 | claimed = periodic_usecs (ehci, frame, uframe); | ||
718 | if (claimed > usecs) | ||
719 | return 0; | ||
720 | } | ||
721 | } while ((frame += 1) < ehci->periodic_size); | ||
722 | |||
723 | /* just check the specified uframe, at that period */ | ||
724 | } else { | ||
725 | do { | ||
726 | claimed = periodic_usecs (ehci, frame, uframe); | ||
727 | if (claimed > usecs) | ||
728 | return 0; | ||
729 | } while ((frame += period) < ehci->periodic_size); | ||
730 | } | 786 | } |
731 | 787 | ||
732 | // success! | 788 | // success! |
@@ -737,40 +793,40 @@ static int check_intr_schedule ( | |||
737 | struct ehci_hcd *ehci, | 793 | struct ehci_hcd *ehci, |
738 | unsigned frame, | 794 | unsigned frame, |
739 | unsigned uframe, | 795 | unsigned uframe, |
740 | const struct ehci_qh *qh, | 796 | struct ehci_qh *qh, |
741 | __hc32 *c_maskp | 797 | unsigned *c_maskp, |
798 | struct ehci_tt *tt | ||
742 | ) | 799 | ) |
743 | { | 800 | { |
744 | int retval = -ENOSPC; | 801 | int retval = -ENOSPC; |
745 | u8 mask = 0; | 802 | u8 mask = 0; |
746 | 803 | ||
747 | if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ | 804 | if (qh->ps.c_usecs && uframe >= 6) /* FSTN territory? */ |
748 | goto done; | 805 | goto done; |
749 | 806 | ||
750 | if (!check_period (ehci, frame, uframe, qh->period, qh->usecs)) | 807 | if (!check_period(ehci, frame, uframe, qh->ps.bw_uperiod, qh->ps.usecs)) |
751 | goto done; | 808 | goto done; |
752 | if (!qh->c_usecs) { | 809 | if (!qh->ps.c_usecs) { |
753 | retval = 0; | 810 | retval = 0; |
754 | *c_maskp = 0; | 811 | *c_maskp = 0; |
755 | goto done; | 812 | goto done; |
756 | } | 813 | } |
757 | 814 | ||
758 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED | 815 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED |
759 | if (tt_available (ehci, qh->period, qh->dev, frame, uframe, | 816 | if (tt_available(ehci, &qh->ps, tt, frame, uframe)) { |
760 | qh->tt_usecs)) { | ||
761 | unsigned i; | 817 | unsigned i; |
762 | 818 | ||
763 | /* TODO : this may need FSTN for SSPLIT in uframe 5. */ | 819 | /* TODO : this may need FSTN for SSPLIT in uframe 5. */ |
764 | for (i=uframe+1; i<8 && i<uframe+4; i++) | 820 | for (i = uframe+2; i < 8 && i <= uframe+4; i++) |
765 | if (!check_period (ehci, frame, i, | 821 | if (!check_period(ehci, frame, i, |
766 | qh->period, qh->c_usecs)) | 822 | qh->ps.bw_uperiod, qh->ps.c_usecs)) |
767 | goto done; | 823 | goto done; |
768 | else | 824 | else |
769 | mask |= 1 << i; | 825 | mask |= 1 << i; |
770 | 826 | ||
771 | retval = 0; | 827 | retval = 0; |
772 | 828 | ||
773 | *c_maskp = cpu_to_hc32(ehci, mask << 8); | 829 | *c_maskp = mask; |
774 | } | 830 | } |
775 | #else | 831 | #else |
776 | /* Make sure this tt's buffer is also available for CSPLITs. | 832 | /* Make sure this tt's buffer is also available for CSPLITs. |
@@ -781,15 +837,15 @@ static int check_intr_schedule ( | |||
781 | * one smart pass... | 837 | * one smart pass... |
782 | */ | 838 | */ |
783 | mask = 0x03 << (uframe + qh->gap_uf); | 839 | mask = 0x03 << (uframe + qh->gap_uf); |
784 | *c_maskp = cpu_to_hc32(ehci, mask << 8); | 840 | *c_maskp = mask; |
785 | 841 | ||
786 | mask |= 1 << uframe; | 842 | mask |= 1 << uframe; |
787 | if (tt_no_collision (ehci, qh->period, qh->dev, frame, mask)) { | 843 | if (tt_no_collision(ehci, qh->ps.bw_period, qh->ps.udev, frame, mask)) { |
788 | if (!check_period (ehci, frame, uframe + qh->gap_uf + 1, | 844 | if (!check_period(ehci, frame, uframe + qh->gap_uf + 1, |
789 | qh->period, qh->c_usecs)) | 845 | qh->ps.bw_uperiod, qh->ps.c_usecs)) |
790 | goto done; | 846 | goto done; |
791 | if (!check_period (ehci, frame, uframe + qh->gap_uf, | 847 | if (!check_period(ehci, frame, uframe + qh->gap_uf, |
792 | qh->period, qh->c_usecs)) | 848 | qh->ps.bw_uperiod, qh->ps.c_usecs)) |
793 | goto done; | 849 | goto done; |
794 | retval = 0; | 850 | retval = 0; |
795 | } | 851 | } |
@@ -803,62 +859,67 @@ done: | |||
803 | */ | 859 | */ |
804 | static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) | 860 | static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) |
805 | { | 861 | { |
806 | int status; | 862 | int status = 0; |
807 | unsigned uframe; | 863 | unsigned uframe; |
808 | __hc32 c_mask; | 864 | unsigned c_mask; |
809 | unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ | ||
810 | struct ehci_qh_hw *hw = qh->hw; | 865 | struct ehci_qh_hw *hw = qh->hw; |
866 | struct ehci_tt *tt; | ||
811 | 867 | ||
812 | hw->hw_next = EHCI_LIST_END(ehci); | 868 | hw->hw_next = EHCI_LIST_END(ehci); |
813 | frame = qh->start; | ||
814 | 869 | ||
815 | /* reuse the previous schedule slots, if we can */ | 870 | /* reuse the previous schedule slots, if we can */ |
816 | if (frame < qh->period) { | 871 | if (qh->ps.phase != NO_FRAME) { |
817 | uframe = ffs(hc32_to_cpup(ehci, &hw->hw_info2) & QH_SMASK); | 872 | ehci_dbg(ehci, "reused qh %p schedule\n", qh); |
818 | status = check_intr_schedule (ehci, frame, --uframe, | 873 | return 0; |
819 | qh, &c_mask); | 874 | } |
820 | } else { | 875 | |
821 | uframe = 0; | 876 | uframe = 0; |
822 | c_mask = 0; | 877 | c_mask = 0; |
823 | status = -ENOSPC; | 878 | tt = find_tt(qh->ps.udev); |
879 | if (IS_ERR(tt)) { | ||
880 | status = PTR_ERR(tt); | ||
881 | goto done; | ||
824 | } | 882 | } |
883 | compute_tt_budget(ehci->tt_budget, tt); | ||
825 | 884 | ||
826 | /* else scan the schedule to find a group of slots such that all | 885 | /* else scan the schedule to find a group of slots such that all |
827 | * uframes have enough periodic bandwidth available. | 886 | * uframes have enough periodic bandwidth available. |
828 | */ | 887 | */ |
829 | if (status) { | 888 | /* "normal" case, uframing flexible except with splits */ |
830 | /* "normal" case, uframing flexible except with splits */ | 889 | if (qh->ps.bw_period) { |
831 | if (qh->period) { | 890 | int i; |
832 | int i; | 891 | unsigned frame; |
833 | 892 | ||
834 | for (i = qh->period; status && i > 0; --i) { | 893 | for (i = qh->ps.bw_period; i > 0; --i) { |
835 | frame = ++ehci->random_frame % qh->period; | 894 | frame = ++ehci->random_frame & (qh->ps.bw_period - 1); |
836 | for (uframe = 0; uframe < 8; uframe++) { | 895 | for (uframe = 0; uframe < 8; uframe++) { |
837 | status = check_intr_schedule (ehci, | 896 | status = check_intr_schedule(ehci, |
838 | frame, uframe, qh, | 897 | frame, uframe, qh, &c_mask, tt); |
839 | &c_mask); | 898 | if (status == 0) |
840 | if (status == 0) | 899 | goto got_it; |
841 | break; | ||
842 | } | ||
843 | } | 900 | } |
844 | |||
845 | /* qh->period == 0 means every uframe */ | ||
846 | } else { | ||
847 | frame = 0; | ||
848 | status = check_intr_schedule (ehci, 0, 0, qh, &c_mask); | ||
849 | } | 901 | } |
850 | if (status) | ||
851 | goto done; | ||
852 | qh->start = frame; | ||
853 | 902 | ||
854 | /* reset S-frame and (maybe) C-frame masks */ | 903 | /* qh->ps.bw_period == 0 means every uframe */ |
855 | hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); | 904 | } else { |
856 | hw->hw_info2 |= qh->period | 905 | status = check_intr_schedule(ehci, 0, 0, qh, &c_mask, tt); |
857 | ? cpu_to_hc32(ehci, 1 << uframe) | 906 | } |
858 | : cpu_to_hc32(ehci, QH_SMASK); | 907 | if (status) |
859 | hw->hw_info2 |= c_mask; | 908 | goto done; |
860 | } else | 909 | |
861 | ehci_dbg (ehci, "reused qh %p schedule\n", qh); | 910 | got_it: |
911 | qh->ps.phase = (qh->ps.period ? ehci->random_frame & | ||
912 | (qh->ps.period - 1) : 0); | ||
913 | qh->ps.bw_phase = qh->ps.phase & (qh->ps.bw_period - 1); | ||
914 | qh->ps.phase_uf = uframe; | ||
915 | qh->ps.cs_mask = qh->ps.period ? | ||
916 | (c_mask << 8) | (1 << uframe) : | ||
917 | QH_SMASK; | ||
918 | |||
919 | /* reset S-frame and (maybe) C-frame masks */ | ||
920 | hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); | ||
921 | hw->hw_info2 |= cpu_to_hc32(ehci, qh->ps.cs_mask); | ||
922 | reserve_release_intr_bandwidth(ehci, qh, 1); | ||
862 | 923 | ||
863 | done: | 924 | done: |
864 | return status; | 925 | return status; |
@@ -969,7 +1030,8 @@ iso_stream_alloc (gfp_t mem_flags) | |||
969 | if (likely (stream != NULL)) { | 1030 | if (likely (stream != NULL)) { |
970 | INIT_LIST_HEAD(&stream->td_list); | 1031 | INIT_LIST_HEAD(&stream->td_list); |
971 | INIT_LIST_HEAD(&stream->free_list); | 1032 | INIT_LIST_HEAD(&stream->free_list); |
972 | stream->next_uframe = -1; | 1033 | stream->next_uframe = NO_FRAME; |
1034 | stream->ps.phase = NO_FRAME; | ||
973 | } | 1035 | } |
974 | return stream; | 1036 | return stream; |
975 | } | 1037 | } |
@@ -978,25 +1040,24 @@ static void | |||
978 | iso_stream_init ( | 1040 | iso_stream_init ( |
979 | struct ehci_hcd *ehci, | 1041 | struct ehci_hcd *ehci, |
980 | struct ehci_iso_stream *stream, | 1042 | struct ehci_iso_stream *stream, |
981 | struct usb_device *dev, | 1043 | struct urb *urb |
982 | int pipe, | ||
983 | unsigned interval | ||
984 | ) | 1044 | ) |
985 | { | 1045 | { |
986 | static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f }; | 1046 | static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f }; |
987 | 1047 | ||
1048 | struct usb_device *dev = urb->dev; | ||
988 | u32 buf1; | 1049 | u32 buf1; |
989 | unsigned epnum, maxp; | 1050 | unsigned epnum, maxp; |
990 | int is_input; | 1051 | int is_input; |
991 | long bandwidth; | 1052 | unsigned tmp; |
992 | 1053 | ||
993 | /* | 1054 | /* |
994 | * this might be a "high bandwidth" highspeed endpoint, | 1055 | * this might be a "high bandwidth" highspeed endpoint, |
995 | * as encoded in the ep descriptor's wMaxPacket field | 1056 | * as encoded in the ep descriptor's wMaxPacket field |
996 | */ | 1057 | */ |
997 | epnum = usb_pipeendpoint (pipe); | 1058 | epnum = usb_pipeendpoint(urb->pipe); |
998 | is_input = usb_pipein (pipe) ? USB_DIR_IN : 0; | 1059 | is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0; |
999 | maxp = usb_maxpacket(dev, pipe, !is_input); | 1060 | maxp = usb_endpoint_maxp(&urb->ep->desc); |
1000 | if (is_input) { | 1061 | if (is_input) { |
1001 | buf1 = (1 << 11); | 1062 | buf1 = (1 << 11); |
1002 | } else { | 1063 | } else { |
@@ -1020,9 +1081,19 @@ iso_stream_init ( | |||
1020 | /* usbfs wants to report the average usecs per frame tied up | 1081 | /* usbfs wants to report the average usecs per frame tied up |
1021 | * when transfers on this endpoint are scheduled ... | 1082 | * when transfers on this endpoint are scheduled ... |
1022 | */ | 1083 | */ |
1023 | stream->usecs = HS_USECS_ISO (maxp); | 1084 | stream->ps.usecs = HS_USECS_ISO(maxp); |
1024 | bandwidth = stream->usecs * 8; | 1085 | |
1025 | bandwidth /= interval; | 1086 | /* period for bandwidth allocation */ |
1087 | tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE, | ||
1088 | 1 << (urb->ep->desc.bInterval - 1)); | ||
1089 | |||
1090 | /* Allow urb->interval to override */ | ||
1091 | stream->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval); | ||
1092 | |||
1093 | stream->uperiod = urb->interval; | ||
1094 | stream->ps.period = urb->interval >> 3; | ||
1095 | stream->bandwidth = stream->ps.usecs * 8 / | ||
1096 | stream->ps.bw_uperiod; | ||
1026 | 1097 | ||
1027 | } else { | 1098 | } else { |
1028 | u32 addr; | 1099 | u32 addr; |
@@ -1036,36 +1107,46 @@ iso_stream_init ( | |||
1036 | addr |= dev->tt->hub->devnum << 16; | 1107 | addr |= dev->tt->hub->devnum << 16; |
1037 | addr |= epnum << 8; | 1108 | addr |= epnum << 8; |
1038 | addr |= dev->devnum; | 1109 | addr |= dev->devnum; |
1039 | stream->usecs = HS_USECS_ISO (maxp); | 1110 | stream->ps.usecs = HS_USECS_ISO(maxp); |
1040 | think_time = dev->tt ? dev->tt->think_time : 0; | 1111 | think_time = dev->tt ? dev->tt->think_time : 0; |
1041 | stream->tt_usecs = NS_TO_US (think_time + usb_calc_bus_time ( | 1112 | stream->ps.tt_usecs = NS_TO_US(think_time + usb_calc_bus_time( |
1042 | dev->speed, is_input, 1, maxp)); | 1113 | dev->speed, is_input, 1, maxp)); |
1043 | hs_transfers = max (1u, (maxp + 187) / 188); | 1114 | hs_transfers = max (1u, (maxp + 187) / 188); |
1044 | if (is_input) { | 1115 | if (is_input) { |
1045 | u32 tmp; | 1116 | u32 tmp; |
1046 | 1117 | ||
1047 | addr |= 1 << 31; | 1118 | addr |= 1 << 31; |
1048 | stream->c_usecs = stream->usecs; | 1119 | stream->ps.c_usecs = stream->ps.usecs; |
1049 | stream->usecs = HS_USECS_ISO (1); | 1120 | stream->ps.usecs = HS_USECS_ISO(1); |
1050 | stream->raw_mask = 1; | 1121 | stream->ps.cs_mask = 1; |
1051 | 1122 | ||
1052 | /* c-mask as specified in USB 2.0 11.18.4 3.c */ | 1123 | /* c-mask as specified in USB 2.0 11.18.4 3.c */ |
1053 | tmp = (1 << (hs_transfers + 2)) - 1; | 1124 | tmp = (1 << (hs_transfers + 2)) - 1; |
1054 | stream->raw_mask |= tmp << (8 + 2); | 1125 | stream->ps.cs_mask |= tmp << (8 + 2); |
1055 | } else | 1126 | } else |
1056 | stream->raw_mask = smask_out [hs_transfers - 1]; | 1127 | stream->ps.cs_mask = smask_out[hs_transfers - 1]; |
1057 | bandwidth = stream->usecs + stream->c_usecs; | 1128 | |
1058 | bandwidth /= interval << 3; | 1129 | /* period for bandwidth allocation */ |
1130 | tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES, | ||
1131 | 1 << (urb->ep->desc.bInterval - 1)); | ||
1132 | |||
1133 | /* Allow urb->interval to override */ | ||
1134 | stream->ps.bw_period = min_t(unsigned, tmp, urb->interval); | ||
1135 | stream->ps.bw_uperiod = stream->ps.bw_period << 3; | ||
1059 | 1136 | ||
1060 | /* stream->splits gets created from raw_mask later */ | 1137 | stream->ps.period = urb->interval; |
1138 | stream->uperiod = urb->interval << 3; | ||
1139 | stream->bandwidth = (stream->ps.usecs + stream->ps.c_usecs) / | ||
1140 | stream->ps.bw_period; | ||
1141 | |||
1142 | /* stream->splits gets created from cs_mask later */ | ||
1061 | stream->address = cpu_to_hc32(ehci, addr); | 1143 | stream->address = cpu_to_hc32(ehci, addr); |
1062 | } | 1144 | } |
1063 | stream->bandwidth = bandwidth; | ||
1064 | 1145 | ||
1065 | stream->udev = dev; | 1146 | stream->ps.udev = dev; |
1147 | stream->ps.ep = urb->ep; | ||
1066 | 1148 | ||
1067 | stream->bEndpointAddress = is_input | epnum; | 1149 | stream->bEndpointAddress = is_input | epnum; |
1068 | stream->interval = interval; | ||
1069 | stream->maxp = maxp; | 1150 | stream->maxp = maxp; |
1070 | } | 1151 | } |
1071 | 1152 | ||
@@ -1090,9 +1171,7 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb) | |||
1090 | stream = iso_stream_alloc(GFP_ATOMIC); | 1171 | stream = iso_stream_alloc(GFP_ATOMIC); |
1091 | if (likely (stream != NULL)) { | 1172 | if (likely (stream != NULL)) { |
1092 | ep->hcpriv = stream; | 1173 | ep->hcpriv = stream; |
1093 | stream->ep = ep; | 1174 | iso_stream_init(ehci, stream, urb); |
1094 | iso_stream_init(ehci, stream, urb->dev, urb->pipe, | ||
1095 | urb->interval); | ||
1096 | } | 1175 | } |
1097 | 1176 | ||
1098 | /* if dev->ep [epnum] is a QH, hw is set */ | 1177 | /* if dev->ep [epnum] is a QH, hw is set */ |
@@ -1137,7 +1216,7 @@ itd_sched_init( | |||
1137 | dma_addr_t dma = urb->transfer_dma; | 1216 | dma_addr_t dma = urb->transfer_dma; |
1138 | 1217 | ||
1139 | /* how many uframes are needed for these transfers */ | 1218 | /* how many uframes are needed for these transfers */ |
1140 | iso_sched->span = urb->number_of_packets * stream->interval; | 1219 | iso_sched->span = urb->number_of_packets * stream->uperiod; |
1141 | 1220 | ||
1142 | /* figure out per-uframe itd fields that we'll need later | 1221 | /* figure out per-uframe itd fields that we'll need later |
1143 | * when we fit new itds into the schedule. | 1222 | * when we fit new itds into the schedule. |
@@ -1236,7 +1315,7 @@ itd_urb_transaction ( | |||
1236 | 1315 | ||
1237 | memset (itd, 0, sizeof *itd); | 1316 | memset (itd, 0, sizeof *itd); |
1238 | itd->itd_dma = itd_dma; | 1317 | itd->itd_dma = itd_dma; |
1239 | itd->frame = 9999; /* an invalid value */ | 1318 | itd->frame = NO_FRAME; |
1240 | list_add (&itd->itd_list, &sched->td_list); | 1319 | list_add (&itd->itd_list, &sched->td_list); |
1241 | } | 1320 | } |
1242 | spin_unlock_irqrestore (&ehci->lock, flags); | 1321 | spin_unlock_irqrestore (&ehci->lock, flags); |
@@ -1249,49 +1328,106 @@ itd_urb_transaction ( | |||
1249 | 1328 | ||
1250 | /*-------------------------------------------------------------------------*/ | 1329 | /*-------------------------------------------------------------------------*/ |
1251 | 1330 | ||
1331 | static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci, | ||
1332 | struct ehci_iso_stream *stream, int sign) | ||
1333 | { | ||
1334 | unsigned uframe; | ||
1335 | unsigned i, j; | ||
1336 | unsigned s_mask, c_mask, m; | ||
1337 | int usecs = stream->ps.usecs; | ||
1338 | int c_usecs = stream->ps.c_usecs; | ||
1339 | int tt_usecs = stream->ps.tt_usecs; | ||
1340 | struct ehci_tt *tt; | ||
1341 | |||
1342 | if (stream->ps.phase == NO_FRAME) /* Bandwidth wasn't reserved */ | ||
1343 | return; | ||
1344 | uframe = stream->ps.bw_phase << 3; | ||
1345 | |||
1346 | bandwidth_dbg(ehci, sign, "iso", &stream->ps); | ||
1347 | |||
1348 | if (sign < 0) { /* Release bandwidth */ | ||
1349 | usecs = -usecs; | ||
1350 | c_usecs = -c_usecs; | ||
1351 | tt_usecs = -tt_usecs; | ||
1352 | } | ||
1353 | |||
1354 | if (!stream->splits) { /* High speed */ | ||
1355 | for (i = uframe + stream->ps.phase_uf; i < EHCI_BANDWIDTH_SIZE; | ||
1356 | i += stream->ps.bw_uperiod) | ||
1357 | ehci->bandwidth[i] += usecs; | ||
1358 | |||
1359 | } else { /* Full speed */ | ||
1360 | s_mask = stream->ps.cs_mask; | ||
1361 | c_mask = s_mask >> 8; | ||
1362 | |||
1363 | /* NOTE: adjustment needed for frame overflow */ | ||
1364 | for (i = uframe; i < EHCI_BANDWIDTH_SIZE; | ||
1365 | i += stream->ps.bw_uperiod) { | ||
1366 | for ((j = stream->ps.phase_uf, m = 1 << j); j < 8; | ||
1367 | (++j, m <<= 1)) { | ||
1368 | if (s_mask & m) | ||
1369 | ehci->bandwidth[i+j] += usecs; | ||
1370 | else if (c_mask & m) | ||
1371 | ehci->bandwidth[i+j] += c_usecs; | ||
1372 | } | ||
1373 | } | ||
1374 | |||
1375 | tt = find_tt(stream->ps.udev); | ||
1376 | if (sign > 0) | ||
1377 | list_add_tail(&stream->ps.ps_list, &tt->ps_list); | ||
1378 | else | ||
1379 | list_del(&stream->ps.ps_list); | ||
1380 | |||
1381 | for (i = uframe >> 3; i < EHCI_BANDWIDTH_FRAMES; | ||
1382 | i += stream->ps.bw_period) | ||
1383 | tt->bandwidth[i] += tt_usecs; | ||
1384 | } | ||
1385 | } | ||
1386 | |||
1252 | static inline int | 1387 | static inline int |
1253 | itd_slot_ok ( | 1388 | itd_slot_ok ( |
1254 | struct ehci_hcd *ehci, | 1389 | struct ehci_hcd *ehci, |
1255 | u32 mod, | 1390 | struct ehci_iso_stream *stream, |
1256 | u32 uframe, | 1391 | unsigned uframe |
1257 | u8 usecs, | ||
1258 | u32 period | ||
1259 | ) | 1392 | ) |
1260 | { | 1393 | { |
1261 | uframe %= period; | 1394 | unsigned usecs; |
1262 | do { | 1395 | |
1263 | /* can't commit more than uframe_periodic_max usec */ | 1396 | /* convert "usecs we need" to "max already claimed" */ |
1264 | if (periodic_usecs (ehci, uframe >> 3, uframe & 0x7) | 1397 | usecs = ehci->uframe_periodic_max - stream->ps.usecs; |
1265 | > (ehci->uframe_periodic_max - usecs)) | ||
1266 | return 0; | ||
1267 | 1398 | ||
1268 | /* we know urb->interval is 2^N uframes */ | 1399 | for (uframe &= stream->ps.bw_uperiod - 1; uframe < EHCI_BANDWIDTH_SIZE; |
1269 | uframe += period; | 1400 | uframe += stream->ps.bw_uperiod) { |
1270 | } while (uframe < mod); | 1401 | if (ehci->bandwidth[uframe] > usecs) |
1402 | return 0; | ||
1403 | } | ||
1271 | return 1; | 1404 | return 1; |
1272 | } | 1405 | } |
1273 | 1406 | ||
1274 | static inline int | 1407 | static inline int |
1275 | sitd_slot_ok ( | 1408 | sitd_slot_ok ( |
1276 | struct ehci_hcd *ehci, | 1409 | struct ehci_hcd *ehci, |
1277 | u32 mod, | ||
1278 | struct ehci_iso_stream *stream, | 1410 | struct ehci_iso_stream *stream, |
1279 | u32 uframe, | 1411 | unsigned uframe, |
1280 | struct ehci_iso_sched *sched, | 1412 | struct ehci_iso_sched *sched, |
1281 | u32 period_uframes | 1413 | struct ehci_tt *tt |
1282 | ) | 1414 | ) |
1283 | { | 1415 | { |
1284 | u32 mask, tmp; | 1416 | unsigned mask, tmp; |
1285 | u32 frame, uf; | 1417 | unsigned frame, uf; |
1418 | |||
1419 | mask = stream->ps.cs_mask << (uframe & 7); | ||
1286 | 1420 | ||
1287 | mask = stream->raw_mask << (uframe & 7); | 1421 | /* for OUT, don't wrap SSPLIT into H-microframe 7 */ |
1422 | if (((stream->ps.cs_mask & 0xff) << (uframe & 7)) >= (1 << 7)) | ||
1423 | return 0; | ||
1288 | 1424 | ||
1289 | /* for IN, don't wrap CSPLIT into the next frame */ | 1425 | /* for IN, don't wrap CSPLIT into the next frame */ |
1290 | if (mask & ~0xffff) | 1426 | if (mask & ~0xffff) |
1291 | return 0; | 1427 | return 0; |
1292 | 1428 | ||
1293 | /* check bandwidth */ | 1429 | /* check bandwidth */ |
1294 | uframe %= period_uframes; | 1430 | uframe &= stream->ps.bw_uperiod - 1; |
1295 | frame = uframe >> 3; | 1431 | frame = uframe >> 3; |
1296 | 1432 | ||
1297 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED | 1433 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED |
@@ -1299,54 +1435,48 @@ sitd_slot_ok ( | |||
1299 | * tt_available scheduling guarantees 10+% for control/bulk. | 1435 | * tt_available scheduling guarantees 10+% for control/bulk. |
1300 | */ | 1436 | */ |
1301 | uf = uframe & 7; | 1437 | uf = uframe & 7; |
1302 | if (!tt_available(ehci, period_uframes >> 3, | 1438 | if (!tt_available(ehci, &stream->ps, tt, frame, uf)) |
1303 | stream->udev, frame, uf, stream->tt_usecs)) | ||
1304 | return 0; | 1439 | return 0; |
1305 | #else | 1440 | #else |
1306 | /* tt must be idle for start(s), any gap, and csplit. | 1441 | /* tt must be idle for start(s), any gap, and csplit. |
1307 | * assume scheduling slop leaves 10+% for control/bulk. | 1442 | * assume scheduling slop leaves 10+% for control/bulk. |
1308 | */ | 1443 | */ |
1309 | if (!tt_no_collision(ehci, period_uframes >> 3, | 1444 | if (!tt_no_collision(ehci, stream->ps.bw_period, |
1310 | stream->udev, frame, mask)) | 1445 | stream->ps.udev, frame, mask)) |
1311 | return 0; | 1446 | return 0; |
1312 | #endif | 1447 | #endif |
1313 | 1448 | ||
1314 | /* this multi-pass logic is simple, but performance may | ||
1315 | * suffer when the schedule data isn't cached. | ||
1316 | */ | ||
1317 | do { | 1449 | do { |
1318 | u32 max_used; | 1450 | unsigned max_used; |
1319 | 1451 | unsigned i; | |
1320 | frame = uframe >> 3; | ||
1321 | uf = uframe & 7; | ||
1322 | 1452 | ||
1323 | /* check starts (OUT uses more than one) */ | 1453 | /* check starts (OUT uses more than one) */ |
1324 | max_used = ehci->uframe_periodic_max - stream->usecs; | 1454 | uf = uframe; |
1325 | for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) { | 1455 | max_used = ehci->uframe_periodic_max - stream->ps.usecs; |
1326 | if (periodic_usecs (ehci, frame, uf) > max_used) | 1456 | for (tmp = stream->ps.cs_mask & 0xff; tmp; tmp >>= 1, uf++) { |
1457 | if (ehci->bandwidth[uf] > max_used) | ||
1327 | return 0; | 1458 | return 0; |
1328 | } | 1459 | } |
1329 | 1460 | ||
1330 | /* for IN, check CSPLIT */ | 1461 | /* for IN, check CSPLIT */ |
1331 | if (stream->c_usecs) { | 1462 | if (stream->ps.c_usecs) { |
1332 | uf = uframe & 7; | 1463 | max_used = ehci->uframe_periodic_max - |
1333 | max_used = ehci->uframe_periodic_max - stream->c_usecs; | 1464 | stream->ps.c_usecs; |
1334 | do { | 1465 | uf = uframe & ~7; |
1335 | tmp = 1 << uf; | 1466 | tmp = 1 << (2+8); |
1336 | tmp <<= 8; | 1467 | for (i = (uframe & 7) + 2; i < 8; (++i, tmp <<= 1)) { |
1337 | if ((stream->raw_mask & tmp) == 0) | 1468 | if ((stream->ps.cs_mask & tmp) == 0) |
1338 | continue; | 1469 | continue; |
1339 | if (periodic_usecs (ehci, frame, uf) | 1470 | if (ehci->bandwidth[uf+i] > max_used) |
1340 | > max_used) | ||
1341 | return 0; | 1471 | return 0; |
1342 | } while (++uf < 8); | 1472 | } |
1343 | } | 1473 | } |
1344 | 1474 | ||
1345 | /* we know urb->interval is 2^N uframes */ | 1475 | uframe += stream->ps.bw_uperiod; |
1346 | uframe += period_uframes; | 1476 | } while (uframe < EHCI_BANDWIDTH_SIZE); |
1347 | } while (uframe < mod); | ||
1348 | 1477 | ||
1349 | stream->splits = cpu_to_hc32(ehci, stream->raw_mask << (uframe & 7)); | 1478 | stream->ps.cs_mask <<= uframe & 7; |
1479 | stream->splits = cpu_to_hc32(ehci, stream->ps.cs_mask); | ||
1350 | return 1; | 1480 | return 1; |
1351 | } | 1481 | } |
1352 | 1482 | ||
@@ -1361,8 +1491,6 @@ sitd_slot_ok ( | |||
1361 | * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler! | 1491 | * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler! |
1362 | */ | 1492 | */ |
1363 | 1493 | ||
1364 | #define SCHEDULING_DELAY 40 /* microframes */ | ||
1365 | |||
1366 | static int | 1494 | static int |
1367 | iso_stream_schedule ( | 1495 | iso_stream_schedule ( |
1368 | struct ehci_hcd *ehci, | 1496 | struct ehci_hcd *ehci, |
@@ -1370,134 +1498,184 @@ iso_stream_schedule ( | |||
1370 | struct ehci_iso_stream *stream | 1498 | struct ehci_iso_stream *stream |
1371 | ) | 1499 | ) |
1372 | { | 1500 | { |
1373 | u32 now, base, next, start, period, span; | 1501 | u32 now, base, next, start, period, span, now2; |
1374 | int status; | 1502 | u32 wrap = 0, skip = 0; |
1503 | int status = 0; | ||
1375 | unsigned mod = ehci->periodic_size << 3; | 1504 | unsigned mod = ehci->periodic_size << 3; |
1376 | struct ehci_iso_sched *sched = urb->hcpriv; | 1505 | struct ehci_iso_sched *sched = urb->hcpriv; |
1506 | bool empty = list_empty(&stream->td_list); | ||
1507 | bool new_stream = false; | ||
1377 | 1508 | ||
1378 | period = urb->interval; | 1509 | period = stream->uperiod; |
1379 | span = sched->span; | 1510 | span = sched->span; |
1380 | if (!stream->highspeed) { | 1511 | if (!stream->highspeed) |
1381 | period <<= 3; | ||
1382 | span <<= 3; | 1512 | span <<= 3; |
1383 | } | ||
1384 | 1513 | ||
1385 | now = ehci_read_frame_index(ehci) & (mod - 1); | 1514 | /* Start a new isochronous stream? */ |
1515 | if (unlikely(empty && !hcd_periodic_completion_in_progress( | ||
1516 | ehci_to_hcd(ehci), urb->ep))) { | ||
1386 | 1517 | ||
1387 | /* Typical case: reuse current schedule, stream is still active. | 1518 | /* Schedule the endpoint */ |
1388 | * Hopefully there are no gaps from the host falling behind | 1519 | if (stream->ps.phase == NO_FRAME) { |
1389 | * (irq delays etc). If there are, the behavior depends on | 1520 | int done = 0; |
1390 | * whether URB_ISO_ASAP is set. | 1521 | struct ehci_tt *tt = find_tt(stream->ps.udev); |
1391 | */ | ||
1392 | if (likely (!list_empty (&stream->td_list))) { | ||
1393 | 1522 | ||
1394 | /* Take the isochronous scheduling threshold into account */ | 1523 | if (IS_ERR(tt)) { |
1395 | if (ehci->i_thresh) | 1524 | status = PTR_ERR(tt); |
1396 | next = now + ehci->i_thresh; /* uframe cache */ | 1525 | goto fail; |
1397 | else | 1526 | } |
1398 | next = (now + 2 + 7) & ~0x07; /* full frame cache */ | 1527 | compute_tt_budget(ehci->tt_budget, tt); |
1399 | |||
1400 | /* | ||
1401 | * Use ehci->last_iso_frame as the base. There can't be any | ||
1402 | * TDs scheduled for earlier than that. | ||
1403 | */ | ||
1404 | base = ehci->last_iso_frame << 3; | ||
1405 | next = (next - base) & (mod - 1); | ||
1406 | start = (stream->next_uframe - base) & (mod - 1); | ||
1407 | |||
1408 | /* Is the schedule already full? */ | ||
1409 | if (unlikely(start < period)) { | ||
1410 | ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n", | ||
1411 | urb, stream->next_uframe, base, | ||
1412 | period, mod); | ||
1413 | status = -ENOSPC; | ||
1414 | goto fail; | ||
1415 | } | ||
1416 | |||
1417 | /* Behind the scheduling threshold? */ | ||
1418 | if (unlikely(start < next)) { | ||
1419 | unsigned now2 = (now - base) & (mod - 1); | ||
1420 | 1528 | ||
1421 | /* USB_ISO_ASAP: Round up to the first available slot */ | 1529 | start = ((-(++ehci->random_frame)) << 3) & (period - 1); |
1422 | if (urb->transfer_flags & URB_ISO_ASAP) | ||
1423 | start += (next - start + period - 1) & -period; | ||
1424 | 1530 | ||
1425 | /* | 1531 | /* find a uframe slot with enough bandwidth. |
1426 | * Not ASAP: Use the next slot in the stream, | 1532 | * Early uframes are more precious because full-speed |
1427 | * no matter what. | 1533 | * iso IN transfers can't use late uframes, |
1534 | * and therefore they should be allocated last. | ||
1428 | */ | 1535 | */ |
1429 | else if (start + span - period < now2) { | 1536 | next = start; |
1430 | ehci_dbg(ehci, "iso underrun %p (%u+%u < %u)\n", | 1537 | start += period; |
1431 | urb, start + base, | 1538 | do { |
1432 | span - period, now2 + base); | 1539 | start--; |
1540 | /* check schedule: enough space? */ | ||
1541 | if (stream->highspeed) { | ||
1542 | if (itd_slot_ok(ehci, stream, start)) | ||
1543 | done = 1; | ||
1544 | } else { | ||
1545 | if ((start % 8) >= 6) | ||
1546 | continue; | ||
1547 | if (sitd_slot_ok(ehci, stream, start, | ||
1548 | sched, tt)) | ||
1549 | done = 1; | ||
1550 | } | ||
1551 | } while (start > next && !done); | ||
1552 | |||
1553 | /* no room in the schedule */ | ||
1554 | if (!done) { | ||
1555 | ehci_dbg(ehci, "iso sched full %p", urb); | ||
1556 | status = -ENOSPC; | ||
1557 | goto fail; | ||
1433 | } | 1558 | } |
1559 | stream->ps.phase = (start >> 3) & | ||
1560 | (stream->ps.period - 1); | ||
1561 | stream->ps.bw_phase = stream->ps.phase & | ||
1562 | (stream->ps.bw_period - 1); | ||
1563 | stream->ps.phase_uf = start & 7; | ||
1564 | reserve_release_iso_bandwidth(ehci, stream, 1); | ||
1565 | } | ||
1566 | |||
1567 | /* New stream is already scheduled; use the upcoming slot */ | ||
1568 | else { | ||
1569 | start = (stream->ps.phase << 3) + stream->ps.phase_uf; | ||
1434 | } | 1570 | } |
1435 | 1571 | ||
1436 | start += base; | 1572 | stream->next_uframe = start; |
1573 | new_stream = true; | ||
1437 | } | 1574 | } |
1438 | 1575 | ||
1439 | /* need to schedule; when's the next (u)frame we could start? | 1576 | now = ehci_read_frame_index(ehci) & (mod - 1); |
1440 | * this is bigger than ehci->i_thresh allows; scheduling itself | 1577 | |
1441 | * isn't free, the delay should handle reasonably slow cpus. it | 1578 | /* Take the isochronous scheduling threshold into account */ |
1442 | * can also help high bandwidth if the dma and irq loads don't | 1579 | if (ehci->i_thresh) |
1443 | * jump until after the queue is primed. | 1580 | next = now + ehci->i_thresh; /* uframe cache */ |
1581 | else | ||
1582 | next = (now + 2 + 7) & ~0x07; /* full frame cache */ | ||
1583 | |||
1584 | /* | ||
1585 | * Use ehci->last_iso_frame as the base. There can't be any | ||
1586 | * TDs scheduled for earlier than that. | ||
1444 | */ | 1587 | */ |
1445 | else { | 1588 | base = ehci->last_iso_frame << 3; |
1446 | int done = 0; | 1589 | next = (next - base) & (mod - 1); |
1590 | start = (stream->next_uframe - base) & (mod - 1); | ||
1447 | 1591 | ||
1448 | base = now & ~0x07; | 1592 | if (unlikely(new_stream)) |
1449 | start = base + SCHEDULING_DELAY; | 1593 | goto do_ASAP; |
1450 | 1594 | ||
1451 | /* find a uframe slot with enough bandwidth. | 1595 | /* |
1452 | * Early uframes are more precious because full-speed | 1596 | * Typical case: reuse current schedule, stream may still be active. |
1453 | * iso IN transfers can't use late uframes, | 1597 | * Hopefully there are no gaps from the host falling behind |
1454 | * and therefore they should be allocated last. | 1598 | * (irq delays etc). If there are, the behavior depends on |
1455 | */ | 1599 | * whether URB_ISO_ASAP is set. |
1456 | next = start; | 1600 | */ |
1457 | start += period; | 1601 | now2 = (now - base) & (mod - 1); |
1458 | do { | 1602 | |
1459 | start--; | 1603 | /* Is the schedule already full? */ |
1460 | /* check schedule: enough space? */ | 1604 | if (unlikely(!empty && start < period)) { |
1461 | if (stream->highspeed) { | 1605 | ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n", |
1462 | if (itd_slot_ok(ehci, mod, start, | 1606 | urb, stream->next_uframe, base, period, mod); |
1463 | stream->usecs, period)) | 1607 | status = -ENOSPC; |
1464 | done = 1; | 1608 | goto fail; |
1465 | } else { | 1609 | } |
1466 | if ((start % 8) >= 6) | 1610 | |
1467 | continue; | 1611 | /* Is the next packet scheduled after the base time? */ |
1468 | if (sitd_slot_ok(ehci, mod, stream, | 1612 | if (likely(!empty || start <= now2 + period)) { |
1469 | start, sched, period)) | 1613 | |
1470 | done = 1; | 1614 | /* URB_ISO_ASAP: make sure that start >= next */ |
1471 | } | 1615 | if (unlikely(start < next && |
1472 | } while (start > next && !done); | 1616 | (urb->transfer_flags & URB_ISO_ASAP))) |
1617 | goto do_ASAP; | ||
1618 | |||
1619 | /* Otherwise use start, if it's not in the past */ | ||
1620 | if (likely(start >= now2)) | ||
1621 | goto use_start; | ||
1473 | 1622 | ||
1474 | /* no room in the schedule */ | 1623 | /* Otherwise we got an underrun while the queue was empty */ |
1475 | if (!done) { | 1624 | } else { |
1476 | ehci_dbg(ehci, "iso sched full %p", urb); | 1625 | if (urb->transfer_flags & URB_ISO_ASAP) |
1477 | status = -ENOSPC; | 1626 | goto do_ASAP; |
1478 | goto fail; | 1627 | wrap = mod; |
1628 | now2 += mod; | ||
1629 | } | ||
1630 | |||
1631 | /* How many uframes and packets do we need to skip? */ | ||
1632 | skip = (now2 - start + period - 1) & -period; | ||
1633 | if (skip >= span) { /* Entirely in the past? */ | ||
1634 | ehci_dbg(ehci, "iso underrun %p (%u+%u < %u) [%u]\n", | ||
1635 | urb, start + base, span - period, now2 + base, | ||
1636 | base); | ||
1637 | |||
1638 | /* Try to keep the last TD intact for scanning later */ | ||
1639 | skip = span - period; | ||
1640 | |||
1641 | /* Will it come before the current scan position? */ | ||
1642 | if (empty) { | ||
1643 | skip = span; /* Skip the entire URB */ | ||
1644 | status = 1; /* and give it back immediately */ | ||
1645 | iso_sched_free(stream, sched); | ||
1646 | sched = NULL; | ||
1479 | } | 1647 | } |
1480 | } | 1648 | } |
1649 | urb->error_count = skip / period; | ||
1650 | if (sched) | ||
1651 | sched->first_packet = urb->error_count; | ||
1652 | goto use_start; | ||
1481 | 1653 | ||
1654 | do_ASAP: | ||
1655 | /* Use the first slot after "next" */ | ||
1656 | start = next + ((start - next) & (period - 1)); | ||
1657 | |||
1658 | use_start: | ||
1482 | /* Tried to schedule too far into the future? */ | 1659 | /* Tried to schedule too far into the future? */ |
1483 | if (unlikely(start - base + span - period >= mod)) { | 1660 | if (unlikely(start + span - period >= mod + wrap)) { |
1484 | ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n", | 1661 | ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n", |
1485 | urb, start - base, span - period, mod); | 1662 | urb, start, span - period, mod + wrap); |
1486 | status = -EFBIG; | 1663 | status = -EFBIG; |
1487 | goto fail; | 1664 | goto fail; |
1488 | } | 1665 | } |
1489 | 1666 | ||
1490 | stream->next_uframe = start & (mod - 1); | 1667 | start += base; |
1668 | stream->next_uframe = (start + skip) & (mod - 1); | ||
1491 | 1669 | ||
1492 | /* report high speed start in uframes; full speed, in frames */ | 1670 | /* report high speed start in uframes; full speed, in frames */ |
1493 | urb->start_frame = stream->next_uframe; | 1671 | urb->start_frame = start & (mod - 1); |
1494 | if (!stream->highspeed) | 1672 | if (!stream->highspeed) |
1495 | urb->start_frame >>= 3; | 1673 | urb->start_frame >>= 3; |
1496 | 1674 | ||
1497 | /* Make sure scan_isoc() sees these */ | 1675 | /* Make sure scan_isoc() sees these */ |
1498 | if (ehci->isoc_count == 0) | 1676 | if (ehci->isoc_count == 0) |
1499 | ehci->last_iso_frame = now >> 3; | 1677 | ehci->last_iso_frame = now >> 3; |
1500 | return 0; | 1678 | return status; |
1501 | 1679 | ||
1502 | fail: | 1680 | fail: |
1503 | iso_sched_free(stream, sched); | 1681 | iso_sched_free(stream, sched); |
@@ -1610,7 +1788,8 @@ static void itd_link_urb( | |||
1610 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 1788 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
1611 | 1789 | ||
1612 | /* fill iTDs uframe by uframe */ | 1790 | /* fill iTDs uframe by uframe */ |
1613 | for (packet = 0, itd = NULL; packet < urb->number_of_packets; ) { | 1791 | for (packet = iso_sched->first_packet, itd = NULL; |
1792 | packet < urb->number_of_packets;) { | ||
1614 | if (itd == NULL) { | 1793 | if (itd == NULL) { |
1615 | /* ASSERT: we have all necessary itds */ | 1794 | /* ASSERT: we have all necessary itds */ |
1616 | // BUG_ON (list_empty (&iso_sched->td_list)); | 1795 | // BUG_ON (list_empty (&iso_sched->td_list)); |
@@ -1630,7 +1809,7 @@ static void itd_link_urb( | |||
1630 | 1809 | ||
1631 | itd_patch(ehci, itd, iso_sched, packet, uframe); | 1810 | itd_patch(ehci, itd, iso_sched, packet, uframe); |
1632 | 1811 | ||
1633 | next_uframe += stream->interval; | 1812 | next_uframe += stream->uperiod; |
1634 | next_uframe &= mod - 1; | 1813 | next_uframe &= mod - 1; |
1635 | packet++; | 1814 | packet++; |
1636 | 1815 | ||
@@ -1770,9 +1949,9 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb, | |||
1770 | ehci_dbg (ehci, "can't get iso stream\n"); | 1949 | ehci_dbg (ehci, "can't get iso stream\n"); |
1771 | return -ENOMEM; | 1950 | return -ENOMEM; |
1772 | } | 1951 | } |
1773 | if (unlikely (urb->interval != stream->interval)) { | 1952 | if (unlikely(urb->interval != stream->uperiod)) { |
1774 | ehci_dbg (ehci, "can't change iso interval %d --> %d\n", | 1953 | ehci_dbg (ehci, "can't change iso interval %d --> %d\n", |
1775 | stream->interval, urb->interval); | 1954 | stream->uperiod, urb->interval); |
1776 | goto done; | 1955 | goto done; |
1777 | } | 1956 | } |
1778 | 1957 | ||
@@ -1804,10 +1983,14 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb, | |||
1804 | if (unlikely(status)) | 1983 | if (unlikely(status)) |
1805 | goto done_not_linked; | 1984 | goto done_not_linked; |
1806 | status = iso_stream_schedule(ehci, urb, stream); | 1985 | status = iso_stream_schedule(ehci, urb, stream); |
1807 | if (likely (status == 0)) | 1986 | if (likely(status == 0)) { |
1808 | itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); | 1987 | itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); |
1809 | else | 1988 | } else if (status > 0) { |
1989 | status = 0; | ||
1990 | ehci_urb_done(ehci, urb, 0); | ||
1991 | } else { | ||
1810 | usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); | 1992 | usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); |
1993 | } | ||
1811 | done_not_linked: | 1994 | done_not_linked: |
1812 | spin_unlock_irqrestore (&ehci->lock, flags); | 1995 | spin_unlock_irqrestore (&ehci->lock, flags); |
1813 | done: | 1996 | done: |
@@ -1833,7 +2016,7 @@ sitd_sched_init( | |||
1833 | dma_addr_t dma = urb->transfer_dma; | 2016 | dma_addr_t dma = urb->transfer_dma; |
1834 | 2017 | ||
1835 | /* how many frames are needed for these transfers */ | 2018 | /* how many frames are needed for these transfers */ |
1836 | iso_sched->span = urb->number_of_packets * stream->interval; | 2019 | iso_sched->span = urb->number_of_packets * stream->ps.period; |
1837 | 2020 | ||
1838 | /* figure out per-frame sitd fields that we'll need later | 2021 | /* figure out per-frame sitd fields that we'll need later |
1839 | * when we fit new sitds into the schedule. | 2022 | * when we fit new sitds into the schedule. |
@@ -1925,7 +2108,7 @@ sitd_urb_transaction ( | |||
1925 | 2108 | ||
1926 | memset (sitd, 0, sizeof *sitd); | 2109 | memset (sitd, 0, sizeof *sitd); |
1927 | sitd->sitd_dma = sitd_dma; | 2110 | sitd->sitd_dma = sitd_dma; |
1928 | sitd->frame = 9999; /* an invalid value */ | 2111 | sitd->frame = NO_FRAME; |
1929 | list_add (&sitd->sitd_list, &iso_sched->td_list); | 2112 | list_add (&sitd->sitd_list, &iso_sched->td_list); |
1930 | } | 2113 | } |
1931 | 2114 | ||
@@ -2008,7 +2191,7 @@ static void sitd_link_urb( | |||
2008 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 2191 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
2009 | 2192 | ||
2010 | /* fill sITDs frame by frame */ | 2193 | /* fill sITDs frame by frame */ |
2011 | for (packet = 0, sitd = NULL; | 2194 | for (packet = sched->first_packet, sitd = NULL; |
2012 | packet < urb->number_of_packets; | 2195 | packet < urb->number_of_packets; |
2013 | packet++) { | 2196 | packet++) { |
2014 | 2197 | ||
@@ -2027,7 +2210,7 @@ static void sitd_link_urb( | |||
2027 | sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1), | 2210 | sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1), |
2028 | sitd); | 2211 | sitd); |
2029 | 2212 | ||
2030 | next_uframe += stream->interval << 3; | 2213 | next_uframe += stream->uperiod; |
2031 | } | 2214 | } |
2032 | stream->next_uframe = next_uframe & (mod - 1); | 2215 | stream->next_uframe = next_uframe & (mod - 1); |
2033 | 2216 | ||
@@ -2146,9 +2329,9 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, | |||
2146 | ehci_dbg (ehci, "can't get iso stream\n"); | 2329 | ehci_dbg (ehci, "can't get iso stream\n"); |
2147 | return -ENOMEM; | 2330 | return -ENOMEM; |
2148 | } | 2331 | } |
2149 | if (urb->interval != stream->interval) { | 2332 | if (urb->interval != stream->ps.period) { |
2150 | ehci_dbg (ehci, "can't change iso interval %d --> %d\n", | 2333 | ehci_dbg (ehci, "can't change iso interval %d --> %d\n", |
2151 | stream->interval, urb->interval); | 2334 | stream->ps.period, urb->interval); |
2152 | goto done; | 2335 | goto done; |
2153 | } | 2336 | } |
2154 | 2337 | ||
@@ -2178,10 +2361,14 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, | |||
2178 | if (unlikely(status)) | 2361 | if (unlikely(status)) |
2179 | goto done_not_linked; | 2362 | goto done_not_linked; |
2180 | status = iso_stream_schedule(ehci, urb, stream); | 2363 | status = iso_stream_schedule(ehci, urb, stream); |
2181 | if (status == 0) | 2364 | if (likely(status == 0)) { |
2182 | sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); | 2365 | sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); |
2183 | else | 2366 | } else if (status > 0) { |
2367 | status = 0; | ||
2368 | ehci_urb_done(ehci, urb, 0); | ||
2369 | } else { | ||
2184 | usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); | 2370 | usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); |
2371 | } | ||
2185 | done_not_linked: | 2372 | done_not_linked: |
2186 | spin_unlock_irqrestore (&ehci->lock, flags); | 2373 | spin_unlock_irqrestore (&ehci->lock, flags); |
2187 | done: | 2374 | done: |
@@ -2259,7 +2446,8 @@ restart: | |||
2259 | q.itd->hw_next != EHCI_LIST_END(ehci)) | 2446 | q.itd->hw_next != EHCI_LIST_END(ehci)) |
2260 | *hw_p = q.itd->hw_next; | 2447 | *hw_p = q.itd->hw_next; |
2261 | else | 2448 | else |
2262 | *hw_p = ehci->dummy->qh_dma; | 2449 | *hw_p = cpu_to_hc32(ehci, |
2450 | ehci->dummy->qh_dma); | ||
2263 | type = Q_NEXT_TYPE(ehci, q.itd->hw_next); | 2451 | type = Q_NEXT_TYPE(ehci, q.itd->hw_next); |
2264 | wmb(); | 2452 | wmb(); |
2265 | modified = itd_complete (ehci, q.itd); | 2453 | modified = itd_complete (ehci, q.itd); |
@@ -2294,7 +2482,8 @@ restart: | |||
2294 | q.sitd->hw_next != EHCI_LIST_END(ehci)) | 2482 | q.sitd->hw_next != EHCI_LIST_END(ehci)) |
2295 | *hw_p = q.sitd->hw_next; | 2483 | *hw_p = q.sitd->hw_next; |
2296 | else | 2484 | else |
2297 | *hw_p = ehci->dummy->qh_dma; | 2485 | *hw_p = cpu_to_hc32(ehci, |
2486 | ehci->dummy->qh_dma); | ||
2298 | type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); | 2487 | type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); |
2299 | wmb(); | 2488 | wmb(); |
2300 | modified = sitd_complete (ehci, q.sitd); | 2489 | modified = sitd_complete (ehci, q.sitd); |
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c index b2de52d39614..8a734498079b 100644 --- a/drivers/usb/host/ehci-sead3.c +++ b/drivers/usb/host/ehci-sead3.c | |||
@@ -55,7 +55,7 @@ const struct hc_driver ehci_sead3_hc_driver = { | |||
55 | * generic hardware linkage | 55 | * generic hardware linkage |
56 | */ | 56 | */ |
57 | .irq = ehci_irq, | 57 | .irq = ehci_irq, |
58 | .flags = HCD_MEMORY | HCD_USB2, | 58 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
59 | 59 | ||
60 | /* | 60 | /* |
61 | * basic lifecycle operations | 61 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c index 93e59a13bc1f..dc899eb2b861 100644 --- a/drivers/usb/host/ehci-sh.c +++ b/drivers/usb/host/ehci-sh.c | |||
@@ -36,7 +36,7 @@ static const struct hc_driver ehci_sh_hc_driver = { | |||
36 | * generic hardware linkage | 36 | * generic hardware linkage |
37 | */ | 37 | */ |
38 | .irq = ehci_irq, | 38 | .irq = ehci_irq, |
39 | .flags = HCD_USB2 | HCD_MEMORY, | 39 | .flags = HCD_USB2 | HCD_MEMORY | HCD_BH, |
40 | 40 | ||
41 | /* | 41 | /* |
42 | * basic lifecycle operations | 42 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci-sysfs.c b/drivers/usb/host/ehci-sysfs.c index 14ced00ba220..f6459dfb6f54 100644 --- a/drivers/usb/host/ehci-sysfs.c +++ b/drivers/usb/host/ehci-sysfs.c | |||
@@ -97,8 +97,7 @@ static ssize_t store_uframe_periodic_max(struct device *dev, | |||
97 | { | 97 | { |
98 | struct ehci_hcd *ehci; | 98 | struct ehci_hcd *ehci; |
99 | unsigned uframe_periodic_max; | 99 | unsigned uframe_periodic_max; |
100 | unsigned frame, uframe; | 100 | unsigned uframe; |
101 | unsigned short allocated_max; | ||
102 | unsigned long flags; | 101 | unsigned long flags; |
103 | ssize_t ret; | 102 | ssize_t ret; |
104 | 103 | ||
@@ -122,16 +121,14 @@ static ssize_t store_uframe_periodic_max(struct device *dev, | |||
122 | 121 | ||
123 | /* | 122 | /* |
124 | * for request to decrease max periodic bandwidth, we have to check | 123 | * for request to decrease max periodic bandwidth, we have to check |
125 | * every microframe in the schedule to see whether the decrease is | 124 | * to see whether the decrease is possible. |
126 | * possible. | ||
127 | */ | 125 | */ |
128 | if (uframe_periodic_max < ehci->uframe_periodic_max) { | 126 | if (uframe_periodic_max < ehci->uframe_periodic_max) { |
129 | allocated_max = 0; | 127 | u8 allocated_max = 0; |
130 | 128 | ||
131 | for (frame = 0; frame < ehci->periodic_size; ++frame) | 129 | for (uframe = 0; uframe < EHCI_BANDWIDTH_SIZE; ++uframe) |
132 | for (uframe = 0; uframe < 7; ++uframe) | 130 | allocated_max = max(allocated_max, |
133 | allocated_max = max(allocated_max, | 131 | ehci->bandwidth[uframe]); |
134 | periodic_usecs (ehci, frame, uframe)); | ||
135 | 132 | ||
136 | if (allocated_max > uframe_periodic_max) { | 133 | if (allocated_max > uframe_periodic_max) { |
137 | ehci_info(ehci, | 134 | ehci_info(ehci, |
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 78fa76da3324..e6d8e26e48cc 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -388,7 +388,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
388 | 388 | ||
389 | err = clk_prepare_enable(tegra->clk); | 389 | err = clk_prepare_enable(tegra->clk); |
390 | if (err) | 390 | if (err) |
391 | goto cleanup_clk_get; | 391 | goto cleanup_hcd_create; |
392 | 392 | ||
393 | tegra_periph_reset_assert(tegra->clk); | 393 | tegra_periph_reset_assert(tegra->clk); |
394 | udelay(1); | 394 | udelay(1); |
@@ -465,8 +465,6 @@ cleanup_phy: | |||
465 | usb_phy_shutdown(hcd->phy); | 465 | usb_phy_shutdown(hcd->phy); |
466 | cleanup_clk_en: | 466 | cleanup_clk_en: |
467 | clk_disable_unprepare(tegra->clk); | 467 | clk_disable_unprepare(tegra->clk); |
468 | cleanup_clk_get: | ||
469 | clk_put(tegra->clk); | ||
470 | cleanup_hcd_create: | 468 | cleanup_hcd_create: |
471 | usb_put_hcd(hcd); | 469 | usb_put_hcd(hcd); |
472 | return err; | 470 | return err; |
diff --git a/drivers/usb/host/ehci-tilegx.c b/drivers/usb/host/ehci-tilegx.c index cca4be90a864..67026ffbf9a8 100644 --- a/drivers/usb/host/ehci-tilegx.c +++ b/drivers/usb/host/ehci-tilegx.c | |||
@@ -61,7 +61,7 @@ static const struct hc_driver ehci_tilegx_hc_driver = { | |||
61 | * Generic hardware linkage. | 61 | * Generic hardware linkage. |
62 | */ | 62 | */ |
63 | .irq = ehci_irq, | 63 | .irq = ehci_irq, |
64 | .flags = HCD_MEMORY | HCD_USB2, | 64 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * Basic lifecycle operations. | 67 | * Basic lifecycle operations. |
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c index 59e0e24c753f..cdad8438c02b 100644 --- a/drivers/usb/host/ehci-w90x900.c +++ b/drivers/usb/host/ehci-w90x900.c | |||
@@ -11,13 +11,28 @@ | |||
11 | * | 11 | * |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/dma-mapping.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/of.h> | ||
14 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
20 | #include <linux/usb.h> | ||
21 | #include <linux/usb/hcd.h> | ||
22 | |||
23 | #include "ehci.h" | ||
15 | 24 | ||
16 | /* enable phy0 and phy1 for w90p910 */ | 25 | /* enable phy0 and phy1 for w90p910 */ |
17 | #define ENPHY (0x01<<8) | 26 | #define ENPHY (0x01<<8) |
18 | #define PHY0_CTR (0xA4) | 27 | #define PHY0_CTR (0xA4) |
19 | #define PHY1_CTR (0xA8) | 28 | #define PHY1_CTR (0xA8) |
20 | 29 | ||
30 | #define DRIVER_DESC "EHCI w90x900 driver" | ||
31 | |||
32 | static const char hcd_name[] = "ehci-w90x900 "; | ||
33 | |||
34 | static struct hc_driver __read_mostly ehci_w90x900_hc_driver; | ||
35 | |||
21 | static int usb_w90x900_probe(const struct hc_driver *driver, | 36 | static int usb_w90x900_probe(const struct hc_driver *driver, |
22 | struct platform_device *pdev) | 37 | struct platform_device *pdev) |
23 | { | 38 | { |
@@ -90,8 +105,8 @@ err1: | |||
90 | return retval; | 105 | return retval; |
91 | } | 106 | } |
92 | 107 | ||
93 | static | 108 | static void usb_w90x900_remove(struct usb_hcd *hcd, |
94 | void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev) | 109 | struct platform_device *pdev) |
95 | { | 110 | { |
96 | usb_remove_hcd(hcd); | 111 | usb_remove_hcd(hcd); |
97 | iounmap(hcd->regs); | 112 | iounmap(hcd->regs); |
@@ -99,54 +114,6 @@ void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev) | |||
99 | usb_put_hcd(hcd); | 114 | usb_put_hcd(hcd); |
100 | } | 115 | } |
101 | 116 | ||
102 | static const struct hc_driver ehci_w90x900_hc_driver = { | ||
103 | .description = hcd_name, | ||
104 | .product_desc = "Nuvoton w90x900 EHCI Host Controller", | ||
105 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
106 | |||
107 | /* | ||
108 | * generic hardware linkage | ||
109 | */ | ||
110 | .irq = ehci_irq, | ||
111 | .flags = HCD_USB2|HCD_MEMORY, | ||
112 | |||
113 | /* | ||
114 | * basic lifecycle operations | ||
115 | */ | ||
116 | .reset = ehci_setup, | ||
117 | .start = ehci_run, | ||
118 | |||
119 | .stop = ehci_stop, | ||
120 | .shutdown = ehci_shutdown, | ||
121 | |||
122 | /* | ||
123 | * managing i/o requests and associated device resources | ||
124 | */ | ||
125 | .urb_enqueue = ehci_urb_enqueue, | ||
126 | .urb_dequeue = ehci_urb_dequeue, | ||
127 | .endpoint_disable = ehci_endpoint_disable, | ||
128 | .endpoint_reset = ehci_endpoint_reset, | ||
129 | |||
130 | /* | ||
131 | * scheduling support | ||
132 | */ | ||
133 | .get_frame_number = ehci_get_frame, | ||
134 | |||
135 | /* | ||
136 | * root hub support | ||
137 | */ | ||
138 | .hub_status_data = ehci_hub_status_data, | ||
139 | .hub_control = ehci_hub_control, | ||
140 | #ifdef CONFIG_PM | ||
141 | .bus_suspend = ehci_bus_suspend, | ||
142 | .bus_resume = ehci_bus_resume, | ||
143 | #endif | ||
144 | .relinquish_port = ehci_relinquish_port, | ||
145 | .port_handed_over = ehci_port_handed_over, | ||
146 | |||
147 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
148 | }; | ||
149 | |||
150 | static int ehci_w90x900_probe(struct platform_device *pdev) | 117 | static int ehci_w90x900_probe(struct platform_device *pdev) |
151 | { | 118 | { |
152 | if (usb_disabled()) | 119 | if (usb_disabled()) |
@@ -173,7 +140,25 @@ static struct platform_driver ehci_hcd_w90x900_driver = { | |||
173 | }, | 140 | }, |
174 | }; | 141 | }; |
175 | 142 | ||
143 | static int __init ehci_w90X900_init(void) | ||
144 | { | ||
145 | if (usb_disabled()) | ||
146 | return -ENODEV; | ||
147 | |||
148 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
149 | |||
150 | ehci_init_driver(&ehci_w90x900_hc_driver, NULL); | ||
151 | return platform_driver_register(&ehci_hcd_w90x900_driver); | ||
152 | } | ||
153 | module_init(ehci_w90X900_init); | ||
154 | |||
155 | static void __exit ehci_w90X900_cleanup(void) | ||
156 | { | ||
157 | platform_driver_unregister(&ehci_hcd_w90x900_driver); | ||
158 | } | ||
159 | module_exit(ehci_w90X900_cleanup); | ||
160 | |||
161 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
176 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); | 162 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); |
177 | MODULE_DESCRIPTION("w90p910 usb ehci driver!"); | ||
178 | MODULE_LICENSE("GPL"); | ||
179 | MODULE_ALIAS("platform:w90p910-ehci"); | 163 | MODULE_ALIAS("platform:w90p910-ehci"); |
164 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c index eba962e6ebfb..95979f9f4381 100644 --- a/drivers/usb/host/ehci-xilinx-of.c +++ b/drivers/usb/host/ehci-xilinx-of.c | |||
@@ -79,7 +79,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = { | |||
79 | * generic hardware linkage | 79 | * generic hardware linkage |
80 | */ | 80 | */ |
81 | .irq = ehci_irq, | 81 | .irq = ehci_irq, |
82 | .flags = HCD_MEMORY | HCD_USB2, | 82 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * basic lifecycle operations | 85 | * basic lifecycle operations |
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 291db7d09f22..e8f41c5e771b 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -54,6 +54,28 @@ struct ehci_stats { | |||
54 | unsigned long unlink; | 54 | unsigned long unlink; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | /* | ||
58 | * Scheduling and budgeting information for periodic transfers, for both | ||
59 | * high-speed devices and full/low-speed devices lying behind a TT. | ||
60 | */ | ||
61 | struct ehci_per_sched { | ||
62 | struct usb_device *udev; /* access to the TT */ | ||
63 | struct usb_host_endpoint *ep; | ||
64 | struct list_head ps_list; /* node on ehci_tt's ps_list */ | ||
65 | u16 tt_usecs; /* time on the FS/LS bus */ | ||
66 | u16 cs_mask; /* C-mask and S-mask bytes */ | ||
67 | u16 period; /* actual period in frames */ | ||
68 | u16 phase; /* actual phase, frame part */ | ||
69 | u8 bw_phase; /* same, for bandwidth | ||
70 | reservation */ | ||
71 | u8 phase_uf; /* uframe part of the phase */ | ||
72 | u8 usecs, c_usecs; /* times on the HS bus */ | ||
73 | u8 bw_uperiod; /* period in microframes, for | ||
74 | bandwidth reservation */ | ||
75 | u8 bw_period; /* same, in frames */ | ||
76 | }; | ||
77 | #define NO_FRAME 29999 /* frame not assigned yet */ | ||
78 | |||
57 | /* ehci_hcd->lock guards shared data against other CPUs: | 79 | /* ehci_hcd->lock guards shared data against other CPUs: |
58 | * ehci_hcd: async, unlink, periodic (and shadow), ... | 80 | * ehci_hcd: async, unlink, periodic (and shadow), ... |
59 | * usb_host_endpoint: hcpriv | 81 | * usb_host_endpoint: hcpriv |
@@ -230,6 +252,15 @@ struct ehci_hcd { /* one per controller */ | |||
230 | struct dentry *debug_dir; | 252 | struct dentry *debug_dir; |
231 | #endif | 253 | #endif |
232 | 254 | ||
255 | /* bandwidth usage */ | ||
256 | #define EHCI_BANDWIDTH_SIZE 64 | ||
257 | #define EHCI_BANDWIDTH_FRAMES (EHCI_BANDWIDTH_SIZE >> 3) | ||
258 | u8 bandwidth[EHCI_BANDWIDTH_SIZE]; | ||
259 | /* us allocated per uframe */ | ||
260 | u8 tt_budget[EHCI_BANDWIDTH_SIZE]; | ||
261 | /* us budgeted per uframe */ | ||
262 | struct list_head tt_list; | ||
263 | |||
233 | /* platform-specific data -- must come last */ | 264 | /* platform-specific data -- must come last */ |
234 | unsigned long priv[0] __aligned(sizeof(s64)); | 265 | unsigned long priv[0] __aligned(sizeof(s64)); |
235 | }; | 266 | }; |
@@ -385,6 +416,7 @@ struct ehci_qh { | |||
385 | struct list_head intr_node; /* list of intr QHs */ | 416 | struct list_head intr_node; /* list of intr QHs */ |
386 | struct ehci_qtd *dummy; | 417 | struct ehci_qtd *dummy; |
387 | struct list_head unlink_node; | 418 | struct list_head unlink_node; |
419 | struct ehci_per_sched ps; /* scheduling info */ | ||
388 | 420 | ||
389 | unsigned unlink_cycle; | 421 | unsigned unlink_cycle; |
390 | 422 | ||
@@ -398,16 +430,8 @@ struct ehci_qh { | |||
398 | u8 xacterrs; /* XactErr retry counter */ | 430 | u8 xacterrs; /* XactErr retry counter */ |
399 | #define QH_XACTERR_MAX 32 /* XactErr retry limit */ | 431 | #define QH_XACTERR_MAX 32 /* XactErr retry limit */ |
400 | 432 | ||
401 | /* periodic schedule info */ | ||
402 | u8 usecs; /* intr bandwidth */ | ||
403 | u8 gap_uf; /* uframes split/csplit gap */ | 433 | u8 gap_uf; /* uframes split/csplit gap */ |
404 | u8 c_usecs; /* ... split completion bw */ | ||
405 | u16 tt_usecs; /* tt downstream bandwidth */ | ||
406 | unsigned short period; /* polling interval */ | ||
407 | unsigned short start; /* where polling starts */ | ||
408 | #define NO_FRAME ((unsigned short)~0) /* pick new start */ | ||
409 | 434 | ||
410 | struct usb_device *dev; /* access to TT */ | ||
411 | unsigned is_out:1; /* bulk or intr OUT */ | 435 | unsigned is_out:1; /* bulk or intr OUT */ |
412 | unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ | 436 | unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ |
413 | unsigned dequeue_during_giveback:1; | 437 | unsigned dequeue_during_giveback:1; |
@@ -434,6 +458,7 @@ struct ehci_iso_packet { | |||
434 | struct ehci_iso_sched { | 458 | struct ehci_iso_sched { |
435 | struct list_head td_list; | 459 | struct list_head td_list; |
436 | unsigned span; | 460 | unsigned span; |
461 | unsigned first_packet; | ||
437 | struct ehci_iso_packet packet [0]; | 462 | struct ehci_iso_packet packet [0]; |
438 | }; | 463 | }; |
439 | 464 | ||
@@ -449,22 +474,17 @@ struct ehci_iso_stream { | |||
449 | u8 highspeed; | 474 | u8 highspeed; |
450 | struct list_head td_list; /* queued itds/sitds */ | 475 | struct list_head td_list; /* queued itds/sitds */ |
451 | struct list_head free_list; /* list of unused itds/sitds */ | 476 | struct list_head free_list; /* list of unused itds/sitds */ |
452 | struct usb_device *udev; | ||
453 | struct usb_host_endpoint *ep; | ||
454 | 477 | ||
455 | /* output of (re)scheduling */ | 478 | /* output of (re)scheduling */ |
456 | int next_uframe; | 479 | struct ehci_per_sched ps; /* scheduling info */ |
480 | unsigned next_uframe; | ||
457 | __hc32 splits; | 481 | __hc32 splits; |
458 | 482 | ||
459 | /* the rest is derived from the endpoint descriptor, | 483 | /* the rest is derived from the endpoint descriptor, |
460 | * trusting urb->interval == f(epdesc->bInterval) and | ||
461 | * including the extra info for hw_bufp[0..2] | 484 | * including the extra info for hw_bufp[0..2] |
462 | */ | 485 | */ |
463 | u8 usecs, c_usecs; | 486 | u16 uperiod; /* period in uframes */ |
464 | u16 interval; | ||
465 | u16 tt_usecs; | ||
466 | u16 maxp; | 487 | u16 maxp; |
467 | u16 raw_mask; | ||
468 | unsigned bandwidth; | 488 | unsigned bandwidth; |
469 | 489 | ||
470 | /* This is used to initialize iTD's hw_bufp fields */ | 490 | /* This is used to initialize iTD's hw_bufp fields */ |
@@ -579,6 +599,35 @@ struct ehci_fstn { | |||
579 | 599 | ||
580 | /*-------------------------------------------------------------------------*/ | 600 | /*-------------------------------------------------------------------------*/ |
581 | 601 | ||
602 | /* | ||
603 | * USB-2.0 Specification Sections 11.14 and 11.18 | ||
604 | * Scheduling and budgeting split transactions using TTs | ||
605 | * | ||
606 | * A hub can have a single TT for all its ports, or multiple TTs (one for each | ||
607 | * port). The bandwidth and budgeting information for the full/low-speed bus | ||
608 | * below each TT is self-contained and independent of the other TTs or the | ||
609 | * high-speed bus. | ||
610 | * | ||
611 | * "Bandwidth" refers to the number of microseconds on the FS/LS bus allocated | ||
612 | * to an interrupt or isochronous endpoint for each frame. "Budget" refers to | ||
613 | * the best-case estimate of the number of full-speed bytes allocated to an | ||
614 | * endpoint for each microframe within an allocated frame. | ||
615 | * | ||
616 | * Removal of an endpoint invalidates a TT's budget. Instead of trying to | ||
617 | * keep an up-to-date record, we recompute the budget when it is needed. | ||
618 | */ | ||
619 | |||
620 | struct ehci_tt { | ||
621 | u16 bandwidth[EHCI_BANDWIDTH_FRAMES]; | ||
622 | |||
623 | struct list_head tt_list; /* List of all ehci_tt's */ | ||
624 | struct list_head ps_list; /* Items using this TT */ | ||
625 | struct usb_tt *usb_tt; | ||
626 | int tt_port; /* TT port number */ | ||
627 | }; | ||
628 | |||
629 | /*-------------------------------------------------------------------------*/ | ||
630 | |||
582 | /* Prepare the PORTSC wakeup flags during controller suspend/resume */ | 631 | /* Prepare the PORTSC wakeup flags during controller suspend/resume */ |
583 | 632 | ||
584 | #define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ | 633 | #define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ |
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index fce13bcc4a3e..55486bd23cf1 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c | |||
@@ -412,7 +412,7 @@ struct debug_buffer { | |||
412 | tmp = 'h'; break; \ | 412 | tmp = 'h'; break; \ |
413 | default: \ | 413 | default: \ |
414 | tmp = '?'; break; \ | 414 | tmp = '?'; break; \ |
415 | }; tmp; }) | 415 | } tmp; }) |
416 | 416 | ||
417 | static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) | 417 | static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) |
418 | { | 418 | { |
diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c index 299253c826c7..e1c6d850a7e1 100644 --- a/drivers/usb/host/fusbh200-hcd.c +++ b/drivers/usb/host/fusbh200-hcd.c | |||
@@ -402,7 +402,7 @@ struct debug_buffer { | |||
402 | case QH_LOW_SPEED: tmp = 'l'; break; \ | 402 | case QH_LOW_SPEED: tmp = 'l'; break; \ |
403 | case QH_HIGH_SPEED: tmp = 'h'; break; \ | 403 | case QH_HIGH_SPEED: tmp = 'h'; break; \ |
404 | default: tmp = '?'; break; \ | 404 | default: tmp = '?'; break; \ |
405 | }; tmp; }) | 405 | } tmp; }) |
406 | 406 | ||
407 | static inline char token_mark(struct fusbh200_hcd *fusbh200, __hc32 token) | 407 | static inline char token_mark(struct fusbh200_hcd *fusbh200, __hc32 token) |
408 | { | 408 | { |
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c index 5b86ffb88f1c..ada0a52797b1 100644 --- a/drivers/usb/host/hwa-hc.c +++ b/drivers/usb/host/hwa-hc.c | |||
@@ -199,10 +199,14 @@ static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd) | |||
199 | { | 199 | { |
200 | struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); | 200 | struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); |
201 | struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); | 201 | struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); |
202 | struct wahc *wa = &hwahc->wa; | ||
202 | 203 | ||
203 | dev_err(wusbhc->dev, "%s (%p [%p]) UNIMPLEMENTED\n", __func__, | 204 | /* |
204 | usb_hcd, hwahc); | 205 | * We cannot query the HWA for the WUSB time since that requires sending |
205 | return -ENOSYS; | 206 | * a synchronous URB and this function can be called in_interrupt. |
207 | * Instead, query the USB frame number for our parent and use that. | ||
208 | */ | ||
209 | return usb_get_current_frame_number(wa->usb_dev); | ||
206 | } | 210 | } |
207 | 211 | ||
208 | static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, | 212 | static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, |
@@ -566,14 +570,10 @@ found: | |||
566 | goto error; | 570 | goto error; |
567 | } | 571 | } |
568 | wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr; | 572 | wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr; |
569 | /* Make LE fields CPU order */ | 573 | if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100) |
570 | wa_descr->bcdWAVersion = le16_to_cpu(wa_descr->bcdWAVersion); | ||
571 | wa_descr->wNumRPipes = le16_to_cpu(wa_descr->wNumRPipes); | ||
572 | wa_descr->wRPipeMaxBlock = le16_to_cpu(wa_descr->wRPipeMaxBlock); | ||
573 | if (wa_descr->bcdWAVersion > 0x0100) | ||
574 | dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n", | 574 | dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n", |
575 | wa_descr->bcdWAVersion & 0xff00 >> 8, | 575 | le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00 >> 8, |
576 | wa_descr->bcdWAVersion & 0x00ff); | 576 | le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff); |
577 | result = 0; | 577 | result = 0; |
578 | error: | 578 | error: |
579 | return result; | 579 | return result; |
@@ -679,7 +679,8 @@ static void hwahc_security_release(struct hwahc *hwahc) | |||
679 | /* nothing to do here so far... */ | 679 | /* nothing to do here so far... */ |
680 | } | 680 | } |
681 | 681 | ||
682 | static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface) | 682 | static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface, |
683 | kernel_ulong_t quirks) | ||
683 | { | 684 | { |
684 | int result; | 685 | int result; |
685 | struct device *dev = &iface->dev; | 686 | struct device *dev = &iface->dev; |
@@ -724,7 +725,7 @@ static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface) | |||
724 | dev_err(dev, "Can't create WUSB HC structures: %d\n", result); | 725 | dev_err(dev, "Can't create WUSB HC structures: %d\n", result); |
725 | goto error_wusbhc_create; | 726 | goto error_wusbhc_create; |
726 | } | 727 | } |
727 | result = wa_create(&hwahc->wa, iface); | 728 | result = wa_create(&hwahc->wa, iface, quirks); |
728 | if (result < 0) | 729 | if (result < 0) |
729 | goto error_wa_create; | 730 | goto error_wa_create; |
730 | return 0; | 731 | return 0; |
@@ -780,7 +781,7 @@ static int hwahc_probe(struct usb_interface *usb_iface, | |||
780 | wusbhc = usb_hcd_to_wusbhc(usb_hcd); | 781 | wusbhc = usb_hcd_to_wusbhc(usb_hcd); |
781 | hwahc = container_of(wusbhc, struct hwahc, wusbhc); | 782 | hwahc = container_of(wusbhc, struct hwahc, wusbhc); |
782 | hwahc_init(hwahc); | 783 | hwahc_init(hwahc); |
783 | result = hwahc_create(hwahc, usb_iface); | 784 | result = hwahc_create(hwahc, usb_iface, id->driver_info); |
784 | if (result < 0) { | 785 | if (result < 0) { |
785 | dev_err(dev, "Cannot initialize internals: %d\n", result); | 786 | dev_err(dev, "Cannot initialize internals: %d\n", result); |
786 | goto error_hwahc_create; | 787 | goto error_hwahc_create; |
@@ -824,6 +825,12 @@ static void hwahc_disconnect(struct usb_interface *usb_iface) | |||
824 | } | 825 | } |
825 | 826 | ||
826 | static struct usb_device_id hwahc_id_table[] = { | 827 | static struct usb_device_id hwahc_id_table[] = { |
828 | /* Alereon 5310 */ | ||
829 | { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01), | ||
830 | .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC }, | ||
831 | /* Alereon 5611 */ | ||
832 | { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5611, 0xe0, 0x02, 0x01), | ||
833 | .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC }, | ||
827 | /* FIXME: use class labels for this */ | 834 | /* FIXME: use class labels for this */ |
828 | { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), }, | 835 | { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), }, |
829 | {}, | 836 | {}, |
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c index 6f29abad6815..935a2dd367a8 100644 --- a/drivers/usb/host/isp1362-hcd.c +++ b/drivers/usb/host/isp1362-hcd.c | |||
@@ -2108,7 +2108,7 @@ static int isp1362_show(struct seq_file *s, void *unused) | |||
2108 | default: | 2108 | default: |
2109 | s = "?"; | 2109 | s = "?"; |
2110 | break; | 2110 | break; |
2111 | }; | 2111 | } |
2112 | s;}), ep->maxpacket) ; | 2112 | s;}), ep->maxpacket) ; |
2113 | list_for_each_entry(urb, &ep->hep->urb_list, urb_list) { | 2113 | list_for_each_entry(urb, &ep->hep->urb_list, urb_list) { |
2114 | seq_printf(s, " urb%p, %d/%d\n", urb, | 2114 | seq_printf(s, " urb%p, %d/%d\n", urb, |
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index caa3764a3407..476b5a5baf25 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c | |||
@@ -13,19 +13,24 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/clk.h> | 15 | #include <linux/clk.h> |
16 | #include <linux/platform_device.h> | 16 | #include <linux/dma-mapping.h> |
17 | #include <linux/of_platform.h> | 17 | #include <linux/of_platform.h> |
18 | #include <linux/of_gpio.h> | 18 | #include <linux/of_gpio.h> |
19 | #include <linux/platform_device.h> | ||
19 | #include <linux/platform_data/atmel.h> | 20 | #include <linux/platform_data/atmel.h> |
21 | #include <linux/io.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/usb.h> | ||
25 | #include <linux/usb/hcd.h> | ||
20 | 26 | ||
21 | #include <mach/hardware.h> | 27 | #include <mach/hardware.h> |
22 | #include <asm/gpio.h> | 28 | #include <asm/gpio.h> |
23 | 29 | ||
24 | #include <mach/cpu.h> | 30 | #include <mach/cpu.h> |
25 | 31 | ||
26 | #ifndef CONFIG_ARCH_AT91 | 32 | |
27 | #error "CONFIG_ARCH_AT91 must be defined." | 33 | #include "ohci.h" |
28 | #endif | ||
29 | 34 | ||
30 | #define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS) | 35 | #define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS) |
31 | #define at91_for_each_port(index) \ | 36 | #define at91_for_each_port(index) \ |
@@ -33,7 +38,17 @@ | |||
33 | 38 | ||
34 | /* interface, function and usb clocks; sometimes also an AHB clock */ | 39 | /* interface, function and usb clocks; sometimes also an AHB clock */ |
35 | static struct clk *iclk, *fclk, *uclk, *hclk; | 40 | static struct clk *iclk, *fclk, *uclk, *hclk; |
41 | /* interface and function clocks; sometimes also an AHB clock */ | ||
42 | |||
43 | #define DRIVER_DESC "OHCI Atmel driver" | ||
44 | |||
45 | static const char hcd_name[] = "ohci-atmel"; | ||
46 | |||
47 | static struct hc_driver __read_mostly ohci_at91_hc_driver; | ||
36 | static int clocked; | 48 | static int clocked; |
49 | static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, | ||
50 | u16 wValue, u16 wIndex, char *buf, u16 wLength); | ||
51 | static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); | ||
37 | 52 | ||
38 | extern int usb_disabled(void); | 53 | extern int usb_disabled(void); |
39 | 54 | ||
@@ -117,6 +132,8 @@ static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); | |||
117 | static int usb_hcd_at91_probe(const struct hc_driver *driver, | 132 | static int usb_hcd_at91_probe(const struct hc_driver *driver, |
118 | struct platform_device *pdev) | 133 | struct platform_device *pdev) |
119 | { | 134 | { |
135 | struct at91_usbh_data *board; | ||
136 | struct ohci_hcd *ohci; | ||
120 | int retval; | 137 | int retval; |
121 | struct usb_hcd *hcd = NULL; | 138 | struct usb_hcd *hcd = NULL; |
122 | 139 | ||
@@ -177,8 +194,10 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
177 | } | 194 | } |
178 | } | 195 | } |
179 | 196 | ||
197 | board = hcd->self.controller->platform_data; | ||
198 | ohci = hcd_to_ohci(hcd); | ||
199 | ohci->num_ports = board->ports; | ||
180 | at91_start_hc(pdev); | 200 | at91_start_hc(pdev); |
181 | ohci_hcd_init(hcd_to_ohci(hcd)); | ||
182 | 201 | ||
183 | retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); | 202 | retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); |
184 | if (retval == 0) | 203 | if (retval == 0) |
@@ -238,36 +257,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd, | |||
238 | } | 257 | } |
239 | 258 | ||
240 | /*-------------------------------------------------------------------------*/ | 259 | /*-------------------------------------------------------------------------*/ |
241 | |||
242 | static int | ||
243 | ohci_at91_reset (struct usb_hcd *hcd) | ||
244 | { | ||
245 | struct at91_usbh_data *board = dev_get_platdata(hcd->self.controller); | ||
246 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | ||
247 | int ret; | ||
248 | |||
249 | if ((ret = ohci_init(ohci)) < 0) | ||
250 | return ret; | ||
251 | |||
252 | ohci->num_ports = board->ports; | ||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | static int | ||
257 | ohci_at91_start (struct usb_hcd *hcd) | ||
258 | { | ||
259 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | ||
260 | int ret; | ||
261 | |||
262 | if ((ret = ohci_run(ohci)) < 0) { | ||
263 | dev_err(hcd->self.controller, "can't start %s\n", | ||
264 | hcd->self.bus_name); | ||
265 | ohci_stop(hcd); | ||
266 | return ret; | ||
267 | } | ||
268 | return 0; | ||
269 | } | ||
270 | |||
271 | static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) | 260 | static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) |
272 | { | 261 | { |
273 | if (!valid_port(port)) | 262 | if (!valid_port(port)) |
@@ -297,8 +286,8 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) | |||
297 | */ | 286 | */ |
298 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) | 287 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) |
299 | { | 288 | { |
300 | struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller); | 289 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; |
301 | int length = ohci_hub_status_data(hcd, buf); | 290 | int length = orig_ohci_hub_status_data(hcd, buf); |
302 | int port; | 291 | int port; |
303 | 292 | ||
304 | at91_for_each_port(port) { | 293 | at91_for_each_port(port) { |
@@ -376,7 +365,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
376 | break; | 365 | break; |
377 | } | 366 | } |
378 | 367 | ||
379 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength); | 368 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, |
369 | buf, wLength); | ||
380 | if (ret) | 370 | if (ret) |
381 | goto out; | 371 | goto out; |
382 | 372 | ||
@@ -430,51 +420,6 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
430 | 420 | ||
431 | /*-------------------------------------------------------------------------*/ | 421 | /*-------------------------------------------------------------------------*/ |
432 | 422 | ||
433 | static const struct hc_driver ohci_at91_hc_driver = { | ||
434 | .description = hcd_name, | ||
435 | .product_desc = "AT91 OHCI", | ||
436 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
437 | |||
438 | /* | ||
439 | * generic hardware linkage | ||
440 | */ | ||
441 | .irq = ohci_irq, | ||
442 | .flags = HCD_USB11 | HCD_MEMORY, | ||
443 | |||
444 | /* | ||
445 | * basic lifecycle operations | ||
446 | */ | ||
447 | .reset = ohci_at91_reset, | ||
448 | .start = ohci_at91_start, | ||
449 | .stop = ohci_stop, | ||
450 | .shutdown = ohci_shutdown, | ||
451 | |||
452 | /* | ||
453 | * managing i/o requests and associated device resources | ||
454 | */ | ||
455 | .urb_enqueue = ohci_urb_enqueue, | ||
456 | .urb_dequeue = ohci_urb_dequeue, | ||
457 | .endpoint_disable = ohci_endpoint_disable, | ||
458 | |||
459 | /* | ||
460 | * scheduling support | ||
461 | */ | ||
462 | .get_frame_number = ohci_get_frame, | ||
463 | |||
464 | /* | ||
465 | * root hub support | ||
466 | */ | ||
467 | .hub_status_data = ohci_at91_hub_status_data, | ||
468 | .hub_control = ohci_at91_hub_control, | ||
469 | #ifdef CONFIG_PM | ||
470 | .bus_suspend = ohci_bus_suspend, | ||
471 | .bus_resume = ohci_bus_resume, | ||
472 | #endif | ||
473 | .start_port_reset = ohci_start_port_reset, | ||
474 | }; | ||
475 | |||
476 | /*-------------------------------------------------------------------------*/ | ||
477 | |||
478 | static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) | 423 | static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) |
479 | { | 424 | { |
480 | struct platform_device *pdev = data; | 425 | struct platform_device *pdev = data; |
@@ -703,7 +648,11 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
703 | * REVISIT: some boards will be able to turn VBUS off... | 648 | * REVISIT: some boards will be able to turn VBUS off... |
704 | */ | 649 | */ |
705 | if (at91_suspend_entering_slow_clock()) { | 650 | if (at91_suspend_entering_slow_clock()) { |
706 | ohci_usb_reset (ohci); | 651 | ohci->hc_control = ohci_readl(ohci, &ohci->regs->control); |
652 | ohci->hc_control &= OHCI_CTRL_RWC; | ||
653 | ohci_writel(ohci, ohci->hc_control, &ohci->regs->control); | ||
654 | ohci->rh_state = OHCI_RH_HALTED; | ||
655 | |||
707 | /* flush the writes */ | 656 | /* flush the writes */ |
708 | (void) ohci_readl (ohci, &ohci->regs->control); | 657 | (void) ohci_readl (ohci, &ohci->regs->control); |
709 | at91_stop_clock(); | 658 | at91_stop_clock(); |
@@ -730,8 +679,6 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev) | |||
730 | #define ohci_hcd_at91_drv_resume NULL | 679 | #define ohci_hcd_at91_drv_resume NULL |
731 | #endif | 680 | #endif |
732 | 681 | ||
733 | MODULE_ALIAS("platform:at91_ohci"); | ||
734 | |||
735 | static struct platform_driver ohci_hcd_at91_driver = { | 682 | static struct platform_driver ohci_hcd_at91_driver = { |
736 | .probe = ohci_hcd_at91_drv_probe, | 683 | .probe = ohci_hcd_at91_drv_probe, |
737 | .remove = ohci_hcd_at91_drv_remove, | 684 | .remove = ohci_hcd_at91_drv_remove, |
@@ -744,3 +691,40 @@ static struct platform_driver ohci_hcd_at91_driver = { | |||
744 | .of_match_table = of_match_ptr(at91_ohci_dt_ids), | 691 | .of_match_table = of_match_ptr(at91_ohci_dt_ids), |
745 | }, | 692 | }, |
746 | }; | 693 | }; |
694 | |||
695 | static int __init ohci_at91_init(void) | ||
696 | { | ||
697 | if (usb_disabled()) | ||
698 | return -ENODEV; | ||
699 | |||
700 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
701 | ohci_init_driver(&ohci_at91_hc_driver, NULL); | ||
702 | |||
703 | /* | ||
704 | * The Atmel HW has some unusual quirks, which require Atmel-specific | ||
705 | * workarounds. We override certain hc_driver functions here to | ||
706 | * achieve that. We explicitly do not enhance ohci_driver_overrides to | ||
707 | * allow this more easily, since this is an unusual case, and we don't | ||
708 | * want to encourage others to override these functions by making it | ||
709 | * too easy. | ||
710 | */ | ||
711 | |||
712 | orig_ohci_hub_control = ohci_at91_hc_driver.hub_control; | ||
713 | orig_ohci_hub_status_data = ohci_at91_hc_driver.hub_status_data; | ||
714 | |||
715 | ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data; | ||
716 | ohci_at91_hc_driver.hub_control = ohci_at91_hub_control; | ||
717 | |||
718 | return platform_driver_register(&ohci_hcd_at91_driver); | ||
719 | } | ||
720 | module_init(ohci_at91_init); | ||
721 | |||
722 | static void __exit ohci_at91_cleanup(void) | ||
723 | { | ||
724 | platform_driver_unregister(&ohci_hcd_at91_driver); | ||
725 | } | ||
726 | module_exit(ohci_at91_cleanup); | ||
727 | |||
728 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
729 | MODULE_LICENSE("GPL"); | ||
730 | MODULE_ALIAS("platform:at91_ohci"); | ||
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index 31b81f9eacdc..3fca52ec02ac 100644 --- a/drivers/usb/host/ohci-dbg.c +++ b/drivers/usb/host/ohci-dbg.c | |||
@@ -17,7 +17,7 @@ | |||
17 | case PIPE_BULK: temp = "bulk"; break; \ | 17 | case PIPE_BULK: temp = "bulk"; break; \ |
18 | case PIPE_INTERRUPT: temp = "intr"; break; \ | 18 | case PIPE_INTERRUPT: temp = "intr"; break; \ |
19 | default: temp = "isoc"; break; \ | 19 | default: temp = "isoc"; break; \ |
20 | }; temp;}) | 20 | } temp;}) |
21 | #define pipestring(pipe) edstring(usb_pipetype(pipe)) | 21 | #define pipestring(pipe) edstring(usb_pipetype(pipe)) |
22 | 22 | ||
23 | /* debug| print the main components of an URB | 23 | /* debug| print the main components of an URB |
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c deleted file mode 100644 index 84a20d5223b9..000000000000 --- a/drivers/usb/host/ohci-ep93xx.c +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | /* | ||
2 | * OHCI HCD (Host Controller Driver) for USB. | ||
3 | * | ||
4 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> | ||
5 | * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> | ||
6 | * (C) Copyright 2002 Hewlett-Packard Company | ||
7 | * | ||
8 | * Bus Glue for ep93xx. | ||
9 | * | ||
10 | * Written by Christopher Hoover <ch@hpl.hp.com> | ||
11 | * Based on fragments of previous driver by Russell King et al. | ||
12 | * | ||
13 | * Modified for LH7A404 from ohci-sa1111.c | ||
14 | * by Durgesh Pattamatta <pattamattad@sharpsec.com> | ||
15 | * | ||
16 | * Modified for pxa27x from ohci-lh7a404.c | ||
17 | * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004 | ||
18 | * | ||
19 | * Modified for ep93xx from ohci-pxa27x.c | ||
20 | * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006 | ||
21 | * Based on an earlier driver by Ray Lehtiniemi | ||
22 | * | ||
23 | * This file is licenced under the GPL. | ||
24 | */ | ||
25 | |||
26 | #include <linux/clk.h> | ||
27 | #include <linux/device.h> | ||
28 | #include <linux/signal.h> | ||
29 | #include <linux/platform_device.h> | ||
30 | |||
31 | static struct clk *usb_host_clock; | ||
32 | |||
33 | static int ohci_ep93xx_start(struct usb_hcd *hcd) | ||
34 | { | ||
35 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
36 | int ret; | ||
37 | |||
38 | if ((ret = ohci_init(ohci)) < 0) | ||
39 | return ret; | ||
40 | |||
41 | if ((ret = ohci_run(ohci)) < 0) { | ||
42 | dev_err(hcd->self.controller, "can't start %s\n", | ||
43 | hcd->self.bus_name); | ||
44 | ohci_stop(hcd); | ||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static struct hc_driver ohci_ep93xx_hc_driver = { | ||
52 | .description = hcd_name, | ||
53 | .product_desc = "EP93xx OHCI", | ||
54 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
55 | .irq = ohci_irq, | ||
56 | .flags = HCD_USB11 | HCD_MEMORY, | ||
57 | .start = ohci_ep93xx_start, | ||
58 | .stop = ohci_stop, | ||
59 | .shutdown = ohci_shutdown, | ||
60 | .urb_enqueue = ohci_urb_enqueue, | ||
61 | .urb_dequeue = ohci_urb_dequeue, | ||
62 | .endpoint_disable = ohci_endpoint_disable, | ||
63 | .get_frame_number = ohci_get_frame, | ||
64 | .hub_status_data = ohci_hub_status_data, | ||
65 | .hub_control = ohci_hub_control, | ||
66 | #ifdef CONFIG_PM | ||
67 | .bus_suspend = ohci_bus_suspend, | ||
68 | .bus_resume = ohci_bus_resume, | ||
69 | #endif | ||
70 | .start_port_reset = ohci_start_port_reset, | ||
71 | }; | ||
72 | |||
73 | static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev) | ||
74 | { | ||
75 | struct usb_hcd *hcd; | ||
76 | struct resource *res; | ||
77 | int irq; | ||
78 | int ret; | ||
79 | |||
80 | if (usb_disabled()) | ||
81 | return -ENODEV; | ||
82 | |||
83 | irq = platform_get_irq(pdev, 0); | ||
84 | if (irq < 0) | ||
85 | return irq; | ||
86 | |||
87 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
88 | if (!res) | ||
89 | return -ENXIO; | ||
90 | |||
91 | hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx"); | ||
92 | if (!hcd) | ||
93 | return -ENOMEM; | ||
94 | |||
95 | hcd->rsrc_start = res->start; | ||
96 | hcd->rsrc_len = resource_size(res); | ||
97 | |||
98 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); | ||
99 | if (IS_ERR(hcd->regs)) { | ||
100 | ret = PTR_ERR(hcd->regs); | ||
101 | goto err_put_hcd; | ||
102 | } | ||
103 | |||
104 | usb_host_clock = devm_clk_get(&pdev->dev, NULL); | ||
105 | if (IS_ERR(usb_host_clock)) { | ||
106 | ret = PTR_ERR(usb_host_clock); | ||
107 | goto err_put_hcd; | ||
108 | } | ||
109 | |||
110 | clk_enable(usb_host_clock); | ||
111 | |||
112 | ohci_hcd_init(hcd_to_ohci(hcd)); | ||
113 | |||
114 | ret = usb_add_hcd(hcd, irq, 0); | ||
115 | if (ret) | ||
116 | goto err_clk_disable; | ||
117 | |||
118 | return 0; | ||
119 | |||
120 | err_clk_disable: | ||
121 | clk_disable(usb_host_clock); | ||
122 | err_put_hcd: | ||
123 | usb_put_hcd(hcd); | ||
124 | |||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev) | ||
129 | { | ||
130 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
131 | |||
132 | usb_remove_hcd(hcd); | ||
133 | clk_disable(usb_host_clock); | ||
134 | usb_put_hcd(hcd); | ||
135 | |||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | #ifdef CONFIG_PM | ||
140 | static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state) | ||
141 | { | ||
142 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
143 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
144 | |||
145 | if (time_before(jiffies, ohci->next_statechange)) | ||
146 | msleep(5); | ||
147 | ohci->next_statechange = jiffies; | ||
148 | |||
149 | clk_disable(usb_host_clock); | ||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev) | ||
154 | { | ||
155 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
156 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
157 | |||
158 | if (time_before(jiffies, ohci->next_statechange)) | ||
159 | msleep(5); | ||
160 | ohci->next_statechange = jiffies; | ||
161 | |||
162 | clk_enable(usb_host_clock); | ||
163 | |||
164 | ohci_resume(hcd, false); | ||
165 | return 0; | ||
166 | } | ||
167 | #endif | ||
168 | |||
169 | |||
170 | static struct platform_driver ohci_hcd_ep93xx_driver = { | ||
171 | .probe = ohci_hcd_ep93xx_drv_probe, | ||
172 | .remove = ohci_hcd_ep93xx_drv_remove, | ||
173 | .shutdown = usb_hcd_platform_shutdown, | ||
174 | #ifdef CONFIG_PM | ||
175 | .suspend = ohci_hcd_ep93xx_drv_suspend, | ||
176 | .resume = ohci_hcd_ep93xx_drv_resume, | ||
177 | #endif | ||
178 | .driver = { | ||
179 | .name = "ep93xx-ohci", | ||
180 | .owner = THIS_MODULE, | ||
181 | }, | ||
182 | }; | ||
183 | |||
184 | MODULE_ALIAS("platform:ep93xx-ohci"); | ||
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index dc6ee9adacf5..a87baedc0aa7 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c | |||
@@ -12,98 +12,55 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/clk.h> | 14 | #include <linux/clk.h> |
15 | #include <linux/dma-mapping.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
15 | #include <linux/of.h> | 19 | #include <linux/of.h> |
16 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
17 | #include <linux/platform_data/usb-ohci-exynos.h> | ||
18 | #include <linux/usb/phy.h> | 21 | #include <linux/usb/phy.h> |
19 | #include <linux/usb/samsung_usb_phy.h> | 22 | #include <linux/usb/samsung_usb_phy.h> |
23 | #include <linux/usb.h> | ||
24 | #include <linux/usb/hcd.h> | ||
25 | #include <linux/usb/otg.h> | ||
26 | |||
27 | #include "ohci.h" | ||
28 | |||
29 | #define DRIVER_DESC "OHCI EXYNOS driver" | ||
30 | |||
31 | static const char hcd_name[] = "ohci-exynos"; | ||
32 | static struct hc_driver __read_mostly exynos_ohci_hc_driver; | ||
33 | |||
34 | #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv) | ||
20 | 35 | ||
21 | struct exynos_ohci_hcd { | 36 | struct exynos_ohci_hcd { |
22 | struct device *dev; | ||
23 | struct usb_hcd *hcd; | ||
24 | struct clk *clk; | 37 | struct clk *clk; |
25 | struct usb_phy *phy; | 38 | struct usb_phy *phy; |
26 | struct usb_otg *otg; | 39 | struct usb_otg *otg; |
27 | struct exynos4_ohci_platdata *pdata; | ||
28 | }; | 40 | }; |
29 | 41 | ||
30 | static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci) | 42 | static void exynos_ohci_phy_enable(struct platform_device *pdev) |
31 | { | 43 | { |
32 | struct platform_device *pdev = to_platform_device(exynos_ohci->dev); | 44 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
45 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | ||
33 | 46 | ||
34 | if (exynos_ohci->phy) | 47 | if (exynos_ohci->phy) |
35 | usb_phy_init(exynos_ohci->phy); | 48 | usb_phy_init(exynos_ohci->phy); |
36 | else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_init) | ||
37 | exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); | ||
38 | } | 49 | } |
39 | 50 | ||
40 | static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci) | 51 | static void exynos_ohci_phy_disable(struct platform_device *pdev) |
41 | { | 52 | { |
42 | struct platform_device *pdev = to_platform_device(exynos_ohci->dev); | 53 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
54 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | ||
43 | 55 | ||
44 | if (exynos_ohci->phy) | 56 | if (exynos_ohci->phy) |
45 | usb_phy_shutdown(exynos_ohci->phy); | 57 | usb_phy_shutdown(exynos_ohci->phy); |
46 | else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_exit) | ||
47 | exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); | ||
48 | } | ||
49 | |||
50 | static int ohci_exynos_reset(struct usb_hcd *hcd) | ||
51 | { | ||
52 | return ohci_init(hcd_to_ohci(hcd)); | ||
53 | } | 58 | } |
54 | 59 | ||
55 | static int ohci_exynos_start(struct usb_hcd *hcd) | ||
56 | { | ||
57 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
58 | int ret; | ||
59 | |||
60 | ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci); | ||
61 | |||
62 | ret = ohci_run(ohci); | ||
63 | if (ret < 0) { | ||
64 | dev_err(hcd->self.controller, "can't start %s\n", | ||
65 | hcd->self.bus_name); | ||
66 | ohci_stop(hcd); | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static const struct hc_driver exynos_ohci_hc_driver = { | ||
74 | .description = hcd_name, | ||
75 | .product_desc = "EXYNOS OHCI Host Controller", | ||
76 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
77 | |||
78 | .irq = ohci_irq, | ||
79 | .flags = HCD_MEMORY|HCD_USB11, | ||
80 | |||
81 | .reset = ohci_exynos_reset, | ||
82 | .start = ohci_exynos_start, | ||
83 | .stop = ohci_stop, | ||
84 | .shutdown = ohci_shutdown, | ||
85 | |||
86 | .get_frame_number = ohci_get_frame, | ||
87 | |||
88 | .urb_enqueue = ohci_urb_enqueue, | ||
89 | .urb_dequeue = ohci_urb_dequeue, | ||
90 | .endpoint_disable = ohci_endpoint_disable, | ||
91 | |||
92 | .hub_status_data = ohci_hub_status_data, | ||
93 | .hub_control = ohci_hub_control, | ||
94 | #ifdef CONFIG_PM | ||
95 | .bus_suspend = ohci_bus_suspend, | ||
96 | .bus_resume = ohci_bus_resume, | ||
97 | #endif | ||
98 | .start_port_reset = ohci_start_port_reset, | ||
99 | }; | ||
100 | |||
101 | static int exynos_ohci_probe(struct platform_device *pdev) | 60 | static int exynos_ohci_probe(struct platform_device *pdev) |
102 | { | 61 | { |
103 | struct exynos4_ohci_platdata *pdata = dev_get_platdata(&pdev->dev); | ||
104 | struct exynos_ohci_hcd *exynos_ohci; | 62 | struct exynos_ohci_hcd *exynos_ohci; |
105 | struct usb_hcd *hcd; | 63 | struct usb_hcd *hcd; |
106 | struct ohci_hcd *ohci; | ||
107 | struct resource *res; | 64 | struct resource *res; |
108 | struct usb_phy *phy; | 65 | struct usb_phy *phy; |
109 | int irq; | 66 | int irq; |
@@ -119,10 +76,14 @@ static int exynos_ohci_probe(struct platform_device *pdev) | |||
119 | if (!pdev->dev.coherent_dma_mask) | 76 | if (!pdev->dev.coherent_dma_mask) |
120 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); | 77 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
121 | 78 | ||
122 | exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd), | 79 | hcd = usb_create_hcd(&exynos_ohci_hc_driver, |
123 | GFP_KERNEL); | 80 | &pdev->dev, dev_name(&pdev->dev)); |
124 | if (!exynos_ohci) | 81 | if (!hcd) { |
82 | dev_err(&pdev->dev, "Unable to create HCD\n"); | ||
125 | return -ENOMEM; | 83 | return -ENOMEM; |
84 | } | ||
85 | |||
86 | exynos_ohci = to_exynos_ohci(hcd); | ||
126 | 87 | ||
127 | if (of_device_is_compatible(pdev->dev.of_node, | 88 | if (of_device_is_compatible(pdev->dev.of_node, |
128 | "samsung,exynos5440-ohci")) | 89 | "samsung,exynos5440-ohci")) |
@@ -130,30 +91,15 @@ static int exynos_ohci_probe(struct platform_device *pdev) | |||
130 | 91 | ||
131 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 92 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
132 | if (IS_ERR(phy)) { | 93 | if (IS_ERR(phy)) { |
133 | /* Fallback to pdata */ | 94 | usb_put_hcd(hcd); |
134 | if (!pdata) { | 95 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); |
135 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | 96 | return -EPROBE_DEFER; |
136 | return -EPROBE_DEFER; | ||
137 | } else { | ||
138 | exynos_ohci->pdata = pdata; | ||
139 | } | ||
140 | } else { | 97 | } else { |
141 | exynos_ohci->phy = phy; | 98 | exynos_ohci->phy = phy; |
142 | exynos_ohci->otg = phy->otg; | 99 | exynos_ohci->otg = phy->otg; |
143 | } | 100 | } |
144 | 101 | ||
145 | skip_phy: | 102 | skip_phy: |
146 | |||
147 | exynos_ohci->dev = &pdev->dev; | ||
148 | |||
149 | hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev, | ||
150 | dev_name(&pdev->dev)); | ||
151 | if (!hcd) { | ||
152 | dev_err(&pdev->dev, "Unable to create HCD\n"); | ||
153 | return -ENOMEM; | ||
154 | } | ||
155 | |||
156 | exynos_ohci->hcd = hcd; | ||
157 | exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); | 103 | exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); |
158 | 104 | ||
159 | if (IS_ERR(exynos_ohci->clk)) { | 105 | if (IS_ERR(exynos_ohci->clk)) { |
@@ -190,26 +136,21 @@ skip_phy: | |||
190 | } | 136 | } |
191 | 137 | ||
192 | if (exynos_ohci->otg) | 138 | if (exynos_ohci->otg) |
193 | exynos_ohci->otg->set_host(exynos_ohci->otg, | 139 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
194 | &exynos_ohci->hcd->self); | ||
195 | 140 | ||
196 | exynos_ohci_phy_enable(exynos_ohci); | 141 | platform_set_drvdata(pdev, hcd); |
197 | 142 | ||
198 | ohci = hcd_to_ohci(hcd); | 143 | exynos_ohci_phy_enable(pdev); |
199 | ohci_hcd_init(ohci); | ||
200 | 144 | ||
201 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | 145 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
202 | if (err) { | 146 | if (err) { |
203 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 147 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
204 | goto fail_add_hcd; | 148 | goto fail_add_hcd; |
205 | } | 149 | } |
206 | |||
207 | platform_set_drvdata(pdev, exynos_ohci); | ||
208 | |||
209 | return 0; | 150 | return 0; |
210 | 151 | ||
211 | fail_add_hcd: | 152 | fail_add_hcd: |
212 | exynos_ohci_phy_disable(exynos_ohci); | 153 | exynos_ohci_phy_disable(pdev); |
213 | fail_io: | 154 | fail_io: |
214 | clk_disable_unprepare(exynos_ohci->clk); | 155 | clk_disable_unprepare(exynos_ohci->clk); |
215 | fail_clk: | 156 | fail_clk: |
@@ -219,16 +160,15 @@ fail_clk: | |||
219 | 160 | ||
220 | static int exynos_ohci_remove(struct platform_device *pdev) | 161 | static int exynos_ohci_remove(struct platform_device *pdev) |
221 | { | 162 | { |
222 | struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); | 163 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
223 | struct usb_hcd *hcd = exynos_ohci->hcd; | 164 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
224 | 165 | ||
225 | usb_remove_hcd(hcd); | 166 | usb_remove_hcd(hcd); |
226 | 167 | ||
227 | if (exynos_ohci->otg) | 168 | if (exynos_ohci->otg) |
228 | exynos_ohci->otg->set_host(exynos_ohci->otg, | 169 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
229 | &exynos_ohci->hcd->self); | ||
230 | 170 | ||
231 | exynos_ohci_phy_disable(exynos_ohci); | 171 | exynos_ohci_phy_disable(pdev); |
232 | 172 | ||
233 | clk_disable_unprepare(exynos_ohci->clk); | 173 | clk_disable_unprepare(exynos_ohci->clk); |
234 | 174 | ||
@@ -239,8 +179,7 @@ static int exynos_ohci_remove(struct platform_device *pdev) | |||
239 | 179 | ||
240 | static void exynos_ohci_shutdown(struct platform_device *pdev) | 180 | static void exynos_ohci_shutdown(struct platform_device *pdev) |
241 | { | 181 | { |
242 | struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); | 182 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
243 | struct usb_hcd *hcd = exynos_ohci->hcd; | ||
244 | 183 | ||
245 | if (hcd->driver->shutdown) | 184 | if (hcd->driver->shutdown) |
246 | hcd->driver->shutdown(hcd); | 185 | hcd->driver->shutdown(hcd); |
@@ -249,9 +188,10 @@ static void exynos_ohci_shutdown(struct platform_device *pdev) | |||
249 | #ifdef CONFIG_PM | 188 | #ifdef CONFIG_PM |
250 | static int exynos_ohci_suspend(struct device *dev) | 189 | static int exynos_ohci_suspend(struct device *dev) |
251 | { | 190 | { |
252 | struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); | 191 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
253 | struct usb_hcd *hcd = exynos_ohci->hcd; | 192 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
254 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 193 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
194 | struct platform_device *pdev = to_platform_device(dev); | ||
255 | unsigned long flags; | 195 | unsigned long flags; |
256 | int rc = 0; | 196 | int rc = 0; |
257 | 197 | ||
@@ -271,10 +211,9 @@ static int exynos_ohci_suspend(struct device *dev) | |||
271 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 211 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
272 | 212 | ||
273 | if (exynos_ohci->otg) | 213 | if (exynos_ohci->otg) |
274 | exynos_ohci->otg->set_host(exynos_ohci->otg, | 214 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
275 | &exynos_ohci->hcd->self); | ||
276 | 215 | ||
277 | exynos_ohci_phy_disable(exynos_ohci); | 216 | exynos_ohci_phy_disable(pdev); |
278 | 217 | ||
279 | clk_disable_unprepare(exynos_ohci->clk); | 218 | clk_disable_unprepare(exynos_ohci->clk); |
280 | 219 | ||
@@ -286,16 +225,16 @@ fail: | |||
286 | 225 | ||
287 | static int exynos_ohci_resume(struct device *dev) | 226 | static int exynos_ohci_resume(struct device *dev) |
288 | { | 227 | { |
289 | struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); | 228 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
290 | struct usb_hcd *hcd = exynos_ohci->hcd; | 229 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
230 | struct platform_device *pdev = to_platform_device(dev); | ||
291 | 231 | ||
292 | clk_prepare_enable(exynos_ohci->clk); | 232 | clk_prepare_enable(exynos_ohci->clk); |
293 | 233 | ||
294 | if (exynos_ohci->otg) | 234 | if (exynos_ohci->otg) |
295 | exynos_ohci->otg->set_host(exynos_ohci->otg, | 235 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
296 | &exynos_ohci->hcd->self); | ||
297 | 236 | ||
298 | exynos_ohci_phy_enable(exynos_ohci); | 237 | exynos_ohci_phy_enable(pdev); |
299 | 238 | ||
300 | ohci_resume(hcd, false); | 239 | ohci_resume(hcd, false); |
301 | 240 | ||
@@ -306,6 +245,10 @@ static int exynos_ohci_resume(struct device *dev) | |||
306 | #define exynos_ohci_resume NULL | 245 | #define exynos_ohci_resume NULL |
307 | #endif | 246 | #endif |
308 | 247 | ||
248 | static const struct ohci_driver_overrides exynos_overrides __initconst = { | ||
249 | .extra_priv_size = sizeof(struct exynos_ohci_hcd), | ||
250 | }; | ||
251 | |||
309 | static const struct dev_pm_ops exynos_ohci_pm_ops = { | 252 | static const struct dev_pm_ops exynos_ohci_pm_ops = { |
310 | .suspend = exynos_ohci_suspend, | 253 | .suspend = exynos_ohci_suspend, |
311 | .resume = exynos_ohci_resume, | 254 | .resume = exynos_ohci_resume, |
@@ -331,6 +274,23 @@ static struct platform_driver exynos_ohci_driver = { | |||
331 | .of_match_table = of_match_ptr(exynos_ohci_match), | 274 | .of_match_table = of_match_ptr(exynos_ohci_match), |
332 | } | 275 | } |
333 | }; | 276 | }; |
277 | static int __init ohci_exynos_init(void) | ||
278 | { | ||
279 | if (usb_disabled()) | ||
280 | return -ENODEV; | ||
281 | |||
282 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
283 | ohci_init_driver(&exynos_ohci_hc_driver, &exynos_overrides); | ||
284 | return platform_driver_register(&exynos_ohci_driver); | ||
285 | } | ||
286 | module_init(ohci_exynos_init); | ||
287 | |||
288 | static void __exit ohci_exynos_cleanup(void) | ||
289 | { | ||
290 | platform_driver_unregister(&exynos_ohci_driver); | ||
291 | } | ||
292 | module_exit(ohci_exynos_cleanup); | ||
334 | 293 | ||
335 | MODULE_ALIAS("platform:exynos-ohci"); | 294 | MODULE_ALIAS("platform:exynos-ohci"); |
336 | MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); | 295 | MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); |
296 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 604cad1bcf9c..8ada13f8dde2 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -1161,10 +1161,12 @@ void ohci_init_driver(struct hc_driver *drv, | |||
1161 | /* Copy the generic table to drv and then apply the overrides */ | 1161 | /* Copy the generic table to drv and then apply the overrides */ |
1162 | *drv = ohci_hc_driver; | 1162 | *drv = ohci_hc_driver; |
1163 | 1163 | ||
1164 | drv->product_desc = over->product_desc; | 1164 | if (over) { |
1165 | drv->hcd_priv_size += over->extra_priv_size; | 1165 | drv->product_desc = over->product_desc; |
1166 | if (over->reset) | 1166 | drv->hcd_priv_size += over->extra_priv_size; |
1167 | drv->reset = over->reset; | 1167 | if (over->reset) |
1168 | drv->reset = over->reset; | ||
1169 | } | ||
1168 | } | 1170 | } |
1169 | EXPORT_SYMBOL_GPL(ohci_init_driver); | 1171 | EXPORT_SYMBOL_GPL(ohci_init_driver); |
1170 | 1172 | ||
@@ -1179,46 +1181,6 @@ MODULE_LICENSE ("GPL"); | |||
1179 | #define SA1111_DRIVER ohci_hcd_sa1111_driver | 1181 | #define SA1111_DRIVER ohci_hcd_sa1111_driver |
1180 | #endif | 1182 | #endif |
1181 | 1183 | ||
1182 | #if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX) | ||
1183 | #include "ohci-s3c2410.c" | ||
1184 | #define S3C2410_PLATFORM_DRIVER ohci_hcd_s3c2410_driver | ||
1185 | #endif | ||
1186 | |||
1187 | #ifdef CONFIG_USB_OHCI_EXYNOS | ||
1188 | #include "ohci-exynos.c" | ||
1189 | #define EXYNOS_PLATFORM_DRIVER exynos_ohci_driver | ||
1190 | #endif | ||
1191 | |||
1192 | #ifdef CONFIG_USB_OHCI_HCD_OMAP1 | ||
1193 | #include "ohci-omap.c" | ||
1194 | #define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver | ||
1195 | #endif | ||
1196 | |||
1197 | #ifdef CONFIG_USB_OHCI_HCD_OMAP3 | ||
1198 | #include "ohci-omap3.c" | ||
1199 | #define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver | ||
1200 | #endif | ||
1201 | |||
1202 | #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx) | ||
1203 | #include "ohci-pxa27x.c" | ||
1204 | #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver | ||
1205 | #endif | ||
1206 | |||
1207 | #ifdef CONFIG_ARCH_EP93XX | ||
1208 | #include "ohci-ep93xx.c" | ||
1209 | #define EP93XX_PLATFORM_DRIVER ohci_hcd_ep93xx_driver | ||
1210 | #endif | ||
1211 | |||
1212 | #ifdef CONFIG_ARCH_AT91 | ||
1213 | #include "ohci-at91.c" | ||
1214 | #define AT91_PLATFORM_DRIVER ohci_hcd_at91_driver | ||
1215 | #endif | ||
1216 | |||
1217 | #ifdef CONFIG_ARCH_LPC32XX | ||
1218 | #include "ohci-nxp.c" | ||
1219 | #define NXP_PLATFORM_DRIVER usb_hcd_nxp_driver | ||
1220 | #endif | ||
1221 | |||
1222 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX | 1184 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX |
1223 | #include "ohci-da8xx.c" | 1185 | #include "ohci-da8xx.c" |
1224 | #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver | 1186 | #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver |
@@ -1229,11 +1191,6 @@ MODULE_LICENSE ("GPL"); | |||
1229 | #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver | 1191 | #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver |
1230 | #endif | 1192 | #endif |
1231 | 1193 | ||
1232 | #ifdef CONFIG_PLAT_SPEAR | ||
1233 | #include "ohci-spear.c" | ||
1234 | #define SPEAR_PLATFORM_DRIVER spear_ohci_hcd_driver | ||
1235 | #endif | ||
1236 | |||
1237 | #ifdef CONFIG_PPC_PS3 | 1194 | #ifdef CONFIG_PPC_PS3 |
1238 | #include "ohci-ps3.c" | 1195 | #include "ohci-ps3.c" |
1239 | #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver | 1196 | #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver |
@@ -1296,18 +1253,6 @@ static int __init ohci_hcd_mod_init(void) | |||
1296 | goto error_platform; | 1253 | goto error_platform; |
1297 | #endif | 1254 | #endif |
1298 | 1255 | ||
1299 | #ifdef OMAP1_PLATFORM_DRIVER | ||
1300 | retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER); | ||
1301 | if (retval < 0) | ||
1302 | goto error_omap1_platform; | ||
1303 | #endif | ||
1304 | |||
1305 | #ifdef OMAP3_PLATFORM_DRIVER | ||
1306 | retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER); | ||
1307 | if (retval < 0) | ||
1308 | goto error_omap3_platform; | ||
1309 | #endif | ||
1310 | |||
1311 | #ifdef OF_PLATFORM_DRIVER | 1256 | #ifdef OF_PLATFORM_DRIVER |
1312 | retval = platform_driver_register(&OF_PLATFORM_DRIVER); | 1257 | retval = platform_driver_register(&OF_PLATFORM_DRIVER); |
1313 | if (retval < 0) | 1258 | if (retval < 0) |
@@ -1332,79 +1277,19 @@ static int __init ohci_hcd_mod_init(void) | |||
1332 | goto error_tmio; | 1277 | goto error_tmio; |
1333 | #endif | 1278 | #endif |
1334 | 1279 | ||
1335 | #ifdef S3C2410_PLATFORM_DRIVER | ||
1336 | retval = platform_driver_register(&S3C2410_PLATFORM_DRIVER); | ||
1337 | if (retval < 0) | ||
1338 | goto error_s3c2410; | ||
1339 | #endif | ||
1340 | |||
1341 | #ifdef EXYNOS_PLATFORM_DRIVER | ||
1342 | retval = platform_driver_register(&EXYNOS_PLATFORM_DRIVER); | ||
1343 | if (retval < 0) | ||
1344 | goto error_exynos; | ||
1345 | #endif | ||
1346 | |||
1347 | #ifdef EP93XX_PLATFORM_DRIVER | ||
1348 | retval = platform_driver_register(&EP93XX_PLATFORM_DRIVER); | ||
1349 | if (retval < 0) | ||
1350 | goto error_ep93xx; | ||
1351 | #endif | ||
1352 | |||
1353 | #ifdef AT91_PLATFORM_DRIVER | ||
1354 | retval = platform_driver_register(&AT91_PLATFORM_DRIVER); | ||
1355 | if (retval < 0) | ||
1356 | goto error_at91; | ||
1357 | #endif | ||
1358 | |||
1359 | #ifdef NXP_PLATFORM_DRIVER | ||
1360 | retval = platform_driver_register(&NXP_PLATFORM_DRIVER); | ||
1361 | if (retval < 0) | ||
1362 | goto error_nxp; | ||
1363 | #endif | ||
1364 | |||
1365 | #ifdef DAVINCI_PLATFORM_DRIVER | 1280 | #ifdef DAVINCI_PLATFORM_DRIVER |
1366 | retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER); | 1281 | retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER); |
1367 | if (retval < 0) | 1282 | if (retval < 0) |
1368 | goto error_davinci; | 1283 | goto error_davinci; |
1369 | #endif | 1284 | #endif |
1370 | 1285 | ||
1371 | #ifdef SPEAR_PLATFORM_DRIVER | ||
1372 | retval = platform_driver_register(&SPEAR_PLATFORM_DRIVER); | ||
1373 | if (retval < 0) | ||
1374 | goto error_spear; | ||
1375 | #endif | ||
1376 | |||
1377 | return retval; | 1286 | return retval; |
1378 | 1287 | ||
1379 | /* Error path */ | 1288 | /* Error path */ |
1380 | #ifdef SPEAR_PLATFORM_DRIVER | ||
1381 | platform_driver_unregister(&SPEAR_PLATFORM_DRIVER); | ||
1382 | error_spear: | ||
1383 | #endif | ||
1384 | #ifdef DAVINCI_PLATFORM_DRIVER | 1289 | #ifdef DAVINCI_PLATFORM_DRIVER |
1385 | platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); | 1290 | platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); |
1386 | error_davinci: | 1291 | error_davinci: |
1387 | #endif | 1292 | #endif |
1388 | #ifdef NXP_PLATFORM_DRIVER | ||
1389 | platform_driver_unregister(&NXP_PLATFORM_DRIVER); | ||
1390 | error_nxp: | ||
1391 | #endif | ||
1392 | #ifdef AT91_PLATFORM_DRIVER | ||
1393 | platform_driver_unregister(&AT91_PLATFORM_DRIVER); | ||
1394 | error_at91: | ||
1395 | #endif | ||
1396 | #ifdef EP93XX_PLATFORM_DRIVER | ||
1397 | platform_driver_unregister(&EP93XX_PLATFORM_DRIVER); | ||
1398 | error_ep93xx: | ||
1399 | #endif | ||
1400 | #ifdef EXYNOS_PLATFORM_DRIVER | ||
1401 | platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER); | ||
1402 | error_exynos: | ||
1403 | #endif | ||
1404 | #ifdef S3C2410_PLATFORM_DRIVER | ||
1405 | platform_driver_unregister(&S3C2410_PLATFORM_DRIVER); | ||
1406 | error_s3c2410: | ||
1407 | #endif | ||
1408 | #ifdef TMIO_OHCI_DRIVER | 1293 | #ifdef TMIO_OHCI_DRIVER |
1409 | platform_driver_unregister(&TMIO_OHCI_DRIVER); | 1294 | platform_driver_unregister(&TMIO_OHCI_DRIVER); |
1410 | error_tmio: | 1295 | error_tmio: |
@@ -1421,14 +1306,6 @@ static int __init ohci_hcd_mod_init(void) | |||
1421 | platform_driver_unregister(&OF_PLATFORM_DRIVER); | 1306 | platform_driver_unregister(&OF_PLATFORM_DRIVER); |
1422 | error_of_platform: | 1307 | error_of_platform: |
1423 | #endif | 1308 | #endif |
1424 | #ifdef OMAP3_PLATFORM_DRIVER | ||
1425 | platform_driver_unregister(&OMAP3_PLATFORM_DRIVER); | ||
1426 | error_omap3_platform: | ||
1427 | #endif | ||
1428 | #ifdef OMAP1_PLATFORM_DRIVER | ||
1429 | platform_driver_unregister(&OMAP1_PLATFORM_DRIVER); | ||
1430 | error_omap1_platform: | ||
1431 | #endif | ||
1432 | #ifdef PLATFORM_DRIVER | 1309 | #ifdef PLATFORM_DRIVER |
1433 | platform_driver_unregister(&PLATFORM_DRIVER); | 1310 | platform_driver_unregister(&PLATFORM_DRIVER); |
1434 | error_platform: | 1311 | error_platform: |
@@ -1450,27 +1327,9 @@ module_init(ohci_hcd_mod_init); | |||
1450 | 1327 | ||
1451 | static void __exit ohci_hcd_mod_exit(void) | 1328 | static void __exit ohci_hcd_mod_exit(void) |
1452 | { | 1329 | { |
1453 | #ifdef SPEAR_PLATFORM_DRIVER | ||
1454 | platform_driver_unregister(&SPEAR_PLATFORM_DRIVER); | ||
1455 | #endif | ||
1456 | #ifdef DAVINCI_PLATFORM_DRIVER | 1330 | #ifdef DAVINCI_PLATFORM_DRIVER |
1457 | platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); | 1331 | platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); |
1458 | #endif | 1332 | #endif |
1459 | #ifdef NXP_PLATFORM_DRIVER | ||
1460 | platform_driver_unregister(&NXP_PLATFORM_DRIVER); | ||
1461 | #endif | ||
1462 | #ifdef AT91_PLATFORM_DRIVER | ||
1463 | platform_driver_unregister(&AT91_PLATFORM_DRIVER); | ||
1464 | #endif | ||
1465 | #ifdef EP93XX_PLATFORM_DRIVER | ||
1466 | platform_driver_unregister(&EP93XX_PLATFORM_DRIVER); | ||
1467 | #endif | ||
1468 | #ifdef EXYNOS_PLATFORM_DRIVER | ||
1469 | platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER); | ||
1470 | #endif | ||
1471 | #ifdef S3C2410_PLATFORM_DRIVER | ||
1472 | platform_driver_unregister(&S3C2410_PLATFORM_DRIVER); | ||
1473 | #endif | ||
1474 | #ifdef TMIO_OHCI_DRIVER | 1333 | #ifdef TMIO_OHCI_DRIVER |
1475 | platform_driver_unregister(&TMIO_OHCI_DRIVER); | 1334 | platform_driver_unregister(&TMIO_OHCI_DRIVER); |
1476 | #endif | 1335 | #endif |
@@ -1483,12 +1342,6 @@ static void __exit ohci_hcd_mod_exit(void) | |||
1483 | #ifdef OF_PLATFORM_DRIVER | 1342 | #ifdef OF_PLATFORM_DRIVER |
1484 | platform_driver_unregister(&OF_PLATFORM_DRIVER); | 1343 | platform_driver_unregister(&OF_PLATFORM_DRIVER); |
1485 | #endif | 1344 | #endif |
1486 | #ifdef OMAP3_PLATFORM_DRIVER | ||
1487 | platform_driver_unregister(&OMAP3_PLATFORM_DRIVER); | ||
1488 | #endif | ||
1489 | #ifdef OMAP1_PLATFORM_DRIVER | ||
1490 | platform_driver_unregister(&OMAP1_PLATFORM_DRIVER); | ||
1491 | #endif | ||
1492 | #ifdef PLATFORM_DRIVER | 1345 | #ifdef PLATFORM_DRIVER |
1493 | platform_driver_unregister(&PLATFORM_DRIVER); | 1346 | platform_driver_unregister(&PLATFORM_DRIVER); |
1494 | #endif | 1347 | #endif |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index 2347ab83f046..61705a760e7d 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
@@ -212,10 +212,11 @@ __acquires(ohci->lock) | |||
212 | /* Sometimes PCI D3 suspend trashes frame timings ... */ | 212 | /* Sometimes PCI D3 suspend trashes frame timings ... */ |
213 | periodic_reinit (ohci); | 213 | periodic_reinit (ohci); |
214 | 214 | ||
215 | /* the following code is executed with ohci->lock held and | 215 | /* |
216 | * irqs disabled if and only if autostopped is true | 216 | * The following code is executed with ohci->lock held and |
217 | * irqs disabled if and only if autostopped is true. This | ||
218 | * will cause sparse to warn about a "context imbalance". | ||
217 | */ | 219 | */ |
218 | |||
219 | skip_resume: | 220 | skip_resume: |
220 | /* interrupts might have been disabled */ | 221 | /* interrupts might have been disabled */ |
221 | ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); | 222 | ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); |
@@ -531,7 +532,7 @@ ohci_hub_descriptor ( | |||
531 | temp |= 0x0010; | 532 | temp |= 0x0010; |
532 | else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ | 533 | else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ |
533 | temp |= 0x0008; | 534 | temp |= 0x0008; |
534 | desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); | 535 | desc->wHubCharacteristics = cpu_to_le16(temp); |
535 | 536 | ||
536 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 537 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
537 | rh = roothub_b (ohci); | 538 | rh = roothub_b (ohci); |
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c index 7d7d507d54e8..9ab7e24ba65d 100644 --- a/drivers/usb/host/ohci-nxp.c +++ b/drivers/usb/host/ohci-nxp.c | |||
@@ -19,10 +19,19 @@ | |||
19 | * or implied. | 19 | * or implied. |
20 | */ | 20 | */ |
21 | #include <linux/clk.h> | 21 | #include <linux/clk.h> |
22 | #include <linux/platform_device.h> | 22 | #include <linux/dma-mapping.h> |
23 | #include <linux/io.h> | ||
23 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <linux/kernel.h> | ||
26 | #include <linux/module.h> | ||
24 | #include <linux/of.h> | 27 | #include <linux/of.h> |
28 | #include <linux/platform_device.h> | ||
25 | #include <linux/usb/isp1301.h> | 29 | #include <linux/usb/isp1301.h> |
30 | #include <linux/usb.h> | ||
31 | #include <linux/usb/hcd.h> | ||
32 | |||
33 | #include "ohci.h" | ||
34 | |||
26 | 35 | ||
27 | #include <mach/hardware.h> | 36 | #include <mach/hardware.h> |
28 | #include <asm/mach-types.h> | 37 | #include <asm/mach-types.h> |
@@ -57,6 +66,11 @@ | |||
57 | #define start_int_umask(irq) | 66 | #define start_int_umask(irq) |
58 | #endif | 67 | #endif |
59 | 68 | ||
69 | #define DRIVER_DESC "OHCI NXP driver" | ||
70 | |||
71 | static const char hcd_name[] = "ohci-nxp"; | ||
72 | static struct hc_driver __read_mostly ohci_nxp_hc_driver; | ||
73 | |||
60 | static struct i2c_client *isp1301_i2c_client; | 74 | static struct i2c_client *isp1301_i2c_client; |
61 | 75 | ||
62 | extern int usb_disabled(void); | 76 | extern int usb_disabled(void); |
@@ -132,14 +146,14 @@ static inline void isp1301_vbus_off(void) | |||
132 | OTG1_VBUS_DRV); | 146 | OTG1_VBUS_DRV); |
133 | } | 147 | } |
134 | 148 | ||
135 | static void nxp_start_hc(void) | 149 | static void ohci_nxp_start_hc(void) |
136 | { | 150 | { |
137 | unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; | 151 | unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; |
138 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); | 152 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
139 | isp1301_vbus_on(); | 153 | isp1301_vbus_on(); |
140 | } | 154 | } |
141 | 155 | ||
142 | static void nxp_stop_hc(void) | 156 | static void ohci_nxp_stop_hc(void) |
143 | { | 157 | { |
144 | unsigned long tmp; | 158 | unsigned long tmp; |
145 | isp1301_vbus_off(); | 159 | isp1301_vbus_off(); |
@@ -147,68 +161,9 @@ static void nxp_stop_hc(void) | |||
147 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); | 161 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
148 | } | 162 | } |
149 | 163 | ||
150 | static int ohci_nxp_start(struct usb_hcd *hcd) | 164 | static int ohci_hcd_nxp_probe(struct platform_device *pdev) |
151 | { | ||
152 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
153 | int ret; | ||
154 | |||
155 | if ((ret = ohci_init(ohci)) < 0) | ||
156 | return ret; | ||
157 | |||
158 | if ((ret = ohci_run(ohci)) < 0) { | ||
159 | dev_err(hcd->self.controller, "can't start\n"); | ||
160 | ohci_stop(hcd); | ||
161 | return ret; | ||
162 | } | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static const struct hc_driver ohci_nxp_hc_driver = { | ||
167 | .description = hcd_name, | ||
168 | .product_desc = "nxp OHCI", | ||
169 | |||
170 | /* | ||
171 | * generic hardware linkage | ||
172 | */ | ||
173 | .irq = ohci_irq, | ||
174 | .flags = HCD_USB11 | HCD_MEMORY, | ||
175 | |||
176 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
177 | /* | ||
178 | * basic lifecycle operations | ||
179 | */ | ||
180 | .start = ohci_nxp_start, | ||
181 | .stop = ohci_stop, | ||
182 | .shutdown = ohci_shutdown, | ||
183 | |||
184 | /* | ||
185 | * managing i/o requests and associated device resources | ||
186 | */ | ||
187 | .urb_enqueue = ohci_urb_enqueue, | ||
188 | .urb_dequeue = ohci_urb_dequeue, | ||
189 | .endpoint_disable = ohci_endpoint_disable, | ||
190 | |||
191 | /* | ||
192 | * scheduling support | ||
193 | */ | ||
194 | .get_frame_number = ohci_get_frame, | ||
195 | |||
196 | /* | ||
197 | * root hub support | ||
198 | */ | ||
199 | .hub_status_data = ohci_hub_status_data, | ||
200 | .hub_control = ohci_hub_control, | ||
201 | #ifdef CONFIG_PM | ||
202 | .bus_suspend = ohci_bus_suspend, | ||
203 | .bus_resume = ohci_bus_resume, | ||
204 | #endif | ||
205 | .start_port_reset = ohci_start_port_reset, | ||
206 | }; | ||
207 | |||
208 | static int usb_hcd_nxp_probe(struct platform_device *pdev) | ||
209 | { | 165 | { |
210 | struct usb_hcd *hcd = 0; | 166 | struct usb_hcd *hcd = 0; |
211 | struct ohci_hcd *ohci; | ||
212 | const struct hc_driver *driver = &ohci_nxp_hc_driver; | 167 | const struct hc_driver *driver = &ohci_nxp_hc_driver; |
213 | struct resource *res; | 168 | struct resource *res; |
214 | int ret = 0, irq; | 169 | int ret = 0, irq; |
@@ -313,17 +268,15 @@ static int usb_hcd_nxp_probe(struct platform_device *pdev) | |||
313 | goto fail_resource; | 268 | goto fail_resource; |
314 | } | 269 | } |
315 | 270 | ||
316 | nxp_start_hc(); | 271 | ohci_nxp_start_hc(); |
317 | platform_set_drvdata(pdev, hcd); | 272 | platform_set_drvdata(pdev, hcd); |
318 | ohci = hcd_to_ohci(hcd); | ||
319 | ohci_hcd_init(ohci); | ||
320 | 273 | ||
321 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); | 274 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); |
322 | ret = usb_add_hcd(hcd, irq, 0); | 275 | ret = usb_add_hcd(hcd, irq, 0); |
323 | if (ret == 0) | 276 | if (ret == 0) |
324 | return ret; | 277 | return ret; |
325 | 278 | ||
326 | nxp_stop_hc(); | 279 | ohci_nxp_stop_hc(); |
327 | fail_resource: | 280 | fail_resource: |
328 | usb_put_hcd(hcd); | 281 | usb_put_hcd(hcd); |
329 | fail_hcd: | 282 | fail_hcd: |
@@ -345,12 +298,12 @@ fail_disable: | |||
345 | return ret; | 298 | return ret; |
346 | } | 299 | } |
347 | 300 | ||
348 | static int usb_hcd_nxp_remove(struct platform_device *pdev) | 301 | static int ohci_hcd_nxp_remove(struct platform_device *pdev) |
349 | { | 302 | { |
350 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 303 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
351 | 304 | ||
352 | usb_remove_hcd(hcd); | 305 | usb_remove_hcd(hcd); |
353 | nxp_stop_hc(); | 306 | ohci_nxp_stop_hc(); |
354 | usb_put_hcd(hcd); | 307 | usb_put_hcd(hcd); |
355 | clk_disable(usb_pll_clk); | 308 | clk_disable(usb_pll_clk); |
356 | clk_put(usb_pll_clk); | 309 | clk_put(usb_pll_clk); |
@@ -366,20 +319,40 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev) | |||
366 | MODULE_ALIAS("platform:usb-ohci"); | 319 | MODULE_ALIAS("platform:usb-ohci"); |
367 | 320 | ||
368 | #ifdef CONFIG_OF | 321 | #ifdef CONFIG_OF |
369 | static const struct of_device_id usb_hcd_nxp_match[] = { | 322 | static const struct of_device_id ohci_hcd_nxp_match[] = { |
370 | { .compatible = "nxp,ohci-nxp" }, | 323 | { .compatible = "nxp,ohci-nxp" }, |
371 | {}, | 324 | {}, |
372 | }; | 325 | }; |
373 | MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match); | 326 | MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match); |
374 | #endif | 327 | #endif |
375 | 328 | ||
376 | static struct platform_driver usb_hcd_nxp_driver = { | 329 | static struct platform_driver ohci_hcd_nxp_driver = { |
377 | .driver = { | 330 | .driver = { |
378 | .name = "usb-ohci", | 331 | .name = "usb-ohci", |
379 | .owner = THIS_MODULE, | 332 | .owner = THIS_MODULE, |
380 | .of_match_table = of_match_ptr(usb_hcd_nxp_match), | 333 | .of_match_table = of_match_ptr(ohci_hcd_nxp_match), |
381 | }, | 334 | }, |
382 | .probe = usb_hcd_nxp_probe, | 335 | .probe = ohci_hcd_nxp_probe, |
383 | .remove = usb_hcd_nxp_remove, | 336 | .remove = ohci_hcd_nxp_remove, |
384 | }; | 337 | }; |
385 | 338 | ||
339 | static int __init ohci_nxp_init(void) | ||
340 | { | ||
341 | if (usb_disabled()) | ||
342 | return -ENODEV; | ||
343 | |||
344 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
345 | |||
346 | ohci_init_driver(&ohci_nxp_hc_driver, NULL); | ||
347 | return platform_driver_register(&ohci_hcd_nxp_driver); | ||
348 | } | ||
349 | module_init(ohci_nxp_init); | ||
350 | |||
351 | static void __exit ohci_nxp_cleanup(void) | ||
352 | { | ||
353 | platform_driver_unregister(&ohci_hcd_nxp_driver); | ||
354 | } | ||
355 | module_exit(ohci_nxp_cleanup); | ||
356 | |||
357 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
358 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index 31d3a12eb486..f253214741ba 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c | |||
@@ -14,12 +14,21 @@ | |||
14 | * This file is licenced under the GPL. | 14 | * This file is licenced under the GPL. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/signal.h> | ||
18 | #include <linux/jiffies.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/clk.h> | 17 | #include <linux/clk.h> |
18 | #include <linux/dma-mapping.h> | ||
21 | #include <linux/err.h> | 19 | #include <linux/err.h> |
22 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
21 | #include <linux/io.h> | ||
22 | #include <linux/jiffies.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/usb/otg.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/signal.h> | ||
28 | #include <linux/usb.h> | ||
29 | #include <linux/usb/hcd.h> | ||
30 | |||
31 | #include "ohci.h" | ||
23 | 32 | ||
24 | #include <asm/io.h> | 33 | #include <asm/io.h> |
25 | #include <asm/mach-types.h> | 34 | #include <asm/mach-types.h> |
@@ -42,10 +51,7 @@ | |||
42 | #define OMAP1510_LB_MMU_RAM_H 0xfffec234 | 51 | #define OMAP1510_LB_MMU_RAM_H 0xfffec234 |
43 | #define OMAP1510_LB_MMU_RAM_L 0xfffec238 | 52 | #define OMAP1510_LB_MMU_RAM_L 0xfffec238 |
44 | 53 | ||
45 | 54 | #define DRIVER_DESC "OHCI OMAP driver" | |
46 | #ifndef CONFIG_ARCH_OMAP | ||
47 | #error "This file is OMAP bus glue. CONFIG_OMAP must be defined." | ||
48 | #endif | ||
49 | 55 | ||
50 | #ifdef CONFIG_TPS65010 | 56 | #ifdef CONFIG_TPS65010 |
51 | #include <linux/i2c/tps65010.h> | 57 | #include <linux/i2c/tps65010.h> |
@@ -68,8 +74,9 @@ extern int ocpi_enable(void); | |||
68 | 74 | ||
69 | static struct clk *usb_host_ck; | 75 | static struct clk *usb_host_ck; |
70 | static struct clk *usb_dc_ck; | 76 | static struct clk *usb_dc_ck; |
71 | static int host_enabled; | 77 | |
72 | static int host_initialized; | 78 | static const char hcd_name[] = "ohci-omap"; |
79 | static struct hc_driver __read_mostly ohci_omap_hc_driver; | ||
73 | 80 | ||
74 | static void omap_ohci_clock_power(int on) | 81 | static void omap_ohci_clock_power(int on) |
75 | { | 82 | { |
@@ -188,7 +195,7 @@ static void start_hnp(struct ohci_hcd *ohci) | |||
188 | 195 | ||
189 | /*-------------------------------------------------------------------------*/ | 196 | /*-------------------------------------------------------------------------*/ |
190 | 197 | ||
191 | static int ohci_omap_init(struct usb_hcd *hcd) | 198 | static int ohci_omap_reset(struct usb_hcd *hcd) |
192 | { | 199 | { |
193 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 200 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
194 | struct omap_usb_config *config = dev_get_platdata(hcd->self.controller); | 201 | struct omap_usb_config *config = dev_get_platdata(hcd->self.controller); |
@@ -198,9 +205,9 @@ static int ohci_omap_init(struct usb_hcd *hcd) | |||
198 | dev_dbg(hcd->self.controller, "starting USB Controller\n"); | 205 | dev_dbg(hcd->self.controller, "starting USB Controller\n"); |
199 | 206 | ||
200 | if (config->otg) { | 207 | if (config->otg) { |
201 | ohci_to_hcd(ohci)->self.otg_port = config->otg; | 208 | hcd->self.otg_port = config->otg; |
202 | /* default/minimum OTG power budget: 8 mA */ | 209 | /* default/minimum OTG power budget: 8 mA */ |
203 | ohci_to_hcd(ohci)->power_budget = 8; | 210 | hcd->power_budget = 8; |
204 | } | 211 | } |
205 | 212 | ||
206 | /* boards can use OTG transceivers in non-OTG modes */ | 213 | /* boards can use OTG transceivers in non-OTG modes */ |
@@ -238,9 +245,15 @@ static int ohci_omap_init(struct usb_hcd *hcd) | |||
238 | omap_1510_local_bus_init(); | 245 | omap_1510_local_bus_init(); |
239 | } | 246 | } |
240 | 247 | ||
241 | if ((ret = ohci_init(ohci)) < 0) | 248 | ret = ohci_setup(hcd); |
249 | if (ret < 0) | ||
242 | return ret; | 250 | return ret; |
243 | 251 | ||
252 | if (config->otg || config->rwc) { | ||
253 | ohci->hc_control = OHCI_CTRL_RWC; | ||
254 | writel(OHCI_CTRL_RWC, &ohci->regs->control); | ||
255 | } | ||
256 | |||
244 | /* board-specific power switching and overcurrent support */ | 257 | /* board-specific power switching and overcurrent support */ |
245 | if (machine_is_omap_osk() || machine_is_omap_innovator()) { | 258 | if (machine_is_omap_osk() || machine_is_omap_innovator()) { |
246 | u32 rh = roothub_a (ohci); | 259 | u32 rh = roothub_a (ohci); |
@@ -281,14 +294,6 @@ static int ohci_omap_init(struct usb_hcd *hcd) | |||
281 | return 0; | 294 | return 0; |
282 | } | 295 | } |
283 | 296 | ||
284 | static void ohci_omap_stop(struct usb_hcd *hcd) | ||
285 | { | ||
286 | dev_dbg(hcd->self.controller, "stopping USB Controller\n"); | ||
287 | ohci_stop(hcd); | ||
288 | omap_ohci_clock_power(0); | ||
289 | } | ||
290 | |||
291 | |||
292 | /*-------------------------------------------------------------------------*/ | 297 | /*-------------------------------------------------------------------------*/ |
293 | 298 | ||
294 | /** | 299 | /** |
@@ -304,7 +309,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver, | |||
304 | { | 309 | { |
305 | int retval, irq; | 310 | int retval, irq; |
306 | struct usb_hcd *hcd = 0; | 311 | struct usb_hcd *hcd = 0; |
307 | struct ohci_hcd *ohci; | ||
308 | 312 | ||
309 | if (pdev->num_resources != 2) { | 313 | if (pdev->num_resources != 2) { |
310 | printk(KERN_ERR "hcd probe: invalid num_resources: %i\n", | 314 | printk(KERN_ERR "hcd probe: invalid num_resources: %i\n", |
@@ -354,12 +358,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver, | |||
354 | goto err2; | 358 | goto err2; |
355 | } | 359 | } |
356 | 360 | ||
357 | ohci = hcd_to_ohci(hcd); | ||
358 | ohci_hcd_init(ohci); | ||
359 | |||
360 | host_initialized = 0; | ||
361 | host_enabled = 1; | ||
362 | |||
363 | irq = platform_get_irq(pdev, 0); | 361 | irq = platform_get_irq(pdev, 0); |
364 | if (irq < 0) { | 362 | if (irq < 0) { |
365 | retval = -ENXIO; | 363 | retval = -ENXIO; |
@@ -369,11 +367,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver, | |||
369 | if (retval) | 367 | if (retval) |
370 | goto err3; | 368 | goto err3; |
371 | 369 | ||
372 | host_initialized = 1; | ||
373 | |||
374 | if (!host_enabled) | ||
375 | omap_ohci_clock_power(0); | ||
376 | |||
377 | return 0; | 370 | return 0; |
378 | err3: | 371 | err3: |
379 | iounmap(hcd->regs); | 372 | iounmap(hcd->regs); |
@@ -402,7 +395,9 @@ err0: | |||
402 | static inline void | 395 | static inline void |
403 | usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) | 396 | usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) |
404 | { | 397 | { |
398 | dev_dbg(hcd->self.controller, "stopping USB Controller\n"); | ||
405 | usb_remove_hcd(hcd); | 399 | usb_remove_hcd(hcd); |
400 | omap_ohci_clock_power(0); | ||
406 | if (!IS_ERR_OR_NULL(hcd->phy)) { | 401 | if (!IS_ERR_OR_NULL(hcd->phy)) { |
407 | (void) otg_set_host(hcd->phy->otg, 0); | 402 | (void) otg_set_host(hcd->phy->otg, 0); |
408 | usb_put_phy(hcd->phy); | 403 | usb_put_phy(hcd->phy); |
@@ -418,76 +413,6 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) | |||
418 | 413 | ||
419 | /*-------------------------------------------------------------------------*/ | 414 | /*-------------------------------------------------------------------------*/ |
420 | 415 | ||
421 | static int | ||
422 | ohci_omap_start (struct usb_hcd *hcd) | ||
423 | { | ||
424 | struct omap_usb_config *config; | ||
425 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | ||
426 | int ret; | ||
427 | |||
428 | if (!host_enabled) | ||
429 | return 0; | ||
430 | config = dev_get_platdata(hcd->self.controller); | ||
431 | if (config->otg || config->rwc) { | ||
432 | ohci->hc_control = OHCI_CTRL_RWC; | ||
433 | writel(OHCI_CTRL_RWC, &ohci->regs->control); | ||
434 | } | ||
435 | |||
436 | if ((ret = ohci_run (ohci)) < 0) { | ||
437 | dev_err(hcd->self.controller, "can't start\n"); | ||
438 | ohci_stop (hcd); | ||
439 | return ret; | ||
440 | } | ||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | /*-------------------------------------------------------------------------*/ | ||
445 | |||
446 | static const struct hc_driver ohci_omap_hc_driver = { | ||
447 | .description = hcd_name, | ||
448 | .product_desc = "OMAP OHCI", | ||
449 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
450 | |||
451 | /* | ||
452 | * generic hardware linkage | ||
453 | */ | ||
454 | .irq = ohci_irq, | ||
455 | .flags = HCD_USB11 | HCD_MEMORY, | ||
456 | |||
457 | /* | ||
458 | * basic lifecycle operations | ||
459 | */ | ||
460 | .reset = ohci_omap_init, | ||
461 | .start = ohci_omap_start, | ||
462 | .stop = ohci_omap_stop, | ||
463 | .shutdown = ohci_shutdown, | ||
464 | |||
465 | /* | ||
466 | * managing i/o requests and associated device resources | ||
467 | */ | ||
468 | .urb_enqueue = ohci_urb_enqueue, | ||
469 | .urb_dequeue = ohci_urb_dequeue, | ||
470 | .endpoint_disable = ohci_endpoint_disable, | ||
471 | |||
472 | /* | ||
473 | * scheduling support | ||
474 | */ | ||
475 | .get_frame_number = ohci_get_frame, | ||
476 | |||
477 | /* | ||
478 | * root hub support | ||
479 | */ | ||
480 | .hub_status_data = ohci_hub_status_data, | ||
481 | .hub_control = ohci_hub_control, | ||
482 | #ifdef CONFIG_PM | ||
483 | .bus_suspend = ohci_bus_suspend, | ||
484 | .bus_resume = ohci_bus_resume, | ||
485 | #endif | ||
486 | .start_port_reset = ohci_start_port_reset, | ||
487 | }; | ||
488 | |||
489 | /*-------------------------------------------------------------------------*/ | ||
490 | |||
491 | static int ohci_hcd_omap_drv_probe(struct platform_device *dev) | 416 | static int ohci_hcd_omap_drv_probe(struct platform_device *dev) |
492 | { | 417 | { |
493 | return usb_hcd_omap_probe(&ohci_omap_hc_driver, dev); | 418 | return usb_hcd_omap_probe(&ohci_omap_hc_driver, dev); |
@@ -506,16 +431,23 @@ static int ohci_hcd_omap_drv_remove(struct platform_device *dev) | |||
506 | 431 | ||
507 | #ifdef CONFIG_PM | 432 | #ifdef CONFIG_PM |
508 | 433 | ||
509 | static int ohci_omap_suspend(struct platform_device *dev, pm_message_t message) | 434 | static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t message) |
510 | { | 435 | { |
511 | struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(dev)); | 436 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
437 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
438 | bool do_wakeup = device_may_wakeup(&pdev->dev); | ||
439 | int ret; | ||
512 | 440 | ||
513 | if (time_before(jiffies, ohci->next_statechange)) | 441 | if (time_before(jiffies, ohci->next_statechange)) |
514 | msleep(5); | 442 | msleep(5); |
515 | ohci->next_statechange = jiffies; | 443 | ohci->next_statechange = jiffies; |
516 | 444 | ||
445 | ret = ohci_suspend(hcd, do_wakeup); | ||
446 | if (ret) | ||
447 | return ret; | ||
448 | |||
517 | omap_ohci_clock_power(0); | 449 | omap_ohci_clock_power(0); |
518 | return 0; | 450 | return ret; |
519 | } | 451 | } |
520 | 452 | ||
521 | static int ohci_omap_resume(struct platform_device *dev) | 453 | static int ohci_omap_resume(struct platform_device *dev) |
@@ -553,4 +485,29 @@ static struct platform_driver ohci_hcd_omap_driver = { | |||
553 | }, | 485 | }, |
554 | }; | 486 | }; |
555 | 487 | ||
488 | static const struct ohci_driver_overrides omap_overrides __initconst = { | ||
489 | .product_desc = "OMAP OHCI", | ||
490 | .reset = ohci_omap_reset | ||
491 | }; | ||
492 | |||
493 | static int __init ohci_omap_init(void) | ||
494 | { | ||
495 | if (usb_disabled()) | ||
496 | return -ENODEV; | ||
497 | |||
498 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
499 | |||
500 | ohci_init_driver(&ohci_omap_hc_driver, &omap_overrides); | ||
501 | return platform_driver_register(&ohci_hcd_omap_driver); | ||
502 | } | ||
503 | module_init(ohci_omap_init); | ||
504 | |||
505 | static void __exit ohci_omap_cleanup(void) | ||
506 | { | ||
507 | platform_driver_unregister(&ohci_hcd_omap_driver); | ||
508 | } | ||
509 | module_exit(ohci_omap_cleanup); | ||
510 | |||
511 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
556 | MODULE_ALIAS("platform:ohci"); | 512 | MODULE_ALIAS("platform:ohci"); |
513 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c index a09af26f69ed..408d06a68571 100644 --- a/drivers/usb/host/ohci-omap3.c +++ b/drivers/usb/host/ohci-omap3.c | |||
@@ -29,90 +29,22 @@ | |||
29 | * - add kernel-doc | 29 | * - add kernel-doc |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <linux/dma-mapping.h> | ||
33 | #include <linux/kernel.h> | ||
34 | #include <linux/module.h> | ||
35 | #include <linux/of.h> | ||
36 | #include <linux/usb/otg.h> | ||
32 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
33 | #include <linux/pm_runtime.h> | 38 | #include <linux/pm_runtime.h> |
34 | #include <linux/of.h> | 39 | #include <linux/usb.h> |
35 | #include <linux/dma-mapping.h> | 40 | #include <linux/usb/hcd.h> |
36 | |||
37 | /*-------------------------------------------------------------------------*/ | ||
38 | |||
39 | static int ohci_omap3_init(struct usb_hcd *hcd) | ||
40 | { | ||
41 | dev_dbg(hcd->self.controller, "starting OHCI controller\n"); | ||
42 | |||
43 | return ohci_init(hcd_to_ohci(hcd)); | ||
44 | } | ||
45 | |||
46 | /*-------------------------------------------------------------------------*/ | ||
47 | |||
48 | static int ohci_omap3_start(struct usb_hcd *hcd) | ||
49 | { | ||
50 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
51 | int ret; | ||
52 | |||
53 | /* | ||
54 | * RemoteWakeupConnected has to be set explicitly before | ||
55 | * calling ohci_run. The reset value of RWC is 0. | ||
56 | */ | ||
57 | ohci->hc_control = OHCI_CTRL_RWC; | ||
58 | writel(OHCI_CTRL_RWC, &ohci->regs->control); | ||
59 | |||
60 | ret = ohci_run(ohci); | ||
61 | |||
62 | if (ret < 0) { | ||
63 | dev_err(hcd->self.controller, "can't start\n"); | ||
64 | ohci_stop(hcd); | ||
65 | } | ||
66 | 41 | ||
67 | return ret; | 42 | #include "ohci.h" |
68 | } | ||
69 | 43 | ||
70 | /*-------------------------------------------------------------------------*/ | 44 | #define DRIVER_DESC "OHCI OMAP3 driver" |
71 | 45 | ||
72 | static const struct hc_driver ohci_omap3_hc_driver = { | 46 | static const char hcd_name[] = "ohci-omap3"; |
73 | .description = hcd_name, | 47 | static struct hc_driver __read_mostly ohci_omap3_hc_driver; |
74 | .product_desc = "OMAP3 OHCI Host Controller", | ||
75 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
76 | |||
77 | /* | ||
78 | * generic hardware linkage | ||
79 | */ | ||
80 | .irq = ohci_irq, | ||
81 | .flags = HCD_USB11 | HCD_MEMORY, | ||
82 | |||
83 | /* | ||
84 | * basic lifecycle operations | ||
85 | */ | ||
86 | .reset = ohci_omap3_init, | ||
87 | .start = ohci_omap3_start, | ||
88 | .stop = ohci_stop, | ||
89 | .shutdown = ohci_shutdown, | ||
90 | |||
91 | /* | ||
92 | * managing i/o requests and associated device resources | ||
93 | */ | ||
94 | .urb_enqueue = ohci_urb_enqueue, | ||
95 | .urb_dequeue = ohci_urb_dequeue, | ||
96 | .endpoint_disable = ohci_endpoint_disable, | ||
97 | |||
98 | /* | ||
99 | * scheduling support | ||
100 | */ | ||
101 | .get_frame_number = ohci_get_frame, | ||
102 | |||
103 | /* | ||
104 | * root hub support | ||
105 | */ | ||
106 | .hub_status_data = ohci_hub_status_data, | ||
107 | .hub_control = ohci_hub_control, | ||
108 | #ifdef CONFIG_PM | ||
109 | .bus_suspend = ohci_bus_suspend, | ||
110 | .bus_resume = ohci_bus_resume, | ||
111 | #endif | ||
112 | .start_port_reset = ohci_start_port_reset, | ||
113 | }; | ||
114 | |||
115 | /*-------------------------------------------------------------------------*/ | ||
116 | 48 | ||
117 | /* | 49 | /* |
118 | * configure so an HC device and id are always provided | 50 | * configure so an HC device and id are always provided |
@@ -129,6 +61,7 @@ static const struct hc_driver ohci_omap3_hc_driver = { | |||
129 | static int ohci_hcd_omap3_probe(struct platform_device *pdev) | 61 | static int ohci_hcd_omap3_probe(struct platform_device *pdev) |
130 | { | 62 | { |
131 | struct device *dev = &pdev->dev; | 63 | struct device *dev = &pdev->dev; |
64 | struct ohci_hcd *ohci; | ||
132 | struct usb_hcd *hcd = NULL; | 65 | struct usb_hcd *hcd = NULL; |
133 | void __iomem *regs = NULL; | 66 | void __iomem *regs = NULL; |
134 | struct resource *res; | 67 | struct resource *res; |
@@ -185,7 +118,12 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev) | |||
185 | pm_runtime_enable(dev); | 118 | pm_runtime_enable(dev); |
186 | pm_runtime_get_sync(dev); | 119 | pm_runtime_get_sync(dev); |
187 | 120 | ||
188 | ohci_hcd_init(hcd_to_ohci(hcd)); | 121 | ohci = hcd_to_ohci(hcd); |
122 | /* | ||
123 | * RemoteWakeupConnected has to be set explicitly before | ||
124 | * calling ohci_run. The reset value of RWC is 0. | ||
125 | */ | ||
126 | ohci->hc_control = OHCI_CTRL_RWC; | ||
189 | 127 | ||
190 | ret = usb_add_hcd(hcd, irq, 0); | 128 | ret = usb_add_hcd(hcd, irq, 0); |
191 | if (ret) { | 129 | if (ret) { |
@@ -248,5 +186,25 @@ static struct platform_driver ohci_hcd_omap3_driver = { | |||
248 | }, | 186 | }, |
249 | }; | 187 | }; |
250 | 188 | ||
189 | static int __init ohci_omap3_init(void) | ||
190 | { | ||
191 | if (usb_disabled()) | ||
192 | return -ENODEV; | ||
193 | |||
194 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
195 | |||
196 | ohci_init_driver(&ohci_omap3_hc_driver, NULL); | ||
197 | return platform_driver_register(&ohci_hcd_omap3_driver); | ||
198 | } | ||
199 | module_init(ohci_omap3_init); | ||
200 | |||
201 | static void __exit ohci_omap3_cleanup(void) | ||
202 | { | ||
203 | platform_driver_unregister(&ohci_hcd_omap3_driver); | ||
204 | } | ||
205 | module_exit(ohci_omap3_cleanup); | ||
206 | |||
207 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
251 | MODULE_ALIAS("platform:ohci-omap3"); | 208 | MODULE_ALIAS("platform:ohci-omap3"); |
252 | MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>"); | 209 | MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>"); |
210 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index ec337c2bd5e0..90879e9ccbec 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
@@ -150,28 +150,16 @@ static int ohci_quirk_nec(struct usb_hcd *hcd) | |||
150 | static int ohci_quirk_amd700(struct usb_hcd *hcd) | 150 | static int ohci_quirk_amd700(struct usb_hcd *hcd) |
151 | { | 151 | { |
152 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 152 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
153 | struct pci_dev *amd_smbus_dev; | ||
154 | u8 rev; | ||
155 | 153 | ||
156 | if (usb_amd_find_chipset_info()) | 154 | if (usb_amd_find_chipset_info()) |
157 | ohci->flags |= OHCI_QUIRK_AMD_PLL; | 155 | ohci->flags |= OHCI_QUIRK_AMD_PLL; |
158 | 156 | ||
159 | amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, | ||
160 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); | ||
161 | if (!amd_smbus_dev) | ||
162 | return 0; | ||
163 | |||
164 | rev = amd_smbus_dev->revision; | ||
165 | |||
166 | /* SB800 needs pre-fetch fix */ | 157 | /* SB800 needs pre-fetch fix */ |
167 | if ((rev >= 0x40) && (rev <= 0x4f)) { | 158 | if (usb_amd_prefetch_quirk()) { |
168 | ohci->flags |= OHCI_QUIRK_AMD_PREFETCH; | 159 | ohci->flags |= OHCI_QUIRK_AMD_PREFETCH; |
169 | ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); | 160 | ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); |
170 | } | 161 | } |
171 | 162 | ||
172 | pci_dev_put(amd_smbus_dev); | ||
173 | amd_smbus_dev = NULL; | ||
174 | |||
175 | return 0; | 163 | return 0; |
176 | } | 164 | } |
177 | 165 | ||
@@ -323,3 +311,4 @@ module_exit(ohci_pci_cleanup); | |||
323 | 311 | ||
324 | MODULE_DESCRIPTION(DRIVER_DESC); | 312 | MODULE_DESCRIPTION(DRIVER_DESC); |
325 | MODULE_LICENSE("GPL"); | 313 | MODULE_LICENSE("GPL"); |
314 | MODULE_SOFTDEP("pre: ehci_pci"); | ||
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c index a4c6410f0ed4..f351ff5b171f 100644 --- a/drivers/usb/host/ohci-platform.c +++ b/drivers/usb/host/ohci-platform.c | |||
@@ -139,14 +139,21 @@ static int ohci_platform_remove(struct platform_device *dev) | |||
139 | 139 | ||
140 | static int ohci_platform_suspend(struct device *dev) | 140 | static int ohci_platform_suspend(struct device *dev) |
141 | { | 141 | { |
142 | struct usb_ohci_pdata *pdata = dev_get_platdata(dev); | 142 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
143 | struct usb_ohci_pdata *pdata = dev->platform_data; | ||
143 | struct platform_device *pdev = | 144 | struct platform_device *pdev = |
144 | container_of(dev, struct platform_device, dev); | 145 | container_of(dev, struct platform_device, dev); |
146 | bool do_wakeup = device_may_wakeup(dev); | ||
147 | int ret; | ||
148 | |||
149 | ret = ohci_suspend(hcd, do_wakeup); | ||
150 | if (ret) | ||
151 | return ret; | ||
145 | 152 | ||
146 | if (pdata->power_suspend) | 153 | if (pdata->power_suspend) |
147 | pdata->power_suspend(pdev); | 154 | pdata->power_suspend(pdev); |
148 | 155 | ||
149 | return 0; | 156 | return ret; |
150 | } | 157 | } |
151 | 158 | ||
152 | static int ohci_platform_resume(struct device *dev) | 159 | static int ohci_platform_resume(struct device *dev) |
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index 93371a235e82..deea5d1d6394 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c | |||
@@ -19,15 +19,26 @@ | |||
19 | * This file is licenced under the GPL. | 19 | * This file is licenced under the GPL. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/device.h> | ||
23 | #include <linux/signal.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/device.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/module.h> | ||
26 | #include <linux/of_platform.h> | 27 | #include <linux/of_platform.h> |
27 | #include <linux/of_gpio.h> | 28 | #include <linux/of_gpio.h> |
28 | #include <mach/hardware.h> | ||
29 | #include <linux/platform_data/usb-ohci-pxa27x.h> | 29 | #include <linux/platform_data/usb-ohci-pxa27x.h> |
30 | #include <linux/platform_data/usb-pxa3xx-ulpi.h> | 30 | #include <linux/platform_data/usb-pxa3xx-ulpi.h> |
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/signal.h> | ||
33 | #include <linux/usb.h> | ||
34 | #include <linux/usb/hcd.h> | ||
35 | #include <linux/usb/otg.h> | ||
36 | |||
37 | #include <mach/hardware.h> | ||
38 | |||
39 | #include "ohci.h" | ||
40 | |||
41 | #define DRIVER_DESC "OHCI PXA27x/PXA3x driver" | ||
31 | 42 | ||
32 | /* | 43 | /* |
33 | * UHC: USB Host Controller (OHCI-like) register definitions | 44 | * UHC: USB Host Controller (OHCI-like) register definitions |
@@ -101,16 +112,16 @@ | |||
101 | 112 | ||
102 | #define PXA_UHC_MAX_PORTNUM 3 | 113 | #define PXA_UHC_MAX_PORTNUM 3 |
103 | 114 | ||
104 | struct pxa27x_ohci { | 115 | static const char hcd_name[] = "ohci-pxa27x"; |
105 | /* must be 1st member here for hcd_to_ohci() to work */ | 116 | |
106 | struct ohci_hcd ohci; | 117 | static struct hc_driver __read_mostly ohci_pxa27x_hc_driver; |
107 | 118 | ||
108 | struct device *dev; | 119 | struct pxa27x_ohci { |
109 | struct clk *clk; | 120 | struct clk *clk; |
110 | void __iomem *mmio_base; | 121 | void __iomem *mmio_base; |
111 | }; | 122 | }; |
112 | 123 | ||
113 | #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)hcd_to_ohci(hcd) | 124 | #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv) |
114 | 125 | ||
115 | /* | 126 | /* |
116 | PMM_NPS_MODE -- PMM Non-power switching mode | 127 | PMM_NPS_MODE -- PMM Non-power switching mode |
@@ -122,10 +133,10 @@ struct pxa27x_ohci { | |||
122 | PMM_PERPORT_MODE -- PMM per port switching mode | 133 | PMM_PERPORT_MODE -- PMM per port switching mode |
123 | Ports are powered individually. | 134 | Ports are powered individually. |
124 | */ | 135 | */ |
125 | static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode) | 136 | static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *pxa_ohci, int mode) |
126 | { | 137 | { |
127 | uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA); | 138 | uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA); |
128 | uint32_t uhcrhdb = __raw_readl(ohci->mmio_base + UHCRHDB); | 139 | uint32_t uhcrhdb = __raw_readl(pxa_ohci->mmio_base + UHCRHDB); |
129 | 140 | ||
130 | switch (mode) { | 141 | switch (mode) { |
131 | case PMM_NPS_MODE: | 142 | case PMM_NPS_MODE: |
@@ -149,20 +160,18 @@ static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode) | |||
149 | uhcrhda |= RH_A_NPS; | 160 | uhcrhda |= RH_A_NPS; |
150 | } | 161 | } |
151 | 162 | ||
152 | __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA); | 163 | __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA); |
153 | __raw_writel(uhcrhdb, ohci->mmio_base + UHCRHDB); | 164 | __raw_writel(uhcrhdb, pxa_ohci->mmio_base + UHCRHDB); |
154 | return 0; | 165 | return 0; |
155 | } | 166 | } |
156 | 167 | ||
157 | extern int usb_disabled(void); | ||
158 | |||
159 | /*-------------------------------------------------------------------------*/ | 168 | /*-------------------------------------------------------------------------*/ |
160 | 169 | ||
161 | static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci, | 170 | static inline void pxa27x_setup_hc(struct pxa27x_ohci *pxa_ohci, |
162 | struct pxaohci_platform_data *inf) | 171 | struct pxaohci_platform_data *inf) |
163 | { | 172 | { |
164 | uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR); | 173 | uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR); |
165 | uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA); | 174 | uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA); |
166 | 175 | ||
167 | if (inf->flags & ENABLE_PORT1) | 176 | if (inf->flags & ENABLE_PORT1) |
168 | uhchr &= ~UHCHR_SSEP1; | 177 | uhchr &= ~UHCHR_SSEP1; |
@@ -194,17 +203,17 @@ static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci, | |||
194 | uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); | 203 | uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); |
195 | } | 204 | } |
196 | 205 | ||
197 | __raw_writel(uhchr, ohci->mmio_base + UHCHR); | 206 | __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); |
198 | __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA); | 207 | __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA); |
199 | } | 208 | } |
200 | 209 | ||
201 | static inline void pxa27x_reset_hc(struct pxa27x_ohci *ohci) | 210 | static inline void pxa27x_reset_hc(struct pxa27x_ohci *pxa_ohci) |
202 | { | 211 | { |
203 | uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR); | 212 | uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR); |
204 | 213 | ||
205 | __raw_writel(uhchr | UHCHR_FHR, ohci->mmio_base + UHCHR); | 214 | __raw_writel(uhchr | UHCHR_FHR, pxa_ohci->mmio_base + UHCHR); |
206 | udelay(11); | 215 | udelay(11); |
207 | __raw_writel(uhchr & ~UHCHR_FHR, ohci->mmio_base + UHCHR); | 216 | __raw_writel(uhchr & ~UHCHR_FHR, pxa_ohci->mmio_base + UHCHR); |
208 | } | 217 | } |
209 | 218 | ||
210 | #ifdef CONFIG_PXA27x | 219 | #ifdef CONFIG_PXA27x |
@@ -213,25 +222,26 @@ extern void pxa27x_clear_otgph(void); | |||
213 | #define pxa27x_clear_otgph() do {} while (0) | 222 | #define pxa27x_clear_otgph() do {} while (0) |
214 | #endif | 223 | #endif |
215 | 224 | ||
216 | static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev) | 225 | static int pxa27x_start_hc(struct pxa27x_ohci *pxa_ohci, struct device *dev) |
217 | { | 226 | { |
218 | int retval = 0; | 227 | int retval = 0; |
219 | struct pxaohci_platform_data *inf; | 228 | struct pxaohci_platform_data *inf; |
220 | uint32_t uhchr; | 229 | uint32_t uhchr; |
230 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
221 | 231 | ||
222 | inf = dev_get_platdata(dev); | 232 | inf = dev_get_platdata(dev); |
223 | 233 | ||
224 | clk_prepare_enable(ohci->clk); | 234 | clk_prepare_enable(pxa_ohci->clk); |
225 | 235 | ||
226 | pxa27x_reset_hc(ohci); | 236 | pxa27x_reset_hc(pxa_ohci); |
227 | 237 | ||
228 | uhchr = __raw_readl(ohci->mmio_base + UHCHR) | UHCHR_FSBIR; | 238 | uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) | UHCHR_FSBIR; |
229 | __raw_writel(uhchr, ohci->mmio_base + UHCHR); | 239 | __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); |
230 | 240 | ||
231 | while (__raw_readl(ohci->mmio_base + UHCHR) & UHCHR_FSBIR) | 241 | while (__raw_readl(pxa_ohci->mmio_base + UHCHR) & UHCHR_FSBIR) |
232 | cpu_relax(); | 242 | cpu_relax(); |
233 | 243 | ||
234 | pxa27x_setup_hc(ohci, inf); | 244 | pxa27x_setup_hc(pxa_ohci, inf); |
235 | 245 | ||
236 | if (inf->init) | 246 | if (inf->init) |
237 | retval = inf->init(dev); | 247 | retval = inf->init(dev); |
@@ -240,38 +250,39 @@ static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev) | |||
240 | return retval; | 250 | return retval; |
241 | 251 | ||
242 | if (cpu_is_pxa3xx()) | 252 | if (cpu_is_pxa3xx()) |
243 | pxa3xx_u2d_start_hc(&ohci_to_hcd(&ohci->ohci)->self); | 253 | pxa3xx_u2d_start_hc(&hcd->self); |
244 | 254 | ||
245 | uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE; | 255 | uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) & ~UHCHR_SSE; |
246 | __raw_writel(uhchr, ohci->mmio_base + UHCHR); | 256 | __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); |
247 | __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE); | 257 | __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, pxa_ohci->mmio_base + UHCHIE); |
248 | 258 | ||
249 | /* Clear any OTG Pin Hold */ | 259 | /* Clear any OTG Pin Hold */ |
250 | pxa27x_clear_otgph(); | 260 | pxa27x_clear_otgph(); |
251 | return 0; | 261 | return 0; |
252 | } | 262 | } |
253 | 263 | ||
254 | static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev) | 264 | static void pxa27x_stop_hc(struct pxa27x_ohci *pxa_ohci, struct device *dev) |
255 | { | 265 | { |
256 | struct pxaohci_platform_data *inf; | 266 | struct pxaohci_platform_data *inf; |
267 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
257 | uint32_t uhccoms; | 268 | uint32_t uhccoms; |
258 | 269 | ||
259 | inf = dev_get_platdata(dev); | 270 | inf = dev_get_platdata(dev); |
260 | 271 | ||
261 | if (cpu_is_pxa3xx()) | 272 | if (cpu_is_pxa3xx()) |
262 | pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self); | 273 | pxa3xx_u2d_stop_hc(&hcd->self); |
263 | 274 | ||
264 | if (inf->exit) | 275 | if (inf->exit) |
265 | inf->exit(dev); | 276 | inf->exit(dev); |
266 | 277 | ||
267 | pxa27x_reset_hc(ohci); | 278 | pxa27x_reset_hc(pxa_ohci); |
268 | 279 | ||
269 | /* Host Controller Reset */ | 280 | /* Host Controller Reset */ |
270 | uhccoms = __raw_readl(ohci->mmio_base + UHCCOMS) | 0x01; | 281 | uhccoms = __raw_readl(pxa_ohci->mmio_base + UHCCOMS) | 0x01; |
271 | __raw_writel(uhccoms, ohci->mmio_base + UHCCOMS); | 282 | __raw_writel(uhccoms, pxa_ohci->mmio_base + UHCCOMS); |
272 | udelay(10); | 283 | udelay(10); |
273 | 284 | ||
274 | clk_disable_unprepare(ohci->clk); | 285 | clk_disable_unprepare(pxa_ohci->clk); |
275 | } | 286 | } |
276 | 287 | ||
277 | #ifdef CONFIG_OF | 288 | #ifdef CONFIG_OF |
@@ -356,7 +367,8 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
356 | int retval, irq; | 367 | int retval, irq; |
357 | struct usb_hcd *hcd; | 368 | struct usb_hcd *hcd; |
358 | struct pxaohci_platform_data *inf; | 369 | struct pxaohci_platform_data *inf; |
359 | struct pxa27x_ohci *ohci; | 370 | struct pxa27x_ohci *pxa_ohci; |
371 | struct ohci_hcd *ohci; | ||
360 | struct resource *r; | 372 | struct resource *r; |
361 | struct clk *usb_clk; | 373 | struct clk *usb_clk; |
362 | 374 | ||
@@ -409,29 +421,31 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
409 | } | 421 | } |
410 | 422 | ||
411 | /* initialize "struct pxa27x_ohci" */ | 423 | /* initialize "struct pxa27x_ohci" */ |
412 | ohci = (struct pxa27x_ohci *)hcd_to_ohci(hcd); | 424 | pxa_ohci = to_pxa27x_ohci(hcd); |
413 | ohci->dev = &pdev->dev; | 425 | pxa_ohci->clk = usb_clk; |
414 | ohci->clk = usb_clk; | 426 | pxa_ohci->mmio_base = (void __iomem *)hcd->regs; |
415 | ohci->mmio_base = (void __iomem *)hcd->regs; | ||
416 | 427 | ||
417 | if ((retval = pxa27x_start_hc(ohci, &pdev->dev)) < 0) { | 428 | retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); |
429 | if (retval < 0) { | ||
418 | pr_debug("pxa27x_start_hc failed"); | 430 | pr_debug("pxa27x_start_hc failed"); |
419 | goto err3; | 431 | goto err3; |
420 | } | 432 | } |
421 | 433 | ||
422 | /* Select Power Management Mode */ | 434 | /* Select Power Management Mode */ |
423 | pxa27x_ohci_select_pmm(ohci, inf->port_mode); | 435 | pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode); |
424 | 436 | ||
425 | if (inf->power_budget) | 437 | if (inf->power_budget) |
426 | hcd->power_budget = inf->power_budget; | 438 | hcd->power_budget = inf->power_budget; |
427 | 439 | ||
428 | ohci_hcd_init(hcd_to_ohci(hcd)); | 440 | /* The value of NDP in roothub_a is incorrect on this hardware */ |
441 | ohci = hcd_to_ohci(hcd); | ||
442 | ohci->num_ports = 3; | ||
429 | 443 | ||
430 | retval = usb_add_hcd(hcd, irq, 0); | 444 | retval = usb_add_hcd(hcd, irq, 0); |
431 | if (retval == 0) | 445 | if (retval == 0) |
432 | return retval; | 446 | return retval; |
433 | 447 | ||
434 | pxa27x_stop_hc(ohci, &pdev->dev); | 448 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); |
435 | err3: | 449 | err3: |
436 | iounmap(hcd->regs); | 450 | iounmap(hcd->regs); |
437 | err2: | 451 | err2: |
@@ -459,88 +473,18 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
459 | */ | 473 | */ |
460 | void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) | 474 | void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) |
461 | { | 475 | { |
462 | struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); | 476 | struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd); |
463 | 477 | ||
464 | usb_remove_hcd(hcd); | 478 | usb_remove_hcd(hcd); |
465 | pxa27x_stop_hc(ohci, &pdev->dev); | 479 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); |
466 | iounmap(hcd->regs); | 480 | iounmap(hcd->regs); |
467 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 481 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
482 | clk_put(pxa_ohci->clk); | ||
468 | usb_put_hcd(hcd); | 483 | usb_put_hcd(hcd); |
469 | clk_put(ohci->clk); | ||
470 | } | ||
471 | |||
472 | /*-------------------------------------------------------------------------*/ | ||
473 | |||
474 | static int | ||
475 | ohci_pxa27x_start (struct usb_hcd *hcd) | ||
476 | { | ||
477 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | ||
478 | int ret; | ||
479 | |||
480 | ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci); | ||
481 | |||
482 | /* The value of NDP in roothub_a is incorrect on this hardware */ | ||
483 | ohci->num_ports = 3; | ||
484 | |||
485 | if ((ret = ohci_init(ohci)) < 0) | ||
486 | return ret; | ||
487 | |||
488 | if ((ret = ohci_run (ohci)) < 0) { | ||
489 | dev_err(hcd->self.controller, "can't start %s", | ||
490 | hcd->self.bus_name); | ||
491 | ohci_stop (hcd); | ||
492 | return ret; | ||
493 | } | ||
494 | |||
495 | return 0; | ||
496 | } | 484 | } |
497 | 485 | ||
498 | /*-------------------------------------------------------------------------*/ | 486 | /*-------------------------------------------------------------------------*/ |
499 | 487 | ||
500 | static const struct hc_driver ohci_pxa27x_hc_driver = { | ||
501 | .description = hcd_name, | ||
502 | .product_desc = "PXA27x OHCI", | ||
503 | .hcd_priv_size = sizeof(struct pxa27x_ohci), | ||
504 | |||
505 | /* | ||
506 | * generic hardware linkage | ||
507 | */ | ||
508 | .irq = ohci_irq, | ||
509 | .flags = HCD_USB11 | HCD_MEMORY, | ||
510 | |||
511 | /* | ||
512 | * basic lifecycle operations | ||
513 | */ | ||
514 | .start = ohci_pxa27x_start, | ||
515 | .stop = ohci_stop, | ||
516 | .shutdown = ohci_shutdown, | ||
517 | |||
518 | /* | ||
519 | * managing i/o requests and associated device resources | ||
520 | */ | ||
521 | .urb_enqueue = ohci_urb_enqueue, | ||
522 | .urb_dequeue = ohci_urb_dequeue, | ||
523 | .endpoint_disable = ohci_endpoint_disable, | ||
524 | |||
525 | /* | ||
526 | * scheduling support | ||
527 | */ | ||
528 | .get_frame_number = ohci_get_frame, | ||
529 | |||
530 | /* | ||
531 | * root hub support | ||
532 | */ | ||
533 | .hub_status_data = ohci_hub_status_data, | ||
534 | .hub_control = ohci_hub_control, | ||
535 | #ifdef CONFIG_PM | ||
536 | .bus_suspend = ohci_bus_suspend, | ||
537 | .bus_resume = ohci_bus_resume, | ||
538 | #endif | ||
539 | .start_port_reset = ohci_start_port_reset, | ||
540 | }; | ||
541 | |||
542 | /*-------------------------------------------------------------------------*/ | ||
543 | |||
544 | static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev) | 488 | static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev) |
545 | { | 489 | { |
546 | pr_debug ("In ohci_hcd_pxa27x_drv_probe"); | 490 | pr_debug ("In ohci_hcd_pxa27x_drv_probe"); |
@@ -563,32 +507,42 @@ static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev) | |||
563 | static int ohci_hcd_pxa27x_drv_suspend(struct device *dev) | 507 | static int ohci_hcd_pxa27x_drv_suspend(struct device *dev) |
564 | { | 508 | { |
565 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 509 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
566 | struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); | 510 | struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd); |
511 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
512 | bool do_wakeup = device_may_wakeup(dev); | ||
513 | int ret; | ||
514 | |||
567 | 515 | ||
568 | if (time_before(jiffies, ohci->ohci.next_statechange)) | 516 | if (time_before(jiffies, ohci->next_statechange)) |
569 | msleep(5); | 517 | msleep(5); |
570 | ohci->ohci.next_statechange = jiffies; | 518 | ohci->next_statechange = jiffies; |
571 | 519 | ||
572 | pxa27x_stop_hc(ohci, dev); | 520 | ret = ohci_suspend(hcd, do_wakeup); |
573 | return 0; | 521 | if (ret) |
522 | return ret; | ||
523 | |||
524 | pxa27x_stop_hc(pxa_ohci, dev); | ||
525 | return ret; | ||
574 | } | 526 | } |
575 | 527 | ||
576 | static int ohci_hcd_pxa27x_drv_resume(struct device *dev) | 528 | static int ohci_hcd_pxa27x_drv_resume(struct device *dev) |
577 | { | 529 | { |
578 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 530 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
579 | struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); | 531 | struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd); |
580 | struct pxaohci_platform_data *inf = dev_get_platdata(dev); | 532 | struct pxaohci_platform_data *inf = dev_get_platdata(dev); |
533 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
581 | int status; | 534 | int status; |
582 | 535 | ||
583 | if (time_before(jiffies, ohci->ohci.next_statechange)) | 536 | if (time_before(jiffies, ohci->next_statechange)) |
584 | msleep(5); | 537 | msleep(5); |
585 | ohci->ohci.next_statechange = jiffies; | 538 | ohci->next_statechange = jiffies; |
586 | 539 | ||
587 | if ((status = pxa27x_start_hc(ohci, dev)) < 0) | 540 | status = pxa27x_start_hc(pxa_ohci, dev); |
541 | if (status < 0) | ||
588 | return status; | 542 | return status; |
589 | 543 | ||
590 | /* Select Power Management Mode */ | 544 | /* Select Power Management Mode */ |
591 | pxa27x_ohci_select_pmm(ohci, inf->port_mode); | 545 | pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode); |
592 | 546 | ||
593 | ohci_resume(hcd, false); | 547 | ohci_resume(hcd, false); |
594 | return 0; | 548 | return 0; |
@@ -600,9 +554,6 @@ static const struct dev_pm_ops ohci_hcd_pxa27x_pm_ops = { | |||
600 | }; | 554 | }; |
601 | #endif | 555 | #endif |
602 | 556 | ||
603 | /* work with hotplug and coldplug */ | ||
604 | MODULE_ALIAS("platform:pxa27x-ohci"); | ||
605 | |||
606 | static struct platform_driver ohci_hcd_pxa27x_driver = { | 557 | static struct platform_driver ohci_hcd_pxa27x_driver = { |
607 | .probe = ohci_hcd_pxa27x_drv_probe, | 558 | .probe = ohci_hcd_pxa27x_drv_probe, |
608 | .remove = ohci_hcd_pxa27x_drv_remove, | 559 | .remove = ohci_hcd_pxa27x_drv_remove, |
@@ -617,3 +568,27 @@ static struct platform_driver ohci_hcd_pxa27x_driver = { | |||
617 | }, | 568 | }, |
618 | }; | 569 | }; |
619 | 570 | ||
571 | static const struct ohci_driver_overrides pxa27x_overrides __initconst = { | ||
572 | .extra_priv_size = sizeof(struct pxa27x_ohci), | ||
573 | }; | ||
574 | |||
575 | static int __init ohci_pxa27x_init(void) | ||
576 | { | ||
577 | if (usb_disabled()) | ||
578 | return -ENODEV; | ||
579 | |||
580 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
581 | ohci_init_driver(&ohci_pxa27x_hc_driver, &pxa27x_overrides); | ||
582 | return platform_driver_register(&ohci_hcd_pxa27x_driver); | ||
583 | } | ||
584 | module_init(ohci_pxa27x_init); | ||
585 | |||
586 | static void __exit ohci_pxa27x_cleanup(void) | ||
587 | { | ||
588 | platform_driver_unregister(&ohci_hcd_pxa27x_driver); | ||
589 | } | ||
590 | module_exit(ohci_pxa27x_cleanup); | ||
591 | |||
592 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
593 | MODULE_LICENSE("GPL"); | ||
594 | MODULE_ALIAS("platform:pxa27x-ohci"); | ||
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c index 4919afa4125e..be3429e08d90 100644 --- a/drivers/usb/host/ohci-s3c2410.c +++ b/drivers/usb/host/ohci-s3c2410.c | |||
@@ -19,19 +19,36 @@ | |||
19 | * This file is licenced under the GPL. | 19 | * This file is licenced under the GPL. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/io.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/platform_device.h> | ||
24 | #include <linux/platform_data/usb-ohci-s3c2410.h> | 27 | #include <linux/platform_data/usb-ohci-s3c2410.h> |
28 | #include <linux/usb.h> | ||
29 | #include <linux/usb/hcd.h> | ||
30 | |||
31 | #include "ohci.h" | ||
32 | |||
25 | 33 | ||
26 | #define valid_port(idx) ((idx) == 1 || (idx) == 2) | 34 | #define valid_port(idx) ((idx) == 1 || (idx) == 2) |
27 | 35 | ||
28 | /* clock device associated with the hcd */ | 36 | /* clock device associated with the hcd */ |
29 | 37 | ||
38 | |||
39 | #define DRIVER_DESC "OHCI S3C2410 driver" | ||
40 | |||
41 | static const char hcd_name[] = "ohci-s3c2410"; | ||
42 | |||
30 | static struct clk *clk; | 43 | static struct clk *clk; |
31 | static struct clk *usb_clk; | 44 | static struct clk *usb_clk; |
32 | 45 | ||
33 | /* forward definitions */ | 46 | /* forward definitions */ |
34 | 47 | ||
48 | static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, | ||
49 | u16 wValue, u16 wIndex, char *buf, u16 wLength); | ||
50 | static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); | ||
51 | |||
35 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); | 52 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); |
36 | 53 | ||
37 | /* conversion functions */ | 54 | /* conversion functions */ |
@@ -93,7 +110,7 @@ ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
93 | int orig; | 110 | int orig; |
94 | int portno; | 111 | int portno; |
95 | 112 | ||
96 | orig = ohci_hub_status_data(hcd, buf); | 113 | orig = orig_ohci_hub_status_data(hcd, buf); |
97 | 114 | ||
98 | if (info == NULL) | 115 | if (info == NULL) |
99 | return orig; | 116 | return orig; |
@@ -164,7 +181,7 @@ static int ohci_s3c2410_hub_control( | |||
164 | * process the request straight away and exit */ | 181 | * process the request straight away and exit */ |
165 | 182 | ||
166 | if (info == NULL) { | 183 | if (info == NULL) { |
167 | ret = ohci_hub_control(hcd, typeReq, wValue, | 184 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, |
168 | wIndex, buf, wLength); | 185 | wIndex, buf, wLength); |
169 | goto out; | 186 | goto out; |
170 | } | 187 | } |
@@ -214,7 +231,7 @@ static int ohci_s3c2410_hub_control( | |||
214 | break; | 231 | break; |
215 | } | 232 | } |
216 | 233 | ||
217 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | 234 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
218 | if (ret) | 235 | if (ret) |
219 | goto out; | 236 | goto out; |
220 | 237 | ||
@@ -374,8 +391,6 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver, | |||
374 | 391 | ||
375 | s3c2410_start_hc(dev, hcd); | 392 | s3c2410_start_hc(dev, hcd); |
376 | 393 | ||
377 | ohci_hcd_init(hcd_to_ohci(hcd)); | ||
378 | |||
379 | retval = usb_add_hcd(hcd, dev->resource[1].start, 0); | 394 | retval = usb_add_hcd(hcd, dev->resource[1].start, 0); |
380 | if (retval != 0) | 395 | if (retval != 0) |
381 | goto err_ioremap; | 396 | goto err_ioremap; |
@@ -392,71 +407,7 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver, | |||
392 | 407 | ||
393 | /*-------------------------------------------------------------------------*/ | 408 | /*-------------------------------------------------------------------------*/ |
394 | 409 | ||
395 | static int | 410 | static struct hc_driver __read_mostly ohci_s3c2410_hc_driver; |
396 | ohci_s3c2410_start(struct usb_hcd *hcd) | ||
397 | { | ||
398 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
399 | int ret; | ||
400 | |||
401 | ret = ohci_init(ohci); | ||
402 | if (ret < 0) | ||
403 | return ret; | ||
404 | |||
405 | ret = ohci_run(ohci); | ||
406 | if (ret < 0) { | ||
407 | dev_err(hcd->self.controller, "can't start %s\n", | ||
408 | hcd->self.bus_name); | ||
409 | ohci_stop(hcd); | ||
410 | return ret; | ||
411 | } | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | |||
417 | static const struct hc_driver ohci_s3c2410_hc_driver = { | ||
418 | .description = hcd_name, | ||
419 | .product_desc = "S3C24XX OHCI", | ||
420 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
421 | |||
422 | /* | ||
423 | * generic hardware linkage | ||
424 | */ | ||
425 | .irq = ohci_irq, | ||
426 | .flags = HCD_USB11 | HCD_MEMORY, | ||
427 | |||
428 | /* | ||
429 | * basic lifecycle operations | ||
430 | */ | ||
431 | .start = ohci_s3c2410_start, | ||
432 | .stop = ohci_stop, | ||
433 | .shutdown = ohci_shutdown, | ||
434 | |||
435 | /* | ||
436 | * managing i/o requests and associated device resources | ||
437 | */ | ||
438 | .urb_enqueue = ohci_urb_enqueue, | ||
439 | .urb_dequeue = ohci_urb_dequeue, | ||
440 | .endpoint_disable = ohci_endpoint_disable, | ||
441 | |||
442 | /* | ||
443 | * scheduling support | ||
444 | */ | ||
445 | .get_frame_number = ohci_get_frame, | ||
446 | |||
447 | /* | ||
448 | * root hub support | ||
449 | */ | ||
450 | .hub_status_data = ohci_s3c2410_hub_status_data, | ||
451 | .hub_control = ohci_s3c2410_hub_control, | ||
452 | #ifdef CONFIG_PM | ||
453 | .bus_suspend = ohci_bus_suspend, | ||
454 | .bus_resume = ohci_bus_resume, | ||
455 | #endif | ||
456 | .start_port_reset = ohci_start_port_reset, | ||
457 | }; | ||
458 | |||
459 | /* device driver */ | ||
460 | 411 | ||
461 | static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) | 412 | static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) |
462 | { | 413 | { |
@@ -533,4 +484,39 @@ static struct platform_driver ohci_hcd_s3c2410_driver = { | |||
533 | }, | 484 | }, |
534 | }; | 485 | }; |
535 | 486 | ||
487 | static int __init ohci_s3c2410_init(void) | ||
488 | { | ||
489 | if (usb_disabled()) | ||
490 | return -ENODEV; | ||
491 | |||
492 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
493 | ohci_init_driver(&ohci_s3c2410_hc_driver, NULL); | ||
494 | |||
495 | /* | ||
496 | * The Samsung HW has some unusual quirks, which require | ||
497 | * Sumsung-specific workarounds. We override certain hc_driver | ||
498 | * functions here to achieve that. We explicitly do not enhance | ||
499 | * ohci_driver_overrides to allow this more easily, since this | ||
500 | * is an unusual case, and we don't want to encourage others to | ||
501 | * override these functions by making it too easy. | ||
502 | */ | ||
503 | |||
504 | orig_ohci_hub_control = ohci_s3c2410_hc_driver.hub_control; | ||
505 | orig_ohci_hub_status_data = ohci_s3c2410_hc_driver.hub_status_data; | ||
506 | |||
507 | ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data; | ||
508 | ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control; | ||
509 | |||
510 | return platform_driver_register(&ohci_hcd_s3c2410_driver); | ||
511 | } | ||
512 | module_init(ohci_s3c2410_init); | ||
513 | |||
514 | static void __exit ohci_s3c2410_cleanup(void) | ||
515 | { | ||
516 | platform_driver_unregister(&ohci_hcd_s3c2410_driver); | ||
517 | } | ||
518 | module_exit(ohci_s3c2410_cleanup); | ||
519 | |||
520 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
521 | MODULE_LICENSE("GPL"); | ||
536 | MODULE_ALIAS("platform:s3c2410-ohci"); | 522 | MODULE_ALIAS("platform:s3c2410-ohci"); |
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c index d479d5ddab88..2a5de5fecd8f 100644 --- a/drivers/usb/host/ohci-sm501.c +++ b/drivers/usb/host/ohci-sm501.c | |||
@@ -216,14 +216,21 @@ static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev) | |||
216 | static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg) | 216 | static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg) |
217 | { | 217 | { |
218 | struct device *dev = &pdev->dev; | 218 | struct device *dev = &pdev->dev; |
219 | struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev)); | 219 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
220 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
221 | bool do_wakeup = device_may_wakeup(dev); | ||
222 | int ret; | ||
220 | 223 | ||
221 | if (time_before(jiffies, ohci->next_statechange)) | 224 | if (time_before(jiffies, ohci->next_statechange)) |
222 | msleep(5); | 225 | msleep(5); |
223 | ohci->next_statechange = jiffies; | 226 | ohci->next_statechange = jiffies; |
224 | 227 | ||
228 | ret = ohci_suspend(hcd, do_wakeup); | ||
229 | if (ret) | ||
230 | return ret; | ||
231 | |||
225 | sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); | 232 | sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); |
226 | return 0; | 233 | return ret; |
227 | } | 234 | } |
228 | 235 | ||
229 | static int ohci_sm501_resume(struct platform_device *pdev) | 236 | static int ohci_sm501_resume(struct platform_device *pdev) |
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c index cc9dd9e4f05e..31ff3fc4e26f 100644 --- a/drivers/usb/host/ohci-spear.c +++ b/drivers/usb/host/ohci-spear.c | |||
@@ -11,92 +11,37 @@ | |||
11 | * warranty of any kind, whether express or implied. | 11 | * warranty of any kind, whether express or implied. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/signal.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/clk.h> | 14 | #include <linux/clk.h> |
15 | #include <linux/dma-mapping.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
17 | #include <linux/of.h> | 19 | #include <linux/of.h> |
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/signal.h> | ||
22 | #include <linux/usb.h> | ||
23 | #include <linux/usb/hcd.h> | ||
24 | |||
25 | #include "ohci.h" | ||
18 | 26 | ||
27 | #define DRIVER_DESC "OHCI SPEAr driver" | ||
28 | |||
29 | static const char hcd_name[] = "SPEAr-ohci"; | ||
19 | struct spear_ohci { | 30 | struct spear_ohci { |
20 | struct ohci_hcd ohci; | ||
21 | struct clk *clk; | 31 | struct clk *clk; |
22 | }; | 32 | }; |
23 | 33 | ||
24 | #define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd) | 34 | #define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv) |
25 | |||
26 | static void spear_start_ohci(struct spear_ohci *ohci) | ||
27 | { | ||
28 | clk_prepare_enable(ohci->clk); | ||
29 | } | ||
30 | |||
31 | static void spear_stop_ohci(struct spear_ohci *ohci) | ||
32 | { | ||
33 | clk_disable_unprepare(ohci->clk); | ||
34 | } | ||
35 | |||
36 | static int ohci_spear_start(struct usb_hcd *hcd) | ||
37 | { | ||
38 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
39 | int ret; | ||
40 | |||
41 | ret = ohci_init(ohci); | ||
42 | if (ret < 0) | ||
43 | return ret; | ||
44 | ohci->regs = hcd->regs; | ||
45 | |||
46 | ret = ohci_run(ohci); | ||
47 | if (ret < 0) { | ||
48 | dev_err(hcd->self.controller, "can't start\n"); | ||
49 | ohci_stop(hcd); | ||
50 | return ret; | ||
51 | } | ||
52 | |||
53 | create_debug_files(ohci); | ||
54 | |||
55 | #ifdef DEBUG | ||
56 | ohci_dump(ohci, 1); | ||
57 | #endif | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static const struct hc_driver ohci_spear_hc_driver = { | ||
62 | .description = hcd_name, | ||
63 | .product_desc = "SPEAr OHCI", | ||
64 | .hcd_priv_size = sizeof(struct spear_ohci), | ||
65 | |||
66 | /* generic hardware linkage */ | ||
67 | .irq = ohci_irq, | ||
68 | .flags = HCD_USB11 | HCD_MEMORY, | ||
69 | |||
70 | /* basic lifecycle operations */ | ||
71 | .start = ohci_spear_start, | ||
72 | .stop = ohci_stop, | ||
73 | .shutdown = ohci_shutdown, | ||
74 | #ifdef CONFIG_PM | ||
75 | .bus_suspend = ohci_bus_suspend, | ||
76 | .bus_resume = ohci_bus_resume, | ||
77 | #endif | ||
78 | |||
79 | /* managing i/o requests and associated device resources */ | ||
80 | .urb_enqueue = ohci_urb_enqueue, | ||
81 | .urb_dequeue = ohci_urb_dequeue, | ||
82 | .endpoint_disable = ohci_endpoint_disable, | ||
83 | |||
84 | /* scheduling support */ | ||
85 | .get_frame_number = ohci_get_frame, | ||
86 | 35 | ||
87 | /* root hub support */ | 36 | static struct hc_driver __read_mostly ohci_spear_hc_driver; |
88 | .hub_status_data = ohci_hub_status_data, | ||
89 | .hub_control = ohci_hub_control, | ||
90 | |||
91 | .start_port_reset = ohci_start_port_reset, | ||
92 | }; | ||
93 | 37 | ||
94 | static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) | 38 | static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) |
95 | { | 39 | { |
96 | const struct hc_driver *driver = &ohci_spear_hc_driver; | 40 | const struct hc_driver *driver = &ohci_spear_hc_driver; |
41 | struct ohci_hcd *ohci; | ||
97 | struct usb_hcd *hcd = NULL; | 42 | struct usb_hcd *hcd = NULL; |
98 | struct clk *usbh_clk; | 43 | struct clk *usbh_clk; |
99 | struct spear_ohci *ohci_p; | 44 | struct spear_ohci *sohci_p; |
100 | struct resource *res; | 45 | struct resource *res; |
101 | int retval, irq; | 46 | int retval, irq; |
102 | 47 | ||
@@ -151,16 +96,18 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) | |||
151 | goto err_put_hcd; | 96 | goto err_put_hcd; |
152 | } | 97 | } |
153 | 98 | ||
154 | ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd); | 99 | sohci_p = to_spear_ohci(hcd); |
155 | ohci_p->clk = usbh_clk; | 100 | sohci_p->clk = usbh_clk; |
156 | spear_start_ohci(ohci_p); | 101 | |
157 | ohci_hcd_init(hcd_to_ohci(hcd)); | 102 | clk_prepare_enable(sohci_p->clk); |
103 | |||
104 | ohci = hcd_to_ohci(hcd); | ||
158 | 105 | ||
159 | retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); | 106 | retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); |
160 | if (retval == 0) | 107 | if (retval == 0) |
161 | return retval; | 108 | return retval; |
162 | 109 | ||
163 | spear_stop_ohci(ohci_p); | 110 | clk_disable_unprepare(sohci_p->clk); |
164 | err_put_hcd: | 111 | err_put_hcd: |
165 | usb_put_hcd(hcd); | 112 | usb_put_hcd(hcd); |
166 | fail: | 113 | fail: |
@@ -172,11 +119,11 @@ fail: | |||
172 | static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) | 119 | static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) |
173 | { | 120 | { |
174 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 121 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
175 | struct spear_ohci *ohci_p = to_spear_ohci(hcd); | 122 | struct spear_ohci *sohci_p = to_spear_ohci(hcd); |
176 | 123 | ||
177 | usb_remove_hcd(hcd); | 124 | usb_remove_hcd(hcd); |
178 | if (ohci_p->clk) | 125 | if (sohci_p->clk) |
179 | spear_stop_ohci(ohci_p); | 126 | clk_disable_unprepare(sohci_p->clk); |
180 | 127 | ||
181 | usb_put_hcd(hcd); | 128 | usb_put_hcd(hcd); |
182 | return 0; | 129 | return 0; |
@@ -188,13 +135,14 @@ static int spear_ohci_hcd_drv_suspend(struct platform_device *dev, | |||
188 | { | 135 | { |
189 | struct usb_hcd *hcd = platform_get_drvdata(dev); | 136 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
190 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 137 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
191 | struct spear_ohci *ohci_p = to_spear_ohci(hcd); | 138 | struct spear_ohci *sohci_p = to_spear_ohci(hcd); |
192 | 139 | ||
193 | if (time_before(jiffies, ohci->next_statechange)) | 140 | if (time_before(jiffies, ohci->next_statechange)) |
194 | msleep(5); | 141 | msleep(5); |
195 | ohci->next_statechange = jiffies; | 142 | ohci->next_statechange = jiffies; |
196 | 143 | ||
197 | spear_stop_ohci(ohci_p); | 144 | clk_disable_unprepare(sohci_p->clk); |
145 | |||
198 | return 0; | 146 | return 0; |
199 | } | 147 | } |
200 | 148 | ||
@@ -202,13 +150,13 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev) | |||
202 | { | 150 | { |
203 | struct usb_hcd *hcd = platform_get_drvdata(dev); | 151 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
204 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 152 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
205 | struct spear_ohci *ohci_p = to_spear_ohci(hcd); | 153 | struct spear_ohci *sohci_p = to_spear_ohci(hcd); |
206 | 154 | ||
207 | if (time_before(jiffies, ohci->next_statechange)) | 155 | if (time_before(jiffies, ohci->next_statechange)) |
208 | msleep(5); | 156 | msleep(5); |
209 | ohci->next_statechange = jiffies; | 157 | ohci->next_statechange = jiffies; |
210 | 158 | ||
211 | spear_start_ohci(ohci_p); | 159 | clk_prepare_enable(sohci_p->clk); |
212 | ohci_resume(hcd, false); | 160 | ohci_resume(hcd, false); |
213 | return 0; | 161 | return 0; |
214 | } | 162 | } |
@@ -234,4 +182,28 @@ static struct platform_driver spear_ohci_hcd_driver = { | |||
234 | }, | 182 | }, |
235 | }; | 183 | }; |
236 | 184 | ||
185 | static const struct ohci_driver_overrides spear_overrides __initconst = { | ||
186 | .extra_priv_size = sizeof(struct spear_ohci), | ||
187 | }; | ||
188 | static int __init ohci_spear_init(void) | ||
189 | { | ||
190 | if (usb_disabled()) | ||
191 | return -ENODEV; | ||
192 | |||
193 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
194 | |||
195 | ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides); | ||
196 | return platform_driver_register(&spear_ohci_hcd_driver); | ||
197 | } | ||
198 | module_init(ohci_spear_init); | ||
199 | |||
200 | static void __exit ohci_spear_cleanup(void) | ||
201 | { | ||
202 | platform_driver_unregister(&spear_ohci_hcd_driver); | ||
203 | } | ||
204 | module_exit(ohci_spear_cleanup); | ||
205 | |||
206 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
207 | MODULE_AUTHOR("Deepak Sikri"); | ||
208 | MODULE_LICENSE("GPL v2"); | ||
237 | MODULE_ALIAS("platform:spear-ohci"); | 209 | MODULE_ALIAS("platform:spear-ohci"); |
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index 08ef2829a7e2..dfbdd3aefe98 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c | |||
@@ -79,11 +79,30 @@ | |||
79 | #define USB_INTEL_USB3_PSSEN 0xD8 | 79 | #define USB_INTEL_USB3_PSSEN 0xD8 |
80 | #define USB_INTEL_USB3PRM 0xDC | 80 | #define USB_INTEL_USB3PRM 0xDC |
81 | 81 | ||
82 | /* | ||
83 | * amd_chipset_gen values represent AMD different chipset generations | ||
84 | */ | ||
85 | enum amd_chipset_gen { | ||
86 | NOT_AMD_CHIPSET = 0, | ||
87 | AMD_CHIPSET_SB600, | ||
88 | AMD_CHIPSET_SB700, | ||
89 | AMD_CHIPSET_SB800, | ||
90 | AMD_CHIPSET_HUDSON2, | ||
91 | AMD_CHIPSET_BOLTON, | ||
92 | AMD_CHIPSET_YANGTZE, | ||
93 | AMD_CHIPSET_UNKNOWN, | ||
94 | }; | ||
95 | |||
96 | struct amd_chipset_type { | ||
97 | enum amd_chipset_gen gen; | ||
98 | u8 rev; | ||
99 | }; | ||
100 | |||
82 | static struct amd_chipset_info { | 101 | static struct amd_chipset_info { |
83 | struct pci_dev *nb_dev; | 102 | struct pci_dev *nb_dev; |
84 | struct pci_dev *smbus_dev; | 103 | struct pci_dev *smbus_dev; |
85 | int nb_type; | 104 | int nb_type; |
86 | int sb_type; | 105 | struct amd_chipset_type sb_type; |
87 | int isoc_reqs; | 106 | int isoc_reqs; |
88 | int probe_count; | 107 | int probe_count; |
89 | int probe_result; | 108 | int probe_result; |
@@ -91,6 +110,51 @@ static struct amd_chipset_info { | |||
91 | 110 | ||
92 | static DEFINE_SPINLOCK(amd_lock); | 111 | static DEFINE_SPINLOCK(amd_lock); |
93 | 112 | ||
113 | /* | ||
114 | * amd_chipset_sb_type_init - initialize amd chipset southbridge type | ||
115 | * | ||
116 | * AMD FCH/SB generation and revision is identified by SMBus controller | ||
117 | * vendor, device and revision IDs. | ||
118 | * | ||
119 | * Returns: 1 if it is an AMD chipset, 0 otherwise. | ||
120 | */ | ||
121 | static int amd_chipset_sb_type_init(struct amd_chipset_info *pinfo) | ||
122 | { | ||
123 | u8 rev = 0; | ||
124 | pinfo->sb_type.gen = AMD_CHIPSET_UNKNOWN; | ||
125 | |||
126 | pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, | ||
127 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); | ||
128 | if (pinfo->smbus_dev) { | ||
129 | rev = pinfo->smbus_dev->revision; | ||
130 | if (rev >= 0x10 && rev <= 0x1f) | ||
131 | pinfo->sb_type.gen = AMD_CHIPSET_SB600; | ||
132 | else if (rev >= 0x30 && rev <= 0x3f) | ||
133 | pinfo->sb_type.gen = AMD_CHIPSET_SB700; | ||
134 | else if (rev >= 0x40 && rev <= 0x4f) | ||
135 | pinfo->sb_type.gen = AMD_CHIPSET_SB800; | ||
136 | } else { | ||
137 | pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
138 | PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL); | ||
139 | |||
140 | if (!pinfo->smbus_dev) { | ||
141 | pinfo->sb_type.gen = NOT_AMD_CHIPSET; | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | rev = pinfo->smbus_dev->revision; | ||
146 | if (rev >= 0x11 && rev <= 0x14) | ||
147 | pinfo->sb_type.gen = AMD_CHIPSET_HUDSON2; | ||
148 | else if (rev >= 0x15 && rev <= 0x18) | ||
149 | pinfo->sb_type.gen = AMD_CHIPSET_BOLTON; | ||
150 | else if (rev >= 0x39 && rev <= 0x3a) | ||
151 | pinfo->sb_type.gen = AMD_CHIPSET_YANGTZE; | ||
152 | } | ||
153 | |||
154 | pinfo->sb_type.rev = rev; | ||
155 | return 1; | ||
156 | } | ||
157 | |||
94 | void sb800_prefetch(struct device *dev, int on) | 158 | void sb800_prefetch(struct device *dev, int on) |
95 | { | 159 | { |
96 | u16 misc; | 160 | u16 misc; |
@@ -106,7 +170,6 @@ EXPORT_SYMBOL_GPL(sb800_prefetch); | |||
106 | 170 | ||
107 | int usb_amd_find_chipset_info(void) | 171 | int usb_amd_find_chipset_info(void) |
108 | { | 172 | { |
109 | u8 rev = 0; | ||
110 | unsigned long flags; | 173 | unsigned long flags; |
111 | struct amd_chipset_info info; | 174 | struct amd_chipset_info info; |
112 | int ret; | 175 | int ret; |
@@ -122,27 +185,17 @@ int usb_amd_find_chipset_info(void) | |||
122 | memset(&info, 0, sizeof(info)); | 185 | memset(&info, 0, sizeof(info)); |
123 | spin_unlock_irqrestore(&amd_lock, flags); | 186 | spin_unlock_irqrestore(&amd_lock, flags); |
124 | 187 | ||
125 | info.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); | 188 | if (!amd_chipset_sb_type_init(&info)) { |
126 | if (info.smbus_dev) { | 189 | ret = 0; |
127 | rev = info.smbus_dev->revision; | 190 | goto commit; |
128 | if (rev >= 0x40) | ||
129 | info.sb_type = 1; | ||
130 | else if (rev >= 0x30 && rev <= 0x3b) | ||
131 | info.sb_type = 3; | ||
132 | } else { | ||
133 | info.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
134 | 0x780b, NULL); | ||
135 | if (!info.smbus_dev) { | ||
136 | ret = 0; | ||
137 | goto commit; | ||
138 | } | ||
139 | |||
140 | rev = info.smbus_dev->revision; | ||
141 | if (rev >= 0x11 && rev <= 0x18) | ||
142 | info.sb_type = 2; | ||
143 | } | 191 | } |
144 | 192 | ||
145 | if (info.sb_type == 0) { | 193 | /* Below chipset generations needn't enable AMD PLL quirk */ |
194 | if (info.sb_type.gen == AMD_CHIPSET_UNKNOWN || | ||
195 | info.sb_type.gen == AMD_CHIPSET_SB600 || | ||
196 | info.sb_type.gen == AMD_CHIPSET_YANGTZE || | ||
197 | (info.sb_type.gen == AMD_CHIPSET_SB700 && | ||
198 | info.sb_type.rev > 0x3b)) { | ||
146 | if (info.smbus_dev) { | 199 | if (info.smbus_dev) { |
147 | pci_dev_put(info.smbus_dev); | 200 | pci_dev_put(info.smbus_dev); |
148 | info.smbus_dev = NULL; | 201 | info.smbus_dev = NULL; |
@@ -197,6 +250,39 @@ commit: | |||
197 | } | 250 | } |
198 | EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); | 251 | EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); |
199 | 252 | ||
253 | int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *pdev) | ||
254 | { | ||
255 | /* Make sure amd chipset type has already been initialized */ | ||
256 | usb_amd_find_chipset_info(); | ||
257 | if (amd_chipset.sb_type.gen != AMD_CHIPSET_YANGTZE) | ||
258 | return 0; | ||
259 | |||
260 | dev_dbg(&pdev->dev, "QUIRK: Enable AMD remote wakeup fix\n"); | ||
261 | return 1; | ||
262 | } | ||
263 | EXPORT_SYMBOL_GPL(usb_hcd_amd_remote_wakeup_quirk); | ||
264 | |||
265 | bool usb_amd_hang_symptom_quirk(void) | ||
266 | { | ||
267 | u8 rev; | ||
268 | |||
269 | usb_amd_find_chipset_info(); | ||
270 | rev = amd_chipset.sb_type.rev; | ||
271 | /* SB600 and old version of SB700 have hang symptom bug */ | ||
272 | return amd_chipset.sb_type.gen == AMD_CHIPSET_SB600 || | ||
273 | (amd_chipset.sb_type.gen == AMD_CHIPSET_SB700 && | ||
274 | rev >= 0x3a && rev <= 0x3b); | ||
275 | } | ||
276 | EXPORT_SYMBOL_GPL(usb_amd_hang_symptom_quirk); | ||
277 | |||
278 | bool usb_amd_prefetch_quirk(void) | ||
279 | { | ||
280 | usb_amd_find_chipset_info(); | ||
281 | /* SB800 needs pre-fetch fix */ | ||
282 | return amd_chipset.sb_type.gen == AMD_CHIPSET_SB800; | ||
283 | } | ||
284 | EXPORT_SYMBOL_GPL(usb_amd_prefetch_quirk); | ||
285 | |||
200 | /* | 286 | /* |
201 | * The hardware normally enables the A-link power management feature, which | 287 | * The hardware normally enables the A-link power management feature, which |
202 | * lets the system lower the power consumption in idle states. | 288 | * lets the system lower the power consumption in idle states. |
@@ -229,7 +315,9 @@ static void usb_amd_quirk_pll(int disable) | |||
229 | } | 315 | } |
230 | } | 316 | } |
231 | 317 | ||
232 | if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) { | 318 | if (amd_chipset.sb_type.gen == AMD_CHIPSET_SB800 || |
319 | amd_chipset.sb_type.gen == AMD_CHIPSET_HUDSON2 || | ||
320 | amd_chipset.sb_type.gen == AMD_CHIPSET_BOLTON) { | ||
233 | outb_p(AB_REG_BAR_LOW, 0xcd6); | 321 | outb_p(AB_REG_BAR_LOW, 0xcd6); |
234 | addr_low = inb_p(0xcd7); | 322 | addr_low = inb_p(0xcd7); |
235 | outb_p(AB_REG_BAR_HIGH, 0xcd6); | 323 | outb_p(AB_REG_BAR_HIGH, 0xcd6); |
@@ -240,7 +328,8 @@ static void usb_amd_quirk_pll(int disable) | |||
240 | outl_p(0x40, AB_DATA(addr)); | 328 | outl_p(0x40, AB_DATA(addr)); |
241 | outl_p(0x34, AB_INDX(addr)); | 329 | outl_p(0x34, AB_INDX(addr)); |
242 | val = inl_p(AB_DATA(addr)); | 330 | val = inl_p(AB_DATA(addr)); |
243 | } else if (amd_chipset.sb_type == 3) { | 331 | } else if (amd_chipset.sb_type.gen == AMD_CHIPSET_SB700 && |
332 | amd_chipset.sb_type.rev <= 0x3b) { | ||
244 | pci_read_config_dword(amd_chipset.smbus_dev, | 333 | pci_read_config_dword(amd_chipset.smbus_dev, |
245 | AB_REG_BAR_SB700, &addr); | 334 | AB_REG_BAR_SB700, &addr); |
246 | outl(AX_INDXC, AB_INDX(addr)); | 335 | outl(AX_INDXC, AB_INDX(addr)); |
@@ -353,7 +442,7 @@ void usb_amd_dev_put(void) | |||
353 | amd_chipset.nb_dev = NULL; | 442 | amd_chipset.nb_dev = NULL; |
354 | amd_chipset.smbus_dev = NULL; | 443 | amd_chipset.smbus_dev = NULL; |
355 | amd_chipset.nb_type = 0; | 444 | amd_chipset.nb_type = 0; |
356 | amd_chipset.sb_type = 0; | 445 | memset(&amd_chipset.sb_type, 0, sizeof(amd_chipset.sb_type)); |
357 | amd_chipset.isoc_reqs = 0; | 446 | amd_chipset.isoc_reqs = 0; |
358 | amd_chipset.probe_result = 0; | 447 | amd_chipset.probe_result = 0; |
359 | 448 | ||
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h index ed6700d00fe6..638e88f7a28b 100644 --- a/drivers/usb/host/pci-quirks.h +++ b/drivers/usb/host/pci-quirks.h | |||
@@ -5,6 +5,8 @@ | |||
5 | void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); | 5 | void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); |
6 | int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); | 6 | int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); |
7 | int usb_amd_find_chipset_info(void); | 7 | int usb_amd_find_chipset_info(void); |
8 | bool usb_amd_hang_symptom_quirk(void); | ||
9 | bool usb_amd_prefetch_quirk(void); | ||
8 | void usb_amd_dev_put(void); | 10 | void usb_amd_dev_put(void); |
9 | void usb_amd_quirk_pll_disable(void); | 11 | void usb_amd_quirk_pll_disable(void); |
10 | void usb_amd_quirk_pll_enable(void); | 12 | void usb_amd_quirk_pll_enable(void); |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 5477bf5df218..79620c39217e 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -1413,7 +1413,7 @@ static int sl811h_show(struct seq_file *s, void *unused) | |||
1413 | case SL11H_CTL1MASK_SE0: s = " se0/reset"; break; | 1413 | case SL11H_CTL1MASK_SE0: s = " se0/reset"; break; |
1414 | case SL11H_CTL1MASK_K: s = " k/resume"; break; | 1414 | case SL11H_CTL1MASK_K: s = " k/resume"; break; |
1415 | default: s = "j"; break; | 1415 | default: s = "j"; break; |
1416 | }; s; }), | 1416 | } s; }), |
1417 | (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "", | 1417 | (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "", |
1418 | (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : ""); | 1418 | (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : ""); |
1419 | 1419 | ||
@@ -1446,7 +1446,7 @@ static int sl811h_show(struct seq_file *s, void *unused) | |||
1446 | case USB_PID_SETUP: s = "setup"; break; | 1446 | case USB_PID_SETUP: s = "setup"; break; |
1447 | case USB_PID_ACK: s = "status"; break; | 1447 | case USB_PID_ACK: s = "status"; break; |
1448 | default: s = "?"; break; | 1448 | default: s = "?"; break; |
1449 | }; s;}), | 1449 | } s;}), |
1450 | ep->maxpacket, | 1450 | ep->maxpacket, |
1451 | ep->nak_count, ep->error_count); | 1451 | ep->nak_count, ep->error_count); |
1452 | list_for_each_entry (urb, &ep->hep->urb_list, urb_list) { | 1452 | list_for_each_entry (urb, &ep->hep->urb_list, urb_list) { |
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c index 455737546525..8e239cdd95d5 100644 --- a/drivers/usb/host/uhci-debug.c +++ b/drivers/usb/host/uhci-debug.c | |||
@@ -310,14 +310,14 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) | |||
310 | unsigned short portsc1, portsc2; | 310 | unsigned short portsc1, portsc2; |
311 | 311 | ||
312 | 312 | ||
313 | usbcmd = uhci_readw(uhci, 0); | 313 | usbcmd = uhci_readw(uhci, USBCMD); |
314 | usbstat = uhci_readw(uhci, 2); | 314 | usbstat = uhci_readw(uhci, USBSTS); |
315 | usbint = uhci_readw(uhci, 4); | 315 | usbint = uhci_readw(uhci, USBINTR); |
316 | usbfrnum = uhci_readw(uhci, 6); | 316 | usbfrnum = uhci_readw(uhci, USBFRNUM); |
317 | flbaseadd = uhci_readl(uhci, 8); | 317 | flbaseadd = uhci_readl(uhci, USBFLBASEADD); |
318 | sof = uhci_readb(uhci, 12); | 318 | sof = uhci_readb(uhci, USBSOF); |
319 | portsc1 = uhci_readw(uhci, 16); | 319 | portsc1 = uhci_readw(uhci, USBPORTSC1); |
320 | portsc2 = uhci_readw(uhci, 18); | 320 | portsc2 = uhci_readw(uhci, USBPORTSC2); |
321 | 321 | ||
322 | out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", | 322 | out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", |
323 | usbcmd, | 323 | usbcmd, |
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c index 9189bc984c98..93e17b12fb33 100644 --- a/drivers/usb/host/uhci-hub.c +++ b/drivers/usb/host/uhci-hub.c | |||
@@ -75,8 +75,6 @@ static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf) | |||
75 | return !!*buf; | 75 | return !!*buf; |
76 | } | 76 | } |
77 | 77 | ||
78 | #define OK(x) len = (x); break | ||
79 | |||
80 | #define CLR_RH_PORTSTAT(x) \ | 78 | #define CLR_RH_PORTSTAT(x) \ |
81 | status = uhci_readw(uhci, port_addr); \ | 79 | status = uhci_readw(uhci, port_addr); \ |
82 | status &= ~(RWC_BITS|WZ_BITS); \ | 80 | status &= ~(RWC_BITS|WZ_BITS); \ |
@@ -244,7 +242,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
244 | u16 wIndex, char *buf, u16 wLength) | 242 | u16 wIndex, char *buf, u16 wLength) |
245 | { | 243 | { |
246 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 244 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
247 | int status, lstatus, retval = 0, len = 0; | 245 | int status, lstatus, retval = 0; |
248 | unsigned int port = wIndex - 1; | 246 | unsigned int port = wIndex - 1; |
249 | unsigned long port_addr = USBPORTSC1 + 2 * port; | 247 | unsigned long port_addr = USBPORTSC1 + 2 * port; |
250 | u16 wPortChange, wPortStatus; | 248 | u16 wPortChange, wPortStatus; |
@@ -258,7 +256,8 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
258 | 256 | ||
259 | case GetHubStatus: | 257 | case GetHubStatus: |
260 | *(__le32 *)buf = cpu_to_le32(0); | 258 | *(__le32 *)buf = cpu_to_le32(0); |
261 | OK(4); /* hub power */ | 259 | retval = 4; /* hub power */ |
260 | break; | ||
262 | case GetPortStatus: | 261 | case GetPortStatus: |
263 | if (port >= uhci->rh_numports) | 262 | if (port >= uhci->rh_numports) |
264 | goto err; | 263 | goto err; |
@@ -311,13 +310,14 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
311 | 310 | ||
312 | *(__le16 *)buf = cpu_to_le16(wPortStatus); | 311 | *(__le16 *)buf = cpu_to_le16(wPortStatus); |
313 | *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange); | 312 | *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange); |
314 | OK(4); | 313 | retval = 4; |
314 | break; | ||
315 | case SetHubFeature: /* We don't implement these */ | 315 | case SetHubFeature: /* We don't implement these */ |
316 | case ClearHubFeature: | 316 | case ClearHubFeature: |
317 | switch (wValue) { | 317 | switch (wValue) { |
318 | case C_HUB_OVER_CURRENT: | 318 | case C_HUB_OVER_CURRENT: |
319 | case C_HUB_LOCAL_POWER: | 319 | case C_HUB_LOCAL_POWER: |
320 | OK(0); | 320 | break; |
321 | default: | 321 | default: |
322 | goto err; | 322 | goto err; |
323 | } | 323 | } |
@@ -329,7 +329,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
329 | switch (wValue) { | 329 | switch (wValue) { |
330 | case USB_PORT_FEAT_SUSPEND: | 330 | case USB_PORT_FEAT_SUSPEND: |
331 | SET_RH_PORTSTAT(USBPORTSC_SUSP); | 331 | SET_RH_PORTSTAT(USBPORTSC_SUSP); |
332 | OK(0); | 332 | break; |
333 | case USB_PORT_FEAT_RESET: | 333 | case USB_PORT_FEAT_RESET: |
334 | SET_RH_PORTSTAT(USBPORTSC_PR); | 334 | SET_RH_PORTSTAT(USBPORTSC_PR); |
335 | 335 | ||
@@ -338,10 +338,10 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
338 | 338 | ||
339 | /* USB v2.0 7.1.7.5 */ | 339 | /* USB v2.0 7.1.7.5 */ |
340 | uhci->ports_timeout = jiffies + msecs_to_jiffies(50); | 340 | uhci->ports_timeout = jiffies + msecs_to_jiffies(50); |
341 | OK(0); | 341 | break; |
342 | case USB_PORT_FEAT_POWER: | 342 | case USB_PORT_FEAT_POWER: |
343 | /* UHCI has no power switching */ | 343 | /* UHCI has no power switching */ |
344 | OK(0); | 344 | break; |
345 | default: | 345 | default: |
346 | goto err; | 346 | goto err; |
347 | } | 347 | } |
@@ -356,10 +356,10 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
356 | 356 | ||
357 | /* Disable terminates Resume signalling */ | 357 | /* Disable terminates Resume signalling */ |
358 | uhci_finish_suspend(uhci, port, port_addr); | 358 | uhci_finish_suspend(uhci, port, port_addr); |
359 | OK(0); | 359 | break; |
360 | case USB_PORT_FEAT_C_ENABLE: | 360 | case USB_PORT_FEAT_C_ENABLE: |
361 | CLR_RH_PORTSTAT(USBPORTSC_PEC); | 361 | CLR_RH_PORTSTAT(USBPORTSC_PEC); |
362 | OK(0); | 362 | break; |
363 | case USB_PORT_FEAT_SUSPEND: | 363 | case USB_PORT_FEAT_SUSPEND: |
364 | if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) { | 364 | if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) { |
365 | 365 | ||
@@ -382,32 +382,32 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
382 | uhci->ports_timeout = jiffies + | 382 | uhci->ports_timeout = jiffies + |
383 | msecs_to_jiffies(20); | 383 | msecs_to_jiffies(20); |
384 | } | 384 | } |
385 | OK(0); | 385 | break; |
386 | case USB_PORT_FEAT_C_SUSPEND: | 386 | case USB_PORT_FEAT_C_SUSPEND: |
387 | clear_bit(port, &uhci->port_c_suspend); | 387 | clear_bit(port, &uhci->port_c_suspend); |
388 | OK(0); | 388 | break; |
389 | case USB_PORT_FEAT_POWER: | 389 | case USB_PORT_FEAT_POWER: |
390 | /* UHCI has no power switching */ | 390 | /* UHCI has no power switching */ |
391 | goto err; | 391 | goto err; |
392 | case USB_PORT_FEAT_C_CONNECTION: | 392 | case USB_PORT_FEAT_C_CONNECTION: |
393 | CLR_RH_PORTSTAT(USBPORTSC_CSC); | 393 | CLR_RH_PORTSTAT(USBPORTSC_CSC); |
394 | OK(0); | 394 | break; |
395 | case USB_PORT_FEAT_C_OVER_CURRENT: | 395 | case USB_PORT_FEAT_C_OVER_CURRENT: |
396 | CLR_RH_PORTSTAT(USBPORTSC_OCC); | 396 | CLR_RH_PORTSTAT(USBPORTSC_OCC); |
397 | OK(0); | 397 | break; |
398 | case USB_PORT_FEAT_C_RESET: | 398 | case USB_PORT_FEAT_C_RESET: |
399 | /* this driver won't report these */ | 399 | /* this driver won't report these */ |
400 | OK(0); | 400 | break; |
401 | default: | 401 | default: |
402 | goto err; | 402 | goto err; |
403 | } | 403 | } |
404 | break; | 404 | break; |
405 | case GetHubDescriptor: | 405 | case GetHubDescriptor: |
406 | len = min_t(unsigned int, sizeof(root_hub_hub_des), wLength); | 406 | retval = min_t(unsigned int, sizeof(root_hub_hub_des), wLength); |
407 | memcpy(buf, root_hub_hub_des, len); | 407 | memcpy(buf, root_hub_hub_des, retval); |
408 | if (len > 2) | 408 | if (retval > 2) |
409 | buf[2] = uhci->rh_numports; | 409 | buf[2] = uhci->rh_numports; |
410 | OK(len); | 410 | break; |
411 | default: | 411 | default: |
412 | err: | 412 | err: |
413 | retval = -EPIPE; | 413 | retval = -EPIPE; |
diff --git a/drivers/usb/host/uhci-pci.c b/drivers/usb/host/uhci-pci.c index 0f228c46eeda..4cd79888804b 100644 --- a/drivers/usb/host/uhci-pci.c +++ b/drivers/usb/host/uhci-pci.c | |||
@@ -162,6 +162,8 @@ static void uhci_shutdown(struct pci_dev *pdev) | |||
162 | 162 | ||
163 | #ifdef CONFIG_PM | 163 | #ifdef CONFIG_PM |
164 | 164 | ||
165 | static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated); | ||
166 | |||
165 | static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | 167 | static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) |
166 | { | 168 | { |
167 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 169 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
@@ -174,12 +176,6 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
174 | if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) | 176 | if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) |
175 | goto done_okay; /* Already suspended or dead */ | 177 | goto done_okay; /* Already suspended or dead */ |
176 | 178 | ||
177 | if (uhci->rh_state > UHCI_RH_SUSPENDED) { | ||
178 | dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); | ||
179 | rc = -EBUSY; | ||
180 | goto done; | ||
181 | }; | ||
182 | |||
183 | /* All PCI host controllers are required to disable IRQ generation | 179 | /* All PCI host controllers are required to disable IRQ generation |
184 | * at the source, so we must turn off PIRQ. | 180 | * at the source, so we must turn off PIRQ. |
185 | */ | 181 | */ |
@@ -195,8 +191,15 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
195 | 191 | ||
196 | done_okay: | 192 | done_okay: |
197 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 193 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
198 | done: | ||
199 | spin_unlock_irq(&uhci->lock); | 194 | spin_unlock_irq(&uhci->lock); |
195 | |||
196 | synchronize_irq(hcd->irq); | ||
197 | |||
198 | /* Check for race with a wakeup request */ | ||
199 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) { | ||
200 | uhci_pci_resume(hcd, false); | ||
201 | rc = -EBUSY; | ||
202 | } | ||
200 | return rc; | 203 | return rc; |
201 | } | 204 | } |
202 | 205 | ||
@@ -299,3 +302,5 @@ static struct pci_driver uhci_pci_driver = { | |||
299 | }, | 302 | }, |
300 | #endif | 303 | #endif |
301 | }; | 304 | }; |
305 | |||
306 | MODULE_SOFTDEP("pre: ehci_pci"); | ||
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c index d033a0ec7f0d..ded842bc6578 100644 --- a/drivers/usb/host/uhci-platform.c +++ b/drivers/usb/host/uhci-platform.c | |||
@@ -105,8 +105,7 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev) | |||
105 | 105 | ||
106 | uhci->regs = hcd->regs; | 106 | uhci->regs = hcd->regs; |
107 | 107 | ||
108 | ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED | | 108 | ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); |
109 | IRQF_SHARED); | ||
110 | if (ret) | 109 | if (ret) |
111 | goto err_uhci; | 110 | goto err_uhci; |
112 | 111 | ||
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index ecc88db804e0..1b0888f8da9a 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c | |||
@@ -134,7 +134,7 @@ static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, | |||
134 | default: | 134 | default: |
135 | ret = asl_urb_enqueue(whc, urb, mem_flags); | 135 | ret = asl_urb_enqueue(whc, urb, mem_flags); |
136 | break; | 136 | break; |
137 | }; | 137 | } |
138 | 138 | ||
139 | return ret; | 139 | return ret; |
140 | } | 140 | } |
@@ -160,7 +160,7 @@ static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status) | |||
160 | default: | 160 | default: |
161 | ret = asl_urb_dequeue(whc, urb, status); | 161 | ret = asl_urb_dequeue(whc, urb, status); |
162 | break; | 162 | break; |
163 | }; | 163 | } |
164 | 164 | ||
165 | return ret; | 165 | return ret; |
166 | } | 166 | } |
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index e8b4c56dcf62..805f2348eeba 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
@@ -296,7 +296,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) | |||
296 | /* Wait for last stop endpoint command to finish */ | 296 | /* Wait for last stop endpoint command to finish */ |
297 | timeleft = wait_for_completion_interruptible_timeout( | 297 | timeleft = wait_for_completion_interruptible_timeout( |
298 | cmd->completion, | 298 | cmd->completion, |
299 | USB_CTRL_SET_TIMEOUT); | 299 | XHCI_CMD_DEFAULT_TIMEOUT); |
300 | if (timeleft <= 0) { | 300 | if (timeleft <= 0) { |
301 | xhci_warn(xhci, "%s while waiting for stop endpoint command\n", | 301 | xhci_warn(xhci, "%s while waiting for stop endpoint command\n", |
302 | timeleft == 0 ? "Timeout" : "Signal"); | 302 | timeleft == 0 ? "Timeout" : "Signal"); |
@@ -524,7 +524,8 @@ static void xhci_hub_report_usb3_link_state(u32 *status, u32 status_reg) | |||
524 | * the compliance mode timer is deleted. A port won't enter | 524 | * the compliance mode timer is deleted. A port won't enter |
525 | * compliance mode if it has previously entered U0. | 525 | * compliance mode if it has previously entered U0. |
526 | */ | 526 | */ |
527 | void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex) | 527 | static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, |
528 | u16 wIndex) | ||
528 | { | 529 | { |
529 | u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1); | 530 | u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1); |
530 | bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0); | 531 | bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0); |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 83bcd13622c3..49b8bd063fab 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -1693,9 +1693,7 @@ void xhci_free_command(struct xhci_hcd *xhci, | |||
1693 | void xhci_mem_cleanup(struct xhci_hcd *xhci) | 1693 | void xhci_mem_cleanup(struct xhci_hcd *xhci) |
1694 | { | 1694 | { |
1695 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 1695 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
1696 | struct dev_info *dev_info, *next; | ||
1697 | struct xhci_cd *cur_cd, *next_cd; | 1696 | struct xhci_cd *cur_cd, *next_cd; |
1698 | unsigned long flags; | ||
1699 | int size; | 1697 | int size; |
1700 | int i, j, num_ports; | 1698 | int i, j, num_ports; |
1701 | 1699 | ||
@@ -1756,13 +1754,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
1756 | 1754 | ||
1757 | scratchpad_free(xhci); | 1755 | scratchpad_free(xhci); |
1758 | 1756 | ||
1759 | spin_lock_irqsave(&xhci->lock, flags); | ||
1760 | list_for_each_entry_safe(dev_info, next, &xhci->lpm_failed_devs, list) { | ||
1761 | list_del(&dev_info->list); | ||
1762 | kfree(dev_info); | ||
1763 | } | ||
1764 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1765 | |||
1766 | if (!xhci->rh_bw) | 1757 | if (!xhci->rh_bw) |
1767 | goto no_bw; | 1758 | goto no_bw; |
1768 | 1759 | ||
@@ -2231,7 +2222,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2231 | u32 page_size, temp; | 2222 | u32 page_size, temp; |
2232 | int i; | 2223 | int i; |
2233 | 2224 | ||
2234 | INIT_LIST_HEAD(&xhci->lpm_failed_devs); | ||
2235 | INIT_LIST_HEAD(&xhci->cancel_cmd_list); | 2225 | INIT_LIST_HEAD(&xhci->cancel_cmd_list); |
2236 | 2226 | ||
2237 | page_size = xhci_readl(xhci, &xhci->op_regs->page_size); | 2227 | page_size = xhci_readl(xhci, &xhci->op_regs->page_size); |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 6bfbd80ec2b9..1e2f3f495843 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -178,7 +178,7 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) | |||
178 | if (ring->type == TYPE_EVENT && | 178 | if (ring->type == TYPE_EVENT && |
179 | last_trb_on_last_seg(xhci, ring, | 179 | last_trb_on_last_seg(xhci, ring, |
180 | ring->deq_seg, ring->dequeue)) { | 180 | ring->deq_seg, ring->dequeue)) { |
181 | ring->cycle_state = (ring->cycle_state ? 0 : 1); | 181 | ring->cycle_state ^= 1; |
182 | } | 182 | } |
183 | ring->deq_seg = ring->deq_seg->next; | 183 | ring->deq_seg = ring->deq_seg->next; |
184 | ring->dequeue = ring->deq_seg->trbs; | 184 | ring->dequeue = ring->deq_seg->trbs; |
@@ -726,7 +726,7 @@ static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, | |||
726 | 726 | ||
727 | /* Must be called with xhci->lock held in interrupt context */ | 727 | /* Must be called with xhci->lock held in interrupt context */ |
728 | static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, | 728 | static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, |
729 | struct xhci_td *cur_td, int status, char *adjective) | 729 | struct xhci_td *cur_td, int status) |
730 | { | 730 | { |
731 | struct usb_hcd *hcd; | 731 | struct usb_hcd *hcd; |
732 | struct urb *urb; | 732 | struct urb *urb; |
@@ -765,10 +765,9 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, | |||
765 | * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain | 765 | * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain |
766 | * bit cleared) so that the HW will skip over them. | 766 | * bit cleared) so that the HW will skip over them. |
767 | */ | 767 | */ |
768 | static void handle_stopped_endpoint(struct xhci_hcd *xhci, | 768 | static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, |
769 | union xhci_trb *trb, struct xhci_event_cmd *event) | 769 | union xhci_trb *trb, struct xhci_event_cmd *event) |
770 | { | 770 | { |
771 | unsigned int slot_id; | ||
772 | unsigned int ep_index; | 771 | unsigned int ep_index; |
773 | struct xhci_virt_device *virt_dev; | 772 | struct xhci_virt_device *virt_dev; |
774 | struct xhci_ring *ep_ring; | 773 | struct xhci_ring *ep_ring; |
@@ -779,10 +778,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
779 | 778 | ||
780 | struct xhci_dequeue_state deq_state; | 779 | struct xhci_dequeue_state deq_state; |
781 | 780 | ||
782 | if (unlikely(TRB_TO_SUSPEND_PORT( | 781 | if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { |
783 | le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])))) { | ||
784 | slot_id = TRB_TO_SLOT_ID( | ||
785 | le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])); | ||
786 | virt_dev = xhci->devs[slot_id]; | 782 | virt_dev = xhci->devs[slot_id]; |
787 | if (virt_dev) | 783 | if (virt_dev) |
788 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, | 784 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, |
@@ -795,7 +791,6 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
795 | } | 791 | } |
796 | 792 | ||
797 | memset(&deq_state, 0, sizeof(deq_state)); | 793 | memset(&deq_state, 0, sizeof(deq_state)); |
798 | slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3])); | ||
799 | ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); | 794 | ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); |
800 | ep = &xhci->devs[slot_id]->eps[ep_index]; | 795 | ep = &xhci->devs[slot_id]->eps[ep_index]; |
801 | 796 | ||
@@ -891,7 +886,7 @@ remove_finished_td: | |||
891 | /* Doesn't matter what we pass for status, since the core will | 886 | /* Doesn't matter what we pass for status, since the core will |
892 | * just overwrite it (because the URB has been unlinked). | 887 | * just overwrite it (because the URB has been unlinked). |
893 | */ | 888 | */ |
894 | xhci_giveback_urb_in_irq(xhci, cur_td, 0, "cancelled"); | 889 | xhci_giveback_urb_in_irq(xhci, cur_td, 0); |
895 | 890 | ||
896 | /* Stop processing the cancelled list if the watchdog timer is | 891 | /* Stop processing the cancelled list if the watchdog timer is |
897 | * running. | 892 | * running. |
@@ -1001,7 +996,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
1001 | if (!list_empty(&cur_td->cancelled_td_list)) | 996 | if (!list_empty(&cur_td->cancelled_td_list)) |
1002 | list_del_init(&cur_td->cancelled_td_list); | 997 | list_del_init(&cur_td->cancelled_td_list); |
1003 | xhci_giveback_urb_in_irq(xhci, cur_td, | 998 | xhci_giveback_urb_in_irq(xhci, cur_td, |
1004 | -ESHUTDOWN, "killed"); | 999 | -ESHUTDOWN); |
1005 | } | 1000 | } |
1006 | while (!list_empty(&temp_ep->cancelled_td_list)) { | 1001 | while (!list_empty(&temp_ep->cancelled_td_list)) { |
1007 | cur_td = list_first_entry( | 1002 | cur_td = list_first_entry( |
@@ -1010,7 +1005,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
1010 | cancelled_td_list); | 1005 | cancelled_td_list); |
1011 | list_del_init(&cur_td->cancelled_td_list); | 1006 | list_del_init(&cur_td->cancelled_td_list); |
1012 | xhci_giveback_urb_in_irq(xhci, cur_td, | 1007 | xhci_giveback_urb_in_irq(xhci, cur_td, |
1013 | -ESHUTDOWN, "killed"); | 1008 | -ESHUTDOWN); |
1014 | } | 1009 | } |
1015 | } | 1010 | } |
1016 | } | 1011 | } |
@@ -1077,11 +1072,9 @@ static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci, | |||
1077 | * endpoint doorbell to restart the ring, but only if there aren't more | 1072 | * endpoint doorbell to restart the ring, but only if there aren't more |
1078 | * cancellations pending. | 1073 | * cancellations pending. |
1079 | */ | 1074 | */ |
1080 | static void handle_set_deq_completion(struct xhci_hcd *xhci, | 1075 | static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, |
1081 | struct xhci_event_cmd *event, | 1076 | union xhci_trb *trb, u32 cmd_comp_code) |
1082 | union xhci_trb *trb) | ||
1083 | { | 1077 | { |
1084 | unsigned int slot_id; | ||
1085 | unsigned int ep_index; | 1078 | unsigned int ep_index; |
1086 | unsigned int stream_id; | 1079 | unsigned int stream_id; |
1087 | struct xhci_ring *ep_ring; | 1080 | struct xhci_ring *ep_ring; |
@@ -1089,7 +1082,6 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
1089 | struct xhci_ep_ctx *ep_ctx; | 1082 | struct xhci_ep_ctx *ep_ctx; |
1090 | struct xhci_slot_ctx *slot_ctx; | 1083 | struct xhci_slot_ctx *slot_ctx; |
1091 | 1084 | ||
1092 | slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3])); | ||
1093 | ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); | 1085 | ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); |
1094 | stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); | 1086 | stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); |
1095 | dev = xhci->devs[slot_id]; | 1087 | dev = xhci->devs[slot_id]; |
@@ -1107,11 +1099,11 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
1107 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); | 1099 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); |
1108 | slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); | 1100 | slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); |
1109 | 1101 | ||
1110 | if (GET_COMP_CODE(le32_to_cpu(event->status)) != COMP_SUCCESS) { | 1102 | if (cmd_comp_code != COMP_SUCCESS) { |
1111 | unsigned int ep_state; | 1103 | unsigned int ep_state; |
1112 | unsigned int slot_state; | 1104 | unsigned int slot_state; |
1113 | 1105 | ||
1114 | switch (GET_COMP_CODE(le32_to_cpu(event->status))) { | 1106 | switch (cmd_comp_code) { |
1115 | case COMP_TRB_ERR: | 1107 | case COMP_TRB_ERR: |
1116 | xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because " | 1108 | xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because " |
1117 | "of stream ID configuration\n"); | 1109 | "of stream ID configuration\n"); |
@@ -1134,7 +1126,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
1134 | default: | 1126 | default: |
1135 | xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown " | 1127 | xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown " |
1136 | "completion code of %u.\n", | 1128 | "completion code of %u.\n", |
1137 | GET_COMP_CODE(le32_to_cpu(event->status))); | 1129 | cmd_comp_code); |
1138 | break; | 1130 | break; |
1139 | } | 1131 | } |
1140 | /* OK what do we do now? The endpoint state is hosed, and we | 1132 | /* OK what do we do now? The endpoint state is hosed, and we |
@@ -1171,21 +1163,17 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
1171 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); | 1163 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); |
1172 | } | 1164 | } |
1173 | 1165 | ||
1174 | static void handle_reset_ep_completion(struct xhci_hcd *xhci, | 1166 | static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, |
1175 | struct xhci_event_cmd *event, | 1167 | union xhci_trb *trb, u32 cmd_comp_code) |
1176 | union xhci_trb *trb) | ||
1177 | { | 1168 | { |
1178 | int slot_id; | ||
1179 | unsigned int ep_index; | 1169 | unsigned int ep_index; |
1180 | 1170 | ||
1181 | slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3])); | ||
1182 | ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); | 1171 | ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); |
1183 | /* This command will only fail if the endpoint wasn't halted, | 1172 | /* This command will only fail if the endpoint wasn't halted, |
1184 | * but we don't care. | 1173 | * but we don't care. |
1185 | */ | 1174 | */ |
1186 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, | 1175 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, |
1187 | "Ignoring reset ep completion code of %u", | 1176 | "Ignoring reset ep completion code of %u", cmd_comp_code); |
1188 | GET_COMP_CODE(le32_to_cpu(event->status))); | ||
1189 | 1177 | ||
1190 | /* HW with the reset endpoint quirk needs to have a configure endpoint | 1178 | /* HW with the reset endpoint quirk needs to have a configure endpoint |
1191 | * command complete before the endpoint can be used. Queue that here | 1179 | * command complete before the endpoint can be used. Queue that here |
@@ -1386,21 +1374,149 @@ static int handle_stopped_cmd_ring(struct xhci_hcd *xhci, | |||
1386 | return cur_trb_is_good; | 1374 | return cur_trb_is_good; |
1387 | } | 1375 | } |
1388 | 1376 | ||
1377 | static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, | ||
1378 | u32 cmd_comp_code) | ||
1379 | { | ||
1380 | if (cmd_comp_code == COMP_SUCCESS) | ||
1381 | xhci->slot_id = slot_id; | ||
1382 | else | ||
1383 | xhci->slot_id = 0; | ||
1384 | complete(&xhci->addr_dev); | ||
1385 | } | ||
1386 | |||
1387 | static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) | ||
1388 | { | ||
1389 | struct xhci_virt_device *virt_dev; | ||
1390 | |||
1391 | virt_dev = xhci->devs[slot_id]; | ||
1392 | if (!virt_dev) | ||
1393 | return; | ||
1394 | if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) | ||
1395 | /* Delete default control endpoint resources */ | ||
1396 | xhci_free_device_endpoint_resources(xhci, virt_dev, true); | ||
1397 | xhci_free_virt_device(xhci, slot_id); | ||
1398 | } | ||
1399 | |||
1400 | static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, | ||
1401 | struct xhci_event_cmd *event, u32 cmd_comp_code) | ||
1402 | { | ||
1403 | struct xhci_virt_device *virt_dev; | ||
1404 | struct xhci_input_control_ctx *ctrl_ctx; | ||
1405 | unsigned int ep_index; | ||
1406 | unsigned int ep_state; | ||
1407 | u32 add_flags, drop_flags; | ||
1408 | |||
1409 | virt_dev = xhci->devs[slot_id]; | ||
1410 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
1411 | return; | ||
1412 | /* | ||
1413 | * Configure endpoint commands can come from the USB core | ||
1414 | * configuration or alt setting changes, or because the HW | ||
1415 | * needed an extra configure endpoint command after a reset | ||
1416 | * endpoint command or streams were being configured. | ||
1417 | * If the command was for a halted endpoint, the xHCI driver | ||
1418 | * is not waiting on the configure endpoint command. | ||
1419 | */ | ||
1420 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); | ||
1421 | if (!ctrl_ctx) { | ||
1422 | xhci_warn(xhci, "Could not get input context, bad type.\n"); | ||
1423 | return; | ||
1424 | } | ||
1425 | |||
1426 | add_flags = le32_to_cpu(ctrl_ctx->add_flags); | ||
1427 | drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); | ||
1428 | /* Input ctx add_flags are the endpoint index plus one */ | ||
1429 | ep_index = xhci_last_valid_endpoint(add_flags) - 1; | ||
1430 | |||
1431 | /* A usb_set_interface() call directly after clearing a halted | ||
1432 | * condition may race on this quirky hardware. Not worth | ||
1433 | * worrying about, since this is prototype hardware. Not sure | ||
1434 | * if this will work for streams, but streams support was | ||
1435 | * untested on this prototype. | ||
1436 | */ | ||
1437 | if (xhci->quirks & XHCI_RESET_EP_QUIRK && | ||
1438 | ep_index != (unsigned int) -1 && | ||
1439 | add_flags - SLOT_FLAG == drop_flags) { | ||
1440 | ep_state = virt_dev->eps[ep_index].ep_state; | ||
1441 | if (!(ep_state & EP_HALTED)) | ||
1442 | goto bandwidth_change; | ||
1443 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | ||
1444 | "Completed config ep cmd - " | ||
1445 | "last ep index = %d, state = %d", | ||
1446 | ep_index, ep_state); | ||
1447 | /* Clear internal halted state and restart ring(s) */ | ||
1448 | virt_dev->eps[ep_index].ep_state &= ~EP_HALTED; | ||
1449 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); | ||
1450 | return; | ||
1451 | } | ||
1452 | bandwidth_change: | ||
1453 | xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, | ||
1454 | "Completed config ep cmd"); | ||
1455 | virt_dev->cmd_status = cmd_comp_code; | ||
1456 | complete(&virt_dev->cmd_completion); | ||
1457 | return; | ||
1458 | } | ||
1459 | |||
1460 | static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id, | ||
1461 | struct xhci_event_cmd *event, u32 cmd_comp_code) | ||
1462 | { | ||
1463 | struct xhci_virt_device *virt_dev; | ||
1464 | |||
1465 | virt_dev = xhci->devs[slot_id]; | ||
1466 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
1467 | return; | ||
1468 | virt_dev->cmd_status = cmd_comp_code; | ||
1469 | complete(&virt_dev->cmd_completion); | ||
1470 | } | ||
1471 | |||
1472 | static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id, | ||
1473 | u32 cmd_comp_code) | ||
1474 | { | ||
1475 | xhci->devs[slot_id]->cmd_status = cmd_comp_code; | ||
1476 | complete(&xhci->addr_dev); | ||
1477 | } | ||
1478 | |||
1479 | static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, | ||
1480 | struct xhci_event_cmd *event) | ||
1481 | { | ||
1482 | struct xhci_virt_device *virt_dev; | ||
1483 | |||
1484 | xhci_dbg(xhci, "Completed reset device command.\n"); | ||
1485 | virt_dev = xhci->devs[slot_id]; | ||
1486 | if (virt_dev) | ||
1487 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, event); | ||
1488 | else | ||
1489 | xhci_warn(xhci, "Reset device command completion " | ||
1490 | "for disabled slot %u\n", slot_id); | ||
1491 | } | ||
1492 | |||
1493 | static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, | ||
1494 | struct xhci_event_cmd *event) | ||
1495 | { | ||
1496 | if (!(xhci->quirks & XHCI_NEC_HOST)) { | ||
1497 | xhci->error_bitmask |= 1 << 6; | ||
1498 | return; | ||
1499 | } | ||
1500 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | ||
1501 | "NEC firmware version %2x.%02x", | ||
1502 | NEC_FW_MAJOR(le32_to_cpu(event->status)), | ||
1503 | NEC_FW_MINOR(le32_to_cpu(event->status))); | ||
1504 | } | ||
1505 | |||
1389 | static void handle_cmd_completion(struct xhci_hcd *xhci, | 1506 | static void handle_cmd_completion(struct xhci_hcd *xhci, |
1390 | struct xhci_event_cmd *event) | 1507 | struct xhci_event_cmd *event) |
1391 | { | 1508 | { |
1392 | int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); | 1509 | int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); |
1393 | u64 cmd_dma; | 1510 | u64 cmd_dma; |
1394 | dma_addr_t cmd_dequeue_dma; | 1511 | dma_addr_t cmd_dequeue_dma; |
1395 | struct xhci_input_control_ctx *ctrl_ctx; | 1512 | u32 cmd_comp_code; |
1396 | struct xhci_virt_device *virt_dev; | 1513 | union xhci_trb *cmd_trb; |
1397 | unsigned int ep_index; | 1514 | u32 cmd_type; |
1398 | struct xhci_ring *ep_ring; | ||
1399 | unsigned int ep_state; | ||
1400 | 1515 | ||
1401 | cmd_dma = le64_to_cpu(event->cmd_trb); | 1516 | cmd_dma = le64_to_cpu(event->cmd_trb); |
1517 | cmd_trb = xhci->cmd_ring->dequeue; | ||
1402 | cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, | 1518 | cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, |
1403 | xhci->cmd_ring->dequeue); | 1519 | cmd_trb); |
1404 | /* Is the command ring deq ptr out of sync with the deq seg ptr? */ | 1520 | /* Is the command ring deq ptr out of sync with the deq seg ptr? */ |
1405 | if (cmd_dequeue_dma == 0) { | 1521 | if (cmd_dequeue_dma == 0) { |
1406 | xhci->error_bitmask |= 1 << 4; | 1522 | xhci->error_bitmask |= 1 << 4; |
@@ -1412,19 +1528,17 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1412 | return; | 1528 | return; |
1413 | } | 1529 | } |
1414 | 1530 | ||
1415 | trace_xhci_cmd_completion(&xhci->cmd_ring->dequeue->generic, | 1531 | trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event); |
1416 | (struct xhci_generic_trb *) event); | ||
1417 | 1532 | ||
1418 | if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) || | 1533 | cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); |
1419 | (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) { | 1534 | if (cmd_comp_code == COMP_CMD_ABORT || cmd_comp_code == COMP_CMD_STOP) { |
1420 | /* If the return value is 0, we think the trb pointed by | 1535 | /* If the return value is 0, we think the trb pointed by |
1421 | * command ring dequeue pointer is a good trb. The good | 1536 | * command ring dequeue pointer is a good trb. The good |
1422 | * trb means we don't want to cancel the trb, but it have | 1537 | * trb means we don't want to cancel the trb, but it have |
1423 | * been stopped by host. So we should handle it normally. | 1538 | * been stopped by host. So we should handle it normally. |
1424 | * Otherwise, driver should invoke inc_deq() and return. | 1539 | * Otherwise, driver should invoke inc_deq() and return. |
1425 | */ | 1540 | */ |
1426 | if (handle_stopped_cmd_ring(xhci, | 1541 | if (handle_stopped_cmd_ring(xhci, cmd_comp_code)) { |
1427 | GET_COMP_CODE(le32_to_cpu(event->status)))) { | ||
1428 | inc_deq(xhci, xhci->cmd_ring); | 1542 | inc_deq(xhci, xhci->cmd_ring); |
1429 | return; | 1543 | return; |
1430 | } | 1544 | } |
@@ -1436,117 +1550,47 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1436 | return; | 1550 | return; |
1437 | } | 1551 | } |
1438 | 1552 | ||
1439 | switch (le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]) | 1553 | cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); |
1440 | & TRB_TYPE_BITMASK) { | 1554 | switch (cmd_type) { |
1441 | case TRB_TYPE(TRB_ENABLE_SLOT): | 1555 | case TRB_ENABLE_SLOT: |
1442 | if (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_SUCCESS) | 1556 | xhci_handle_cmd_enable_slot(xhci, slot_id, cmd_comp_code); |
1443 | xhci->slot_id = slot_id; | ||
1444 | else | ||
1445 | xhci->slot_id = 0; | ||
1446 | complete(&xhci->addr_dev); | ||
1447 | break; | 1557 | break; |
1448 | case TRB_TYPE(TRB_DISABLE_SLOT): | 1558 | case TRB_DISABLE_SLOT: |
1449 | if (xhci->devs[slot_id]) { | 1559 | xhci_handle_cmd_disable_slot(xhci, slot_id); |
1450 | if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) | ||
1451 | /* Delete default control endpoint resources */ | ||
1452 | xhci_free_device_endpoint_resources(xhci, | ||
1453 | xhci->devs[slot_id], true); | ||
1454 | xhci_free_virt_device(xhci, slot_id); | ||
1455 | } | ||
1456 | break; | 1560 | break; |
1457 | case TRB_TYPE(TRB_CONFIG_EP): | 1561 | case TRB_CONFIG_EP: |
1458 | virt_dev = xhci->devs[slot_id]; | 1562 | xhci_handle_cmd_config_ep(xhci, slot_id, event, cmd_comp_code); |
1459 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
1460 | break; | ||
1461 | /* | ||
1462 | * Configure endpoint commands can come from the USB core | ||
1463 | * configuration or alt setting changes, or because the HW | ||
1464 | * needed an extra configure endpoint command after a reset | ||
1465 | * endpoint command or streams were being configured. | ||
1466 | * If the command was for a halted endpoint, the xHCI driver | ||
1467 | * is not waiting on the configure endpoint command. | ||
1468 | */ | ||
1469 | ctrl_ctx = xhci_get_input_control_ctx(xhci, | ||
1470 | virt_dev->in_ctx); | ||
1471 | if (!ctrl_ctx) { | ||
1472 | xhci_warn(xhci, "Could not get input context, bad type.\n"); | ||
1473 | break; | ||
1474 | } | ||
1475 | /* Input ctx add_flags are the endpoint index plus one */ | ||
1476 | ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1; | ||
1477 | /* A usb_set_interface() call directly after clearing a halted | ||
1478 | * condition may race on this quirky hardware. Not worth | ||
1479 | * worrying about, since this is prototype hardware. Not sure | ||
1480 | * if this will work for streams, but streams support was | ||
1481 | * untested on this prototype. | ||
1482 | */ | ||
1483 | if (xhci->quirks & XHCI_RESET_EP_QUIRK && | ||
1484 | ep_index != (unsigned int) -1 && | ||
1485 | le32_to_cpu(ctrl_ctx->add_flags) - SLOT_FLAG == | ||
1486 | le32_to_cpu(ctrl_ctx->drop_flags)) { | ||
1487 | ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; | ||
1488 | ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; | ||
1489 | if (!(ep_state & EP_HALTED)) | ||
1490 | goto bandwidth_change; | ||
1491 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | ||
1492 | "Completed config ep cmd - " | ||
1493 | "last ep index = %d, state = %d", | ||
1494 | ep_index, ep_state); | ||
1495 | /* Clear internal halted state and restart ring(s) */ | ||
1496 | xhci->devs[slot_id]->eps[ep_index].ep_state &= | ||
1497 | ~EP_HALTED; | ||
1498 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); | ||
1499 | break; | ||
1500 | } | ||
1501 | bandwidth_change: | ||
1502 | xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, | ||
1503 | "Completed config ep cmd"); | ||
1504 | xhci->devs[slot_id]->cmd_status = | ||
1505 | GET_COMP_CODE(le32_to_cpu(event->status)); | ||
1506 | complete(&xhci->devs[slot_id]->cmd_completion); | ||
1507 | break; | 1563 | break; |
1508 | case TRB_TYPE(TRB_EVAL_CONTEXT): | 1564 | case TRB_EVAL_CONTEXT: |
1509 | virt_dev = xhci->devs[slot_id]; | 1565 | xhci_handle_cmd_eval_ctx(xhci, slot_id, event, cmd_comp_code); |
1510 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
1511 | break; | ||
1512 | xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status)); | ||
1513 | complete(&xhci->devs[slot_id]->cmd_completion); | ||
1514 | break; | 1566 | break; |
1515 | case TRB_TYPE(TRB_ADDR_DEV): | 1567 | case TRB_ADDR_DEV: |
1516 | xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status)); | 1568 | xhci_handle_cmd_addr_dev(xhci, slot_id, cmd_comp_code); |
1517 | complete(&xhci->addr_dev); | ||
1518 | break; | 1569 | break; |
1519 | case TRB_TYPE(TRB_STOP_RING): | 1570 | case TRB_STOP_RING: |
1520 | handle_stopped_endpoint(xhci, xhci->cmd_ring->dequeue, event); | 1571 | WARN_ON(slot_id != TRB_TO_SLOT_ID( |
1572 | le32_to_cpu(cmd_trb->generic.field[3]))); | ||
1573 | xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, event); | ||
1521 | break; | 1574 | break; |
1522 | case TRB_TYPE(TRB_SET_DEQ): | 1575 | case TRB_SET_DEQ: |
1523 | handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); | 1576 | WARN_ON(slot_id != TRB_TO_SLOT_ID( |
1577 | le32_to_cpu(cmd_trb->generic.field[3]))); | ||
1578 | xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); | ||
1524 | break; | 1579 | break; |
1525 | case TRB_TYPE(TRB_CMD_NOOP): | 1580 | case TRB_CMD_NOOP: |
1526 | break; | 1581 | break; |
1527 | case TRB_TYPE(TRB_RESET_EP): | 1582 | case TRB_RESET_EP: |
1528 | handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); | 1583 | WARN_ON(slot_id != TRB_TO_SLOT_ID( |
1584 | le32_to_cpu(cmd_trb->generic.field[3]))); | ||
1585 | xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code); | ||
1529 | break; | 1586 | break; |
1530 | case TRB_TYPE(TRB_RESET_DEV): | 1587 | case TRB_RESET_DEV: |
1531 | xhci_dbg(xhci, "Completed reset device command.\n"); | 1588 | WARN_ON(slot_id != TRB_TO_SLOT_ID( |
1532 | slot_id = TRB_TO_SLOT_ID( | 1589 | le32_to_cpu(cmd_trb->generic.field[3]))); |
1533 | le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])); | 1590 | xhci_handle_cmd_reset_dev(xhci, slot_id, event); |
1534 | virt_dev = xhci->devs[slot_id]; | ||
1535 | if (virt_dev) | ||
1536 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, event); | ||
1537 | else | ||
1538 | xhci_warn(xhci, "Reset device command completion " | ||
1539 | "for disabled slot %u\n", slot_id); | ||
1540 | break; | 1591 | break; |
1541 | case TRB_TYPE(TRB_NEC_GET_FW): | 1592 | case TRB_NEC_GET_FW: |
1542 | if (!(xhci->quirks & XHCI_NEC_HOST)) { | 1593 | xhci_handle_cmd_nec_get_fw(xhci, event); |
1543 | xhci->error_bitmask |= 1 << 6; | ||
1544 | break; | ||
1545 | } | ||
1546 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | ||
1547 | "NEC firmware version %2x.%02x", | ||
1548 | NEC_FW_MAJOR(le32_to_cpu(event->status)), | ||
1549 | NEC_FW_MINOR(le32_to_cpu(event->status))); | ||
1550 | break; | 1594 | break; |
1551 | default: | 1595 | default: |
1552 | /* Skip over unknown commands on the event ring */ | 1596 | /* Skip over unknown commands on the event ring */ |
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 6e0d886bcce5..4265b48856f6 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -3459,7 +3459,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3459 | /* Wait for the Reset Device command to finish */ | 3459 | /* Wait for the Reset Device command to finish */ |
3460 | timeleft = wait_for_completion_interruptible_timeout( | 3460 | timeleft = wait_for_completion_interruptible_timeout( |
3461 | reset_device_cmd->completion, | 3461 | reset_device_cmd->completion, |
3462 | USB_CTRL_SET_TIMEOUT); | 3462 | XHCI_CMD_DEFAULT_TIMEOUT); |
3463 | if (timeleft <= 0) { | 3463 | if (timeleft <= 0) { |
3464 | xhci_warn(xhci, "%s while waiting for reset device command\n", | 3464 | xhci_warn(xhci, "%s while waiting for reset device command\n", |
3465 | timeleft == 0 ? "Timeout" : "Signal"); | 3465 | timeleft == 0 ? "Timeout" : "Signal"); |
@@ -3583,11 +3583,6 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3583 | del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); | 3583 | del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); |
3584 | } | 3584 | } |
3585 | 3585 | ||
3586 | if (udev->usb2_hw_lpm_enabled) { | ||
3587 | xhci_set_usb2_hardware_lpm(hcd, udev, 0); | ||
3588 | udev->usb2_hw_lpm_enabled = 0; | ||
3589 | } | ||
3590 | |||
3591 | spin_lock_irqsave(&xhci->lock, flags); | 3586 | spin_lock_irqsave(&xhci->lock, flags); |
3592 | /* Don't disable the slot if the host controller is dead. */ | 3587 | /* Don't disable the slot if the host controller is dead. */ |
3593 | state = xhci_readl(xhci, &xhci->op_regs->status); | 3588 | state = xhci_readl(xhci, &xhci->op_regs->status); |
@@ -3721,9 +3716,6 @@ disable_slot: | |||
3721 | * the device). | 3716 | * the device). |
3722 | * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so | 3717 | * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so |
3723 | * we should only issue and wait on one address command at the same time. | 3718 | * we should only issue and wait on one address command at the same time. |
3724 | * | ||
3725 | * We add one to the device address issued by the hardware because the USB core | ||
3726 | * uses address 1 for the root hubs (even though they're not really devices). | ||
3727 | */ | 3719 | */ |
3728 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | 3720 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) |
3729 | { | 3721 | { |
@@ -3868,16 +3860,13 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3868 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); | 3860 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); |
3869 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, | 3861 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, |
3870 | slot_ctx->dev_info >> 27); | 3862 | slot_ctx->dev_info >> 27); |
3871 | /* Use kernel assigned address for devices; store xHC assigned | ||
3872 | * address locally. */ | ||
3873 | virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK) | ||
3874 | + 1; | ||
3875 | /* Zero the input context control for later use */ | 3863 | /* Zero the input context control for later use */ |
3876 | ctrl_ctx->add_flags = 0; | 3864 | ctrl_ctx->add_flags = 0; |
3877 | ctrl_ctx->drop_flags = 0; | 3865 | ctrl_ctx->drop_flags = 0; |
3878 | 3866 | ||
3879 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3867 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
3880 | "Internal device address = %d", virt_dev->address); | 3868 | "Internal device address = %d", |
3869 | le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); | ||
3881 | 3870 | ||
3882 | return 0; | 3871 | return 0; |
3883 | } | 3872 | } |
@@ -4025,133 +4014,6 @@ static int xhci_calculate_usb2_hw_lpm_params(struct usb_device *udev) | |||
4025 | return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm); | 4014 | return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm); |
4026 | } | 4015 | } |
4027 | 4016 | ||
4028 | static int xhci_usb2_software_lpm_test(struct usb_hcd *hcd, | ||
4029 | struct usb_device *udev) | ||
4030 | { | ||
4031 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
4032 | struct dev_info *dev_info; | ||
4033 | __le32 __iomem **port_array; | ||
4034 | __le32 __iomem *addr, *pm_addr; | ||
4035 | u32 temp, dev_id; | ||
4036 | unsigned int port_num; | ||
4037 | unsigned long flags; | ||
4038 | int hird; | ||
4039 | int ret; | ||
4040 | |||
4041 | if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support || | ||
4042 | !udev->lpm_capable) | ||
4043 | return -EINVAL; | ||
4044 | |||
4045 | /* we only support lpm for non-hub device connected to root hub yet */ | ||
4046 | if (!udev->parent || udev->parent->parent || | ||
4047 | udev->descriptor.bDeviceClass == USB_CLASS_HUB) | ||
4048 | return -EINVAL; | ||
4049 | |||
4050 | spin_lock_irqsave(&xhci->lock, flags); | ||
4051 | |||
4052 | /* Look for devices in lpm_failed_devs list */ | ||
4053 | dev_id = le16_to_cpu(udev->descriptor.idVendor) << 16 | | ||
4054 | le16_to_cpu(udev->descriptor.idProduct); | ||
4055 | list_for_each_entry(dev_info, &xhci->lpm_failed_devs, list) { | ||
4056 | if (dev_info->dev_id == dev_id) { | ||
4057 | ret = -EINVAL; | ||
4058 | goto finish; | ||
4059 | } | ||
4060 | } | ||
4061 | |||
4062 | port_array = xhci->usb2_ports; | ||
4063 | port_num = udev->portnum - 1; | ||
4064 | |||
4065 | if (port_num > HCS_MAX_PORTS(xhci->hcs_params1)) { | ||
4066 | xhci_dbg(xhci, "invalid port number %d\n", udev->portnum); | ||
4067 | ret = -EINVAL; | ||
4068 | goto finish; | ||
4069 | } | ||
4070 | |||
4071 | /* | ||
4072 | * Test USB 2.0 software LPM. | ||
4073 | * FIXME: some xHCI 1.0 hosts may implement a new register to set up | ||
4074 | * hardware-controlled USB 2.0 LPM. See section 5.4.11 and 4.23.5.1.1.1 | ||
4075 | * in the June 2011 errata release. | ||
4076 | */ | ||
4077 | xhci_dbg(xhci, "test port %d software LPM\n", port_num); | ||
4078 | /* | ||
4079 | * Set L1 Device Slot and HIRD/BESL. | ||
4080 | * Check device's USB 2.0 extension descriptor to determine whether | ||
4081 | * HIRD or BESL shoule be used. See USB2.0 LPM errata. | ||
4082 | */ | ||
4083 | pm_addr = port_array[port_num] + PORTPMSC; | ||
4084 | hird = xhci_calculate_hird_besl(xhci, udev); | ||
4085 | temp = PORT_L1DS(udev->slot_id) | PORT_HIRD(hird); | ||
4086 | xhci_writel(xhci, temp, pm_addr); | ||
4087 | |||
4088 | /* Set port link state to U2(L1) */ | ||
4089 | addr = port_array[port_num]; | ||
4090 | xhci_set_link_state(xhci, port_array, port_num, XDEV_U2); | ||
4091 | |||
4092 | /* wait for ACK */ | ||
4093 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
4094 | msleep(10); | ||
4095 | spin_lock_irqsave(&xhci->lock, flags); | ||
4096 | |||
4097 | /* Check L1 Status */ | ||
4098 | ret = xhci_handshake(xhci, pm_addr, | ||
4099 | PORT_L1S_MASK, PORT_L1S_SUCCESS, 125); | ||
4100 | if (ret != -ETIMEDOUT) { | ||
4101 | /* enter L1 successfully */ | ||
4102 | temp = xhci_readl(xhci, addr); | ||
4103 | xhci_dbg(xhci, "port %d entered L1 state, port status 0x%x\n", | ||
4104 | port_num, temp); | ||
4105 | ret = 0; | ||
4106 | } else { | ||
4107 | temp = xhci_readl(xhci, pm_addr); | ||
4108 | xhci_dbg(xhci, "port %d software lpm failed, L1 status %d\n", | ||
4109 | port_num, temp & PORT_L1S_MASK); | ||
4110 | ret = -EINVAL; | ||
4111 | } | ||
4112 | |||
4113 | /* Resume the port */ | ||
4114 | xhci_set_link_state(xhci, port_array, port_num, XDEV_U0); | ||
4115 | |||
4116 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
4117 | msleep(10); | ||
4118 | spin_lock_irqsave(&xhci->lock, flags); | ||
4119 | |||
4120 | /* Clear PLC */ | ||
4121 | xhci_test_and_clear_bit(xhci, port_array, port_num, PORT_PLC); | ||
4122 | |||
4123 | /* Check PORTSC to make sure the device is in the right state */ | ||
4124 | if (!ret) { | ||
4125 | temp = xhci_readl(xhci, addr); | ||
4126 | xhci_dbg(xhci, "resumed port %d status 0x%x\n", port_num, temp); | ||
4127 | if (!(temp & PORT_CONNECT) || !(temp & PORT_PE) || | ||
4128 | (temp & PORT_PLS_MASK) != XDEV_U0) { | ||
4129 | xhci_dbg(xhci, "port L1 resume fail\n"); | ||
4130 | ret = -EINVAL; | ||
4131 | } | ||
4132 | } | ||
4133 | |||
4134 | if (ret) { | ||
4135 | /* Insert dev to lpm_failed_devs list */ | ||
4136 | xhci_warn(xhci, "device LPM test failed, may disconnect and " | ||
4137 | "re-enumerate\n"); | ||
4138 | dev_info = kzalloc(sizeof(struct dev_info), GFP_ATOMIC); | ||
4139 | if (!dev_info) { | ||
4140 | ret = -ENOMEM; | ||
4141 | goto finish; | ||
4142 | } | ||
4143 | dev_info->dev_id = dev_id; | ||
4144 | INIT_LIST_HEAD(&dev_info->list); | ||
4145 | list_add(&dev_info->list, &xhci->lpm_failed_devs); | ||
4146 | } else { | ||
4147 | xhci_ring_device(xhci, udev->slot_id); | ||
4148 | } | ||
4149 | |||
4150 | finish: | ||
4151 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
4152 | return ret; | ||
4153 | } | ||
4154 | |||
4155 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | 4017 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, |
4156 | struct usb_device *udev, int enable) | 4018 | struct usb_device *udev, int enable) |
4157 | { | 4019 | { |
@@ -4228,7 +4090,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | |||
4228 | } | 4090 | } |
4229 | 4091 | ||
4230 | pm_val &= ~PORT_HIRD_MASK; | 4092 | pm_val &= ~PORT_HIRD_MASK; |
4231 | pm_val |= PORT_HIRD(hird) | PORT_RWE; | 4093 | pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); |
4232 | xhci_writel(xhci, pm_val, pm_addr); | 4094 | xhci_writel(xhci, pm_val, pm_addr); |
4233 | pm_val = xhci_readl(xhci, pm_addr); | 4095 | pm_val = xhci_readl(xhci, pm_addr); |
4234 | pm_val |= PORT_HLE; | 4096 | pm_val |= PORT_HLE; |
@@ -4236,7 +4098,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | |||
4236 | /* flush write */ | 4098 | /* flush write */ |
4237 | xhci_readl(xhci, pm_addr); | 4099 | xhci_readl(xhci, pm_addr); |
4238 | } else { | 4100 | } else { |
4239 | pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK); | 4101 | pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK); |
4240 | xhci_writel(xhci, pm_val, pm_addr); | 4102 | xhci_writel(xhci, pm_val, pm_addr); |
4241 | /* flush write */ | 4103 | /* flush write */ |
4242 | xhci_readl(xhci, pm_addr); | 4104 | xhci_readl(xhci, pm_addr); |
@@ -4279,24 +4141,26 @@ static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port, | |||
4279 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) | 4141 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) |
4280 | { | 4142 | { |
4281 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 4143 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
4282 | int ret; | ||
4283 | int portnum = udev->portnum - 1; | 4144 | int portnum = udev->portnum - 1; |
4284 | 4145 | ||
4285 | ret = xhci_usb2_software_lpm_test(hcd, udev); | 4146 | if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support || |
4286 | if (!ret) { | 4147 | !udev->lpm_capable) |
4287 | xhci_dbg(xhci, "software LPM test succeed\n"); | 4148 | return 0; |
4288 | if (xhci->hw_lpm_support == 1 && | 4149 | |
4289 | xhci_check_usb2_port_capability(xhci, portnum, XHCI_HLC)) { | 4150 | /* we only support lpm for non-hub device connected to root hub yet */ |
4290 | udev->usb2_hw_lpm_capable = 1; | 4151 | if (!udev->parent || udev->parent->parent || |
4291 | udev->l1_params.timeout = XHCI_L1_TIMEOUT; | 4152 | udev->descriptor.bDeviceClass == USB_CLASS_HUB) |
4292 | udev->l1_params.besl = XHCI_DEFAULT_BESL; | 4153 | return 0; |
4293 | if (xhci_check_usb2_port_capability(xhci, portnum, | 4154 | |
4294 | XHCI_BLC)) | 4155 | if (xhci->hw_lpm_support == 1 && |
4295 | udev->usb2_hw_lpm_besl_capable = 1; | 4156 | xhci_check_usb2_port_capability( |
4296 | ret = xhci_set_usb2_hardware_lpm(hcd, udev, 1); | 4157 | xhci, portnum, XHCI_HLC)) { |
4297 | if (!ret) | 4158 | udev->usb2_hw_lpm_capable = 1; |
4298 | udev->usb2_hw_lpm_enabled = 1; | 4159 | udev->l1_params.timeout = XHCI_L1_TIMEOUT; |
4299 | } | 4160 | udev->l1_params.besl = XHCI_DEFAULT_BESL; |
4161 | if (xhci_check_usb2_port_capability(xhci, portnum, | ||
4162 | XHCI_BLC)) | ||
4163 | udev->usb2_hw_lpm_besl_capable = 1; | ||
4300 | } | 4164 | } |
4301 | 4165 | ||
4302 | return 0; | 4166 | return 0; |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 941d5f59e4dc..03c74b7965f8 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -383,6 +383,7 @@ struct xhci_op_regs { | |||
383 | #define PORT_RWE (1 << 3) | 383 | #define PORT_RWE (1 << 3) |
384 | #define PORT_HIRD(p) (((p) & 0xf) << 4) | 384 | #define PORT_HIRD(p) (((p) & 0xf) << 4) |
385 | #define PORT_HIRD_MASK (0xf << 4) | 385 | #define PORT_HIRD_MASK (0xf << 4) |
386 | #define PORT_L1DS_MASK (0xff << 8) | ||
386 | #define PORT_L1DS(p) (((p) & 0xff) << 8) | 387 | #define PORT_L1DS(p) (((p) & 0xff) << 8) |
387 | #define PORT_HLE (1 << 16) | 388 | #define PORT_HLE (1 << 16) |
388 | 389 | ||
@@ -934,8 +935,6 @@ struct xhci_virt_device { | |||
934 | /* Rings saved to ensure old alt settings can be re-instated */ | 935 | /* Rings saved to ensure old alt settings can be re-instated */ |
935 | struct xhci_ring **ring_cache; | 936 | struct xhci_ring **ring_cache; |
936 | int num_rings_cached; | 937 | int num_rings_cached; |
937 | /* Store xHC assigned device address */ | ||
938 | int address; | ||
939 | #define XHCI_MAX_RINGS_CACHED 31 | 938 | #define XHCI_MAX_RINGS_CACHED 31 |
940 | struct xhci_virt_ep eps[31]; | 939 | struct xhci_virt_ep eps[31]; |
941 | struct completion cmd_completion; | 940 | struct completion cmd_completion; |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index aa28ac8c7607..b4152820d655 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -120,7 +120,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) | |||
120 | struct usb_host_endpoint *e; | 120 | struct usb_host_endpoint *e; |
121 | 121 | ||
122 | e = alt->endpoint + ep; | 122 | e = alt->endpoint + ep; |
123 | switch (e->desc.bmAttributes) { | 123 | switch (usb_endpoint_type(&e->desc)) { |
124 | case USB_ENDPOINT_XFER_BULK: | 124 | case USB_ENDPOINT_XFER_BULK: |
125 | break; | 125 | break; |
126 | case USB_ENDPOINT_XFER_ISOC: | 126 | case USB_ENDPOINT_XFER_ISOC: |
@@ -437,7 +437,7 @@ alloc_sglist(int nents, int max, int vary) | |||
437 | if (max == 0) | 437 | if (max == 0) |
438 | return NULL; | 438 | return NULL; |
439 | 439 | ||
440 | sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL); | 440 | sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL); |
441 | if (!sg) | 441 | if (!sg) |
442 | return NULL; | 442 | return NULL; |
443 | sg_init_table(sg, nents); | 443 | sg_init_table(sg, nents); |
@@ -573,7 +573,7 @@ static int is_good_config(struct usbtest_dev *tdev, int len) | |||
573 | { | 573 | { |
574 | struct usb_config_descriptor *config; | 574 | struct usb_config_descriptor *config; |
575 | 575 | ||
576 | if (len < sizeof *config) | 576 | if (len < sizeof(*config)) |
577 | return 0; | 577 | return 0; |
578 | config = (struct usb_config_descriptor *) tdev->buf; | 578 | config = (struct usb_config_descriptor *) tdev->buf; |
579 | 579 | ||
@@ -606,6 +606,76 @@ static int is_good_config(struct usbtest_dev *tdev, int len) | |||
606 | return 0; | 606 | return 0; |
607 | } | 607 | } |
608 | 608 | ||
609 | static int is_good_ext(struct usbtest_dev *tdev, u8 *buf) | ||
610 | { | ||
611 | struct usb_ext_cap_descriptor *ext; | ||
612 | u32 attr; | ||
613 | |||
614 | ext = (struct usb_ext_cap_descriptor *) buf; | ||
615 | |||
616 | if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) { | ||
617 | ERROR(tdev, "bogus usb 2.0 extension descriptor length\n"); | ||
618 | return 0; | ||
619 | } | ||
620 | |||
621 | attr = le32_to_cpu(ext->bmAttributes); | ||
622 | /* bits[1:4] is used and others are reserved */ | ||
623 | if (attr & ~0x1e) { /* reserved == 0 */ | ||
624 | ERROR(tdev, "reserved bits set\n"); | ||
625 | return 0; | ||
626 | } | ||
627 | |||
628 | return 1; | ||
629 | } | ||
630 | |||
631 | static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf) | ||
632 | { | ||
633 | struct usb_ss_cap_descriptor *ss; | ||
634 | |||
635 | ss = (struct usb_ss_cap_descriptor *) buf; | ||
636 | |||
637 | if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) { | ||
638 | ERROR(tdev, "bogus superspeed device capability descriptor length\n"); | ||
639 | return 0; | ||
640 | } | ||
641 | |||
642 | /* | ||
643 | * only bit[1] of bmAttributes is used for LTM and others are | ||
644 | * reserved | ||
645 | */ | ||
646 | if (ss->bmAttributes & ~0x02) { /* reserved == 0 */ | ||
647 | ERROR(tdev, "reserved bits set in bmAttributes\n"); | ||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | /* bits[0:3] of wSpeedSupported is used and others are reserved */ | ||
652 | if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */ | ||
653 | ERROR(tdev, "reserved bits set in wSpeedSupported\n"); | ||
654 | return 0; | ||
655 | } | ||
656 | |||
657 | return 1; | ||
658 | } | ||
659 | |||
660 | static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf) | ||
661 | { | ||
662 | struct usb_ss_container_id_descriptor *con_id; | ||
663 | |||
664 | con_id = (struct usb_ss_container_id_descriptor *) buf; | ||
665 | |||
666 | if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) { | ||
667 | ERROR(tdev, "bogus container id descriptor length\n"); | ||
668 | return 0; | ||
669 | } | ||
670 | |||
671 | if (con_id->bReserved) { /* reserved == 0 */ | ||
672 | ERROR(tdev, "reserved bits set\n"); | ||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | return 1; | ||
677 | } | ||
678 | |||
609 | /* sanity test for standard requests working with usb_control_mesg() and some | 679 | /* sanity test for standard requests working with usb_control_mesg() and some |
610 | * of the utility functions which use it. | 680 | * of the utility functions which use it. |
611 | * | 681 | * |
@@ -683,12 +753,96 @@ static int ch9_postconfig(struct usbtest_dev *dev) | |||
683 | 753 | ||
684 | /* there's always [9.4.3] a device descriptor [9.6.1] */ | 754 | /* there's always [9.4.3] a device descriptor [9.6.1] */ |
685 | retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0, | 755 | retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0, |
686 | dev->buf, sizeof udev->descriptor); | 756 | dev->buf, sizeof(udev->descriptor)); |
687 | if (retval != sizeof udev->descriptor) { | 757 | if (retval != sizeof(udev->descriptor)) { |
688 | dev_err(&iface->dev, "dev descriptor --> %d\n", retval); | 758 | dev_err(&iface->dev, "dev descriptor --> %d\n", retval); |
689 | return (retval < 0) ? retval : -EDOM; | 759 | return (retval < 0) ? retval : -EDOM; |
690 | } | 760 | } |
691 | 761 | ||
762 | /* | ||
763 | * there's always [9.4.3] a bos device descriptor [9.6.2] in USB | ||
764 | * 3.0 spec | ||
765 | */ | ||
766 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) { | ||
767 | struct usb_bos_descriptor *bos = NULL; | ||
768 | struct usb_dev_cap_header *header = NULL; | ||
769 | unsigned total, num, length; | ||
770 | u8 *buf; | ||
771 | |||
772 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, | ||
773 | sizeof(*udev->bos->desc)); | ||
774 | if (retval != sizeof(*udev->bos->desc)) { | ||
775 | dev_err(&iface->dev, "bos descriptor --> %d\n", retval); | ||
776 | return (retval < 0) ? retval : -EDOM; | ||
777 | } | ||
778 | |||
779 | bos = (struct usb_bos_descriptor *)dev->buf; | ||
780 | total = le16_to_cpu(bos->wTotalLength); | ||
781 | num = bos->bNumDeviceCaps; | ||
782 | |||
783 | if (total > TBUF_SIZE) | ||
784 | total = TBUF_SIZE; | ||
785 | |||
786 | /* | ||
787 | * get generic device-level capability descriptors [9.6.2] | ||
788 | * in USB 3.0 spec | ||
789 | */ | ||
790 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, | ||
791 | total); | ||
792 | if (retval != total) { | ||
793 | dev_err(&iface->dev, "bos descriptor set --> %d\n", | ||
794 | retval); | ||
795 | return (retval < 0) ? retval : -EDOM; | ||
796 | } | ||
797 | |||
798 | length = sizeof(*udev->bos->desc); | ||
799 | buf = dev->buf; | ||
800 | for (i = 0; i < num; i++) { | ||
801 | buf += length; | ||
802 | if (buf + sizeof(struct usb_dev_cap_header) > | ||
803 | dev->buf + total) | ||
804 | break; | ||
805 | |||
806 | header = (struct usb_dev_cap_header *)buf; | ||
807 | length = header->bLength; | ||
808 | |||
809 | if (header->bDescriptorType != | ||
810 | USB_DT_DEVICE_CAPABILITY) { | ||
811 | dev_warn(&udev->dev, "not device capability descriptor, skip\n"); | ||
812 | continue; | ||
813 | } | ||
814 | |||
815 | switch (header->bDevCapabilityType) { | ||
816 | case USB_CAP_TYPE_EXT: | ||
817 | if (buf + USB_DT_USB_EXT_CAP_SIZE > | ||
818 | dev->buf + total || | ||
819 | !is_good_ext(dev, buf)) { | ||
820 | dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n"); | ||
821 | return -EDOM; | ||
822 | } | ||
823 | break; | ||
824 | case USB_SS_CAP_TYPE: | ||
825 | if (buf + USB_DT_USB_SS_CAP_SIZE > | ||
826 | dev->buf + total || | ||
827 | !is_good_ss_cap(dev, buf)) { | ||
828 | dev_err(&iface->dev, "bogus superspeed device capability descriptor\n"); | ||
829 | return -EDOM; | ||
830 | } | ||
831 | break; | ||
832 | case CONTAINER_ID_TYPE: | ||
833 | if (buf + USB_DT_USB_SS_CONTN_ID_SIZE > | ||
834 | dev->buf + total || | ||
835 | !is_good_con_id(dev, buf)) { | ||
836 | dev_err(&iface->dev, "bogus container id descriptor\n"); | ||
837 | return -EDOM; | ||
838 | } | ||
839 | break; | ||
840 | default: | ||
841 | break; | ||
842 | } | ||
843 | } | ||
844 | } | ||
845 | |||
692 | /* there's always [9.4.3] at least one config descriptor [9.6.3] */ | 846 | /* there's always [9.4.3] at least one config descriptor [9.6.3] */ |
693 | for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { | 847 | for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { |
694 | retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, | 848 | retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, |
@@ -954,7 +1108,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param) | |||
954 | * device, but some are chosen to trigger protocol stalls | 1108 | * device, but some are chosen to trigger protocol stalls |
955 | * or short reads. | 1109 | * or short reads. |
956 | */ | 1110 | */ |
957 | memset(&req, 0, sizeof req); | 1111 | memset(&req, 0, sizeof(req)); |
958 | req.bRequest = USB_REQ_GET_DESCRIPTOR; | 1112 | req.bRequest = USB_REQ_GET_DESCRIPTOR; |
959 | req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; | 1113 | req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; |
960 | 1114 | ||
@@ -1074,7 +1228,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param) | |||
1074 | if (!u) | 1228 | if (!u) |
1075 | goto cleanup; | 1229 | goto cleanup; |
1076 | 1230 | ||
1077 | reqp = kmalloc(sizeof *reqp, GFP_KERNEL); | 1231 | reqp = kmalloc(sizeof(*reqp), GFP_KERNEL); |
1078 | if (!reqp) | 1232 | if (!reqp) |
1079 | goto cleanup; | 1233 | goto cleanup; |
1080 | reqp->setup = req; | 1234 | reqp->setup = req; |
@@ -1667,13 +1821,13 @@ test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param, | |||
1667 | if (param->sglen > 10) | 1821 | if (param->sglen > 10) |
1668 | return -EDOM; | 1822 | return -EDOM; |
1669 | 1823 | ||
1670 | memset(&context, 0, sizeof context); | 1824 | memset(&context, 0, sizeof(context)); |
1671 | context.count = param->iterations * param->sglen; | 1825 | context.count = param->iterations * param->sglen; |
1672 | context.dev = dev; | 1826 | context.dev = dev; |
1673 | init_completion(&context.done); | 1827 | init_completion(&context.done); |
1674 | spin_lock_init(&context.lock); | 1828 | spin_lock_init(&context.lock); |
1675 | 1829 | ||
1676 | memset(urbs, 0, sizeof urbs); | 1830 | memset(urbs, 0, sizeof(urbs)); |
1677 | udev = testdev_to_usbdev(dev); | 1831 | udev = testdev_to_usbdev(dev); |
1678 | dev_info(&dev->intf->dev, | 1832 | dev_info(&dev->intf->dev, |
1679 | "... iso period %d %sframes, wMaxPacket %04x\n", | 1833 | "... iso period %d %sframes, wMaxPacket %04x\n", |
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index c258a97ef1b0..57dfc0cedb00 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig | |||
@@ -75,6 +75,7 @@ config USB_MUSB_TUSB6010 | |||
75 | config USB_MUSB_OMAP2PLUS | 75 | config USB_MUSB_OMAP2PLUS |
76 | tristate "OMAP2430 and onwards" | 76 | tristate "OMAP2430 and onwards" |
77 | depends on ARCH_OMAP2PLUS | 77 | depends on ARCH_OMAP2PLUS |
78 | select GENERIC_PHY | ||
78 | 79 | ||
79 | config USB_MUSB_AM35X | 80 | config USB_MUSB_AM35X |
80 | tristate "AM35x" | 81 | tristate "AM35x" |
@@ -90,7 +91,7 @@ config USB_MUSB_BLACKFIN | |||
90 | depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523) | 91 | depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523) |
91 | 92 | ||
92 | config USB_MUSB_UX500 | 93 | config USB_MUSB_UX500 |
93 | tristate "U8500 and U5500" | 94 | tristate "Ux500 platforms" |
94 | 95 | ||
95 | endchoice | 96 | endchoice |
96 | 97 | ||
@@ -112,7 +113,7 @@ choice | |||
112 | allow using DMA on multiplatform kernels. | 113 | allow using DMA on multiplatform kernels. |
113 | 114 | ||
114 | config USB_UX500_DMA | 115 | config USB_UX500_DMA |
115 | bool 'ST Ericsson U8500 and U5500' | 116 | bool 'ST Ericsson Ux500' |
116 | depends on USB_MUSB_UX500 | 117 | depends on USB_MUSB_UX500 |
117 | help | 118 | help |
118 | Enable DMA transfers on UX500 platforms. | 119 | Enable DMA transfers on UX500 platforms. |
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c index 5c310c664218..ca45b39db5b9 100644 --- a/drivers/usb/musb/am35x.c +++ b/drivers/usb/musb/am35x.c | |||
@@ -89,7 +89,6 @@ struct am35x_glue { | |||
89 | struct clk *phy_clk; | 89 | struct clk *phy_clk; |
90 | struct clk *clk; | 90 | struct clk *clk; |
91 | }; | 91 | }; |
92 | #define glue_to_musb(g) platform_get_drvdata(g->musb) | ||
93 | 92 | ||
94 | /* | 93 | /* |
95 | * am35x_musb_enable - enable interrupts | 94 | * am35x_musb_enable - enable interrupts |
@@ -452,14 +451,18 @@ static const struct musb_platform_ops am35x_ops = { | |||
452 | .set_vbus = am35x_musb_set_vbus, | 451 | .set_vbus = am35x_musb_set_vbus, |
453 | }; | 452 | }; |
454 | 453 | ||
455 | static u64 am35x_dmamask = DMA_BIT_MASK(32); | 454 | static const struct platform_device_info am35x_dev_info = { |
455 | .name = "musb-hdrc", | ||
456 | .id = PLATFORM_DEVID_AUTO, | ||
457 | .dma_mask = DMA_BIT_MASK(32), | ||
458 | }; | ||
456 | 459 | ||
457 | static int am35x_probe(struct platform_device *pdev) | 460 | static int am35x_probe(struct platform_device *pdev) |
458 | { | 461 | { |
459 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); | 462 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
460 | struct platform_device *musb; | 463 | struct platform_device *musb; |
461 | struct am35x_glue *glue; | 464 | struct am35x_glue *glue; |
462 | 465 | struct platform_device_info pinfo; | |
463 | struct clk *phy_clk; | 466 | struct clk *phy_clk; |
464 | struct clk *clk; | 467 | struct clk *clk; |
465 | 468 | ||
@@ -471,12 +474,6 @@ static int am35x_probe(struct platform_device *pdev) | |||
471 | goto err0; | 474 | goto err0; |
472 | } | 475 | } |
473 | 476 | ||
474 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | ||
475 | if (!musb) { | ||
476 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | ||
477 | goto err1; | ||
478 | } | ||
479 | |||
480 | phy_clk = clk_get(&pdev->dev, "fck"); | 477 | phy_clk = clk_get(&pdev->dev, "fck"); |
481 | if (IS_ERR(phy_clk)) { | 478 | if (IS_ERR(phy_clk)) { |
482 | dev_err(&pdev->dev, "failed to get PHY clock\n"); | 479 | dev_err(&pdev->dev, "failed to get PHY clock\n"); |
@@ -503,12 +500,7 @@ static int am35x_probe(struct platform_device *pdev) | |||
503 | goto err6; | 500 | goto err6; |
504 | } | 501 | } |
505 | 502 | ||
506 | musb->dev.parent = &pdev->dev; | ||
507 | musb->dev.dma_mask = &am35x_dmamask; | ||
508 | musb->dev.coherent_dma_mask = am35x_dmamask; | ||
509 | |||
510 | glue->dev = &pdev->dev; | 503 | glue->dev = &pdev->dev; |
511 | glue->musb = musb; | ||
512 | glue->phy_clk = phy_clk; | 504 | glue->phy_clk = phy_clk; |
513 | glue->clk = clk; | 505 | glue->clk = clk; |
514 | 506 | ||
@@ -516,22 +508,17 @@ static int am35x_probe(struct platform_device *pdev) | |||
516 | 508 | ||
517 | platform_set_drvdata(pdev, glue); | 509 | platform_set_drvdata(pdev, glue); |
518 | 510 | ||
519 | ret = platform_device_add_resources(musb, pdev->resource, | 511 | pinfo = am35x_dev_info; |
520 | pdev->num_resources); | 512 | pinfo.parent = &pdev->dev; |
521 | if (ret) { | 513 | pinfo.res = pdev->resource; |
522 | dev_err(&pdev->dev, "failed to add resources\n"); | 514 | pinfo.num_res = pdev->num_resources; |
523 | goto err7; | 515 | pinfo.data = pdata; |
524 | } | 516 | pinfo.size_data = sizeof(*pdata); |
525 | 517 | ||
526 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 518 | glue->musb = musb = platform_device_register_full(&pinfo); |
527 | if (ret) { | 519 | if (IS_ERR(musb)) { |
528 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 520 | ret = PTR_ERR(musb); |
529 | goto err7; | 521 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
530 | } | ||
531 | |||
532 | ret = platform_device_add(musb); | ||
533 | if (ret) { | ||
534 | dev_err(&pdev->dev, "failed to register musb device\n"); | ||
535 | goto err7; | 522 | goto err7; |
536 | } | 523 | } |
537 | 524 | ||
@@ -550,9 +537,6 @@ err4: | |||
550 | clk_put(phy_clk); | 537 | clk_put(phy_clk); |
551 | 538 | ||
552 | err3: | 539 | err3: |
553 | platform_device_put(musb); | ||
554 | |||
555 | err1: | ||
556 | kfree(glue); | 540 | kfree(glue); |
557 | 541 | ||
558 | err0: | 542 | err0: |
@@ -615,23 +599,16 @@ static int am35x_resume(struct device *dev) | |||
615 | 599 | ||
616 | return 0; | 600 | return 0; |
617 | } | 601 | } |
618 | |||
619 | static struct dev_pm_ops am35x_pm_ops = { | ||
620 | .suspend = am35x_suspend, | ||
621 | .resume = am35x_resume, | ||
622 | }; | ||
623 | |||
624 | #define DEV_PM_OPS &am35x_pm_ops | ||
625 | #else | ||
626 | #define DEV_PM_OPS NULL | ||
627 | #endif | 602 | #endif |
628 | 603 | ||
604 | static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume); | ||
605 | |||
629 | static struct platform_driver am35x_driver = { | 606 | static struct platform_driver am35x_driver = { |
630 | .probe = am35x_probe, | 607 | .probe = am35x_probe, |
631 | .remove = am35x_remove, | 608 | .remove = am35x_remove, |
632 | .driver = { | 609 | .driver = { |
633 | .name = "musb-am35x", | 610 | .name = "musb-am35x", |
634 | .pm = DEV_PM_OPS, | 611 | .pm = &am35x_pm_ops, |
635 | }, | 612 | }, |
636 | }; | 613 | }; |
637 | 614 | ||
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c index 72e2056b6082..d9692f78e227 100644 --- a/drivers/usb/musb/blackfin.c +++ b/drivers/usb/musb/blackfin.c | |||
@@ -561,23 +561,16 @@ static int bfin_resume(struct device *dev) | |||
561 | 561 | ||
562 | return 0; | 562 | return 0; |
563 | } | 563 | } |
564 | |||
565 | static struct dev_pm_ops bfin_pm_ops = { | ||
566 | .suspend = bfin_suspend, | ||
567 | .resume = bfin_resume, | ||
568 | }; | ||
569 | |||
570 | #define DEV_PM_OPS &bfin_pm_ops | ||
571 | #else | ||
572 | #define DEV_PM_OPS NULL | ||
573 | #endif | 564 | #endif |
574 | 565 | ||
566 | static SIMPLE_DEV_PM_OPS(bfin_pm_ops, bfin_suspend, bfin_resume); | ||
567 | |||
575 | static struct platform_driver bfin_driver = { | 568 | static struct platform_driver bfin_driver = { |
576 | .probe = bfin_probe, | 569 | .probe = bfin_probe, |
577 | .remove = __exit_p(bfin_remove), | 570 | .remove = __exit_p(bfin_remove), |
578 | .driver = { | 571 | .driver = { |
579 | .name = "musb-blackfin", | 572 | .name = "musb-blackfin", |
580 | .pm = DEV_PM_OPS, | 573 | .pm = &bfin_pm_ops, |
581 | }, | 574 | }, |
582 | }; | 575 | }; |
583 | 576 | ||
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index d9ddf4122f37..2f2c1cb36421 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c | |||
@@ -472,7 +472,11 @@ static const struct musb_platform_ops da8xx_ops = { | |||
472 | .set_vbus = da8xx_musb_set_vbus, | 472 | .set_vbus = da8xx_musb_set_vbus, |
473 | }; | 473 | }; |
474 | 474 | ||
475 | static u64 da8xx_dmamask = DMA_BIT_MASK(32); | 475 | static const struct platform_device_info da8xx_dev_info = { |
476 | .name = "musb-hdrc", | ||
477 | .id = PLATFORM_DEVID_AUTO, | ||
478 | .dma_mask = DMA_BIT_MASK(32), | ||
479 | }; | ||
476 | 480 | ||
477 | static int da8xx_probe(struct platform_device *pdev) | 481 | static int da8xx_probe(struct platform_device *pdev) |
478 | { | 482 | { |
@@ -480,7 +484,7 @@ static int da8xx_probe(struct platform_device *pdev) | |||
480 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); | 484 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
481 | struct platform_device *musb; | 485 | struct platform_device *musb; |
482 | struct da8xx_glue *glue; | 486 | struct da8xx_glue *glue; |
483 | 487 | struct platform_device_info pinfo; | |
484 | struct clk *clk; | 488 | struct clk *clk; |
485 | 489 | ||
486 | int ret = -ENOMEM; | 490 | int ret = -ENOMEM; |
@@ -491,12 +495,6 @@ static int da8xx_probe(struct platform_device *pdev) | |||
491 | goto err0; | 495 | goto err0; |
492 | } | 496 | } |
493 | 497 | ||
494 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | ||
495 | if (!musb) { | ||
496 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | ||
497 | goto err1; | ||
498 | } | ||
499 | |||
500 | clk = clk_get(&pdev->dev, "usb20"); | 498 | clk = clk_get(&pdev->dev, "usb20"); |
501 | if (IS_ERR(clk)) { | 499 | if (IS_ERR(clk)) { |
502 | dev_err(&pdev->dev, "failed to get clock\n"); | 500 | dev_err(&pdev->dev, "failed to get clock\n"); |
@@ -510,12 +508,7 @@ static int da8xx_probe(struct platform_device *pdev) | |||
510 | goto err4; | 508 | goto err4; |
511 | } | 509 | } |
512 | 510 | ||
513 | musb->dev.parent = &pdev->dev; | ||
514 | musb->dev.dma_mask = &da8xx_dmamask; | ||
515 | musb->dev.coherent_dma_mask = da8xx_dmamask; | ||
516 | |||
517 | glue->dev = &pdev->dev; | 511 | glue->dev = &pdev->dev; |
518 | glue->musb = musb; | ||
519 | glue->clk = clk; | 512 | glue->clk = clk; |
520 | 513 | ||
521 | pdata->platform_ops = &da8xx_ops; | 514 | pdata->platform_ops = &da8xx_ops; |
@@ -535,22 +528,17 @@ static int da8xx_probe(struct platform_device *pdev) | |||
535 | musb_resources[1].end = pdev->resource[1].end; | 528 | musb_resources[1].end = pdev->resource[1].end; |
536 | musb_resources[1].flags = pdev->resource[1].flags; | 529 | musb_resources[1].flags = pdev->resource[1].flags; |
537 | 530 | ||
538 | ret = platform_device_add_resources(musb, musb_resources, | 531 | pinfo = da8xx_dev_info; |
539 | ARRAY_SIZE(musb_resources)); | 532 | pinfo.parent = &pdev->dev; |
540 | if (ret) { | 533 | pinfo.res = musb_resources; |
541 | dev_err(&pdev->dev, "failed to add resources\n"); | 534 | pinfo.num_res = ARRAY_SIZE(musb_resources); |
542 | goto err5; | 535 | pinfo.data = pdata; |
543 | } | 536 | pinfo.size_data = sizeof(*pdata); |
544 | 537 | ||
545 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 538 | glue->musb = musb = platform_device_register_full(&pinfo); |
546 | if (ret) { | 539 | if (IS_ERR(musb)) { |
547 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 540 | ret = PTR_ERR(musb); |
548 | goto err5; | 541 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
549 | } | ||
550 | |||
551 | ret = platform_device_add(musb); | ||
552 | if (ret) { | ||
553 | dev_err(&pdev->dev, "failed to register musb device\n"); | ||
554 | goto err5; | 542 | goto err5; |
555 | } | 543 | } |
556 | 544 | ||
@@ -563,9 +551,6 @@ err4: | |||
563 | clk_put(clk); | 551 | clk_put(clk); |
564 | 552 | ||
565 | err3: | 553 | err3: |
566 | platform_device_put(musb); | ||
567 | |||
568 | err1: | ||
569 | kfree(glue); | 554 | kfree(glue); |
570 | 555 | ||
571 | err0: | 556 | err0: |
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c index ed0834e2b72e..1121fd741bf8 100644 --- a/drivers/usb/musb/davinci.c +++ b/drivers/usb/musb/davinci.c | |||
@@ -505,14 +505,19 @@ static const struct musb_platform_ops davinci_ops = { | |||
505 | .set_vbus = davinci_musb_set_vbus, | 505 | .set_vbus = davinci_musb_set_vbus, |
506 | }; | 506 | }; |
507 | 507 | ||
508 | static u64 davinci_dmamask = DMA_BIT_MASK(32); | 508 | static const struct platform_device_info davinci_dev_info = { |
509 | .name = "musb-hdrc", | ||
510 | .id = PLATFORM_DEVID_AUTO, | ||
511 | .dma_mask = DMA_BIT_MASK(32), | ||
512 | }; | ||
509 | 513 | ||
510 | static int davinci_probe(struct platform_device *pdev) | 514 | static int davinci_probe(struct platform_device *pdev) |
511 | { | 515 | { |
512 | struct resource musb_resources[2]; | 516 | struct resource musb_resources[3]; |
513 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); | 517 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
514 | struct platform_device *musb; | 518 | struct platform_device *musb; |
515 | struct davinci_glue *glue; | 519 | struct davinci_glue *glue; |
520 | struct platform_device_info pinfo; | ||
516 | struct clk *clk; | 521 | struct clk *clk; |
517 | 522 | ||
518 | int ret = -ENOMEM; | 523 | int ret = -ENOMEM; |
@@ -523,12 +528,6 @@ static int davinci_probe(struct platform_device *pdev) | |||
523 | goto err0; | 528 | goto err0; |
524 | } | 529 | } |
525 | 530 | ||
526 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | ||
527 | if (!musb) { | ||
528 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | ||
529 | goto err1; | ||
530 | } | ||
531 | |||
532 | clk = clk_get(&pdev->dev, "usb"); | 531 | clk = clk_get(&pdev->dev, "usb"); |
533 | if (IS_ERR(clk)) { | 532 | if (IS_ERR(clk)) { |
534 | dev_err(&pdev->dev, "failed to get clock\n"); | 533 | dev_err(&pdev->dev, "failed to get clock\n"); |
@@ -542,12 +541,7 @@ static int davinci_probe(struct platform_device *pdev) | |||
542 | goto err4; | 541 | goto err4; |
543 | } | 542 | } |
544 | 543 | ||
545 | musb->dev.parent = &pdev->dev; | ||
546 | musb->dev.dma_mask = &davinci_dmamask; | ||
547 | musb->dev.coherent_dma_mask = davinci_dmamask; | ||
548 | |||
549 | glue->dev = &pdev->dev; | 544 | glue->dev = &pdev->dev; |
550 | glue->musb = musb; | ||
551 | glue->clk = clk; | 545 | glue->clk = clk; |
552 | 546 | ||
553 | pdata->platform_ops = &davinci_ops; | 547 | pdata->platform_ops = &davinci_ops; |
@@ -567,22 +561,26 @@ static int davinci_probe(struct platform_device *pdev) | |||
567 | musb_resources[1].end = pdev->resource[1].end; | 561 | musb_resources[1].end = pdev->resource[1].end; |
568 | musb_resources[1].flags = pdev->resource[1].flags; | 562 | musb_resources[1].flags = pdev->resource[1].flags; |
569 | 563 | ||
570 | ret = platform_device_add_resources(musb, musb_resources, | 564 | /* |
571 | ARRAY_SIZE(musb_resources)); | 565 | * For DM6467 3 resources are passed. A placeholder for the 3rd |
572 | if (ret) { | 566 | * resource is always there, so it's safe to always copy it... |
573 | dev_err(&pdev->dev, "failed to add resources\n"); | 567 | */ |
574 | goto err5; | 568 | musb_resources[2].name = pdev->resource[2].name; |
575 | } | 569 | musb_resources[2].start = pdev->resource[2].start; |
576 | 570 | musb_resources[2].end = pdev->resource[2].end; | |
577 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 571 | musb_resources[2].flags = pdev->resource[2].flags; |
578 | if (ret) { | 572 | |
579 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 573 | pinfo = davinci_dev_info; |
580 | goto err5; | 574 | pinfo.parent = &pdev->dev; |
581 | } | 575 | pinfo.res = musb_resources; |
582 | 576 | pinfo.num_res = ARRAY_SIZE(musb_resources); | |
583 | ret = platform_device_add(musb); | 577 | pinfo.data = pdata; |
584 | if (ret) { | 578 | pinfo.size_data = sizeof(*pdata); |
585 | dev_err(&pdev->dev, "failed to register musb device\n"); | 579 | |
580 | glue->musb = musb = platform_device_register_full(&pinfo); | ||
581 | if (IS_ERR(musb)) { | ||
582 | ret = PTR_ERR(musb); | ||
583 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); | ||
586 | goto err5; | 584 | goto err5; |
587 | } | 585 | } |
588 | 586 | ||
@@ -595,9 +593,6 @@ err4: | |||
595 | clk_put(clk); | 593 | clk_put(clk); |
596 | 594 | ||
597 | err3: | 595 | err3: |
598 | platform_device_put(musb); | ||
599 | |||
600 | err1: | ||
601 | kfree(glue); | 596 | kfree(glue); |
602 | 597 | ||
603 | err0: | 598 | err0: |
diff --git a/drivers/usb/musb/musb_am335x.c b/drivers/usb/musb/musb_am335x.c index 41ac5b5b57ce..8be9b02c3cc2 100644 --- a/drivers/usb/musb/musb_am335x.c +++ b/drivers/usb/musb/musb_am335x.c | |||
@@ -46,7 +46,7 @@ static struct platform_driver am335x_child_driver = { | |||
46 | .remove = am335x_child_remove, | 46 | .remove = am335x_child_remove, |
47 | .driver = { | 47 | .driver = { |
48 | .name = "am335x-usb-childs", | 48 | .name = "am335x-usb-childs", |
49 | .of_match_table = of_match_ptr(am335x_child_of_match), | 49 | .of_match_table = am335x_child_of_match, |
50 | }, | 50 | }, |
51 | }; | 51 | }; |
52 | 52 | ||
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index cd70cc886171..0a43329569d1 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -617,7 +617,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
617 | /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */ | 617 | /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */ |
618 | default: | 618 | default: |
619 | s = "VALID"; break; | 619 | s = "VALID"; break; |
620 | }; s; }), | 620 | } s; }), |
621 | VBUSERR_RETRY_COUNT - musb->vbuserr_retry, | 621 | VBUSERR_RETRY_COUNT - musb->vbuserr_retry, |
622 | musb->port1_status); | 622 | musb->port1_status); |
623 | 623 | ||
@@ -1809,8 +1809,7 @@ static void musb_free(struct musb *musb) | |||
1809 | disable_irq_wake(musb->nIrq); | 1809 | disable_irq_wake(musb->nIrq); |
1810 | free_irq(musb->nIrq, musb); | 1810 | free_irq(musb->nIrq, musb); |
1811 | } | 1811 | } |
1812 | if (musb->dma_controller) | 1812 | cancel_work_sync(&musb->irq_work); |
1813 | dma_controller_destroy(musb->dma_controller); | ||
1814 | 1813 | ||
1815 | musb_host_free(musb); | 1814 | musb_host_free(musb); |
1816 | } | 1815 | } |
@@ -1885,8 +1884,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1885 | 1884 | ||
1886 | pm_runtime_get_sync(musb->controller); | 1885 | pm_runtime_get_sync(musb->controller); |
1887 | 1886 | ||
1888 | if (use_dma && dev->dma_mask) | 1887 | if (use_dma && dev->dma_mask) { |
1889 | musb->dma_controller = dma_controller_create(musb, musb->mregs); | 1888 | musb->dma_controller = dma_controller_create(musb, musb->mregs); |
1889 | if (IS_ERR(musb->dma_controller)) { | ||
1890 | status = PTR_ERR(musb->dma_controller); | ||
1891 | goto fail2_5; | ||
1892 | } | ||
1893 | } | ||
1890 | 1894 | ||
1891 | /* be sure interrupts are disabled before connecting ISR */ | 1895 | /* be sure interrupts are disabled before connecting ISR */ |
1892 | musb_platform_disable(musb); | 1896 | musb_platform_disable(musb); |
@@ -1946,6 +1950,8 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1946 | if (status < 0) | 1950 | if (status < 0) |
1947 | goto fail3; | 1951 | goto fail3; |
1948 | status = musb_gadget_setup(musb); | 1952 | status = musb_gadget_setup(musb); |
1953 | if (status) | ||
1954 | musb_host_cleanup(musb); | ||
1949 | break; | 1955 | break; |
1950 | default: | 1956 | default: |
1951 | dev_err(dev, "unsupported port mode %d\n", musb->port_mode); | 1957 | dev_err(dev, "unsupported port mode %d\n", musb->port_mode); |
@@ -1972,10 +1978,12 @@ fail5: | |||
1972 | 1978 | ||
1973 | fail4: | 1979 | fail4: |
1974 | musb_gadget_cleanup(musb); | 1980 | musb_gadget_cleanup(musb); |
1981 | musb_host_cleanup(musb); | ||
1975 | 1982 | ||
1976 | fail3: | 1983 | fail3: |
1977 | if (musb->dma_controller) | 1984 | if (musb->dma_controller) |
1978 | dma_controller_destroy(musb->dma_controller); | 1985 | dma_controller_destroy(musb->dma_controller); |
1986 | fail2_5: | ||
1979 | pm_runtime_put_sync(musb->controller); | 1987 | pm_runtime_put_sync(musb->controller); |
1980 | 1988 | ||
1981 | fail2: | 1989 | fail2: |
@@ -2032,6 +2040,9 @@ static int musb_remove(struct platform_device *pdev) | |||
2032 | musb_exit_debugfs(musb); | 2040 | musb_exit_debugfs(musb); |
2033 | musb_shutdown(pdev); | 2041 | musb_shutdown(pdev); |
2034 | 2042 | ||
2043 | if (musb->dma_controller) | ||
2044 | dma_controller_destroy(musb->dma_controller); | ||
2045 | |||
2035 | musb_free(musb); | 2046 | musb_free(musb); |
2036 | device_init_wakeup(dev, 0); | 2047 | device_init_wakeup(dev, 0); |
2037 | return 0; | 2048 | return 0; |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 1c5bf75ee8ff..29f7cd7c7964 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <linux/usb.h> | 46 | #include <linux/usb.h> |
47 | #include <linux/usb/otg.h> | 47 | #include <linux/usb/otg.h> |
48 | #include <linux/usb/musb.h> | 48 | #include <linux/usb/musb.h> |
49 | #include <linux/phy/phy.h> | ||
49 | 50 | ||
50 | struct musb; | 51 | struct musb; |
51 | struct musb_hw_ep; | 52 | struct musb_hw_ep; |
@@ -341,6 +342,7 @@ struct musb { | |||
341 | u16 int_tx; | 342 | u16 int_tx; |
342 | 343 | ||
343 | struct usb_phy *xceiv; | 344 | struct usb_phy *xceiv; |
345 | struct phy *phy; | ||
344 | 346 | ||
345 | int nIrq; | 347 | int nIrq; |
346 | unsigned irq_wake:1; | 348 | unsigned irq_wake:1; |
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index ae959746f77f..ff9d6de2b746 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c | |||
@@ -484,6 +484,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) | |||
484 | if (ret) | 484 | if (ret) |
485 | goto err; | 485 | goto err; |
486 | 486 | ||
487 | ret = -EINVAL; | ||
487 | if (port > MUSB_DMA_NUM_CHANNELS || !port) | 488 | if (port > MUSB_DMA_NUM_CHANNELS || !port) |
488 | goto err; | 489 | goto err; |
489 | if (is_tx) | 490 | if (is_tx) |
@@ -503,6 +504,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) | |||
503 | dc = dma_request_slave_channel(dev, str); | 504 | dc = dma_request_slave_channel(dev, str); |
504 | if (!dc) { | 505 | if (!dc) { |
505 | dev_err(dev, "Falied to request %s.\n", str); | 506 | dev_err(dev, "Falied to request %s.\n", str); |
507 | ret = -EPROBE_DEFER; | ||
506 | goto err; | 508 | goto err; |
507 | } | 509 | } |
508 | cppi41_channel->dc = dc; | 510 | cppi41_channel->dc = dc; |
@@ -510,7 +512,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) | |||
510 | return 0; | 512 | return 0; |
511 | err: | 513 | err: |
512 | cppi41_release_all_dma_chans(controller); | 514 | cppi41_release_all_dma_chans(controller); |
513 | return -EINVAL; | 515 | return ret; |
514 | } | 516 | } |
515 | 517 | ||
516 | void dma_controller_destroy(struct dma_controller *c) | 518 | void dma_controller_destroy(struct dma_controller *c) |
@@ -526,7 +528,7 @@ struct dma_controller *dma_controller_create(struct musb *musb, | |||
526 | void __iomem *base) | 528 | void __iomem *base) |
527 | { | 529 | { |
528 | struct cppi41_dma_controller *controller; | 530 | struct cppi41_dma_controller *controller; |
529 | int ret; | 531 | int ret = 0; |
530 | 532 | ||
531 | if (!musb->controller->of_node) { | 533 | if (!musb->controller->of_node) { |
532 | dev_err(musb->controller, "Need DT for the DMA engine.\n"); | 534 | dev_err(musb->controller, "Need DT for the DMA engine.\n"); |
@@ -553,5 +555,7 @@ struct dma_controller *dma_controller_create(struct musb *musb, | |||
553 | plat_get_fail: | 555 | plat_get_fail: |
554 | kfree(controller); | 556 | kfree(controller); |
555 | kzalloc_fail: | 557 | kzalloc_fail: |
558 | if (ret == -EPROBE_DEFER) | ||
559 | return ERR_PTR(ret); | ||
556 | return NULL; | 560 | return NULL; |
557 | } | 561 | } |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index bd4138d80a48..1901f6fe5807 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -121,6 +121,43 @@ struct dsps_glue { | |||
121 | unsigned long last_timer; /* last timer data for each instance */ | 121 | unsigned long last_timer; /* last timer data for each instance */ |
122 | }; | 122 | }; |
123 | 123 | ||
124 | static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | ||
125 | { | ||
126 | struct device *dev = musb->controller; | ||
127 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); | ||
128 | |||
129 | if (timeout == 0) | ||
130 | timeout = jiffies + msecs_to_jiffies(3); | ||
131 | |||
132 | /* Never idle if active, or when VBUS timeout is not set as host */ | ||
133 | if (musb->is_active || (musb->a_wait_bcon == 0 && | ||
134 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | ||
135 | dev_dbg(musb->controller, "%s active, deleting timer\n", | ||
136 | usb_otg_state_string(musb->xceiv->state)); | ||
137 | del_timer(&glue->timer); | ||
138 | glue->last_timer = jiffies; | ||
139 | return; | ||
140 | } | ||
141 | if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE) | ||
142 | return; | ||
143 | |||
144 | if (!musb->g.dev.driver) | ||
145 | return; | ||
146 | |||
147 | if (time_after(glue->last_timer, timeout) && | ||
148 | timer_pending(&glue->timer)) { | ||
149 | dev_dbg(musb->controller, | ||
150 | "Longer idle timer already pending, ignoring...\n"); | ||
151 | return; | ||
152 | } | ||
153 | glue->last_timer = timeout; | ||
154 | |||
155 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | ||
156 | usb_otg_state_string(musb->xceiv->state), | ||
157 | jiffies_to_msecs(timeout - jiffies)); | ||
158 | mod_timer(&glue->timer, timeout); | ||
159 | } | ||
160 | |||
124 | /** | 161 | /** |
125 | * dsps_musb_enable - enable interrupts | 162 | * dsps_musb_enable - enable interrupts |
126 | */ | 163 | */ |
@@ -143,6 +180,7 @@ static void dsps_musb_enable(struct musb *musb) | |||
143 | /* Force the DRVVBUS IRQ so we can start polling for ID change. */ | 180 | /* Force the DRVVBUS IRQ so we can start polling for ID change. */ |
144 | dsps_writel(reg_base, wrp->coreintr_set, | 181 | dsps_writel(reg_base, wrp->coreintr_set, |
145 | (1 << wrp->drvvbus) << wrp->usb_shift); | 182 | (1 << wrp->drvvbus) << wrp->usb_shift); |
183 | dsps_musb_try_idle(musb, 0); | ||
146 | } | 184 | } |
147 | 185 | ||
148 | /** | 186 | /** |
@@ -171,6 +209,7 @@ static void otg_timer(unsigned long _musb) | |||
171 | const struct dsps_musb_wrapper *wrp = glue->wrp; | 209 | const struct dsps_musb_wrapper *wrp = glue->wrp; |
172 | u8 devctl; | 210 | u8 devctl; |
173 | unsigned long flags; | 211 | unsigned long flags; |
212 | int skip_session = 0; | ||
174 | 213 | ||
175 | /* | 214 | /* |
176 | * We poll because DSPS IP's won't expose several OTG-critical | 215 | * We poll because DSPS IP's won't expose several OTG-critical |
@@ -183,10 +222,12 @@ static void otg_timer(unsigned long _musb) | |||
183 | spin_lock_irqsave(&musb->lock, flags); | 222 | spin_lock_irqsave(&musb->lock, flags); |
184 | switch (musb->xceiv->state) { | 223 | switch (musb->xceiv->state) { |
185 | case OTG_STATE_A_WAIT_BCON: | 224 | case OTG_STATE_A_WAIT_BCON: |
186 | devctl &= ~MUSB_DEVCTL_SESSION; | 225 | dsps_writeb(musb->mregs, MUSB_DEVCTL, 0); |
187 | dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 226 | skip_session = 1; |
227 | /* fall */ | ||
188 | 228 | ||
189 | devctl = dsps_readb(musb->mregs, MUSB_DEVCTL); | 229 | case OTG_STATE_A_IDLE: |
230 | case OTG_STATE_B_IDLE: | ||
190 | if (devctl & MUSB_DEVCTL_BDEVICE) { | 231 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
191 | musb->xceiv->state = OTG_STATE_B_IDLE; | 232 | musb->xceiv->state = OTG_STATE_B_IDLE; |
192 | MUSB_DEV_MODE(musb); | 233 | MUSB_DEV_MODE(musb); |
@@ -194,60 +235,21 @@ static void otg_timer(unsigned long _musb) | |||
194 | musb->xceiv->state = OTG_STATE_A_IDLE; | 235 | musb->xceiv->state = OTG_STATE_A_IDLE; |
195 | MUSB_HST_MODE(musb); | 236 | MUSB_HST_MODE(musb); |
196 | } | 237 | } |
238 | if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) | ||
239 | dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); | ||
240 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | ||
197 | break; | 241 | break; |
198 | case OTG_STATE_A_WAIT_VFALL: | 242 | case OTG_STATE_A_WAIT_VFALL: |
199 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 243 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; |
200 | dsps_writel(musb->ctrl_base, wrp->coreintr_set, | 244 | dsps_writel(musb->ctrl_base, wrp->coreintr_set, |
201 | MUSB_INTR_VBUSERROR << wrp->usb_shift); | 245 | MUSB_INTR_VBUSERROR << wrp->usb_shift); |
202 | break; | 246 | break; |
203 | case OTG_STATE_B_IDLE: | ||
204 | devctl = dsps_readb(mregs, MUSB_DEVCTL); | ||
205 | if (devctl & MUSB_DEVCTL_BDEVICE) | ||
206 | mod_timer(&glue->timer, | ||
207 | jiffies + wrp->poll_seconds * HZ); | ||
208 | else | ||
209 | musb->xceiv->state = OTG_STATE_A_IDLE; | ||
210 | break; | ||
211 | default: | 247 | default: |
212 | break; | 248 | break; |
213 | } | 249 | } |
214 | spin_unlock_irqrestore(&musb->lock, flags); | 250 | spin_unlock_irqrestore(&musb->lock, flags); |
215 | } | 251 | } |
216 | 252 | ||
217 | static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | ||
218 | { | ||
219 | struct device *dev = musb->controller; | ||
220 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); | ||
221 | |||
222 | if (timeout == 0) | ||
223 | timeout = jiffies + msecs_to_jiffies(3); | ||
224 | |||
225 | /* Never idle if active, or when VBUS timeout is not set as host */ | ||
226 | if (musb->is_active || (musb->a_wait_bcon == 0 && | ||
227 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | ||
228 | dev_dbg(musb->controller, "%s active, deleting timer\n", | ||
229 | usb_otg_state_string(musb->xceiv->state)); | ||
230 | del_timer(&glue->timer); | ||
231 | glue->last_timer = jiffies; | ||
232 | return; | ||
233 | } | ||
234 | if (musb->port_mode == MUSB_PORT_MODE_HOST) | ||
235 | return; | ||
236 | |||
237 | if (time_after(glue->last_timer, timeout) && | ||
238 | timer_pending(&glue->timer)) { | ||
239 | dev_dbg(musb->controller, | ||
240 | "Longer idle timer already pending, ignoring...\n"); | ||
241 | return; | ||
242 | } | ||
243 | glue->last_timer = timeout; | ||
244 | |||
245 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | ||
246 | usb_otg_state_string(musb->xceiv->state), | ||
247 | jiffies_to_msecs(timeout - jiffies)); | ||
248 | mod_timer(&glue->timer, timeout); | ||
249 | } | ||
250 | |||
251 | static irqreturn_t dsps_interrupt(int irq, void *hci) | 253 | static irqreturn_t dsps_interrupt(int irq, void *hci) |
252 | { | 254 | { |
253 | struct musb *musb = hci; | 255 | struct musb *musb = hci; |
@@ -443,7 +445,7 @@ static int get_musb_port_mode(struct device *dev) | |||
443 | case USB_DR_MODE_OTG: | 445 | case USB_DR_MODE_OTG: |
444 | default: | 446 | default: |
445 | return MUSB_PORT_MODE_DUAL_ROLE; | 447 | return MUSB_PORT_MODE_DUAL_ROLE; |
446 | }; | 448 | } |
447 | } | 449 | } |
448 | 450 | ||
449 | static int dsps_create_musb_pdev(struct dsps_glue *glue, | 451 | static int dsps_create_musb_pdev(struct dsps_glue *glue, |
@@ -631,7 +633,7 @@ static struct platform_driver dsps_usbss_driver = { | |||
631 | .remove = dsps_remove, | 633 | .remove = dsps_remove, |
632 | .driver = { | 634 | .driver = { |
633 | .name = "musb-dsps", | 635 | .name = "musb-dsps", |
634 | .of_match_table = of_match_ptr(musb_dsps_of_match), | 636 | .of_match_table = musb_dsps_of_match, |
635 | }, | 637 | }, |
636 | }; | 638 | }; |
637 | 639 | ||
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 3671898a4535..d2d3a173b315 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -1121,7 +1121,7 @@ static int musb_gadget_enable(struct usb_ep *ep, | |||
1121 | case USB_ENDPOINT_XFER_BULK: s = "bulk"; break; | 1121 | case USB_ENDPOINT_XFER_BULK: s = "bulk"; break; |
1122 | case USB_ENDPOINT_XFER_INT: s = "int"; break; | 1122 | case USB_ENDPOINT_XFER_INT: s = "int"; break; |
1123 | default: s = "iso"; break; | 1123 | default: s = "iso"; break; |
1124 | }; s; }), | 1124 | } s; }), |
1125 | musb_ep->is_in ? "IN" : "OUT", | 1125 | musb_ep->is_in ? "IN" : "OUT", |
1126 | musb_ep->dma ? "dma, " : "", | 1126 | musb_ep->dma ? "dma, " : "", |
1127 | musb_ep->packet_sz); | 1127 | musb_ep->packet_sz); |
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index 9a2b8c85f19a..6582a20bec05 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c | |||
@@ -253,7 +253,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh) | |||
253 | case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break; | 253 | case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break; |
254 | case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break; | 254 | case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break; |
255 | default: s = "-intr"; break; | 255 | default: s = "-intr"; break; |
256 | }; s; }), | 256 | } s; }), |
257 | epnum, buf + offset, len); | 257 | epnum, buf + offset, len); |
258 | 258 | ||
259 | /* Configure endpoint */ | 259 | /* Configure endpoint */ |
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index d1d6b83aabca..9af6bba5eac9 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c | |||
@@ -220,6 +220,23 @@ int musb_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
220 | return retval; | 220 | return retval; |
221 | } | 221 | } |
222 | 222 | ||
223 | static int musb_has_gadget(struct musb *musb) | ||
224 | { | ||
225 | /* | ||
226 | * In host-only mode we start a connection right away. In OTG mode | ||
227 | * we have to wait until we loaded a gadget. We don't really need a | ||
228 | * gadget if we operate as a host but we should not start a session | ||
229 | * as a device without a gadget or else we explode. | ||
230 | */ | ||
231 | #ifdef CONFIG_USB_MUSB_HOST | ||
232 | return 1; | ||
233 | #else | ||
234 | if (musb->port_mode == MUSB_PORT_MODE_HOST) | ||
235 | return 1; | ||
236 | return musb->g.dev.driver != NULL; | ||
237 | #endif | ||
238 | } | ||
239 | |||
223 | int musb_hub_control( | 240 | int musb_hub_control( |
224 | struct usb_hcd *hcd, | 241 | struct usb_hcd *hcd, |
225 | u16 typeReq, | 242 | u16 typeReq, |
@@ -362,7 +379,7 @@ int musb_hub_control( | |||
362 | * initialization logic, e.g. for OTG, or change any | 379 | * initialization logic, e.g. for OTG, or change any |
363 | * logic relating to VBUS power-up. | 380 | * logic relating to VBUS power-up. |
364 | */ | 381 | */ |
365 | if (!hcd->self.is_b_host) | 382 | if (!hcd->self.is_b_host && musb_has_gadget(musb)) |
366 | musb_start(musb); | 383 | musb_start(musb); |
367 | break; | 384 | break; |
368 | case USB_PORT_FEAT_RESET: | 385 | case USB_PORT_FEAT_RESET: |
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 59d2245db1c8..2a408cdaf7b2 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/delay.h> | 38 | #include <linux/delay.h> |
39 | #include <linux/usb/musb-omap.h> | 39 | #include <linux/usb/musb-omap.h> |
40 | #include <linux/usb/omap_control_usb.h> | 40 | #include <linux/usb/omap_control_usb.h> |
41 | #include <linux/of_platform.h> | ||
41 | 42 | ||
42 | #include "musb_core.h" | 43 | #include "musb_core.h" |
43 | #include "omap2430.h" | 44 | #include "omap2430.h" |
@@ -305,6 +306,9 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue) | |||
305 | default: | 306 | default: |
306 | dev_dbg(dev, "ID float\n"); | 307 | dev_dbg(dev, "ID float\n"); |
307 | } | 308 | } |
309 | |||
310 | atomic_notifier_call_chain(&musb->xceiv->notifier, | ||
311 | musb->xceiv->last_event, NULL); | ||
308 | } | 312 | } |
309 | 313 | ||
310 | 314 | ||
@@ -348,11 +352,21 @@ static int omap2430_musb_init(struct musb *musb) | |||
348 | * up through ULPI. TWL4030-family PMICs include one, | 352 | * up through ULPI. TWL4030-family PMICs include one, |
349 | * which needs a driver, drivers aren't always needed. | 353 | * which needs a driver, drivers aren't always needed. |
350 | */ | 354 | */ |
351 | if (dev->parent->of_node) | 355 | if (dev->parent->of_node) { |
356 | musb->phy = devm_phy_get(dev->parent, "usb2-phy"); | ||
357 | |||
358 | /* We can't totally remove musb->xceiv as of now because | ||
359 | * musb core uses xceiv.state and xceiv.otg. Once we have | ||
360 | * a separate state machine to handle otg, these can be moved | ||
361 | * out of xceiv and then we can start using the generic PHY | ||
362 | * framework | ||
363 | */ | ||
352 | musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, | 364 | musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, |
353 | "usb-phy", 0); | 365 | "usb-phy", 0); |
354 | else | 366 | } else { |
355 | musb->xceiv = devm_usb_get_phy_dev(dev, 0); | 367 | musb->xceiv = devm_usb_get_phy_dev(dev, 0); |
368 | musb->phy = devm_phy_get(dev, "usb"); | ||
369 | } | ||
356 | 370 | ||
357 | if (IS_ERR(musb->xceiv)) { | 371 | if (IS_ERR(musb->xceiv)) { |
358 | status = PTR_ERR(musb->xceiv); | 372 | status = PTR_ERR(musb->xceiv); |
@@ -364,6 +378,10 @@ static int omap2430_musb_init(struct musb *musb) | |||
364 | return -EPROBE_DEFER; | 378 | return -EPROBE_DEFER; |
365 | } | 379 | } |
366 | 380 | ||
381 | if (IS_ERR(musb->phy)) { | ||
382 | pr_err("HS USB OTG: no PHY configured\n"); | ||
383 | return PTR_ERR(musb->phy); | ||
384 | } | ||
367 | musb->isr = omap2430_musb_interrupt; | 385 | musb->isr = omap2430_musb_interrupt; |
368 | 386 | ||
369 | status = pm_runtime_get_sync(dev); | 387 | status = pm_runtime_get_sync(dev); |
@@ -397,7 +415,7 @@ static int omap2430_musb_init(struct musb *musb) | |||
397 | if (glue->status != OMAP_MUSB_UNKNOWN) | 415 | if (glue->status != OMAP_MUSB_UNKNOWN) |
398 | omap_musb_set_mailbox(glue); | 416 | omap_musb_set_mailbox(glue); |
399 | 417 | ||
400 | usb_phy_init(musb->xceiv); | 418 | phy_init(musb->phy); |
401 | 419 | ||
402 | pm_runtime_put_noidle(musb->controller); | 420 | pm_runtime_put_noidle(musb->controller); |
403 | return 0; | 421 | return 0; |
@@ -460,6 +478,7 @@ static int omap2430_musb_exit(struct musb *musb) | |||
460 | del_timer_sync(&musb_idle_timer); | 478 | del_timer_sync(&musb_idle_timer); |
461 | 479 | ||
462 | omap2430_low_level_exit(musb); | 480 | omap2430_low_level_exit(musb); |
481 | phy_exit(musb->phy); | ||
463 | 482 | ||
464 | return 0; | 483 | return 0; |
465 | } | 484 | } |
@@ -509,8 +528,12 @@ static int omap2430_probe(struct platform_device *pdev) | |||
509 | glue->dev = &pdev->dev; | 528 | glue->dev = &pdev->dev; |
510 | glue->musb = musb; | 529 | glue->musb = musb; |
511 | glue->status = OMAP_MUSB_UNKNOWN; | 530 | glue->status = OMAP_MUSB_UNKNOWN; |
531 | glue->control_otghs = ERR_PTR(-ENODEV); | ||
512 | 532 | ||
513 | if (np) { | 533 | if (np) { |
534 | struct device_node *control_node; | ||
535 | struct platform_device *control_pdev; | ||
536 | |||
514 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | 537 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
515 | if (!pdata) { | 538 | if (!pdata) { |
516 | dev_err(&pdev->dev, | 539 | dev_err(&pdev->dev, |
@@ -539,22 +562,20 @@ static int omap2430_probe(struct platform_device *pdev) | |||
539 | of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); | 562 | of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); |
540 | of_property_read_u32(np, "power", (u32 *)&pdata->power); | 563 | of_property_read_u32(np, "power", (u32 *)&pdata->power); |
541 | config->multipoint = of_property_read_bool(np, "multipoint"); | 564 | config->multipoint = of_property_read_bool(np, "multipoint"); |
542 | pdata->has_mailbox = of_property_read_bool(np, | ||
543 | "ti,has-mailbox"); | ||
544 | 565 | ||
545 | pdata->board_data = data; | 566 | pdata->board_data = data; |
546 | pdata->config = config; | 567 | pdata->config = config; |
547 | } | ||
548 | 568 | ||
549 | if (pdata->has_mailbox) { | 569 | control_node = of_parse_phandle(np, "ctrl-module", 0); |
550 | glue->control_otghs = omap_get_control_dev(); | 570 | if (control_node) { |
551 | if (IS_ERR(glue->control_otghs)) { | 571 | control_pdev = of_find_device_by_node(control_node); |
552 | dev_vdbg(&pdev->dev, "Failed to get control device\n"); | 572 | if (!control_pdev) { |
553 | ret = PTR_ERR(glue->control_otghs); | 573 | dev_err(&pdev->dev, "Failed to get control device\n"); |
554 | goto err2; | 574 | ret = -EINVAL; |
575 | goto err2; | ||
576 | } | ||
577 | glue->control_otghs = &control_pdev->dev; | ||
555 | } | 578 | } |
556 | } else { | ||
557 | glue->control_otghs = ERR_PTR(-ENODEV); | ||
558 | } | 579 | } |
559 | pdata->platform_ops = &omap2430_ops; | 580 | pdata->platform_ops = &omap2430_ops; |
560 | 581 | ||
@@ -638,7 +659,7 @@ static int omap2430_runtime_suspend(struct device *dev) | |||
638 | OTG_INTERFSEL); | 659 | OTG_INTERFSEL); |
639 | 660 | ||
640 | omap2430_low_level_exit(musb); | 661 | omap2430_low_level_exit(musb); |
641 | usb_phy_set_suspend(musb->xceiv, 1); | 662 | phy_power_off(musb->phy); |
642 | } | 663 | } |
643 | 664 | ||
644 | return 0; | 665 | return 0; |
@@ -653,8 +674,7 @@ static int omap2430_runtime_resume(struct device *dev) | |||
653 | omap2430_low_level_init(musb); | 674 | omap2430_low_level_init(musb); |
654 | musb_writel(musb->mregs, OTG_INTERFSEL, | 675 | musb_writel(musb->mregs, OTG_INTERFSEL, |
655 | musb->context.otg_interfsel); | 676 | musb->context.otg_interfsel); |
656 | 677 | phy_power_on(musb->phy); | |
657 | usb_phy_set_suspend(musb->xceiv, 0); | ||
658 | } | 678 | } |
659 | 679 | ||
660 | return 0; | 680 | return 0; |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index b3b3ed723882..4432314d70ee 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -1152,7 +1152,11 @@ static const struct musb_platform_ops tusb_ops = { | |||
1152 | .set_vbus = tusb_musb_set_vbus, | 1152 | .set_vbus = tusb_musb_set_vbus, |
1153 | }; | 1153 | }; |
1154 | 1154 | ||
1155 | static u64 tusb_dmamask = DMA_BIT_MASK(32); | 1155 | static const struct platform_device_info tusb_dev_info = { |
1156 | .name = "musb-hdrc", | ||
1157 | .id = PLATFORM_DEVID_AUTO, | ||
1158 | .dma_mask = DMA_BIT_MASK(32), | ||
1159 | }; | ||
1156 | 1160 | ||
1157 | static int tusb_probe(struct platform_device *pdev) | 1161 | static int tusb_probe(struct platform_device *pdev) |
1158 | { | 1162 | { |
@@ -1160,7 +1164,7 @@ static int tusb_probe(struct platform_device *pdev) | |||
1160 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); | 1164 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
1161 | struct platform_device *musb; | 1165 | struct platform_device *musb; |
1162 | struct tusb6010_glue *glue; | 1166 | struct tusb6010_glue *glue; |
1163 | 1167 | struct platform_device_info pinfo; | |
1164 | int ret = -ENOMEM; | 1168 | int ret = -ENOMEM; |
1165 | 1169 | ||
1166 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 1170 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); |
@@ -1169,18 +1173,7 @@ static int tusb_probe(struct platform_device *pdev) | |||
1169 | goto err0; | 1173 | goto err0; |
1170 | } | 1174 | } |
1171 | 1175 | ||
1172 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | ||
1173 | if (!musb) { | ||
1174 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | ||
1175 | goto err1; | ||
1176 | } | ||
1177 | |||
1178 | musb->dev.parent = &pdev->dev; | ||
1179 | musb->dev.dma_mask = &tusb_dmamask; | ||
1180 | musb->dev.coherent_dma_mask = tusb_dmamask; | ||
1181 | |||
1182 | glue->dev = &pdev->dev; | 1176 | glue->dev = &pdev->dev; |
1183 | glue->musb = musb; | ||
1184 | 1177 | ||
1185 | pdata->platform_ops = &tusb_ops; | 1178 | pdata->platform_ops = &tusb_ops; |
1186 | 1179 | ||
@@ -1204,31 +1197,23 @@ static int tusb_probe(struct platform_device *pdev) | |||
1204 | musb_resources[2].end = pdev->resource[2].end; | 1197 | musb_resources[2].end = pdev->resource[2].end; |
1205 | musb_resources[2].flags = pdev->resource[2].flags; | 1198 | musb_resources[2].flags = pdev->resource[2].flags; |
1206 | 1199 | ||
1207 | ret = platform_device_add_resources(musb, musb_resources, | 1200 | pinfo = tusb_dev_info; |
1208 | ARRAY_SIZE(musb_resources)); | 1201 | pinfo.parent = &pdev->dev; |
1209 | if (ret) { | 1202 | pinfo.res = musb_resources; |
1210 | dev_err(&pdev->dev, "failed to add resources\n"); | 1203 | pinfo.num_res = ARRAY_SIZE(musb_resources); |
1211 | goto err3; | 1204 | pinfo.data = pdata; |
1212 | } | 1205 | pinfo.size_data = sizeof(*pdata); |
1213 | 1206 | ||
1214 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 1207 | glue->musb = musb = platform_device_register_full(&pinfo); |
1215 | if (ret) { | 1208 | if (IS_ERR(musb)) { |
1216 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 1209 | ret = PTR_ERR(musb); |
1217 | goto err3; | 1210 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
1218 | } | ||
1219 | |||
1220 | ret = platform_device_add(musb); | ||
1221 | if (ret) { | ||
1222 | dev_err(&pdev->dev, "failed to register musb device\n"); | ||
1223 | goto err3; | 1211 | goto err3; |
1224 | } | 1212 | } |
1225 | 1213 | ||
1226 | return 0; | 1214 | return 0; |
1227 | 1215 | ||
1228 | err3: | 1216 | err3: |
1229 | platform_device_put(musb); | ||
1230 | |||
1231 | err1: | ||
1232 | kfree(glue); | 1217 | kfree(glue); |
1233 | 1218 | ||
1234 | err0: | 1219 | err0: |
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c index 59256b12f746..f483d1924c28 100644 --- a/drivers/usb/musb/ux500.c +++ b/drivers/usb/musb/ux500.c | |||
@@ -376,17 +376,10 @@ static int ux500_resume(struct device *dev) | |||
376 | 376 | ||
377 | return 0; | 377 | return 0; |
378 | } | 378 | } |
379 | |||
380 | static const struct dev_pm_ops ux500_pm_ops = { | ||
381 | .suspend = ux500_suspend, | ||
382 | .resume = ux500_resume, | ||
383 | }; | ||
384 | |||
385 | #define DEV_PM_OPS (&ux500_pm_ops) | ||
386 | #else | ||
387 | #define DEV_PM_OPS NULL | ||
388 | #endif | 379 | #endif |
389 | 380 | ||
381 | static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume); | ||
382 | |||
390 | static const struct of_device_id ux500_match[] = { | 383 | static const struct of_device_id ux500_match[] = { |
391 | { .compatible = "stericsson,db8500-musb", }, | 384 | { .compatible = "stericsson,db8500-musb", }, |
392 | {} | 385 | {} |
@@ -397,7 +390,7 @@ static struct platform_driver ux500_driver = { | |||
397 | .remove = ux500_remove, | 390 | .remove = ux500_remove, |
398 | .driver = { | 391 | .driver = { |
399 | .name = "musb-ux500", | 392 | .name = "musb-ux500", |
400 | .pm = DEV_PM_OPS, | 393 | .pm = &ux500_pm_ops, |
401 | .of_match_table = ux500_match, | 394 | .of_match_table = ux500_match, |
402 | }, | 395 | }, |
403 | }; | 396 | }; |
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index d5589f9c60a9..08e2f39027ec 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig | |||
@@ -66,17 +66,6 @@ config OMAP_CONTROL_USB | |||
66 | power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an | 66 | power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an |
67 | additional register to power on USB3 PHY. | 67 | additional register to power on USB3 PHY. |
68 | 68 | ||
69 | config OMAP_USB2 | ||
70 | tristate "OMAP USB2 PHY Driver" | ||
71 | depends on ARCH_OMAP2PLUS | ||
72 | select OMAP_CONTROL_USB | ||
73 | select USB_PHY | ||
74 | help | ||
75 | Enable this to support the transceiver that is part of SOC. This | ||
76 | driver takes care of all the PHY functionality apart from comparator. | ||
77 | The USB OTG controller communicates with the comparator using this | ||
78 | driver. | ||
79 | |||
80 | config OMAP_USB3 | 69 | config OMAP_USB3 |
81 | tristate "OMAP USB3 PHY Driver" | 70 | tristate "OMAP USB3 PHY Driver" |
82 | depends on ARCH_OMAP2PLUS || COMPILE_TEST | 71 | depends on ARCH_OMAP2PLUS || COMPILE_TEST |
@@ -93,6 +82,7 @@ config AM335X_CONTROL_USB | |||
93 | 82 | ||
94 | config AM335X_PHY_USB | 83 | config AM335X_PHY_USB |
95 | tristate "AM335x USB PHY Driver" | 84 | tristate "AM335x USB PHY Driver" |
85 | depends on ARM || COMPILE_TEST | ||
96 | select USB_PHY | 86 | select USB_PHY |
97 | select AM335X_CONTROL_USB | 87 | select AM335X_CONTROL_USB |
98 | select NOP_USB_XCEIV | 88 | select NOP_USB_XCEIV |
@@ -123,16 +113,6 @@ config SAMSUNG_USB3PHY | |||
123 | Enable this to support Samsung USB 3.0 (Super Speed) phy controller | 113 | Enable this to support Samsung USB 3.0 (Super Speed) phy controller |
124 | for samsung SoCs. | 114 | for samsung SoCs. |
125 | 115 | ||
126 | config TWL4030_USB | ||
127 | tristate "TWL4030 USB Transceiver Driver" | ||
128 | depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS | ||
129 | select USB_PHY | ||
130 | help | ||
131 | Enable this to support the USB OTG transceiver on TWL4030 | ||
132 | family chips (including the TWL5030 and TPS659x0 devices). | ||
133 | This transceiver supports high and full speed devices plus, | ||
134 | in host mode, low speed. | ||
135 | |||
136 | config TWL6030_USB | 116 | config TWL6030_USB |
137 | tristate "TWL6030 USB Transceiver Driver" | 117 | tristate "TWL6030 USB Transceiver Driver" |
138 | depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS | 118 | depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS |
@@ -214,6 +194,19 @@ config USB_RCAR_PHY | |||
214 | To compile this driver as a module, choose M here: the | 194 | To compile this driver as a module, choose M here: the |
215 | module will be called phy-rcar-usb. | 195 | module will be called phy-rcar-usb. |
216 | 196 | ||
197 | config USB_RCAR_GEN2_PHY | ||
198 | tristate "Renesas R-Car Gen2 USB PHY support" | ||
199 | depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST | ||
200 | select USB_PHY | ||
201 | help | ||
202 | Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver. | ||
203 | It is typically used to control internal USB PHY for USBHS, | ||
204 | and to configure shared USB channels 0 and 2. | ||
205 | This driver supports R8A7790 and R8A7791. | ||
206 | |||
207 | To compile this driver as a module, choose M here: the | ||
208 | module will be called phy-rcar-gen2-usb. | ||
209 | |||
217 | config USB_ULPI | 210 | config USB_ULPI |
218 | bool "Generic ULPI Transceiver Driver" | 211 | bool "Generic ULPI Transceiver Driver" |
219 | depends on ARM | 212 | depends on ARM |
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 2135e85f46ed..022c1da7fb78 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile | |||
@@ -15,12 +15,10 @@ obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o | |||
15 | obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o | 15 | obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o |
16 | obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o | 16 | obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o |
17 | obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o | 17 | obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o |
18 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o | ||
19 | obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o | 18 | obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o |
20 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o | 19 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o |
21 | obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o | 20 | obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o |
22 | obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o | 21 | obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o |
23 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o | ||
24 | obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o | 22 | obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o |
25 | obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o | 23 | obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o |
26 | obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o | 24 | obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o |
@@ -29,5 +27,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o | |||
29 | obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o | 27 | obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o |
30 | obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o | 28 | obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o |
31 | obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o | 29 | obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o |
30 | obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o | ||
32 | obj-$(CONFIG_USB_ULPI) += phy-ulpi.o | 31 | obj-$(CONFIG_USB_ULPI) += phy-ulpi.o |
33 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o | 32 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o |
diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c index 22cf07d62e4c..634f49acd20e 100644 --- a/drivers/usb/phy/phy-am335x-control.c +++ b/drivers/usb/phy/phy-am335x-control.c | |||
@@ -26,6 +26,41 @@ struct am335x_control_usb { | |||
26 | #define USBPHY_OTGVDET_EN (1 << 19) | 26 | #define USBPHY_OTGVDET_EN (1 << 19) |
27 | #define USBPHY_OTGSESSEND_EN (1 << 20) | 27 | #define USBPHY_OTGSESSEND_EN (1 << 20) |
28 | 28 | ||
29 | #define AM335X_PHY0_WK_EN (1 << 0) | ||
30 | #define AM335X_PHY1_WK_EN (1 << 8) | ||
31 | |||
32 | static void am335x_phy_wkup(struct phy_control *phy_ctrl, u32 id, bool on) | ||
33 | { | ||
34 | struct am335x_control_usb *usb_ctrl; | ||
35 | u32 val; | ||
36 | u32 reg; | ||
37 | |||
38 | usb_ctrl = container_of(phy_ctrl, struct am335x_control_usb, phy_ctrl); | ||
39 | |||
40 | switch (id) { | ||
41 | case 0: | ||
42 | reg = AM335X_PHY0_WK_EN; | ||
43 | break; | ||
44 | case 1: | ||
45 | reg = AM335X_PHY1_WK_EN; | ||
46 | break; | ||
47 | default: | ||
48 | WARN_ON(1); | ||
49 | return; | ||
50 | } | ||
51 | |||
52 | spin_lock(&usb_ctrl->lock); | ||
53 | val = readl(usb_ctrl->wkup); | ||
54 | |||
55 | if (on) | ||
56 | val |= reg; | ||
57 | else | ||
58 | val &= ~reg; | ||
59 | |||
60 | writel(val, usb_ctrl->wkup); | ||
61 | spin_unlock(&usb_ctrl->lock); | ||
62 | } | ||
63 | |||
29 | static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) | 64 | static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) |
30 | { | 65 | { |
31 | struct am335x_control_usb *usb_ctrl; | 66 | struct am335x_control_usb *usb_ctrl; |
@@ -59,6 +94,7 @@ static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) | |||
59 | 94 | ||
60 | static const struct phy_control ctrl_am335x = { | 95 | static const struct phy_control ctrl_am335x = { |
61 | .phy_power = am335x_phy_power, | 96 | .phy_power = am335x_phy_power, |
97 | .phy_wkup = am335x_phy_wkup, | ||
62 | }; | 98 | }; |
63 | 99 | ||
64 | static const struct of_device_id omap_control_usb_id_table[] = { | 100 | static const struct of_device_id omap_control_usb_id_table[] = { |
@@ -117,6 +153,12 @@ static int am335x_control_usb_probe(struct platform_device *pdev) | |||
117 | ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res); | 153 | ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res); |
118 | if (IS_ERR(ctrl_usb->phy_reg)) | 154 | if (IS_ERR(ctrl_usb->phy_reg)) |
119 | return PTR_ERR(ctrl_usb->phy_reg); | 155 | return PTR_ERR(ctrl_usb->phy_reg); |
156 | |||
157 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wakeup"); | ||
158 | ctrl_usb->wkup = devm_ioremap_resource(&pdev->dev, res); | ||
159 | if (IS_ERR(ctrl_usb->wkup)) | ||
160 | return PTR_ERR(ctrl_usb->wkup); | ||
161 | |||
120 | spin_lock_init(&ctrl_usb->lock); | 162 | spin_lock_init(&ctrl_usb->lock); |
121 | ctrl_usb->phy_ctrl = *phy_ctrl; | 163 | ctrl_usb->phy_ctrl = *phy_ctrl; |
122 | 164 | ||
@@ -129,7 +171,7 @@ static struct platform_driver am335x_control_driver = { | |||
129 | .driver = { | 171 | .driver = { |
130 | .name = "am335x-control-usb", | 172 | .name = "am335x-control-usb", |
131 | .owner = THIS_MODULE, | 173 | .owner = THIS_MODULE, |
132 | .of_match_table = of_match_ptr(omap_control_usb_id_table), | 174 | .of_match_table = omap_control_usb_id_table, |
133 | }, | 175 | }, |
134 | }; | 176 | }; |
135 | 177 | ||
diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c index c4d614d1f173..6370e50649d7 100644 --- a/drivers/usb/phy/phy-am335x.c +++ b/drivers/usb/phy/phy-am335x.c | |||
@@ -53,21 +53,20 @@ static int am335x_phy_probe(struct platform_device *pdev) | |||
53 | } | 53 | } |
54 | 54 | ||
55 | ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, | 55 | ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, |
56 | USB_PHY_TYPE_USB2, 0, false, false); | 56 | USB_PHY_TYPE_USB2, 0, false); |
57 | if (ret) | 57 | if (ret) |
58 | return ret; | 58 | return ret; |
59 | 59 | ||
60 | ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); | 60 | ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); |
61 | if (ret) | 61 | if (ret) |
62 | goto err_add; | 62 | return ret; |
63 | am_phy->usb_phy_gen.phy.init = am335x_init; | 63 | am_phy->usb_phy_gen.phy.init = am335x_init; |
64 | am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; | 64 | am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; |
65 | 65 | ||
66 | platform_set_drvdata(pdev, am_phy); | 66 | platform_set_drvdata(pdev, am_phy); |
67 | |||
67 | return 0; | 68 | return 0; |
68 | 69 | ||
69 | err_add: | ||
70 | usb_phy_gen_cleanup_phy(&am_phy->usb_phy_gen); | ||
71 | return ret; | 70 | return ret; |
72 | } | 71 | } |
73 | 72 | ||
@@ -79,6 +78,40 @@ static int am335x_phy_remove(struct platform_device *pdev) | |||
79 | return 0; | 78 | return 0; |
80 | } | 79 | } |
81 | 80 | ||
81 | #ifdef CONFIG_PM_RUNTIME | ||
82 | |||
83 | static int am335x_phy_runtime_suspend(struct device *dev) | ||
84 | { | ||
85 | struct platform_device *pdev = to_platform_device(dev); | ||
86 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | ||
87 | |||
88 | if (device_may_wakeup(dev)) | ||
89 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); | ||
90 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); | ||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | static int am335x_phy_runtime_resume(struct device *dev) | ||
95 | { | ||
96 | struct platform_device *pdev = to_platform_device(dev); | ||
97 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | ||
98 | |||
99 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); | ||
100 | if (device_may_wakeup(dev)) | ||
101 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static const struct dev_pm_ops am335x_pm_ops = { | ||
106 | SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend, | ||
107 | am335x_phy_runtime_resume, NULL) | ||
108 | }; | ||
109 | |||
110 | #define DEV_PM_OPS (&am335x_pm_ops) | ||
111 | #else | ||
112 | #define DEV_PM_OPS NULL | ||
113 | #endif | ||
114 | |||
82 | static const struct of_device_id am335x_phy_ids[] = { | 115 | static const struct of_device_id am335x_phy_ids[] = { |
83 | { .compatible = "ti,am335x-usb-phy" }, | 116 | { .compatible = "ti,am335x-usb-phy" }, |
84 | { } | 117 | { } |
@@ -91,7 +124,8 @@ static struct platform_driver am335x_phy_driver = { | |||
91 | .driver = { | 124 | .driver = { |
92 | .name = "am335x-phy-driver", | 125 | .name = "am335x-phy-driver", |
93 | .owner = THIS_MODULE, | 126 | .owner = THIS_MODULE, |
94 | .of_match_table = of_match_ptr(am335x_phy_ids), | 127 | .pm = DEV_PM_OPS, |
128 | .of_match_table = am335x_phy_ids, | ||
95 | }, | 129 | }, |
96 | }; | 130 | }; |
97 | 131 | ||
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c index fa7c9f9628b5..7f3c73b967ce 100644 --- a/drivers/usb/phy/phy-fsl-usb.c +++ b/drivers/usb/phy/phy-fsl-usb.c | |||
@@ -134,7 +134,7 @@ int write_ulpi(u8 addr, u8 data) | |||
134 | /* Operations that will be called from OTG Finite State Machine */ | 134 | /* Operations that will be called from OTG Finite State Machine */ |
135 | 135 | ||
136 | /* Charge vbus for vbus pulsing in SRP */ | 136 | /* Charge vbus for vbus pulsing in SRP */ |
137 | void fsl_otg_chrg_vbus(int on) | 137 | void fsl_otg_chrg_vbus(struct otg_fsm *fsm, int on) |
138 | { | 138 | { |
139 | u32 tmp; | 139 | u32 tmp; |
140 | 140 | ||
@@ -170,7 +170,7 @@ void fsl_otg_dischrg_vbus(int on) | |||
170 | } | 170 | } |
171 | 171 | ||
172 | /* A-device driver vbus, controlled through PP bit in PORTSC */ | 172 | /* A-device driver vbus, controlled through PP bit in PORTSC */ |
173 | void fsl_otg_drv_vbus(int on) | 173 | void fsl_otg_drv_vbus(struct otg_fsm *fsm, int on) |
174 | { | 174 | { |
175 | u32 tmp; | 175 | u32 tmp; |
176 | 176 | ||
@@ -188,7 +188,7 @@ void fsl_otg_drv_vbus(int on) | |||
188 | * Pull-up D+, signalling connect by periperal. Also used in | 188 | * Pull-up D+, signalling connect by periperal. Also used in |
189 | * data-line pulsing in SRP | 189 | * data-line pulsing in SRP |
190 | */ | 190 | */ |
191 | void fsl_otg_loc_conn(int on) | 191 | void fsl_otg_loc_conn(struct otg_fsm *fsm, int on) |
192 | { | 192 | { |
193 | u32 tmp; | 193 | u32 tmp; |
194 | 194 | ||
@@ -207,7 +207,7 @@ void fsl_otg_loc_conn(int on) | |||
207 | * port. In host mode, controller will automatically send SOF. | 207 | * port. In host mode, controller will automatically send SOF. |
208 | * Suspend will block the data on the port. | 208 | * Suspend will block the data on the port. |
209 | */ | 209 | */ |
210 | void fsl_otg_loc_sof(int on) | 210 | void fsl_otg_loc_sof(struct otg_fsm *fsm, int on) |
211 | { | 211 | { |
212 | u32 tmp; | 212 | u32 tmp; |
213 | 213 | ||
@@ -222,7 +222,7 @@ void fsl_otg_loc_sof(int on) | |||
222 | } | 222 | } |
223 | 223 | ||
224 | /* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */ | 224 | /* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */ |
225 | void fsl_otg_start_pulse(void) | 225 | void fsl_otg_start_pulse(struct otg_fsm *fsm) |
226 | { | 226 | { |
227 | u32 tmp; | 227 | u32 tmp; |
228 | 228 | ||
@@ -235,7 +235,7 @@ void fsl_otg_start_pulse(void) | |||
235 | fsl_otg_loc_conn(1); | 235 | fsl_otg_loc_conn(1); |
236 | #endif | 236 | #endif |
237 | 237 | ||
238 | fsl_otg_add_timer(b_data_pulse_tmr); | 238 | fsl_otg_add_timer(fsm, b_data_pulse_tmr); |
239 | } | 239 | } |
240 | 240 | ||
241 | void b_data_pulse_end(unsigned long foo) | 241 | void b_data_pulse_end(unsigned long foo) |
@@ -252,14 +252,14 @@ void b_data_pulse_end(unsigned long foo) | |||
252 | void fsl_otg_pulse_vbus(void) | 252 | void fsl_otg_pulse_vbus(void) |
253 | { | 253 | { |
254 | srp_wait_done = 0; | 254 | srp_wait_done = 0; |
255 | fsl_otg_chrg_vbus(1); | 255 | fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 1); |
256 | /* start the timer to end vbus charge */ | 256 | /* start the timer to end vbus charge */ |
257 | fsl_otg_add_timer(b_vbus_pulse_tmr); | 257 | fsl_otg_add_timer(&fsl_otg_dev->fsm, b_vbus_pulse_tmr); |
258 | } | 258 | } |
259 | 259 | ||
260 | void b_vbus_pulse_end(unsigned long foo) | 260 | void b_vbus_pulse_end(unsigned long foo) |
261 | { | 261 | { |
262 | fsl_otg_chrg_vbus(0); | 262 | fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 0); |
263 | 263 | ||
264 | /* | 264 | /* |
265 | * As USB3300 using the same a_sess_vld and b_sess_vld voltage | 265 | * As USB3300 using the same a_sess_vld and b_sess_vld voltage |
@@ -267,7 +267,7 @@ void b_vbus_pulse_end(unsigned long foo) | |||
267 | * residual voltage of vbus pulsing and A device pull up | 267 | * residual voltage of vbus pulsing and A device pull up |
268 | */ | 268 | */ |
269 | fsl_otg_dischrg_vbus(1); | 269 | fsl_otg_dischrg_vbus(1); |
270 | fsl_otg_add_timer(b_srp_wait_tmr); | 270 | fsl_otg_add_timer(&fsl_otg_dev->fsm, b_srp_wait_tmr); |
271 | } | 271 | } |
272 | 272 | ||
273 | void b_srp_end(unsigned long foo) | 273 | void b_srp_end(unsigned long foo) |
@@ -289,7 +289,7 @@ void a_wait_enum(unsigned long foo) | |||
289 | { | 289 | { |
290 | VDBG("a_wait_enum timeout\n"); | 290 | VDBG("a_wait_enum timeout\n"); |
291 | if (!fsl_otg_dev->phy.otg->host->b_hnp_enable) | 291 | if (!fsl_otg_dev->phy.otg->host->b_hnp_enable) |
292 | fsl_otg_add_timer(a_wait_enum_tmr); | 292 | fsl_otg_add_timer(&fsl_otg_dev->fsm, a_wait_enum_tmr); |
293 | else | 293 | else |
294 | otg_statemachine(&fsl_otg_dev->fsm); | 294 | otg_statemachine(&fsl_otg_dev->fsm); |
295 | } | 295 | } |
@@ -375,8 +375,42 @@ void fsl_otg_uninit_timers(void) | |||
375 | kfree(b_vbus_pulse_tmr); | 375 | kfree(b_vbus_pulse_tmr); |
376 | } | 376 | } |
377 | 377 | ||
378 | static struct fsl_otg_timer *fsl_otg_get_timer(enum otg_fsm_timer t) | ||
379 | { | ||
380 | struct fsl_otg_timer *timer; | ||
381 | |||
382 | /* REVISIT: use array of pointers to timers instead */ | ||
383 | switch (t) { | ||
384 | case A_WAIT_VRISE: | ||
385 | timer = a_wait_vrise_tmr; | ||
386 | break; | ||
387 | case A_WAIT_BCON: | ||
388 | timer = a_wait_vrise_tmr; | ||
389 | break; | ||
390 | case A_AIDL_BDIS: | ||
391 | timer = a_wait_vrise_tmr; | ||
392 | break; | ||
393 | case B_ASE0_BRST: | ||
394 | timer = a_wait_vrise_tmr; | ||
395 | break; | ||
396 | case B_SE0_SRP: | ||
397 | timer = a_wait_vrise_tmr; | ||
398 | break; | ||
399 | case B_SRP_FAIL: | ||
400 | timer = a_wait_vrise_tmr; | ||
401 | break; | ||
402 | case A_WAIT_ENUM: | ||
403 | timer = a_wait_vrise_tmr; | ||
404 | break; | ||
405 | default: | ||
406 | timer = NULL; | ||
407 | } | ||
408 | |||
409 | return timer; | ||
410 | } | ||
411 | |||
378 | /* Add timer to timer list */ | 412 | /* Add timer to timer list */ |
379 | void fsl_otg_add_timer(void *gtimer) | 413 | void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer) |
380 | { | 414 | { |
381 | struct fsl_otg_timer *timer = gtimer; | 415 | struct fsl_otg_timer *timer = gtimer; |
382 | struct fsl_otg_timer *tmp_timer; | 416 | struct fsl_otg_timer *tmp_timer; |
@@ -394,8 +428,19 @@ void fsl_otg_add_timer(void *gtimer) | |||
394 | list_add_tail(&timer->list, &active_timers); | 428 | list_add_tail(&timer->list, &active_timers); |
395 | } | 429 | } |
396 | 430 | ||
431 | static void fsl_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) | ||
432 | { | ||
433 | struct fsl_otg_timer *timer; | ||
434 | |||
435 | timer = fsl_otg_get_timer(t); | ||
436 | if (!timer) | ||
437 | return; | ||
438 | |||
439 | fsl_otg_add_timer(fsm, timer); | ||
440 | } | ||
441 | |||
397 | /* Remove timer from the timer list; clear timeout status */ | 442 | /* Remove timer from the timer list; clear timeout status */ |
398 | void fsl_otg_del_timer(void *gtimer) | 443 | void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer) |
399 | { | 444 | { |
400 | struct fsl_otg_timer *timer = gtimer; | 445 | struct fsl_otg_timer *timer = gtimer; |
401 | struct fsl_otg_timer *tmp_timer, *del_tmp; | 446 | struct fsl_otg_timer *tmp_timer, *del_tmp; |
@@ -405,6 +450,17 @@ void fsl_otg_del_timer(void *gtimer) | |||
405 | list_del(&timer->list); | 450 | list_del(&timer->list); |
406 | } | 451 | } |
407 | 452 | ||
453 | static void fsl_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) | ||
454 | { | ||
455 | struct fsl_otg_timer *timer; | ||
456 | |||
457 | timer = fsl_otg_get_timer(t); | ||
458 | if (!timer) | ||
459 | return; | ||
460 | |||
461 | fsl_otg_del_timer(fsm, timer); | ||
462 | } | ||
463 | |||
408 | /* | 464 | /* |
409 | * Reduce timer count by 1, and find timeout conditions. | 465 | * Reduce timer count by 1, and find timeout conditions. |
410 | * Called by fsl_otg 1ms timer interrupt | 466 | * Called by fsl_otg 1ms timer interrupt |
@@ -468,7 +524,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) | |||
468 | retval = dev->driver->pm->resume(dev); | 524 | retval = dev->driver->pm->resume(dev); |
469 | if (fsm->id) { | 525 | if (fsm->id) { |
470 | /* default-b */ | 526 | /* default-b */ |
471 | fsl_otg_drv_vbus(1); | 527 | fsl_otg_drv_vbus(fsm, 1); |
472 | /* | 528 | /* |
473 | * Workaround: b_host can't driver | 529 | * Workaround: b_host can't driver |
474 | * vbus, but PP in PORTSC needs to | 530 | * vbus, but PP in PORTSC needs to |
@@ -493,7 +549,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) | |||
493 | retval = dev->driver->pm->suspend(dev); | 549 | retval = dev->driver->pm->suspend(dev); |
494 | if (fsm->id) | 550 | if (fsm->id) |
495 | /* default-b */ | 551 | /* default-b */ |
496 | fsl_otg_drv_vbus(0); | 552 | fsl_otg_drv_vbus(fsm, 0); |
497 | } | 553 | } |
498 | otg_dev->host_working = 0; | 554 | otg_dev->host_working = 0; |
499 | } | 555 | } |
@@ -757,8 +813,8 @@ static struct otg_fsm_ops fsl_otg_ops = { | |||
757 | .loc_sof = fsl_otg_loc_sof, | 813 | .loc_sof = fsl_otg_loc_sof, |
758 | .start_pulse = fsl_otg_start_pulse, | 814 | .start_pulse = fsl_otg_start_pulse, |
759 | 815 | ||
760 | .add_timer = fsl_otg_add_timer, | 816 | .add_timer = fsl_otg_fsm_add_timer, |
761 | .del_timer = fsl_otg_del_timer, | 817 | .del_timer = fsl_otg_fsm_del_timer, |
762 | 818 | ||
763 | .start_host = fsl_otg_start_host, | 819 | .start_host = fsl_otg_start_host, |
764 | .start_gadget = fsl_otg_start_gadget, | 820 | .start_gadget = fsl_otg_start_gadget, |
@@ -1011,7 +1067,7 @@ static int show_fsl_usb2_otg_state(struct device *dev, | |||
1011 | "b_bus_suspend: %d\n" | 1067 | "b_bus_suspend: %d\n" |
1012 | "b_conn: %d\n" | 1068 | "b_conn: %d\n" |
1013 | "b_se0_srp: %d\n" | 1069 | "b_se0_srp: %d\n" |
1014 | "b_sess_end: %d\n" | 1070 | "b_ssend_srp: %d\n" |
1015 | "b_sess_vld: %d\n" | 1071 | "b_sess_vld: %d\n" |
1016 | "id: %d\n", | 1072 | "id: %d\n", |
1017 | fsm->a_bus_req, | 1073 | fsm->a_bus_req, |
@@ -1026,7 +1082,7 @@ static int show_fsl_usb2_otg_state(struct device *dev, | |||
1026 | fsm->b_bus_suspend, | 1082 | fsm->b_bus_suspend, |
1027 | fsm->b_conn, | 1083 | fsm->b_conn, |
1028 | fsm->b_se0_srp, | 1084 | fsm->b_se0_srp, |
1029 | fsm->b_sess_end, | 1085 | fsm->b_ssend_srp, |
1030 | fsm->b_sess_vld, | 1086 | fsm->b_sess_vld, |
1031 | fsm->id); | 1087 | fsm->id); |
1032 | size -= t; | 1088 | size -= t; |
@@ -1057,7 +1113,7 @@ static long fsl_otg_ioctl(struct file *file, unsigned int cmd, | |||
1057 | break; | 1113 | break; |
1058 | 1114 | ||
1059 | case SET_A_SUSPEND_REQ: | 1115 | case SET_A_SUSPEND_REQ: |
1060 | fsl_otg_dev->fsm.a_suspend_req = arg; | 1116 | fsl_otg_dev->fsm.a_suspend_req_inf = arg; |
1061 | break; | 1117 | break; |
1062 | 1118 | ||
1063 | case SET_A_BUS_DROP: | 1119 | case SET_A_BUS_DROP: |
diff --git a/drivers/usb/phy/phy-fsl-usb.h b/drivers/usb/phy/phy-fsl-usb.h index e1859b8ef567..7365170a2f23 100644 --- a/drivers/usb/phy/phy-fsl-usb.h +++ b/drivers/usb/phy/phy-fsl-usb.h | |||
@@ -401,6 +401,6 @@ struct fsl_otg_config { | |||
401 | #define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int) | 401 | #define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int) |
402 | #define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int) | 402 | #define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int) |
403 | 403 | ||
404 | void fsl_otg_add_timer(void *timer); | 404 | void fsl_otg_add_timer(struct otg_fsm *fsm, void *timer); |
405 | void fsl_otg_del_timer(void *timer); | 405 | void fsl_otg_del_timer(struct otg_fsm *fsm, void *timer); |
406 | void fsl_otg_pulse_vbus(void); | 406 | void fsl_otg_pulse_vbus(void); |
diff --git a/drivers/usb/phy/phy-fsm-usb.c b/drivers/usb/phy/phy-fsm-usb.c index 7f4596606e18..329c2d2f8595 100644 --- a/drivers/usb/phy/phy-fsm-usb.c +++ b/drivers/usb/phy/phy-fsm-usb.c | |||
@@ -41,17 +41,17 @@ static int otg_set_protocol(struct otg_fsm *fsm, int protocol) | |||
41 | fsm->protocol, protocol); | 41 | fsm->protocol, protocol); |
42 | /* stop old protocol */ | 42 | /* stop old protocol */ |
43 | if (fsm->protocol == PROTO_HOST) | 43 | if (fsm->protocol == PROTO_HOST) |
44 | ret = fsm->ops->start_host(fsm, 0); | 44 | ret = otg_start_host(fsm, 0); |
45 | else if (fsm->protocol == PROTO_GADGET) | 45 | else if (fsm->protocol == PROTO_GADGET) |
46 | ret = fsm->ops->start_gadget(fsm, 0); | 46 | ret = otg_start_gadget(fsm, 0); |
47 | if (ret) | 47 | if (ret) |
48 | return ret; | 48 | return ret; |
49 | 49 | ||
50 | /* start new protocol */ | 50 | /* start new protocol */ |
51 | if (protocol == PROTO_HOST) | 51 | if (protocol == PROTO_HOST) |
52 | ret = fsm->ops->start_host(fsm, 1); | 52 | ret = otg_start_host(fsm, 1); |
53 | else if (protocol == PROTO_GADGET) | 53 | else if (protocol == PROTO_GADGET) |
54 | ret = fsm->ops->start_gadget(fsm, 1); | 54 | ret = otg_start_gadget(fsm, 1); |
55 | if (ret) | 55 | if (ret) |
56 | return ret; | 56 | return ret; |
57 | 57 | ||
@@ -69,42 +69,50 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) | |||
69 | { | 69 | { |
70 | switch (old_state) { | 70 | switch (old_state) { |
71 | case OTG_STATE_B_IDLE: | 71 | case OTG_STATE_B_IDLE: |
72 | otg_del_timer(fsm, b_se0_srp_tmr); | 72 | otg_del_timer(fsm, B_SE0_SRP); |
73 | fsm->b_se0_srp = 0; | 73 | fsm->b_se0_srp = 0; |
74 | fsm->adp_sns = 0; | ||
75 | fsm->adp_prb = 0; | ||
74 | break; | 76 | break; |
75 | case OTG_STATE_B_SRP_INIT: | 77 | case OTG_STATE_B_SRP_INIT: |
78 | fsm->data_pulse = 0; | ||
76 | fsm->b_srp_done = 0; | 79 | fsm->b_srp_done = 0; |
77 | break; | 80 | break; |
78 | case OTG_STATE_B_PERIPHERAL: | 81 | case OTG_STATE_B_PERIPHERAL: |
79 | break; | 82 | break; |
80 | case OTG_STATE_B_WAIT_ACON: | 83 | case OTG_STATE_B_WAIT_ACON: |
81 | otg_del_timer(fsm, b_ase0_brst_tmr); | 84 | otg_del_timer(fsm, B_ASE0_BRST); |
82 | fsm->b_ase0_brst_tmout = 0; | 85 | fsm->b_ase0_brst_tmout = 0; |
83 | break; | 86 | break; |
84 | case OTG_STATE_B_HOST: | 87 | case OTG_STATE_B_HOST: |
85 | break; | 88 | break; |
86 | case OTG_STATE_A_IDLE: | 89 | case OTG_STATE_A_IDLE: |
90 | fsm->adp_prb = 0; | ||
87 | break; | 91 | break; |
88 | case OTG_STATE_A_WAIT_VRISE: | 92 | case OTG_STATE_A_WAIT_VRISE: |
89 | otg_del_timer(fsm, a_wait_vrise_tmr); | 93 | otg_del_timer(fsm, A_WAIT_VRISE); |
90 | fsm->a_wait_vrise_tmout = 0; | 94 | fsm->a_wait_vrise_tmout = 0; |
91 | break; | 95 | break; |
92 | case OTG_STATE_A_WAIT_BCON: | 96 | case OTG_STATE_A_WAIT_BCON: |
93 | otg_del_timer(fsm, a_wait_bcon_tmr); | 97 | otg_del_timer(fsm, A_WAIT_BCON); |
94 | fsm->a_wait_bcon_tmout = 0; | 98 | fsm->a_wait_bcon_tmout = 0; |
95 | break; | 99 | break; |
96 | case OTG_STATE_A_HOST: | 100 | case OTG_STATE_A_HOST: |
97 | otg_del_timer(fsm, a_wait_enum_tmr); | 101 | otg_del_timer(fsm, A_WAIT_ENUM); |
98 | break; | 102 | break; |
99 | case OTG_STATE_A_SUSPEND: | 103 | case OTG_STATE_A_SUSPEND: |
100 | otg_del_timer(fsm, a_aidl_bdis_tmr); | 104 | otg_del_timer(fsm, A_AIDL_BDIS); |
101 | fsm->a_aidl_bdis_tmout = 0; | 105 | fsm->a_aidl_bdis_tmout = 0; |
102 | fsm->a_suspend_req = 0; | 106 | fsm->a_suspend_req_inf = 0; |
103 | break; | 107 | break; |
104 | case OTG_STATE_A_PERIPHERAL: | 108 | case OTG_STATE_A_PERIPHERAL: |
109 | otg_del_timer(fsm, A_BIDL_ADIS); | ||
110 | fsm->a_bidl_adis_tmout = 0; | ||
105 | break; | 111 | break; |
106 | case OTG_STATE_A_WAIT_VFALL: | 112 | case OTG_STATE_A_WAIT_VFALL: |
107 | otg_del_timer(fsm, a_wait_vrise_tmr); | 113 | otg_del_timer(fsm, A_WAIT_VFALL); |
114 | fsm->a_wait_vfall_tmout = 0; | ||
115 | otg_del_timer(fsm, A_WAIT_VRISE); | ||
108 | break; | 116 | break; |
109 | case OTG_STATE_A_VBUS_ERR: | 117 | case OTG_STATE_A_VBUS_ERR: |
110 | break; | 118 | break; |
@@ -127,14 +135,19 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
127 | otg_chrg_vbus(fsm, 0); | 135 | otg_chrg_vbus(fsm, 0); |
128 | otg_loc_conn(fsm, 0); | 136 | otg_loc_conn(fsm, 0); |
129 | otg_loc_sof(fsm, 0); | 137 | otg_loc_sof(fsm, 0); |
138 | /* | ||
139 | * Driver is responsible for starting ADP probing | ||
140 | * if ADP sensing times out. | ||
141 | */ | ||
142 | otg_start_adp_sns(fsm); | ||
130 | otg_set_protocol(fsm, PROTO_UNDEF); | 143 | otg_set_protocol(fsm, PROTO_UNDEF); |
131 | otg_add_timer(fsm, b_se0_srp_tmr); | 144 | otg_add_timer(fsm, B_SE0_SRP); |
132 | break; | 145 | break; |
133 | case OTG_STATE_B_SRP_INIT: | 146 | case OTG_STATE_B_SRP_INIT: |
134 | otg_start_pulse(fsm); | 147 | otg_start_pulse(fsm); |
135 | otg_loc_sof(fsm, 0); | 148 | otg_loc_sof(fsm, 0); |
136 | otg_set_protocol(fsm, PROTO_UNDEF); | 149 | otg_set_protocol(fsm, PROTO_UNDEF); |
137 | otg_add_timer(fsm, b_srp_fail_tmr); | 150 | otg_add_timer(fsm, B_SRP_FAIL); |
138 | break; | 151 | break; |
139 | case OTG_STATE_B_PERIPHERAL: | 152 | case OTG_STATE_B_PERIPHERAL: |
140 | otg_chrg_vbus(fsm, 0); | 153 | otg_chrg_vbus(fsm, 0); |
@@ -147,7 +160,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
147 | otg_loc_conn(fsm, 0); | 160 | otg_loc_conn(fsm, 0); |
148 | otg_loc_sof(fsm, 0); | 161 | otg_loc_sof(fsm, 0); |
149 | otg_set_protocol(fsm, PROTO_HOST); | 162 | otg_set_protocol(fsm, PROTO_HOST); |
150 | otg_add_timer(fsm, b_ase0_brst_tmr); | 163 | otg_add_timer(fsm, B_ASE0_BRST); |
151 | fsm->a_bus_suspend = 0; | 164 | fsm->a_bus_suspend = 0; |
152 | break; | 165 | break; |
153 | case OTG_STATE_B_HOST: | 166 | case OTG_STATE_B_HOST: |
@@ -163,6 +176,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
163 | otg_chrg_vbus(fsm, 0); | 176 | otg_chrg_vbus(fsm, 0); |
164 | otg_loc_conn(fsm, 0); | 177 | otg_loc_conn(fsm, 0); |
165 | otg_loc_sof(fsm, 0); | 178 | otg_loc_sof(fsm, 0); |
179 | otg_start_adp_prb(fsm); | ||
166 | otg_set_protocol(fsm, PROTO_HOST); | 180 | otg_set_protocol(fsm, PROTO_HOST); |
167 | break; | 181 | break; |
168 | case OTG_STATE_A_WAIT_VRISE: | 182 | case OTG_STATE_A_WAIT_VRISE: |
@@ -170,14 +184,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
170 | otg_loc_conn(fsm, 0); | 184 | otg_loc_conn(fsm, 0); |
171 | otg_loc_sof(fsm, 0); | 185 | otg_loc_sof(fsm, 0); |
172 | otg_set_protocol(fsm, PROTO_HOST); | 186 | otg_set_protocol(fsm, PROTO_HOST); |
173 | otg_add_timer(fsm, a_wait_vrise_tmr); | 187 | otg_add_timer(fsm, A_WAIT_VRISE); |
174 | break; | 188 | break; |
175 | case OTG_STATE_A_WAIT_BCON: | 189 | case OTG_STATE_A_WAIT_BCON: |
176 | otg_drv_vbus(fsm, 1); | 190 | otg_drv_vbus(fsm, 1); |
177 | otg_loc_conn(fsm, 0); | 191 | otg_loc_conn(fsm, 0); |
178 | otg_loc_sof(fsm, 0); | 192 | otg_loc_sof(fsm, 0); |
179 | otg_set_protocol(fsm, PROTO_HOST); | 193 | otg_set_protocol(fsm, PROTO_HOST); |
180 | otg_add_timer(fsm, a_wait_bcon_tmr); | 194 | otg_add_timer(fsm, A_WAIT_BCON); |
181 | break; | 195 | break; |
182 | case OTG_STATE_A_HOST: | 196 | case OTG_STATE_A_HOST: |
183 | otg_drv_vbus(fsm, 1); | 197 | otg_drv_vbus(fsm, 1); |
@@ -188,15 +202,15 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
188 | * When HNP is triggered while a_bus_req = 0, a_host will | 202 | * When HNP is triggered while a_bus_req = 0, a_host will |
189 | * suspend too fast to complete a_set_b_hnp_en | 203 | * suspend too fast to complete a_set_b_hnp_en |
190 | */ | 204 | */ |
191 | if (!fsm->a_bus_req || fsm->a_suspend_req) | 205 | if (!fsm->a_bus_req || fsm->a_suspend_req_inf) |
192 | otg_add_timer(fsm, a_wait_enum_tmr); | 206 | otg_add_timer(fsm, A_WAIT_ENUM); |
193 | break; | 207 | break; |
194 | case OTG_STATE_A_SUSPEND: | 208 | case OTG_STATE_A_SUSPEND: |
195 | otg_drv_vbus(fsm, 1); | 209 | otg_drv_vbus(fsm, 1); |
196 | otg_loc_conn(fsm, 0); | 210 | otg_loc_conn(fsm, 0); |
197 | otg_loc_sof(fsm, 0); | 211 | otg_loc_sof(fsm, 0); |
198 | otg_set_protocol(fsm, PROTO_HOST); | 212 | otg_set_protocol(fsm, PROTO_HOST); |
199 | otg_add_timer(fsm, a_aidl_bdis_tmr); | 213 | otg_add_timer(fsm, A_AIDL_BDIS); |
200 | 214 | ||
201 | break; | 215 | break; |
202 | case OTG_STATE_A_PERIPHERAL: | 216 | case OTG_STATE_A_PERIPHERAL: |
@@ -204,12 +218,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
204 | otg_loc_sof(fsm, 0); | 218 | otg_loc_sof(fsm, 0); |
205 | otg_set_protocol(fsm, PROTO_GADGET); | 219 | otg_set_protocol(fsm, PROTO_GADGET); |
206 | otg_drv_vbus(fsm, 1); | 220 | otg_drv_vbus(fsm, 1); |
221 | otg_add_timer(fsm, A_BIDL_ADIS); | ||
207 | break; | 222 | break; |
208 | case OTG_STATE_A_WAIT_VFALL: | 223 | case OTG_STATE_A_WAIT_VFALL: |
209 | otg_drv_vbus(fsm, 0); | 224 | otg_drv_vbus(fsm, 0); |
210 | otg_loc_conn(fsm, 0); | 225 | otg_loc_conn(fsm, 0); |
211 | otg_loc_sof(fsm, 0); | 226 | otg_loc_sof(fsm, 0); |
212 | otg_set_protocol(fsm, PROTO_HOST); | 227 | otg_set_protocol(fsm, PROTO_HOST); |
228 | otg_add_timer(fsm, A_WAIT_VFALL); | ||
213 | break; | 229 | break; |
214 | case OTG_STATE_A_VBUS_ERR: | 230 | case OTG_STATE_A_VBUS_ERR: |
215 | otg_drv_vbus(fsm, 0); | 231 | otg_drv_vbus(fsm, 0); |
@@ -250,7 +266,8 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
250 | otg_set_state(fsm, OTG_STATE_A_IDLE); | 266 | otg_set_state(fsm, OTG_STATE_A_IDLE); |
251 | else if (fsm->b_sess_vld && fsm->otg->gadget) | 267 | else if (fsm->b_sess_vld && fsm->otg->gadget) |
252 | otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); | 268 | otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); |
253 | else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp) | 269 | else if ((fsm->b_bus_req || fsm->adp_change || fsm->power_up) && |
270 | fsm->b_ssend_srp && fsm->b_se0_srp) | ||
254 | otg_set_state(fsm, OTG_STATE_B_SRP_INIT); | 271 | otg_set_state(fsm, OTG_STATE_B_SRP_INIT); |
255 | break; | 272 | break; |
256 | case OTG_STATE_B_SRP_INIT: | 273 | case OTG_STATE_B_SRP_INIT: |
@@ -277,13 +294,14 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
277 | case OTG_STATE_B_HOST: | 294 | case OTG_STATE_B_HOST: |
278 | if (!fsm->id || !fsm->b_sess_vld) | 295 | if (!fsm->id || !fsm->b_sess_vld) |
279 | otg_set_state(fsm, OTG_STATE_B_IDLE); | 296 | otg_set_state(fsm, OTG_STATE_B_IDLE); |
280 | else if (!fsm->b_bus_req || !fsm->a_conn) | 297 | else if (!fsm->b_bus_req || !fsm->a_conn || fsm->test_device) |
281 | otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); | 298 | otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); |
282 | break; | 299 | break; |
283 | case OTG_STATE_A_IDLE: | 300 | case OTG_STATE_A_IDLE: |
284 | if (fsm->id) | 301 | if (fsm->id) |
285 | otg_set_state(fsm, OTG_STATE_B_IDLE); | 302 | otg_set_state(fsm, OTG_STATE_B_IDLE); |
286 | else if (!fsm->a_bus_drop && (fsm->a_bus_req || fsm->a_srp_det)) | 303 | else if (!fsm->a_bus_drop && (fsm->a_bus_req || |
304 | fsm->a_srp_det || fsm->adp_change || fsm->power_up)) | ||
287 | otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE); | 305 | otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE); |
288 | break; | 306 | break; |
289 | case OTG_STATE_A_WAIT_VRISE: | 307 | case OTG_STATE_A_WAIT_VRISE: |
@@ -301,7 +319,7 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
301 | otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); | 319 | otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); |
302 | break; | 320 | break; |
303 | case OTG_STATE_A_HOST: | 321 | case OTG_STATE_A_HOST: |
304 | if ((!fsm->a_bus_req || fsm->a_suspend_req) && | 322 | if ((!fsm->a_bus_req || fsm->a_suspend_req_inf) && |
305 | fsm->otg->host->b_hnp_enable) | 323 | fsm->otg->host->b_hnp_enable) |
306 | otg_set_state(fsm, OTG_STATE_A_SUSPEND); | 324 | otg_set_state(fsm, OTG_STATE_A_SUSPEND); |
307 | else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop) | 325 | else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop) |
@@ -324,14 +342,14 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
324 | case OTG_STATE_A_PERIPHERAL: | 342 | case OTG_STATE_A_PERIPHERAL: |
325 | if (fsm->id || fsm->a_bus_drop) | 343 | if (fsm->id || fsm->a_bus_drop) |
326 | otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); | 344 | otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); |
327 | else if (fsm->b_bus_suspend) | 345 | else if (fsm->a_bidl_adis_tmout || fsm->b_bus_suspend) |
328 | otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); | 346 | otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); |
329 | else if (!fsm->a_vbus_vld) | 347 | else if (!fsm->a_vbus_vld) |
330 | otg_set_state(fsm, OTG_STATE_A_VBUS_ERR); | 348 | otg_set_state(fsm, OTG_STATE_A_VBUS_ERR); |
331 | break; | 349 | break; |
332 | case OTG_STATE_A_WAIT_VFALL: | 350 | case OTG_STATE_A_WAIT_VFALL: |
333 | if (fsm->id || fsm->a_bus_req || (!fsm->a_sess_vld && | 351 | if (fsm->a_wait_vfall_tmout || fsm->id || fsm->a_bus_req || |
334 | !fsm->b_conn)) | 352 | (!fsm->a_sess_vld && !fsm->b_conn)) |
335 | otg_set_state(fsm, OTG_STATE_A_IDLE); | 353 | otg_set_state(fsm, OTG_STATE_A_IDLE); |
336 | break; | 354 | break; |
337 | case OTG_STATE_A_VBUS_ERR: | 355 | case OTG_STATE_A_VBUS_ERR: |
diff --git a/drivers/usb/phy/phy-fsm-usb.h b/drivers/usb/phy/phy-fsm-usb.h index fbe586206f33..7441b46a27f1 100644 --- a/drivers/usb/phy/phy-fsm-usb.h +++ b/drivers/usb/phy/phy-fsm-usb.h | |||
@@ -34,45 +34,76 @@ | |||
34 | #define PROTO_HOST (1) | 34 | #define PROTO_HOST (1) |
35 | #define PROTO_GADGET (2) | 35 | #define PROTO_GADGET (2) |
36 | 36 | ||
37 | enum otg_fsm_timer { | ||
38 | /* Standard OTG timers */ | ||
39 | A_WAIT_VRISE, | ||
40 | A_WAIT_VFALL, | ||
41 | A_WAIT_BCON, | ||
42 | A_AIDL_BDIS, | ||
43 | B_ASE0_BRST, | ||
44 | A_BIDL_ADIS, | ||
45 | |||
46 | /* Auxiliary timers */ | ||
47 | B_SE0_SRP, | ||
48 | B_SRP_FAIL, | ||
49 | A_WAIT_ENUM, | ||
50 | |||
51 | NUM_OTG_FSM_TIMERS, | ||
52 | }; | ||
53 | |||
37 | /* OTG state machine according to the OTG spec */ | 54 | /* OTG state machine according to the OTG spec */ |
38 | struct otg_fsm { | 55 | struct otg_fsm { |
39 | /* Input */ | 56 | /* Input */ |
57 | int id; | ||
58 | int adp_change; | ||
59 | int power_up; | ||
60 | int test_device; | ||
61 | int a_bus_drop; | ||
62 | int a_bus_req; | ||
63 | int a_srp_det; | ||
64 | int a_vbus_vld; | ||
65 | int b_conn; | ||
40 | int a_bus_resume; | 66 | int a_bus_resume; |
41 | int a_bus_suspend; | 67 | int a_bus_suspend; |
42 | int a_conn; | 68 | int a_conn; |
69 | int b_bus_req; | ||
70 | int b_se0_srp; | ||
71 | int b_ssend_srp; | ||
72 | int b_sess_vld; | ||
73 | /* Auxilary inputs */ | ||
43 | int a_sess_vld; | 74 | int a_sess_vld; |
44 | int a_srp_det; | ||
45 | int a_vbus_vld; | ||
46 | int b_bus_resume; | 75 | int b_bus_resume; |
47 | int b_bus_suspend; | 76 | int b_bus_suspend; |
48 | int b_conn; | 77 | |
49 | int b_se0_srp; | 78 | /* Output */ |
50 | int b_sess_end; | 79 | int data_pulse; |
51 | int b_sess_vld; | 80 | int drv_vbus; |
52 | int id; | 81 | int loc_conn; |
82 | int loc_sof; | ||
83 | int adp_prb; | ||
84 | int adp_sns; | ||
53 | 85 | ||
54 | /* Internal variables */ | 86 | /* Internal variables */ |
55 | int a_set_b_hnp_en; | 87 | int a_set_b_hnp_en; |
56 | int b_srp_done; | 88 | int b_srp_done; |
57 | int b_hnp_enable; | 89 | int b_hnp_enable; |
90 | int a_clr_err; | ||
91 | |||
92 | /* Informative variables */ | ||
93 | int a_bus_drop_inf; | ||
94 | int a_bus_req_inf; | ||
95 | int a_clr_err_inf; | ||
96 | int b_bus_req_inf; | ||
97 | /* Auxilary informative variables */ | ||
98 | int a_suspend_req_inf; | ||
58 | 99 | ||
59 | /* Timeout indicator for timers */ | 100 | /* Timeout indicator for timers */ |
60 | int a_wait_vrise_tmout; | 101 | int a_wait_vrise_tmout; |
102 | int a_wait_vfall_tmout; | ||
61 | int a_wait_bcon_tmout; | 103 | int a_wait_bcon_tmout; |
62 | int a_aidl_bdis_tmout; | 104 | int a_aidl_bdis_tmout; |
63 | int b_ase0_brst_tmout; | 105 | int b_ase0_brst_tmout; |
64 | 106 | int a_bidl_adis_tmout; | |
65 | /* Informative variables */ | ||
66 | int a_bus_drop; | ||
67 | int a_bus_req; | ||
68 | int a_clr_err; | ||
69 | int a_suspend_req; | ||
70 | int b_bus_req; | ||
71 | |||
72 | /* Output */ | ||
73 | int drv_vbus; | ||
74 | int loc_conn; | ||
75 | int loc_sof; | ||
76 | 107 | ||
77 | struct otg_fsm_ops *ops; | 108 | struct otg_fsm_ops *ops; |
78 | struct usb_otg *otg; | 109 | struct usb_otg *otg; |
@@ -83,65 +114,123 @@ struct otg_fsm { | |||
83 | }; | 114 | }; |
84 | 115 | ||
85 | struct otg_fsm_ops { | 116 | struct otg_fsm_ops { |
86 | void (*chrg_vbus)(int on); | 117 | void (*chrg_vbus)(struct otg_fsm *fsm, int on); |
87 | void (*drv_vbus)(int on); | 118 | void (*drv_vbus)(struct otg_fsm *fsm, int on); |
88 | void (*loc_conn)(int on); | 119 | void (*loc_conn)(struct otg_fsm *fsm, int on); |
89 | void (*loc_sof)(int on); | 120 | void (*loc_sof)(struct otg_fsm *fsm, int on); |
90 | void (*start_pulse)(void); | 121 | void (*start_pulse)(struct otg_fsm *fsm); |
91 | void (*add_timer)(void *timer); | 122 | void (*start_adp_prb)(struct otg_fsm *fsm); |
92 | void (*del_timer)(void *timer); | 123 | void (*start_adp_sns)(struct otg_fsm *fsm); |
124 | void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); | ||
125 | void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); | ||
93 | int (*start_host)(struct otg_fsm *fsm, int on); | 126 | int (*start_host)(struct otg_fsm *fsm, int on); |
94 | int (*start_gadget)(struct otg_fsm *fsm, int on); | 127 | int (*start_gadget)(struct otg_fsm *fsm, int on); |
95 | }; | 128 | }; |
96 | 129 | ||
97 | 130 | ||
98 | static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on) | 131 | static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on) |
99 | { | 132 | { |
100 | fsm->ops->chrg_vbus(on); | 133 | if (!fsm->ops->chrg_vbus) |
134 | return -EOPNOTSUPP; | ||
135 | fsm->ops->chrg_vbus(fsm, on); | ||
136 | return 0; | ||
101 | } | 137 | } |
102 | 138 | ||
103 | static inline void otg_drv_vbus(struct otg_fsm *fsm, int on) | 139 | static inline int otg_drv_vbus(struct otg_fsm *fsm, int on) |
104 | { | 140 | { |
141 | if (!fsm->ops->drv_vbus) | ||
142 | return -EOPNOTSUPP; | ||
105 | if (fsm->drv_vbus != on) { | 143 | if (fsm->drv_vbus != on) { |
106 | fsm->drv_vbus = on; | 144 | fsm->drv_vbus = on; |
107 | fsm->ops->drv_vbus(on); | 145 | fsm->ops->drv_vbus(fsm, on); |
108 | } | 146 | } |
147 | return 0; | ||
109 | } | 148 | } |
110 | 149 | ||
111 | static inline void otg_loc_conn(struct otg_fsm *fsm, int on) | 150 | static inline int otg_loc_conn(struct otg_fsm *fsm, int on) |
112 | { | 151 | { |
152 | if (!fsm->ops->loc_conn) | ||
153 | return -EOPNOTSUPP; | ||
113 | if (fsm->loc_conn != on) { | 154 | if (fsm->loc_conn != on) { |
114 | fsm->loc_conn = on; | 155 | fsm->loc_conn = on; |
115 | fsm->ops->loc_conn(on); | 156 | fsm->ops->loc_conn(fsm, on); |
116 | } | 157 | } |
158 | return 0; | ||
117 | } | 159 | } |
118 | 160 | ||
119 | static inline void otg_loc_sof(struct otg_fsm *fsm, int on) | 161 | static inline int otg_loc_sof(struct otg_fsm *fsm, int on) |
120 | { | 162 | { |
163 | if (!fsm->ops->loc_sof) | ||
164 | return -EOPNOTSUPP; | ||
121 | if (fsm->loc_sof != on) { | 165 | if (fsm->loc_sof != on) { |
122 | fsm->loc_sof = on; | 166 | fsm->loc_sof = on; |
123 | fsm->ops->loc_sof(on); | 167 | fsm->ops->loc_sof(fsm, on); |
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static inline int otg_start_pulse(struct otg_fsm *fsm) | ||
173 | { | ||
174 | if (!fsm->ops->start_pulse) | ||
175 | return -EOPNOTSUPP; | ||
176 | if (!fsm->data_pulse) { | ||
177 | fsm->data_pulse = 1; | ||
178 | fsm->ops->start_pulse(fsm); | ||
124 | } | 179 | } |
180 | return 0; | ||
125 | } | 181 | } |
126 | 182 | ||
127 | static inline void otg_start_pulse(struct otg_fsm *fsm) | 183 | static inline int otg_start_adp_prb(struct otg_fsm *fsm) |
128 | { | 184 | { |
129 | fsm->ops->start_pulse(); | 185 | if (!fsm->ops->start_adp_prb) |
186 | return -EOPNOTSUPP; | ||
187 | if (!fsm->adp_prb) { | ||
188 | fsm->adp_sns = 0; | ||
189 | fsm->adp_prb = 1; | ||
190 | fsm->ops->start_adp_prb(fsm); | ||
191 | } | ||
192 | return 0; | ||
130 | } | 193 | } |
131 | 194 | ||
132 | static inline void otg_add_timer(struct otg_fsm *fsm, void *timer) | 195 | static inline int otg_start_adp_sns(struct otg_fsm *fsm) |
133 | { | 196 | { |
134 | fsm->ops->add_timer(timer); | 197 | if (!fsm->ops->start_adp_sns) |
198 | return -EOPNOTSUPP; | ||
199 | if (!fsm->adp_sns) { | ||
200 | fsm->adp_sns = 1; | ||
201 | fsm->ops->start_adp_sns(fsm); | ||
202 | } | ||
203 | return 0; | ||
135 | } | 204 | } |
136 | 205 | ||
137 | static inline void otg_del_timer(struct otg_fsm *fsm, void *timer) | 206 | static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) |
138 | { | 207 | { |
139 | fsm->ops->del_timer(timer); | 208 | if (!fsm->ops->add_timer) |
209 | return -EOPNOTSUPP; | ||
210 | fsm->ops->add_timer(fsm, timer); | ||
211 | return 0; | ||
140 | } | 212 | } |
141 | 213 | ||
142 | int otg_statemachine(struct otg_fsm *fsm); | 214 | static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) |
215 | { | ||
216 | if (!fsm->ops->del_timer) | ||
217 | return -EOPNOTSUPP; | ||
218 | fsm->ops->del_timer(fsm, timer); | ||
219 | return 0; | ||
220 | } | ||
143 | 221 | ||
144 | /* Defined by device specific driver, for different timer implementation */ | 222 | static inline int otg_start_host(struct otg_fsm *fsm, int on) |
145 | extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr, | 223 | { |
146 | *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr, | 224 | if (!fsm->ops->start_host) |
147 | *a_wait_enum_tmr; | 225 | return -EOPNOTSUPP; |
226 | return fsm->ops->start_host(fsm, on); | ||
227 | } | ||
228 | |||
229 | static inline int otg_start_gadget(struct otg_fsm *fsm, int on) | ||
230 | { | ||
231 | if (!fsm->ops->start_gadget) | ||
232 | return -EOPNOTSUPP; | ||
233 | return fsm->ops->start_gadget(fsm, on); | ||
234 | } | ||
235 | |||
236 | int otg_statemachine(struct otg_fsm *fsm); | ||
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index efe59f3f7fda..fce3a9e9bb5d 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c | |||
@@ -35,6 +35,9 @@ | |||
35 | #include <linux/clk.h> | 35 | #include <linux/clk.h> |
36 | #include <linux/regulator/consumer.h> | 36 | #include <linux/regulator/consumer.h> |
37 | #include <linux/of.h> | 37 | #include <linux/of.h> |
38 | #include <linux/of_gpio.h> | ||
39 | #include <linux/gpio.h> | ||
40 | #include <linux/delay.h> | ||
38 | 41 | ||
39 | #include "phy-generic.h" | 42 | #include "phy-generic.h" |
40 | 43 | ||
@@ -64,6 +67,23 @@ static int nop_set_suspend(struct usb_phy *x, int suspend) | |||
64 | return 0; | 67 | return 0; |
65 | } | 68 | } |
66 | 69 | ||
70 | static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted) | ||
71 | { | ||
72 | int value; | ||
73 | |||
74 | if (!gpio_is_valid(nop->gpio_reset)) | ||
75 | return; | ||
76 | |||
77 | value = asserted; | ||
78 | if (nop->reset_active_low) | ||
79 | value = !value; | ||
80 | |||
81 | gpio_set_value_cansleep(nop->gpio_reset, value); | ||
82 | |||
83 | if (!asserted) | ||
84 | usleep_range(10000, 20000); | ||
85 | } | ||
86 | |||
67 | int usb_gen_phy_init(struct usb_phy *phy) | 87 | int usb_gen_phy_init(struct usb_phy *phy) |
68 | { | 88 | { |
69 | struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); | 89 | struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); |
@@ -74,13 +94,10 @@ int usb_gen_phy_init(struct usb_phy *phy) | |||
74 | } | 94 | } |
75 | 95 | ||
76 | if (!IS_ERR(nop->clk)) | 96 | if (!IS_ERR(nop->clk)) |
77 | clk_enable(nop->clk); | 97 | clk_prepare_enable(nop->clk); |
78 | 98 | ||
79 | if (!IS_ERR(nop->reset)) { | 99 | /* De-assert RESET */ |
80 | /* De-assert RESET */ | 100 | nop_reset_set(nop, 0); |
81 | if (regulator_enable(nop->reset)) | ||
82 | dev_err(phy->dev, "Failed to de-assert reset\n"); | ||
83 | } | ||
84 | 101 | ||
85 | return 0; | 102 | return 0; |
86 | } | 103 | } |
@@ -90,14 +107,11 @@ void usb_gen_phy_shutdown(struct usb_phy *phy) | |||
90 | { | 107 | { |
91 | struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); | 108 | struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); |
92 | 109 | ||
93 | if (!IS_ERR(nop->reset)) { | 110 | /* Assert RESET */ |
94 | /* Assert RESET */ | 111 | nop_reset_set(nop, 1); |
95 | if (regulator_disable(nop->reset)) | ||
96 | dev_err(phy->dev, "Failed to assert reset\n"); | ||
97 | } | ||
98 | 112 | ||
99 | if (!IS_ERR(nop->clk)) | 113 | if (!IS_ERR(nop->clk)) |
100 | clk_disable(nop->clk); | 114 | clk_disable_unprepare(nop->clk); |
101 | 115 | ||
102 | if (!IS_ERR(nop->vcc)) { | 116 | if (!IS_ERR(nop->vcc)) { |
103 | if (regulator_disable(nop->vcc)) | 117 | if (regulator_disable(nop->vcc)) |
@@ -136,8 +150,7 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
136 | } | 150 | } |
137 | 151 | ||
138 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | 152 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, |
139 | enum usb_phy_type type, u32 clk_rate, bool needs_vcc, | 153 | enum usb_phy_type type, u32 clk_rate, bool needs_vcc) |
140 | bool needs_reset) | ||
141 | { | 154 | { |
142 | int err; | 155 | int err; |
143 | 156 | ||
@@ -160,14 +173,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | |||
160 | } | 173 | } |
161 | } | 174 | } |
162 | 175 | ||
163 | if (!IS_ERR(nop->clk)) { | ||
164 | err = clk_prepare(nop->clk); | ||
165 | if (err) { | ||
166 | dev_err(dev, "Error preparing clock\n"); | ||
167 | return err; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | nop->vcc = devm_regulator_get(dev, "vcc"); | 176 | nop->vcc = devm_regulator_get(dev, "vcc"); |
172 | if (IS_ERR(nop->vcc)) { | 177 | if (IS_ERR(nop->vcc)) { |
173 | dev_dbg(dev, "Error getting vcc regulator: %ld\n", | 178 | dev_dbg(dev, "Error getting vcc regulator: %ld\n", |
@@ -176,12 +181,22 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | |||
176 | return -EPROBE_DEFER; | 181 | return -EPROBE_DEFER; |
177 | } | 182 | } |
178 | 183 | ||
179 | nop->reset = devm_regulator_get(dev, "reset"); | 184 | if (gpio_is_valid(nop->gpio_reset)) { |
180 | if (IS_ERR(nop->reset)) { | 185 | unsigned long gpio_flags; |
181 | dev_dbg(dev, "Error getting reset regulator: %ld\n", | 186 | |
182 | PTR_ERR(nop->reset)); | 187 | /* Assert RESET */ |
183 | if (needs_reset) | 188 | if (nop->reset_active_low) |
184 | return -EPROBE_DEFER; | 189 | gpio_flags = GPIOF_OUT_INIT_LOW; |
190 | else | ||
191 | gpio_flags = GPIOF_OUT_INIT_HIGH; | ||
192 | |||
193 | err = devm_gpio_request_one(dev, nop->gpio_reset, | ||
194 | gpio_flags, dev_name(dev)); | ||
195 | if (err) { | ||
196 | dev_err(dev, "Error requesting RESET GPIO %d\n", | ||
197 | nop->gpio_reset); | ||
198 | return err; | ||
199 | } | ||
185 | } | 200 | } |
186 | 201 | ||
187 | nop->dev = dev; | 202 | nop->dev = dev; |
@@ -200,13 +215,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | |||
200 | } | 215 | } |
201 | EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); | 216 | EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); |
202 | 217 | ||
203 | void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop) | ||
204 | { | ||
205 | if (!IS_ERR(nop->clk)) | ||
206 | clk_unprepare(nop->clk); | ||
207 | } | ||
208 | EXPORT_SYMBOL_GPL(usb_phy_gen_cleanup_phy); | ||
209 | |||
210 | static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) | 218 | static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) |
211 | { | 219 | { |
212 | struct device *dev = &pdev->dev; | 220 | struct device *dev = &pdev->dev; |
@@ -217,31 +225,36 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) | |||
217 | int err; | 225 | int err; |
218 | u32 clk_rate = 0; | 226 | u32 clk_rate = 0; |
219 | bool needs_vcc = false; | 227 | bool needs_vcc = false; |
220 | bool needs_reset = false; | 228 | |
229 | nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); | ||
230 | if (!nop) | ||
231 | return -ENOMEM; | ||
232 | |||
233 | nop->reset_active_low = true; /* default behaviour */ | ||
221 | 234 | ||
222 | if (dev->of_node) { | 235 | if (dev->of_node) { |
223 | struct device_node *node = dev->of_node; | 236 | struct device_node *node = dev->of_node; |
237 | enum of_gpio_flags flags; | ||
224 | 238 | ||
225 | if (of_property_read_u32(node, "clock-frequency", &clk_rate)) | 239 | if (of_property_read_u32(node, "clock-frequency", &clk_rate)) |
226 | clk_rate = 0; | 240 | clk_rate = 0; |
227 | 241 | ||
228 | needs_vcc = of_property_read_bool(node, "vcc-supply"); | 242 | needs_vcc = of_property_read_bool(node, "vcc-supply"); |
229 | needs_reset = of_property_read_bool(node, "reset-supply"); | 243 | nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios", |
244 | 0, &flags); | ||
245 | if (nop->gpio_reset == -EPROBE_DEFER) | ||
246 | return -EPROBE_DEFER; | ||
247 | |||
248 | nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW; | ||
230 | 249 | ||
231 | } else if (pdata) { | 250 | } else if (pdata) { |
232 | type = pdata->type; | 251 | type = pdata->type; |
233 | clk_rate = pdata->clk_rate; | 252 | clk_rate = pdata->clk_rate; |
234 | needs_vcc = pdata->needs_vcc; | 253 | needs_vcc = pdata->needs_vcc; |
235 | needs_reset = pdata->needs_reset; | 254 | nop->gpio_reset = pdata->gpio_reset; |
236 | } | 255 | } |
237 | 256 | ||
238 | nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); | 257 | err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc); |
239 | if (!nop) | ||
240 | return -ENOMEM; | ||
241 | |||
242 | |||
243 | err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc, | ||
244 | needs_reset); | ||
245 | if (err) | 258 | if (err) |
246 | return err; | 259 | return err; |
247 | 260 | ||
@@ -252,15 +265,13 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) | |||
252 | if (err) { | 265 | if (err) { |
253 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", | 266 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", |
254 | err); | 267 | err); |
255 | goto err_add; | 268 | return err; |
256 | } | 269 | } |
257 | 270 | ||
258 | platform_set_drvdata(pdev, nop); | 271 | platform_set_drvdata(pdev, nop); |
259 | 272 | ||
260 | return 0; | 273 | return 0; |
261 | 274 | ||
262 | err_add: | ||
263 | usb_phy_gen_cleanup_phy(nop); | ||
264 | return err; | 275 | return err; |
265 | } | 276 | } |
266 | 277 | ||
@@ -268,7 +279,6 @@ static int usb_phy_gen_xceiv_remove(struct platform_device *pdev) | |||
268 | { | 279 | { |
269 | struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); | 280 | struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); |
270 | 281 | ||
271 | usb_phy_gen_cleanup_phy(nop); | ||
272 | usb_remove_phy(&nop->phy); | 282 | usb_remove_phy(&nop->phy); |
273 | 283 | ||
274 | return 0; | 284 | return 0; |
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h index 61687d5a965b..d2a220d81734 100644 --- a/drivers/usb/phy/phy-generic.h +++ b/drivers/usb/phy/phy-generic.h | |||
@@ -6,15 +6,14 @@ struct usb_phy_gen_xceiv { | |||
6 | struct device *dev; | 6 | struct device *dev; |
7 | struct clk *clk; | 7 | struct clk *clk; |
8 | struct regulator *vcc; | 8 | struct regulator *vcc; |
9 | struct regulator *reset; | 9 | int gpio_reset; |
10 | bool reset_active_low; | ||
10 | }; | 11 | }; |
11 | 12 | ||
12 | int usb_gen_phy_init(struct usb_phy *phy); | 13 | int usb_gen_phy_init(struct usb_phy *phy); |
13 | void usb_gen_phy_shutdown(struct usb_phy *phy); | 14 | void usb_gen_phy_shutdown(struct usb_phy *phy); |
14 | 15 | ||
15 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | 16 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, |
16 | enum usb_phy_type type, u32 clk_rate, bool needs_vcc, | 17 | enum usb_phy_type type, u32 clk_rate, bool needs_vcc); |
17 | bool needs_reset); | ||
18 | void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop); | ||
19 | 18 | ||
20 | #endif | 19 | #endif |
diff --git a/drivers/usb/phy/phy-omap-control.c b/drivers/usb/phy/phy-omap-control.c index a4dda8e12562..09c5ace1edd8 100644 --- a/drivers/usb/phy/phy-omap-control.c +++ b/drivers/usb/phy/phy-omap-control.c | |||
@@ -20,87 +20,77 @@ | |||
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/of.h> | 22 | #include <linux/of.h> |
23 | #include <linux/of_device.h> | ||
23 | #include <linux/err.h> | 24 | #include <linux/err.h> |
24 | #include <linux/io.h> | 25 | #include <linux/io.h> |
25 | #include <linux/clk.h> | 26 | #include <linux/clk.h> |
26 | #include <linux/usb/omap_control_usb.h> | 27 | #include <linux/usb/omap_control_usb.h> |
27 | 28 | ||
28 | static struct omap_control_usb *control_usb; | ||
29 | |||
30 | /** | ||
31 | * omap_get_control_dev - returns the device pointer for this control device | ||
32 | * | ||
33 | * This API should be called to get the device pointer for this control | ||
34 | * module device. This device pointer should be used for called other | ||
35 | * exported API's in this driver. | ||
36 | * | ||
37 | * To be used by PHY driver and glue driver. | ||
38 | */ | ||
39 | struct device *omap_get_control_dev(void) | ||
40 | { | ||
41 | if (!control_usb) | ||
42 | return ERR_PTR(-ENODEV); | ||
43 | |||
44 | return control_usb->dev; | ||
45 | } | ||
46 | EXPORT_SYMBOL_GPL(omap_get_control_dev); | ||
47 | |||
48 | /** | 29 | /** |
49 | * omap_control_usb3_phy_power - power on/off the serializer using control | 30 | * omap_control_usb_phy_power - power on/off the phy using control module reg |
50 | * module | ||
51 | * @dev: the control module device | 31 | * @dev: the control module device |
52 | * @on: 0 to off and 1 to on based on powering on or off the PHY | 32 | * @on: 0 or 1, based on powering on or off the PHY |
53 | * | ||
54 | * usb3 PHY driver should call this API to power on or off the PHY. | ||
55 | */ | 33 | */ |
56 | void omap_control_usb3_phy_power(struct device *dev, bool on) | 34 | void omap_control_usb_phy_power(struct device *dev, int on) |
57 | { | 35 | { |
58 | u32 val; | 36 | u32 val; |
59 | unsigned long rate; | 37 | unsigned long rate; |
60 | struct omap_control_usb *control_usb = dev_get_drvdata(dev); | 38 | struct omap_control_usb *control_usb; |
61 | 39 | ||
62 | if (control_usb->type != OMAP_CTRL_DEV_TYPE2) | 40 | if (IS_ERR(dev) || !dev) { |
41 | pr_err("%s: invalid device\n", __func__); | ||
63 | return; | 42 | return; |
43 | } | ||
64 | 44 | ||
65 | rate = clk_get_rate(control_usb->sys_clk); | 45 | control_usb = dev_get_drvdata(dev); |
66 | rate = rate/1000000; | 46 | if (!control_usb) { |
67 | 47 | dev_err(dev, "%s: invalid control usb device\n", __func__); | |
68 | val = readl(control_usb->phy_power); | 48 | return; |
69 | |||
70 | if (on) { | ||
71 | val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK | | ||
72 | OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK); | ||
73 | val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON << | ||
74 | OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; | ||
75 | val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT; | ||
76 | } else { | ||
77 | val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK; | ||
78 | val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF << | ||
79 | OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; | ||
80 | } | 49 | } |
81 | 50 | ||
82 | writel(val, control_usb->phy_power); | 51 | if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) |
83 | } | 52 | return; |
84 | EXPORT_SYMBOL_GPL(omap_control_usb3_phy_power); | ||
85 | 53 | ||
86 | /** | 54 | val = readl(control_usb->power); |
87 | * omap_control_usb_phy_power - power on/off the phy using control module reg | ||
88 | * @dev: the control module device | ||
89 | * @on: 0 or 1, based on powering on or off the PHY | ||
90 | */ | ||
91 | void omap_control_usb_phy_power(struct device *dev, int on) | ||
92 | { | ||
93 | u32 val; | ||
94 | struct omap_control_usb *control_usb = dev_get_drvdata(dev); | ||
95 | 55 | ||
96 | val = readl(control_usb->dev_conf); | 56 | switch (control_usb->type) { |
57 | case OMAP_CTRL_TYPE_USB2: | ||
58 | if (on) | ||
59 | val &= ~OMAP_CTRL_DEV_PHY_PD; | ||
60 | else | ||
61 | val |= OMAP_CTRL_DEV_PHY_PD; | ||
62 | break; | ||
97 | 63 | ||
98 | if (on) | 64 | case OMAP_CTRL_TYPE_PIPE3: |
99 | val &= ~OMAP_CTRL_DEV_PHY_PD; | 65 | rate = clk_get_rate(control_usb->sys_clk); |
100 | else | 66 | rate = rate/1000000; |
101 | val |= OMAP_CTRL_DEV_PHY_PD; | 67 | |
68 | if (on) { | ||
69 | val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK | | ||
70 | OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK); | ||
71 | val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON << | ||
72 | OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; | ||
73 | val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT; | ||
74 | } else { | ||
75 | val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK; | ||
76 | val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF << | ||
77 | OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; | ||
78 | } | ||
79 | break; | ||
102 | 80 | ||
103 | writel(val, control_usb->dev_conf); | 81 | case OMAP_CTRL_TYPE_DRA7USB2: |
82 | if (on) | ||
83 | val &= ~OMAP_CTRL_USB2_PHY_PD; | ||
84 | else | ||
85 | val |= OMAP_CTRL_USB2_PHY_PD; | ||
86 | break; | ||
87 | default: | ||
88 | dev_err(dev, "%s: type %d not recognized\n", | ||
89 | __func__, control_usb->type); | ||
90 | break; | ||
91 | } | ||
92 | |||
93 | writel(val, control_usb->power); | ||
104 | } | 94 | } |
105 | EXPORT_SYMBOL_GPL(omap_control_usb_phy_power); | 95 | EXPORT_SYMBOL_GPL(omap_control_usb_phy_power); |
106 | 96 | ||
@@ -172,11 +162,19 @@ void omap_control_usb_set_mode(struct device *dev, | |||
172 | { | 162 | { |
173 | struct omap_control_usb *ctrl_usb; | 163 | struct omap_control_usb *ctrl_usb; |
174 | 164 | ||
175 | if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_DEV_TYPE1) | 165 | if (IS_ERR(dev) || !dev) |
176 | return; | 166 | return; |
177 | 167 | ||
178 | ctrl_usb = dev_get_drvdata(dev); | 168 | ctrl_usb = dev_get_drvdata(dev); |
179 | 169 | ||
170 | if (!ctrl_usb) { | ||
171 | dev_err(dev, "Invalid control usb device\n"); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | if (ctrl_usb->type != OMAP_CTRL_TYPE_OTGHS) | ||
176 | return; | ||
177 | |||
180 | switch (mode) { | 178 | switch (mode) { |
181 | case USB_MODE_HOST: | 179 | case USB_MODE_HOST: |
182 | omap_control_usb_host_mode(ctrl_usb); | 180 | omap_control_usb_host_mode(ctrl_usb); |
@@ -193,12 +191,46 @@ void omap_control_usb_set_mode(struct device *dev, | |||
193 | } | 191 | } |
194 | EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); | 192 | EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); |
195 | 193 | ||
194 | #ifdef CONFIG_OF | ||
195 | |||
196 | static const enum omap_control_usb_type otghs_data = OMAP_CTRL_TYPE_OTGHS; | ||
197 | static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2; | ||
198 | static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; | ||
199 | static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; | ||
200 | |||
201 | static const struct of_device_id omap_control_usb_id_table[] = { | ||
202 | { | ||
203 | .compatible = "ti,control-phy-otghs", | ||
204 | .data = &otghs_data, | ||
205 | }, | ||
206 | { | ||
207 | .compatible = "ti,control-phy-usb2", | ||
208 | .data = &usb2_data, | ||
209 | }, | ||
210 | { | ||
211 | .compatible = "ti,control-phy-pipe3", | ||
212 | .data = &pipe3_data, | ||
213 | }, | ||
214 | { | ||
215 | .compatible = "ti,control-phy-dra7usb2", | ||
216 | .data = &dra7usb2_data, | ||
217 | }, | ||
218 | {}, | ||
219 | }; | ||
220 | MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); | ||
221 | #endif | ||
222 | |||
223 | |||
196 | static int omap_control_usb_probe(struct platform_device *pdev) | 224 | static int omap_control_usb_probe(struct platform_device *pdev) |
197 | { | 225 | { |
198 | struct resource *res; | 226 | struct resource *res; |
199 | struct device_node *np = pdev->dev.of_node; | 227 | const struct of_device_id *of_id; |
200 | struct omap_control_usb_platform_data *pdata = | 228 | struct omap_control_usb *control_usb; |
201 | dev_get_platdata(&pdev->dev); | 229 | |
230 | of_id = of_match_device(of_match_ptr(omap_control_usb_id_table), | ||
231 | &pdev->dev); | ||
232 | if (!of_id) | ||
233 | return -EINVAL; | ||
202 | 234 | ||
203 | control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), | 235 | control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), |
204 | GFP_KERNEL); | 236 | GFP_KERNEL); |
@@ -207,40 +239,27 @@ static int omap_control_usb_probe(struct platform_device *pdev) | |||
207 | return -ENOMEM; | 239 | return -ENOMEM; |
208 | } | 240 | } |
209 | 241 | ||
210 | if (np) { | 242 | control_usb->dev = &pdev->dev; |
211 | of_property_read_u32(np, "ti,type", &control_usb->type); | 243 | control_usb->type = *(enum omap_control_usb_type *)of_id->data; |
212 | } else if (pdata) { | ||
213 | control_usb->type = pdata->type; | ||
214 | } else { | ||
215 | dev_err(&pdev->dev, "no pdata present\n"); | ||
216 | return -EINVAL; | ||
217 | } | ||
218 | |||
219 | control_usb->dev = &pdev->dev; | ||
220 | |||
221 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | ||
222 | "control_dev_conf"); | ||
223 | control_usb->dev_conf = devm_ioremap_resource(&pdev->dev, res); | ||
224 | if (IS_ERR(control_usb->dev_conf)) | ||
225 | return PTR_ERR(control_usb->dev_conf); | ||
226 | 244 | ||
227 | if (control_usb->type == OMAP_CTRL_DEV_TYPE1) { | 245 | if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) { |
228 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 246 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
229 | "otghs_control"); | 247 | "otghs_control"); |
230 | control_usb->otghs_control = devm_ioremap_resource( | 248 | control_usb->otghs_control = devm_ioremap_resource( |
231 | &pdev->dev, res); | 249 | &pdev->dev, res); |
232 | if (IS_ERR(control_usb->otghs_control)) | 250 | if (IS_ERR(control_usb->otghs_control)) |
233 | return PTR_ERR(control_usb->otghs_control); | 251 | return PTR_ERR(control_usb->otghs_control); |
234 | } | 252 | } else { |
235 | |||
236 | if (control_usb->type == OMAP_CTRL_DEV_TYPE2) { | ||
237 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 253 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
238 | "phy_power_usb"); | 254 | "power"); |
239 | control_usb->phy_power = devm_ioremap_resource( | 255 | control_usb->power = devm_ioremap_resource(&pdev->dev, res); |
240 | &pdev->dev, res); | 256 | if (IS_ERR(control_usb->power)) { |
241 | if (IS_ERR(control_usb->phy_power)) | 257 | dev_err(&pdev->dev, "Couldn't get power register\n"); |
242 | return PTR_ERR(control_usb->phy_power); | 258 | return PTR_ERR(control_usb->power); |
259 | } | ||
260 | } | ||
243 | 261 | ||
262 | if (control_usb->type == OMAP_CTRL_TYPE_PIPE3) { | ||
244 | control_usb->sys_clk = devm_clk_get(control_usb->dev, | 263 | control_usb->sys_clk = devm_clk_get(control_usb->dev, |
245 | "sys_clkin"); | 264 | "sys_clkin"); |
246 | if (IS_ERR(control_usb->sys_clk)) { | 265 | if (IS_ERR(control_usb->sys_clk)) { |
@@ -249,20 +268,11 @@ static int omap_control_usb_probe(struct platform_device *pdev) | |||
249 | } | 268 | } |
250 | } | 269 | } |
251 | 270 | ||
252 | |||
253 | dev_set_drvdata(control_usb->dev, control_usb); | 271 | dev_set_drvdata(control_usb->dev, control_usb); |
254 | 272 | ||
255 | return 0; | 273 | return 0; |
256 | } | 274 | } |
257 | 275 | ||
258 | #ifdef CONFIG_OF | ||
259 | static const struct of_device_id omap_control_usb_id_table[] = { | ||
260 | { .compatible = "ti,omap-control-usb" }, | ||
261 | {} | ||
262 | }; | ||
263 | MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); | ||
264 | #endif | ||
265 | |||
266 | static struct platform_driver omap_control_usb_driver = { | 276 | static struct platform_driver omap_control_usb_driver = { |
267 | .probe = omap_control_usb_probe, | 277 | .probe = omap_control_usb_probe, |
268 | .driver = { | 278 | .driver = { |
diff --git a/drivers/usb/phy/phy-omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c index 4e8a0405f956..0c6ba29bdddd 100644 --- a/drivers/usb/phy/phy-omap-usb3.c +++ b/drivers/usb/phy/phy-omap-usb3.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/pm_runtime.h> | 26 | #include <linux/pm_runtime.h> |
27 | #include <linux/delay.h> | 27 | #include <linux/delay.h> |
28 | #include <linux/usb/omap_control_usb.h> | 28 | #include <linux/usb/omap_control_usb.h> |
29 | #include <linux/of_platform.h> | ||
29 | 30 | ||
30 | #define PLL_STATUS 0x00000004 | 31 | #define PLL_STATUS 0x00000004 |
31 | #define PLL_GO 0x00000008 | 32 | #define PLL_GO 0x00000008 |
@@ -100,7 +101,7 @@ static int omap_usb3_suspend(struct usb_phy *x, int suspend) | |||
100 | udelay(1); | 101 | udelay(1); |
101 | } while (--timeout); | 102 | } while (--timeout); |
102 | 103 | ||
103 | omap_control_usb3_phy_power(phy->control_dev, 0); | 104 | omap_control_usb_phy_power(phy->control_dev, 0); |
104 | 105 | ||
105 | phy->is_suspended = 1; | 106 | phy->is_suspended = 1; |
106 | } else if (!suspend && phy->is_suspended) { | 107 | } else if (!suspend && phy->is_suspended) { |
@@ -189,15 +190,21 @@ static int omap_usb3_init(struct usb_phy *x) | |||
189 | if (ret) | 190 | if (ret) |
190 | return ret; | 191 | return ret; |
191 | 192 | ||
192 | omap_control_usb3_phy_power(phy->control_dev, 1); | 193 | omap_control_usb_phy_power(phy->control_dev, 1); |
193 | 194 | ||
194 | return 0; | 195 | return 0; |
195 | } | 196 | } |
196 | 197 | ||
197 | static int omap_usb3_probe(struct platform_device *pdev) | 198 | static int omap_usb3_probe(struct platform_device *pdev) |
198 | { | 199 | { |
199 | struct omap_usb *phy; | 200 | struct omap_usb *phy; |
200 | struct resource *res; | 201 | struct resource *res; |
202 | struct device_node *node = pdev->dev.of_node; | ||
203 | struct device_node *control_node; | ||
204 | struct platform_device *control_pdev; | ||
205 | |||
206 | if (!node) | ||
207 | return -EINVAL; | ||
201 | 208 | ||
202 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); | 209 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); |
203 | if (!phy) { | 210 | if (!phy) { |
@@ -239,13 +246,20 @@ static int omap_usb3_probe(struct platform_device *pdev) | |||
239 | return -EINVAL; | 246 | return -EINVAL; |
240 | } | 247 | } |
241 | 248 | ||
242 | phy->control_dev = omap_get_control_dev(); | 249 | control_node = of_parse_phandle(node, "ctrl-module", 0); |
243 | if (IS_ERR(phy->control_dev)) { | 250 | if (!control_node) { |
244 | dev_dbg(&pdev->dev, "Failed to get control device\n"); | 251 | dev_err(&pdev->dev, "Failed to get control device phandle\n"); |
245 | return -ENODEV; | 252 | return -EINVAL; |
246 | } | 253 | } |
254 | control_pdev = of_find_device_by_node(control_node); | ||
255 | if (!control_pdev) { | ||
256 | dev_err(&pdev->dev, "Failed to get control device\n"); | ||
257 | return -EINVAL; | ||
258 | } | ||
259 | |||
260 | phy->control_dev = &control_pdev->dev; | ||
247 | 261 | ||
248 | omap_control_usb3_phy_power(phy->control_dev, 0); | 262 | omap_control_usb_phy_power(phy->control_dev, 0); |
249 | usb_add_phy_dev(&phy->phy); | 263 | usb_add_phy_dev(&phy->phy); |
250 | 264 | ||
251 | platform_set_drvdata(pdev, phy); | 265 | platform_set_drvdata(pdev, phy); |
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c b/drivers/usb/phy/phy-rcar-gen2-usb.c new file mode 100644 index 000000000000..a99a6953f11c --- /dev/null +++ b/drivers/usb/phy/phy-rcar-gen2-usb.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /* | ||
2 | * Renesas R-Car Gen2 USB phy driver | ||
3 | * | ||
4 | * Copyright (C) 2013 Renesas Solutions Corp. | ||
5 | * Copyright (C) 2013 Cogent Embedded, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/clk.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/platform_data/usb-rcar-gen2-phy.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/spinlock.h> | ||
19 | #include <linux/usb/otg.h> | ||
20 | |||
21 | struct rcar_gen2_usb_phy_priv { | ||
22 | struct usb_phy phy; | ||
23 | void __iomem *base; | ||
24 | struct clk *clk; | ||
25 | spinlock_t lock; | ||
26 | int usecount; | ||
27 | u32 ugctrl2; | ||
28 | }; | ||
29 | |||
30 | #define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy) | ||
31 | |||
32 | /* Low Power Status register */ | ||
33 | #define USBHS_LPSTS_REG 0x02 | ||
34 | #define USBHS_LPSTS_SUSPM (1 << 14) | ||
35 | |||
36 | /* USB General control register */ | ||
37 | #define USBHS_UGCTRL_REG 0x80 | ||
38 | #define USBHS_UGCTRL_CONNECT (1 << 2) | ||
39 | #define USBHS_UGCTRL_PLLRESET (1 << 0) | ||
40 | |||
41 | /* USB General control register 2 */ | ||
42 | #define USBHS_UGCTRL2_REG 0x84 | ||
43 | #define USBHS_UGCTRL2_USB0_PCI (1 << 4) | ||
44 | #define USBHS_UGCTRL2_USB0_HS (3 << 4) | ||
45 | #define USBHS_UGCTRL2_USB2_PCI (0 << 31) | ||
46 | #define USBHS_UGCTRL2_USB2_SS (1 << 31) | ||
47 | |||
48 | /* USB General status register */ | ||
49 | #define USBHS_UGSTS_REG 0x88 | ||
50 | #define USBHS_UGSTS_LOCK (3 << 8) | ||
51 | |||
52 | /* Enable USBHS internal phy */ | ||
53 | static int __rcar_gen2_usbhs_phy_enable(void __iomem *base) | ||
54 | { | ||
55 | u32 val; | ||
56 | int i; | ||
57 | |||
58 | /* USBHS PHY power on */ | ||
59 | val = ioread32(base + USBHS_UGCTRL_REG); | ||
60 | val &= ~USBHS_UGCTRL_PLLRESET; | ||
61 | iowrite32(val, base + USBHS_UGCTRL_REG); | ||
62 | |||
63 | val = ioread16(base + USBHS_LPSTS_REG); | ||
64 | val |= USBHS_LPSTS_SUSPM; | ||
65 | iowrite16(val, base + USBHS_LPSTS_REG); | ||
66 | |||
67 | for (i = 0; i < 20; i++) { | ||
68 | val = ioread32(base + USBHS_UGSTS_REG); | ||
69 | if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) { | ||
70 | val = ioread32(base + USBHS_UGCTRL_REG); | ||
71 | val |= USBHS_UGCTRL_CONNECT; | ||
72 | iowrite32(val, base + USBHS_UGCTRL_REG); | ||
73 | return 0; | ||
74 | } | ||
75 | udelay(1); | ||
76 | } | ||
77 | |||
78 | /* Timed out waiting for the PLL lock */ | ||
79 | return -ETIMEDOUT; | ||
80 | } | ||
81 | |||
82 | /* Disable USBHS internal phy */ | ||
83 | static int __rcar_gen2_usbhs_phy_disable(void __iomem *base) | ||
84 | { | ||
85 | u32 val; | ||
86 | |||
87 | /* USBHS PHY power off */ | ||
88 | val = ioread32(base + USBHS_UGCTRL_REG); | ||
89 | val &= ~USBHS_UGCTRL_CONNECT; | ||
90 | iowrite32(val, base + USBHS_UGCTRL_REG); | ||
91 | |||
92 | val = ioread16(base + USBHS_LPSTS_REG); | ||
93 | val &= ~USBHS_LPSTS_SUSPM; | ||
94 | iowrite16(val, base + USBHS_LPSTS_REG); | ||
95 | |||
96 | val = ioread32(base + USBHS_UGCTRL_REG); | ||
97 | val |= USBHS_UGCTRL_PLLRESET; | ||
98 | iowrite32(val, base + USBHS_UGCTRL_REG); | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | /* Setup USB channels */ | ||
103 | static void __rcar_gen2_usb_phy_init(struct rcar_gen2_usb_phy_priv *priv) | ||
104 | { | ||
105 | u32 val; | ||
106 | |||
107 | clk_prepare_enable(priv->clk); | ||
108 | |||
109 | /* Set USB channels in the USBHS UGCTRL2 register */ | ||
110 | val = ioread32(priv->base); | ||
111 | val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS); | ||
112 | val |= priv->ugctrl2; | ||
113 | iowrite32(val, priv->base); | ||
114 | } | ||
115 | |||
116 | /* Shutdown USB channels */ | ||
117 | static void __rcar_gen2_usb_phy_shutdown(struct rcar_gen2_usb_phy_priv *priv) | ||
118 | { | ||
119 | __rcar_gen2_usbhs_phy_disable(priv->base); | ||
120 | clk_disable_unprepare(priv->clk); | ||
121 | } | ||
122 | |||
123 | static int rcar_gen2_usb_phy_set_suspend(struct usb_phy *phy, int suspend) | ||
124 | { | ||
125 | struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy); | ||
126 | unsigned long flags; | ||
127 | int retval; | ||
128 | |||
129 | spin_lock_irqsave(&priv->lock, flags); | ||
130 | retval = suspend ? __rcar_gen2_usbhs_phy_disable(priv->base) : | ||
131 | __rcar_gen2_usbhs_phy_enable(priv->base); | ||
132 | spin_unlock_irqrestore(&priv->lock, flags); | ||
133 | return retval; | ||
134 | } | ||
135 | |||
136 | static int rcar_gen2_usb_phy_init(struct usb_phy *phy) | ||
137 | { | ||
138 | struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy); | ||
139 | unsigned long flags; | ||
140 | |||
141 | spin_lock_irqsave(&priv->lock, flags); | ||
142 | /* | ||
143 | * Enable the clock and setup USB channels | ||
144 | * if it's the first user | ||
145 | */ | ||
146 | if (!priv->usecount++) | ||
147 | __rcar_gen2_usb_phy_init(priv); | ||
148 | spin_unlock_irqrestore(&priv->lock, flags); | ||
149 | return 0; | ||
150 | } | ||
151 | |||
152 | static void rcar_gen2_usb_phy_shutdown(struct usb_phy *phy) | ||
153 | { | ||
154 | struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy); | ||
155 | unsigned long flags; | ||
156 | |||
157 | spin_lock_irqsave(&priv->lock, flags); | ||
158 | if (!priv->usecount) { | ||
159 | dev_warn(phy->dev, "Trying to disable phy with 0 usecount\n"); | ||
160 | goto out; | ||
161 | } | ||
162 | |||
163 | /* Disable everything if it's the last user */ | ||
164 | if (!--priv->usecount) | ||
165 | __rcar_gen2_usb_phy_shutdown(priv); | ||
166 | out: | ||
167 | spin_unlock_irqrestore(&priv->lock, flags); | ||
168 | } | ||
169 | |||
170 | static int rcar_gen2_usb_phy_probe(struct platform_device *pdev) | ||
171 | { | ||
172 | struct device *dev = &pdev->dev; | ||
173 | struct rcar_gen2_phy_platform_data *pdata; | ||
174 | struct rcar_gen2_usb_phy_priv *priv; | ||
175 | struct resource *res; | ||
176 | void __iomem *base; | ||
177 | struct clk *clk; | ||
178 | int retval; | ||
179 | |||
180 | pdata = dev_get_platdata(&pdev->dev); | ||
181 | if (!pdata) { | ||
182 | dev_err(dev, "No platform data\n"); | ||
183 | return -EINVAL; | ||
184 | } | ||
185 | |||
186 | clk = devm_clk_get(&pdev->dev, "usbhs"); | ||
187 | if (IS_ERR(clk)) { | ||
188 | dev_err(&pdev->dev, "Can't get the clock\n"); | ||
189 | return PTR_ERR(clk); | ||
190 | } | ||
191 | |||
192 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
193 | base = devm_ioremap_resource(dev, res); | ||
194 | if (IS_ERR(base)) | ||
195 | return PTR_ERR(base); | ||
196 | |||
197 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
198 | if (!priv) { | ||
199 | dev_err(dev, "Memory allocation failed\n"); | ||
200 | return -ENOMEM; | ||
201 | } | ||
202 | |||
203 | spin_lock_init(&priv->lock); | ||
204 | priv->clk = clk; | ||
205 | priv->base = base; | ||
206 | priv->ugctrl2 = pdata->chan0_pci ? | ||
207 | USBHS_UGCTRL2_USB0_PCI : USBHS_UGCTRL2_USB0_HS; | ||
208 | priv->ugctrl2 |= pdata->chan2_pci ? | ||
209 | USBHS_UGCTRL2_USB2_PCI : USBHS_UGCTRL2_USB2_SS; | ||
210 | priv->phy.dev = dev; | ||
211 | priv->phy.label = dev_name(dev); | ||
212 | priv->phy.init = rcar_gen2_usb_phy_init; | ||
213 | priv->phy.shutdown = rcar_gen2_usb_phy_shutdown; | ||
214 | priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend; | ||
215 | |||
216 | retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); | ||
217 | if (retval < 0) { | ||
218 | dev_err(dev, "Failed to add USB phy\n"); | ||
219 | return retval; | ||
220 | } | ||
221 | |||
222 | platform_set_drvdata(pdev, priv); | ||
223 | |||
224 | return retval; | ||
225 | } | ||
226 | |||
227 | static int rcar_gen2_usb_phy_remove(struct platform_device *pdev) | ||
228 | { | ||
229 | struct rcar_gen2_usb_phy_priv *priv = platform_get_drvdata(pdev); | ||
230 | |||
231 | usb_remove_phy(&priv->phy); | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static struct platform_driver rcar_gen2_usb_phy_driver = { | ||
237 | .driver = { | ||
238 | .name = "usb_phy_rcar_gen2", | ||
239 | }, | ||
240 | .probe = rcar_gen2_usb_phy_probe, | ||
241 | .remove = rcar_gen2_usb_phy_remove, | ||
242 | }; | ||
243 | |||
244 | module_platform_driver(rcar_gen2_usb_phy_driver); | ||
245 | |||
246 | MODULE_LICENSE("GPL v2"); | ||
247 | MODULE_DESCRIPTION("Renesas R-Car Gen2 USB phy"); | ||
248 | MODULE_AUTHOR("Valentine Barshak <valentine.barshak@cogentembedded.com>"); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c index ff70e4b19b97..b3ba86627b72 100644 --- a/drivers/usb/phy/phy-samsung-usb2.c +++ b/drivers/usb/phy/phy-samsung-usb2.c | |||
@@ -411,6 +411,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev) | |||
411 | sphy->drv_data = drv_data; | 411 | sphy->drv_data = drv_data; |
412 | sphy->phy.dev = sphy->dev; | 412 | sphy->phy.dev = sphy->dev; |
413 | sphy->phy.label = "samsung-usb2phy"; | 413 | sphy->phy.label = "samsung-usb2phy"; |
414 | sphy->phy.type = USB_PHY_TYPE_USB2; | ||
414 | sphy->phy.init = samsung_usb2phy_init; | 415 | sphy->phy.init = samsung_usb2phy_init; |
415 | sphy->phy.shutdown = samsung_usb2phy_shutdown; | 416 | sphy->phy.shutdown = samsung_usb2phy_shutdown; |
416 | 417 | ||
@@ -426,7 +427,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev) | |||
426 | 427 | ||
427 | platform_set_drvdata(pdev, sphy); | 428 | platform_set_drvdata(pdev, sphy); |
428 | 429 | ||
429 | return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2); | 430 | return usb_add_phy_dev(&sphy->phy); |
430 | } | 431 | } |
431 | 432 | ||
432 | static int samsung_usb2phy_remove(struct platform_device *pdev) | 433 | static int samsung_usb2phy_remove(struct platform_device *pdev) |
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c index c6eb22213de6..cc0819248acf 100644 --- a/drivers/usb/phy/phy-samsung-usb3.c +++ b/drivers/usb/phy/phy-samsung-usb3.c | |||
@@ -271,6 +271,7 @@ static int samsung_usb3phy_probe(struct platform_device *pdev) | |||
271 | sphy->clk = clk; | 271 | sphy->clk = clk; |
272 | sphy->phy.dev = sphy->dev; | 272 | sphy->phy.dev = sphy->dev; |
273 | sphy->phy.label = "samsung-usb3phy"; | 273 | sphy->phy.label = "samsung-usb3phy"; |
274 | sphy->phy.type = USB_PHY_TYPE_USB3; | ||
274 | sphy->phy.init = samsung_usb3phy_init; | 275 | sphy->phy.init = samsung_usb3phy_init; |
275 | sphy->phy.shutdown = samsung_usb3phy_shutdown; | 276 | sphy->phy.shutdown = samsung_usb3phy_shutdown; |
276 | sphy->drv_data = samsung_usbphy_get_driver_data(pdev); | 277 | sphy->drv_data = samsung_usbphy_get_driver_data(pdev); |
@@ -283,7 +284,7 @@ static int samsung_usb3phy_probe(struct platform_device *pdev) | |||
283 | 284 | ||
284 | platform_set_drvdata(pdev, sphy); | 285 | platform_set_drvdata(pdev, sphy); |
285 | 286 | ||
286 | return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB3); | 287 | return usb_add_phy_dev(&sphy->phy); |
287 | } | 288 | } |
288 | 289 | ||
289 | static int samsung_usb3phy_remove(struct platform_device *pdev) | 290 | static int samsung_usb3phy_remove(struct platform_device *pdev) |
diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index e9cb1cb8abc7..82232acf1ab6 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c | |||
@@ -1090,7 +1090,7 @@ static struct platform_driver tegra_usb_phy_driver = { | |||
1090 | .driver = { | 1090 | .driver = { |
1091 | .name = "tegra-phy", | 1091 | .name = "tegra-phy", |
1092 | .owner = THIS_MODULE, | 1092 | .owner = THIS_MODULE, |
1093 | .of_match_table = of_match_ptr(tegra_usb_phy_id_table), | 1093 | .of_match_table = tegra_usb_phy_id_table, |
1094 | }, | 1094 | }, |
1095 | }; | 1095 | }; |
1096 | module_platform_driver(tegra_usb_phy_driver); | 1096 | module_platform_driver(tegra_usb_phy_driver); |
diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c index 16dbc9382678..30e8a61552d4 100644 --- a/drivers/usb/phy/phy-twl6030-usb.c +++ b/drivers/usb/phy/phy-twl6030-usb.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/err.h> | 33 | #include <linux/err.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <linux/of.h> | ||
36 | 37 | ||
37 | /* usb register definitions */ | 38 | /* usb register definitions */ |
38 | #define USB_VENDOR_ID_LSB 0x00 | 39 | #define USB_VENDOR_ID_LSB 0x00 |
diff --git a/drivers/usb/phy/phy-ulpi-viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c index 7c22a5390fc3..18bb8264b5a0 100644 --- a/drivers/usb/phy/phy-ulpi-viewport.c +++ b/drivers/usb/phy/phy-ulpi-viewport.c | |||
@@ -36,7 +36,7 @@ static int ulpi_viewport_wait(void __iomem *view, u32 mask) | |||
36 | return 0; | 36 | return 0; |
37 | 37 | ||
38 | udelay(1); | 38 | udelay(1); |
39 | }; | 39 | } |
40 | 40 | ||
41 | return -ETIMEDOUT; | 41 | return -ETIMEDOUT; |
42 | } | 42 | } |
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index a9984c700d2c..1b74523e1fee 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c | |||
@@ -98,7 +98,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type) | |||
98 | 98 | ||
99 | ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); | 99 | ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); |
100 | if (!ptr) | 100 | if (!ptr) |
101 | return NULL; | 101 | return ERR_PTR(-ENOMEM); |
102 | 102 | ||
103 | phy = usb_get_phy(type); | 103 | phy = usb_get_phy(type); |
104 | if (!IS_ERR(phy)) { | 104 | if (!IS_ERR(phy)) { |
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index 781426230d69..6e1b69d0f5f5 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c | |||
@@ -279,7 +279,7 @@ static void cyberjack_read_int_callback(struct urb *urb) | |||
279 | 279 | ||
280 | old_rdtodo = priv->rdtodo; | 280 | old_rdtodo = priv->rdtodo; |
281 | 281 | ||
282 | if (old_rdtodo + size < old_rdtodo) { | 282 | if (old_rdtodo > SHRT_MAX - size) { |
283 | dev_dbg(dev, "To many bulk_in urbs to do.\n"); | 283 | dev_dbg(dev, "To many bulk_in urbs to do.\n"); |
284 | spin_unlock(&priv->lock); | 284 | spin_unlock(&priv->lock); |
285 | goto resubmit; | 285 | goto resubmit; |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index b21d553c245b..9ced8937a8f3 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -1967,8 +1967,16 @@ static int ftdi_process_packet(struct usb_serial_port *port, | |||
1967 | port->icount.dsr++; | 1967 | port->icount.dsr++; |
1968 | if (diff_status & FTDI_RS0_RI) | 1968 | if (diff_status & FTDI_RS0_RI) |
1969 | port->icount.rng++; | 1969 | port->icount.rng++; |
1970 | if (diff_status & FTDI_RS0_RLSD) | 1970 | if (diff_status & FTDI_RS0_RLSD) { |
1971 | struct tty_struct *tty; | ||
1972 | |||
1971 | port->icount.dcd++; | 1973 | port->icount.dcd++; |
1974 | tty = tty_port_tty_get(&port->port); | ||
1975 | if (tty) | ||
1976 | usb_serial_handle_dcd_change(port, tty, | ||
1977 | status & FTDI_RS0_RLSD); | ||
1978 | tty_kref_put(tty); | ||
1979 | } | ||
1972 | 1980 | ||
1973 | wake_up_interruptible(&port->port.delta_msr_wait); | 1981 | wake_up_interruptible(&port->port.delta_msr_wait); |
1974 | priv->prev_status = status; | 1982 | priv->prev_status = status; |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 1f31e6b4c251..2b01ec8651c2 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -7,7 +7,6 @@ | |||
7 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License version | 8 | * modify it under the terms of the GNU General Public License version |
9 | * 2 as published by the Free Software Foundation. | 9 | * 2 as published by the Free Software Foundation. |
10 | * | ||
11 | */ | 10 | */ |
12 | 11 | ||
13 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
@@ -37,7 +36,6 @@ MODULE_PARM_DESC(product, "User specified USB idProduct"); | |||
37 | 36 | ||
38 | static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ | 37 | static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ |
39 | 38 | ||
40 | /* All of the device info needed for the Generic Serial Converter */ | ||
41 | struct usb_serial_driver usb_serial_generic_device = { | 39 | struct usb_serial_driver usb_serial_generic_device = { |
42 | .driver = { | 40 | .driver = { |
43 | .owner = THIS_MODULE, | 41 | .owner = THIS_MODULE, |
@@ -66,7 +64,6 @@ int usb_serial_generic_register(void) | |||
66 | generic_device_ids[0].match_flags = | 64 | generic_device_ids[0].match_flags = |
67 | USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; | 65 | USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; |
68 | 66 | ||
69 | /* register our generic driver with ourselves */ | ||
70 | retval = usb_serial_register_drivers(serial_drivers, | 67 | retval = usb_serial_register_drivers(serial_drivers, |
71 | "usbserial_generic", generic_device_ids); | 68 | "usbserial_generic", generic_device_ids); |
72 | #endif | 69 | #endif |
@@ -76,7 +73,6 @@ int usb_serial_generic_register(void) | |||
76 | void usb_serial_generic_deregister(void) | 73 | void usb_serial_generic_deregister(void) |
77 | { | 74 | { |
78 | #ifdef CONFIG_USB_SERIAL_GENERIC | 75 | #ifdef CONFIG_USB_SERIAL_GENERIC |
79 | /* remove our generic driver */ | ||
80 | usb_serial_deregister_drivers(serial_drivers); | 76 | usb_serial_deregister_drivers(serial_drivers); |
81 | #endif | 77 | #endif |
82 | } | 78 | } |
@@ -86,13 +82,11 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port | |||
86 | int result = 0; | 82 | int result = 0; |
87 | unsigned long flags; | 83 | unsigned long flags; |
88 | 84 | ||
89 | /* clear the throttle flags */ | ||
90 | spin_lock_irqsave(&port->lock, flags); | 85 | spin_lock_irqsave(&port->lock, flags); |
91 | port->throttled = 0; | 86 | port->throttled = 0; |
92 | port->throttle_req = 0; | 87 | port->throttle_req = 0; |
93 | spin_unlock_irqrestore(&port->lock, flags); | 88 | spin_unlock_irqrestore(&port->lock, flags); |
94 | 89 | ||
95 | /* if we have a bulk endpoint, start reading from it */ | ||
96 | if (port->bulk_in_size) | 90 | if (port->bulk_in_size) |
97 | result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); | 91 | result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); |
98 | 92 | ||
@@ -127,12 +121,16 @@ int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, | |||
127 | } | 121 | } |
128 | 122 | ||
129 | /** | 123 | /** |
130 | * usb_serial_generic_write_start - kick off an URB write | 124 | * usb_serial_generic_write_start - start writing buffered data |
131 | * @port: Pointer to the &struct usb_serial_port data | 125 | * @port: usb-serial port |
126 | * @mem_flags: flags to use for memory allocations | ||
127 | * | ||
128 | * Serialised using USB_SERIAL_WRITE_BUSY flag. | ||
132 | * | 129 | * |
133 | * Returns zero on success, or a negative errno value | 130 | * Return: Zero on success or if busy, otherwise a negative errno value. |
134 | */ | 131 | */ |
135 | static int usb_serial_generic_write_start(struct usb_serial_port *port) | 132 | int usb_serial_generic_write_start(struct usb_serial_port *port, |
133 | gfp_t mem_flags) | ||
136 | { | 134 | { |
137 | struct urb *urb; | 135 | struct urb *urb; |
138 | int count, result; | 136 | int count, result; |
@@ -163,7 +161,7 @@ retry: | |||
163 | spin_unlock_irqrestore(&port->lock, flags); | 161 | spin_unlock_irqrestore(&port->lock, flags); |
164 | 162 | ||
165 | clear_bit(i, &port->write_urbs_free); | 163 | clear_bit(i, &port->write_urbs_free); |
166 | result = usb_submit_urb(urb, GFP_ATOMIC); | 164 | result = usb_submit_urb(urb, mem_flags); |
167 | if (result) { | 165 | if (result) { |
168 | dev_err_console(port, "%s - error submitting urb: %d\n", | 166 | dev_err_console(port, "%s - error submitting urb: %d\n", |
169 | __func__, result); | 167 | __func__, result); |
@@ -175,34 +173,34 @@ retry: | |||
175 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); | 173 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
176 | return result; | 174 | return result; |
177 | } | 175 | } |
178 | 176 | /* | |
179 | /* Try sending off another urb, unless in irq context (in which case | 177 | * Try sending off another urb, unless called from completion handler |
180 | * there will be no free urb). */ | 178 | * (in which case there will be no free urb or no data). |
181 | if (!in_irq()) | 179 | */ |
180 | if (mem_flags != GFP_ATOMIC) | ||
182 | goto retry; | 181 | goto retry; |
183 | 182 | ||
184 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); | 183 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
185 | 184 | ||
186 | return 0; | 185 | return 0; |
187 | } | 186 | } |
187 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_start); | ||
188 | 188 | ||
189 | /** | 189 | /** |
190 | * usb_serial_generic_write - generic write function for serial USB devices | 190 | * usb_serial_generic_write - generic write function |
191 | * @tty: Pointer to &struct tty_struct for the device | 191 | * @tty: tty for the port |
192 | * @port: Pointer to the &usb_serial_port structure for the device | 192 | * @port: usb-serial port |
193 | * @buf: Pointer to the data to write | 193 | * @buf: data to write |
194 | * @count: Number of bytes to write | 194 | * @count: number of bytes to write |
195 | * | 195 | * |
196 | * Returns the number of characters actually written, which may be anything | 196 | * Return: The number of characters buffered, which may be anything from |
197 | * from zero to @count. If an error occurs, it returns the negative errno | 197 | * zero to @count, or a negative errno value. |
198 | * value. | ||
199 | */ | 198 | */ |
200 | int usb_serial_generic_write(struct tty_struct *tty, | 199 | int usb_serial_generic_write(struct tty_struct *tty, |
201 | struct usb_serial_port *port, const unsigned char *buf, int count) | 200 | struct usb_serial_port *port, const unsigned char *buf, int count) |
202 | { | 201 | { |
203 | int result; | 202 | int result; |
204 | 203 | ||
205 | /* only do something if we have a bulk out endpoint */ | ||
206 | if (!port->bulk_out_size) | 204 | if (!port->bulk_out_size) |
207 | return -ENODEV; | 205 | return -ENODEV; |
208 | 206 | ||
@@ -210,7 +208,7 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
210 | return 0; | 208 | return 0; |
211 | 209 | ||
212 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); | 210 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); |
213 | result = usb_serial_generic_write_start(port); | 211 | result = usb_serial_generic_write_start(port, GFP_KERNEL); |
214 | if (result) | 212 | if (result) |
215 | return result; | 213 | return result; |
216 | 214 | ||
@@ -337,10 +335,11 @@ void usb_serial_generic_process_read_urb(struct urb *urb) | |||
337 | 335 | ||
338 | if (!urb->actual_length) | 336 | if (!urb->actual_length) |
339 | return; | 337 | return; |
340 | 338 | /* | |
341 | /* The per character mucking around with sysrq path it too slow for | 339 | * The per character mucking around with sysrq path it too slow for |
342 | stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases | 340 | * stuff like 3G modems, so shortcircuit it in the 99.9999999% of |
343 | where the USB serial is not a console anyway */ | 341 | * cases where the USB serial is not a console anyway. |
342 | */ | ||
344 | if (!port->port.console || !port->sysrq) | 343 | if (!port->port.console || !port->sysrq) |
345 | tty_insert_flip_string(&port->port, ch, urb->actual_length); | 344 | tty_insert_flip_string(&port->port, ch, urb->actual_length); |
346 | else { | 345 | else { |
@@ -413,7 +412,7 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb) | |||
413 | kfifo_reset_out(&port->write_fifo); | 412 | kfifo_reset_out(&port->write_fifo); |
414 | spin_unlock_irqrestore(&port->lock, flags); | 413 | spin_unlock_irqrestore(&port->lock, flags); |
415 | } else { | 414 | } else { |
416 | usb_serial_generic_write_start(port); | 415 | usb_serial_generic_write_start(port, GFP_ATOMIC); |
417 | } | 416 | } |
418 | 417 | ||
419 | usb_serial_port_softint(port); | 418 | usb_serial_port_softint(port); |
@@ -425,8 +424,6 @@ void usb_serial_generic_throttle(struct tty_struct *tty) | |||
425 | struct usb_serial_port *port = tty->driver_data; | 424 | struct usb_serial_port *port = tty->driver_data; |
426 | unsigned long flags; | 425 | unsigned long flags; |
427 | 426 | ||
428 | /* Set the throttle request flag. It will be picked up | ||
429 | * by usb_serial_generic_read_bulk_callback(). */ | ||
430 | spin_lock_irqsave(&port->lock, flags); | 427 | spin_lock_irqsave(&port->lock, flags); |
431 | port->throttle_req = 1; | 428 | port->throttle_req = 1; |
432 | spin_unlock_irqrestore(&port->lock, flags); | 429 | spin_unlock_irqrestore(&port->lock, flags); |
@@ -438,7 +435,6 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty) | |||
438 | struct usb_serial_port *port = tty->driver_data; | 435 | struct usb_serial_port *port = tty->driver_data; |
439 | int was_throttled; | 436 | int was_throttled; |
440 | 437 | ||
441 | /* Clear the throttle flags */ | ||
442 | spin_lock_irq(&port->lock); | 438 | spin_lock_irq(&port->lock); |
443 | was_throttled = port->throttled; | 439 | was_throttled = port->throttled; |
444 | port->throttled = port->throttle_req = 0; | 440 | port->throttled = port->throttle_req = 0; |
@@ -558,10 +554,10 @@ int usb_serial_handle_break(struct usb_serial_port *port) | |||
558 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); | 554 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); |
559 | 555 | ||
560 | /** | 556 | /** |
561 | * usb_serial_handle_dcd_change - handle a change of carrier detect state | 557 | * usb_serial_handle_dcd_change - handle a change of carrier detect state |
562 | * @port: usb_serial_port structure for the open port | 558 | * @port: usb-serial port |
563 | * @tty: tty_struct structure for the port | 559 | * @tty: tty for the port |
564 | * @status: new carrier detect status, nonzero if active | 560 | * @status: new carrier detect status, nonzero if active |
565 | */ | 561 | */ |
566 | void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, | 562 | void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, |
567 | struct tty_struct *tty, unsigned int status) | 563 | struct tty_struct *tty, unsigned int status) |
@@ -570,6 +566,16 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, | |||
570 | 566 | ||
571 | dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status); | 567 | dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status); |
572 | 568 | ||
569 | if (tty) { | ||
570 | struct tty_ldisc *ld = tty_ldisc_ref(tty); | ||
571 | |||
572 | if (ld) { | ||
573 | if (ld->ops->dcd_change) | ||
574 | ld->ops->dcd_change(tty, status); | ||
575 | tty_ldisc_deref(ld); | ||
576 | } | ||
577 | } | ||
578 | |||
573 | if (status) | 579 | if (status) |
574 | wake_up_interruptible(&port->open_wait); | 580 | wake_up_interruptible(&port->open_wait); |
575 | else if (tty && !C_CLOCAL(tty)) | 581 | else if (tty && !C_CLOCAL(tty)) |
@@ -595,7 +601,7 @@ int usb_serial_generic_resume(struct usb_serial *serial) | |||
595 | } | 601 | } |
596 | 602 | ||
597 | if (port->bulk_out_size) { | 603 | if (port->bulk_out_size) { |
598 | r = usb_serial_generic_write_start(port); | 604 | r = usb_serial_generic_write_start(port, GFP_NOIO); |
599 | if (r < 0) | 605 | if (r < 0) |
600 | c++; | 606 | c++; |
601 | } | 607 | } |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index fdf953539c62..e5bdd987b9e8 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -1532,7 +1532,11 @@ static int mos7840_tiocmget(struct tty_struct *tty) | |||
1532 | return -ENODEV; | 1532 | return -ENODEV; |
1533 | 1533 | ||
1534 | status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); | 1534 | status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); |
1535 | if (status != 1) | ||
1536 | return -EIO; | ||
1535 | status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); | 1537 | status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); |
1538 | if (status != 1) | ||
1539 | return -EIO; | ||
1536 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | 1540 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) |
1537 | | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | 1541 | | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) |
1538 | | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) | 1542 | | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) |
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index acaee066b99a..c3d94853b4ab 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -1376,6 +1376,23 @@ static const struct usb_device_id option_ids[] = { | |||
1376 | .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, | 1376 | .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, |
1377 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */ | 1377 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */ |
1378 | .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, | 1378 | .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, |
1379 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1533, 0xff, 0xff, 0xff) }, | ||
1380 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1534, 0xff, 0xff, 0xff) }, | ||
1381 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1535, 0xff, 0xff, 0xff) }, | ||
1382 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1545, 0xff, 0xff, 0xff) }, | ||
1383 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1546, 0xff, 0xff, 0xff) }, | ||
1384 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1547, 0xff, 0xff, 0xff) }, | ||
1385 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1565, 0xff, 0xff, 0xff) }, | ||
1386 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1566, 0xff, 0xff, 0xff) }, | ||
1387 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1567, 0xff, 0xff, 0xff) }, | ||
1388 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1589, 0xff, 0xff, 0xff) }, | ||
1389 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1590, 0xff, 0xff, 0xff) }, | ||
1390 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1591, 0xff, 0xff, 0xff) }, | ||
1391 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1592, 0xff, 0xff, 0xff) }, | ||
1392 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1594, 0xff, 0xff, 0xff) }, | ||
1393 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1596, 0xff, 0xff, 0xff) }, | ||
1394 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1598, 0xff, 0xff, 0xff) }, | ||
1395 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1600, 0xff, 0xff, 0xff) }, | ||
1379 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, | 1396 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, |
1380 | 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist }, | 1397 | 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist }, |
1381 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, | 1398 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, |
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c index 7f78f300f8fb..f06ed82e63d1 100644 --- a/drivers/usb/wusbcore/cbaf.c +++ b/drivers/usb/wusbcore/cbaf.c | |||
@@ -208,9 +208,9 @@ static int cbaf_check(struct cbaf *cbaf) | |||
208 | ar_name = "ASSOCIATE"; | 208 | ar_name = "ASSOCIATE"; |
209 | ar_assoc = 1; | 209 | ar_assoc = 1; |
210 | break; | 210 | break; |
211 | }; | 211 | } |
212 | break; | 212 | break; |
213 | }; | 213 | } |
214 | 214 | ||
215 | dev_dbg(dev, "Association request #%02u: 0x%04x/%04x " | 215 | dev_dbg(dev, "Association request #%02u: 0x%04x/%04x " |
216 | "(%zu bytes): %s\n", | 216 | "(%zu bytes): %s\n", |
@@ -623,6 +623,8 @@ static int cbaf_probe(struct usb_interface *iface, | |||
623 | 623 | ||
624 | error_create_group: | 624 | error_create_group: |
625 | error_check: | 625 | error_check: |
626 | usb_put_intf(iface); | ||
627 | usb_put_dev(cbaf->usb_dev); | ||
626 | kfree(cbaf->buffer); | 628 | kfree(cbaf->buffer); |
627 | error_kmalloc_buffer: | 629 | error_kmalloc_buffer: |
628 | kfree(cbaf); | 630 | kfree(cbaf); |
@@ -637,6 +639,7 @@ static void cbaf_disconnect(struct usb_interface *iface) | |||
637 | sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group); | 639 | sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group); |
638 | usb_set_intfdata(iface, NULL); | 640 | usb_set_intfdata(iface, NULL); |
639 | usb_put_intf(iface); | 641 | usb_put_intf(iface); |
642 | usb_put_dev(cbaf->usb_dev); | ||
640 | kfree(cbaf->buffer); | 643 | kfree(cbaf->buffer); |
641 | /* paranoia: clean up crypto keys */ | 644 | /* paranoia: clean up crypto keys */ |
642 | kzfree(cbaf); | 645 | kzfree(cbaf); |
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c index 33a12788f9ca..e538b72c4e3a 100644 --- a/drivers/usb/wusbcore/devconnect.c +++ b/drivers/usb/wusbcore/devconnect.c | |||
@@ -973,7 +973,7 @@ int wusb_usb_ncb(struct notifier_block *nb, unsigned long val, | |||
973 | default: | 973 | default: |
974 | WARN_ON(1); | 974 | WARN_ON(1); |
975 | result = NOTIFY_BAD; | 975 | result = NOTIFY_BAD; |
976 | }; | 976 | } |
977 | return result; | 977 | return result; |
978 | } | 978 | } |
979 | 979 | ||
diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c index a09b65ebd9bb..368360f9a93a 100644 --- a/drivers/usb/wusbcore/wa-hc.c +++ b/drivers/usb/wusbcore/wa-hc.c | |||
@@ -33,7 +33,8 @@ | |||
33 | * wa->usb_dev and wa->usb_iface initialized and refcounted, | 33 | * wa->usb_dev and wa->usb_iface initialized and refcounted, |
34 | * wa->wa_descr initialized. | 34 | * wa->wa_descr initialized. |
35 | */ | 35 | */ |
36 | int wa_create(struct wahc *wa, struct usb_interface *iface) | 36 | int wa_create(struct wahc *wa, struct usb_interface *iface, |
37 | kernel_ulong_t quirks) | ||
37 | { | 38 | { |
38 | int result; | 39 | int result; |
39 | struct device *dev = &iface->dev; | 40 | struct device *dev = &iface->dev; |
@@ -41,14 +42,15 @@ int wa_create(struct wahc *wa, struct usb_interface *iface) | |||
41 | result = wa_rpipes_create(wa); | 42 | result = wa_rpipes_create(wa); |
42 | if (result < 0) | 43 | if (result < 0) |
43 | goto error_rpipes_create; | 44 | goto error_rpipes_create; |
45 | wa->quirks = quirks; | ||
44 | /* Fill up Data Transfer EP pointers */ | 46 | /* Fill up Data Transfer EP pointers */ |
45 | wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; | 47 | wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; |
46 | wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; | 48 | wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; |
47 | wa->xfer_result_size = usb_endpoint_maxp(wa->dti_epd); | 49 | wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd); |
48 | wa->xfer_result = kmalloc(wa->xfer_result_size, GFP_KERNEL); | 50 | wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL); |
49 | if (wa->xfer_result == NULL) { | 51 | if (wa->dti_buf == NULL) { |
50 | result = -ENOMEM; | 52 | result = -ENOMEM; |
51 | goto error_xfer_result_alloc; | 53 | goto error_dti_buf_alloc; |
52 | } | 54 | } |
53 | result = wa_nep_create(wa, iface); | 55 | result = wa_nep_create(wa, iface); |
54 | if (result < 0) { | 56 | if (result < 0) { |
@@ -59,8 +61,8 @@ int wa_create(struct wahc *wa, struct usb_interface *iface) | |||
59 | return 0; | 61 | return 0; |
60 | 62 | ||
61 | error_nep_create: | 63 | error_nep_create: |
62 | kfree(wa->xfer_result); | 64 | kfree(wa->dti_buf); |
63 | error_xfer_result_alloc: | 65 | error_dti_buf_alloc: |
64 | wa_rpipes_destroy(wa); | 66 | wa_rpipes_destroy(wa); |
65 | error_rpipes_create: | 67 | error_rpipes_create: |
66 | return result; | 68 | return result; |
@@ -76,7 +78,7 @@ void __wa_destroy(struct wahc *wa) | |||
76 | usb_kill_urb(wa->buf_in_urb); | 78 | usb_kill_urb(wa->buf_in_urb); |
77 | usb_put_urb(wa->buf_in_urb); | 79 | usb_put_urb(wa->buf_in_urb); |
78 | } | 80 | } |
79 | kfree(wa->xfer_result); | 81 | kfree(wa->dti_buf); |
80 | wa_nep_destroy(wa); | 82 | wa_nep_destroy(wa); |
81 | wa_rpipes_destroy(wa); | 83 | wa_rpipes_destroy(wa); |
82 | } | 84 | } |
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h index cf250c21e946..e614f02f0cf2 100644 --- a/drivers/usb/wusbcore/wa-hc.h +++ b/drivers/usb/wusbcore/wa-hc.h | |||
@@ -117,11 +117,25 @@ struct wa_rpipe { | |||
117 | struct wahc *wa; | 117 | struct wahc *wa; |
118 | spinlock_t seg_lock; | 118 | spinlock_t seg_lock; |
119 | struct list_head seg_list; | 119 | struct list_head seg_list; |
120 | struct list_head list_node; | ||
120 | atomic_t segs_available; | 121 | atomic_t segs_available; |
121 | u8 buffer[1]; /* For reads/writes on USB */ | 122 | u8 buffer[1]; /* For reads/writes on USB */ |
122 | }; | 123 | }; |
123 | 124 | ||
124 | 125 | ||
126 | enum wa_dti_state { | ||
127 | WA_DTI_TRANSFER_RESULT_PENDING, | ||
128 | WA_DTI_ISOC_PACKET_STATUS_PENDING | ||
129 | }; | ||
130 | |||
131 | enum wa_quirks { | ||
132 | /* | ||
133 | * The Alereon HWA expects the data frames in isochronous transfer | ||
134 | * requests to be concatenated and not sent as separate packets. | ||
135 | */ | ||
136 | WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC = 0x01, | ||
137 | }; | ||
138 | |||
125 | /** | 139 | /** |
126 | * Instance of a HWA Host Controller | 140 | * Instance of a HWA Host Controller |
127 | * | 141 | * |
@@ -178,14 +192,26 @@ struct wahc { | |||
178 | 192 | ||
179 | u16 rpipes; | 193 | u16 rpipes; |
180 | unsigned long *rpipe_bm; /* rpipe usage bitmap */ | 194 | unsigned long *rpipe_bm; /* rpipe usage bitmap */ |
181 | spinlock_t rpipe_bm_lock; /* protect rpipe_bm */ | 195 | struct list_head rpipe_delayed_list; /* delayed RPIPES. */ |
196 | spinlock_t rpipe_lock; /* protect rpipe_bm and delayed list */ | ||
182 | struct mutex rpipe_mutex; /* assigning resources to endpoints */ | 197 | struct mutex rpipe_mutex; /* assigning resources to endpoints */ |
183 | 198 | ||
199 | /* | ||
200 | * dti_state is used to track the state of the dti_urb. When dti_state | ||
201 | * is WA_DTI_ISOC_PACKET_STATUS_PENDING, dti_isoc_xfer_in_progress and | ||
202 | * dti_isoc_xfer_seg identify which xfer the incoming isoc packet status | ||
203 | * refers to. | ||
204 | */ | ||
205 | enum wa_dti_state dti_state; | ||
206 | u32 dti_isoc_xfer_in_progress; | ||
207 | u8 dti_isoc_xfer_seg; | ||
184 | struct urb *dti_urb; /* URB for reading xfer results */ | 208 | struct urb *dti_urb; /* URB for reading xfer results */ |
185 | struct urb *buf_in_urb; /* URB for reading data in */ | 209 | struct urb *buf_in_urb; /* URB for reading data in */ |
186 | struct edc dti_edc; /* DTI error density counter */ | 210 | struct edc dti_edc; /* DTI error density counter */ |
187 | struct wa_xfer_result *xfer_result; /* real size = dti_ep maxpktsize */ | 211 | void *dti_buf; |
188 | size_t xfer_result_size; | 212 | size_t dti_buf_size; |
213 | |||
214 | unsigned long dto_in_use; /* protect dto endoint serialization. */ | ||
189 | 215 | ||
190 | s32 status; /* For reading status */ | 216 | s32 status; /* For reading status */ |
191 | 217 | ||
@@ -200,10 +226,13 @@ struct wahc { | |||
200 | struct work_struct xfer_enqueue_work; | 226 | struct work_struct xfer_enqueue_work; |
201 | struct work_struct xfer_error_work; | 227 | struct work_struct xfer_error_work; |
202 | atomic_t xfer_id_count; | 228 | atomic_t xfer_id_count; |
229 | |||
230 | kernel_ulong_t quirks; | ||
203 | }; | 231 | }; |
204 | 232 | ||
205 | 233 | ||
206 | extern int wa_create(struct wahc *wa, struct usb_interface *iface); | 234 | extern int wa_create(struct wahc *wa, struct usb_interface *iface, |
235 | kernel_ulong_t); | ||
207 | extern void __wa_destroy(struct wahc *wa); | 236 | extern void __wa_destroy(struct wahc *wa); |
208 | void wa_reset_all(struct wahc *wa); | 237 | void wa_reset_all(struct wahc *wa); |
209 | 238 | ||
@@ -239,7 +268,8 @@ static inline void wa_nep_disarm(struct wahc *wa) | |||
239 | /* RPipes */ | 268 | /* RPipes */ |
240 | static inline void wa_rpipe_init(struct wahc *wa) | 269 | static inline void wa_rpipe_init(struct wahc *wa) |
241 | { | 270 | { |
242 | spin_lock_init(&wa->rpipe_bm_lock); | 271 | INIT_LIST_HEAD(&wa->rpipe_delayed_list); |
272 | spin_lock_init(&wa->rpipe_lock); | ||
243 | mutex_init(&wa->rpipe_mutex); | 273 | mutex_init(&wa->rpipe_mutex); |
244 | } | 274 | } |
245 | 275 | ||
@@ -247,6 +277,7 @@ static inline void wa_init(struct wahc *wa) | |||
247 | { | 277 | { |
248 | edc_init(&wa->nep_edc); | 278 | edc_init(&wa->nep_edc); |
249 | atomic_set(&wa->notifs_queued, 0); | 279 | atomic_set(&wa->notifs_queued, 0); |
280 | wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING; | ||
250 | wa_rpipe_init(wa); | 281 | wa_rpipe_init(wa); |
251 | edc_init(&wa->dti_edc); | 282 | edc_init(&wa->dti_edc); |
252 | INIT_LIST_HEAD(&wa->xfer_list); | 283 | INIT_LIST_HEAD(&wa->xfer_list); |
@@ -255,6 +286,7 @@ static inline void wa_init(struct wahc *wa) | |||
255 | spin_lock_init(&wa->xfer_list_lock); | 286 | spin_lock_init(&wa->xfer_list_lock); |
256 | INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run); | 287 | INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run); |
257 | INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run); | 288 | INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run); |
289 | wa->dto_in_use = 0; | ||
258 | atomic_set(&wa->xfer_id_count, 1); | 290 | atomic_set(&wa->xfer_id_count, 1); |
259 | } | 291 | } |
260 | 292 | ||
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c index fd4f1ce6256a..b48e74cc54d7 100644 --- a/drivers/usb/wusbcore/wa-rpipe.c +++ b/drivers/usb/wusbcore/wa-rpipe.c | |||
@@ -143,17 +143,18 @@ static void rpipe_init(struct wa_rpipe *rpipe) | |||
143 | kref_init(&rpipe->refcnt); | 143 | kref_init(&rpipe->refcnt); |
144 | spin_lock_init(&rpipe->seg_lock); | 144 | spin_lock_init(&rpipe->seg_lock); |
145 | INIT_LIST_HEAD(&rpipe->seg_list); | 145 | INIT_LIST_HEAD(&rpipe->seg_list); |
146 | INIT_LIST_HEAD(&rpipe->list_node); | ||
146 | } | 147 | } |
147 | 148 | ||
148 | static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx) | 149 | static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx) |
149 | { | 150 | { |
150 | unsigned long flags; | 151 | unsigned long flags; |
151 | 152 | ||
152 | spin_lock_irqsave(&wa->rpipe_bm_lock, flags); | 153 | spin_lock_irqsave(&wa->rpipe_lock, flags); |
153 | rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx); | 154 | rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx); |
154 | if (rpipe_idx < wa->rpipes) | 155 | if (rpipe_idx < wa->rpipes) |
155 | set_bit(rpipe_idx, wa->rpipe_bm); | 156 | set_bit(rpipe_idx, wa->rpipe_bm); |
156 | spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags); | 157 | spin_unlock_irqrestore(&wa->rpipe_lock, flags); |
157 | 158 | ||
158 | return rpipe_idx; | 159 | return rpipe_idx; |
159 | } | 160 | } |
@@ -162,9 +163,9 @@ static void rpipe_put_idx(struct wahc *wa, unsigned rpipe_idx) | |||
162 | { | 163 | { |
163 | unsigned long flags; | 164 | unsigned long flags; |
164 | 165 | ||
165 | spin_lock_irqsave(&wa->rpipe_bm_lock, flags); | 166 | spin_lock_irqsave(&wa->rpipe_lock, flags); |
166 | clear_bit(rpipe_idx, wa->rpipe_bm); | 167 | clear_bit(rpipe_idx, wa->rpipe_bm); |
167 | spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags); | 168 | spin_unlock_irqrestore(&wa->rpipe_lock, flags); |
168 | } | 169 | } |
169 | 170 | ||
170 | void rpipe_destroy(struct kref *_rpipe) | 171 | void rpipe_destroy(struct kref *_rpipe) |
@@ -333,7 +334,10 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa, | |||
333 | /* FIXME: compute so seg_size > ep->maxpktsize */ | 334 | /* FIXME: compute so seg_size > ep->maxpktsize */ |
334 | rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ | 335 | rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ |
335 | /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */ | 336 | /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */ |
336 | rpipe->descr.wMaxPacketSize = cpu_to_le16(ep->desc.wMaxPacketSize); | 337 | if (usb_endpoint_xfer_isoc(&ep->desc)) |
338 | rpipe->descr.wMaxPacketSize = epcd->wOverTheAirPacketSize; | ||
339 | else | ||
340 | rpipe->descr.wMaxPacketSize = ep->desc.wMaxPacketSize; | ||
337 | 341 | ||
338 | rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int, | 342 | rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int, |
339 | epcd->bMaxBurst, 16U), 1U); | 343 | epcd->bMaxBurst, 16U), 1U); |
@@ -361,8 +365,10 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa, | |||
361 | epcd->bMaxSequence, 32U), 2U); | 365 | epcd->bMaxSequence, 32U), 2U); |
362 | rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1; | 366 | rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1; |
363 | rpipe->descr.bInterval = ep->desc.bInterval; | 367 | rpipe->descr.bInterval = ep->desc.bInterval; |
364 | /* FIXME: bOverTheAirInterval */ | 368 | if (usb_endpoint_xfer_isoc(&ep->desc)) |
365 | rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */ | 369 | rpipe->descr.bOverTheAirInterval = epcd->bOverTheAirInterval; |
370 | else | ||
371 | rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */ | ||
366 | /* FIXME: xmit power & preamble blah blah */ | 372 | /* FIXME: xmit power & preamble blah blah */ |
367 | rpipe->descr.bmAttribute = (ep->desc.bmAttributes & | 373 | rpipe->descr.bmAttribute = (ep->desc.bmAttributes & |
368 | USB_ENDPOINT_XFERTYPE_MASK); | 374 | USB_ENDPOINT_XFERTYPE_MASK); |
@@ -477,7 +483,7 @@ error: | |||
477 | */ | 483 | */ |
478 | int wa_rpipes_create(struct wahc *wa) | 484 | int wa_rpipes_create(struct wahc *wa) |
479 | { | 485 | { |
480 | wa->rpipes = wa->wa_descr->wNumRPipes; | 486 | wa->rpipes = le16_to_cpu(wa->wa_descr->wNumRPipes); |
481 | wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long), | 487 | wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long), |
482 | GFP_KERNEL); | 488 | GFP_KERNEL); |
483 | if (wa->rpipe_bm == NULL) | 489 | if (wa->rpipe_bm == NULL) |
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c index 6ad02f57c366..ed5abe87b049 100644 --- a/drivers/usb/wusbcore/wa-xfer.c +++ b/drivers/usb/wusbcore/wa-xfer.c | |||
@@ -91,7 +91,8 @@ | |||
91 | #include "wusbhc.h" | 91 | #include "wusbhc.h" |
92 | 92 | ||
93 | enum { | 93 | enum { |
94 | WA_SEGS_MAX = 255, | 94 | /* [WUSB] section 8.3.3 allocates 7 bits for the segment index. */ |
95 | WA_SEGS_MAX = 128, | ||
95 | }; | 96 | }; |
96 | 97 | ||
97 | enum wa_seg_status { | 98 | enum wa_seg_status { |
@@ -107,6 +108,7 @@ enum wa_seg_status { | |||
107 | }; | 108 | }; |
108 | 109 | ||
109 | static void wa_xfer_delayed_run(struct wa_rpipe *); | 110 | static void wa_xfer_delayed_run(struct wa_rpipe *); |
111 | static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting); | ||
110 | 112 | ||
111 | /* | 113 | /* |
112 | * Life cycle governed by 'struct urb' (the refcount of the struct is | 114 | * Life cycle governed by 'struct urb' (the refcount of the struct is |
@@ -114,24 +116,27 @@ static void wa_xfer_delayed_run(struct wa_rpipe *); | |||
114 | * struct). | 116 | * struct). |
115 | */ | 117 | */ |
116 | struct wa_seg { | 118 | struct wa_seg { |
117 | struct urb urb; | 119 | struct urb tr_urb; /* transfer request urb. */ |
118 | struct urb *dto_urb; /* for data output? */ | 120 | struct urb *isoc_pack_desc_urb; /* for isoc packet descriptor. */ |
121 | struct urb *dto_urb; /* for data output. */ | ||
119 | struct list_head list_node; /* for rpipe->req_list */ | 122 | struct list_head list_node; /* for rpipe->req_list */ |
120 | struct wa_xfer *xfer; /* out xfer */ | 123 | struct wa_xfer *xfer; /* out xfer */ |
121 | u8 index; /* which segment we are */ | 124 | u8 index; /* which segment we are */ |
125 | int isoc_frame_count; /* number of isoc frames in this segment. */ | ||
126 | int isoc_frame_offset; /* starting frame offset in the xfer URB. */ | ||
127 | int isoc_size; /* size of all isoc frames sent by this seg. */ | ||
122 | enum wa_seg_status status; | 128 | enum wa_seg_status status; |
123 | ssize_t result; /* bytes xfered or error */ | 129 | ssize_t result; /* bytes xfered or error */ |
124 | struct wa_xfer_hdr xfer_hdr; | 130 | struct wa_xfer_hdr xfer_hdr; |
125 | u8 xfer_extra[]; /* xtra space for xfer_hdr_ctl */ | ||
126 | }; | 131 | }; |
127 | 132 | ||
128 | static inline void wa_seg_init(struct wa_seg *seg) | 133 | static inline void wa_seg_init(struct wa_seg *seg) |
129 | { | 134 | { |
130 | usb_init_urb(&seg->urb); | 135 | usb_init_urb(&seg->tr_urb); |
131 | 136 | ||
132 | /* set the remaining memory to 0. */ | 137 | /* set the remaining memory to 0. */ |
133 | memset(((void *)seg) + sizeof(seg->urb), 0, | 138 | memset(((void *)seg) + sizeof(seg->tr_urb), 0, |
134 | sizeof(*seg) - sizeof(seg->urb)); | 139 | sizeof(*seg) - sizeof(seg->tr_urb)); |
135 | } | 140 | } |
136 | 141 | ||
137 | /* | 142 | /* |
@@ -153,12 +158,17 @@ struct wa_xfer { | |||
153 | unsigned is_dma:1; | 158 | unsigned is_dma:1; |
154 | size_t seg_size; | 159 | size_t seg_size; |
155 | int result; | 160 | int result; |
161 | /* Isoc frame that the current transfer buffer corresponds to. */ | ||
162 | int dto_isoc_frame_index; | ||
156 | 163 | ||
157 | gfp_t gfp; /* allocation mask */ | 164 | gfp_t gfp; /* allocation mask */ |
158 | 165 | ||
159 | struct wusb_dev *wusb_dev; /* for activity timestamps */ | 166 | struct wusb_dev *wusb_dev; /* for activity timestamps */ |
160 | }; | 167 | }; |
161 | 168 | ||
169 | static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer, | ||
170 | struct wa_seg *seg, int curr_iso_frame); | ||
171 | |||
162 | static inline void wa_xfer_init(struct wa_xfer *xfer) | 172 | static inline void wa_xfer_init(struct wa_xfer *xfer) |
163 | { | 173 | { |
164 | kref_init(&xfer->refcnt); | 174 | kref_init(&xfer->refcnt); |
@@ -169,7 +179,7 @@ static inline void wa_xfer_init(struct wa_xfer *xfer) | |||
169 | /* | 179 | /* |
170 | * Destroy a transfer structure | 180 | * Destroy a transfer structure |
171 | * | 181 | * |
172 | * Note that freeing xfer->seg[cnt]->urb will free the containing | 182 | * Note that freeing xfer->seg[cnt]->tr_urb will free the containing |
173 | * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs. | 183 | * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs. |
174 | */ | 184 | */ |
175 | static void wa_xfer_destroy(struct kref *_xfer) | 185 | static void wa_xfer_destroy(struct kref *_xfer) |
@@ -178,9 +188,17 @@ static void wa_xfer_destroy(struct kref *_xfer) | |||
178 | if (xfer->seg) { | 188 | if (xfer->seg) { |
179 | unsigned cnt; | 189 | unsigned cnt; |
180 | for (cnt = 0; cnt < xfer->segs; cnt++) { | 190 | for (cnt = 0; cnt < xfer->segs; cnt++) { |
181 | usb_free_urb(xfer->seg[cnt]->dto_urb); | 191 | struct wa_seg *seg = xfer->seg[cnt]; |
182 | usb_free_urb(&xfer->seg[cnt]->urb); | 192 | if (seg) { |
193 | usb_free_urb(seg->isoc_pack_desc_urb); | ||
194 | if (seg->dto_urb) { | ||
195 | kfree(seg->dto_urb->sg); | ||
196 | usb_free_urb(seg->dto_urb); | ||
197 | } | ||
198 | usb_free_urb(&seg->tr_urb); | ||
199 | } | ||
183 | } | 200 | } |
201 | kfree(xfer->seg); | ||
184 | } | 202 | } |
185 | kfree(xfer); | 203 | kfree(xfer); |
186 | } | 204 | } |
@@ -196,6 +214,59 @@ static void wa_xfer_put(struct wa_xfer *xfer) | |||
196 | } | 214 | } |
197 | 215 | ||
198 | /* | 216 | /* |
217 | * Try to get exclusive access to the DTO endpoint resource. Return true | ||
218 | * if successful. | ||
219 | */ | ||
220 | static inline int __wa_dto_try_get(struct wahc *wa) | ||
221 | { | ||
222 | return (test_and_set_bit(0, &wa->dto_in_use) == 0); | ||
223 | } | ||
224 | |||
225 | /* Release the DTO endpoint resource. */ | ||
226 | static inline void __wa_dto_put(struct wahc *wa) | ||
227 | { | ||
228 | clear_bit_unlock(0, &wa->dto_in_use); | ||
229 | } | ||
230 | |||
231 | /* Service RPIPEs that are waiting on the DTO resource. */ | ||
232 | static void wa_check_for_delayed_rpipes(struct wahc *wa) | ||
233 | { | ||
234 | unsigned long flags; | ||
235 | int dto_waiting = 0; | ||
236 | struct wa_rpipe *rpipe; | ||
237 | |||
238 | spin_lock_irqsave(&wa->rpipe_lock, flags); | ||
239 | while (!list_empty(&wa->rpipe_delayed_list) && !dto_waiting) { | ||
240 | rpipe = list_first_entry(&wa->rpipe_delayed_list, | ||
241 | struct wa_rpipe, list_node); | ||
242 | __wa_xfer_delayed_run(rpipe, &dto_waiting); | ||
243 | /* remove this RPIPE from the list if it is not waiting. */ | ||
244 | if (!dto_waiting) { | ||
245 | pr_debug("%s: RPIPE %d serviced and removed from delayed list.\n", | ||
246 | __func__, | ||
247 | le16_to_cpu(rpipe->descr.wRPipeIndex)); | ||
248 | list_del_init(&rpipe->list_node); | ||
249 | } | ||
250 | } | ||
251 | spin_unlock_irqrestore(&wa->rpipe_lock, flags); | ||
252 | } | ||
253 | |||
254 | /* add this RPIPE to the end of the delayed RPIPE list. */ | ||
255 | static void wa_add_delayed_rpipe(struct wahc *wa, struct wa_rpipe *rpipe) | ||
256 | { | ||
257 | unsigned long flags; | ||
258 | |||
259 | spin_lock_irqsave(&wa->rpipe_lock, flags); | ||
260 | /* add rpipe to the list if it is not already on it. */ | ||
261 | if (list_empty(&rpipe->list_node)) { | ||
262 | pr_debug("%s: adding RPIPE %d to the delayed list.\n", | ||
263 | __func__, le16_to_cpu(rpipe->descr.wRPipeIndex)); | ||
264 | list_add_tail(&rpipe->list_node, &wa->rpipe_delayed_list); | ||
265 | } | ||
266 | spin_unlock_irqrestore(&wa->rpipe_lock, flags); | ||
267 | } | ||
268 | |||
269 | /* | ||
199 | * xfer is referenced | 270 | * xfer is referenced |
200 | * | 271 | * |
201 | * xfer->lock has to be unlocked | 272 | * xfer->lock has to be unlocked |
@@ -232,6 +303,31 @@ static void wa_xfer_completion(struct wa_xfer *xfer) | |||
232 | } | 303 | } |
233 | 304 | ||
234 | /* | 305 | /* |
306 | * Initialize a transfer's ID | ||
307 | * | ||
308 | * We need to use a sequential number; if we use the pointer or the | ||
309 | * hash of the pointer, it can repeat over sequential transfers and | ||
310 | * then it will confuse the HWA....wonder why in hell they put a 32 | ||
311 | * bit handle in there then. | ||
312 | */ | ||
313 | static void wa_xfer_id_init(struct wa_xfer *xfer) | ||
314 | { | ||
315 | xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count); | ||
316 | } | ||
317 | |||
318 | /* Return the xfer's ID. */ | ||
319 | static inline u32 wa_xfer_id(struct wa_xfer *xfer) | ||
320 | { | ||
321 | return xfer->id; | ||
322 | } | ||
323 | |||
324 | /* Return the xfer's ID in transport format (little endian). */ | ||
325 | static inline __le32 wa_xfer_id_le32(struct wa_xfer *xfer) | ||
326 | { | ||
327 | return cpu_to_le32(xfer->id); | ||
328 | } | ||
329 | |||
330 | /* | ||
235 | * If transfer is done, wrap it up and return true | 331 | * If transfer is done, wrap it up and return true |
236 | * | 332 | * |
237 | * xfer->lock has to be locked | 333 | * xfer->lock has to be locked |
@@ -253,33 +349,37 @@ static unsigned __wa_xfer_is_done(struct wa_xfer *xfer) | |||
253 | switch (seg->status) { | 349 | switch (seg->status) { |
254 | case WA_SEG_DONE: | 350 | case WA_SEG_DONE: |
255 | if (found_short && seg->result > 0) { | 351 | if (found_short && seg->result > 0) { |
256 | dev_dbg(dev, "xfer %p#%u: bad short segments (%zu)\n", | 352 | dev_dbg(dev, "xfer %p ID %08X#%u: bad short segments (%zu)\n", |
257 | xfer, cnt, seg->result); | 353 | xfer, wa_xfer_id(xfer), cnt, |
354 | seg->result); | ||
258 | urb->status = -EINVAL; | 355 | urb->status = -EINVAL; |
259 | goto out; | 356 | goto out; |
260 | } | 357 | } |
261 | urb->actual_length += seg->result; | 358 | urb->actual_length += seg->result; |
262 | if (seg->result < xfer->seg_size | 359 | if (!(usb_pipeisoc(xfer->urb->pipe)) |
360 | && seg->result < xfer->seg_size | ||
263 | && cnt != xfer->segs-1) | 361 | && cnt != xfer->segs-1) |
264 | found_short = 1; | 362 | found_short = 1; |
265 | dev_dbg(dev, "xfer %p#%u: DONE short %d " | 363 | dev_dbg(dev, "xfer %p ID %08X#%u: DONE short %d " |
266 | "result %zu urb->actual_length %d\n", | 364 | "result %zu urb->actual_length %d\n", |
267 | xfer, seg->index, found_short, seg->result, | 365 | xfer, wa_xfer_id(xfer), seg->index, found_short, |
268 | urb->actual_length); | 366 | seg->result, urb->actual_length); |
269 | break; | 367 | break; |
270 | case WA_SEG_ERROR: | 368 | case WA_SEG_ERROR: |
271 | xfer->result = seg->result; | 369 | xfer->result = seg->result; |
272 | dev_dbg(dev, "xfer %p#%u: ERROR result %zu\n", | 370 | dev_dbg(dev, "xfer %p ID %08X#%u: ERROR result %zu(0x%08zX)\n", |
273 | xfer, seg->index, seg->result); | 371 | xfer, wa_xfer_id(xfer), seg->index, seg->result, |
372 | seg->result); | ||
274 | goto out; | 373 | goto out; |
275 | case WA_SEG_ABORTED: | 374 | case WA_SEG_ABORTED: |
276 | dev_dbg(dev, "xfer %p#%u ABORTED: result %d\n", | 375 | dev_dbg(dev, "xfer %p ID %08X#%u ABORTED: result %d\n", |
277 | xfer, seg->index, urb->status); | 376 | xfer, wa_xfer_id(xfer), seg->index, |
377 | urb->status); | ||
278 | xfer->result = urb->status; | 378 | xfer->result = urb->status; |
279 | goto out; | 379 | goto out; |
280 | default: | 380 | default: |
281 | dev_warn(dev, "xfer %p#%u: is_done bad state %d\n", | 381 | dev_warn(dev, "xfer %p ID %08X#%u: is_done bad state %d\n", |
282 | xfer, cnt, seg->status); | 382 | xfer, wa_xfer_id(xfer), cnt, seg->status); |
283 | xfer->result = -EINVAL; | 383 | xfer->result = -EINVAL; |
284 | goto out; | 384 | goto out; |
285 | } | 385 | } |
@@ -290,29 +390,6 @@ out: | |||
290 | } | 390 | } |
291 | 391 | ||
292 | /* | 392 | /* |
293 | * Initialize a transfer's ID | ||
294 | * | ||
295 | * We need to use a sequential number; if we use the pointer or the | ||
296 | * hash of the pointer, it can repeat over sequential transfers and | ||
297 | * then it will confuse the HWA....wonder why in hell they put a 32 | ||
298 | * bit handle in there then. | ||
299 | */ | ||
300 | static void wa_xfer_id_init(struct wa_xfer *xfer) | ||
301 | { | ||
302 | xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count); | ||
303 | } | ||
304 | |||
305 | /* | ||
306 | * Return the xfer's ID associated with xfer | ||
307 | * | ||
308 | * Need to generate a | ||
309 | */ | ||
310 | static u32 wa_xfer_id(struct wa_xfer *xfer) | ||
311 | { | ||
312 | return xfer->id; | ||
313 | } | ||
314 | |||
315 | /* | ||
316 | * Search for a transfer list ID on the HCD's URB list | 393 | * Search for a transfer list ID on the HCD's URB list |
317 | * | 394 | * |
318 | * For 32 bit architectures, we use the pointer itself; for 64 bits, a | 395 | * For 32 bit architectures, we use the pointer itself; for 64 bits, a |
@@ -356,15 +433,11 @@ static void __wa_xfer_abort_cb(struct urb *urb) | |||
356 | * | 433 | * |
357 | * The callback (see above) does nothing but freeing up the data by | 434 | * The callback (see above) does nothing but freeing up the data by |
358 | * putting the URB. Because the URB is allocated at the head of the | 435 | * putting the URB. Because the URB is allocated at the head of the |
359 | * struct, the whole space we allocated is kfreed. | 436 | * struct, the whole space we allocated is kfreed. * |
360 | * | ||
361 | * We'll get an 'aborted transaction' xfer result on DTI, that'll | ||
362 | * politely ignore because at this point the transaction has been | ||
363 | * marked as aborted already. | ||
364 | */ | 437 | */ |
365 | static void __wa_xfer_abort(struct wa_xfer *xfer) | 438 | static int __wa_xfer_abort(struct wa_xfer *xfer) |
366 | { | 439 | { |
367 | int result; | 440 | int result = -ENOMEM; |
368 | struct device *dev = &xfer->wa->usb_iface->dev; | 441 | struct device *dev = &xfer->wa->usb_iface->dev; |
369 | struct wa_xfer_abort_buffer *b; | 442 | struct wa_xfer_abort_buffer *b; |
370 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; | 443 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; |
@@ -375,7 +448,7 @@ static void __wa_xfer_abort(struct wa_xfer *xfer) | |||
375 | b->cmd.bLength = sizeof(b->cmd); | 448 | b->cmd.bLength = sizeof(b->cmd); |
376 | b->cmd.bRequestType = WA_XFER_ABORT; | 449 | b->cmd.bRequestType = WA_XFER_ABORT; |
377 | b->cmd.wRPipe = rpipe->descr.wRPipeIndex; | 450 | b->cmd.wRPipe = rpipe->descr.wRPipeIndex; |
378 | b->cmd.dwTransferID = wa_xfer_id(xfer); | 451 | b->cmd.dwTransferID = wa_xfer_id_le32(xfer); |
379 | 452 | ||
380 | usb_init_urb(&b->urb); | 453 | usb_init_urb(&b->urb); |
381 | usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev, | 454 | usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev, |
@@ -385,7 +458,7 @@ static void __wa_xfer_abort(struct wa_xfer *xfer) | |||
385 | result = usb_submit_urb(&b->urb, GFP_ATOMIC); | 458 | result = usb_submit_urb(&b->urb, GFP_ATOMIC); |
386 | if (result < 0) | 459 | if (result < 0) |
387 | goto error_submit; | 460 | goto error_submit; |
388 | return; /* callback frees! */ | 461 | return result; /* callback frees! */ |
389 | 462 | ||
390 | 463 | ||
391 | error_submit: | 464 | error_submit: |
@@ -394,11 +467,52 @@ error_submit: | |||
394 | xfer, result); | 467 | xfer, result); |
395 | kfree(b); | 468 | kfree(b); |
396 | error_kmalloc: | 469 | error_kmalloc: |
397 | return; | 470 | return result; |
398 | 471 | ||
399 | } | 472 | } |
400 | 473 | ||
401 | /* | 474 | /* |
475 | * Calculate the number of isoc frames starting from isoc_frame_offset | ||
476 | * that will fit a in transfer segment. | ||
477 | */ | ||
478 | static int __wa_seg_calculate_isoc_frame_count(struct wa_xfer *xfer, | ||
479 | int isoc_frame_offset, int *total_size) | ||
480 | { | ||
481 | int segment_size = 0, frame_count = 0; | ||
482 | int index = isoc_frame_offset; | ||
483 | struct usb_iso_packet_descriptor *iso_frame_desc = | ||
484 | xfer->urb->iso_frame_desc; | ||
485 | |||
486 | while ((index < xfer->urb->number_of_packets) | ||
487 | && ((segment_size + iso_frame_desc[index].length) | ||
488 | <= xfer->seg_size)) { | ||
489 | /* | ||
490 | * For Alereon HWA devices, only include an isoc frame in a | ||
491 | * segment if it is physically contiguous with the previous | ||
492 | * frame. This is required because those devices expect | ||
493 | * the isoc frames to be sent as a single USB transaction as | ||
494 | * opposed to one transaction per frame with standard HWA. | ||
495 | */ | ||
496 | if ((xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) | ||
497 | && (index > isoc_frame_offset) | ||
498 | && ((iso_frame_desc[index - 1].offset + | ||
499 | iso_frame_desc[index - 1].length) != | ||
500 | iso_frame_desc[index].offset)) | ||
501 | break; | ||
502 | |||
503 | /* this frame fits. count it. */ | ||
504 | ++frame_count; | ||
505 | segment_size += iso_frame_desc[index].length; | ||
506 | |||
507 | /* move to the next isoc frame. */ | ||
508 | ++index; | ||
509 | } | ||
510 | |||
511 | *total_size = segment_size; | ||
512 | return frame_count; | ||
513 | } | ||
514 | |||
515 | /* | ||
402 | * | 516 | * |
403 | * @returns < 0 on error, transfer segment request size if ok | 517 | * @returns < 0 on error, transfer segment request size if ok |
404 | */ | 518 | */ |
@@ -422,43 +536,92 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer, | |||
422 | result = sizeof(struct wa_xfer_bi); | 536 | result = sizeof(struct wa_xfer_bi); |
423 | break; | 537 | break; |
424 | case USB_ENDPOINT_XFER_ISOC: | 538 | case USB_ENDPOINT_XFER_ISOC: |
425 | dev_err(dev, "FIXME: ISOC not implemented\n"); | 539 | if (usb_pipeout(urb->pipe)) { |
426 | result = -ENOSYS; | 540 | *pxfer_type = WA_XFER_TYPE_ISO; |
427 | goto error; | 541 | result = sizeof(struct wa_xfer_hwaiso); |
542 | } else { | ||
543 | dev_err(dev, "FIXME: ISOC IN not implemented\n"); | ||
544 | result = -ENOSYS; | ||
545 | goto error; | ||
546 | } | ||
547 | break; | ||
428 | default: | 548 | default: |
429 | /* never happens */ | 549 | /* never happens */ |
430 | BUG(); | 550 | BUG(); |
431 | result = -EINVAL; /* shut gcc up */ | 551 | result = -EINVAL; /* shut gcc up */ |
432 | }; | 552 | } |
433 | xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0; | 553 | xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0; |
434 | xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; | 554 | xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; |
435 | xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) | 555 | |
436 | * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1); | ||
437 | /* Compute the segment size and make sure it is a multiple of | ||
438 | * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of | ||
439 | * a check (FIXME) */ | ||
440 | maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); | 556 | maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); |
441 | if (xfer->seg_size < maxpktsize) { | 557 | if ((rpipe->descr.bmAttribute & 0x3) == USB_ENDPOINT_XFER_ISOC) { |
442 | dev_err(dev, "HW BUG? seg_size %zu smaller than maxpktsize " | 558 | int index = 0; |
443 | "%zu\n", xfer->seg_size, maxpktsize); | 559 | |
444 | result = -EINVAL; | 560 | xfer->seg_size = maxpktsize; |
445 | goto error; | 561 | xfer->segs = 0; |
562 | /* | ||
563 | * loop over urb->number_of_packets to determine how many | ||
564 | * xfer segments will be needed to send the isoc frames. | ||
565 | */ | ||
566 | while (index < urb->number_of_packets) { | ||
567 | int seg_size; /* don't care. */ | ||
568 | index += __wa_seg_calculate_isoc_frame_count(xfer, | ||
569 | index, &seg_size); | ||
570 | ++xfer->segs; | ||
571 | } | ||
572 | } else { | ||
573 | xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) | ||
574 | * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1); | ||
575 | /* Compute the segment size and make sure it is a multiple of | ||
576 | * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of | ||
577 | * a check (FIXME) */ | ||
578 | if (xfer->seg_size < maxpktsize) { | ||
579 | dev_err(dev, | ||
580 | "HW BUG? seg_size %zu smaller than maxpktsize %zu\n", | ||
581 | xfer->seg_size, maxpktsize); | ||
582 | result = -EINVAL; | ||
583 | goto error; | ||
584 | } | ||
585 | xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; | ||
586 | xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, | ||
587 | xfer->seg_size); | ||
588 | if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL) | ||
589 | xfer->segs = 1; | ||
446 | } | 590 | } |
447 | xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; | 591 | |
448 | xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, xfer->seg_size); | 592 | if (xfer->segs > WA_SEGS_MAX) { |
449 | if (xfer->segs >= WA_SEGS_MAX) { | 593 | dev_err(dev, "BUG? oops, number of segments %zu bigger than %d\n", |
450 | dev_err(dev, "BUG? ops, number of segments %d bigger than %d\n", | 594 | (urb->transfer_buffer_length/xfer->seg_size), |
451 | (int)(urb->transfer_buffer_length / xfer->seg_size), | ||
452 | WA_SEGS_MAX); | 595 | WA_SEGS_MAX); |
453 | result = -EINVAL; | 596 | result = -EINVAL; |
454 | goto error; | 597 | goto error; |
455 | } | 598 | } |
456 | if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL) | ||
457 | xfer->segs = 1; | ||
458 | error: | 599 | error: |
459 | return result; | 600 | return result; |
460 | } | 601 | } |
461 | 602 | ||
603 | static void __wa_setup_isoc_packet_descr( | ||
604 | struct wa_xfer_packet_info_hwaiso *packet_desc, | ||
605 | struct wa_xfer *xfer, | ||
606 | struct wa_seg *seg) { | ||
607 | struct usb_iso_packet_descriptor *iso_frame_desc = | ||
608 | xfer->urb->iso_frame_desc; | ||
609 | int frame_index; | ||
610 | |||
611 | /* populate isoc packet descriptor. */ | ||
612 | packet_desc->bPacketType = WA_XFER_ISO_PACKET_INFO; | ||
613 | packet_desc->wLength = cpu_to_le16(sizeof(*packet_desc) + | ||
614 | (sizeof(packet_desc->PacketLength[0]) * | ||
615 | seg->isoc_frame_count)); | ||
616 | for (frame_index = 0; frame_index < seg->isoc_frame_count; | ||
617 | ++frame_index) { | ||
618 | int offset_index = frame_index + seg->isoc_frame_offset; | ||
619 | packet_desc->PacketLength[frame_index] = | ||
620 | cpu_to_le16(iso_frame_desc[offset_index].length); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | |||
462 | /* Fill in the common request header and xfer-type specific data. */ | 625 | /* Fill in the common request header and xfer-type specific data. */ |
463 | static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, | 626 | static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, |
464 | struct wa_xfer_hdr *xfer_hdr0, | 627 | struct wa_xfer_hdr *xfer_hdr0, |
@@ -466,12 +629,13 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, | |||
466 | size_t xfer_hdr_size) | 629 | size_t xfer_hdr_size) |
467 | { | 630 | { |
468 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; | 631 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; |
632 | struct wa_seg *seg = xfer->seg[0]; | ||
469 | 633 | ||
470 | xfer_hdr0 = &xfer->seg[0]->xfer_hdr; | 634 | xfer_hdr0 = &seg->xfer_hdr; |
471 | xfer_hdr0->bLength = xfer_hdr_size; | 635 | xfer_hdr0->bLength = xfer_hdr_size; |
472 | xfer_hdr0->bRequestType = xfer_type; | 636 | xfer_hdr0->bRequestType = xfer_type; |
473 | xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex; | 637 | xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex; |
474 | xfer_hdr0->dwTransferID = wa_xfer_id(xfer); | 638 | xfer_hdr0->dwTransferID = wa_xfer_id_le32(xfer); |
475 | xfer_hdr0->bTransferSegment = 0; | 639 | xfer_hdr0->bTransferSegment = 0; |
476 | switch (xfer_type) { | 640 | switch (xfer_type) { |
477 | case WA_XFER_TYPE_CTL: { | 641 | case WA_XFER_TYPE_CTL: { |
@@ -484,8 +648,18 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, | |||
484 | } | 648 | } |
485 | case WA_XFER_TYPE_BI: | 649 | case WA_XFER_TYPE_BI: |
486 | break; | 650 | break; |
487 | case WA_XFER_TYPE_ISO: | 651 | case WA_XFER_TYPE_ISO: { |
488 | printk(KERN_ERR "FIXME: ISOC not implemented\n"); | 652 | struct wa_xfer_hwaiso *xfer_iso = |
653 | container_of(xfer_hdr0, struct wa_xfer_hwaiso, hdr); | ||
654 | struct wa_xfer_packet_info_hwaiso *packet_desc = | ||
655 | ((void *)xfer_iso) + xfer_hdr_size; | ||
656 | |||
657 | /* populate the isoc section of the transfer request. */ | ||
658 | xfer_iso->dwNumOfPackets = cpu_to_le32(seg->isoc_frame_count); | ||
659 | /* populate isoc packet descriptor. */ | ||
660 | __wa_setup_isoc_packet_descr(packet_desc, xfer, seg); | ||
661 | break; | ||
662 | } | ||
489 | default: | 663 | default: |
490 | BUG(); | 664 | BUG(); |
491 | }; | 665 | }; |
@@ -494,12 +668,12 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, | |||
494 | /* | 668 | /* |
495 | * Callback for the OUT data phase of the segment request | 669 | * Callback for the OUT data phase of the segment request |
496 | * | 670 | * |
497 | * Check wa_seg_cb(); most comments also apply here because this | 671 | * Check wa_seg_tr_cb(); most comments also apply here because this |
498 | * function does almost the same thing and they work closely | 672 | * function does almost the same thing and they work closely |
499 | * together. | 673 | * together. |
500 | * | 674 | * |
501 | * If the seg request has failed but this DTO phase has succeeded, | 675 | * If the seg request has failed but this DTO phase has succeeded, |
502 | * wa_seg_cb() has already failed the segment and moved the | 676 | * wa_seg_tr_cb() has already failed the segment and moved the |
503 | * status to WA_SEG_ERROR, so this will go through 'case 0' and | 677 | * status to WA_SEG_ERROR, so this will go through 'case 0' and |
504 | * effectively do nothing. | 678 | * effectively do nothing. |
505 | */ | 679 | */ |
@@ -512,6 +686,139 @@ static void wa_seg_dto_cb(struct urb *urb) | |||
512 | struct wa_rpipe *rpipe; | 686 | struct wa_rpipe *rpipe; |
513 | unsigned long flags; | 687 | unsigned long flags; |
514 | unsigned rpipe_ready = 0; | 688 | unsigned rpipe_ready = 0; |
689 | int data_send_done = 1, release_dto = 0, holding_dto = 0; | ||
690 | u8 done = 0; | ||
691 | int result; | ||
692 | |||
693 | /* free the sg if it was used. */ | ||
694 | kfree(urb->sg); | ||
695 | urb->sg = NULL; | ||
696 | |||
697 | spin_lock_irqsave(&xfer->lock, flags); | ||
698 | wa = xfer->wa; | ||
699 | dev = &wa->usb_iface->dev; | ||
700 | if (usb_pipeisoc(xfer->urb->pipe)) { | ||
701 | /* Alereon HWA sends all isoc frames in a single transfer. */ | ||
702 | if (wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) | ||
703 | xfer->dto_isoc_frame_index += seg->isoc_frame_count; | ||
704 | else | ||
705 | xfer->dto_isoc_frame_index += 1; | ||
706 | if (xfer->dto_isoc_frame_index < seg->isoc_frame_count) { | ||
707 | data_send_done = 0; | ||
708 | holding_dto = 1; /* checked in error cases. */ | ||
709 | /* | ||
710 | * if this is the last isoc frame of the segment, we | ||
711 | * can release DTO after sending this frame. | ||
712 | */ | ||
713 | if ((xfer->dto_isoc_frame_index + 1) >= | ||
714 | seg->isoc_frame_count) | ||
715 | release_dto = 1; | ||
716 | } | ||
717 | dev_dbg(dev, "xfer 0x%08X#%u: isoc frame = %d, holding_dto = %d, release_dto = %d.\n", | ||
718 | wa_xfer_id(xfer), seg->index, | ||
719 | xfer->dto_isoc_frame_index, holding_dto, release_dto); | ||
720 | } | ||
721 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
722 | |||
723 | switch (urb->status) { | ||
724 | case 0: | ||
725 | spin_lock_irqsave(&xfer->lock, flags); | ||
726 | seg->result += urb->actual_length; | ||
727 | if (data_send_done) { | ||
728 | dev_dbg(dev, "xfer 0x%08X#%u: data out done (%zu bytes)\n", | ||
729 | wa_xfer_id(xfer), seg->index, seg->result); | ||
730 | if (seg->status < WA_SEG_PENDING) | ||
731 | seg->status = WA_SEG_PENDING; | ||
732 | } else { | ||
733 | /* should only hit this for isoc xfers. */ | ||
734 | /* | ||
735 | * Populate the dto URB with the next isoc frame buffer, | ||
736 | * send the URB and release DTO if we no longer need it. | ||
737 | */ | ||
738 | __wa_populate_dto_urb_isoc(xfer, seg, | ||
739 | seg->isoc_frame_offset + | ||
740 | xfer->dto_isoc_frame_index); | ||
741 | |||
742 | /* resubmit the URB with the next isoc frame. */ | ||
743 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); | ||
744 | if (result < 0) { | ||
745 | dev_err(dev, "xfer 0x%08X#%u: DTO submit failed: %d\n", | ||
746 | wa_xfer_id(xfer), seg->index, result); | ||
747 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
748 | goto error_dto_submit; | ||
749 | } | ||
750 | } | ||
751 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
752 | if (release_dto) { | ||
753 | __wa_dto_put(wa); | ||
754 | wa_check_for_delayed_rpipes(wa); | ||
755 | } | ||
756 | break; | ||
757 | case -ECONNRESET: /* URB unlinked; no need to do anything */ | ||
758 | case -ENOENT: /* as it was done by the who unlinked us */ | ||
759 | if (holding_dto) { | ||
760 | __wa_dto_put(wa); | ||
761 | wa_check_for_delayed_rpipes(wa); | ||
762 | } | ||
763 | break; | ||
764 | default: /* Other errors ... */ | ||
765 | dev_err(dev, "xfer 0x%08X#%u: data out error %d\n", | ||
766 | wa_xfer_id(xfer), seg->index, urb->status); | ||
767 | goto error_default; | ||
768 | } | ||
769 | |||
770 | return; | ||
771 | |||
772 | error_dto_submit: | ||
773 | error_default: | ||
774 | spin_lock_irqsave(&xfer->lock, flags); | ||
775 | rpipe = xfer->ep->hcpriv; | ||
776 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, | ||
777 | EDC_ERROR_TIMEFRAME)){ | ||
778 | dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n"); | ||
779 | wa_reset_all(wa); | ||
780 | } | ||
781 | if (seg->status != WA_SEG_ERROR) { | ||
782 | seg->status = WA_SEG_ERROR; | ||
783 | seg->result = urb->status; | ||
784 | xfer->segs_done++; | ||
785 | __wa_xfer_abort(xfer); | ||
786 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
787 | done = __wa_xfer_is_done(xfer); | ||
788 | } | ||
789 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
790 | if (holding_dto) { | ||
791 | __wa_dto_put(wa); | ||
792 | wa_check_for_delayed_rpipes(wa); | ||
793 | } | ||
794 | if (done) | ||
795 | wa_xfer_completion(xfer); | ||
796 | if (rpipe_ready) | ||
797 | wa_xfer_delayed_run(rpipe); | ||
798 | |||
799 | } | ||
800 | |||
801 | /* | ||
802 | * Callback for the isoc packet descriptor phase of the segment request | ||
803 | * | ||
804 | * Check wa_seg_tr_cb(); most comments also apply here because this | ||
805 | * function does almost the same thing and they work closely | ||
806 | * together. | ||
807 | * | ||
808 | * If the seg request has failed but this phase has succeeded, | ||
809 | * wa_seg_tr_cb() has already failed the segment and moved the | ||
810 | * status to WA_SEG_ERROR, so this will go through 'case 0' and | ||
811 | * effectively do nothing. | ||
812 | */ | ||
813 | static void wa_seg_iso_pack_desc_cb(struct urb *urb) | ||
814 | { | ||
815 | struct wa_seg *seg = urb->context; | ||
816 | struct wa_xfer *xfer = seg->xfer; | ||
817 | struct wahc *wa; | ||
818 | struct device *dev; | ||
819 | struct wa_rpipe *rpipe; | ||
820 | unsigned long flags; | ||
821 | unsigned rpipe_ready = 0; | ||
515 | u8 done = 0; | 822 | u8 done = 0; |
516 | 823 | ||
517 | switch (urb->status) { | 824 | switch (urb->status) { |
@@ -519,11 +826,10 @@ static void wa_seg_dto_cb(struct urb *urb) | |||
519 | spin_lock_irqsave(&xfer->lock, flags); | 826 | spin_lock_irqsave(&xfer->lock, flags); |
520 | wa = xfer->wa; | 827 | wa = xfer->wa; |
521 | dev = &wa->usb_iface->dev; | 828 | dev = &wa->usb_iface->dev; |
522 | dev_dbg(dev, "xfer %p#%u: data out done (%d bytes)\n", | 829 | dev_dbg(dev, "iso xfer %08X#%u: packet descriptor done\n", |
523 | xfer, seg->index, urb->actual_length); | 830 | wa_xfer_id(xfer), seg->index); |
524 | if (seg->status < WA_SEG_PENDING) | 831 | if (xfer->is_inbound && seg->status < WA_SEG_PENDING) |
525 | seg->status = WA_SEG_PENDING; | 832 | seg->status = WA_SEG_PENDING; |
526 | seg->result = urb->actual_length; | ||
527 | spin_unlock_irqrestore(&xfer->lock, flags); | 833 | spin_unlock_irqrestore(&xfer->lock, flags); |
528 | break; | 834 | break; |
529 | case -ECONNRESET: /* URB unlinked; no need to do anything */ | 835 | case -ECONNRESET: /* URB unlinked; no need to do anything */ |
@@ -534,15 +840,15 @@ static void wa_seg_dto_cb(struct urb *urb) | |||
534 | wa = xfer->wa; | 840 | wa = xfer->wa; |
535 | dev = &wa->usb_iface->dev; | 841 | dev = &wa->usb_iface->dev; |
536 | rpipe = xfer->ep->hcpriv; | 842 | rpipe = xfer->ep->hcpriv; |
537 | dev_dbg(dev, "xfer %p#%u: data out error %d\n", | 843 | pr_err_ratelimited("iso xfer %08X#%u: packet descriptor error %d\n", |
538 | xfer, seg->index, urb->status); | 844 | wa_xfer_id(xfer), seg->index, urb->status); |
539 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, | 845 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, |
540 | EDC_ERROR_TIMEFRAME)){ | 846 | EDC_ERROR_TIMEFRAME)){ |
541 | dev_err(dev, "DTO: URB max acceptable errors " | 847 | dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n"); |
542 | "exceeded, resetting device\n"); | ||
543 | wa_reset_all(wa); | 848 | wa_reset_all(wa); |
544 | } | 849 | } |
545 | if (seg->status != WA_SEG_ERROR) { | 850 | if (seg->status != WA_SEG_ERROR) { |
851 | usb_unlink_urb(seg->dto_urb); | ||
546 | seg->status = WA_SEG_ERROR; | 852 | seg->status = WA_SEG_ERROR; |
547 | seg->result = urb->status; | 853 | seg->result = urb->status; |
548 | xfer->segs_done++; | 854 | xfer->segs_done++; |
@@ -572,11 +878,11 @@ static void wa_seg_dto_cb(struct urb *urb) | |||
572 | * We have to check before setting the status to WA_SEG_PENDING | 878 | * We have to check before setting the status to WA_SEG_PENDING |
573 | * because sometimes the xfer result callback arrives before this | 879 | * because sometimes the xfer result callback arrives before this |
574 | * callback (geeeeeeze), so it might happen that we are already in | 880 | * callback (geeeeeeze), so it might happen that we are already in |
575 | * another state. As well, we don't set it if the transfer is inbound, | 881 | * another state. As well, we don't set it if the transfer is not inbound, |
576 | * as in that case, wa_seg_dto_cb will do it when the OUT data phase | 882 | * as in that case, wa_seg_dto_cb will do it when the OUT data phase |
577 | * finishes. | 883 | * finishes. |
578 | */ | 884 | */ |
579 | static void wa_seg_cb(struct urb *urb) | 885 | static void wa_seg_tr_cb(struct urb *urb) |
580 | { | 886 | { |
581 | struct wa_seg *seg = urb->context; | 887 | struct wa_seg *seg = urb->context; |
582 | struct wa_xfer *xfer = seg->xfer; | 888 | struct wa_xfer *xfer = seg->xfer; |
@@ -592,8 +898,11 @@ static void wa_seg_cb(struct urb *urb) | |||
592 | spin_lock_irqsave(&xfer->lock, flags); | 898 | spin_lock_irqsave(&xfer->lock, flags); |
593 | wa = xfer->wa; | 899 | wa = xfer->wa; |
594 | dev = &wa->usb_iface->dev; | 900 | dev = &wa->usb_iface->dev; |
595 | dev_dbg(dev, "xfer %p#%u: request done\n", xfer, seg->index); | 901 | dev_dbg(dev, "xfer %p ID 0x%08X#%u: request done\n", |
596 | if (xfer->is_inbound && seg->status < WA_SEG_PENDING) | 902 | xfer, wa_xfer_id(xfer), seg->index); |
903 | if (xfer->is_inbound && | ||
904 | seg->status < WA_SEG_PENDING && | ||
905 | !(usb_pipeisoc(xfer->urb->pipe))) | ||
597 | seg->status = WA_SEG_PENDING; | 906 | seg->status = WA_SEG_PENDING; |
598 | spin_unlock_irqrestore(&xfer->lock, flags); | 907 | spin_unlock_irqrestore(&xfer->lock, flags); |
599 | break; | 908 | break; |
@@ -606,14 +915,16 @@ static void wa_seg_cb(struct urb *urb) | |||
606 | dev = &wa->usb_iface->dev; | 915 | dev = &wa->usb_iface->dev; |
607 | rpipe = xfer->ep->hcpriv; | 916 | rpipe = xfer->ep->hcpriv; |
608 | if (printk_ratelimit()) | 917 | if (printk_ratelimit()) |
609 | dev_err(dev, "xfer %p#%u: request error %d\n", | 918 | dev_err(dev, "xfer %p ID 0x%08X#%u: request error %d\n", |
610 | xfer, seg->index, urb->status); | 919 | xfer, wa_xfer_id(xfer), seg->index, |
920 | urb->status); | ||
611 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, | 921 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, |
612 | EDC_ERROR_TIMEFRAME)){ | 922 | EDC_ERROR_TIMEFRAME)){ |
613 | dev_err(dev, "DTO: URB max acceptable errors " | 923 | dev_err(dev, "DTO: URB max acceptable errors " |
614 | "exceeded, resetting device\n"); | 924 | "exceeded, resetting device\n"); |
615 | wa_reset_all(wa); | 925 | wa_reset_all(wa); |
616 | } | 926 | } |
927 | usb_unlink_urb(seg->isoc_pack_desc_urb); | ||
617 | usb_unlink_urb(seg->dto_urb); | 928 | usb_unlink_urb(seg->dto_urb); |
618 | seg->status = WA_SEG_ERROR; | 929 | seg->status = WA_SEG_ERROR; |
619 | seg->result = urb->status; | 930 | seg->result = urb->status; |
@@ -629,9 +940,11 @@ static void wa_seg_cb(struct urb *urb) | |||
629 | } | 940 | } |
630 | } | 941 | } |
631 | 942 | ||
632 | /* allocate an SG list to store bytes_to_transfer bytes and copy the | 943 | /* |
944 | * Allocate an SG list to store bytes_to_transfer bytes and copy the | ||
633 | * subset of the in_sg that matches the buffer subset | 945 | * subset of the in_sg that matches the buffer subset |
634 | * we are about to transfer. */ | 946 | * we are about to transfer. |
947 | */ | ||
635 | static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, | 948 | static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, |
636 | const unsigned int bytes_transferred, | 949 | const unsigned int bytes_transferred, |
637 | const unsigned int bytes_to_transfer, unsigned int *out_num_sgs) | 950 | const unsigned int bytes_to_transfer, unsigned int *out_num_sgs) |
@@ -710,6 +1023,75 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, | |||
710 | } | 1023 | } |
711 | 1024 | ||
712 | /* | 1025 | /* |
1026 | * Populate DMA buffer info for the isoc dto urb. | ||
1027 | */ | ||
1028 | static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer, | ||
1029 | struct wa_seg *seg, int curr_iso_frame) | ||
1030 | { | ||
1031 | seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
1032 | seg->dto_urb->sg = NULL; | ||
1033 | seg->dto_urb->num_sgs = 0; | ||
1034 | /* dto urb buffer address pulled from iso_frame_desc. */ | ||
1035 | seg->dto_urb->transfer_dma = xfer->urb->transfer_dma + | ||
1036 | xfer->urb->iso_frame_desc[curr_iso_frame].offset; | ||
1037 | /* The Alereon HWA sends a single URB with all isoc segs. */ | ||
1038 | if (xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) | ||
1039 | seg->dto_urb->transfer_buffer_length = seg->isoc_size; | ||
1040 | else | ||
1041 | seg->dto_urb->transfer_buffer_length = | ||
1042 | xfer->urb->iso_frame_desc[curr_iso_frame].length; | ||
1043 | } | ||
1044 | |||
1045 | /* | ||
1046 | * Populate buffer ptr and size, DMA buffer or SG list for the dto urb. | ||
1047 | */ | ||
1048 | static int __wa_populate_dto_urb(struct wa_xfer *xfer, | ||
1049 | struct wa_seg *seg, size_t buf_itr_offset, size_t buf_itr_size) | ||
1050 | { | ||
1051 | int result = 0; | ||
1052 | |||
1053 | if (xfer->is_dma) { | ||
1054 | seg->dto_urb->transfer_dma = | ||
1055 | xfer->urb->transfer_dma + buf_itr_offset; | ||
1056 | seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
1057 | seg->dto_urb->sg = NULL; | ||
1058 | seg->dto_urb->num_sgs = 0; | ||
1059 | } else { | ||
1060 | /* do buffer or SG processing. */ | ||
1061 | seg->dto_urb->transfer_flags &= | ||
1062 | ~URB_NO_TRANSFER_DMA_MAP; | ||
1063 | /* this should always be 0 before a resubmit. */ | ||
1064 | seg->dto_urb->num_mapped_sgs = 0; | ||
1065 | |||
1066 | if (xfer->urb->transfer_buffer) { | ||
1067 | seg->dto_urb->transfer_buffer = | ||
1068 | xfer->urb->transfer_buffer + | ||
1069 | buf_itr_offset; | ||
1070 | seg->dto_urb->sg = NULL; | ||
1071 | seg->dto_urb->num_sgs = 0; | ||
1072 | } else { | ||
1073 | seg->dto_urb->transfer_buffer = NULL; | ||
1074 | |||
1075 | /* | ||
1076 | * allocate an SG list to store seg_size bytes | ||
1077 | * and copy the subset of the xfer->urb->sg that | ||
1078 | * matches the buffer subset we are about to | ||
1079 | * read. | ||
1080 | */ | ||
1081 | seg->dto_urb->sg = wa_xfer_create_subset_sg( | ||
1082 | xfer->urb->sg, | ||
1083 | buf_itr_offset, buf_itr_size, | ||
1084 | &(seg->dto_urb->num_sgs)); | ||
1085 | if (!(seg->dto_urb->sg)) | ||
1086 | result = -ENOMEM; | ||
1087 | } | ||
1088 | } | ||
1089 | seg->dto_urb->transfer_buffer_length = buf_itr_size; | ||
1090 | |||
1091 | return result; | ||
1092 | } | ||
1093 | |||
1094 | /* | ||
713 | * Allocate the segs array and initialize each of them | 1095 | * Allocate the segs array and initialize each of them |
714 | * | 1096 | * |
715 | * The segments are freed by wa_xfer_destroy() when the xfer use count | 1097 | * The segments are freed by wa_xfer_destroy() when the xfer use count |
@@ -719,13 +1101,14 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, | |||
719 | */ | 1101 | */ |
720 | static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | 1102 | static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) |
721 | { | 1103 | { |
722 | int result, cnt; | 1104 | int result, cnt, iso_frame_offset; |
723 | size_t alloc_size = sizeof(*xfer->seg[0]) | 1105 | size_t alloc_size = sizeof(*xfer->seg[0]) |
724 | - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size; | 1106 | - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size; |
725 | struct usb_device *usb_dev = xfer->wa->usb_dev; | 1107 | struct usb_device *usb_dev = xfer->wa->usb_dev; |
726 | const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; | 1108 | const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; |
727 | struct wa_seg *seg; | 1109 | struct wa_seg *seg; |
728 | size_t buf_itr, buf_size, buf_itr_size; | 1110 | size_t buf_itr, buf_size, buf_itr_size; |
1111 | int xfer_isoc_frame_offset = 0; | ||
729 | 1112 | ||
730 | result = -ENOMEM; | 1113 | result = -ENOMEM; |
731 | xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); | 1114 | xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); |
@@ -733,18 +1116,35 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
733 | goto error_segs_kzalloc; | 1116 | goto error_segs_kzalloc; |
734 | buf_itr = 0; | 1117 | buf_itr = 0; |
735 | buf_size = xfer->urb->transfer_buffer_length; | 1118 | buf_size = xfer->urb->transfer_buffer_length; |
1119 | iso_frame_offset = 0; | ||
736 | for (cnt = 0; cnt < xfer->segs; cnt++) { | 1120 | for (cnt = 0; cnt < xfer->segs; cnt++) { |
737 | seg = xfer->seg[cnt] = kmalloc(alloc_size, GFP_ATOMIC); | 1121 | size_t iso_pkt_descr_size = 0; |
1122 | int seg_isoc_frame_count = 0, seg_isoc_size = 0; | ||
1123 | |||
1124 | if (usb_pipeisoc(xfer->urb->pipe)) { | ||
1125 | seg_isoc_frame_count = | ||
1126 | __wa_seg_calculate_isoc_frame_count(xfer, | ||
1127 | xfer_isoc_frame_offset, &seg_isoc_size); | ||
1128 | |||
1129 | iso_pkt_descr_size = | ||
1130 | sizeof(struct wa_xfer_packet_info_hwaiso) + | ||
1131 | (seg_isoc_frame_count * sizeof(__le16)); | ||
1132 | } | ||
1133 | seg = xfer->seg[cnt] = kmalloc(alloc_size + iso_pkt_descr_size, | ||
1134 | GFP_ATOMIC); | ||
738 | if (seg == NULL) | 1135 | if (seg == NULL) |
739 | goto error_seg_kmalloc; | 1136 | goto error_seg_kmalloc; |
740 | wa_seg_init(seg); | 1137 | wa_seg_init(seg); |
741 | seg->xfer = xfer; | 1138 | seg->xfer = xfer; |
742 | seg->index = cnt; | 1139 | seg->index = cnt; |
743 | usb_fill_bulk_urb(&seg->urb, usb_dev, | 1140 | seg->isoc_frame_count = seg_isoc_frame_count; |
1141 | seg->isoc_frame_offset = xfer_isoc_frame_offset; | ||
1142 | seg->isoc_size = seg_isoc_size; | ||
1143 | usb_fill_bulk_urb(&seg->tr_urb, usb_dev, | ||
744 | usb_sndbulkpipe(usb_dev, | 1144 | usb_sndbulkpipe(usb_dev, |
745 | dto_epd->bEndpointAddress), | 1145 | dto_epd->bEndpointAddress), |
746 | &seg->xfer_hdr, xfer_hdr_size, | 1146 | &seg->xfer_hdr, xfer_hdr_size, |
747 | wa_seg_cb, seg); | 1147 | wa_seg_tr_cb, seg); |
748 | buf_itr_size = min(buf_size, xfer->seg_size); | 1148 | buf_itr_size = min(buf_size, xfer->seg_size); |
749 | if (xfer->is_inbound == 0 && buf_size > 0) { | 1149 | if (xfer->is_inbound == 0 && buf_size > 0) { |
750 | /* outbound data. */ | 1150 | /* outbound data. */ |
@@ -756,69 +1156,64 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
756 | usb_sndbulkpipe(usb_dev, | 1156 | usb_sndbulkpipe(usb_dev, |
757 | dto_epd->bEndpointAddress), | 1157 | dto_epd->bEndpointAddress), |
758 | NULL, 0, wa_seg_dto_cb, seg); | 1158 | NULL, 0, wa_seg_dto_cb, seg); |
759 | if (xfer->is_dma) { | 1159 | |
760 | seg->dto_urb->transfer_dma = | 1160 | if (usb_pipeisoc(xfer->urb->pipe)) { |
761 | xfer->urb->transfer_dma + buf_itr; | 1161 | /* iso packet descriptor. */ |
762 | seg->dto_urb->transfer_flags |= | 1162 | seg->isoc_pack_desc_urb = |
763 | URB_NO_TRANSFER_DMA_MAP; | 1163 | usb_alloc_urb(0, GFP_ATOMIC); |
764 | seg->dto_urb->transfer_buffer = NULL; | 1164 | if (seg->isoc_pack_desc_urb == NULL) |
765 | seg->dto_urb->sg = NULL; | 1165 | goto error_iso_pack_desc_alloc; |
766 | seg->dto_urb->num_sgs = 0; | 1166 | /* |
1167 | * The buffer for the isoc packet descriptor | ||
1168 | * after the transfer request header in the | ||
1169 | * segment object memory buffer. | ||
1170 | */ | ||
1171 | usb_fill_bulk_urb( | ||
1172 | seg->isoc_pack_desc_urb, usb_dev, | ||
1173 | usb_sndbulkpipe(usb_dev, | ||
1174 | dto_epd->bEndpointAddress), | ||
1175 | (void *)(&seg->xfer_hdr) + | ||
1176 | xfer_hdr_size, | ||
1177 | iso_pkt_descr_size, | ||
1178 | wa_seg_iso_pack_desc_cb, seg); | ||
1179 | |||
1180 | /* | ||
1181 | * Fill in the xfer buffer information for the | ||
1182 | * first isoc frame. Subsequent frames in this | ||
1183 | * segment will be filled in and sent from the | ||
1184 | * DTO completion routine, if needed. | ||
1185 | */ | ||
1186 | __wa_populate_dto_urb_isoc(xfer, seg, | ||
1187 | xfer_isoc_frame_offset); | ||
1188 | /* adjust starting frame offset for next seg. */ | ||
1189 | xfer_isoc_frame_offset += seg_isoc_frame_count; | ||
767 | } else { | 1190 | } else { |
768 | /* do buffer or SG processing. */ | 1191 | /* fill in the xfer buffer information. */ |
769 | seg->dto_urb->transfer_flags &= | 1192 | result = __wa_populate_dto_urb(xfer, seg, |
770 | ~URB_NO_TRANSFER_DMA_MAP; | 1193 | buf_itr, buf_itr_size); |
771 | /* this should always be 0 before a resubmit. */ | 1194 | if (result < 0) |
772 | seg->dto_urb->num_mapped_sgs = 0; | 1195 | goto error_seg_outbound_populate; |
773 | 1196 | ||
774 | if (xfer->urb->transfer_buffer) { | 1197 | buf_itr += buf_itr_size; |
775 | seg->dto_urb->transfer_buffer = | 1198 | buf_size -= buf_itr_size; |
776 | xfer->urb->transfer_buffer + | ||
777 | buf_itr; | ||
778 | seg->dto_urb->sg = NULL; | ||
779 | seg->dto_urb->num_sgs = 0; | ||
780 | } else { | ||
781 | /* allocate an SG list to store seg_size | ||
782 | bytes and copy the subset of the | ||
783 | xfer->urb->sg that matches the | ||
784 | buffer subset we are about to read. | ||
785 | */ | ||
786 | seg->dto_urb->sg = | ||
787 | wa_xfer_create_subset_sg( | ||
788 | xfer->urb->sg, | ||
789 | buf_itr, buf_itr_size, | ||
790 | &(seg->dto_urb->num_sgs)); | ||
791 | |||
792 | if (!(seg->dto_urb->sg)) { | ||
793 | seg->dto_urb->num_sgs = 0; | ||
794 | goto error_sg_alloc; | ||
795 | } | ||
796 | |||
797 | seg->dto_urb->transfer_buffer = NULL; | ||
798 | } | ||
799 | } | 1199 | } |
800 | seg->dto_urb->transfer_buffer_length = buf_itr_size; | ||
801 | } | 1200 | } |
802 | seg->status = WA_SEG_READY; | 1201 | seg->status = WA_SEG_READY; |
803 | buf_itr += buf_itr_size; | ||
804 | buf_size -= buf_itr_size; | ||
805 | } | 1202 | } |
806 | return 0; | 1203 | return 0; |
807 | 1204 | ||
808 | error_sg_alloc: | 1205 | /* |
1206 | * Free the memory for the current segment which failed to init. | ||
1207 | * Use the fact that cnt is left at were it failed. The remaining | ||
1208 | * segments will be cleaned up by wa_xfer_destroy. | ||
1209 | */ | ||
1210 | error_iso_pack_desc_alloc: | ||
1211 | error_seg_outbound_populate: | ||
809 | usb_free_urb(xfer->seg[cnt]->dto_urb); | 1212 | usb_free_urb(xfer->seg[cnt]->dto_urb); |
810 | error_dto_alloc: | 1213 | error_dto_alloc: |
811 | kfree(xfer->seg[cnt]); | 1214 | kfree(xfer->seg[cnt]); |
812 | cnt--; | 1215 | xfer->seg[cnt] = NULL; |
813 | error_seg_kmalloc: | 1216 | error_seg_kmalloc: |
814 | /* use the fact that cnt is left at were it failed */ | ||
815 | for (; cnt >= 0; cnt--) { | ||
816 | if (xfer->seg[cnt] && xfer->is_inbound == 0) { | ||
817 | usb_free_urb(xfer->seg[cnt]->dto_urb); | ||
818 | kfree(xfer->seg[cnt]->dto_urb->sg); | ||
819 | } | ||
820 | kfree(xfer->seg[cnt]); | ||
821 | } | ||
822 | error_segs_kzalloc: | 1217 | error_segs_kzalloc: |
823 | return result; | 1218 | return result; |
824 | } | 1219 | } |
@@ -856,21 +1251,45 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb) | |||
856 | wa_xfer_id_init(xfer); | 1251 | wa_xfer_id_init(xfer); |
857 | __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size); | 1252 | __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size); |
858 | 1253 | ||
859 | /* Fill remainig headers */ | 1254 | /* Fill remaining headers */ |
860 | xfer_hdr = xfer_hdr0; | 1255 | xfer_hdr = xfer_hdr0; |
861 | transfer_size = urb->transfer_buffer_length; | 1256 | if (xfer_type == WA_XFER_TYPE_ISO) { |
862 | xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ? | 1257 | xfer_hdr0->dwTransferLength = |
863 | xfer->seg_size : transfer_size; | 1258 | cpu_to_le32(xfer->seg[0]->isoc_size); |
864 | transfer_size -= xfer->seg_size; | 1259 | for (cnt = 1; cnt < xfer->segs; cnt++) { |
865 | for (cnt = 1; cnt < xfer->segs; cnt++) { | 1260 | struct wa_xfer_packet_info_hwaiso *packet_desc; |
866 | xfer_hdr = &xfer->seg[cnt]->xfer_hdr; | 1261 | struct wa_seg *seg = xfer->seg[cnt]; |
867 | memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); | 1262 | |
868 | xfer_hdr->bTransferSegment = cnt; | 1263 | xfer_hdr = &seg->xfer_hdr; |
869 | xfer_hdr->dwTransferLength = transfer_size > xfer->seg_size ? | 1264 | packet_desc = ((void *)xfer_hdr) + xfer_hdr_size; |
870 | cpu_to_le32(xfer->seg_size) | 1265 | /* |
871 | : cpu_to_le32(transfer_size); | 1266 | * Copy values from the 0th header. Segment specific |
872 | xfer->seg[cnt]->status = WA_SEG_READY; | 1267 | * values are set below. |
1268 | */ | ||
1269 | memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); | ||
1270 | xfer_hdr->bTransferSegment = cnt; | ||
1271 | xfer_hdr->dwTransferLength = | ||
1272 | cpu_to_le32(seg->isoc_size); | ||
1273 | __wa_setup_isoc_packet_descr(packet_desc, xfer, seg); | ||
1274 | seg->status = WA_SEG_READY; | ||
1275 | } | ||
1276 | } else { | ||
1277 | transfer_size = urb->transfer_buffer_length; | ||
1278 | xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ? | ||
1279 | cpu_to_le32(xfer->seg_size) : | ||
1280 | cpu_to_le32(transfer_size); | ||
873 | transfer_size -= xfer->seg_size; | 1281 | transfer_size -= xfer->seg_size; |
1282 | for (cnt = 1; cnt < xfer->segs; cnt++) { | ||
1283 | xfer_hdr = &xfer->seg[cnt]->xfer_hdr; | ||
1284 | memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); | ||
1285 | xfer_hdr->bTransferSegment = cnt; | ||
1286 | xfer_hdr->dwTransferLength = | ||
1287 | transfer_size > xfer->seg_size ? | ||
1288 | cpu_to_le32(xfer->seg_size) | ||
1289 | : cpu_to_le32(transfer_size); | ||
1290 | xfer->seg[cnt]->status = WA_SEG_READY; | ||
1291 | transfer_size -= xfer->seg_size; | ||
1292 | } | ||
874 | } | 1293 | } |
875 | xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */ | 1294 | xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */ |
876 | result = 0; | 1295 | result = 0; |
@@ -885,20 +1304,46 @@ error_setup_sizes: | |||
885 | * rpipe->seg_lock is held! | 1304 | * rpipe->seg_lock is held! |
886 | */ | 1305 | */ |
887 | static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, | 1306 | static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, |
888 | struct wa_seg *seg) | 1307 | struct wa_seg *seg, int *dto_done) |
889 | { | 1308 | { |
890 | int result; | 1309 | int result; |
891 | result = usb_submit_urb(&seg->urb, GFP_ATOMIC); | 1310 | |
1311 | /* default to done unless we encounter a multi-frame isoc segment. */ | ||
1312 | *dto_done = 1; | ||
1313 | |||
1314 | /* submit the transfer request. */ | ||
1315 | result = usb_submit_urb(&seg->tr_urb, GFP_ATOMIC); | ||
892 | if (result < 0) { | 1316 | if (result < 0) { |
893 | printk(KERN_ERR "xfer %p#%u: REQ submit failed: %d\n", | 1317 | pr_err("%s: xfer %p#%u: REQ submit failed: %d\n", |
894 | xfer, seg->index, result); | 1318 | __func__, xfer, seg->index, result); |
895 | goto error_seg_submit; | 1319 | goto error_seg_submit; |
896 | } | 1320 | } |
1321 | /* submit the isoc packet descriptor if present. */ | ||
1322 | if (seg->isoc_pack_desc_urb) { | ||
1323 | struct wahc *wa = xfer->wa; | ||
1324 | |||
1325 | result = usb_submit_urb(seg->isoc_pack_desc_urb, GFP_ATOMIC); | ||
1326 | if (result < 0) { | ||
1327 | pr_err("%s: xfer %p#%u: ISO packet descriptor submit failed: %d\n", | ||
1328 | __func__, xfer, seg->index, result); | ||
1329 | goto error_iso_pack_desc_submit; | ||
1330 | } | ||
1331 | xfer->dto_isoc_frame_index = 0; | ||
1332 | /* | ||
1333 | * If this segment contains more than one isoc frame, hold | ||
1334 | * onto the dto resource until we send all frames. | ||
1335 | * Only applies to non-Alereon devices. | ||
1336 | */ | ||
1337 | if (((wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) == 0) | ||
1338 | && (seg->isoc_frame_count > 1)) | ||
1339 | *dto_done = 0; | ||
1340 | } | ||
1341 | /* submit the out data if this is an out request. */ | ||
897 | if (seg->dto_urb) { | 1342 | if (seg->dto_urb) { |
898 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); | 1343 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); |
899 | if (result < 0) { | 1344 | if (result < 0) { |
900 | printk(KERN_ERR "xfer %p#%u: DTO submit failed: %d\n", | 1345 | pr_err("%s: xfer %p#%u: DTO submit failed: %d\n", |
901 | xfer, seg->index, result); | 1346 | __func__, xfer, seg->index, result); |
902 | goto error_dto_submit; | 1347 | goto error_dto_submit; |
903 | } | 1348 | } |
904 | } | 1349 | } |
@@ -907,38 +1352,48 @@ static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, | |||
907 | return 0; | 1352 | return 0; |
908 | 1353 | ||
909 | error_dto_submit: | 1354 | error_dto_submit: |
910 | usb_unlink_urb(&seg->urb); | 1355 | usb_unlink_urb(seg->isoc_pack_desc_urb); |
1356 | error_iso_pack_desc_submit: | ||
1357 | usb_unlink_urb(&seg->tr_urb); | ||
911 | error_seg_submit: | 1358 | error_seg_submit: |
912 | seg->status = WA_SEG_ERROR; | 1359 | seg->status = WA_SEG_ERROR; |
913 | seg->result = result; | 1360 | seg->result = result; |
1361 | *dto_done = 1; | ||
914 | return result; | 1362 | return result; |
915 | } | 1363 | } |
916 | 1364 | ||
917 | /* | 1365 | /* |
918 | * Execute more queued request segments until the maximum concurrent allowed | 1366 | * Execute more queued request segments until the maximum concurrent allowed. |
1367 | * Return true if the DTO resource was acquired and released. | ||
919 | * | 1368 | * |
920 | * The ugly unlock/lock sequence on the error path is needed as the | 1369 | * The ugly unlock/lock sequence on the error path is needed as the |
921 | * xfer->lock normally nests the seg_lock and not viceversa. | 1370 | * xfer->lock normally nests the seg_lock and not viceversa. |
922 | * | ||
923 | */ | 1371 | */ |
924 | static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) | 1372 | static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting) |
925 | { | 1373 | { |
926 | int result; | 1374 | int result, dto_acquired = 0, dto_done = 0; |
927 | struct device *dev = &rpipe->wa->usb_iface->dev; | 1375 | struct device *dev = &rpipe->wa->usb_iface->dev; |
928 | struct wa_seg *seg; | 1376 | struct wa_seg *seg; |
929 | struct wa_xfer *xfer; | 1377 | struct wa_xfer *xfer; |
930 | unsigned long flags; | 1378 | unsigned long flags; |
931 | 1379 | ||
1380 | *dto_waiting = 0; | ||
1381 | |||
932 | spin_lock_irqsave(&rpipe->seg_lock, flags); | 1382 | spin_lock_irqsave(&rpipe->seg_lock, flags); |
933 | while (atomic_read(&rpipe->segs_available) > 0 | 1383 | while (atomic_read(&rpipe->segs_available) > 0 |
934 | && !list_empty(&rpipe->seg_list)) { | 1384 | && !list_empty(&rpipe->seg_list) |
1385 | && (dto_acquired = __wa_dto_try_get(rpipe->wa))) { | ||
935 | seg = list_first_entry(&(rpipe->seg_list), struct wa_seg, | 1386 | seg = list_first_entry(&(rpipe->seg_list), struct wa_seg, |
936 | list_node); | 1387 | list_node); |
937 | list_del(&seg->list_node); | 1388 | list_del(&seg->list_node); |
938 | xfer = seg->xfer; | 1389 | xfer = seg->xfer; |
939 | result = __wa_seg_submit(rpipe, xfer, seg); | 1390 | result = __wa_seg_submit(rpipe, xfer, seg, &dto_done); |
940 | dev_dbg(dev, "xfer %p#%u submitted from delayed [%d segments available] %d\n", | 1391 | /* release the dto resource if this RPIPE is done with it. */ |
941 | xfer, seg->index, atomic_read(&rpipe->segs_available), result); | 1392 | if (dto_done) |
1393 | __wa_dto_put(rpipe->wa); | ||
1394 | dev_dbg(dev, "xfer %p ID %08X#%u submitted from delayed [%d segments available] %d\n", | ||
1395 | xfer, wa_xfer_id(xfer), seg->index, | ||
1396 | atomic_read(&rpipe->segs_available), result); | ||
942 | if (unlikely(result < 0)) { | 1397 | if (unlikely(result < 0)) { |
943 | spin_unlock_irqrestore(&rpipe->seg_lock, flags); | 1398 | spin_unlock_irqrestore(&rpipe->seg_lock, flags); |
944 | spin_lock_irqsave(&xfer->lock, flags); | 1399 | spin_lock_irqsave(&xfer->lock, flags); |
@@ -948,7 +1403,37 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) | |||
948 | spin_lock_irqsave(&rpipe->seg_lock, flags); | 1403 | spin_lock_irqsave(&rpipe->seg_lock, flags); |
949 | } | 1404 | } |
950 | } | 1405 | } |
1406 | /* | ||
1407 | * Mark this RPIPE as waiting if dto was not acquired, there are | ||
1408 | * delayed segs and no active transfers to wake us up later. | ||
1409 | */ | ||
1410 | if (!dto_acquired && !list_empty(&rpipe->seg_list) | ||
1411 | && (atomic_read(&rpipe->segs_available) == | ||
1412 | le16_to_cpu(rpipe->descr.wRequests))) | ||
1413 | *dto_waiting = 1; | ||
1414 | |||
951 | spin_unlock_irqrestore(&rpipe->seg_lock, flags); | 1415 | spin_unlock_irqrestore(&rpipe->seg_lock, flags); |
1416 | |||
1417 | return dto_done; | ||
1418 | } | ||
1419 | |||
1420 | static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) | ||
1421 | { | ||
1422 | int dto_waiting; | ||
1423 | int dto_done = __wa_xfer_delayed_run(rpipe, &dto_waiting); | ||
1424 | |||
1425 | /* | ||
1426 | * If this RPIPE is waiting on the DTO resource, add it to the tail of | ||
1427 | * the waiting list. | ||
1428 | * Otherwise, if the WA DTO resource was acquired and released by | ||
1429 | * __wa_xfer_delayed_run, another RPIPE may have attempted to acquire | ||
1430 | * DTO and failed during that time. Check the delayed list and process | ||
1431 | * any waiters. Start searching from the next RPIPE index. | ||
1432 | */ | ||
1433 | if (dto_waiting) | ||
1434 | wa_add_delayed_rpipe(rpipe->wa, rpipe); | ||
1435 | else if (dto_done) | ||
1436 | wa_check_for_delayed_rpipes(rpipe->wa); | ||
952 | } | 1437 | } |
953 | 1438 | ||
954 | /* | 1439 | /* |
@@ -960,7 +1445,7 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) | |||
960 | */ | 1445 | */ |
961 | static int __wa_xfer_submit(struct wa_xfer *xfer) | 1446 | static int __wa_xfer_submit(struct wa_xfer *xfer) |
962 | { | 1447 | { |
963 | int result; | 1448 | int result, dto_acquired = 0, dto_done = 0, dto_waiting = 0; |
964 | struct wahc *wa = xfer->wa; | 1449 | struct wahc *wa = xfer->wa; |
965 | struct device *dev = &wa->usb_iface->dev; | 1450 | struct device *dev = &wa->usb_iface->dev; |
966 | unsigned cnt; | 1451 | unsigned cnt; |
@@ -979,27 +1464,58 @@ static int __wa_xfer_submit(struct wa_xfer *xfer) | |||
979 | result = 0; | 1464 | result = 0; |
980 | spin_lock_irqsave(&rpipe->seg_lock, flags); | 1465 | spin_lock_irqsave(&rpipe->seg_lock, flags); |
981 | for (cnt = 0; cnt < xfer->segs; cnt++) { | 1466 | for (cnt = 0; cnt < xfer->segs; cnt++) { |
1467 | int delay_seg = 1; | ||
1468 | |||
982 | available = atomic_read(&rpipe->segs_available); | 1469 | available = atomic_read(&rpipe->segs_available); |
983 | empty = list_empty(&rpipe->seg_list); | 1470 | empty = list_empty(&rpipe->seg_list); |
984 | seg = xfer->seg[cnt]; | 1471 | seg = xfer->seg[cnt]; |
985 | dev_dbg(dev, "xfer %p#%u: available %u empty %u (%s)\n", | 1472 | if (available && empty) { |
986 | xfer, cnt, available, empty, | 1473 | /* |
987 | available == 0 || !empty ? "delayed" : "submitted"); | 1474 | * Only attempt to acquire DTO if we have a segment |
988 | if (available == 0 || !empty) { | 1475 | * to send. |
989 | dev_dbg(dev, "xfer %p#%u: delayed\n", xfer, cnt); | 1476 | */ |
1477 | dto_acquired = __wa_dto_try_get(rpipe->wa); | ||
1478 | if (dto_acquired) { | ||
1479 | delay_seg = 0; | ||
1480 | result = __wa_seg_submit(rpipe, xfer, seg, | ||
1481 | &dto_done); | ||
1482 | dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u submitted\n", | ||
1483 | xfer, wa_xfer_id(xfer), cnt, available, | ||
1484 | empty); | ||
1485 | if (dto_done) | ||
1486 | __wa_dto_put(rpipe->wa); | ||
1487 | |||
1488 | if (result < 0) { | ||
1489 | __wa_xfer_abort(xfer); | ||
1490 | goto error_seg_submit; | ||
1491 | } | ||
1492 | } | ||
1493 | } | ||
1494 | |||
1495 | if (delay_seg) { | ||
1496 | dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u delayed\n", | ||
1497 | xfer, wa_xfer_id(xfer), cnt, available, empty); | ||
990 | seg->status = WA_SEG_DELAYED; | 1498 | seg->status = WA_SEG_DELAYED; |
991 | list_add_tail(&seg->list_node, &rpipe->seg_list); | 1499 | list_add_tail(&seg->list_node, &rpipe->seg_list); |
992 | } else { | ||
993 | result = __wa_seg_submit(rpipe, xfer, seg); | ||
994 | if (result < 0) { | ||
995 | __wa_xfer_abort(xfer); | ||
996 | goto error_seg_submit; | ||
997 | } | ||
998 | } | 1500 | } |
999 | xfer->segs_submitted++; | 1501 | xfer->segs_submitted++; |
1000 | } | 1502 | } |
1001 | error_seg_submit: | 1503 | error_seg_submit: |
1504 | /* | ||
1505 | * Mark this RPIPE as waiting if dto was not acquired, there are | ||
1506 | * delayed segs and no active transfers to wake us up later. | ||
1507 | */ | ||
1508 | if (!dto_acquired && !list_empty(&rpipe->seg_list) | ||
1509 | && (atomic_read(&rpipe->segs_available) == | ||
1510 | le16_to_cpu(rpipe->descr.wRequests))) | ||
1511 | dto_waiting = 1; | ||
1002 | spin_unlock_irqrestore(&rpipe->seg_lock, flags); | 1512 | spin_unlock_irqrestore(&rpipe->seg_lock, flags); |
1513 | |||
1514 | if (dto_waiting) | ||
1515 | wa_add_delayed_rpipe(rpipe->wa, rpipe); | ||
1516 | else if (dto_done) | ||
1517 | wa_check_for_delayed_rpipes(rpipe->wa); | ||
1518 | |||
1003 | return result; | 1519 | return result; |
1004 | } | 1520 | } |
1005 | 1521 | ||
@@ -1025,7 +1541,7 @@ error_seg_submit: | |||
1025 | * result never kicks in, the xfer will timeout from the USB code and | 1541 | * result never kicks in, the xfer will timeout from the USB code and |
1026 | * dequeue() will be called. | 1542 | * dequeue() will be called. |
1027 | */ | 1543 | */ |
1028 | static void wa_urb_enqueue_b(struct wa_xfer *xfer) | 1544 | static int wa_urb_enqueue_b(struct wa_xfer *xfer) |
1029 | { | 1545 | { |
1030 | int result; | 1546 | int result; |
1031 | unsigned long flags; | 1547 | unsigned long flags; |
@@ -1036,18 +1552,22 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer) | |||
1036 | unsigned done; | 1552 | unsigned done; |
1037 | 1553 | ||
1038 | result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp); | 1554 | result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp); |
1039 | if (result < 0) | 1555 | if (result < 0) { |
1556 | pr_err("%s: error_rpipe_get\n", __func__); | ||
1040 | goto error_rpipe_get; | 1557 | goto error_rpipe_get; |
1558 | } | ||
1041 | result = -ENODEV; | 1559 | result = -ENODEV; |
1042 | /* FIXME: segmentation broken -- kills DWA */ | 1560 | /* FIXME: segmentation broken -- kills DWA */ |
1043 | mutex_lock(&wusbhc->mutex); /* get a WUSB dev */ | 1561 | mutex_lock(&wusbhc->mutex); /* get a WUSB dev */ |
1044 | if (urb->dev == NULL) { | 1562 | if (urb->dev == NULL) { |
1045 | mutex_unlock(&wusbhc->mutex); | 1563 | mutex_unlock(&wusbhc->mutex); |
1564 | pr_err("%s: error usb dev gone\n", __func__); | ||
1046 | goto error_dev_gone; | 1565 | goto error_dev_gone; |
1047 | } | 1566 | } |
1048 | wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); | 1567 | wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); |
1049 | if (wusb_dev == NULL) { | 1568 | if (wusb_dev == NULL) { |
1050 | mutex_unlock(&wusbhc->mutex); | 1569 | mutex_unlock(&wusbhc->mutex); |
1570 | pr_err("%s: error wusb dev gone\n", __func__); | ||
1051 | goto error_dev_gone; | 1571 | goto error_dev_gone; |
1052 | } | 1572 | } |
1053 | mutex_unlock(&wusbhc->mutex); | 1573 | mutex_unlock(&wusbhc->mutex); |
@@ -1055,21 +1575,28 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer) | |||
1055 | spin_lock_irqsave(&xfer->lock, flags); | 1575 | spin_lock_irqsave(&xfer->lock, flags); |
1056 | xfer->wusb_dev = wusb_dev; | 1576 | xfer->wusb_dev = wusb_dev; |
1057 | result = urb->status; | 1577 | result = urb->status; |
1058 | if (urb->status != -EINPROGRESS) | 1578 | if (urb->status != -EINPROGRESS) { |
1579 | pr_err("%s: error_dequeued\n", __func__); | ||
1059 | goto error_dequeued; | 1580 | goto error_dequeued; |
1581 | } | ||
1060 | 1582 | ||
1061 | result = __wa_xfer_setup(xfer, urb); | 1583 | result = __wa_xfer_setup(xfer, urb); |
1062 | if (result < 0) | 1584 | if (result < 0) { |
1585 | pr_err("%s: error_xfer_setup\n", __func__); | ||
1063 | goto error_xfer_setup; | 1586 | goto error_xfer_setup; |
1587 | } | ||
1064 | result = __wa_xfer_submit(xfer); | 1588 | result = __wa_xfer_submit(xfer); |
1065 | if (result < 0) | 1589 | if (result < 0) { |
1590 | pr_err("%s: error_xfer_submit\n", __func__); | ||
1066 | goto error_xfer_submit; | 1591 | goto error_xfer_submit; |
1592 | } | ||
1067 | spin_unlock_irqrestore(&xfer->lock, flags); | 1593 | spin_unlock_irqrestore(&xfer->lock, flags); |
1068 | return; | 1594 | return 0; |
1069 | 1595 | ||
1070 | /* this is basically wa_xfer_completion() broken up wa_xfer_giveback() | 1596 | /* |
1071 | * does a wa_xfer_put() that will call wa_xfer_destroy() and clean | 1597 | * this is basically wa_xfer_completion() broken up wa_xfer_giveback() |
1072 | * upundo setup(). | 1598 | * does a wa_xfer_put() that will call wa_xfer_destroy() and undo |
1599 | * setup(). | ||
1073 | */ | 1600 | */ |
1074 | error_xfer_setup: | 1601 | error_xfer_setup: |
1075 | error_dequeued: | 1602 | error_dequeued: |
@@ -1081,8 +1608,7 @@ error_dev_gone: | |||
1081 | rpipe_put(xfer->ep->hcpriv); | 1608 | rpipe_put(xfer->ep->hcpriv); |
1082 | error_rpipe_get: | 1609 | error_rpipe_get: |
1083 | xfer->result = result; | 1610 | xfer->result = result; |
1084 | wa_xfer_giveback(xfer); | 1611 | return result; |
1085 | return; | ||
1086 | 1612 | ||
1087 | error_xfer_submit: | 1613 | error_xfer_submit: |
1088 | done = __wa_xfer_is_done(xfer); | 1614 | done = __wa_xfer_is_done(xfer); |
@@ -1090,6 +1616,8 @@ error_xfer_submit: | |||
1090 | spin_unlock_irqrestore(&xfer->lock, flags); | 1616 | spin_unlock_irqrestore(&xfer->lock, flags); |
1091 | if (done) | 1617 | if (done) |
1092 | wa_xfer_completion(xfer); | 1618 | wa_xfer_completion(xfer); |
1619 | /* return success since the completion routine will run. */ | ||
1620 | return 0; | ||
1093 | } | 1621 | } |
1094 | 1622 | ||
1095 | /* | 1623 | /* |
@@ -1123,7 +1651,8 @@ void wa_urb_enqueue_run(struct work_struct *ws) | |||
1123 | list_del_init(&xfer->list_node); | 1651 | list_del_init(&xfer->list_node); |
1124 | 1652 | ||
1125 | urb = xfer->urb; | 1653 | urb = xfer->urb; |
1126 | wa_urb_enqueue_b(xfer); | 1654 | if (wa_urb_enqueue_b(xfer) < 0) |
1655 | wa_xfer_giveback(xfer); | ||
1127 | usb_put_urb(urb); /* taken when queuing */ | 1656 | usb_put_urb(urb); /* taken when queuing */ |
1128 | } | 1657 | } |
1129 | } | 1658 | } |
@@ -1229,7 +1758,19 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep, | |||
1229 | spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); | 1758 | spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); |
1230 | queue_work(wusbd, &wa->xfer_enqueue_work); | 1759 | queue_work(wusbd, &wa->xfer_enqueue_work); |
1231 | } else { | 1760 | } else { |
1232 | wa_urb_enqueue_b(xfer); | 1761 | result = wa_urb_enqueue_b(xfer); |
1762 | if (result < 0) { | ||
1763 | /* | ||
1764 | * URB submit/enqueue failed. Clean up, return an | ||
1765 | * error and do not run the callback. This avoids | ||
1766 | * an infinite submit/complete loop. | ||
1767 | */ | ||
1768 | dev_err(dev, "%s: URB enqueue failed: %d\n", | ||
1769 | __func__, result); | ||
1770 | wa_put(xfer->wa); | ||
1771 | wa_xfer_put(xfer); | ||
1772 | return result; | ||
1773 | } | ||
1233 | } | 1774 | } |
1234 | return 0; | 1775 | return 0; |
1235 | 1776 | ||
@@ -1264,7 +1805,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1264 | struct wa_xfer *xfer; | 1805 | struct wa_xfer *xfer; |
1265 | struct wa_seg *seg; | 1806 | struct wa_seg *seg; |
1266 | struct wa_rpipe *rpipe; | 1807 | struct wa_rpipe *rpipe; |
1267 | unsigned cnt; | 1808 | unsigned cnt, done = 0, xfer_abort_pending; |
1268 | unsigned rpipe_ready = 0; | 1809 | unsigned rpipe_ready = 0; |
1269 | 1810 | ||
1270 | xfer = urb->hcpriv; | 1811 | xfer = urb->hcpriv; |
@@ -1278,6 +1819,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1278 | goto out; | 1819 | goto out; |
1279 | } | 1820 | } |
1280 | spin_lock_irqsave(&xfer->lock, flags); | 1821 | spin_lock_irqsave(&xfer->lock, flags); |
1822 | pr_debug("%s: DEQUEUE xfer id 0x%08X\n", __func__, wa_xfer_id(xfer)); | ||
1281 | rpipe = xfer->ep->hcpriv; | 1823 | rpipe = xfer->ep->hcpriv; |
1282 | if (rpipe == NULL) { | 1824 | if (rpipe == NULL) { |
1283 | pr_debug("%s: xfer id 0x%08X has no RPIPE. %s", | 1825 | pr_debug("%s: xfer id 0x%08X has no RPIPE. %s", |
@@ -1293,9 +1835,11 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1293 | if (xfer->seg == NULL) /* still hasn't reached */ | 1835 | if (xfer->seg == NULL) /* still hasn't reached */ |
1294 | goto out_unlock; /* setup(), enqueue_b() completes */ | 1836 | goto out_unlock; /* setup(), enqueue_b() completes */ |
1295 | /* Ok, the xfer is in flight already, it's been setup and submitted.*/ | 1837 | /* Ok, the xfer is in flight already, it's been setup and submitted.*/ |
1296 | __wa_xfer_abort(xfer); | 1838 | xfer_abort_pending = __wa_xfer_abort(xfer) >= 0; |
1297 | for (cnt = 0; cnt < xfer->segs; cnt++) { | 1839 | for (cnt = 0; cnt < xfer->segs; cnt++) { |
1298 | seg = xfer->seg[cnt]; | 1840 | seg = xfer->seg[cnt]; |
1841 | pr_debug("%s: xfer id 0x%08X#%d status = %d\n", | ||
1842 | __func__, wa_xfer_id(xfer), cnt, seg->status); | ||
1299 | switch (seg->status) { | 1843 | switch (seg->status) { |
1300 | case WA_SEG_NOTREADY: | 1844 | case WA_SEG_NOTREADY: |
1301 | case WA_SEG_READY: | 1845 | case WA_SEG_READY: |
@@ -1304,42 +1848,50 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1304 | WARN_ON(1); | 1848 | WARN_ON(1); |
1305 | break; | 1849 | break; |
1306 | case WA_SEG_DELAYED: | 1850 | case WA_SEG_DELAYED: |
1851 | /* | ||
1852 | * delete from rpipe delayed list. If no segments on | ||
1853 | * this xfer have been submitted, __wa_xfer_is_done will | ||
1854 | * trigger a giveback below. Otherwise, the submitted | ||
1855 | * segments will be completed in the DTI interrupt. | ||
1856 | */ | ||
1307 | seg->status = WA_SEG_ABORTED; | 1857 | seg->status = WA_SEG_ABORTED; |
1308 | spin_lock_irqsave(&rpipe->seg_lock, flags2); | 1858 | spin_lock_irqsave(&rpipe->seg_lock, flags2); |
1309 | list_del(&seg->list_node); | 1859 | list_del(&seg->list_node); |
1310 | xfer->segs_done++; | 1860 | xfer->segs_done++; |
1311 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
1312 | spin_unlock_irqrestore(&rpipe->seg_lock, flags2); | 1861 | spin_unlock_irqrestore(&rpipe->seg_lock, flags2); |
1313 | break; | 1862 | break; |
1314 | case WA_SEG_SUBMITTED: | ||
1315 | seg->status = WA_SEG_ABORTED; | ||
1316 | usb_unlink_urb(&seg->urb); | ||
1317 | if (xfer->is_inbound == 0) | ||
1318 | usb_unlink_urb(seg->dto_urb); | ||
1319 | xfer->segs_done++; | ||
1320 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
1321 | break; | ||
1322 | case WA_SEG_PENDING: | ||
1323 | seg->status = WA_SEG_ABORTED; | ||
1324 | xfer->segs_done++; | ||
1325 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
1326 | break; | ||
1327 | case WA_SEG_DTI_PENDING: | ||
1328 | usb_unlink_urb(wa->dti_urb); | ||
1329 | seg->status = WA_SEG_ABORTED; | ||
1330 | xfer->segs_done++; | ||
1331 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
1332 | break; | ||
1333 | case WA_SEG_DONE: | 1863 | case WA_SEG_DONE: |
1334 | case WA_SEG_ERROR: | 1864 | case WA_SEG_ERROR: |
1335 | case WA_SEG_ABORTED: | 1865 | case WA_SEG_ABORTED: |
1336 | break; | 1866 | break; |
1867 | /* | ||
1868 | * In the states below, the HWA device already knows | ||
1869 | * about the transfer. If an abort request was sent, | ||
1870 | * allow the HWA to process it and wait for the | ||
1871 | * results. Otherwise, the DTI state and seg completed | ||
1872 | * counts can get out of sync. | ||
1873 | */ | ||
1874 | case WA_SEG_SUBMITTED: | ||
1875 | case WA_SEG_PENDING: | ||
1876 | case WA_SEG_DTI_PENDING: | ||
1877 | /* | ||
1878 | * Check if the abort was successfully sent. This could | ||
1879 | * be false if the HWA has been removed but we haven't | ||
1880 | * gotten the disconnect notification yet. | ||
1881 | */ | ||
1882 | if (!xfer_abort_pending) { | ||
1883 | seg->status = WA_SEG_ABORTED; | ||
1884 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
1885 | xfer->segs_done++; | ||
1886 | } | ||
1887 | break; | ||
1337 | } | 1888 | } |
1338 | } | 1889 | } |
1339 | xfer->result = urb->status; /* -ENOENT or -ECONNRESET */ | 1890 | xfer->result = urb->status; /* -ENOENT or -ECONNRESET */ |
1340 | __wa_xfer_is_done(xfer); | 1891 | done = __wa_xfer_is_done(xfer); |
1341 | spin_unlock_irqrestore(&xfer->lock, flags); | 1892 | spin_unlock_irqrestore(&xfer->lock, flags); |
1342 | wa_xfer_completion(xfer); | 1893 | if (done) |
1894 | wa_xfer_completion(xfer); | ||
1343 | if (rpipe_ready) | 1895 | if (rpipe_ready) |
1344 | wa_xfer_delayed_run(rpipe); | 1896 | wa_xfer_delayed_run(rpipe); |
1345 | return 0; | 1897 | return 0; |
@@ -1410,13 +1962,56 @@ static int wa_xfer_status_to_errno(u8 status) | |||
1410 | } | 1962 | } |
1411 | 1963 | ||
1412 | /* | 1964 | /* |
1965 | * If a last segment flag and/or a transfer result error is encountered, | ||
1966 | * no other segment transfer results will be returned from the device. | ||
1967 | * Mark the remaining submitted or pending xfers as completed so that | ||
1968 | * the xfer will complete cleanly. | ||
1969 | */ | ||
1970 | static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, | ||
1971 | struct wa_seg *incoming_seg) | ||
1972 | { | ||
1973 | int index; | ||
1974 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; | ||
1975 | |||
1976 | for (index = incoming_seg->index + 1; index < xfer->segs_submitted; | ||
1977 | index++) { | ||
1978 | struct wa_seg *current_seg = xfer->seg[index]; | ||
1979 | |||
1980 | BUG_ON(current_seg == NULL); | ||
1981 | |||
1982 | switch (current_seg->status) { | ||
1983 | case WA_SEG_SUBMITTED: | ||
1984 | case WA_SEG_PENDING: | ||
1985 | case WA_SEG_DTI_PENDING: | ||
1986 | rpipe_avail_inc(rpipe); | ||
1987 | /* | ||
1988 | * do not increment RPIPE avail for the WA_SEG_DELAYED case | ||
1989 | * since it has not been submitted to the RPIPE. | ||
1990 | */ | ||
1991 | case WA_SEG_DELAYED: | ||
1992 | xfer->segs_done++; | ||
1993 | current_seg->status = incoming_seg->status; | ||
1994 | break; | ||
1995 | case WA_SEG_ABORTED: | ||
1996 | break; | ||
1997 | default: | ||
1998 | WARN(1, "%s: xfer 0x%08X#%d. bad seg status = %d\n", | ||
1999 | __func__, wa_xfer_id(xfer), index, | ||
2000 | current_seg->status); | ||
2001 | break; | ||
2002 | } | ||
2003 | } | ||
2004 | } | ||
2005 | |||
2006 | /* | ||
1413 | * Process a xfer result completion message | 2007 | * Process a xfer result completion message |
1414 | * | 2008 | * |
1415 | * inbound transfers: need to schedule a DTI read | 2009 | * inbound transfers: need to schedule a buf_in_urb read |
1416 | * | 2010 | * |
1417 | * FIXME: this function needs to be broken up in parts | 2011 | * FIXME: this function needs to be broken up in parts |
1418 | */ | 2012 | */ |
1419 | static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer) | 2013 | static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer, |
2014 | struct wa_xfer_result *xfer_result) | ||
1420 | { | 2015 | { |
1421 | int result; | 2016 | int result; |
1422 | struct device *dev = &wa->usb_iface->dev; | 2017 | struct device *dev = &wa->usb_iface->dev; |
@@ -1424,8 +2019,7 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer) | |||
1424 | u8 seg_idx; | 2019 | u8 seg_idx; |
1425 | struct wa_seg *seg; | 2020 | struct wa_seg *seg; |
1426 | struct wa_rpipe *rpipe; | 2021 | struct wa_rpipe *rpipe; |
1427 | struct wa_xfer_result *xfer_result = wa->xfer_result; | 2022 | unsigned done = 0; |
1428 | u8 done = 0; | ||
1429 | u8 usb_status; | 2023 | u8 usb_status; |
1430 | unsigned rpipe_ready = 0; | 2024 | unsigned rpipe_ready = 0; |
1431 | 2025 | ||
@@ -1436,8 +2030,8 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer) | |||
1436 | seg = xfer->seg[seg_idx]; | 2030 | seg = xfer->seg[seg_idx]; |
1437 | rpipe = xfer->ep->hcpriv; | 2031 | rpipe = xfer->ep->hcpriv; |
1438 | usb_status = xfer_result->bTransferStatus; | 2032 | usb_status = xfer_result->bTransferStatus; |
1439 | dev_dbg(dev, "xfer %p#%u: bTransferStatus 0x%02x (seg status %u)\n", | 2033 | dev_dbg(dev, "xfer %p ID 0x%08X#%u: bTransferStatus 0x%02x (seg status %u)\n", |
1440 | xfer, seg_idx, usb_status, seg->status); | 2034 | xfer, wa_xfer_id(xfer), seg_idx, usb_status, seg->status); |
1441 | if (seg->status == WA_SEG_ABORTED | 2035 | if (seg->status == WA_SEG_ABORTED |
1442 | || seg->status == WA_SEG_ERROR) /* already handled */ | 2036 | || seg->status == WA_SEG_ERROR) /* already handled */ |
1443 | goto segment_aborted; | 2037 | goto segment_aborted; |
@@ -1453,12 +2047,19 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer) | |||
1453 | seg->result = wa_xfer_status_to_errno(usb_status); | 2047 | seg->result = wa_xfer_status_to_errno(usb_status); |
1454 | dev_err(dev, "DTI: xfer %p#:%08X:%u failed (0x%02x)\n", | 2048 | dev_err(dev, "DTI: xfer %p#:%08X:%u failed (0x%02x)\n", |
1455 | xfer, xfer->id, seg->index, usb_status); | 2049 | xfer, xfer->id, seg->index, usb_status); |
2050 | seg->status = ((usb_status & 0x7F) == WA_XFER_STATUS_ABORTED) ? | ||
2051 | WA_SEG_ABORTED : WA_SEG_ERROR; | ||
1456 | goto error_complete; | 2052 | goto error_complete; |
1457 | } | 2053 | } |
1458 | /* FIXME: we ignore warnings, tally them for stats */ | 2054 | /* FIXME: we ignore warnings, tally them for stats */ |
1459 | if (usb_status & 0x40) /* Warning?... */ | 2055 | if (usb_status & 0x40) /* Warning?... */ |
1460 | usb_status = 0; /* ... pass */ | 2056 | usb_status = 0; /* ... pass */ |
1461 | if (xfer->is_inbound) { /* IN data phase: read to buffer */ | 2057 | if (usb_pipeisoc(xfer->urb->pipe)) { |
2058 | /* set up WA state to read the isoc packet status next. */ | ||
2059 | wa->dti_isoc_xfer_in_progress = wa_xfer_id(xfer); | ||
2060 | wa->dti_isoc_xfer_seg = seg_idx; | ||
2061 | wa->dti_state = WA_DTI_ISOC_PACKET_STATUS_PENDING; | ||
2062 | } else if (xfer->is_inbound) { /* IN data phase: read to buffer */ | ||
1462 | seg->status = WA_SEG_DTI_PENDING; | 2063 | seg->status = WA_SEG_DTI_PENDING; |
1463 | BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); | 2064 | BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); |
1464 | /* this should always be 0 before a resubmit. */ | 2065 | /* this should always be 0 before a resubmit. */ |
@@ -1535,12 +2136,14 @@ error_submit_buf_in: | |||
1535 | xfer, seg_idx, result); | 2136 | xfer, seg_idx, result); |
1536 | seg->result = result; | 2137 | seg->result = result; |
1537 | kfree(wa->buf_in_urb->sg); | 2138 | kfree(wa->buf_in_urb->sg); |
2139 | wa->buf_in_urb->sg = NULL; | ||
1538 | error_sg_alloc: | 2140 | error_sg_alloc: |
1539 | __wa_xfer_abort(xfer); | 2141 | __wa_xfer_abort(xfer); |
1540 | error_complete: | ||
1541 | seg->status = WA_SEG_ERROR; | 2142 | seg->status = WA_SEG_ERROR; |
2143 | error_complete: | ||
1542 | xfer->segs_done++; | 2144 | xfer->segs_done++; |
1543 | rpipe_ready = rpipe_avail_inc(rpipe); | 2145 | rpipe_ready = rpipe_avail_inc(rpipe); |
2146 | wa_complete_remaining_xfer_segs(xfer, seg); | ||
1544 | done = __wa_xfer_is_done(xfer); | 2147 | done = __wa_xfer_is_done(xfer); |
1545 | /* | 2148 | /* |
1546 | * queue work item to clear STALL for control endpoints. | 2149 | * queue work item to clear STALL for control endpoints. |
@@ -1552,10 +2155,8 @@ error_complete: | |||
1552 | 2155 | ||
1553 | dev_info(dev, "Control EP stall. Queue delayed work.\n"); | 2156 | dev_info(dev, "Control EP stall. Queue delayed work.\n"); |
1554 | spin_lock_irq(&wa->xfer_list_lock); | 2157 | spin_lock_irq(&wa->xfer_list_lock); |
1555 | /* remove xfer from xfer_list. */ | 2158 | /* move xfer from xfer_list to xfer_errored_list. */ |
1556 | list_del(&xfer->list_node); | 2159 | list_move_tail(&xfer->list_node, &wa->xfer_errored_list); |
1557 | /* add xfer to xfer_errored_list. */ | ||
1558 | list_add_tail(&xfer->list_node, &wa->xfer_errored_list); | ||
1559 | spin_unlock_irq(&wa->xfer_list_lock); | 2160 | spin_unlock_irq(&wa->xfer_list_lock); |
1560 | spin_unlock_irqrestore(&xfer->lock, flags); | 2161 | spin_unlock_irqrestore(&xfer->lock, flags); |
1561 | queue_work(wusbd, &wa->xfer_error_work); | 2162 | queue_work(wusbd, &wa->xfer_error_work); |
@@ -1587,6 +2188,90 @@ segment_aborted: | |||
1587 | } | 2188 | } |
1588 | 2189 | ||
1589 | /* | 2190 | /* |
2191 | * Process a isochronous packet status message | ||
2192 | * | ||
2193 | * inbound transfers: need to schedule a buf_in_urb read | ||
2194 | */ | ||
2195 | static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) | ||
2196 | { | ||
2197 | struct device *dev = &wa->usb_iface->dev; | ||
2198 | struct wa_xfer_packet_status_hwaiso *packet_status; | ||
2199 | struct wa_xfer_packet_status_len_hwaiso *status_array; | ||
2200 | struct wa_xfer *xfer; | ||
2201 | unsigned long flags; | ||
2202 | struct wa_seg *seg; | ||
2203 | struct wa_rpipe *rpipe; | ||
2204 | unsigned done = 0; | ||
2205 | unsigned rpipe_ready = 0, seg_index; | ||
2206 | int expected_size; | ||
2207 | |||
2208 | /* We have a xfer result buffer; check it */ | ||
2209 | dev_dbg(dev, "DTI: isoc packet status %d bytes at %p\n", | ||
2210 | urb->actual_length, urb->transfer_buffer); | ||
2211 | packet_status = (struct wa_xfer_packet_status_hwaiso *)(wa->dti_buf); | ||
2212 | if (packet_status->bPacketType != WA_XFER_ISO_PACKET_STATUS) { | ||
2213 | dev_err(dev, "DTI Error: isoc packet status--bad type 0x%02x\n", | ||
2214 | packet_status->bPacketType); | ||
2215 | goto error_parse_buffer; | ||
2216 | } | ||
2217 | xfer = wa_xfer_get_by_id(wa, wa->dti_isoc_xfer_in_progress); | ||
2218 | if (xfer == NULL) { | ||
2219 | dev_err(dev, "DTI Error: isoc packet status--unknown xfer 0x%08x\n", | ||
2220 | wa->dti_isoc_xfer_in_progress); | ||
2221 | goto error_parse_buffer; | ||
2222 | } | ||
2223 | spin_lock_irqsave(&xfer->lock, flags); | ||
2224 | if (unlikely(wa->dti_isoc_xfer_seg >= xfer->segs)) | ||
2225 | goto error_bad_seg; | ||
2226 | seg = xfer->seg[wa->dti_isoc_xfer_seg]; | ||
2227 | rpipe = xfer->ep->hcpriv; | ||
2228 | expected_size = sizeof(*packet_status) + | ||
2229 | (sizeof(packet_status->PacketStatus[0]) * | ||
2230 | seg->isoc_frame_count); | ||
2231 | if (urb->actual_length != expected_size) { | ||
2232 | dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d bytes vs %d needed)\n", | ||
2233 | urb->actual_length, expected_size); | ||
2234 | goto error_bad_seg; | ||
2235 | } | ||
2236 | if (le16_to_cpu(packet_status->wLength) != expected_size) { | ||
2237 | dev_err(dev, "DTI Error: isoc packet status--bad length %u\n", | ||
2238 | le16_to_cpu(packet_status->wLength)); | ||
2239 | goto error_bad_seg; | ||
2240 | } | ||
2241 | /* isoc packet status and lengths back xfer urb. */ | ||
2242 | status_array = packet_status->PacketStatus; | ||
2243 | for (seg_index = 0; seg_index < seg->isoc_frame_count; ++seg_index) { | ||
2244 | xfer->urb->iso_frame_desc[seg->index].status = | ||
2245 | wa_xfer_status_to_errno( | ||
2246 | le16_to_cpu(status_array[seg_index].PacketStatus)); | ||
2247 | xfer->urb->iso_frame_desc[seg->index].actual_length = | ||
2248 | le16_to_cpu(status_array[seg_index].PacketLength); | ||
2249 | } | ||
2250 | |||
2251 | if (!xfer->is_inbound) { | ||
2252 | /* OUT transfer, complete it -- */ | ||
2253 | seg->status = WA_SEG_DONE; | ||
2254 | xfer->segs_done++; | ||
2255 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
2256 | done = __wa_xfer_is_done(xfer); | ||
2257 | } | ||
2258 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
2259 | wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING; | ||
2260 | if (done) | ||
2261 | wa_xfer_completion(xfer); | ||
2262 | if (rpipe_ready) | ||
2263 | wa_xfer_delayed_run(rpipe); | ||
2264 | wa_xfer_put(xfer); | ||
2265 | return; | ||
2266 | |||
2267 | error_bad_seg: | ||
2268 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
2269 | wa_xfer_put(xfer); | ||
2270 | error_parse_buffer: | ||
2271 | return; | ||
2272 | } | ||
2273 | |||
2274 | /* | ||
1590 | * Callback for the IN data phase | 2275 | * Callback for the IN data phase |
1591 | * | 2276 | * |
1592 | * If successful transition state; otherwise, take a note of the | 2277 | * If successful transition state; otherwise, take a note of the |
@@ -1687,56 +2372,61 @@ static void wa_buf_in_cb(struct urb *urb) | |||
1687 | * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many | 2372 | * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many |
1688 | * errors) in the URBs. | 2373 | * errors) in the URBs. |
1689 | */ | 2374 | */ |
1690 | static void wa_xfer_result_cb(struct urb *urb) | 2375 | static void wa_dti_cb(struct urb *urb) |
1691 | { | 2376 | { |
1692 | int result; | 2377 | int result; |
1693 | struct wahc *wa = urb->context; | 2378 | struct wahc *wa = urb->context; |
1694 | struct device *dev = &wa->usb_iface->dev; | 2379 | struct device *dev = &wa->usb_iface->dev; |
1695 | struct wa_xfer_result *xfer_result; | ||
1696 | u32 xfer_id; | 2380 | u32 xfer_id; |
1697 | struct wa_xfer *xfer; | ||
1698 | u8 usb_status; | 2381 | u8 usb_status; |
1699 | 2382 | ||
1700 | BUG_ON(wa->dti_urb != urb); | 2383 | BUG_ON(wa->dti_urb != urb); |
1701 | switch (wa->dti_urb->status) { | 2384 | switch (wa->dti_urb->status) { |
1702 | case 0: | 2385 | case 0: |
1703 | /* We have a xfer result buffer; check it */ | 2386 | if (wa->dti_state == WA_DTI_TRANSFER_RESULT_PENDING) { |
1704 | dev_dbg(dev, "DTI: xfer result %d bytes at %p\n", | 2387 | struct wa_xfer_result *xfer_result; |
1705 | urb->actual_length, urb->transfer_buffer); | 2388 | struct wa_xfer *xfer; |
1706 | if (wa->dti_urb->actual_length != sizeof(*xfer_result)) { | 2389 | |
1707 | dev_err(dev, "DTI Error: xfer result--bad size " | 2390 | /* We have a xfer result buffer; check it */ |
1708 | "xfer result (%d bytes vs %zu needed)\n", | 2391 | dev_dbg(dev, "DTI: xfer result %d bytes at %p\n", |
1709 | urb->actual_length, sizeof(*xfer_result)); | 2392 | urb->actual_length, urb->transfer_buffer); |
1710 | break; | 2393 | if (urb->actual_length != sizeof(*xfer_result)) { |
1711 | } | 2394 | dev_err(dev, "DTI Error: xfer result--bad size xfer result (%d bytes vs %zu needed)\n", |
1712 | xfer_result = wa->xfer_result; | 2395 | urb->actual_length, |
1713 | if (xfer_result->hdr.bLength != sizeof(*xfer_result)) { | 2396 | sizeof(*xfer_result)); |
1714 | dev_err(dev, "DTI Error: xfer result--" | 2397 | break; |
1715 | "bad header length %u\n", | 2398 | } |
1716 | xfer_result->hdr.bLength); | 2399 | xfer_result = (struct wa_xfer_result *)(wa->dti_buf); |
1717 | break; | 2400 | if (xfer_result->hdr.bLength != sizeof(*xfer_result)) { |
1718 | } | 2401 | dev_err(dev, "DTI Error: xfer result--bad header length %u\n", |
1719 | if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) { | 2402 | xfer_result->hdr.bLength); |
1720 | dev_err(dev, "DTI Error: xfer result--" | 2403 | break; |
1721 | "bad header type 0x%02x\n", | 2404 | } |
1722 | xfer_result->hdr.bNotifyType); | 2405 | if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) { |
1723 | break; | 2406 | dev_err(dev, "DTI Error: xfer result--bad header type 0x%02x\n", |
1724 | } | 2407 | xfer_result->hdr.bNotifyType); |
1725 | usb_status = xfer_result->bTransferStatus & 0x3f; | 2408 | break; |
1726 | if (usb_status == WA_XFER_STATUS_NOT_FOUND) | 2409 | } |
1727 | /* taken care of already */ | 2410 | usb_status = xfer_result->bTransferStatus & 0x3f; |
1728 | break; | 2411 | if (usb_status == WA_XFER_STATUS_NOT_FOUND) |
1729 | xfer_id = xfer_result->dwTransferID; | 2412 | /* taken care of already */ |
1730 | xfer = wa_xfer_get_by_id(wa, xfer_id); | 2413 | break; |
1731 | if (xfer == NULL) { | 2414 | xfer_id = le32_to_cpu(xfer_result->dwTransferID); |
1732 | /* FIXME: transaction might have been cancelled */ | 2415 | xfer = wa_xfer_get_by_id(wa, xfer_id); |
1733 | dev_err(dev, "DTI Error: xfer result--" | 2416 | if (xfer == NULL) { |
1734 | "unknown xfer 0x%08x (status 0x%02x)\n", | 2417 | /* FIXME: transaction not found. */ |
1735 | xfer_id, usb_status); | 2418 | dev_err(dev, "DTI Error: xfer result--unknown xfer 0x%08x (status 0x%02x)\n", |
1736 | break; | 2419 | xfer_id, usb_status); |
2420 | break; | ||
2421 | } | ||
2422 | wa_xfer_result_chew(wa, xfer, xfer_result); | ||
2423 | wa_xfer_put(xfer); | ||
2424 | } else if (wa->dti_state == WA_DTI_ISOC_PACKET_STATUS_PENDING) { | ||
2425 | wa_process_iso_packet_status(wa, urb); | ||
2426 | } else { | ||
2427 | dev_err(dev, "DTI Error: unexpected EP state = %d\n", | ||
2428 | wa->dti_state); | ||
1737 | } | 2429 | } |
1738 | wa_xfer_result_chew(wa, xfer); | ||
1739 | wa_xfer_put(xfer); | ||
1740 | break; | 2430 | break; |
1741 | case -ENOENT: /* (we killed the URB)...so, no broadcast */ | 2431 | case -ENOENT: /* (we killed the URB)...so, no broadcast */ |
1742 | case -ESHUTDOWN: /* going away! */ | 2432 | case -ESHUTDOWN: /* going away! */ |
@@ -1777,7 +2467,7 @@ out: | |||
1777 | * don't really set it up and start it until the first xfer complete | 2467 | * don't really set it up and start it until the first xfer complete |
1778 | * notification arrives, which is what we do here. | 2468 | * notification arrives, which is what we do here. |
1779 | * | 2469 | * |
1780 | * Follow up in wa_xfer_result_cb(), as that's where the whole state | 2470 | * Follow up in wa_dti_cb(), as that's where the whole state |
1781 | * machine starts. | 2471 | * machine starts. |
1782 | * | 2472 | * |
1783 | * So here we just initialize the DTI URB for reading transfer result | 2473 | * So here we just initialize the DTI URB for reading transfer result |
@@ -1813,8 +2503,8 @@ void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr) | |||
1813 | usb_fill_bulk_urb( | 2503 | usb_fill_bulk_urb( |
1814 | wa->dti_urb, wa->usb_dev, | 2504 | wa->dti_urb, wa->usb_dev, |
1815 | usb_rcvbulkpipe(wa->usb_dev, 0x80 | notif_xfer->bEndpoint), | 2505 | usb_rcvbulkpipe(wa->usb_dev, 0x80 | notif_xfer->bEndpoint), |
1816 | wa->xfer_result, wa->xfer_result_size, | 2506 | wa->dti_buf, wa->dti_buf_size, |
1817 | wa_xfer_result_cb, wa); | 2507 | wa_dti_cb, wa); |
1818 | 2508 | ||
1819 | wa->buf_in_urb = usb_alloc_urb(0, GFP_KERNEL); | 2509 | wa->buf_in_urb = usb_alloc_urb(0, GFP_KERNEL); |
1820 | if (wa->buf_in_urb == NULL) { | 2510 | if (wa->buf_in_urb == NULL) { |
@@ -1836,6 +2526,7 @@ out: | |||
1836 | 2526 | ||
1837 | error_dti_urb_submit: | 2527 | error_dti_urb_submit: |
1838 | usb_put_urb(wa->buf_in_urb); | 2528 | usb_put_urb(wa->buf_in_urb); |
2529 | wa->buf_in_urb = NULL; | ||
1839 | error_buf_in_urb_alloc: | 2530 | error_buf_in_urb_alloc: |
1840 | usb_put_urb(wa->dti_urb); | 2531 | usb_put_urb(wa->dti_urb); |
1841 | wa->dti_urb = NULL; | 2532 | wa->dti_urb = NULL; |
diff --git a/drivers/uwb/lc-dev.c b/drivers/uwb/lc-dev.c index 9209eafc75b1..80079b8fed15 100644 --- a/drivers/uwb/lc-dev.c +++ b/drivers/uwb/lc-dev.c | |||
@@ -244,7 +244,7 @@ static ssize_t uwb_dev_RSSI_store(struct device *dev, | |||
244 | static DEVICE_ATTR(RSSI, S_IRUGO | S_IWUSR, uwb_dev_RSSI_show, uwb_dev_RSSI_store); | 244 | static DEVICE_ATTR(RSSI, S_IRUGO | S_IWUSR, uwb_dev_RSSI_show, uwb_dev_RSSI_store); |
245 | 245 | ||
246 | 246 | ||
247 | static struct attribute *dev_attrs[] = { | 247 | static struct attribute *uwb_dev_attrs[] = { |
248 | &dev_attr_EUI_48.attr, | 248 | &dev_attr_EUI_48.attr, |
249 | &dev_attr_DevAddr.attr, | 249 | &dev_attr_DevAddr.attr, |
250 | &dev_attr_BPST.attr, | 250 | &dev_attr_BPST.attr, |
@@ -253,20 +253,10 @@ static struct attribute *dev_attrs[] = { | |||
253 | &dev_attr_RSSI.attr, | 253 | &dev_attr_RSSI.attr, |
254 | NULL, | 254 | NULL, |
255 | }; | 255 | }; |
256 | 256 | ATTRIBUTE_GROUPS(uwb_dev); | |
257 | static struct attribute_group dev_attr_group = { | ||
258 | .attrs = dev_attrs, | ||
259 | }; | ||
260 | |||
261 | static const struct attribute_group *groups[] = { | ||
262 | &dev_attr_group, | ||
263 | NULL, | ||
264 | }; | ||
265 | 257 | ||
266 | /** | 258 | /** |
267 | * Device SYSFS registration | 259 | * Device SYSFS registration |
268 | * | ||
269 | * | ||
270 | */ | 260 | */ |
271 | static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev) | 261 | static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev) |
272 | { | 262 | { |
@@ -276,7 +266,7 @@ static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev) | |||
276 | /* Device sysfs files are only useful for neighbor devices not | 266 | /* Device sysfs files are only useful for neighbor devices not |
277 | local radio controllers. */ | 267 | local radio controllers. */ |
278 | if (&uwb_dev->rc->uwb_dev != uwb_dev) | 268 | if (&uwb_dev->rc->uwb_dev != uwb_dev) |
279 | dev->groups = groups; | 269 | dev->groups = uwb_dev_groups; |
280 | dev->parent = parent_dev; | 270 | dev->parent = parent_dev; |
281 | dev_set_drvdata(dev, uwb_dev); | 271 | dev_set_drvdata(dev, uwb_dev); |
282 | 272 | ||
diff --git a/drivers/video/exynos/Kconfig b/drivers/video/exynos/Kconfig index 1b035b2eb6b6..1129d0e9e640 100644 --- a/drivers/video/exynos/Kconfig +++ b/drivers/video/exynos/Kconfig | |||
@@ -16,6 +16,7 @@ if EXYNOS_VIDEO | |||
16 | config EXYNOS_MIPI_DSI | 16 | config EXYNOS_MIPI_DSI |
17 | bool "EXYNOS MIPI DSI driver support." | 17 | bool "EXYNOS MIPI DSI driver support." |
18 | depends on ARCH_S5PV210 || ARCH_EXYNOS | 18 | depends on ARCH_S5PV210 || ARCH_EXYNOS |
19 | select GENERIC_PHY | ||
19 | help | 20 | help |
20 | This enables support for MIPI-DSI device. | 21 | This enables support for MIPI-DSI device. |
21 | 22 | ||
@@ -29,7 +30,7 @@ config EXYNOS_LCD_S6E8AX0 | |||
29 | 30 | ||
30 | config EXYNOS_DP | 31 | config EXYNOS_DP |
31 | bool "EXYNOS DP driver support" | 32 | bool "EXYNOS DP driver support" |
32 | depends on ARCH_EXYNOS | 33 | depends on OF && ARCH_EXYNOS |
33 | default n | 34 | default n |
34 | help | 35 | help |
35 | This enables support for DP device. | 36 | This enables support for DP device. |
diff --git a/drivers/video/exynos/exynos_dp_core.c b/drivers/video/exynos/exynos_dp_core.c index 12bbede3b091..5e1a71580051 100644 --- a/drivers/video/exynos/exynos_dp_core.c +++ b/drivers/video/exynos/exynos_dp_core.c | |||
@@ -19,8 +19,7 @@ | |||
19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
21 | #include <linux/of.h> | 21 | #include <linux/of.h> |
22 | 22 | #include <linux/phy/phy.h> | |
23 | #include <video/exynos_dp.h> | ||
24 | 23 | ||
25 | #include "exynos_dp_core.h" | 24 | #include "exynos_dp_core.h" |
26 | 25 | ||
@@ -894,26 +893,17 @@ static void exynos_dp_hotplug(struct work_struct *work) | |||
894 | dev_err(dp->dev, "unable to config video\n"); | 893 | dev_err(dp->dev, "unable to config video\n"); |
895 | } | 894 | } |
896 | 895 | ||
897 | #ifdef CONFIG_OF | 896 | static struct video_info *exynos_dp_dt_parse_pdata(struct device *dev) |
898 | static struct exynos_dp_platdata *exynos_dp_dt_parse_pdata(struct device *dev) | ||
899 | { | 897 | { |
900 | struct device_node *dp_node = dev->of_node; | 898 | struct device_node *dp_node = dev->of_node; |
901 | struct exynos_dp_platdata *pd; | ||
902 | struct video_info *dp_video_config; | 899 | struct video_info *dp_video_config; |
903 | 900 | ||
904 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); | ||
905 | if (!pd) { | ||
906 | dev_err(dev, "memory allocation for pdata failed\n"); | ||
907 | return ERR_PTR(-ENOMEM); | ||
908 | } | ||
909 | dp_video_config = devm_kzalloc(dev, | 901 | dp_video_config = devm_kzalloc(dev, |
910 | sizeof(*dp_video_config), GFP_KERNEL); | 902 | sizeof(*dp_video_config), GFP_KERNEL); |
911 | |||
912 | if (!dp_video_config) { | 903 | if (!dp_video_config) { |
913 | dev_err(dev, "memory allocation for video config failed\n"); | 904 | dev_err(dev, "memory allocation for video config failed\n"); |
914 | return ERR_PTR(-ENOMEM); | 905 | return ERR_PTR(-ENOMEM); |
915 | } | 906 | } |
916 | pd->video_info = dp_video_config; | ||
917 | 907 | ||
918 | dp_video_config->h_sync_polarity = | 908 | dp_video_config->h_sync_polarity = |
919 | of_property_read_bool(dp_node, "hsync-active-high"); | 909 | of_property_read_bool(dp_node, "hsync-active-high"); |
@@ -960,7 +950,7 @@ static struct exynos_dp_platdata *exynos_dp_dt_parse_pdata(struct device *dev) | |||
960 | return ERR_PTR(-EINVAL); | 950 | return ERR_PTR(-EINVAL); |
961 | } | 951 | } |
962 | 952 | ||
963 | return pd; | 953 | return dp_video_config; |
964 | } | 954 | } |
965 | 955 | ||
966 | static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp) | 956 | static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp) |
@@ -971,8 +961,11 @@ static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp) | |||
971 | 961 | ||
972 | dp_phy_node = of_find_node_by_name(dp_phy_node, "dptx-phy"); | 962 | dp_phy_node = of_find_node_by_name(dp_phy_node, "dptx-phy"); |
973 | if (!dp_phy_node) { | 963 | if (!dp_phy_node) { |
974 | dev_err(dp->dev, "could not find dptx-phy node\n"); | 964 | dp->phy = devm_phy_get(dp->dev, "dp"); |
975 | return -ENODEV; | 965 | if (IS_ERR(dp->phy)) |
966 | return PTR_ERR(dp->phy); | ||
967 | else | ||
968 | return 0; | ||
976 | } | 969 | } |
977 | 970 | ||
978 | if (of_property_read_u32(dp_phy_node, "reg", &phy_base)) { | 971 | if (of_property_read_u32(dp_phy_node, "reg", &phy_base)) { |
@@ -1003,48 +996,34 @@ err: | |||
1003 | 996 | ||
1004 | static void exynos_dp_phy_init(struct exynos_dp_device *dp) | 997 | static void exynos_dp_phy_init(struct exynos_dp_device *dp) |
1005 | { | 998 | { |
1006 | u32 reg; | 999 | if (dp->phy) { |
1007 | 1000 | phy_power_on(dp->phy); | |
1008 | reg = __raw_readl(dp->phy_addr); | 1001 | } else if (dp->phy_addr) { |
1009 | reg |= dp->enable_mask; | 1002 | u32 reg; |
1010 | __raw_writel(reg, dp->phy_addr); | 1003 | |
1011 | } | 1004 | reg = __raw_readl(dp->phy_addr); |
1012 | 1005 | reg |= dp->enable_mask; | |
1013 | static void exynos_dp_phy_exit(struct exynos_dp_device *dp) | 1006 | __raw_writel(reg, dp->phy_addr); |
1014 | { | 1007 | } |
1015 | u32 reg; | ||
1016 | |||
1017 | reg = __raw_readl(dp->phy_addr); | ||
1018 | reg &= ~(dp->enable_mask); | ||
1019 | __raw_writel(reg, dp->phy_addr); | ||
1020 | } | ||
1021 | #else | ||
1022 | static struct exynos_dp_platdata *exynos_dp_dt_parse_pdata(struct device *dev) | ||
1023 | { | ||
1024 | return NULL; | ||
1025 | } | ||
1026 | |||
1027 | static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp) | ||
1028 | { | ||
1029 | return -EINVAL; | ||
1030 | } | ||
1031 | |||
1032 | static void exynos_dp_phy_init(struct exynos_dp_device *dp) | ||
1033 | { | ||
1034 | return; | ||
1035 | } | 1008 | } |
1036 | 1009 | ||
1037 | static void exynos_dp_phy_exit(struct exynos_dp_device *dp) | 1010 | static void exynos_dp_phy_exit(struct exynos_dp_device *dp) |
1038 | { | 1011 | { |
1039 | return; | 1012 | if (dp->phy) { |
1013 | phy_power_off(dp->phy); | ||
1014 | } else if (dp->phy_addr) { | ||
1015 | u32 reg; | ||
1016 | |||
1017 | reg = __raw_readl(dp->phy_addr); | ||
1018 | reg &= ~(dp->enable_mask); | ||
1019 | __raw_writel(reg, dp->phy_addr); | ||
1020 | } | ||
1040 | } | 1021 | } |
1041 | #endif /* CONFIG_OF */ | ||
1042 | 1022 | ||
1043 | static int exynos_dp_probe(struct platform_device *pdev) | 1023 | static int exynos_dp_probe(struct platform_device *pdev) |
1044 | { | 1024 | { |
1045 | struct resource *res; | 1025 | struct resource *res; |
1046 | struct exynos_dp_device *dp; | 1026 | struct exynos_dp_device *dp; |
1047 | struct exynos_dp_platdata *pdata; | ||
1048 | 1027 | ||
1049 | int ret = 0; | 1028 | int ret = 0; |
1050 | 1029 | ||
@@ -1057,21 +1036,13 @@ static int exynos_dp_probe(struct platform_device *pdev) | |||
1057 | 1036 | ||
1058 | dp->dev = &pdev->dev; | 1037 | dp->dev = &pdev->dev; |
1059 | 1038 | ||
1060 | if (pdev->dev.of_node) { | 1039 | dp->video_info = exynos_dp_dt_parse_pdata(&pdev->dev); |
1061 | pdata = exynos_dp_dt_parse_pdata(&pdev->dev); | 1040 | if (IS_ERR(dp->video_info)) |
1062 | if (IS_ERR(pdata)) | 1041 | return PTR_ERR(dp->video_info); |
1063 | return PTR_ERR(pdata); | ||
1064 | 1042 | ||
1065 | ret = exynos_dp_dt_parse_phydata(dp); | 1043 | ret = exynos_dp_dt_parse_phydata(dp); |
1066 | if (ret) | 1044 | if (ret) |
1067 | return ret; | 1045 | return ret; |
1068 | } else { | ||
1069 | pdata = pdev->dev.platform_data; | ||
1070 | if (!pdata) { | ||
1071 | dev_err(&pdev->dev, "no platform data\n"); | ||
1072 | return -EINVAL; | ||
1073 | } | ||
1074 | } | ||
1075 | 1046 | ||
1076 | dp->clock = devm_clk_get(&pdev->dev, "dp"); | 1047 | dp->clock = devm_clk_get(&pdev->dev, "dp"); |
1077 | if (IS_ERR(dp->clock)) { | 1048 | if (IS_ERR(dp->clock)) { |
@@ -1095,15 +1066,7 @@ static int exynos_dp_probe(struct platform_device *pdev) | |||
1095 | 1066 | ||
1096 | INIT_WORK(&dp->hotplug_work, exynos_dp_hotplug); | 1067 | INIT_WORK(&dp->hotplug_work, exynos_dp_hotplug); |
1097 | 1068 | ||
1098 | dp->video_info = pdata->video_info; | 1069 | exynos_dp_phy_init(dp); |
1099 | |||
1100 | if (pdev->dev.of_node) { | ||
1101 | if (dp->phy_addr) | ||
1102 | exynos_dp_phy_init(dp); | ||
1103 | } else { | ||
1104 | if (pdata->phy_init) | ||
1105 | pdata->phy_init(); | ||
1106 | } | ||
1107 | 1070 | ||
1108 | exynos_dp_init_dp(dp); | 1071 | exynos_dp_init_dp(dp); |
1109 | 1072 | ||
@@ -1121,18 +1084,11 @@ static int exynos_dp_probe(struct platform_device *pdev) | |||
1121 | 1084 | ||
1122 | static int exynos_dp_remove(struct platform_device *pdev) | 1085 | static int exynos_dp_remove(struct platform_device *pdev) |
1123 | { | 1086 | { |
1124 | struct exynos_dp_platdata *pdata = pdev->dev.platform_data; | ||
1125 | struct exynos_dp_device *dp = platform_get_drvdata(pdev); | 1087 | struct exynos_dp_device *dp = platform_get_drvdata(pdev); |
1126 | 1088 | ||
1127 | flush_work(&dp->hotplug_work); | 1089 | flush_work(&dp->hotplug_work); |
1128 | 1090 | ||
1129 | if (pdev->dev.of_node) { | 1091 | exynos_dp_phy_exit(dp); |
1130 | if (dp->phy_addr) | ||
1131 | exynos_dp_phy_exit(dp); | ||
1132 | } else { | ||
1133 | if (pdata->phy_exit) | ||
1134 | pdata->phy_exit(); | ||
1135 | } | ||
1136 | 1092 | ||
1137 | clk_disable_unprepare(dp->clock); | 1093 | clk_disable_unprepare(dp->clock); |
1138 | 1094 | ||
@@ -1143,20 +1099,13 @@ static int exynos_dp_remove(struct platform_device *pdev) | |||
1143 | #ifdef CONFIG_PM_SLEEP | 1099 | #ifdef CONFIG_PM_SLEEP |
1144 | static int exynos_dp_suspend(struct device *dev) | 1100 | static int exynos_dp_suspend(struct device *dev) |
1145 | { | 1101 | { |
1146 | struct exynos_dp_platdata *pdata = dev->platform_data; | ||
1147 | struct exynos_dp_device *dp = dev_get_drvdata(dev); | 1102 | struct exynos_dp_device *dp = dev_get_drvdata(dev); |
1148 | 1103 | ||
1149 | disable_irq(dp->irq); | 1104 | disable_irq(dp->irq); |
1150 | 1105 | ||
1151 | flush_work(&dp->hotplug_work); | 1106 | flush_work(&dp->hotplug_work); |
1152 | 1107 | ||
1153 | if (dev->of_node) { | 1108 | exynos_dp_phy_exit(dp); |
1154 | if (dp->phy_addr) | ||
1155 | exynos_dp_phy_exit(dp); | ||
1156 | } else { | ||
1157 | if (pdata->phy_exit) | ||
1158 | pdata->phy_exit(); | ||
1159 | } | ||
1160 | 1109 | ||
1161 | clk_disable_unprepare(dp->clock); | 1110 | clk_disable_unprepare(dp->clock); |
1162 | 1111 | ||
@@ -1165,16 +1114,9 @@ static int exynos_dp_suspend(struct device *dev) | |||
1165 | 1114 | ||
1166 | static int exynos_dp_resume(struct device *dev) | 1115 | static int exynos_dp_resume(struct device *dev) |
1167 | { | 1116 | { |
1168 | struct exynos_dp_platdata *pdata = dev->platform_data; | ||
1169 | struct exynos_dp_device *dp = dev_get_drvdata(dev); | 1117 | struct exynos_dp_device *dp = dev_get_drvdata(dev); |
1170 | 1118 | ||
1171 | if (dev->of_node) { | 1119 | exynos_dp_phy_init(dp); |
1172 | if (dp->phy_addr) | ||
1173 | exynos_dp_phy_init(dp); | ||
1174 | } else { | ||
1175 | if (pdata->phy_init) | ||
1176 | pdata->phy_init(); | ||
1177 | } | ||
1178 | 1120 | ||
1179 | clk_prepare_enable(dp->clock); | 1121 | clk_prepare_enable(dp->clock); |
1180 | 1122 | ||
@@ -1203,7 +1145,7 @@ static struct platform_driver exynos_dp_driver = { | |||
1203 | .name = "exynos-dp", | 1145 | .name = "exynos-dp", |
1204 | .owner = THIS_MODULE, | 1146 | .owner = THIS_MODULE, |
1205 | .pm = &exynos_dp_pm_ops, | 1147 | .pm = &exynos_dp_pm_ops, |
1206 | .of_match_table = of_match_ptr(exynos_dp_match), | 1148 | .of_match_table = exynos_dp_match, |
1207 | }, | 1149 | }, |
1208 | }; | 1150 | }; |
1209 | 1151 | ||
diff --git a/drivers/video/exynos/exynos_dp_core.h b/drivers/video/exynos/exynos_dp_core.h index 6c567bbf2fb8..607e36d0c147 100644 --- a/drivers/video/exynos/exynos_dp_core.h +++ b/drivers/video/exynos/exynos_dp_core.h | |||
@@ -13,6 +13,99 @@ | |||
13 | #ifndef _EXYNOS_DP_CORE_H | 13 | #ifndef _EXYNOS_DP_CORE_H |
14 | #define _EXYNOS_DP_CORE_H | 14 | #define _EXYNOS_DP_CORE_H |
15 | 15 | ||
16 | #define DP_TIMEOUT_LOOP_COUNT 100 | ||
17 | #define MAX_CR_LOOP 5 | ||
18 | #define MAX_EQ_LOOP 5 | ||
19 | |||
20 | enum link_rate_type { | ||
21 | LINK_RATE_1_62GBPS = 0x06, | ||
22 | LINK_RATE_2_70GBPS = 0x0a | ||
23 | }; | ||
24 | |||
25 | enum link_lane_count_type { | ||
26 | LANE_COUNT1 = 1, | ||
27 | LANE_COUNT2 = 2, | ||
28 | LANE_COUNT4 = 4 | ||
29 | }; | ||
30 | |||
31 | enum link_training_state { | ||
32 | START, | ||
33 | CLOCK_RECOVERY, | ||
34 | EQUALIZER_TRAINING, | ||
35 | FINISHED, | ||
36 | FAILED | ||
37 | }; | ||
38 | |||
39 | enum voltage_swing_level { | ||
40 | VOLTAGE_LEVEL_0, | ||
41 | VOLTAGE_LEVEL_1, | ||
42 | VOLTAGE_LEVEL_2, | ||
43 | VOLTAGE_LEVEL_3, | ||
44 | }; | ||
45 | |||
46 | enum pre_emphasis_level { | ||
47 | PRE_EMPHASIS_LEVEL_0, | ||
48 | PRE_EMPHASIS_LEVEL_1, | ||
49 | PRE_EMPHASIS_LEVEL_2, | ||
50 | PRE_EMPHASIS_LEVEL_3, | ||
51 | }; | ||
52 | |||
53 | enum pattern_set { | ||
54 | PRBS7, | ||
55 | D10_2, | ||
56 | TRAINING_PTN1, | ||
57 | TRAINING_PTN2, | ||
58 | DP_NONE | ||
59 | }; | ||
60 | |||
61 | enum color_space { | ||
62 | COLOR_RGB, | ||
63 | COLOR_YCBCR422, | ||
64 | COLOR_YCBCR444 | ||
65 | }; | ||
66 | |||
67 | enum color_depth { | ||
68 | COLOR_6, | ||
69 | COLOR_8, | ||
70 | COLOR_10, | ||
71 | COLOR_12 | ||
72 | }; | ||
73 | |||
74 | enum color_coefficient { | ||
75 | COLOR_YCBCR601, | ||
76 | COLOR_YCBCR709 | ||
77 | }; | ||
78 | |||
79 | enum dynamic_range { | ||
80 | VESA, | ||
81 | CEA | ||
82 | }; | ||
83 | |||
84 | enum pll_status { | ||
85 | PLL_UNLOCKED, | ||
86 | PLL_LOCKED | ||
87 | }; | ||
88 | |||
89 | enum clock_recovery_m_value_type { | ||
90 | CALCULATED_M, | ||
91 | REGISTER_M | ||
92 | }; | ||
93 | |||
94 | enum video_timing_recognition_type { | ||
95 | VIDEO_TIMING_FROM_CAPTURE, | ||
96 | VIDEO_TIMING_FROM_REGISTER | ||
97 | }; | ||
98 | |||
99 | enum analog_power_block { | ||
100 | AUX_BLOCK, | ||
101 | CH0_BLOCK, | ||
102 | CH1_BLOCK, | ||
103 | CH2_BLOCK, | ||
104 | CH3_BLOCK, | ||
105 | ANALOG_TOTAL, | ||
106 | POWER_ALL | ||
107 | }; | ||
108 | |||
16 | enum dp_irq_type { | 109 | enum dp_irq_type { |
17 | DP_IRQ_TYPE_HP_CABLE_IN, | 110 | DP_IRQ_TYPE_HP_CABLE_IN, |
18 | DP_IRQ_TYPE_HP_CABLE_OUT, | 111 | DP_IRQ_TYPE_HP_CABLE_OUT, |
@@ -20,6 +113,22 @@ enum dp_irq_type { | |||
20 | DP_IRQ_TYPE_UNKNOWN, | 113 | DP_IRQ_TYPE_UNKNOWN, |
21 | }; | 114 | }; |
22 | 115 | ||
116 | struct video_info { | ||
117 | char *name; | ||
118 | |||
119 | bool h_sync_polarity; | ||
120 | bool v_sync_polarity; | ||
121 | bool interlaced; | ||
122 | |||
123 | enum color_space color_space; | ||
124 | enum dynamic_range dynamic_range; | ||
125 | enum color_coefficient ycbcr_coeff; | ||
126 | enum color_depth color_depth; | ||
127 | |||
128 | enum link_rate_type link_rate; | ||
129 | enum link_lane_count_type lane_count; | ||
130 | }; | ||
131 | |||
23 | struct link_train { | 132 | struct link_train { |
24 | int eq_loop; | 133 | int eq_loop; |
25 | int cr_loop[4]; | 134 | int cr_loop[4]; |
@@ -42,6 +151,7 @@ struct exynos_dp_device { | |||
42 | struct video_info *video_info; | 151 | struct video_info *video_info; |
43 | struct link_train link_train; | 152 | struct link_train link_train; |
44 | struct work_struct hotplug_work; | 153 | struct work_struct hotplug_work; |
154 | struct phy *phy; | ||
45 | }; | 155 | }; |
46 | 156 | ||
47 | /* exynos_dp_reg.c */ | 157 | /* exynos_dp_reg.c */ |
diff --git a/drivers/video/exynos/exynos_dp_reg.c b/drivers/video/exynos/exynos_dp_reg.c index 29d9d035c73a..b70da5052ff0 100644 --- a/drivers/video/exynos/exynos_dp_reg.c +++ b/drivers/video/exynos/exynos_dp_reg.c | |||
@@ -14,8 +14,6 @@ | |||
14 | #include <linux/io.h> | 14 | #include <linux/io.h> |
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | 16 | ||
17 | #include <video/exynos_dp.h> | ||
18 | |||
19 | #include "exynos_dp_core.h" | 17 | #include "exynos_dp_core.h" |
20 | #include "exynos_dp_reg.h" | 18 | #include "exynos_dp_reg.h" |
21 | 19 | ||
diff --git a/drivers/video/exynos/exynos_mipi_dsi.c b/drivers/video/exynos/exynos_mipi_dsi.c index 32e540600f99..00b3a52c1d68 100644 --- a/drivers/video/exynos/exynos_mipi_dsi.c +++ b/drivers/video/exynos/exynos_mipi_dsi.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/interrupt.h> | 30 | #include <linux/interrupt.h> |
31 | #include <linux/kthread.h> | 31 | #include <linux/kthread.h> |
32 | #include <linux/notifier.h> | 32 | #include <linux/notifier.h> |
33 | #include <linux/phy/phy.h> | ||
33 | #include <linux/regulator/consumer.h> | 34 | #include <linux/regulator/consumer.h> |
34 | #include <linux/pm_runtime.h> | 35 | #include <linux/pm_runtime.h> |
35 | #include <linux/err.h> | 36 | #include <linux/err.h> |
@@ -156,8 +157,7 @@ static int exynos_mipi_dsi_blank_mode(struct mipi_dsim_device *dsim, int power) | |||
156 | exynos_mipi_regulator_enable(dsim); | 157 | exynos_mipi_regulator_enable(dsim); |
157 | 158 | ||
158 | /* enable MIPI-DSI PHY. */ | 159 | /* enable MIPI-DSI PHY. */ |
159 | if (dsim->pd->phy_enable) | 160 | phy_power_on(dsim->phy); |
160 | dsim->pd->phy_enable(pdev, true); | ||
161 | 161 | ||
162 | clk_enable(dsim->clock); | 162 | clk_enable(dsim->clock); |
163 | 163 | ||
@@ -373,6 +373,10 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) | |||
373 | return ret; | 373 | return ret; |
374 | } | 374 | } |
375 | 375 | ||
376 | dsim->phy = devm_phy_get(&pdev->dev, "dsim"); | ||
377 | if (IS_ERR(dsim->phy)) | ||
378 | return PTR_ERR(dsim->phy); | ||
379 | |||
376 | dsim->clock = devm_clk_get(&pdev->dev, "dsim0"); | 380 | dsim->clock = devm_clk_get(&pdev->dev, "dsim0"); |
377 | if (IS_ERR(dsim->clock)) { | 381 | if (IS_ERR(dsim->clock)) { |
378 | dev_err(&pdev->dev, "failed to get dsim clock source\n"); | 382 | dev_err(&pdev->dev, "failed to get dsim clock source\n"); |
@@ -439,8 +443,7 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) | |||
439 | exynos_mipi_regulator_enable(dsim); | 443 | exynos_mipi_regulator_enable(dsim); |
440 | 444 | ||
441 | /* enable MIPI-DSI PHY. */ | 445 | /* enable MIPI-DSI PHY. */ |
442 | if (dsim->pd->phy_enable) | 446 | phy_power_on(dsim->phy); |
443 | dsim->pd->phy_enable(pdev, true); | ||
444 | 447 | ||
445 | exynos_mipi_update_cfg(dsim); | 448 | exynos_mipi_update_cfg(dsim); |
446 | 449 | ||
@@ -504,9 +507,8 @@ static int exynos_mipi_dsi_suspend(struct device *dev) | |||
504 | if (client_drv && client_drv->suspend) | 507 | if (client_drv && client_drv->suspend) |
505 | client_drv->suspend(client_dev); | 508 | client_drv->suspend(client_dev); |
506 | 509 | ||
507 | /* enable MIPI-DSI PHY. */ | 510 | /* disable MIPI-DSI PHY. */ |
508 | if (dsim->pd->phy_enable) | 511 | phy_power_off(dsim->phy); |
509 | dsim->pd->phy_enable(pdev, false); | ||
510 | 512 | ||
511 | clk_disable(dsim->clock); | 513 | clk_disable(dsim->clock); |
512 | 514 | ||
@@ -536,8 +538,7 @@ static int exynos_mipi_dsi_resume(struct device *dev) | |||
536 | exynos_mipi_regulator_enable(dsim); | 538 | exynos_mipi_regulator_enable(dsim); |
537 | 539 | ||
538 | /* enable MIPI-DSI PHY. */ | 540 | /* enable MIPI-DSI PHY. */ |
539 | if (dsim->pd->phy_enable) | 541 | phy_power_on(dsim->phy); |
540 | dsim->pd->phy_enable(pdev, true); | ||
541 | 542 | ||
542 | clk_enable(dsim->clock); | 543 | clk_enable(dsim->clock); |
543 | 544 | ||
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h index 81cbbdb96aae..673a3ce67f31 100644 --- a/include/linux/i2c/twl.h +++ b/include/linux/i2c/twl.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #define __TWL_H_ | 26 | #define __TWL_H_ |
27 | 27 | ||
28 | #include <linux/types.h> | 28 | #include <linux/types.h> |
29 | #include <linux/phy/phy.h> | ||
29 | #include <linux/input/matrix_keypad.h> | 30 | #include <linux/input/matrix_keypad.h> |
30 | 31 | ||
31 | /* | 32 | /* |
@@ -615,6 +616,7 @@ enum twl4030_usb_mode { | |||
615 | struct twl4030_usb_data { | 616 | struct twl4030_usb_data { |
616 | enum twl4030_usb_mode usb_mode; | 617 | enum twl4030_usb_mode usb_mode; |
617 | unsigned long features; | 618 | unsigned long features; |
619 | struct phy_init_data *init_data; | ||
618 | 620 | ||
619 | int (*phy_init)(struct device *dev); | 621 | int (*phy_init)(struct device *dev); |
620 | int (*phy_exit)(struct device *dev); | 622 | int (*phy_exit)(struct device *dev); |
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h new file mode 100644 index 000000000000..6d722695e027 --- /dev/null +++ b/include/linux/phy/phy.h | |||
@@ -0,0 +1,270 @@ | |||
1 | /* | ||
2 | * phy.h -- generic phy header file | ||
3 | * | ||
4 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * | ||
6 | * Author: Kishon Vijay Abraham I <kishon@ti.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #ifndef __DRIVERS_PHY_H | ||
15 | #define __DRIVERS_PHY_H | ||
16 | |||
17 | #include <linux/err.h> | ||
18 | #include <linux/of.h> | ||
19 | #include <linux/device.h> | ||
20 | #include <linux/pm_runtime.h> | ||
21 | |||
22 | struct phy; | ||
23 | |||
24 | /** | ||
25 | * struct phy_ops - set of function pointers for performing phy operations | ||
26 | * @init: operation to be performed for initializing phy | ||
27 | * @exit: operation to be performed while exiting | ||
28 | * @power_on: powering on the phy | ||
29 | * @power_off: powering off the phy | ||
30 | * @owner: the module owner containing the ops | ||
31 | */ | ||
32 | struct phy_ops { | ||
33 | int (*init)(struct phy *phy); | ||
34 | int (*exit)(struct phy *phy); | ||
35 | int (*power_on)(struct phy *phy); | ||
36 | int (*power_off)(struct phy *phy); | ||
37 | struct module *owner; | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * struct phy - represents the phy device | ||
42 | * @dev: phy device | ||
43 | * @id: id of the phy device | ||
44 | * @ops: function pointers for performing phy operations | ||
45 | * @init_data: list of PHY consumers (non-dt only) | ||
46 | * @mutex: mutex to protect phy_ops | ||
47 | * @init_count: used to protect when the PHY is used by multiple consumers | ||
48 | * @power_count: used to protect when the PHY is used by multiple consumers | ||
49 | */ | ||
50 | struct phy { | ||
51 | struct device dev; | ||
52 | int id; | ||
53 | const struct phy_ops *ops; | ||
54 | struct phy_init_data *init_data; | ||
55 | struct mutex mutex; | ||
56 | int init_count; | ||
57 | int power_count; | ||
58 | }; | ||
59 | |||
60 | /** | ||
61 | * struct phy_provider - represents the phy provider | ||
62 | * @dev: phy provider device | ||
63 | * @owner: the module owner having of_xlate | ||
64 | * @of_xlate: function pointer to obtain phy instance from phy pointer | ||
65 | * @list: to maintain a linked list of PHY providers | ||
66 | */ | ||
67 | struct phy_provider { | ||
68 | struct device *dev; | ||
69 | struct module *owner; | ||
70 | struct list_head list; | ||
71 | struct phy * (*of_xlate)(struct device *dev, | ||
72 | struct of_phandle_args *args); | ||
73 | }; | ||
74 | |||
75 | /** | ||
76 | * struct phy_consumer - represents the phy consumer | ||
77 | * @dev_name: the device name of the controller that will use this PHY device | ||
78 | * @port: name given to the consumer port | ||
79 | */ | ||
80 | struct phy_consumer { | ||
81 | const char *dev_name; | ||
82 | const char *port; | ||
83 | }; | ||
84 | |||
85 | /** | ||
86 | * struct phy_init_data - contains the list of PHY consumers | ||
87 | * @num_consumers: number of consumers for this PHY device | ||
88 | * @consumers: list of PHY consumers | ||
89 | */ | ||
90 | struct phy_init_data { | ||
91 | unsigned int num_consumers; | ||
92 | struct phy_consumer *consumers; | ||
93 | }; | ||
94 | |||
95 | #define PHY_CONSUMER(_dev_name, _port) \ | ||
96 | { \ | ||
97 | .dev_name = _dev_name, \ | ||
98 | .port = _port, \ | ||
99 | } | ||
100 | |||
101 | #define to_phy(dev) (container_of((dev), struct phy, dev)) | ||
102 | |||
103 | #define of_phy_provider_register(dev, xlate) \ | ||
104 | __of_phy_provider_register((dev), THIS_MODULE, (xlate)) | ||
105 | |||
106 | #define devm_of_phy_provider_register(dev, xlate) \ | ||
107 | __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) | ||
108 | |||
109 | static inline void phy_set_drvdata(struct phy *phy, void *data) | ||
110 | { | ||
111 | dev_set_drvdata(&phy->dev, data); | ||
112 | } | ||
113 | |||
114 | static inline void *phy_get_drvdata(struct phy *phy) | ||
115 | { | ||
116 | return dev_get_drvdata(&phy->dev); | ||
117 | } | ||
118 | |||
119 | #if IS_ENABLED(CONFIG_GENERIC_PHY) | ||
120 | int phy_pm_runtime_get(struct phy *phy); | ||
121 | int phy_pm_runtime_get_sync(struct phy *phy); | ||
122 | int phy_pm_runtime_put(struct phy *phy); | ||
123 | int phy_pm_runtime_put_sync(struct phy *phy); | ||
124 | void phy_pm_runtime_allow(struct phy *phy); | ||
125 | void phy_pm_runtime_forbid(struct phy *phy); | ||
126 | int phy_init(struct phy *phy); | ||
127 | int phy_exit(struct phy *phy); | ||
128 | int phy_power_on(struct phy *phy); | ||
129 | int phy_power_off(struct phy *phy); | ||
130 | struct phy *phy_get(struct device *dev, const char *string); | ||
131 | struct phy *devm_phy_get(struct device *dev, const char *string); | ||
132 | void phy_put(struct phy *phy); | ||
133 | void devm_phy_put(struct device *dev, struct phy *phy); | ||
134 | struct phy *of_phy_simple_xlate(struct device *dev, | ||
135 | struct of_phandle_args *args); | ||
136 | struct phy *phy_create(struct device *dev, const struct phy_ops *ops, | ||
137 | struct phy_init_data *init_data); | ||
138 | struct phy *devm_phy_create(struct device *dev, | ||
139 | const struct phy_ops *ops, struct phy_init_data *init_data); | ||
140 | void phy_destroy(struct phy *phy); | ||
141 | void devm_phy_destroy(struct device *dev, struct phy *phy); | ||
142 | struct phy_provider *__of_phy_provider_register(struct device *dev, | ||
143 | struct module *owner, struct phy * (*of_xlate)(struct device *dev, | ||
144 | struct of_phandle_args *args)); | ||
145 | struct phy_provider *__devm_of_phy_provider_register(struct device *dev, | ||
146 | struct module *owner, struct phy * (*of_xlate)(struct device *dev, | ||
147 | struct of_phandle_args *args)); | ||
148 | void of_phy_provider_unregister(struct phy_provider *phy_provider); | ||
149 | void devm_of_phy_provider_unregister(struct device *dev, | ||
150 | struct phy_provider *phy_provider); | ||
151 | #else | ||
152 | static inline int phy_pm_runtime_get(struct phy *phy) | ||
153 | { | ||
154 | return -ENOSYS; | ||
155 | } | ||
156 | |||
157 | static inline int phy_pm_runtime_get_sync(struct phy *phy) | ||
158 | { | ||
159 | return -ENOSYS; | ||
160 | } | ||
161 | |||
162 | static inline int phy_pm_runtime_put(struct phy *phy) | ||
163 | { | ||
164 | return -ENOSYS; | ||
165 | } | ||
166 | |||
167 | static inline int phy_pm_runtime_put_sync(struct phy *phy) | ||
168 | { | ||
169 | return -ENOSYS; | ||
170 | } | ||
171 | |||
172 | static inline void phy_pm_runtime_allow(struct phy *phy) | ||
173 | { | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | static inline void phy_pm_runtime_forbid(struct phy *phy) | ||
178 | { | ||
179 | return; | ||
180 | } | ||
181 | |||
182 | static inline int phy_init(struct phy *phy) | ||
183 | { | ||
184 | return -ENOSYS; | ||
185 | } | ||
186 | |||
187 | static inline int phy_exit(struct phy *phy) | ||
188 | { | ||
189 | return -ENOSYS; | ||
190 | } | ||
191 | |||
192 | static inline int phy_power_on(struct phy *phy) | ||
193 | { | ||
194 | return -ENOSYS; | ||
195 | } | ||
196 | |||
197 | static inline int phy_power_off(struct phy *phy) | ||
198 | { | ||
199 | return -ENOSYS; | ||
200 | } | ||
201 | |||
202 | static inline struct phy *phy_get(struct device *dev, const char *string) | ||
203 | { | ||
204 | return ERR_PTR(-ENOSYS); | ||
205 | } | ||
206 | |||
207 | static inline struct phy *devm_phy_get(struct device *dev, const char *string) | ||
208 | { | ||
209 | return ERR_PTR(-ENOSYS); | ||
210 | } | ||
211 | |||
212 | static inline void phy_put(struct phy *phy) | ||
213 | { | ||
214 | } | ||
215 | |||
216 | static inline void devm_phy_put(struct device *dev, struct phy *phy) | ||
217 | { | ||
218 | } | ||
219 | |||
220 | static inline struct phy *of_phy_simple_xlate(struct device *dev, | ||
221 | struct of_phandle_args *args) | ||
222 | { | ||
223 | return ERR_PTR(-ENOSYS); | ||
224 | } | ||
225 | |||
226 | static inline struct phy *phy_create(struct device *dev, | ||
227 | const struct phy_ops *ops, struct phy_init_data *init_data) | ||
228 | { | ||
229 | return ERR_PTR(-ENOSYS); | ||
230 | } | ||
231 | |||
232 | static inline struct phy *devm_phy_create(struct device *dev, | ||
233 | const struct phy_ops *ops, struct phy_init_data *init_data) | ||
234 | { | ||
235 | return ERR_PTR(-ENOSYS); | ||
236 | } | ||
237 | |||
238 | static inline void phy_destroy(struct phy *phy) | ||
239 | { | ||
240 | } | ||
241 | |||
242 | static inline void devm_phy_destroy(struct device *dev, struct phy *phy) | ||
243 | { | ||
244 | } | ||
245 | |||
246 | static inline struct phy_provider *__of_phy_provider_register( | ||
247 | struct device *dev, struct module *owner, struct phy * (*of_xlate)( | ||
248 | struct device *dev, struct of_phandle_args *args)) | ||
249 | { | ||
250 | return ERR_PTR(-ENOSYS); | ||
251 | } | ||
252 | |||
253 | static inline struct phy_provider *__devm_of_phy_provider_register(struct device | ||
254 | *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev, | ||
255 | struct of_phandle_args *args)) | ||
256 | { | ||
257 | return ERR_PTR(-ENOSYS); | ||
258 | } | ||
259 | |||
260 | static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) | ||
261 | { | ||
262 | } | ||
263 | |||
264 | static inline void devm_of_phy_provider_unregister(struct device *dev, | ||
265 | struct phy_provider *phy_provider) | ||
266 | { | ||
267 | } | ||
268 | #endif | ||
269 | |||
270 | #endif /* __DRIVERS_PHY_H */ | ||
diff --git a/include/linux/platform_data/mipi-csis.h b/include/linux/platform_data/mipi-csis.h index bf34e17cee7f..c2fd9024717c 100644 --- a/include/linux/platform_data/mipi-csis.h +++ b/include/linux/platform_data/mipi-csis.h | |||
@@ -25,13 +25,4 @@ struct s5p_platform_mipi_csis { | |||
25 | u8 hs_settle; | 25 | u8 hs_settle; |
26 | }; | 26 | }; |
27 | 27 | ||
28 | /** | ||
29 | * s5p_csis_phy_enable - global MIPI-CSI receiver D-PHY control | ||
30 | * @id: MIPI-CSIS harware instance index (0...1) | ||
31 | * @on: true to enable D-PHY and deassert its reset | ||
32 | * false to disable D-PHY | ||
33 | * @return: 0 on success, or negative error code on failure | ||
34 | */ | ||
35 | int s5p_csis_phy_enable(int id, bool on); | ||
36 | |||
37 | #endif /* __PLAT_SAMSUNG_MIPI_CSIS_H_ */ | 28 | #endif /* __PLAT_SAMSUNG_MIPI_CSIS_H_ */ |
diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h deleted file mode 100644 index 5f28cae18582..000000000000 --- a/include/linux/platform_data/usb-ehci-s5p.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Samsung Electronics Co.Ltd | ||
3 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | */ | ||
10 | |||
11 | #ifndef __PLAT_SAMSUNG_EHCI_H | ||
12 | #define __PLAT_SAMSUNG_EHCI_H __FILE__ | ||
13 | |||
14 | struct s5p_ehci_platdata { | ||
15 | int (*phy_init)(struct platform_device *pdev, int type); | ||
16 | int (*phy_exit)(struct platform_device *pdev, int type); | ||
17 | }; | ||
18 | |||
19 | extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd); | ||
20 | |||
21 | #endif /* __PLAT_SAMSUNG_EHCI_H */ | ||
diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h deleted file mode 100644 index c256c595be5e..000000000000 --- a/include/linux/platform_data/usb-ohci-exynos.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Samsung Electronics Co.Ltd | ||
3 | * http://www.samsung.com/ | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | */ | ||
10 | |||
11 | #ifndef __MACH_EXYNOS_OHCI_H | ||
12 | #define __MACH_EXYNOS_OHCI_H | ||
13 | |||
14 | struct exynos4_ohci_platdata { | ||
15 | int (*phy_init)(struct platform_device *pdev, int type); | ||
16 | int (*phy_exit)(struct platform_device *pdev, int type); | ||
17 | }; | ||
18 | |||
19 | extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd); | ||
20 | |||
21 | #endif /* __MACH_EXYNOS_OHCI_H */ | ||
diff --git a/include/linux/platform_data/usb-rcar-gen2-phy.h b/include/linux/platform_data/usb-rcar-gen2-phy.h new file mode 100644 index 000000000000..dd3ba46c0d90 --- /dev/null +++ b/include/linux/platform_data/usb-rcar-gen2-phy.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Renesas Solutions Corp. | ||
3 | * Copyright (C) 2013 Cogent Embedded, Inc. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #ifndef __USB_RCAR_GEN2_PHY_H | ||
11 | #define __USB_RCAR_GEN2_PHY_H | ||
12 | |||
13 | #include <linux/types.h> | ||
14 | |||
15 | struct rcar_gen2_phy_platform_data { | ||
16 | /* USB channel 0 configuration */ | ||
17 | bool chan0_pci:1; /* true: PCI USB host 0, false: USBHS */ | ||
18 | /* USB channel 2 configuration */ | ||
19 | bool chan2_pci:1; /* true: PCI USB host 2, false: USBSS */ | ||
20 | }; | ||
21 | |||
22 | #endif | ||
diff --git a/include/linux/printk.h b/include/linux/printk.h index e6131a782481..694925837a16 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h | |||
@@ -233,6 +233,8 @@ extern asmlinkage void dump_stack(void) __cold; | |||
233 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | 233 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
234 | #endif | 234 | #endif |
235 | 235 | ||
236 | #include <linux/dynamic_debug.h> | ||
237 | |||
236 | /* If you are writing a driver, please use dev_dbg instead */ | 238 | /* If you are writing a driver, please use dev_dbg instead */ |
237 | #if defined(CONFIG_DYNAMIC_DEBUG) | 239 | #if defined(CONFIG_DYNAMIC_DEBUG) |
238 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ | 240 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
@@ -343,7 +345,19 @@ extern asmlinkage void dump_stack(void) __cold; | |||
343 | #endif | 345 | #endif |
344 | 346 | ||
345 | /* If you are writing a driver, please use dev_dbg instead */ | 347 | /* If you are writing a driver, please use dev_dbg instead */ |
346 | #if defined(DEBUG) | 348 | #if defined(CONFIG_DYNAMIC_DEBUG) |
349 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ | ||
350 | #define pr_debug_ratelimited(fmt, ...) \ | ||
351 | do { \ | ||
352 | static DEFINE_RATELIMIT_STATE(_rs, \ | ||
353 | DEFAULT_RATELIMIT_INTERVAL, \ | ||
354 | DEFAULT_RATELIMIT_BURST); \ | ||
355 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ | ||
356 | if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ | ||
357 | __ratelimit(&_rs)) \ | ||
358 | __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \ | ||
359 | } while (0) | ||
360 | #elif defined(DEBUG) | ||
347 | #define pr_debug_ratelimited(fmt, ...) \ | 361 | #define pr_debug_ratelimited(fmt, ...) \ |
348 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | 362 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
349 | #else | 363 | #else |
diff --git a/include/linux/usb.h b/include/linux/usb.h index 001629cd1a97..7454865ad148 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -475,7 +475,8 @@ struct usb3_lpm_parameters { | |||
475 | * @lpm_capable: device supports LPM | 475 | * @lpm_capable: device supports LPM |
476 | * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM | 476 | * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM |
477 | * @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM | 477 | * @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM |
478 | * @usb2_hw_lpm_enabled: USB2 hardware LPM enabled | 478 | * @usb2_hw_lpm_enabled: USB2 hardware LPM is enabled |
479 | * @usb2_hw_lpm_allowed: Userspace allows USB 2.0 LPM to be enabled | ||
479 | * @usb3_lpm_enabled: USB3 hardware LPM enabled | 480 | * @usb3_lpm_enabled: USB3 hardware LPM enabled |
480 | * @string_langid: language ID for strings | 481 | * @string_langid: language ID for strings |
481 | * @product: iProduct string, if present (static) | 482 | * @product: iProduct string, if present (static) |
@@ -548,6 +549,7 @@ struct usb_device { | |||
548 | unsigned usb2_hw_lpm_capable:1; | 549 | unsigned usb2_hw_lpm_capable:1; |
549 | unsigned usb2_hw_lpm_besl_capable:1; | 550 | unsigned usb2_hw_lpm_besl_capable:1; |
550 | unsigned usb2_hw_lpm_enabled:1; | 551 | unsigned usb2_hw_lpm_enabled:1; |
552 | unsigned usb2_hw_lpm_allowed:1; | ||
551 | unsigned usb3_lpm_enabled:1; | 553 | unsigned usb3_lpm_enabled:1; |
552 | int string_langid; | 554 | int string_langid; |
553 | 555 | ||
@@ -702,7 +704,7 @@ extern int usb_alloc_streams(struct usb_interface *interface, | |||
702 | unsigned int num_streams, gfp_t mem_flags); | 704 | unsigned int num_streams, gfp_t mem_flags); |
703 | 705 | ||
704 | /* Reverts a group of bulk endpoints back to not using stream IDs. */ | 706 | /* Reverts a group of bulk endpoints back to not using stream IDs. */ |
705 | extern void usb_free_streams(struct usb_interface *interface, | 707 | extern int usb_free_streams(struct usb_interface *interface, |
706 | struct usb_host_endpoint **eps, unsigned int num_eps, | 708 | struct usb_host_endpoint **eps, unsigned int num_eps, |
707 | gfp_t mem_flags); | 709 | gfp_t mem_flags); |
708 | 710 | ||
@@ -1209,11 +1211,13 @@ struct usb_anchor { | |||
1209 | struct list_head urb_list; | 1211 | struct list_head urb_list; |
1210 | wait_queue_head_t wait; | 1212 | wait_queue_head_t wait; |
1211 | spinlock_t lock; | 1213 | spinlock_t lock; |
1214 | atomic_t suspend_wakeups; | ||
1212 | unsigned int poisoned:1; | 1215 | unsigned int poisoned:1; |
1213 | }; | 1216 | }; |
1214 | 1217 | ||
1215 | static inline void init_usb_anchor(struct usb_anchor *anchor) | 1218 | static inline void init_usb_anchor(struct usb_anchor *anchor) |
1216 | { | 1219 | { |
1220 | memset(anchor, 0, sizeof(*anchor)); | ||
1217 | INIT_LIST_HEAD(&anchor->urb_list); | 1221 | INIT_LIST_HEAD(&anchor->urb_list); |
1218 | init_waitqueue_head(&anchor->wait); | 1222 | init_waitqueue_head(&anchor->wait); |
1219 | spin_lock_init(&anchor->lock); | 1223 | spin_lock_init(&anchor->lock); |
@@ -1574,6 +1578,8 @@ extern void usb_kill_anchored_urbs(struct usb_anchor *anchor); | |||
1574 | extern void usb_poison_anchored_urbs(struct usb_anchor *anchor); | 1578 | extern void usb_poison_anchored_urbs(struct usb_anchor *anchor); |
1575 | extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor); | 1579 | extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor); |
1576 | extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor); | 1580 | extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor); |
1581 | extern void usb_anchor_suspend_wakeups(struct usb_anchor *anchor); | ||
1582 | extern void usb_anchor_resume_wakeups(struct usb_anchor *anchor); | ||
1577 | extern void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor); | 1583 | extern void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor); |
1578 | extern void usb_unanchor_urb(struct urb *urb); | 1584 | extern void usb_unanchor_urb(struct urb *urb); |
1579 | extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, | 1585 | extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, |
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 75efc45eaa2f..b8aba196f7f1 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h | |||
@@ -73,6 +73,7 @@ struct giveback_urb_bh { | |||
73 | spinlock_t lock; | 73 | spinlock_t lock; |
74 | struct list_head head; | 74 | struct list_head head; |
75 | struct tasklet_struct bh; | 75 | struct tasklet_struct bh; |
76 | struct usb_host_endpoint *completing_ep; | ||
76 | }; | 77 | }; |
77 | 78 | ||
78 | struct usb_hcd { | 79 | struct usb_hcd { |
@@ -140,6 +141,7 @@ struct usb_hcd { | |||
140 | unsigned wireless:1; /* Wireless USB HCD */ | 141 | unsigned wireless:1; /* Wireless USB HCD */ |
141 | unsigned authorized_default:1; | 142 | unsigned authorized_default:1; |
142 | unsigned has_tt:1; /* Integrated TT in root hub */ | 143 | unsigned has_tt:1; /* Integrated TT in root hub */ |
144 | unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */ | ||
143 | 145 | ||
144 | unsigned int irq; /* irq allocated */ | 146 | unsigned int irq; /* irq allocated */ |
145 | void __iomem *regs; /* device memory/io */ | 147 | void __iomem *regs; /* device memory/io */ |
@@ -378,6 +380,12 @@ static inline int hcd_giveback_urb_in_bh(struct usb_hcd *hcd) | |||
378 | return hcd->driver->flags & HCD_BH; | 380 | return hcd->driver->flags & HCD_BH; |
379 | } | 381 | } |
380 | 382 | ||
383 | static inline bool hcd_periodic_completion_in_progress(struct usb_hcd *hcd, | ||
384 | struct usb_host_endpoint *ep) | ||
385 | { | ||
386 | return hcd->high_prio_bh.completing_ep == ep; | ||
387 | } | ||
388 | |||
381 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); | 389 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); |
382 | extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, | 390 | extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, |
383 | int status); | 391 | int status); |
@@ -428,6 +436,8 @@ extern int usb_hcd_pci_probe(struct pci_dev *dev, | |||
428 | extern void usb_hcd_pci_remove(struct pci_dev *dev); | 436 | extern void usb_hcd_pci_remove(struct pci_dev *dev); |
429 | extern void usb_hcd_pci_shutdown(struct pci_dev *dev); | 437 | extern void usb_hcd_pci_shutdown(struct pci_dev *dev); |
430 | 438 | ||
439 | extern int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *dev); | ||
440 | |||
431 | #ifdef CONFIG_PM | 441 | #ifdef CONFIG_PM |
432 | extern const struct dev_pm_ops usb_hcd_pci_pm_ops; | 442 | extern const struct dev_pm_ops usb_hcd_pci_pm_ops; |
433 | #endif | 443 | #endif |
@@ -496,6 +506,7 @@ struct usb_tt { | |||
496 | struct usb_device *hub; /* upstream highspeed hub */ | 506 | struct usb_device *hub; /* upstream highspeed hub */ |
497 | int multi; /* true means one TT per port */ | 507 | int multi; /* true means one TT per port */ |
498 | unsigned think_time; /* think time in ns */ | 508 | unsigned think_time; /* think time in ns */ |
509 | void *hcpriv; /* HCD private data */ | ||
499 | 510 | ||
500 | /* for control/bulk error recovery (CLEAR_TT_BUFFER) */ | 511 | /* for control/bulk error recovery (CLEAR_TT_BUFFER) */ |
501 | spinlock_t lock; | 512 | spinlock_t lock; |
@@ -554,9 +565,8 @@ extern void usb_ep0_reinit(struct usb_device *); | |||
554 | * of (7/6 * 8 * bytecount) = 9.33 * bytecount */ | 565 | * of (7/6 * 8 * bytecount) = 9.33 * bytecount */ |
555 | /* bytecount = data payload byte count */ | 566 | /* bytecount = data payload byte count */ |
556 | 567 | ||
557 | #define NS_TO_US(ns) ((ns + 500L) / 1000L) | 568 | #define NS_TO_US(ns) DIV_ROUND_UP(ns, 1000L) |
558 | /* convert & round nanoseconds to microseconds */ | 569 | /* convert nanoseconds to microseconds, rounding up */ |
559 | |||
560 | 570 | ||
561 | /* | 571 | /* |
562 | * Full/low speed bandwidth allocation constants/support. | 572 | * Full/low speed bandwidth allocation constants/support. |
diff --git a/include/linux/usb/intel_mid_otg.h b/include/linux/usb/intel_mid_otg.h deleted file mode 100644 index 756cf5543ffd..000000000000 --- a/include/linux/usb/intel_mid_otg.h +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | /* | ||
2 | * Intel MID (Langwell/Penwell) USB OTG Transceiver driver | ||
3 | * Copyright (C) 2008 - 2010, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #ifndef __INTEL_MID_OTG_H | ||
21 | #define __INTEL_MID_OTG_H | ||
22 | |||
23 | #include <linux/pm.h> | ||
24 | #include <linux/usb/otg.h> | ||
25 | #include <linux/notifier.h> | ||
26 | |||
27 | struct intel_mid_otg_xceiv; | ||
28 | |||
29 | /* This is a common data structure for Intel MID platform to | ||
30 | * save values of the OTG state machine */ | ||
31 | struct otg_hsm { | ||
32 | /* Input */ | ||
33 | int a_bus_resume; | ||
34 | int a_bus_suspend; | ||
35 | int a_conn; | ||
36 | int a_sess_vld; | ||
37 | int a_srp_det; | ||
38 | int a_vbus_vld; | ||
39 | int b_bus_resume; | ||
40 | int b_bus_suspend; | ||
41 | int b_conn; | ||
42 | int b_se0_srp; | ||
43 | int b_ssend_srp; | ||
44 | int b_sess_end; | ||
45 | int b_sess_vld; | ||
46 | int id; | ||
47 | /* id values */ | ||
48 | #define ID_B 0x05 | ||
49 | #define ID_A 0x04 | ||
50 | #define ID_ACA_C 0x03 | ||
51 | #define ID_ACA_B 0x02 | ||
52 | #define ID_ACA_A 0x01 | ||
53 | int power_up; | ||
54 | int adp_change; | ||
55 | int test_device; | ||
56 | |||
57 | /* Internal variables */ | ||
58 | int a_set_b_hnp_en; | ||
59 | int b_srp_done; | ||
60 | int b_hnp_enable; | ||
61 | int hnp_poll_enable; | ||
62 | |||
63 | /* Timeout indicator for timers */ | ||
64 | int a_wait_vrise_tmout; | ||
65 | int a_wait_bcon_tmout; | ||
66 | int a_aidl_bdis_tmout; | ||
67 | int a_bidl_adis_tmout; | ||
68 | int a_bidl_adis_tmr; | ||
69 | int a_wait_vfall_tmout; | ||
70 | int b_ase0_brst_tmout; | ||
71 | int b_bus_suspend_tmout; | ||
72 | int b_srp_init_tmout; | ||
73 | int b_srp_fail_tmout; | ||
74 | int b_srp_fail_tmr; | ||
75 | int b_adp_sense_tmout; | ||
76 | |||
77 | /* Informative variables */ | ||
78 | int a_bus_drop; | ||
79 | int a_bus_req; | ||
80 | int a_clr_err; | ||
81 | int b_bus_req; | ||
82 | int a_suspend_req; | ||
83 | int b_bus_suspend_vld; | ||
84 | |||
85 | /* Output */ | ||
86 | int drv_vbus; | ||
87 | int loc_conn; | ||
88 | int loc_sof; | ||
89 | |||
90 | /* Others */ | ||
91 | int vbus_srp_up; | ||
92 | }; | ||
93 | |||
94 | /* must provide ULPI access function to read/write registers implemented in | ||
95 | * ULPI address space */ | ||
96 | struct iotg_ulpi_access_ops { | ||
97 | int (*read)(struct intel_mid_otg_xceiv *iotg, u8 reg, u8 *val); | ||
98 | int (*write)(struct intel_mid_otg_xceiv *iotg, u8 reg, u8 val); | ||
99 | }; | ||
100 | |||
101 | #define OTG_A_DEVICE 0x0 | ||
102 | #define OTG_B_DEVICE 0x1 | ||
103 | |||
104 | /* | ||
105 | * the Intel MID (Langwell/Penwell) otg transceiver driver needs to interact | ||
106 | * with device and host drivers to implement the USB OTG related feature. More | ||
107 | * function members are added based on usb_phy data structure for this | ||
108 | * purpose. | ||
109 | */ | ||
110 | struct intel_mid_otg_xceiv { | ||
111 | struct usb_phy otg; | ||
112 | struct otg_hsm hsm; | ||
113 | |||
114 | /* base address */ | ||
115 | void __iomem *base; | ||
116 | |||
117 | /* ops to access ulpi */ | ||
118 | struct iotg_ulpi_access_ops ulpi_ops; | ||
119 | |||
120 | /* atomic notifier for interrupt context */ | ||
121 | struct atomic_notifier_head iotg_notifier; | ||
122 | |||
123 | /* start/stop USB Host function */ | ||
124 | int (*start_host)(struct intel_mid_otg_xceiv *iotg); | ||
125 | int (*stop_host)(struct intel_mid_otg_xceiv *iotg); | ||
126 | |||
127 | /* start/stop USB Peripheral function */ | ||
128 | int (*start_peripheral)(struct intel_mid_otg_xceiv *iotg); | ||
129 | int (*stop_peripheral)(struct intel_mid_otg_xceiv *iotg); | ||
130 | |||
131 | /* start/stop ADP sense/probe function */ | ||
132 | int (*set_adp_probe)(struct intel_mid_otg_xceiv *iotg, | ||
133 | bool enabled, int dev); | ||
134 | int (*set_adp_sense)(struct intel_mid_otg_xceiv *iotg, | ||
135 | bool enabled); | ||
136 | |||
137 | #ifdef CONFIG_PM | ||
138 | /* suspend/resume USB host function */ | ||
139 | int (*suspend_host)(struct intel_mid_otg_xceiv *iotg, | ||
140 | pm_message_t message); | ||
141 | int (*resume_host)(struct intel_mid_otg_xceiv *iotg); | ||
142 | |||
143 | int (*suspend_peripheral)(struct intel_mid_otg_xceiv *iotg, | ||
144 | pm_message_t message); | ||
145 | int (*resume_peripheral)(struct intel_mid_otg_xceiv *iotg); | ||
146 | #endif | ||
147 | |||
148 | }; | ||
149 | static inline | ||
150 | struct intel_mid_otg_xceiv *otg_to_mid_xceiv(struct usb_phy *otg) | ||
151 | { | ||
152 | return container_of(otg, struct intel_mid_otg_xceiv, otg); | ||
153 | } | ||
154 | |||
155 | #define MID_OTG_NOTIFY_CONNECT 0x0001 | ||
156 | #define MID_OTG_NOTIFY_DISCONN 0x0002 | ||
157 | #define MID_OTG_NOTIFY_HSUSPEND 0x0003 | ||
158 | #define MID_OTG_NOTIFY_HRESUME 0x0004 | ||
159 | #define MID_OTG_NOTIFY_CSUSPEND 0x0005 | ||
160 | #define MID_OTG_NOTIFY_CRESUME 0x0006 | ||
161 | #define MID_OTG_NOTIFY_HOSTADD 0x0007 | ||
162 | #define MID_OTG_NOTIFY_HOSTREMOVE 0x0008 | ||
163 | #define MID_OTG_NOTIFY_CLIENTADD 0x0009 | ||
164 | #define MID_OTG_NOTIFY_CLIENTREMOVE 0x000a | ||
165 | |||
166 | static inline int | ||
167 | intel_mid_otg_register_notifier(struct intel_mid_otg_xceiv *iotg, | ||
168 | struct notifier_block *nb) | ||
169 | { | ||
170 | return atomic_notifier_chain_register(&iotg->iotg_notifier, nb); | ||
171 | } | ||
172 | |||
173 | static inline void | ||
174 | intel_mid_otg_unregister_notifier(struct intel_mid_otg_xceiv *iotg, | ||
175 | struct notifier_block *nb) | ||
176 | { | ||
177 | atomic_notifier_chain_unregister(&iotg->iotg_notifier, nb); | ||
178 | } | ||
179 | |||
180 | #endif /* __INTEL_MID_OTG_H */ | ||
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h index 053c26841cc3..eb505250940a 100644 --- a/include/linux/usb/musb.h +++ b/include/linux/usb/musb.h | |||
@@ -99,8 +99,6 @@ struct musb_hdrc_platform_data { | |||
99 | /* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */ | 99 | /* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */ |
100 | u8 mode; | 100 | u8 mode; |
101 | 101 | ||
102 | u8 has_mailbox:1; | ||
103 | |||
104 | /* for clk_get() */ | 102 | /* for clk_get() */ |
105 | const char *clock; | 103 | const char *clock; |
106 | 104 | ||
diff --git a/include/linux/usb/omap_control_usb.h b/include/linux/usb/omap_control_usb.h index 27b5b8c931b0..596b01918813 100644 --- a/include/linux/usb/omap_control_usb.h +++ b/include/linux/usb/omap_control_usb.h | |||
@@ -19,20 +19,23 @@ | |||
19 | #ifndef __OMAP_CONTROL_USB_H__ | 19 | #ifndef __OMAP_CONTROL_USB_H__ |
20 | #define __OMAP_CONTROL_USB_H__ | 20 | #define __OMAP_CONTROL_USB_H__ |
21 | 21 | ||
22 | enum omap_control_usb_type { | ||
23 | OMAP_CTRL_TYPE_OTGHS = 1, /* Mailbox OTGHS_CONTROL */ | ||
24 | OMAP_CTRL_TYPE_USB2, /* USB2_PHY, power down in CONTROL_DEV_CONF */ | ||
25 | OMAP_CTRL_TYPE_PIPE3, /* PIPE3 PHY, DPLL & seperate Rx/Tx power */ | ||
26 | OMAP_CTRL_TYPE_DRA7USB2, /* USB2 PHY, power and power_aux e.g. DRA7 */ | ||
27 | }; | ||
28 | |||
22 | struct omap_control_usb { | 29 | struct omap_control_usb { |
23 | struct device *dev; | 30 | struct device *dev; |
24 | 31 | ||
25 | u32 __iomem *dev_conf; | ||
26 | u32 __iomem *otghs_control; | 32 | u32 __iomem *otghs_control; |
27 | u32 __iomem *phy_power; | 33 | u32 __iomem *power; |
34 | u32 __iomem *power_aux; | ||
28 | 35 | ||
29 | struct clk *sys_clk; | 36 | struct clk *sys_clk; |
30 | 37 | ||
31 | u32 type; | 38 | enum omap_control_usb_type type; |
32 | }; | ||
33 | |||
34 | struct omap_control_usb_platform_data { | ||
35 | u8 type; | ||
36 | }; | 39 | }; |
37 | 40 | ||
38 | enum omap_control_usb_mode { | 41 | enum omap_control_usb_mode { |
@@ -42,10 +45,6 @@ enum omap_control_usb_mode { | |||
42 | USB_MODE_DISCONNECT, | 45 | USB_MODE_DISCONNECT, |
43 | }; | 46 | }; |
44 | 47 | ||
45 | /* To differentiate ctrl module IP having either mailbox or USB3 PHY power */ | ||
46 | #define OMAP_CTRL_DEV_TYPE1 0x1 | ||
47 | #define OMAP_CTRL_DEV_TYPE2 0x2 | ||
48 | |||
49 | #define OMAP_CTRL_DEV_PHY_PD BIT(0) | 48 | #define OMAP_CTRL_DEV_PHY_PD BIT(0) |
50 | 49 | ||
51 | #define OMAP_CTRL_DEV_AVALID BIT(0) | 50 | #define OMAP_CTRL_DEV_AVALID BIT(0) |
@@ -63,26 +62,18 @@ enum omap_control_usb_mode { | |||
63 | #define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3 | 62 | #define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3 |
64 | #define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0 | 63 | #define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0 |
65 | 64 | ||
65 | #define OMAP_CTRL_USB2_PHY_PD BIT(28) | ||
66 | |||
66 | #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB) | 67 | #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB) |
67 | extern struct device *omap_get_control_dev(void); | ||
68 | extern void omap_control_usb_phy_power(struct device *dev, int on); | 68 | extern void omap_control_usb_phy_power(struct device *dev, int on); |
69 | extern void omap_control_usb3_phy_power(struct device *dev, bool on); | ||
70 | extern void omap_control_usb_set_mode(struct device *dev, | 69 | extern void omap_control_usb_set_mode(struct device *dev, |
71 | enum omap_control_usb_mode mode); | 70 | enum omap_control_usb_mode mode); |
72 | #else | 71 | #else |
73 | static inline struct device *omap_get_control_dev(void) | ||
74 | { | ||
75 | return ERR_PTR(-ENODEV); | ||
76 | } | ||
77 | 72 | ||
78 | static inline void omap_control_usb_phy_power(struct device *dev, int on) | 73 | static inline void omap_control_usb_phy_power(struct device *dev, int on) |
79 | { | 74 | { |
80 | } | 75 | } |
81 | 76 | ||
82 | static inline void omap_control_usb3_phy_power(struct device *dev, int on) | ||
83 | { | ||
84 | } | ||
85 | |||
86 | static inline void omap_control_usb_set_mode(struct device *dev, | 77 | static inline void omap_control_usb_set_mode(struct device *dev, |
87 | enum omap_control_usb_mode mode) | 78 | enum omap_control_usb_mode mode) |
88 | { | 79 | { |
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index d528b8045150..704a1ab8240c 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h | |||
@@ -320,6 +320,8 @@ extern struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor); | |||
320 | extern void usb_serial_put(struct usb_serial *serial); | 320 | extern void usb_serial_put(struct usb_serial *serial); |
321 | extern int usb_serial_generic_open(struct tty_struct *tty, | 321 | extern int usb_serial_generic_open(struct tty_struct *tty, |
322 | struct usb_serial_port *port); | 322 | struct usb_serial_port *port); |
323 | extern int usb_serial_generic_write_start(struct usb_serial_port *port, | ||
324 | gfp_t mem_flags); | ||
323 | extern int usb_serial_generic_write(struct tty_struct *tty, | 325 | extern int usb_serial_generic_write(struct tty_struct *tty, |
324 | struct usb_serial_port *port, const unsigned char *buf, int count); | 326 | struct usb_serial_port *port, const unsigned char *buf, int count); |
325 | extern void usb_serial_generic_close(struct usb_serial_port *port); | 327 | extern void usb_serial_generic_close(struct usb_serial_port *port); |
diff --git a/include/linux/usb/usb_phy_gen_xceiv.h b/include/linux/usb/usb_phy_gen_xceiv.h index 11d85b9c1b08..cc8d818a83be 100644 --- a/include/linux/usb/usb_phy_gen_xceiv.h +++ b/include/linux/usb/usb_phy_gen_xceiv.h | |||
@@ -9,7 +9,8 @@ struct usb_phy_gen_xceiv_platform_data { | |||
9 | 9 | ||
10 | /* if set fails with -EPROBE_DEFER if can't get regulator */ | 10 | /* if set fails with -EPROBE_DEFER if can't get regulator */ |
11 | unsigned int needs_vcc:1; | 11 | unsigned int needs_vcc:1; |
12 | unsigned int needs_reset:1; | 12 | unsigned int needs_reset:1; /* deprecated */ |
13 | int gpio_reset; | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) | 16 | #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) |
diff --git a/include/linux/usb/wusb-wa.h b/include/linux/usb/wusb-wa.h index 4ff744e2b678..c1257130769b 100644 --- a/include/linux/usb/wusb-wa.h +++ b/include/linux/usb/wusb-wa.h | |||
@@ -142,7 +142,7 @@ enum wa_notif_type { | |||
142 | struct wa_notif_hdr { | 142 | struct wa_notif_hdr { |
143 | u8 bLength; | 143 | u8 bLength; |
144 | u8 bNotifyType; /* enum wa_notif_type */ | 144 | u8 bNotifyType; /* enum wa_notif_type */ |
145 | } __attribute__((packed)); | 145 | } __packed; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * HWA DN Received notification [(WUSB] section 8.5.4.2) | 148 | * HWA DN Received notification [(WUSB] section 8.5.4.2) |
@@ -158,7 +158,7 @@ struct hwa_notif_dn { | |||
158 | u8 bSourceDeviceAddr; /* from errata 2005/07 */ | 158 | u8 bSourceDeviceAddr; /* from errata 2005/07 */ |
159 | u8 bmAttributes; | 159 | u8 bmAttributes; |
160 | struct wusb_dn_hdr dndata[]; | 160 | struct wusb_dn_hdr dndata[]; |
161 | } __attribute__((packed)); | 161 | } __packed; |
162 | 162 | ||
163 | /* [WUSB] section 8.3.3 */ | 163 | /* [WUSB] section 8.3.3 */ |
164 | enum wa_xfer_type { | 164 | enum wa_xfer_type { |
@@ -167,6 +167,8 @@ enum wa_xfer_type { | |||
167 | WA_XFER_TYPE_ISO = 0x82, | 167 | WA_XFER_TYPE_ISO = 0x82, |
168 | WA_XFER_RESULT = 0x83, | 168 | WA_XFER_RESULT = 0x83, |
169 | WA_XFER_ABORT = 0x84, | 169 | WA_XFER_ABORT = 0x84, |
170 | WA_XFER_ISO_PACKET_INFO = 0xA0, | ||
171 | WA_XFER_ISO_PACKET_STATUS = 0xA1, | ||
170 | }; | 172 | }; |
171 | 173 | ||
172 | /* [WUSB] section 8.3.3 */ | 174 | /* [WUSB] section 8.3.3 */ |
@@ -177,28 +179,47 @@ struct wa_xfer_hdr { | |||
177 | __le32 dwTransferID; /* Host-assigned ID */ | 179 | __le32 dwTransferID; /* Host-assigned ID */ |
178 | __le32 dwTransferLength; /* Length of data to xfer */ | 180 | __le32 dwTransferLength; /* Length of data to xfer */ |
179 | u8 bTransferSegment; | 181 | u8 bTransferSegment; |
180 | } __attribute__((packed)); | 182 | } __packed; |
181 | 183 | ||
182 | struct wa_xfer_ctl { | 184 | struct wa_xfer_ctl { |
183 | struct wa_xfer_hdr hdr; | 185 | struct wa_xfer_hdr hdr; |
184 | u8 bmAttribute; | 186 | u8 bmAttribute; |
185 | __le16 wReserved; | 187 | __le16 wReserved; |
186 | struct usb_ctrlrequest baSetupData; | 188 | struct usb_ctrlrequest baSetupData; |
187 | } __attribute__((packed)); | 189 | } __packed; |
188 | 190 | ||
189 | struct wa_xfer_bi { | 191 | struct wa_xfer_bi { |
190 | struct wa_xfer_hdr hdr; | 192 | struct wa_xfer_hdr hdr; |
191 | u8 bReserved; | 193 | u8 bReserved; |
192 | __le16 wReserved; | 194 | __le16 wReserved; |
193 | } __attribute__((packed)); | 195 | } __packed; |
194 | 196 | ||
197 | /* [WUSB] section 8.5.5 */ | ||
195 | struct wa_xfer_hwaiso { | 198 | struct wa_xfer_hwaiso { |
196 | struct wa_xfer_hdr hdr; | 199 | struct wa_xfer_hdr hdr; |
197 | u8 bReserved; | 200 | u8 bReserved; |
198 | __le16 wPresentationTime; | 201 | __le16 wPresentationTime; |
199 | __le32 dwNumOfPackets; | 202 | __le32 dwNumOfPackets; |
200 | /* FIXME: u8 pktdata[]? */ | 203 | } __packed; |
201 | } __attribute__((packed)); | 204 | |
205 | struct wa_xfer_packet_info_hwaiso { | ||
206 | __le16 wLength; | ||
207 | u8 bPacketType; | ||
208 | u8 bReserved; | ||
209 | __le16 PacketLength[0]; | ||
210 | } __packed; | ||
211 | |||
212 | struct wa_xfer_packet_status_len_hwaiso { | ||
213 | __le16 PacketLength; | ||
214 | __le16 PacketStatus; | ||
215 | } __packed; | ||
216 | |||
217 | struct wa_xfer_packet_status_hwaiso { | ||
218 | __le16 wLength; | ||
219 | u8 bPacketType; | ||
220 | u8 bReserved; | ||
221 | struct wa_xfer_packet_status_len_hwaiso PacketStatus[0]; | ||
222 | } __packed; | ||
202 | 223 | ||
203 | /* [WUSB] section 8.3.3.5 */ | 224 | /* [WUSB] section 8.3.3.5 */ |
204 | struct wa_xfer_abort { | 225 | struct wa_xfer_abort { |
@@ -206,7 +227,7 @@ struct wa_xfer_abort { | |||
206 | u8 bRequestType; | 227 | u8 bRequestType; |
207 | __le16 wRPipe; /* RPipe index */ | 228 | __le16 wRPipe; /* RPipe index */ |
208 | __le32 dwTransferID; /* Host-assigned ID */ | 229 | __le32 dwTransferID; /* Host-assigned ID */ |
209 | } __attribute__((packed)); | 230 | } __packed; |
210 | 231 | ||
211 | /** | 232 | /** |
212 | * WA Transfer Complete notification ([WUSB] section 8.3.3.3) | 233 | * WA Transfer Complete notification ([WUSB] section 8.3.3.3) |
@@ -216,7 +237,7 @@ struct wa_notif_xfer { | |||
216 | struct wa_notif_hdr hdr; | 237 | struct wa_notif_hdr hdr; |
217 | u8 bEndpoint; | 238 | u8 bEndpoint; |
218 | u8 Reserved; | 239 | u8 Reserved; |
219 | } __attribute__((packed)); | 240 | } __packed; |
220 | 241 | ||
221 | /** Transfer result basic codes [WUSB] table 8-15 */ | 242 | /** Transfer result basic codes [WUSB] table 8-15 */ |
222 | enum { | 243 | enum { |
@@ -243,7 +264,7 @@ struct wa_xfer_result { | |||
243 | u8 bTransferSegment; | 264 | u8 bTransferSegment; |
244 | u8 bTransferStatus; | 265 | u8 bTransferStatus; |
245 | __le32 dwNumOfPackets; | 266 | __le32 dwNumOfPackets; |
246 | } __attribute__((packed)); | 267 | } __packed; |
247 | 268 | ||
248 | /** | 269 | /** |
249 | * Wire Adapter Class Descriptor ([WUSB] section 8.5.2.7). | 270 | * Wire Adapter Class Descriptor ([WUSB] section 8.5.2.7). |
@@ -258,16 +279,16 @@ struct wa_xfer_result { | |||
258 | struct usb_wa_descriptor { | 279 | struct usb_wa_descriptor { |
259 | u8 bLength; | 280 | u8 bLength; |
260 | u8 bDescriptorType; | 281 | u8 bDescriptorType; |
261 | u16 bcdWAVersion; | 282 | __le16 bcdWAVersion; |
262 | u8 bNumPorts; /* don't use!! */ | 283 | u8 bNumPorts; /* don't use!! */ |
263 | u8 bmAttributes; /* Reserved == 0 */ | 284 | u8 bmAttributes; /* Reserved == 0 */ |
264 | u16 wNumRPipes; | 285 | __le16 wNumRPipes; |
265 | u16 wRPipeMaxBlock; | 286 | __le16 wRPipeMaxBlock; |
266 | u8 bRPipeBlockSize; | 287 | u8 bRPipeBlockSize; |
267 | u8 bPwrOn2PwrGood; | 288 | u8 bPwrOn2PwrGood; |
268 | u8 bNumMMCIEs; | 289 | u8 bNumMMCIEs; |
269 | u8 DeviceRemovable; /* FIXME: in DWA this is up to 16 bytes */ | 290 | u8 DeviceRemovable; /* FIXME: in DWA this is up to 16 bytes */ |
270 | } __attribute__((packed)); | 291 | } __packed; |
271 | 292 | ||
272 | /** | 293 | /** |
273 | * HWA Device Information Buffer (WUSB1.0[T8.54]) | 294 | * HWA Device Information Buffer (WUSB1.0[T8.54]) |
@@ -277,6 +298,6 @@ struct hwa_dev_info { | |||
277 | u8 bDeviceAddress; | 298 | u8 bDeviceAddress; |
278 | __le16 wPHYRates; | 299 | __le16 wPHYRates; |
279 | u8 bmDeviceAttribute; | 300 | u8 bmDeviceAttribute; |
280 | } __attribute__((packed)); | 301 | } __packed; |
281 | 302 | ||
282 | #endif /* #ifndef __LINUX_USB_WUSB_WA_H */ | 303 | #endif /* #ifndef __LINUX_USB_WUSB_WA_H */ |
diff --git a/include/video/exynos_dp.h b/include/video/exynos_dp.h deleted file mode 100644 index bd8cabd344db..000000000000 --- a/include/video/exynos_dp.h +++ /dev/null | |||
@@ -1,131 +0,0 @@ | |||
1 | /* | ||
2 | * Samsung SoC DP device support | ||
3 | * | ||
4 | * Copyright (C) 2012 Samsung Electronics Co., Ltd. | ||
5 | * Author: Jingoo Han <jg1.han@samsung.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef _EXYNOS_DP_H | ||
13 | #define _EXYNOS_DP_H | ||
14 | |||
15 | #define DP_TIMEOUT_LOOP_COUNT 100 | ||
16 | #define MAX_CR_LOOP 5 | ||
17 | #define MAX_EQ_LOOP 5 | ||
18 | |||
19 | enum link_rate_type { | ||
20 | LINK_RATE_1_62GBPS = 0x06, | ||
21 | LINK_RATE_2_70GBPS = 0x0a | ||
22 | }; | ||
23 | |||
24 | enum link_lane_count_type { | ||
25 | LANE_COUNT1 = 1, | ||
26 | LANE_COUNT2 = 2, | ||
27 | LANE_COUNT4 = 4 | ||
28 | }; | ||
29 | |||
30 | enum link_training_state { | ||
31 | START, | ||
32 | CLOCK_RECOVERY, | ||
33 | EQUALIZER_TRAINING, | ||
34 | FINISHED, | ||
35 | FAILED | ||
36 | }; | ||
37 | |||
38 | enum voltage_swing_level { | ||
39 | VOLTAGE_LEVEL_0, | ||
40 | VOLTAGE_LEVEL_1, | ||
41 | VOLTAGE_LEVEL_2, | ||
42 | VOLTAGE_LEVEL_3, | ||
43 | }; | ||
44 | |||
45 | enum pre_emphasis_level { | ||
46 | PRE_EMPHASIS_LEVEL_0, | ||
47 | PRE_EMPHASIS_LEVEL_1, | ||
48 | PRE_EMPHASIS_LEVEL_2, | ||
49 | PRE_EMPHASIS_LEVEL_3, | ||
50 | }; | ||
51 | |||
52 | enum pattern_set { | ||
53 | PRBS7, | ||
54 | D10_2, | ||
55 | TRAINING_PTN1, | ||
56 | TRAINING_PTN2, | ||
57 | DP_NONE | ||
58 | }; | ||
59 | |||
60 | enum color_space { | ||
61 | COLOR_RGB, | ||
62 | COLOR_YCBCR422, | ||
63 | COLOR_YCBCR444 | ||
64 | }; | ||
65 | |||
66 | enum color_depth { | ||
67 | COLOR_6, | ||
68 | COLOR_8, | ||
69 | COLOR_10, | ||
70 | COLOR_12 | ||
71 | }; | ||
72 | |||
73 | enum color_coefficient { | ||
74 | COLOR_YCBCR601, | ||
75 | COLOR_YCBCR709 | ||
76 | }; | ||
77 | |||
78 | enum dynamic_range { | ||
79 | VESA, | ||
80 | CEA | ||
81 | }; | ||
82 | |||
83 | enum pll_status { | ||
84 | PLL_UNLOCKED, | ||
85 | PLL_LOCKED | ||
86 | }; | ||
87 | |||
88 | enum clock_recovery_m_value_type { | ||
89 | CALCULATED_M, | ||
90 | REGISTER_M | ||
91 | }; | ||
92 | |||
93 | enum video_timing_recognition_type { | ||
94 | VIDEO_TIMING_FROM_CAPTURE, | ||
95 | VIDEO_TIMING_FROM_REGISTER | ||
96 | }; | ||
97 | |||
98 | enum analog_power_block { | ||
99 | AUX_BLOCK, | ||
100 | CH0_BLOCK, | ||
101 | CH1_BLOCK, | ||
102 | CH2_BLOCK, | ||
103 | CH3_BLOCK, | ||
104 | ANALOG_TOTAL, | ||
105 | POWER_ALL | ||
106 | }; | ||
107 | |||
108 | struct video_info { | ||
109 | char *name; | ||
110 | |||
111 | bool h_sync_polarity; | ||
112 | bool v_sync_polarity; | ||
113 | bool interlaced; | ||
114 | |||
115 | enum color_space color_space; | ||
116 | enum dynamic_range dynamic_range; | ||
117 | enum color_coefficient ycbcr_coeff; | ||
118 | enum color_depth color_depth; | ||
119 | |||
120 | enum link_rate_type link_rate; | ||
121 | enum link_lane_count_type lane_count; | ||
122 | }; | ||
123 | |||
124 | struct exynos_dp_platdata { | ||
125 | struct video_info *video_info; | ||
126 | |||
127 | void (*phy_init)(void); | ||
128 | void (*phy_exit)(void); | ||
129 | }; | ||
130 | |||
131 | #endif /* _EXYNOS_DP_H */ | ||
diff --git a/include/video/exynos_mipi_dsim.h b/include/video/exynos_mipi_dsim.h index 89dc88a171af..6a578f8a1b3e 100644 --- a/include/video/exynos_mipi_dsim.h +++ b/include/video/exynos_mipi_dsim.h | |||
@@ -216,6 +216,7 @@ struct mipi_dsim_config { | |||
216 | * automatically. | 216 | * automatically. |
217 | * @e_clk_src: select byte clock source. | 217 | * @e_clk_src: select byte clock source. |
218 | * @pd: pointer to MIPI-DSI driver platform data. | 218 | * @pd: pointer to MIPI-DSI driver platform data. |
219 | * @phy: pointer to the MIPI-DSI PHY | ||
219 | */ | 220 | */ |
220 | struct mipi_dsim_device { | 221 | struct mipi_dsim_device { |
221 | struct device *dev; | 222 | struct device *dev; |
@@ -236,6 +237,7 @@ struct mipi_dsim_device { | |||
236 | bool suspended; | 237 | bool suspended; |
237 | 238 | ||
238 | struct mipi_dsim_platform_data *pd; | 239 | struct mipi_dsim_platform_data *pd; |
240 | struct phy *phy; | ||
239 | }; | 241 | }; |
240 | 242 | ||
241 | /* | 243 | /* |
@@ -248,7 +250,6 @@ struct mipi_dsim_device { | |||
248 | * @enabled: indicate whether mipi controller got enabled or not. | 250 | * @enabled: indicate whether mipi controller got enabled or not. |
249 | * @lcd_panel_info: pointer for lcd panel specific structure. | 251 | * @lcd_panel_info: pointer for lcd panel specific structure. |
250 | * this structure specifies width, height, timing and polarity and so on. | 252 | * this structure specifies width, height, timing and polarity and so on. |
251 | * @phy_enable: pointer to a callback controlling D-PHY enable/reset | ||
252 | */ | 253 | */ |
253 | struct mipi_dsim_platform_data { | 254 | struct mipi_dsim_platform_data { |
254 | char lcd_panel_name[PANEL_NAME_SIZE]; | 255 | char lcd_panel_name[PANEL_NAME_SIZE]; |
@@ -256,8 +257,6 @@ struct mipi_dsim_platform_data { | |||
256 | struct mipi_dsim_config *dsim_config; | 257 | struct mipi_dsim_config *dsim_config; |
257 | unsigned int enabled; | 258 | unsigned int enabled; |
258 | void *lcd_panel_info; | 259 | void *lcd_panel_info; |
259 | |||
260 | int (*phy_enable)(struct platform_device *pdev, bool on); | ||
261 | }; | 260 | }; |
262 | 261 | ||
263 | /* | 262 | /* |