Pull USB updates from Greg KH: "Here is the big USB driver update for 3.17-rc1. Loads of gadget driver changes in here, including some big file movements to make things easier to manage over time. There's also the usual xhci and uas driver updates, and a handful of other changes in here. The changelog has the full details. All of these have been in linux-next for a while" * tag 'usb-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (211 commits) USB: devio: fix issue with log flooding uas: Log a warning when we cannot use uas because the hcd lacks streams uas: Only complain about missing sg if all other checks succeed xhci: Add missing checks for xhci_alloc_command failure xhci: Rename Asrock P67 pci product-id to EJ168 xhci: Blacklist using streams on the Etron EJ168 controller uas: Limit qdepth to 32 when connected over usb-2 uwb/whci: use correct structure type name in sizeof usb-core bInterval quirk USB: serial: ftdi_sio: Add support for new Xsens devices USB: serial: ftdi_sio: Annotate the current Xsens PID assignments usb: chipidea: debug: fix sparse non static symbol warnings usb: ci_hdrc_imx doc: fsl,usbphy is required usb: ci_hdrc_imx: Return -EINVAL for missing USB PHY usb: core: allow zero packet flag for interrupt urbs usb: lvstest: Fix sparse warnings generated by kbuild test bot USB: core: hcd-pci: free IRQ before disabling PCI device when shutting down phy: miphy365x: Represent each PHY channel as a DT subnode phy: miphy365x: Provide support for the MiPHY356x Generic PHY phy: miphy365x: Add Device Tree bindings for the MiPHY365x ...
Unified · Split
| @@ -3,13 +3,13 @@ Date: May 2007 · 2 unmodified lines | |||
| 3 | KernelVersion: 2.6.23 | 3 | KernelVersion: 2.6.23 |
| 4 | Contact: Alan Stern <stern@rowland.harvard.edu> | 4 | Contact: Alan Stern <stern@rowland.harvard.edu> |
| 5 | Description: | 5 | Description: |
| 6 | If CONFIG_USB_PERSIST is set, then each USB device directory | 6 | USB device directories can contain a file named power/persist. |
| 7 | will contain a file named power/persist. The file holds a | 7 | The file holds a boolean value (0 or 1) indicating whether or |
| 8 | boolean value (0 or 1) indicating whether or not the | 8 | not the "USB-Persist" facility is enabled for the device. For |
| 9 | "USB-Persist" facility is enabled for the device. Since the | 9 | hubs this facility is always enabled and their device |
| 10 | facility is inherently dangerous, it is disabled by default | 10 | directories will not contain this file. |
| 11 | for all devices except hubs. For more information, see | 11 | |
| 12 | Documentation/usb/persist.txt. | 12 | For more information, see Documentation/usb/persist.txt. |
| 13 | 13 | ||
| 14 | What: /sys/bus/usb/devices/.../power/autosuspend | 14 | What: /sys/bus/usb/devices/.../power/autosuspend |
| 15 | Date: March 2007 | 15 | Date: March 2007 |
| @@ -0,0 +1,47 @@ | |||
| 1 | Link Layer Validation Device is a standard device for testing of Super | ||
| 2 | Speed Link Layer tests. These nodes are available in sysfs only when lvs | ||
| 3 | driver is bound with root hub device. | ||
| 4 | |||
| 5 | What: /sys/bus/usb/devices/.../get_dev_desc | ||
| 6 | Date: March 2014 | ||
| 7 | Contact: Pratyush Anand <pratyush.anand@st.com> | ||
| 8 | Description: | ||
| 9 | Write to this node to issue "Get Device Descriptor" | ||
| 10 | for Link Layer Validation device. It is needed for TD.7.06. | ||
| 11 | |||
| 12 | What: /sys/bus/usb/devices/.../u1_timeout | ||
| 13 | Date: March 2014 | ||
| 14 | Contact: Pratyush Anand <pratyush.anand@st.com> | ||
| 15 | Description: | ||
| 16 | Set "U1 timeout" for the downstream port where Link Layer | ||
| 17 | Validation device is connected. Timeout value must be between 0 | ||
| 18 | and 127. It is needed for TD.7.18, TD.7.19, TD.7.20 and TD.7.21. | ||
| 19 | |||
| 20 | What: /sys/bus/usb/devices/.../u2_timeout | ||
| 21 | Date: March 2014 | ||
| 22 | Contact: Pratyush Anand <pratyush.anand@st.com> | ||
| 23 | Description: | ||
| 24 | Set "U2 timeout" for the downstream port where Link Layer | ||
| 25 | Validation device is connected. Timeout value must be between 0 | ||
| 26 | and 127. It is needed for TD.7.18, TD.7.19, TD.7.20 and TD.7.21. | ||
| 27 | |||
| 28 | What: /sys/bus/usb/devices/.../hot_reset | ||
| 29 | Date: March 2014 | ||
| 30 | Contact: Pratyush Anand <pratyush.anand@st.com> | ||
| 31 | Description: | ||
| 32 | Write to this node to issue "Reset" for Link Layer Validation | ||
| 33 | device. It is needed for TD.7.29, TD.7.31, TD.7.34 and TD.7.35. | ||
| 34 | |||
| 35 | What: /sys/bus/usb/devices/.../u3_entry | ||
| 36 | Date: March 2014 | ||
| 37 | Contact: Pratyush Anand <pratyush.anand@st.com> | ||
| 38 | Description: | ||
| 39 | Write to this node to issue "U3 entry" for Link Layer | ||
| 40 | Validation device. It is needed for TD.7.35 and TD.7.36. | ||
| 41 | |||
| 42 | What: /sys/bus/usb/devices/.../u3_exit | ||
| 43 | Date: March 2014 | ||
| 44 | Contact: Pratyush Anand <pratyush.anand@st.com> | ||
| 45 | Description: | ||
| 46 | Write to this node to issue "U3 exit" for Link Layer | ||
| 47 | Validation device. It is needed for TD.7.36. | ||
| @@ -556,11 +556,11 @@ been converted to this framework. · 555 unmodified lines | |||
| 556 | Near-term plans include converting all of them, except for "gadgetfs". | 556 | Near-term plans include converting all of them, except for "gadgetfs". |
| 557 | </para> | 557 | </para> |
| 558 | 558 | ||
| 559 | !Edrivers/usb/gadget/f_acm.c | 559 | !Edrivers/usb/gadget/function/f_acm.c |
| 560 | !Edrivers/usb/gadget/f_ecm.c | 560 | !Edrivers/usb/gadget/function/f_ecm.c |
| 561 | !Edrivers/usb/gadget/f_subset.c | 561 | !Edrivers/usb/gadget/function/f_subset.c |
| 562 | !Edrivers/usb/gadget/f_obex.c | 562 | !Edrivers/usb/gadget/function/f_obex.c |
| 563 | !Edrivers/usb/gadget/f_serial.c | 563 | !Edrivers/usb/gadget/function/f_serial.c |
| 564 | 564 | ||
| 565 | </sect1> | 565 | </sect1> |
| 566 | 566 | ||
| @@ -0,0 +1,34 @@ | |||
| 1 | Berlin SATA PHY | ||
| 2 | --------------- | ||
| 3 | |||
| 4 | Required properties: | ||
| 5 | - compatible: should be "marvell,berlin2q-sata-phy" | ||
| 6 | - address-cells: should be 1 | ||
| 7 | - size-cells: should be 0 | ||
| 8 | - phy-cells: from the generic PHY bindings, must be 1 | ||
| 9 | - reg: address and length of the register | ||
| 10 | - clocks: reference to the clock entry | ||
| 11 | |||
| 12 | Sub-nodes: | ||
| 13 | Each PHY should be represented as a sub-node. | ||
| 14 | |||
| 15 | Sub-nodes required properties: | ||
| 16 | - reg: the PHY number | ||
| 17 | |||
| 18 | Example: | ||
| 19 | sata_phy: phy@f7e900a0 { | ||
| 20 | compatible = "marvell,berlin2q-sata-phy"; | ||
| 21 | reg = <0xf7e900a0 0x200>; | ||
| 22 | clocks = <&chip CLKID_SATA>; | ||
| 23 | #address-cells = <1>; | ||
| 24 | #size-cells = <0>; | ||
| 25 | #phy-cells = <1>; | ||
| 26 | |||
| 27 | sata-phy@0 { | ||
| 28 | reg = <0>; | ||
| 29 | }; | ||
| 30 | |||
| 31 | sata-phy@1 { | ||
| 32 | reg = <1>; | ||
| 33 | }; | ||
| 34 | }; | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | Hisilicon hix5hd2 SATA PHY | ||
| 2 | ----------------------- | ||
| 3 | |||
| 4 | Required properties: | ||
| 5 | - compatible: should be "hisilicon,hix5hd2-sata-phy" | ||
| 6 | - reg: offset and length of the PHY registers | ||
| 7 | - #phy-cells: must be 0 | ||
| 8 | Refer to phy/phy-bindings.txt for the generic PHY binding properties | ||
| 9 | |||
| 10 | Optional Properties: | ||
| 11 | - hisilicon,peripheral-syscon: phandle of syscon used to control peripheral. | ||
| 12 | - hisilicon,power-reg: offset and bit number within peripheral-syscon, | ||
| 13 | register of controlling sata power supply. | ||
| 14 | |||
| 15 | Example: | ||
| 16 | sata_phy: phy@f9900000 { | ||
| 17 | compatible = "hisilicon,hix5hd2-sata-phy"; | ||
| 18 | reg = <0xf9900000 0x10000>; | ||
| 19 | #phy-cells = <0>; | ||
| 20 | hisilicon,peripheral-syscon = <&peripheral_ctrl>; | ||
| 21 | hisilicon,power-reg = <0x8 10>; | ||
| 22 | }; | ||
| @@ -10,6 +10,10 @@ Required Properties: · 9 unmodified lines | |||
| 10 | provider can use the values in cells to find the appropriate | 10 | provider can use the values in cells to find the appropriate |
| 11 | PHY. | 11 | PHY. |
| 12 | 12 | ||
| 13 | Optional Properties: | ||
| 14 | phy-supply: Phandle to a regulator that provides power to the PHY. This | ||
| 15 | regulator will be managed during the PHY power on/off sequence. | ||
| 16 | |||
| 13 | For example: | 17 | For example: |
| 14 | 18 | ||
| 15 | phys: phy { | 19 | phys: phy { |
| @@ -0,0 +1,76 @@ | |||
| 1 | STMicroelectronics STi MIPHY365x PHY binding | ||
| 2 | ============================================ | ||
| 3 | |||
| 4 | This binding describes a miphy device that is used to control PHY hardware | ||
| 5 | for SATA and PCIe. | ||
| 6 | |||
| 7 | Required properties (controller (parent) node): | ||
| 8 | - compatible : Should be "st,miphy365x-phy" | ||
| 9 | - st,syscfg : Should be a phandle of the system configuration register group | ||
| 10 | which contain the SATA, PCIe mode setting bits | ||
| 11 | |||
| 12 | Required nodes : A sub-node is required for each channel the controller | ||
| 13 | provides. Address range information including the usual | ||
| 14 | 'reg' and 'reg-names' properties are used inside these | ||
| 15 | nodes to describe the controller's topology. These nodes | ||
| 16 | are translated by the driver's .xlate() function. | ||
| 17 | |||
| 18 | Required properties (port (child) node): | ||
| 19 | - #phy-cells : Should be 1 (See second example) | ||
| 20 | Cell after port phandle is device type from: | ||
| 21 | - MIPHY_TYPE_SATA | ||
| 22 | - MIPHY_TYPE_PCI | ||
| 23 | - reg : Address and length of register sets for each device in | ||
| 24 | "reg-names" | ||
| 25 | - reg-names : The names of the register addresses corresponding to the | ||
| 26 | registers filled in "reg": | ||
| 27 | - sata: For SATA devices | ||
| 28 | - pcie: For PCIe devices | ||
| 29 | - syscfg: To specify the syscfg based config register | ||
| 30 | |||
| 31 | Optional properties (port (child) node): | ||
| 32 | - st,sata-gen : Generation of locally attached SATA IP. Expected values | ||
| 33 | are {1,2,3). If not supplied generation 1 hardware will | ||
| 34 | be expected | ||
| 35 | - st,pcie-tx-pol-inv : Bool property to invert the polarity PCIe Tx (Txn/Txp) | ||
| 36 | - st,sata-tx-pol-inv : Bool property to invert the polarity SATA Tx (Txn/Txp) | ||
| 37 | |||
| 38 | Example: | ||
| 39 | |||
| 40 | miphy365x_phy: miphy365x@fe382000 { | ||
| 41 | compatible = "st,miphy365x-phy"; | ||
| 42 | st,syscfg = <&syscfg_rear>; | ||
| 43 | #address-cells = <1>; | ||
| 44 | #size-cells = <1>; | ||
| 45 | ranges; | ||
| 46 | |||
| 47 | phy_port0: port@fe382000 { | ||
| 48 | reg = <0xfe382000 0x100>, <0xfe394000 0x100>, <0x824 0x4>; | ||
| 49 | reg-names = "sata", "pcie", "syscfg"; | ||
| 50 | #phy-cells = <1>; | ||
| 51 | st,sata-gen = <3>; | ||
| 52 | }; | ||
| 53 | |||
| 54 | phy_port1: port@fe38a000 { | ||
| 55 | reg = <0xfe38a000 0x100>, <0xfe804000 0x100>, <0x828 0x4>;; | ||
| 56 | reg-names = "sata", "pcie", "syscfg"; | ||
| 57 | #phy-cells = <1>; | ||
| 58 | st,pcie-tx-pol-inv; | ||
| 59 | }; | ||
| 60 | }; | ||
| 61 | |||
| 62 | Specifying phy control of devices | ||
| 63 | ================================= | ||
| 64 | |||
| 65 | Device nodes should specify the configuration required in their "phys" | ||
| 66 | property, containing a phandle to the phy port node and a device type. | ||
| 67 | |||
| 68 | Example: | ||
| 69 | |||
| 70 | #include <dt-bindings/phy/phy-miphy365x.h> | ||
| 71 | |||
| 72 | sata0: sata@fe380000 { | ||
| 73 | ... | ||
| 74 | phys = <&phy_port0 MIPHY_TYPE_SATA>; | ||
| 75 | ... | ||
| 76 | }; | ||
| @@ -0,0 +1,24 @@ | |||
| 1 | Qualcomm APQ8064 SATA PHY Controller | ||
| 2 | ------------------------------------ | ||
| 3 | |||
| 4 | SATA PHY nodes are defined to describe on-chip SATA Physical layer controllers. | ||
| 5 | Each SATA PHY controller should have its own node. | ||
| 6 | |||
| 7 | Required properties: | ||
| 8 | - compatible: compatible list, contains "qcom,apq8064-sata-phy". | ||
| 9 | - reg: offset and length of the SATA PHY register set; | ||
| 10 | - #phy-cells: must be zero | ||
| 11 | - clocks: a list of phandles and clock-specifier pairs, one for each entry in | ||
| 12 | clock-names. | ||
| 13 | - clock-names: must be "cfg" for phy config clock. | ||
| 14 | |||
| 15 | Example: | ||
| 16 | sata_phy: sata-phy@1b400000 { | ||
| 17 | compatible = "qcom,apq8064-sata-phy"; | ||
| 18 | reg = <0x1b400000 0x200>; | ||
| 19 | |||
| 20 | clocks = <&gcc SATA_PHY_CFG_CLK>; | ||
| 21 | clock-names = "cfg"; | ||
| 22 | |||
| 23 | #phy-cells = <0>; | ||
| 24 | }; | ||
| @@ -0,0 +1,23 @@ | |||
| 1 | Qualcomm IPQ806x SATA PHY Controller | ||
| 2 | ------------------------------------ | ||
| 3 | |||
| 4 | SATA PHY nodes are defined to describe on-chip SATA Physical layer controllers. | ||
| 5 | Each SATA PHY controller should have its own node. | ||
| 6 | |||
| 7 | Required properties: | ||
| 8 | - compatible: compatible list, contains "qcom,ipq806x-sata-phy" | ||
| 9 | - reg: offset and length of the SATA PHY register set; | ||
| 10 | - #phy-cells: must be zero | ||
| 11 | - clocks: must be exactly one entry | ||
| 12 | - clock-names: must be "cfg" | ||
| 13 | |||
| 14 | Example: | ||
| 15 | sata_phy: sata-phy@1b400000 { | ||
| 16 | compatible = "qcom,ipq806x-sata-phy"; | ||
| 17 | reg = <0x1b400000 0x200>; | ||
| 18 | |||
| 19 | clocks = <&gcc SATA_PHY_CFG_CLK>; | ||
| 20 | clock-names = "cfg"; | ||
| 21 | |||
| 22 | #phy-cells = <0>; | ||
| 23 | }; | ||
| @@ -26,6 +26,7 @@ Samsung S5P/EXYNOS SoC series USB PHY · 25 unmodified lines | |||
| 26 | 26 | ||
| 27 | Required properties: | 27 | Required properties: |
| 28 | - compatible : should be one of the listed compatibles: | 28 | - compatible : should be one of the listed compatibles: |
| 29 | - "samsung,exynos3250-usb2-phy" | ||
| 29 | - "samsung,exynos4210-usb2-phy" | 30 | - "samsung,exynos4210-usb2-phy" |
| 30 | - "samsung,exynos4x12-usb2-phy" | 31 | - "samsung,exynos4x12-usb2-phy" |
| 31 | - "samsung,exynos5250-usb2-phy" | 32 | - "samsung,exynos5250-usb2-phy" |
| @@ -46,6 +47,7 @@ and Exynos 4212) it is as follows: · 14 unmodified lines | |||
| 46 | 1 - USB host ("host"), | 47 | 1 - USB host ("host"), |
| 47 | 2 - HSIC0 ("hsic0"), | 48 | 2 - HSIC0 ("hsic0"), |
| 48 | 3 - HSIC1 ("hsic1"), | 49 | 3 - HSIC1 ("hsic1"), |
| 50 | Exynos3250 has only USB device phy available as phy 0. | ||
| 49 | 51 | ||
| 50 | Exynos 4210 and Exynos 4212 use mode switching and require that mode switch | 52 | Exynos 4210 and Exynos 4212 use mode switching and require that mode switch |
| 51 | register is supplied. | 53 | register is supplied. |
| @@ -9,15 +9,17 @@ Required properties: · 8 unmodified lines | |||
| 9 | e.g. USB2_PHY on OMAP5. | 9 | e.g. USB2_PHY on OMAP5. |
| 10 | "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power control | 10 | "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power control |
| 11 | e.g. USB3 PHY and SATA PHY on OMAP5. | 11 | e.g. USB3 PHY and SATA PHY on OMAP5. |
| 12 | "ti,control-phy-pcie" - for pcie to support external clock for pcie and to | ||
| 13 | set PCS delay value. | ||
| 14 | e.g. PCIE PHY in DRA7x | ||
| 12 | "ti,control-phy-usb2-dra7" - if it has power down register like USB2 PHY on | 15 | "ti,control-phy-usb2-dra7" - if it has power down register like USB2 PHY on |
| 13 | DRA7 platform. | 16 | DRA7 platform. |
| 14 | "ti,control-phy-usb2-am437" - if it has power down register like USB2 PHY on | 17 | "ti,control-phy-usb2-am437" - if it has power down register like USB2 PHY on |
| 15 | AM437 platform. | 18 | AM437 platform. |
| 16 | - reg : Address and length of the register set for the device. It contains | 19 | - reg : register ranges as listed in the reg-names property |
| 17 | the address of "otghs_control" for control-phy-otghs or "power" register | 20 | - reg-names: "otghs_control" for control-phy-otghs |
| 18 | for other types. | 21 | "power", "pcie_pcs" and "control_sma" for control-phy-pcie |
| 19 | - reg-names: should be "otghs_control" control-phy-otghs and "power" for | 22 | "power" for all other types |
| 20 | other types. | ||
| 21 | 23 | ||
| 22 | omap_control_usb: omap-control-usb@4a002300 { | 24 | omap_control_usb: omap-control-usb@4a002300 { |
| 23 | compatible = "ti,control-phy-otghs"; | 25 | compatible = "ti,control-phy-otghs"; |
| @@ -56,8 +58,8 @@ usb2phy@4a0ad080 { · 32 unmodified lines | |||
| 56 | TI PIPE3 PHY | 58 | TI PIPE3 PHY |
| 57 | 59 | ||
| 58 | Required properties: | 60 | Required properties: |
| 59 | - compatible: Should be "ti,phy-usb3" or "ti,phy-pipe3-sata". | 61 | - compatible: Should be "ti,phy-usb3", "ti,phy-pipe3-sata" or |
| 60 | "ti,omap-usb3" is deprecated. | 62 | "ti,phy-pipe3-pcie. "ti,omap-usb3" is deprecated. |
| 61 | - reg : Address and length of the register set for the device. | 63 | - reg : Address and length of the register set for the device. |
| 62 | - reg-names: The names of the register addresses corresponding to the registers | 64 | - reg-names: The names of the register addresses corresponding to the registers |
| 63 | filled in "reg". | 65 | filled in "reg". |
| @@ -69,10 +71,17 @@ Required properties: · 5 unmodified lines | |||
| 69 | * "wkupclk" - wakeup clock. | 71 | * "wkupclk" - wakeup clock. |
| 70 | * "sysclk" - system clock. | 72 | * "sysclk" - system clock. |
| 71 | * "refclk" - reference clock. | 73 | * "refclk" - reference clock. |
| 74 | * "dpll_ref" - external dpll ref clk | ||
| 75 | * "dpll_ref_m2" - external dpll ref clk | ||
| 76 | * "phy-div" - divider for apll | ||
| 77 | * "div-clk" - apll clock | ||
| 72 | 78 | ||
| 73 | Optional properties: | 79 | Optional properties: |
| 74 | - ctrl-module : phandle of the control module used by PHY driver to power on | 80 | - ctrl-module : phandle of the control module used by PHY driver to power on |
| 75 | the PHY. | 81 | the PHY. |
| 82 | - id: If there are multiple instance of the same type, in order to | ||
| 83 | differentiate between each instance "id" can be used (e.g., multi-lane PCIe | ||
| 84 | PHY). If "id" is not provided, it is set to default value of '1'. | ||
| 76 | 85 | ||
| 77 | This is usually a subnode of ocp2scp to which it is connected. | 86 | This is usually a subnode of ocp2scp to which it is connected. |
| 78 | 87 | ||
| @@ -4,6 +4,7 @@ Required properties: · 3 unmodified lines | |||
| 4 | - compatible: Should be "fsl,imx27-usb" | 4 | - compatible: Should be "fsl,imx27-usb" |
| 5 | - reg: Should contain registers location and length | 5 | - reg: Should contain registers location and length |
| 6 | - interrupts: Should contain controller interrupt | 6 | - interrupts: Should contain controller interrupt |
| 7 | - fsl,usbphy: phandle of usb phy that connects to the port | ||
| 7 | 8 | ||
| 8 | Recommended properies: | 9 | Recommended properies: |
| 9 | - phy_type: the type of the phy connected to the core. Should be one | 10 | - phy_type: the type of the phy connected to the core. Should be one |
| @@ -12,7 +13,6 @@ Recommended properies: · 2 unmodified lines | |||
| 12 | - dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg" | 13 | - dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg" |
| 13 | 14 | ||
| 14 | Optional properties: | 15 | Optional properties: |
| 15 | - fsl,usbphy: phandler of usb phy that connects to the only one port | ||
| 16 | - fsl,usbmisc: phandler of non-core register device, with one argument | 16 | - fsl,usbmisc: phandler of non-core register device, with one argument |
| 17 | that indicate usb controller index | 17 | that indicate usb controller index |
| 18 | - vbus-supply: regulator for vbus | 18 | - vbus-supply: regulator for vbus |
| @@ -20,6 +20,12 @@ Required properties : · 19 unmodified lines | |||
| 20 | Present if phy_type == utmi. | 20 | Present if phy_type == utmi. |
| 21 | - ulpi-link: The clock Tegra provides to the ULPI PHY (cdev2). | 21 | - ulpi-link: The clock Tegra provides to the ULPI PHY (cdev2). |
| 22 | Present if phy_type == ulpi, and ULPI link mode is in use. | 22 | Present if phy_type == ulpi, and ULPI link mode is in use. |
| 23 | - resets : Must contain an entry for each entry in reset-names. | ||
| 24 | See ../reset/reset.txt for details. | ||
| 25 | - reset-names : Must include the following entries: | ||
| 26 | - usb: The PHY's own reset signal. | ||
| 27 | - utmi-pads: The reset of the PHY containing the chip-wide UTMI pad control | ||
| 28 | registers. Required even if phy_type == ulpi. | ||
| 23 | 29 | ||
| 24 | Required properties for phy_type == ulpi: | 30 | Required properties for phy_type == ulpi: |
| 25 | - nvidia,phy-reset-gpio : The GPIO used to reset the PHY. | 31 | - nvidia,phy-reset-gpio : The GPIO used to reset the PHY. |
| @@ -56,6 +62,8 @@ Optional properties: · 30 unmodified lines | |||
| 56 | host means this is a host controller | 62 | host means this is a host controller |
| 57 | peripheral means it is device controller | 63 | peripheral means it is device controller |
| 58 | otg means it can operate as either ("on the go") | 64 | otg means it can operate as either ("on the go") |
| 65 | - nvidia,has-utmi-pad-registers : boolean indicates whether this controller | ||
| 66 | contains the UTMI pad control registers common to all USB controllers. | ||
| 59 | 67 | ||
| 60 | VBUS control (required for dr_mode == otg, optional for dr_mode == host): | 68 | VBUS control (required for dr_mode == otg, optional for dr_mode == host): |
| 61 | - vbus-supply: regulator for VBUS | 69 | - vbus-supply: regulator for VBUS |
| @@ -9,8 +9,9 @@ Required properties: · 8 unmodified lines | |||
| 9 | register set for the device. | 9 | register set for the device. |
| 10 | - interrupts: one XHCI interrupt should be described here. | 10 | - interrupts: one XHCI interrupt should be described here. |
| 11 | 11 | ||
| 12 | Optional property: | 12 | Optional properties: |
| 13 | - clocks: reference to a clock | 13 | - clocks: reference to a clock |
| 14 | - usb3-lpm-capable: determines if platform is USB3 LPM capable | ||
| 14 | 15 | ||
| 15 | Example: | 16 | Example: |
| 16 | usb@f0931000 { | 17 | usb@f0931000 { |
| @@ -53,10 +53,12 @@ unregister the PHY. · 52 unmodified lines | |||
| 53 | The PHY driver should create the PHY in order for other peripheral controllers | 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. | 54 | to make use of it. The PHY framework provides 2 APIs to create the PHY. |
| 55 | 55 | ||
| 56 | struct phy *phy_create(struct device *dev, const struct phy_ops *ops, | 56 | struct phy *phy_create(struct device *dev, struct device_node *node, |
| 57 | struct phy_init_data *init_data); | 57 | const struct phy_ops *ops, |
| 58 | struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops, | 58 | struct phy_init_data *init_data); |
| 59 | struct phy_init_data *init_data); | 59 | struct phy *devm_phy_create(struct device *dev, struct device_node *node, |
| 60 | const struct phy_ops *ops, | ||
| 61 | struct phy_init_data *init_data); | ||
| 60 | 62 | ||
| 61 | The PHY drivers can use one of the above 2 APIs to create the PHY by passing | 63 | 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. | 64 | the device pointer, phy ops and init_data. |
| @@ -105,13 +105,13 @@ macros such as these, and use driver_info to store more information. · 104 unmodified lines | |||
| 105 | A short example, for a driver that supports several specific USB devices | 105 | A short example, for a driver that supports several specific USB devices |
| 106 | and their quirks, might have a MODULE_DEVICE_TABLE like this: | 106 | and their quirks, might have a MODULE_DEVICE_TABLE like this: |
| 107 | 107 | ||
| 108 | static const struct usb_device_id mydriver_id_table = { | 108 | static const struct usb_device_id mydriver_id_table[] = { |
| 109 | { USB_DEVICE (0x9999, 0xaaaa), driver_info: QUIRK_X }, | 109 | { USB_DEVICE (0x9999, 0xaaaa), driver_info: QUIRK_X }, |
| 110 | { USB_DEVICE (0xbbbb, 0x8888), driver_info: QUIRK_Y|QUIRK_Z }, | 110 | { USB_DEVICE (0xbbbb, 0x8888), driver_info: QUIRK_Y|QUIRK_Z }, |
| 111 | ... | 111 | ... |
| 112 | { } /* end with an all-zeroes entry */ | 112 | { } /* end with an all-zeroes entry */ |
| 113 | } | 113 | }; |
| 114 | MODULE_DEVICE_TABLE (usb, mydriver_id_table); | 114 | MODULE_DEVICE_TABLE(usb, mydriver_id_table); |
| 115 | 115 | ||
| 116 | Most USB device drivers should pass these tables to the USB subsystem as | 116 | Most USB device drivers should pass these tables to the USB subsystem as |
| 117 | well as to the module management subsystem. Not all, though: some driver | 117 | well as to the module management subsystem. Not all, though: some driver |
| @@ -134,7 +134,7 @@ something like this: · 16 unmodified lines | |||
| 134 | if exposing any operations through usbdevfs: | 134 | if exposing any operations through usbdevfs: |
| 135 | .ioctl = my_ioctl, | 135 | .ioctl = my_ioctl, |
| 136 | */ | 136 | */ |
| 137 | } | 137 | }; |
| 138 | 138 | ||
| 139 | When the USB subsystem knows about a driver's device ID table, it's used when | 139 | When the USB subsystem knows about a driver's device ID table, it's used when |
| 140 | choosing drivers to probe(). The thread doing new device processing checks | 140 | choosing drivers to probe(). The thread doing new device processing checks |
| @@ -2,8 +2,27 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | Alan Stern <stern@rowland.harvard.edu> | 3 | Alan Stern <stern@rowland.harvard.edu> |
| 4 | 4 | ||
| 5 | October 28, 2010 | 5 | Last-updated: February 2014 |
| 6 | 6 | ||
| 7 | |||
| 8 | Contents: | ||
| 9 | --------- | ||
| 10 | * What is Power Management? | ||
| 11 | * What is Remote Wakeup? | ||
| 12 | * When is a USB device idle? | ||
| 13 | * Forms of dynamic PM | ||
| 14 | * The user interface for dynamic PM | ||
| 15 | * Changing the default idle-delay time | ||
| 16 | * Warnings | ||
| 17 | * The driver interface for Power Management | ||
| 18 | * The driver interface for autosuspend and autoresume | ||
| 19 | * Other parts of the driver interface | ||
| 20 | * Mutual exclusion | ||
| 21 | * Interaction between dynamic PM and system PM | ||
| 22 | * xHCI hardware link PM | ||
| 23 | * USB Port Power Control | ||
| 24 | * User Interface for Port Power Control | ||
| 25 | * Suggested Userspace Port Power Policy | ||
| 7 | 26 | ||
| 8 | 27 | ||
| 9 | What is Power Management? | 28 | What is Power Management? |
| @@ -516,3 +535,225 @@ relevant attribute files is usb2_hardware_lpm. · 506 unmodified lines | |||
| 516 | driver will enable hardware LPM for the device. You | 535 | driver will enable hardware LPM for the device. You |
| 517 | can write y/Y/1 or n/N/0 to the file to enable/disable | 536 | can write y/Y/1 or n/N/0 to the file to enable/disable |
| 518 | USB2 hardware LPM manually. This is for test purpose mainly. | 537 | USB2 hardware LPM manually. This is for test purpose mainly. |
| 538 | |||
| 539 | |||
| 540 | USB Port Power Control | ||
| 541 | ---------------------- | ||
| 542 | |||
| 543 | In addition to suspending endpoint devices and enabling hardware | ||
| 544 | controlled link power management, the USB subsystem also has the | ||
| 545 | capability to disable power to ports under some conditions. Power is | ||
| 546 | controlled through Set/ClearPortFeature(PORT_POWER) requests to a hub. | ||
| 547 | In the case of a root or platform-internal hub the host controller | ||
| 548 | driver translates PORT_POWER requests into platform firmware (ACPI) | ||
| 549 | method calls to set the port power state. For more background see the | ||
| 550 | Linux Plumbers Conference 2012 slides [1] and video [2]: | ||
| 551 | |||
| 552 | Upon receiving a ClearPortFeature(PORT_POWER) request a USB port is | ||
| 553 | logically off, and may trigger the actual loss of VBUS to the port [3]. | ||
| 554 | VBUS may be maintained in the case where a hub gangs multiple ports into | ||
| 555 | a shared power well causing power to remain until all ports in the gang | ||
| 556 | are turned off. VBUS may also be maintained by hub ports configured for | ||
| 557 | a charging application. In any event a logically off port will lose | ||
| 558 | connection with its device, not respond to hotplug events, and not | ||
| 559 | respond to remote wakeup events*. | ||
| 560 | |||
| 561 | WARNING: turning off a port may result in the inability to hot add a device. | ||
| 562 | Please see "User Interface for Port Power Control" for details. | ||
| 563 | |||
| 564 | As far as the effect on the device itself it is similar to what a device | ||
| 565 | goes through during system suspend, i.e. the power session is lost. Any | ||
| 566 | USB device or driver that misbehaves with system suspend will be | ||
| 567 | similarly affected by a port power cycle event. For this reason the | ||
| 568 | implementation shares the same device recovery path (and honors the same | ||
| 569 | quirks) as the system resume path for the hub. | ||
| 570 | |||
| 571 | [1]: http://dl.dropbox.com/u/96820575/sarah-sharp-lpt-port-power-off2-mini.pdf | ||
| 572 | [2]: http://linuxplumbers.ubicast.tv/videos/usb-port-power-off-kerneluserspace-api/ | ||
| 573 | [3]: USB 3.1 Section 10.12 | ||
| 574 | * wakeup note: if a device is configured to send wakeup events the port | ||
| 575 | power control implementation will block poweroff attempts on that | ||
| 576 | port. | ||
| 577 | |||
| 578 | |||
| 579 | User Interface for Port Power Control | ||
| 580 | ------------------------------------- | ||
| 581 | |||
| 582 | The port power control mechanism uses the PM runtime system. Poweroff is | ||
| 583 | requested by clearing the power/pm_qos_no_power_off flag of the port device | ||
| 584 | (defaults to 1). If the port is disconnected it will immediately receive a | ||
| 585 | ClearPortFeature(PORT_POWER) request. Otherwise, it will honor the pm runtime | ||
| 586 | rules and require the attached child device and all descendants to be suspended. | ||
| 587 | This mechanism is dependent on the hub advertising port power switching in its | ||
| 588 | hub descriptor (wHubCharacteristics logical power switching mode field). | ||
| 589 | |||
| 590 | Note, some interface devices/drivers do not support autosuspend. Userspace may | ||
| 591 | need to unbind the interface drivers before the usb_device will suspend. An | ||
| 592 | unbound interface device is suspended by default. When unbinding, be careful | ||
| 593 | to unbind interface drivers, not the driver of the parent usb device. Also, | ||
| 594 | leave hub interface drivers bound. If the driver for the usb device (not | ||
| 595 | interface) is unbound the kernel is no longer able to resume the device. If a | ||
| 596 | hub interface driver is unbound, control of its child ports is lost and all | ||
| 597 | attached child-devices will disconnect. A good rule of thumb is that if the | ||
| 598 | 'driver/module' link for a device points to /sys/module/usbcore then unbinding | ||
| 599 | it will interfere with port power control. | ||
| 600 | |||
| 601 | Example of the relevant files for port power control. Note, in this example | ||
| 602 | these files are relative to a usb hub device (prefix). | ||
| 603 | |||
| 604 | prefix=/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1 | ||
| 605 | |||
| 606 | attached child device + | ||
| 607 | hub port device + | | ||
| 608 | hub interface device + | | | ||
| 609 | v v v | ||
| 610 | $prefix/3-1:1.0/3-1-port1/device | ||
| 611 | |||
| 612 | $prefix/3-1:1.0/3-1-port1/power/pm_qos_no_power_off | ||
| 613 | $prefix/3-1:1.0/3-1-port1/device/power/control | ||
| 614 | $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf0>/driver/unbind | ||
| 615 | $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf1>/driver/unbind | ||
| 616 | ... | ||
| 617 | $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intfN>/driver/unbind | ||
| 618 | |||
| 619 | In addition to these files some ports may have a 'peer' link to a port on | ||
| 620 | another hub. The expectation is that all superspeed ports have a | ||
| 621 | hi-speed peer. | ||
| 622 | |||
| 623 | $prefix/3-1:1.0/3-1-port1/peer -> ../../../../usb2/2-1/2-1:1.0/2-1-port1 | ||
| 624 | ../../../../usb2/2-1/2-1:1.0/2-1-port1/peer -> ../../../../usb3/3-1/3-1:1.0/3-1-port1 | ||
| 625 | |||
| 626 | Distinct from 'companion ports', or 'ehci/xhci shared switchover ports' | ||
| 627 | peer ports are simply the hi-speed and superspeed interface pins that | ||
| 628 | are combined into a single usb3 connector. Peer ports share the same | ||
| 629 | ancestor XHCI device. | ||
| 630 | |||
| 631 | While a superspeed port is powered off a device may downgrade its | ||
| 632 | connection and attempt to connect to the hi-speed pins. The | ||
| 633 | implementation takes steps to prevent this: | ||
| 634 | |||
| 635 | 1/ Port suspend is sequenced to guarantee that hi-speed ports are powered-off | ||
| 636 | before their superspeed peer is permitted to power-off. The implication is | ||
| 637 | that the setting pm_qos_no_power_off to zero on a superspeed port may not cause | ||
| 638 | the port to power-off until its highspeed peer has gone to its runtime suspend | ||
| 639 | state. Userspace must take care to order the suspensions if it wants to | ||
| 640 | guarantee that a superspeed port will power-off. | ||
| 641 | |||
| 642 | 2/ Port resume is sequenced to force a superspeed port to power-on prior to its | ||
| 643 | highspeed peer. | ||
| 644 | |||
| 645 | 3/ Port resume always triggers an attached child device to resume. After a | ||
| 646 | power session is lost the device may have been removed, or need reset. | ||
| 647 | Resuming the child device when the parent port regains power resolves those | ||
| 648 | states and clamps the maximum port power cycle frequency at the rate the child | ||
| 649 | device can suspend (autosuspend-delay) and resume (reset-resume latency). | ||
| 650 | |||
| 651 | Sysfs files relevant for port power control: | ||
| 652 | <hubdev-portX>/power/pm_qos_no_power_off: | ||
| 653 | This writable flag controls the state of an idle port. | ||
| 654 | Once all children and descendants have suspended the | ||
| 655 | port may suspend/poweroff provided that | ||
| 656 | pm_qos_no_power_off is '0'. If pm_qos_no_power_off is | ||
| 657 | '1' the port will remain active/powered regardless of | ||
| 658 | the stats of descendants. Defaults to 1. | ||
| 659 | |||
| 660 | <hubdev-portX>/power/runtime_status: | ||
| 661 | This file reflects whether the port is 'active' (power is on) | ||
| 662 | or 'suspended' (logically off). There is no indication to | ||
| 663 | userspace whether VBUS is still supplied. | ||
| 664 | |||
| 665 | <hubdev-portX>/connect_type: | ||
| 666 | An advisory read-only flag to userspace indicating the | ||
| 667 | location and connection type of the port. It returns | ||
| 668 | one of four values 'hotplug', 'hardwired', 'not used', | ||
| 669 | and 'unknown'. All values, besides unknown, are set by | ||
| 670 | platform firmware. | ||
| 671 | |||
| 672 | "hotplug" indicates an externally connectable/visible | ||
| 673 | port on the platform. Typically userspace would choose | ||
| 674 | to keep such a port powered to handle new device | ||
| 675 | connection events. | ||
| 676 | |||
| 677 | "hardwired" refers to a port that is not visible but | ||
| 678 | connectable. Examples are internal ports for USB | ||
| 679 | bluetooth that can be disconnected via an external | ||
| 680 | switch or a port with a hardwired USB camera. It is | ||
| 681 | expected to be safe to allow these ports to suspend | ||
| 682 | provided pm_qos_no_power_off is coordinated with any | ||
| 683 | switch that gates connections. Userspace must arrange | ||
| 684 | for the device to be connected prior to the port | ||
| 685 | powering off, or to activate the port prior to enabling | ||
| 686 | connection via a switch. | ||
| 687 | |||
| 688 | "not used" refers to an internal port that is expected | ||
| 689 | to never have a device connected to it. These may be | ||
| 690 | empty internal ports, or ports that are not physically | ||
| 691 | exposed on a platform. Considered safe to be | ||
| 692 | powered-off at all times. | ||
| 693 | |||
| 694 | "unknown" means platform firmware does not provide | ||
| 695 | information for this port. Most commonly refers to | ||
| 696 | external hub ports which should be considered 'hotplug' | ||
| 697 | for policy decisions. | ||
| 698 | |||
| 699 | NOTE1: since we are relying on the BIOS to get this ACPI | ||
| 700 | information correct, the USB port descriptions may be | ||
| 701 | missing or wrong. | ||
| 702 | |||
| 703 | NOTE2: Take care in clearing pm_qos_no_power_off. Once | ||
| 704 | power is off this port will | ||
| 705 | not respond to new connect events. | ||
| 706 | |||
| 707 | Once a child device is attached additional constraints are | ||
| 708 | applied before the port is allowed to poweroff. | ||
| 709 | |||
| 710 | <child>/power/control: | ||
| 711 | Must be 'auto', and the port will not | ||
| 712 | power down until <child>/power/runtime_status | ||
| 713 | reflects the 'suspended' state. Default | ||
| 714 | value is controlled by child device driver. | ||
| 715 | |||
| 716 | <child>/power/persist: | ||
| 717 | This defaults to '1' for most devices and indicates if | ||
| 718 | kernel can persist the device's configuration across a | ||
| 719 | power session loss (suspend / port-power event). When | ||
| 720 | this value is '0' (quirky devices), port poweroff is | ||
| 721 | disabled. | ||
| 722 | |||
| 723 | <child>/driver/unbind: | ||
| 724 | Wakeup capable devices will block port poweroff. At | ||
| 725 | this time the only mechanism to clear the usb-internal | ||
| 726 | wakeup-capability for an interface device is to unbind | ||
| 727 | its driver. | ||
| 728 | |||
| 729 | Summary of poweroff pre-requisite settings relative to a port device: | ||
| 730 | |||
| 731 | echo 0 > power/pm_qos_no_power_off | ||
| 732 | echo 0 > peer/power/pm_qos_no_power_off # if it exists | ||
| 733 | echo auto > power/control # this is the default value | ||
| 734 | echo auto > <child>/power/control | ||
| 735 | echo 1 > <child>/power/persist # this is the default value | ||
| 736 | |||
| 737 | Suggested Userspace Port Power Policy | ||
| 738 | ------------------------------------- | ||
| 739 | |||
| 740 | As noted above userspace needs to be careful and deliberate about what | ||
| 741 | ports are enabled for poweroff. | ||
| 742 | |||
| 743 | The default configuration is that all ports start with | ||
| 744 | power/pm_qos_no_power_off set to '1' causing ports to always remain | ||
| 745 | active. | ||
| 746 | |||
| 747 | Given confidence in the platform firmware's description of the ports | ||
| 748 | (ACPI _PLD record for a port populates 'connect_type') userspace can | ||
| 749 | clear pm_qos_no_power_off for all 'not used' ports. The same can be | ||
| 750 | done for 'hardwired' ports provided poweroff is coordinated with any | ||
| 751 | connection switch for the port. | ||
| 752 | |||
| 753 | A more aggressive userspace policy is to enable USB port power off for | ||
| 754 | all ports (set <hubdev-portX>/power/pm_qos_no_power_off to '0') when | ||
| 755 | some external factor indicates the user has stopped interacting with the | ||
| 756 | system. For example, a distro may want to enable power off all USB | ||
| 757 | ports when the screen blanks, and re-power them when the screen becomes | ||
| 758 | active. Smart phones and tablets may want to power off USB ports when | ||
| 759 | the user pushes the power button. | ||
| @@ -657,6 +657,8 @@ · 656 unmodified lines | |||
| 657 | <&tegra_car TEGRA114_CLK_PLL_U>, | 657 | <&tegra_car TEGRA114_CLK_PLL_U>, |
| 658 | <&tegra_car TEGRA114_CLK_USBD>; | 658 | <&tegra_car TEGRA114_CLK_USBD>; |
| 659 | clock-names = "reg", "pll_u", "utmi-pads"; | 659 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 660 | resets = <&tegra_car 22>, <&tegra_car 22>; | ||
| 661 | reset-names = "usb", "utmi-pads"; | ||
| 660 | nvidia,hssync-start-delay = <0>; | 662 | nvidia,hssync-start-delay = <0>; |
| 661 | nvidia,idle-wait-delay = <17>; | 663 | nvidia,idle-wait-delay = <17>; |
| 662 | nvidia,elastic-limit = <16>; | 664 | nvidia,elastic-limit = <16>; |
| @@ -667,6 +669,7 @@ · 4 unmodified lines | |||
| 667 | nvidia,hssquelch-level = <2>; | 669 | nvidia,hssquelch-level = <2>; |
| 668 | nvidia,hsdiscon-level = <5>; | 670 | nvidia,hsdiscon-level = <5>; |
| 669 | nvidia,xcvr-hsslew = <12>; | 671 | nvidia,xcvr-hsslew = <12>; |
| 672 | nvidia,has-utmi-pad-registers; | ||
| 670 | status = "disabled"; | 673 | status = "disabled"; |
| 671 | }; | 674 | }; |
| 672 | 675 | ||
| @@ -690,6 +693,8 @@ · 17 unmodified lines | |||
| 690 | <&tegra_car TEGRA114_CLK_PLL_U>, | 693 | <&tegra_car TEGRA114_CLK_PLL_U>, |
| 691 | <&tegra_car TEGRA114_CLK_USBD>; | 694 | <&tegra_car TEGRA114_CLK_USBD>; |
| 692 | clock-names = "reg", "pll_u", "utmi-pads"; | 695 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 696 | resets = <&tegra_car 59>, <&tegra_car 22>; | ||
| 697 | reset-names = "usb", "utmi-pads"; | ||
| 693 | nvidia,hssync-start-delay = <0>; | 698 | nvidia,hssync-start-delay = <0>; |
| 694 | nvidia,idle-wait-delay = <17>; | 699 | nvidia,idle-wait-delay = <17>; |
| 695 | nvidia,elastic-limit = <16>; | 700 | nvidia,elastic-limit = <16>; |
| @@ -613,6 +613,8 @@ · 612 unmodified lines | |||
| 613 | <&tegra_car TEGRA124_CLK_PLL_U>, | 613 | <&tegra_car TEGRA124_CLK_PLL_U>, |
| 614 | <&tegra_car TEGRA124_CLK_USBD>; | 614 | <&tegra_car TEGRA124_CLK_USBD>; |
| 615 | clock-names = "reg", "pll_u", "utmi-pads"; | 615 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 616 | resets = <&tegra_car 59>, <&tegra_car 22>; | ||
| 617 | reset-names = "usb", "utmi-pads"; | ||
| 616 | nvidia,hssync-start-delay = <0>; | 618 | nvidia,hssync-start-delay = <0>; |
| 617 | nvidia,idle-wait-delay = <17>; | 619 | nvidia,idle-wait-delay = <17>; |
| 618 | nvidia,elastic-limit = <16>; | 620 | nvidia,elastic-limit = <16>; |
| @@ -647,6 +649,8 @@ · 28 unmodified lines | |||
| 647 | <&tegra_car TEGRA124_CLK_PLL_U>, | 649 | <&tegra_car TEGRA124_CLK_PLL_U>, |
| 648 | <&tegra_car TEGRA124_CLK_USBD>; | 650 | <&tegra_car TEGRA124_CLK_USBD>; |
| 649 | clock-names = "reg", "pll_u", "utmi-pads"; | 651 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 652 | resets = <&tegra_car 22>, <&tegra_car 22>; | ||
| 653 | reset-names = "usb", "utmi-pads"; | ||
| 650 | nvidia,hssync-start-delay = <0>; | 654 | nvidia,hssync-start-delay = <0>; |
| 651 | nvidia,idle-wait-delay = <17>; | 655 | nvidia,idle-wait-delay = <17>; |
| 652 | nvidia,elastic-limit = <16>; | 656 | nvidia,elastic-limit = <16>; |
| @@ -657,6 +661,7 @@ · 4 unmodified lines | |||
| 657 | nvidia,hssquelch-level = <2>; | 661 | nvidia,hssquelch-level = <2>; |
| 658 | nvidia,hsdiscon-level = <5>; | 662 | nvidia,hsdiscon-level = <5>; |
| 659 | nvidia,xcvr-hsslew = <12>; | 663 | nvidia,xcvr-hsslew = <12>; |
| 664 | nvidia,has-utmi-pad-registers; | ||
| 660 | status = "disabled"; | 665 | status = "disabled"; |
| 661 | }; | 666 | }; |
| 662 | 667 | ||
| @@ -681,6 +686,8 @@ · 18 unmodified lines | |||
| 681 | <&tegra_car TEGRA124_CLK_PLL_U>, | 686 | <&tegra_car TEGRA124_CLK_PLL_U>, |
| 682 | <&tegra_car TEGRA124_CLK_USBD>; | 687 | <&tegra_car TEGRA124_CLK_USBD>; |
| 683 | clock-names = "reg", "pll_u", "utmi-pads"; | 688 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 689 | resets = <&tegra_car 58>, <&tegra_car 22>; | ||
| 690 | reset-names = "usb", "utmi-pads"; | ||
| 684 | nvidia,hssync-start-delay = <0>; | 691 | nvidia,hssync-start-delay = <0>; |
| 685 | nvidia,idle-wait-delay = <17>; | 692 | nvidia,idle-wait-delay = <17>; |
| 686 | nvidia,elastic-limit = <16>; | 693 | nvidia,elastic-limit = <16>; |
| @@ -630,6 +630,8 @@ · 629 unmodified lines | |||
| 630 | <&tegra_car TEGRA20_CLK_CLK_M>, | 630 | <&tegra_car TEGRA20_CLK_CLK_M>, |
| 631 | <&tegra_car TEGRA20_CLK_USBD>; | 631 | <&tegra_car TEGRA20_CLK_USBD>; |
| 632 | clock-names = "reg", "pll_u", "timer", "utmi-pads"; | 632 | clock-names = "reg", "pll_u", "timer", "utmi-pads"; |
| 633 | resets = <&tegra_car 22>, <&tegra_car 22>; | ||
| 634 | reset-names = "usb", "utmi-pads"; | ||
| 633 | nvidia,has-legacy-mode; | 635 | nvidia,has-legacy-mode; |
| 634 | nvidia,hssync-start-delay = <9>; | 636 | nvidia,hssync-start-delay = <9>; |
| 635 | nvidia,idle-wait-delay = <17>; | 637 | nvidia,idle-wait-delay = <17>; |
| @@ -638,6 +640,7 @@ · 2 unmodified lines | |||
| 638 | nvidia,xcvr-setup = <9>; | 640 | nvidia,xcvr-setup = <9>; |
| 639 | nvidia,xcvr-lsfslew = <1>; | 641 | nvidia,xcvr-lsfslew = <1>; |
| 640 | nvidia,xcvr-lsrslew = <1>; | 642 | nvidia,xcvr-lsrslew = <1>; |
| 643 | nvidia,has-utmi-pad-registers; | ||
| 641 | status = "disabled"; | 644 | status = "disabled"; |
| 642 | }; | 645 | }; |
| 643 | 646 | ||
| @@ -661,6 +664,8 @@ · 17 unmodified lines | |||
| 661 | <&tegra_car TEGRA20_CLK_PLL_U>, | 664 | <&tegra_car TEGRA20_CLK_PLL_U>, |
| 662 | <&tegra_car TEGRA20_CLK_CDEV2>; | 665 | <&tegra_car TEGRA20_CLK_CDEV2>; |
| 663 | clock-names = "reg", "pll_u", "ulpi-link"; | 666 | clock-names = "reg", "pll_u", "ulpi-link"; |
| 667 | resets = <&tegra_car 58>, <&tegra_car 22>; | ||
| 668 | reset-names = "usb", "utmi-pads"; | ||
| 664 | status = "disabled"; | 669 | status = "disabled"; |
| 665 | }; | 670 | }; |
| 666 | 671 | ||
| @@ -685,6 +690,8 @@ · 18 unmodified lines | |||
| 685 | <&tegra_car TEGRA20_CLK_CLK_M>, | 690 | <&tegra_car TEGRA20_CLK_CLK_M>, |
| 686 | <&tegra_car TEGRA20_CLK_USBD>; | 691 | <&tegra_car TEGRA20_CLK_USBD>; |
| 687 | clock-names = "reg", "pll_u", "timer", "utmi-pads"; | 692 | clock-names = "reg", "pll_u", "timer", "utmi-pads"; |
| 693 | resets = <&tegra_car 59>, <&tegra_car 22>; | ||
| 694 | reset-names = "usb", "utmi-pads"; | ||
| 688 | nvidia,hssync-start-delay = <9>; | 695 | nvidia,hssync-start-delay = <9>; |
| 689 | nvidia,idle-wait-delay = <17>; | 696 | nvidia,idle-wait-delay = <17>; |
| 690 | nvidia,elastic-limit = <16>; | 697 | nvidia,elastic-limit = <16>; |
| @@ -775,6 +775,8 @@ · 774 unmodified lines | |||
| 775 | <&tegra_car TEGRA30_CLK_PLL_U>, | 775 | <&tegra_car TEGRA30_CLK_PLL_U>, |
| 776 | <&tegra_car TEGRA30_CLK_USBD>; | 776 | <&tegra_car TEGRA30_CLK_USBD>; |
| 777 | clock-names = "reg", "pll_u", "utmi-pads"; | 777 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 778 | resets = <&tegra_car 22>, <&tegra_car 22>; | ||
| 779 | reset-names = "usb", "utmi-pads"; | ||
| 778 | nvidia,hssync-start-delay = <9>; | 780 | nvidia,hssync-start-delay = <9>; |
| 779 | nvidia,idle-wait-delay = <17>; | 781 | nvidia,idle-wait-delay = <17>; |
| 780 | nvidia,elastic-limit = <16>; | 782 | nvidia,elastic-limit = <16>; |
| @@ -786,6 +788,7 @@ · 5 unmodified lines | |||
| 786 | nvidia,xcvr-hsslew = <32>; | 788 | nvidia,xcvr-hsslew = <32>; |
| 787 | nvidia,hssquelch-level = <2>; | 789 | nvidia,hssquelch-level = <2>; |
| 788 | nvidia,hsdiscon-level = <5>; | 790 | nvidia,hsdiscon-level = <5>; |
| 791 | nvidia,has-utmi-pad-registers; | ||
| 789 | status = "disabled"; | 792 | status = "disabled"; |
| 790 | }; | 793 | }; |
| 791 | 794 | ||
| @@ -809,6 +812,8 @@ · 17 unmodified lines | |||
| 809 | <&tegra_car TEGRA30_CLK_PLL_U>, | 812 | <&tegra_car TEGRA30_CLK_PLL_U>, |
| 810 | <&tegra_car TEGRA30_CLK_USBD>; | 813 | <&tegra_car TEGRA30_CLK_USBD>; |
| 811 | clock-names = "reg", "pll_u", "utmi-pads"; | 814 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 815 | resets = <&tegra_car 58>, <&tegra_car 22>; | ||
| 816 | reset-names = "usb", "utmi-pads"; | ||
| 812 | nvidia,hssync-start-delay = <9>; | 817 | nvidia,hssync-start-delay = <9>; |
| 813 | nvidia,idle-wait-delay = <17>; | 818 | nvidia,idle-wait-delay = <17>; |
| 814 | nvidia,elastic-limit = <16>; | 819 | nvidia,elastic-limit = <16>; |
| @@ -843,6 +848,8 @@ · 28 unmodified lines | |||
| 843 | <&tegra_car TEGRA30_CLK_PLL_U>, | 848 | <&tegra_car TEGRA30_CLK_PLL_U>, |
| 844 | <&tegra_car TEGRA30_CLK_USBD>; | 849 | <&tegra_car TEGRA30_CLK_USBD>; |
| 845 | clock-names = "reg", "pll_u", "utmi-pads"; | 850 | clock-names = "reg", "pll_u", "utmi-pads"; |
| 851 | resets = <&tegra_car 59>, <&tegra_car 22>; | ||
| 852 | reset-names = "usb", "utmi-pads"; | ||
| 846 | nvidia,hssync-start-delay = <0>; | 853 | nvidia,hssync-start-delay = <0>; |
| 847 | nvidia,idle-wait-delay = <17>; | 854 | nvidia,idle-wait-delay = <17>; |
| 848 | nvidia,elastic-limit = <16>; | 855 | nvidia,elastic-limit = <16>; |
| @@ -15,6 +15,13 @@ config GENERIC_PHY · 14 unmodified lines | |||
| 15 | phy users can obtain reference to the PHY. All the users of this | 15 | phy users can obtain reference to the PHY. All the users of this |
| 16 | framework should select this config. | 16 | framework should select this config. |
| 17 | 17 | ||
| 18 | config PHY_BERLIN_SATA | ||
| 19 | tristate "Marvell Berlin SATA PHY driver" | ||
| 20 | depends on ARCH_BERLIN && HAS_IOMEM && OF | ||
| 21 | select GENERIC_PHY | ||
| 22 | help | ||
| 23 | Enable this to support the SATA PHY on Marvell Berlin SoCs. | ||
| 24 | |||
| 18 | config PHY_EXYNOS_MIPI_VIDEO | 25 | config PHY_EXYNOS_MIPI_VIDEO |
| 19 | tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver" | 26 | tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver" |
| 20 | depends on HAS_IOMEM | 27 | depends on HAS_IOMEM |
| @@ -27,10 +34,20 @@ config PHY_EXYNOS_MIPI_VIDEO · 6 unmodified lines | |||
| 27 | 34 | ||
| 28 | config PHY_MVEBU_SATA | 35 | config PHY_MVEBU_SATA |
| 29 | def_bool y | 36 | def_bool y |
| 30 | depends on ARCH_KIRKWOOD || ARCH_DOVE || MACH_DOVE || MACH_KIRKWOOD | 37 | depends on ARCH_DOVE || MACH_DOVE || MACH_KIRKWOOD |
| 31 | depends on OF | 38 | depends on OF |
| 32 | select GENERIC_PHY | 39 | select GENERIC_PHY |
| 33 | 40 | ||
| 41 | config PHY_MIPHY365X | ||
| 42 | tristate "STMicroelectronics MIPHY365X PHY driver for STiH41x series" | ||
| 43 | depends on ARCH_STI | ||
| 44 | depends on GENERIC_PHY | ||
| 45 | depends on HAS_IOMEM | ||
| 46 | depends on OF | ||
| 47 | help | ||
| 48 | Enable this to support the miphy transceiver (for SATA/PCIE) | ||
| 49 | that is part of STMicroelectronics STiH41x SoC series. | ||
| 50 | |||
| 34 | config OMAP_CONTROL_PHY | 51 | config OMAP_CONTROL_PHY |
| 35 | tristate "OMAP CONTROL PHY Driver" | 52 | tristate "OMAP CONTROL PHY Driver" |
| 36 | depends on ARCH_OMAP2PLUS || COMPILE_TEST | 53 | depends on ARCH_OMAP2PLUS || COMPILE_TEST |
| @@ -109,6 +126,14 @@ config PHY_EXYNOS5250_SATA · 72 unmodified lines | |||
| 109 | SATA 3.0 Gb/s, SATA 6.0 Gb/s speeds. It supports one SATA host | 126 | SATA 3.0 Gb/s, SATA 6.0 Gb/s speeds. It supports one SATA host |
| 110 | port to accept one SATA device. | 127 | port to accept one SATA device. |
| 111 | 128 | ||
| 129 | config PHY_HIX5HD2_SATA | ||
| 130 | tristate "HIX5HD2 SATA PHY Driver" | ||
| 131 | depends on ARCH_HIX5HD2 && OF && HAS_IOMEM | ||
| 132 | select GENERIC_PHY | ||
| 133 | select MFD_SYSCON | ||
| 134 | help | ||
| 135 | Support for SATA PHY on Hisilicon hix5hd2 Soc. | ||
| 136 | |||
| 112 | config PHY_SUN4I_USB | 137 | config PHY_SUN4I_USB |
| 113 | tristate "Allwinner sunxi SoC USB PHY driver" | 138 | tristate "Allwinner sunxi SoC USB PHY driver" |
| 114 | depends on ARCH_SUNXI && HAS_IOMEM && OF | 139 | depends on ARCH_SUNXI && HAS_IOMEM && OF |
| @@ -124,50 +149,39 @@ config PHY_SUN4I_USB · 9 unmodified lines | |||
| 124 | config PHY_SAMSUNG_USB2 | 149 | config PHY_SAMSUNG_USB2 |
| 125 | tristate "Samsung USB 2.0 PHY driver" | 150 | tristate "Samsung USB 2.0 PHY driver" |
| 126 | depends on HAS_IOMEM | 151 | depends on HAS_IOMEM |
| 152 | depends on USB_EHCI_EXYNOS || USB_OHCI_EXYNOS || USB_DWC2 | ||
| 127 | select GENERIC_PHY | 153 | select GENERIC_PHY |
| 128 | select MFD_SYSCON | 154 | select MFD_SYSCON |
| 155 | default ARCH_EXYNOS | ||
| 129 | help | 156 | help |
| 130 | Enable this to support the Samsung USB 2.0 PHY driver for Samsung | 157 | Enable this to support the Samsung USB 2.0 PHY driver for Samsung |
| 131 | SoCs. This driver provides the interface for USB 2.0 PHY. Support for | 158 | SoCs. This driver provides the interface for USB 2.0 PHY. Support |
| 132 | particular SoCs has to be enabled in addition to this driver. Number | 159 | for particular PHYs will be enabled based on the SoC type in addition |
| 133 | and type of supported phys depends on the SoC. | 160 | to this driver. |
| 134 | 161 | ||
| 135 | config PHY_EXYNOS4210_USB2 | 162 | config PHY_EXYNOS4210_USB2 |
| 136 | bool "Support for Exynos 4210" | 163 | bool |
| 137 | depends on PHY_SAMSUNG_USB2 | 164 | depends on PHY_SAMSUNG_USB2 |
| 138 | depends on CPU_EXYNOS4210 | 165 | default CPU_EXYNOS4210 |
| 139 | help | ||
| 140 | Enable USB PHY support for Exynos 4210. This option requires that | ||
| 141 | Samsung USB 2.0 PHY driver is enabled and means that support for this | ||
| 142 | particular SoC is compiled in the driver. In case of Exynos 4210 four | ||
| 143 | phys are available - device, host, HSIC0 and HSIC1. | ||
| 144 | 166 | ||
| 145 | config PHY_EXYNOS4X12_USB2 | 167 | config PHY_EXYNOS4X12_USB2 |
| 146 | bool "Support for Exynos 4x12" | 168 | bool |
| 147 | depends on PHY_SAMSUNG_USB2 | 169 | depends on PHY_SAMSUNG_USB2 |
| 148 | depends on (SOC_EXYNOS4212 || SOC_EXYNOS4412) | 170 | default SOC_EXYNOS3250 || SOC_EXYNOS4212 || SOC_EXYNOS4412 |
| 149 | help | ||
| 150 | Enable USB PHY support for Exynos 4x12. This option requires that | ||
| 151 | Samsung USB 2.0 PHY driver is enabled and means that support for this | ||
| 152 | particular SoC is compiled in the driver. In case of Exynos 4x12 four | ||
| 153 | phys are available - device, host, HSIC0 and HSIC1. | ||
| 154 | 171 | ||
| 155 | config PHY_EXYNOS5250_USB2 | 172 | config PHY_EXYNOS5250_USB2 |
| 156 | bool "Support for Exynos 5250" | 173 | bool |
| 157 | depends on PHY_SAMSUNG_USB2 | 174 | depends on PHY_SAMSUNG_USB2 |
| 158 | depends on SOC_EXYNOS5250 | 175 | default SOC_EXYNOS5250 || SOC_EXYNOS5420 |
| 159 | help | ||
| 160 | Enable USB PHY support for Exynos 5250. This option requires that | ||
| 161 | Samsung USB 2.0 PHY driver is enabled and means that support for this | ||
| 162 | particular SoC is compiled in the driver. In case of Exynos 5250 four | ||
| 163 | phys are available - device, host, HSIC0 and HSIC. | ||
| 164 | 176 | ||
| 165 | config PHY_EXYNOS5_USBDRD | 177 | config PHY_EXYNOS5_USBDRD |
| 166 | tristate "Exynos5 SoC series USB DRD PHY driver" | 178 | tristate "Exynos5 SoC series USB DRD PHY driver" |
| 167 | depends on ARCH_EXYNOS5 && OF | 179 | depends on ARCH_EXYNOS5 && OF |
| 168 | depends on HAS_IOMEM | 180 | depends on HAS_IOMEM |
| 181 | depends on USB_DWC3_EXYNOS | ||
| 169 | select GENERIC_PHY | 182 | select GENERIC_PHY |
| 170 | select MFD_SYSCON | 183 | select MFD_SYSCON |
| 184 | default y | ||
| 171 | help | 185 | help |
| 172 | Enable USB DRD PHY support for Exynos 5 SoC series. | 186 | Enable USB DRD PHY support for Exynos 5 SoC series. |
| 173 | This driver provides PHY interface for USB 3.0 DRD controller | 187 | This driver provides PHY interface for USB 3.0 DRD controller |
| @@ -180,4 +194,18 @@ config PHY_XGENE · 6 unmodified lines | |||
| 180 | help | 194 | help |
| 181 | This option enables support for APM X-Gene SoC multi-purpose PHY. | 195 | This option enables support for APM X-Gene SoC multi-purpose PHY. |
| 182 | 196 | ||
| 197 | config PHY_QCOM_APQ8064_SATA | ||
| 198 | tristate "Qualcomm APQ8064 SATA SerDes/PHY driver" | ||
| 199 | depends on ARCH_QCOM | ||
| 200 | depends on HAS_IOMEM | ||
| 201 | depends on OF | ||
| 202 | select GENERIC_PHY | ||
| 203 | |||
| 204 | config PHY_QCOM_IPQ806X_SATA | ||
| 205 | tristate "Qualcomm IPQ806x SATA SerDes/PHY driver" | ||
| 206 | depends on ARCH_QCOM | ||
| 207 | depends on HAS_IOMEM | ||
| 208 | depends on OF | ||
| 209 | select GENERIC_PHY | ||
| 210 | |||
| 183 | endmenu | 211 | endmenu |
| @@ -3,15 +3,18 @@ · 2 unmodified lines | |||
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | obj-$(CONFIG_GENERIC_PHY) += phy-core.o | 5 | obj-$(CONFIG_GENERIC_PHY) += phy-core.o |
| 6 | obj-$(CONFIG_PHY_BERLIN_SATA) += phy-berlin-sata.o | ||
| 6 | obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o | 7 | obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o |
| 7 | obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o | 8 | obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o |
| 8 | obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o | 9 | obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o |
| 9 | obj-$(CONFIG_PHY_MVEBU_SATA) += phy-mvebu-sata.o | 10 | obj-$(CONFIG_PHY_MVEBU_SATA) += phy-mvebu-sata.o |
| 11 | obj-$(CONFIG_PHY_MIPHY365X) += phy-miphy365x.o | ||
| 10 | obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o | 12 | obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o |
| 11 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o | 13 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o |
| 12 | obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o | 14 | obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o |
| 13 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o | 15 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o |
| 14 | obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o | 16 | obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o |
| 17 | obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o | ||
| 15 | obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o | 18 | obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o |
| 16 | obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o | 19 | obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o |
| 17 | phy-exynos-usb2-y += phy-samsung-usb2.o | 20 | phy-exynos-usb2-y += phy-samsung-usb2.o |
| @@ -20,3 +23,5 @@ phy-exynos-usb2-$(CONFIG_PHY_EXYNOS4X12_USB2) += phy-exynos4x12-usb2.o · 2 unmodified lines | |||
| 20 | phy-exynos-usb2-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o | 23 | phy-exynos-usb2-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o |
| 21 | obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o | 24 | obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o |
| 22 | obj-$(CONFIG_PHY_XGENE) += phy-xgene.o | 25 | obj-$(CONFIG_PHY_XGENE) += phy-xgene.o |
| 26 | obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o | ||
| 27 | obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o | ||
| @@ -117,7 +117,7 @@ static int bcm_kona_usb2_probe(struct platform_device *pdev) · 116 unmodified lines | |||
| 117 | 117 | ||
| 118 | platform_set_drvdata(pdev, phy); | 118 | platform_set_drvdata(pdev, phy); |
| 119 | 119 | ||
| 120 | gphy = devm_phy_create(dev, &ops, NULL); | 120 | gphy = devm_phy_create(dev, NULL, &ops, NULL); |
| 121 | if (IS_ERR(gphy)) | 121 | if (IS_ERR(gphy)) |
| 122 | return PTR_ERR(gphy); | 122 | return PTR_ERR(gphy); |
| 123 | 123 | ||
| @@ -0,0 +1,284 @@ | |||
| 1 | /* | ||
| 2 | * Marvell Berlin SATA PHY driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Marvell Technology Group Ltd. | ||
| 5 | * | ||
| 6 | * Antoine Ténart <antoine.tenart@free-electrons.com> | ||
| 7 | * | ||
| 8 | * This file is licensed under the terms of the GNU General Public | ||
| 9 | * License version 2. This program is licensed "as is" without any | ||
| 10 | * warranty of any kind, whether express or implied. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/clk.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/phy/phy.h> | ||
| 16 | #include <linux/io.h> | ||
| 17 | #include <linux/platform_device.h> | ||
| 18 | |||
| 19 | #define HOST_VSA_ADDR 0x0 | ||
| 20 | #define HOST_VSA_DATA 0x4 | ||
| 21 | #define PORT_SCR_CTL 0x2c | ||
| 22 | #define PORT_VSR_ADDR 0x78 | ||
| 23 | #define PORT_VSR_DATA 0x7c | ||
| 24 | |||
| 25 | #define CONTROL_REGISTER 0x0 | ||
| 26 | #define MBUS_SIZE_CONTROL 0x4 | ||
| 27 | |||
| 28 | #define POWER_DOWN_PHY0 BIT(6) | ||
| 29 | #define POWER_DOWN_PHY1 BIT(14) | ||
| 30 | #define MBUS_WRITE_REQUEST_SIZE_128 (BIT(2) << 16) | ||
| 31 | #define MBUS_READ_REQUEST_SIZE_128 (BIT(2) << 19) | ||
| 32 | |||
| 33 | #define PHY_BASE 0x200 | ||
| 34 | |||
| 35 | /* register 0x01 */ | ||
| 36 | #define REF_FREF_SEL_25 BIT(0) | ||
| 37 | #define PHY_MODE_SATA (0x0 << 5) | ||
| 38 | |||
| 39 | /* register 0x02 */ | ||
| 40 | #define USE_MAX_PLL_RATE BIT(12) | ||
| 41 | |||
| 42 | /* register 0x23 */ | ||
| 43 | #define DATA_BIT_WIDTH_10 (0x0 << 10) | ||
| 44 | #define DATA_BIT_WIDTH_20 (0x1 << 10) | ||
| 45 | #define DATA_BIT_WIDTH_40 (0x2 << 10) | ||
| 46 | |||
| 47 | /* register 0x25 */ | ||
| 48 | #define PHY_GEN_MAX_1_5 (0x0 << 10) | ||
| 49 | #define PHY_GEN_MAX_3_0 (0x1 << 10) | ||
| 50 | #define PHY_GEN_MAX_6_0 (0x2 << 10) | ||
| 51 | |||
| 52 | struct phy_berlin_desc { | ||
| 53 | struct phy *phy; | ||
| 54 | u32 power_bit; | ||
| 55 | unsigned index; | ||
| 56 | }; | ||
| 57 | |||
| 58 | struct phy_berlin_priv { | ||
| 59 | void __iomem *base; | ||
| 60 | spinlock_t lock; | ||
| 61 | struct clk *clk; | ||
| 62 | struct phy_berlin_desc **phys; | ||
| 63 | unsigned nphys; | ||
| 64 | }; | ||
| 65 | |||
| 66 | static inline void phy_berlin_sata_reg_setbits(void __iomem *ctrl_reg, u32 reg, | ||
| 67 | u32 mask, u32 val) | ||
| 68 | { | ||
| 69 | u32 regval; | ||
| 70 | |||
| 71 | /* select register */ | ||
| 72 | writel(PHY_BASE + reg, ctrl_reg + PORT_VSR_ADDR); | ||
| 73 | |||
| 74 | /* set bits */ | ||
| 75 | regval = readl(ctrl_reg + PORT_VSR_DATA); | ||
| 76 | regval &= ~mask; | ||
| 77 | regval |= val; | ||
| 78 | writel(regval, ctrl_reg + PORT_VSR_DATA); | ||
| 79 | } | ||
| 80 | |||
| 81 | static int phy_berlin_sata_power_on(struct phy *phy) | ||
| 82 | { | ||
| 83 | struct phy_berlin_desc *desc = phy_get_drvdata(phy); | ||
| 84 | struct phy_berlin_priv *priv = dev_get_drvdata(phy->dev.parent); | ||
| 85 | void __iomem *ctrl_reg = priv->base + 0x60 + (desc->index * 0x80); | ||
| 86 | int ret = 0; | ||
| 87 | u32 regval; | ||
| 88 | |||
| 89 | clk_prepare_enable(priv->clk); | ||
| 90 | |||
| 91 | spin_lock(&priv->lock); | ||
| 92 | |||
| 93 | /* Power on PHY */ | ||
| 94 | writel(CONTROL_REGISTER, priv->base + HOST_VSA_ADDR); | ||
| 95 | regval = readl(priv->base + HOST_VSA_DATA); | ||
| 96 | regval &= ~desc->power_bit; | ||
| 97 | writel(regval, priv->base + HOST_VSA_DATA); | ||
| 98 | |||
| 99 | /* Configure MBus */ | ||
| 100 | writel(MBUS_SIZE_CONTROL, priv->base + HOST_VSA_ADDR); | ||
| 101 | regval = readl(priv->base + HOST_VSA_DATA); | ||
| 102 | regval |= MBUS_WRITE_REQUEST_SIZE_128 | MBUS_READ_REQUEST_SIZE_128; | ||
| 103 | writel(regval, priv->base + HOST_VSA_DATA); | ||
| 104 | |||
| 105 | /* set PHY mode and ref freq to 25 MHz */ | ||
| 106 | phy_berlin_sata_reg_setbits(ctrl_reg, 0x1, 0xff, | ||
| 107 | REF_FREF_SEL_25 | PHY_MODE_SATA); | ||
| 108 | |||
| 109 | /* set PHY up to 6 Gbps */ | ||
| 110 | phy_berlin_sata_reg_setbits(ctrl_reg, 0x25, 0xc00, PHY_GEN_MAX_6_0); | ||
| 111 | |||
| 112 | /* set 40 bits width */ | ||
| 113 | phy_berlin_sata_reg_setbits(ctrl_reg, 0x23, 0xc00, DATA_BIT_WIDTH_40); | ||
| 114 | |||
| 115 | /* use max pll rate */ | ||
| 116 | phy_berlin_sata_reg_setbits(ctrl_reg, 0x2, 0x0, USE_MAX_PLL_RATE); | ||
| 117 | |||
| 118 | /* set Gen3 controller speed */ | ||
| 119 | regval = readl(ctrl_reg + PORT_SCR_CTL); | ||
| 120 | regval &= ~GENMASK(7, 4); | ||
| 121 | regval |= 0x30; | ||
| 122 | writel(regval, ctrl_reg + PORT_SCR_CTL); | ||
| 123 | |||
| 124 | spin_unlock(&priv->lock); | ||
| 125 | |||
| 126 | clk_disable_unprepare(priv->clk); | ||
| 127 | |||
| 128 | return ret; | ||
| 129 | } | ||
| 130 | |||
| 131 | static int phy_berlin_sata_power_off(struct phy *phy) | ||
| 132 | { | ||
| 133 | struct phy_berlin_desc *desc = phy_get_drvdata(phy); | ||
| 134 | struct phy_berlin_priv *priv = dev_get_drvdata(phy->dev.parent); | ||
| 135 | u32 regval; | ||
| 136 | |||
| 137 | clk_prepare_enable(priv->clk); | ||
| 138 | |||
| 139 | spin_lock(&priv->lock); | ||
| 140 | |||
| 141 | /* Power down PHY */ | ||
| 142 | writel(CONTROL_REGISTER, priv->base + HOST_VSA_ADDR); | ||
| 143 | regval = readl(priv->base + HOST_VSA_DATA); | ||
| 144 | regval |= desc->power_bit; | ||
| 145 | writel(regval, priv->base + HOST_VSA_DATA); | ||
| 146 | |||
| 147 | spin_unlock(&priv->lock); | ||
| 148 | |||
| 149 | clk_disable_unprepare(priv->clk); | ||
| 150 | |||
| 151 | return 0; | ||
| 152 | } | ||
| 153 | |||
| 154 | static struct phy *phy_berlin_sata_phy_xlate(struct device *dev, | ||
| 155 | struct of_phandle_args *args) | ||
| 156 | { | ||
| 157 | struct phy_berlin_priv *priv = dev_get_drvdata(dev); | ||
| 158 | int i; | ||
| 159 | |||
| 160 | if (WARN_ON(args->args[0] >= priv->nphys)) | ||
| 161 | return ERR_PTR(-ENODEV); | ||
| 162 | |||
| 163 | for (i = 0; i < priv->nphys; i++) { | ||
| 164 | if (priv->phys[i]->index == args->args[0]) | ||
| 165 | break; | ||
| 166 | } | ||
| 167 | |||
| 168 | if (i == priv->nphys) | ||
| 169 | return ERR_PTR(-ENODEV); | ||
| 170 | |||
| 171 | return priv->phys[i]->phy; | ||
| 172 | } | ||
| 173 | |||
| 174 | static struct phy_ops phy_berlin_sata_ops = { | ||
| 175 | .power_on = phy_berlin_sata_power_on, | ||
| 176 | .power_off = phy_berlin_sata_power_off, | ||
| 177 | .owner = THIS_MODULE, | ||
| 178 | }; | ||
| 179 | |||
| 180 | static u32 phy_berlin_power_down_bits[] = { | ||
| 181 | POWER_DOWN_PHY0, | ||
| 182 | POWER_DOWN_PHY1, | ||
| 183 | }; | ||
| 184 | |||
| 185 | static int phy_berlin_sata_probe(struct platform_device *pdev) | ||
| 186 | { | ||
| 187 | struct device *dev = &pdev->dev; | ||
| 188 | struct device_node *child; | ||
| 189 | struct phy *phy; | ||
| 190 | struct phy_provider *phy_provider; | ||
| 191 | struct phy_berlin_priv *priv; | ||
| 192 | struct resource *res; | ||
| 193 | int i = 0; | ||
| 194 | u32 phy_id; | ||
| 195 | |||
| 196 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 197 | if (!priv) | ||
| 198 | return -ENOMEM; | ||
| 199 | |||
| 200 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 201 | if (!res) | ||
| 202 | return -EINVAL; | ||
| 203 | |||
| 204 | priv->base = devm_ioremap(dev, res->start, resource_size(res)); | ||
| 205 | if (!priv->base) | ||
| 206 | return -ENOMEM; | ||
| 207 | |||
| 208 | priv->clk = devm_clk_get(dev, NULL); | ||
| 209 | if (IS_ERR(priv->clk)) | ||
| 210 | return PTR_ERR(priv->clk); | ||
| 211 | |||
| 212 | priv->nphys = of_get_child_count(dev->of_node); | ||
| 213 | if (priv->nphys == 0) | ||
| 214 | return -ENODEV; | ||
| 215 | |||
| 216 | priv->phys = devm_kzalloc(dev, priv->nphys * sizeof(*priv->phys), | ||
| 217 | GFP_KERNEL); | ||
| 218 | if (!priv->phys) | ||
| 219 | return -ENOMEM; | ||
| 220 | |||
| 221 | dev_set_drvdata(dev, priv); | ||
| 222 | spin_lock_init(&priv->lock); | ||
| 223 | |||
| 224 | for_each_available_child_of_node(dev->of_node, child) { | ||
| 225 | struct phy_berlin_desc *phy_desc; | ||
| 226 | |||
| 227 | if (of_property_read_u32(child, "reg", &phy_id)) { | ||
| 228 | dev_err(dev, "missing reg property in node %s\n", | ||
| 229 | child->name); | ||
| 230 | return -EINVAL; | ||
| 231 | } | ||
| 232 | |||
| 233 | if (phy_id >= ARRAY_SIZE(phy_berlin_power_down_bits)) { | ||
| 234 | dev_err(dev, "invalid reg in node %s\n", child->name); | ||
| 235 | return -EINVAL; | ||
| 236 | } | ||
| 237 | |||
| 238 | phy_desc = devm_kzalloc(dev, sizeof(*phy_desc), GFP_KERNEL); | ||
| 239 | if (!phy_desc) | ||
| 240 | return -ENOMEM; | ||
| 241 | |||
| 242 | phy = devm_phy_create(dev, NULL, &phy_berlin_sata_ops, NULL); | ||
| 243 | if (IS_ERR(phy)) { | ||
| 244 | dev_err(dev, "failed to create PHY %d\n", phy_id); | ||
| 245 | return PTR_ERR(phy); | ||
| 246 | } | ||
| 247 | |||
| 248 | phy_desc->phy = phy; | ||
| 249 | phy_desc->power_bit = phy_berlin_power_down_bits[phy_id]; | ||
| 250 | phy_desc->index = phy_id; | ||
| 251 | phy_set_drvdata(phy, phy_desc); | ||
| 252 | |||
| 253 | priv->phys[i++] = phy_desc; | ||
| 254 | |||
| 255 | /* Make sure the PHY is off */ | ||
| 256 | phy_berlin_sata_power_off(phy); | ||
| 257 | } | ||
| 258 | |||
| 259 | phy_provider = | ||
| 260 | devm_of_phy_provider_register(dev, phy_berlin_sata_phy_xlate); | ||
| 261 | if (IS_ERR(phy_provider)) | ||
| 262 | return PTR_ERR(phy_provider); | ||
| 263 | |||
| 264 | return 0; | ||
| 265 | } | ||
| 266 | |||
| 267 | static const struct of_device_id phy_berlin_sata_of_match[] = { | ||
| 268 | { .compatible = "marvell,berlin2q-sata-phy" }, | ||
| 269 | { }, | ||
| 270 | }; | ||
| 271 | |||
| 272 | static struct platform_driver phy_berlin_sata_driver = { | ||
| 273 | .probe = phy_berlin_sata_probe, | ||
| 274 | .driver = { | ||
| 275 | .name = "phy-berlin-sata", | ||
| 276 | .owner = THIS_MODULE, | ||
| 277 | .of_match_table = phy_berlin_sata_of_match, | ||
| 278 | }, | ||
| 279 | }; | ||
| 280 | module_platform_driver(phy_berlin_sata_driver); | ||
| 281 | |||
| 282 | MODULE_DESCRIPTION("Marvell Berlin SATA PHY driver"); | ||
| 283 | MODULE_AUTHOR("Antoine Ténart <antoine.tenart@free-electrons.com>"); | ||
| 284 | MODULE_LICENSE("GPL v2"); | ||
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | #include <linux/phy/phy.h> | 21 | #include <linux/phy/phy.h> |
| 22 | #include <linux/idr.h> | 22 | #include <linux/idr.h> |
| 23 | #include <linux/pm_runtime.h> | 23 | #include <linux/pm_runtime.h> |
| 24 | #include <linux/regulator/consumer.h> | ||
| 24 | 25 | ||
| 25 | static struct class *phy_class; | 26 | static struct class *phy_class; |
| 26 | static DEFINE_MUTEX(phy_provider_mutex); | 27 | static DEFINE_MUTEX(phy_provider_mutex); |
| @@ -86,10 +87,15 @@ static struct phy *phy_lookup(struct device *device, const char *port) · 59 unmodified lines | |||
| 86 | static struct phy_provider *of_phy_provider_lookup(struct device_node *node) | 87 | static struct phy_provider *of_phy_provider_lookup(struct device_node *node) |
| 87 | { | 88 | { |
| 88 | struct phy_provider *phy_provider; | 89 | struct phy_provider *phy_provider; |
| 90 | struct device_node *child; | ||
| 89 | 91 | ||
| 90 | list_for_each_entry(phy_provider, &phy_provider_list, list) { | 92 | list_for_each_entry(phy_provider, &phy_provider_list, list) { |
| 91 | if (phy_provider->dev->of_node == node) | 93 | if (phy_provider->dev->of_node == node) |
| 92 | return phy_provider; | 94 | return phy_provider; |
| 95 | |||
| 96 | for_each_child_of_node(phy_provider->dev->of_node, child) | ||
| 97 | if (child == node) | ||
| 98 | return phy_provider; | ||
| 93 | } | 99 | } |
| 94 | 100 | ||
| 95 | return ERR_PTR(-EPROBE_DEFER); | 101 | return ERR_PTR(-EPROBE_DEFER); |
| @@ -226,6 +232,12 @@ int phy_power_on(struct phy *phy) · 130 unmodified lines | |||
| 226 | if (!phy) | 232 | if (!phy) |
| 227 | return 0; | 233 | return 0; |
| 228 | 234 | ||
| 235 | if (phy->pwr) { | ||
| 236 | ret = regulator_enable(phy->pwr); | ||
| 237 | if (ret) | ||
| 238 | return ret; | ||
| 239 | } | ||
| 240 | |||
| 229 | ret = phy_pm_runtime_get_sync(phy); | 241 | ret = phy_pm_runtime_get_sync(phy); |
| 230 | if (ret < 0 && ret != -ENOTSUPP) | 242 | if (ret < 0 && ret != -ENOTSUPP) |
| 231 | return ret; | 243 | return ret; |
| @@ -247,6 +259,8 @@ int phy_power_on(struct phy *phy) · 15 unmodified lines | |||
| 247 | out: | 259 | out: |
| 248 | mutex_unlock(&phy->mutex); | 260 | mutex_unlock(&phy->mutex); |
| 249 | phy_pm_runtime_put_sync(phy); | 261 | phy_pm_runtime_put_sync(phy); |
| 262 | if (phy->pwr) | ||
| 263 | regulator_disable(phy->pwr); | ||
| 250 | 264 | ||
| 251 | return ret; | 265 | return ret; |
| 252 | } | 266 | } |
| @@ -272,6 +286,9 @@ int phy_power_off(struct phy *phy) · 19 unmodified lines | |||
| 272 | mutex_unlock(&phy->mutex); | 286 | mutex_unlock(&phy->mutex); |
| 273 | phy_pm_runtime_put(phy); | 287 | phy_pm_runtime_put(phy); |
| 274 | 288 | ||
| 289 | if (phy->pwr) | ||
| 290 | regulator_disable(phy->pwr); | ||
| 291 | |||
| 275 | return 0; | 292 | return 0; |
| 276 | } | 293 | } |
| 277 | EXPORT_SYMBOL_GPL(phy_power_off); | 294 | EXPORT_SYMBOL_GPL(phy_power_off); |
| @@ -398,13 +415,20 @@ struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args · 120 unmodified lines | |||
| 398 | struct phy *phy; | 415 | struct phy *phy; |
| 399 | struct class_dev_iter iter; | 416 | struct class_dev_iter iter; |
| 400 | struct device_node *node = dev->of_node; | 417 | struct device_node *node = dev->of_node; |
| 418 | struct device_node *child; | ||
| 401 | 419 | ||
| 402 | class_dev_iter_init(&iter, phy_class, NULL, NULL); | 420 | class_dev_iter_init(&iter, phy_class, NULL, NULL); |
| 403 | while ((dev = class_dev_iter_next(&iter))) { | 421 | while ((dev = class_dev_iter_next(&iter))) { |
| 404 | phy = to_phy(dev); | 422 | phy = to_phy(dev); |
| 405 | if (node != phy->dev.of_node) | 423 | if (node != phy->dev.of_node) { |
| 424 | for_each_child_of_node(node, child) { | ||
| 425 | if (child == phy->dev.of_node) | ||
| 426 | goto phy_found; | ||
| 427 | } | ||
| 406 | continue; | 428 | continue; |
| 429 | } | ||
| 407 | 430 | ||
| 431 | phy_found: | ||
| 408 | class_dev_iter_exit(&iter); | 432 | class_dev_iter_exit(&iter); |
| 409 | return phy; | 433 | return phy; |
| 410 | } | 434 | } |
| @@ -562,13 +586,15 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get); · 151 unmodified lines | |||
| 562 | /** | 586 | /** |
| 563 | * phy_create() - create a new phy | 587 | * phy_create() - create a new phy |
| 564 | * @dev: device that is creating the new phy | 588 | * @dev: device that is creating the new phy |
| 589 | * @node: device node of the phy | ||
| 565 | * @ops: function pointers for performing phy operations | 590 | * @ops: function pointers for performing phy operations |
| 566 | * @init_data: contains the list of PHY consumers or NULL | 591 | * @init_data: contains the list of PHY consumers or NULL |
| 567 | * | 592 | * |
| 568 | * Called to create a phy using phy framework. | 593 | * Called to create a phy using phy framework. |
| 569 | */ | 594 | */ |
| 570 | struct phy *phy_create(struct device *dev, const struct phy_ops *ops, | 595 | struct phy *phy_create(struct device *dev, struct device_node *node, |
| 571 | struct phy_init_data *init_data) | 596 | const struct phy_ops *ops, |
| 597 | struct phy_init_data *init_data) | ||
| 572 | { | 598 | { |
| 573 | int ret; | 599 | int ret; |
| 574 | int id; | 600 | int id; |
| @@ -588,12 +614,22 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, · 13 unmodified lines | |||
| 588 | goto free_phy; | 614 | goto free_phy; |
| 589 | } | 615 | } |
| 590 | 616 | ||
| 617 | /* phy-supply */ | ||
| 618 | phy->pwr = regulator_get_optional(dev, "phy"); | ||
| 619 | if (IS_ERR(phy->pwr)) { | ||
| 620 | if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) { | ||
| 621 | ret = -EPROBE_DEFER; | ||
| 622 | goto free_ida; | ||
| 623 | } | ||
| 624 | phy->pwr = NULL; | ||
| 625 | } | ||
| 626 | |||
| 591 | device_initialize(&phy->dev); | 627 | device_initialize(&phy->dev); |
| 592 | mutex_init(&phy->mutex); | 628 | mutex_init(&phy->mutex); |
| 593 | 629 | ||
| 594 | phy->dev.class = phy_class; | 630 | phy->dev.class = phy_class; |
| 595 | phy->dev.parent = dev; | 631 | phy->dev.parent = dev; |
| 596 | phy->dev.of_node = dev->of_node; | 632 | phy->dev.of_node = node ?: dev->of_node; |
| 597 | phy->id = id; | 633 | phy->id = id; |
| 598 | phy->ops = ops; | 634 | phy->ops = ops; |
| 599 | phy->init_data = init_data; | 635 | phy->init_data = init_data; |
| @@ -617,6 +653,9 @@ put_dev: · 17 unmodified lines | |||
| 617 | put_device(&phy->dev); /* calls phy_release() which frees resources */ | 653 | put_device(&phy->dev); /* calls phy_release() which frees resources */ |
| 618 | return ERR_PTR(ret); | 654 | return ERR_PTR(ret); |
| 619 | 655 | ||
| 656 | free_ida: | ||
| 657 | ida_simple_remove(&phy_ida, phy->id); | ||
| 658 | |||
| 620 | free_phy: | 659 | free_phy: |
| 621 | kfree(phy); | 660 | kfree(phy); |
| 622 | return ERR_PTR(ret); | 661 | return ERR_PTR(ret); |
| @@ -626,6 +665,7 @@ EXPORT_SYMBOL_GPL(phy_create); · 3 unmodified lines | |||
| 626 | /** | 665 | /** |
| 627 | * devm_phy_create() - create a new phy | 666 | * devm_phy_create() - create a new phy |
| 628 | * @dev: device that is creating the new phy | 667 | * @dev: device that is creating the new phy |
| 668 | * @node: device node of the phy | ||
| 629 | * @ops: function pointers for performing phy operations | 669 | * @ops: function pointers for performing phy operations |
| 630 | * @init_data: contains the list of PHY consumers or NULL | 670 | * @init_data: contains the list of PHY consumers or NULL |
| 631 | * | 671 | * |
| @@ -634,8 +674,9 @@ EXPORT_SYMBOL_GPL(phy_create); · 2 unmodified lines | |||
| 634 | * On driver detach, release function is invoked on the devres data, | 674 | * On driver detach, release function is invoked on the devres data, |
| 635 | * then, devres data is freed. | 675 | * then, devres data is freed. |
| 636 | */ | 676 | */ |
| 637 | struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops, | 677 | struct phy *devm_phy_create(struct device *dev, struct device_node *node, |
| 638 | struct phy_init_data *init_data) | 678 | const struct phy_ops *ops, |
| 679 | struct phy_init_data *init_data) | ||
| 639 | { | 680 | { |
| 640 | struct phy **ptr, *phy; | 681 | struct phy **ptr, *phy; |
| 641 | 682 | ||
| @@ -643,7 +684,7 @@ struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops, · 1 unmodified line | |||
| 643 | if (!ptr) | 684 | if (!ptr) |
| 644 | return ERR_PTR(-ENOMEM); | 685 | return ERR_PTR(-ENOMEM); |
| 645 | 686 | ||
| 646 | phy = phy_create(dev, ops, init_data); | 687 | phy = phy_create(dev, node, ops, init_data); |
| 647 | if (!IS_ERR(phy)) { | 688 | if (!IS_ERR(phy)) { |
| 648 | *ptr = phy; | 689 | *ptr = phy; |
| 649 | devres_add(dev, ptr); | 690 | devres_add(dev, ptr); |
| @@ -800,6 +841,7 @@ static void phy_release(struct device *dev) · 150 unmodified lines | |||
| 800 | 841 | ||
| 801 | phy = to_phy(dev); | 842 | phy = to_phy(dev); |
| 802 | dev_vdbg(dev, "releasing '%s'\n", dev_name(dev)); | 843 | dev_vdbg(dev, "releasing '%s'\n", dev_name(dev)); |
| 844 | regulator_put(phy->pwr); | ||
| 803 | ida_simple_remove(&phy_ida, phy->id); | 845 | ida_simple_remove(&phy_ida, phy->id); |
| 804 | kfree(phy); | 846 | kfree(phy); |
| 805 | } | 847 | } |
| @@ -9,6 +9,7 @@ · 8 unmodified lines | |||
| 9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | #include <linux/err.h> | ||
| 12 | #include <linux/io.h> | 13 | #include <linux/io.h> |
| 13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| @@ -76,7 +77,7 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev) · 61 unmodified lines | |||
| 76 | if (IS_ERR(state->regs)) | 77 | if (IS_ERR(state->regs)) |
| 77 | return PTR_ERR(state->regs); | 78 | return PTR_ERR(state->regs); |
| 78 | 79 | ||
| 79 | phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL); | 80 | phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops, NULL); |
| 80 | if (IS_ERR(phy)) { | 81 | if (IS_ERR(phy)) { |
| 81 | dev_err(dev, "failed to create Display Port PHY\n"); | 82 | dev_err(dev, "failed to create Display Port PHY\n"); |
| 82 | return PTR_ERR(phy); | 83 | return PTR_ERR(phy); |
| @@ -84,10 +85,8 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev) · 1 unmodified line | |||
| 84 | phy_set_drvdata(phy, state); | 85 | phy_set_drvdata(phy, state); |
| 85 | 86 | ||
| 86 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | 87 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); |
| 87 | if (IS_ERR(phy_provider)) | ||
| 88 | return PTR_ERR(phy_provider); | ||
| 89 | 88 | ||
| 90 | return 0; | 89 | return PTR_ERR_OR_ZERO(phy_provider); |
| 91 | } | 90 | } |
| 92 | 91 | ||
| 93 | static const struct of_device_id exynos_dp_video_phy_of_match[] = { | 92 | static const struct of_device_id exynos_dp_video_phy_of_match[] = { |
| @@ -9,6 +9,7 @@ · 8 unmodified lines | |||
| 9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | #include <linux/err.h> | ||
| 12 | #include <linux/io.h> | 13 | #include <linux/io.h> |
| 13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| @@ -135,7 +136,7 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev) · 120 unmodified lines | |||
| 135 | spin_lock_init(&state->slock); | 136 | spin_lock_init(&state->slock); |
| 136 | 137 | ||
| 137 | for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) { | 138 | for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) { |
| 138 | struct phy *phy = devm_phy_create(dev, | 139 | struct phy *phy = devm_phy_create(dev, NULL, |
| 139 | &exynos_mipi_video_phy_ops, NULL); | 140 | &exynos_mipi_video_phy_ops, NULL); |
| 140 | if (IS_ERR(phy)) { | 141 | if (IS_ERR(phy)) { |
| 141 | dev_err(dev, "failed to create PHY %d\n", i); | 142 | dev_err(dev, "failed to create PHY %d\n", i); |
| @@ -149,10 +150,8 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev) · 7 unmodified lines | |||
| 149 | 150 | ||
| 150 | phy_provider = devm_of_phy_provider_register(dev, | 151 | phy_provider = devm_of_phy_provider_register(dev, |
| 151 | exynos_mipi_video_phy_xlate); | 152 | exynos_mipi_video_phy_xlate); |
| 152 | if (IS_ERR(phy_provider)) | ||
| 153 | return PTR_ERR(phy_provider); | ||
| 154 | 153 | ||
| 155 | return 0; | 154 | return PTR_ERR_OR_ZERO(phy_provider); |
| 156 | } | 155 | } |
| 157 | 156 | ||
| 158 | static const struct of_device_id exynos_mipi_video_phy_of_match[] = { | 157 | static const struct of_device_id exynos_mipi_video_phy_of_match[] = { |
| @@ -67,6 +67,8 @@ · 66 unmodified lines | |||
| 67 | #define EXYNOS_4x12_UPHYCLK_PHYFSEL_24MHZ (0x5 << 0) | 67 | #define EXYNOS_4x12_UPHYCLK_PHYFSEL_24MHZ (0x5 << 0) |
| 68 | #define EXYNOS_4x12_UPHYCLK_PHYFSEL_50MHZ (0x7 << 0) | 68 | #define EXYNOS_4x12_UPHYCLK_PHYFSEL_50MHZ (0x7 << 0) |
| 69 | 69 | ||
| 70 | #define EXYNOS_3250_UPHYCLK_REFCLKSEL (0x2 << 8) | ||
| 71 | |||
| 70 | #define EXYNOS_4x12_UPHYCLK_PHY0_ID_PULLUP BIT(3) | 72 | #define EXYNOS_4x12_UPHYCLK_PHY0_ID_PULLUP BIT(3) |
| 71 | #define EXYNOS_4x12_UPHYCLK_PHY0_COMMON_ON BIT(4) | 73 | #define EXYNOS_4x12_UPHYCLK_PHY0_COMMON_ON BIT(4) |
| 72 | #define EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON BIT(7) | 74 | #define EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON BIT(7) |
| @@ -86,13 +88,23 @@ · 13 unmodified lines | |||
| 86 | #define EXYNOS_4x12_URSTCON_OTG_HLINK BIT(1) | 88 | #define EXYNOS_4x12_URSTCON_OTG_HLINK BIT(1) |
| 87 | #define EXYNOS_4x12_URSTCON_OTG_PHYLINK BIT(2) | 89 | #define EXYNOS_4x12_URSTCON_OTG_PHYLINK BIT(2) |
| 88 | #define EXYNOS_4x12_URSTCON_HOST_PHY BIT(3) | 90 | #define EXYNOS_4x12_URSTCON_HOST_PHY BIT(3) |
| 91 | /* The following bit defines are presented in the | ||
| 92 | * order taken from the Exynos4412 reference manual. | ||
| 93 | * | ||
| 94 | * During experiments with the hardware and debugging | ||
| 95 | * it was determined that the hardware behaves contrary | ||
| 96 | * to the manual. | ||
| 97 | * | ||
| 98 | * The following bit values were chaned accordingly to the | ||
| 99 | * results of real hardware experiments. | ||
| 100 | */ | ||
| 89 | #define EXYNOS_4x12_URSTCON_PHY1 BIT(4) | 101 | #define EXYNOS_4x12_URSTCON_PHY1 BIT(4) |
| 90 | #define EXYNOS_4x12_URSTCON_HSIC0 BIT(5) | 102 | #define EXYNOS_4x12_URSTCON_HSIC0 BIT(6) |
| 91 | #define EXYNOS_4x12_URSTCON_HSIC1 BIT(6) | 103 | #define EXYNOS_4x12_URSTCON_HSIC1 BIT(5) |
| 92 | #define EXYNOS_4x12_URSTCON_HOST_LINK_ALL BIT(7) | 104 | #define EXYNOS_4x12_URSTCON_HOST_LINK_ALL BIT(7) |
| 93 | #define EXYNOS_4x12_URSTCON_HOST_LINK_P0 BIT(8) | 105 | #define EXYNOS_4x12_URSTCON_HOST_LINK_P0 BIT(10) |
| 94 | #define EXYNOS_4x12_URSTCON_HOST_LINK_P1 BIT(9) | 106 | #define EXYNOS_4x12_URSTCON_HOST_LINK_P1 BIT(9) |
| 95 | #define EXYNOS_4x12_URSTCON_HOST_LINK_P2 BIT(10) | 107 | #define EXYNOS_4x12_URSTCON_HOST_LINK_P2 BIT(8) |
| 96 | 108 | ||
| 97 | /* Isolation, configured in the power management unit */ | 109 | /* Isolation, configured in the power management unit */ |
| 98 | #define EXYNOS_4x12_USB_ISOL_OFFSET 0x704 | 110 | #define EXYNOS_4x12_USB_ISOL_OFFSET 0x704 |
| @@ -187,7 +199,12 @@ static void exynos4x12_setup_clk(struct samsung_usb2_phy_instance *inst) · 88 unmodified lines | |||
| 187 | 199 | ||
| 188 | clk = readl(drv->reg_phy + EXYNOS_4x12_UPHYCLK); | 200 | clk = readl(drv->reg_phy + EXYNOS_4x12_UPHYCLK); |
| 189 | clk &= ~EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK; | 201 | clk &= ~EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK; |
| 202 | |||
| 203 | if (drv->cfg->has_refclk_sel) | ||
| 204 | clk = EXYNOS_3250_UPHYCLK_REFCLKSEL; | ||
| 205 | |||
| 190 | clk |= drv->ref_reg_val << EXYNOS_4x12_UPHYCLK_PHYFSEL_OFFSET; | 206 | clk |= drv->ref_reg_val << EXYNOS_4x12_UPHYCLK_PHYFSEL_OFFSET; |
| 207 | clk |= EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON; | ||
| 191 | writel(clk, drv->reg_phy + EXYNOS_4x12_UPHYCLK); | 208 | writel(clk, drv->reg_phy + EXYNOS_4x12_UPHYCLK); |
| 192 | } | 209 | } |
| 193 | 210 | ||
| @@ -198,27 +215,22 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on) · 4 unmodified lines | |||
| 198 | u32 phypwr = 0; | 215 | u32 phypwr = 0; |
| 199 | u32 rst; | 216 | u32 rst; |
| 200 | u32 pwr; | 217 | u32 pwr; |
| 201 | u32 mode = 0; | ||
| 202 | u32 switch_mode = 0; | ||
| 203 | 218 | ||
| 204 | switch (inst->cfg->id) { | 219 | switch (inst->cfg->id) { |
| 205 | case EXYNOS4x12_DEVICE: | 220 | case EXYNOS4x12_DEVICE: |
| 206 | phypwr = EXYNOS_4x12_UPHYPWR_PHY0; | 221 | phypwr = EXYNOS_4x12_UPHYPWR_PHY0; |
| 207 | rstbits = EXYNOS_4x12_URSTCON_PHY0; | 222 | rstbits = EXYNOS_4x12_URSTCON_PHY0; |
| 208 | mode = EXYNOS_4x12_MODE_SWITCH_DEVICE; | ||
| 209 | switch_mode = 1; | ||
| 210 | break; | 223 | break; |
| 211 | case EXYNOS4x12_HOST: | 224 | case EXYNOS4x12_HOST: |
| 212 | phypwr = EXYNOS_4x12_UPHYPWR_PHY1; | 225 | phypwr = EXYNOS_4x12_UPHYPWR_PHY1; |
| 213 | rstbits = EXYNOS_4x12_URSTCON_HOST_PHY; | 226 | rstbits = EXYNOS_4x12_URSTCON_HOST_PHY | |
| 214 | mode = EXYNOS_4x12_MODE_SWITCH_HOST; | 227 | EXYNOS_4x12_URSTCON_PHY1 | |
| 215 | switch_mode = 1; | 228 | EXYNOS_4x12_URSTCON_HOST_LINK_P0; |
| 216 | break; | 229 | break; |
| 217 | case EXYNOS4x12_HSIC0: | 230 | case EXYNOS4x12_HSIC0: |
| 218 | phypwr = EXYNOS_4x12_UPHYPWR_HSIC0; | 231 | phypwr = EXYNOS_4x12_UPHYPWR_HSIC0; |
| 219 | rstbits = EXYNOS_4x12_URSTCON_HSIC1 | | 232 | rstbits = EXYNOS_4x12_URSTCON_HSIC0 | |
| 220 | EXYNOS_4x12_URSTCON_HOST_LINK_P0 | | 233 | EXYNOS_4x12_URSTCON_HOST_LINK_P1; |
| 221 | EXYNOS_4x12_URSTCON_HOST_PHY; | ||
| 222 | break; | 234 | break; |
| 223 | case EXYNOS4x12_HSIC1: | 235 | case EXYNOS4x12_HSIC1: |
| 224 | phypwr = EXYNOS_4x12_UPHYPWR_HSIC1; | 236 | phypwr = EXYNOS_4x12_UPHYPWR_HSIC1; |
| @@ -228,11 +240,6 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on) · 3 unmodified lines | |||
| 228 | }; | 240 | }; |
| 229 | 241 | ||
| 230 | if (on) { | 242 | if (on) { |
| 231 | if (switch_mode) | ||
| 232 | regmap_update_bits(drv->reg_sys, | ||
| 233 | EXYNOS_4x12_MODE_SWITCH_OFFSET, | ||
| 234 | EXYNOS_4x12_MODE_SWITCH_MASK, mode); | ||
| 235 | |||
| 236 | pwr = readl(drv->reg_phy + EXYNOS_4x12_UPHYPWR); | 243 | pwr = readl(drv->reg_phy + EXYNOS_4x12_UPHYPWR); |
| 237 | pwr &= ~phypwr; | 244 | pwr &= ~phypwr; |
| 238 | writel(pwr, drv->reg_phy + EXYNOS_4x12_UPHYPWR); | 245 | writel(pwr, drv->reg_phy + EXYNOS_4x12_UPHYPWR); |
| @@ -253,41 +260,78 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on) · 14 unmodified lines | |||
| 253 | } | 260 | } |
| 254 | } | 261 | } |
| 255 | 262 | ||
| 256 | static int exynos4x12_power_on(struct samsung_usb2_phy_instance *inst) | 263 | static void exynos4x12_power_on_int(struct samsung_usb2_phy_instance *inst) |
| 257 | { | 264 | { |
| 258 | struct samsung_usb2_phy_driver *drv = inst->drv; | 265 | if (inst->int_cnt++ > 0) |
| 266 | return; | ||
| 259 | 267 | ||
| 260 | inst->enabled = 1; | ||
| 261 | exynos4x12_setup_clk(inst); | 268 | exynos4x12_setup_clk(inst); |
| 262 | exynos4x12_phy_pwr(inst, 1); | ||
| 263 | exynos4x12_isol(inst, 0); | 269 | exynos4x12_isol(inst, 0); |
| 270 | exynos4x12_phy_pwr(inst, 1); | ||
| 271 | } | ||
| 272 | |||
| 273 | static int exynos4x12_power_on(struct samsung_usb2_phy_instance *inst) | ||
| 274 | { | ||
| 275 | struct samsung_usb2_phy_driver *drv = inst->drv; | ||
| 276 | |||
| 277 | if (inst->ext_cnt++ > 0) | ||
| 278 | return 0; | ||
| 264 | 279 | ||
| 265 | /* Power on the device, as it is necessary for HSIC to work */ | 280 | if (inst->cfg->id == EXYNOS4x12_HOST) { |
| 266 | if (inst->cfg->id == EXYNOS4x12_HSIC0) { | 281 | regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET, |
| 267 | struct samsung_usb2_phy_instance *device = | 282 | EXYNOS_4x12_MODE_SWITCH_MASK, |
| 268 | &drv->instances[EXYNOS4x12_DEVICE]; | 283 | EXYNOS_4x12_MODE_SWITCH_HOST); |
| 269 | exynos4x12_phy_pwr(device, 1); | 284 | exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_DEVICE]); |
| 270 | exynos4x12_isol(device, 0); | ||
| 271 | } | 285 | } |
| 272 | 286 | ||
| 287 | if (inst->cfg->id == EXYNOS4x12_DEVICE && drv->cfg->has_mode_switch) | ||
| 288 | regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET, | ||
| 289 | EXYNOS_4x12_MODE_SWITCH_MASK, | ||
| 290 | EXYNOS_4x12_MODE_SWITCH_DEVICE); | ||
| 291 | |||
| 292 | if (inst->cfg->id == EXYNOS4x12_HSIC0 || | ||
| 293 | inst->cfg->id == EXYNOS4x12_HSIC1) { | ||
| 294 | exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_DEVICE]); | ||
| 295 | exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_HOST]); | ||
| 296 | } | ||
| 297 | |||
| 298 | exynos4x12_power_on_int(inst); | ||
| 299 | |||
| 273 | return 0; | 300 | return 0; |
| 274 | } | 301 | } |
| 275 | 302 | ||
| 276 | static int exynos4x12_power_off(struct samsung_usb2_phy_instance *inst) | 303 | static void exynos4x12_power_off_int(struct samsung_usb2_phy_instance *inst) |
| 277 | { | 304 | { |
| 278 | struct samsung_usb2_phy_driver *drv = inst->drv; | 305 | if (inst->int_cnt-- > 1) |
| 279 | struct samsung_usb2_phy_instance *device = | 306 | return; |
| 280 | &drv->instances[EXYNOS4x12_DEVICE]; | ||
| 281 | 307 | ||
| 282 | inst->enabled = 0; | ||
| 283 | exynos4x12_isol(inst, 1); | 308 | exynos4x12_isol(inst, 1); |
| 284 | exynos4x12_phy_pwr(inst, 0); | 309 | exynos4x12_phy_pwr(inst, 0); |
| 310 | } | ||
| 311 | |||
| 312 | static int exynos4x12_power_off(struct samsung_usb2_phy_instance *inst) | ||
| 313 | { | ||
| 314 | struct samsung_usb2_phy_driver *drv = inst->drv; | ||
| 315 | |||
| 316 | if (inst->ext_cnt-- > 1) | ||
| 317 | return 0; | ||
| 318 | |||
| 319 | if (inst->cfg->id == EXYNOS4x12_DEVICE && drv->cfg->has_mode_switch) | ||
| 320 | regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET, | ||
| 321 | EXYNOS_4x12_MODE_SWITCH_MASK, | ||
| 322 | EXYNOS_4x12_MODE_SWITCH_HOST); | ||
| 323 | |||
| 324 | if (inst->cfg->id == EXYNOS4x12_HOST) | ||
| 325 | exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_DEVICE]); | ||
| 285 | 326 | ||
| 286 | if (inst->cfg->id == EXYNOS4x12_HSIC0 && !device->enabled) { | 327 | if (inst->cfg->id == EXYNOS4x12_HSIC0 || |
| 287 | exynos4x12_isol(device, 1); | 328 | inst->cfg->id == EXYNOS4x12_HSIC1) { |
| 288 | exynos4x12_phy_pwr(device, 0); | 329 | exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_DEVICE]); |
| 330 | exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_HOST]); | ||
| 289 | } | 331 | } |
| 290 | 332 | ||
| 333 | exynos4x12_power_off_int(inst); | ||
| 334 | |||
| 291 | return 0; | 335 | return 0; |
| 292 | } | 336 | } |
| 293 | 337 | ||
| @@ -320,6 +364,13 @@ static const struct samsung_usb2_common_phy exynos4x12_phys[] = { · 26 unmodified lines | |||
| 320 | {}, | 364 | {}, |
| 321 | }; | 365 | }; |
| 322 | 366 | ||
| 367 | const struct samsung_usb2_phy_config exynos3250_usb2_phy_config = { | ||
| 368 | .has_refclk_sel = 1, | ||
| 369 | .num_phys = 1, | ||
| 370 | .phys = exynos4x12_phys, | ||
| 371 | .rate_to_clk = exynos4x12_rate_to_clk, | ||
| 372 | }; | ||
| 373 | |||
| 323 | const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config = { | 374 | const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config = { |
| 324 | .has_mode_switch = 1, | 375 | .has_mode_switch = 1, |
| 325 | .num_phys = EXYNOS4x12_NUM_PHYS, | 376 | .num_phys = EXYNOS4x12_NUM_PHYS, |
| @@ -506,7 +506,7 @@ static struct phy_ops exynos5_usbdrd_phy_ops = { · 505 unmodified lines | |||
| 506 | .owner = THIS_MODULE, | 506 | .owner = THIS_MODULE, |
| 507 | }; | 507 | }; |
| 508 | 508 | ||
| 509 | const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = { | 509 | static const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = { |
| 510 | { | 510 | { |
| 511 | .id = EXYNOS5_DRDPHY_UTMI, | 511 | .id = EXYNOS5_DRDPHY_UTMI, |
| 512 | .phy_isol = exynos5_usbdrd_phy_isol, | 512 | .phy_isol = exynos5_usbdrd_phy_isol, |
| @@ -521,13 +521,13 @@ const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = { · 8 unmodified lines | |||
| 521 | }, | 521 | }, |
| 522 | }; | 522 | }; |
| 523 | 523 | ||
| 524 | const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = { | 524 | static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = { |
| 525 | .phy_cfg = phy_cfg_exynos5, | 525 | .phy_cfg = phy_cfg_exynos5, |
| 526 | .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL, | 526 | .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL, |
| 527 | .pmu_offset_usbdrd1_phy = EXYNOS5420_USBDRD1_PHY_CONTROL, | 527 | .pmu_offset_usbdrd1_phy = EXYNOS5420_USBDRD1_PHY_CONTROL, |
| 528 | }; | 528 | }; |
| 529 | 529 | ||
| 530 | const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = { | 530 | static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = { |
| 531 | .phy_cfg = phy_cfg_exynos5, | 531 | .phy_cfg = phy_cfg_exynos5, |
| 532 | .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL, | 532 | .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL, |
| 533 | }; | 533 | }; |
| @@ -635,7 +635,8 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev) · 101 unmodified lines | |||
| 635 | dev_vdbg(dev, "Creating usbdrd_phy phy\n"); | 635 | dev_vdbg(dev, "Creating usbdrd_phy phy\n"); |
| 636 | 636 | ||
| 637 | for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) { | 637 | for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) { |
| 638 | struct phy *phy = devm_phy_create(dev, &exynos5_usbdrd_phy_ops, | 638 | struct phy *phy = devm_phy_create(dev, NULL, |
| 639 | &exynos5_usbdrd_phy_ops, | ||
| 639 | NULL); | 640 | NULL); |
| 640 | if (IS_ERR(phy)) { | 641 | if (IS_ERR(phy)) { |
| 641 | dev_err(dev, "Failed to create usbdrd_phy phy\n"); | 642 | dev_err(dev, "Failed to create usbdrd_phy phy\n"); |
| @@ -210,7 +210,7 @@ static int exynos_sata_phy_probe(struct platform_device *pdev) · 209 unmodified lines | |||
| 210 | return ret; | 210 | return ret; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | sata_phy->phy = devm_phy_create(dev, &exynos_sata_phy_ops, NULL); | 213 | sata_phy->phy = devm_phy_create(dev, NULL, &exynos_sata_phy_ops, NULL); |
| 214 | if (IS_ERR(sata_phy->phy)) { | 214 | if (IS_ERR(sata_phy->phy)) { |
| 215 | clk_disable_unprepare(sata_phy->phyclk); | 215 | clk_disable_unprepare(sata_phy->phyclk); |
| 216 | dev_err(dev, "failed to create PHY\n"); | 216 | dev_err(dev, "failed to create PHY\n"); |
| @@ -318,7 +318,6 @@ static int exynos5250_power_on(struct samsung_usb2_phy_instance *inst) · 317 unmodified lines | |||
| 318 | 318 | ||
| 319 | break; | 319 | break; |
| 320 | } | 320 | } |
| 321 | inst->enabled = 1; | ||
| 322 | exynos5250_isol(inst, 0); | 321 | exynos5250_isol(inst, 0); |
| 323 | 322 | ||
| 324 | return 0; | 323 | return 0; |
| @@ -331,7 +330,6 @@ static int exynos5250_power_off(struct samsung_usb2_phy_instance *inst) · 6 unmodified lines | |||
| 331 | u32 otg; | 330 | u32 otg; |
| 332 | u32 hsic; | 331 | u32 hsic; |
| 333 | 332 | ||
| 334 | inst->enabled = 0; | ||
| 335 | exynos5250_isol(inst, 1); | 333 | exynos5250_isol(inst, 1); |
| 336 | 334 | ||
| 337 | switch (inst->cfg->id) { | 335 | switch (inst->cfg->id) { |
| @@ -0,0 +1,192 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2014 Linaro Ltd. | ||
| 3 | * Copyright (c) 2014 Hisilicon Limited. | ||
| 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 as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/delay.h> | ||
| 12 | #include <linux/io.h> | ||
| 13 | #include <linux/mfd/syscon.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/phy/phy.h> | ||
| 16 | #include <linux/platform_device.h> | ||
| 17 | #include <linux/regmap.h> | ||
| 18 | |||
| 19 | #define SATA_PHY0_CTLL 0xa0 | ||
| 20 | #define MPLL_MULTIPLIER_SHIFT 1 | ||
| 21 | #define MPLL_MULTIPLIER_MASK 0xfe | ||
| 22 | #define MPLL_MULTIPLIER_50M 0x3c | ||
| 23 | #define MPLL_MULTIPLIER_100M 0x1e | ||
| 24 | #define PHY_RESET BIT(0) | ||
| 25 | #define REF_SSP_EN BIT(9) | ||
| 26 | #define SSC_EN BIT(10) | ||
| 27 | #define REF_USE_PAD BIT(23) | ||
| 28 | |||
| 29 | #define SATA_PORT_PHYCTL 0x174 | ||
| 30 | #define SPEED_MODE_MASK 0x6f0000 | ||
| 31 | #define HALF_RATE_SHIFT 16 | ||
| 32 | #define PHY_CONFIG_SHIFT 18 | ||
| 33 | #define GEN2_EN_SHIFT 21 | ||
| 34 | #define SPEED_CTRL BIT(20) | ||
| 35 | |||
| 36 | #define SATA_PORT_PHYCTL1 0x148 | ||
| 37 | #define AMPLITUDE_MASK 0x3ffffe | ||
| 38 | #define AMPLITUDE_GEN3 0x68 | ||
| 39 | #define AMPLITUDE_GEN3_SHIFT 15 | ||
| 40 | #define AMPLITUDE_GEN2 0x56 | ||
| 41 | #define AMPLITUDE_GEN2_SHIFT 8 | ||
| 42 | #define AMPLITUDE_GEN1 0x56 | ||
| 43 | #define AMPLITUDE_GEN1_SHIFT 1 | ||
| 44 | |||
| 45 | #define SATA_PORT_PHYCTL2 0x14c | ||
| 46 | #define PREEMPH_MASK 0x3ffff | ||
| 47 | #define PREEMPH_GEN3 0x20 | ||
| 48 | #define PREEMPH_GEN3_SHIFT 12 | ||
| 49 | #define PREEMPH_GEN2 0x15 | ||
| 50 | #define PREEMPH_GEN2_SHIFT 6 | ||
| 51 | #define PREEMPH_GEN1 0x5 | ||
| 52 | #define PREEMPH_GEN1_SHIFT 0 | ||
| 53 | |||
| 54 | struct hix5hd2_priv { | ||
| 55 | void __iomem *base; | ||
| 56 | struct regmap *peri_ctrl; | ||
| 57 | }; | ||
| 58 | |||
| 59 | enum phy_speed_mode { | ||
| 60 | SPEED_MODE_GEN1 = 0, | ||
| 61 | SPEED_MODE_GEN2 = 1, | ||
| 62 | SPEED_MODE_GEN3 = 2, | ||
| 63 | }; | ||
| 64 | |||
| 65 | static int hix5hd2_sata_phy_init(struct phy *phy) | ||
| 66 | { | ||
| 67 | struct hix5hd2_priv *priv = phy_get_drvdata(phy); | ||
| 68 | u32 val, data[2]; | ||
| 69 | int ret; | ||
| 70 | |||
| 71 | if (priv->peri_ctrl) { | ||
| 72 | ret = of_property_read_u32_array(phy->dev.of_node, | ||
| 73 | "hisilicon,power-reg", | ||
| 74 | &data[0], 2); | ||
| 75 | if (ret) { | ||
| 76 | dev_err(&phy->dev, "Fail read hisilicon,power-reg\n"); | ||
| 77 | return ret; | ||
| 78 | } | ||
| 79 | |||
| 80 | regmap_update_bits(priv->peri_ctrl, data[0], | ||
| 81 | BIT(data[1]), BIT(data[1])); | ||
| 82 | } | ||
| 83 | |||
| 84 | /* reset phy */ | ||
| 85 | val = readl_relaxed(priv->base + SATA_PHY0_CTLL); | ||
| 86 | val &= ~(MPLL_MULTIPLIER_MASK | REF_USE_PAD); | ||
| 87 | val |= MPLL_MULTIPLIER_50M << MPLL_MULTIPLIER_SHIFT | | ||
| 88 | REF_SSP_EN | PHY_RESET; | ||
| 89 | writel_relaxed(val, priv->base + SATA_PHY0_CTLL); | ||
| 90 | msleep(20); | ||
| 91 | val &= ~PHY_RESET; | ||
| 92 | writel_relaxed(val, priv->base + SATA_PHY0_CTLL); | ||
| 93 | |||
| 94 | val = readl_relaxed(priv->base + SATA_PORT_PHYCTL1); | ||
| 95 | val &= ~AMPLITUDE_MASK; | ||
| 96 | val |= AMPLITUDE_GEN3 << AMPLITUDE_GEN3_SHIFT | | ||
| 97 | AMPLITUDE_GEN2 << AMPLITUDE_GEN2_SHIFT | | ||
| 98 | AMPLITUDE_GEN1 << AMPLITUDE_GEN1_SHIFT; | ||
| 99 | writel_relaxed(val, priv->base + SATA_PORT_PHYCTL1); | ||
| 100 | |||
| 101 | val = readl_relaxed(priv->base + SATA_PORT_PHYCTL2); | ||
| 102 | val &= ~PREEMPH_MASK; | ||
| 103 | val |= PREEMPH_GEN3 << PREEMPH_GEN3_SHIFT | | ||
| 104 | PREEMPH_GEN2 << PREEMPH_GEN2_SHIFT | | ||
| 105 | PREEMPH_GEN1 << PREEMPH_GEN1_SHIFT; | ||
| 106 | writel_relaxed(val, priv->base + SATA_PORT_PHYCTL2); | ||
| 107 | |||
| 108 | /* ensure PHYCTRL setting takes effect */ | ||
| 109 | val = readl_relaxed(priv->base + SATA_PORT_PHYCTL); | ||
| 110 | val &= ~SPEED_MODE_MASK; | ||
| 111 | val |= SPEED_MODE_GEN1 << HALF_RATE_SHIFT | | ||
| 112 | SPEED_MODE_GEN1 << PHY_CONFIG_SHIFT | | ||
| 113 | SPEED_MODE_GEN1 << GEN2_EN_SHIFT | SPEED_CTRL; | ||
| 114 | writel_relaxed(val, priv->base + SATA_PORT_PHYCTL); | ||
| 115 | |||
| 116 | msleep(20); | ||
| 117 | val &= ~SPEED_MODE_MASK; | ||
| 118 | val |= SPEED_MODE_GEN3 << HALF_RATE_SHIFT | | ||
| 119 | SPEED_MODE_GEN3 << PHY_CONFIG_SHIFT | | ||
| 120 | SPEED_MODE_GEN3 << GEN2_EN_SHIFT | SPEED_CTRL; | ||
| 121 | writel_relaxed(val, priv->base + SATA_PORT_PHYCTL); | ||
| 122 | |||
| 123 | val &= ~(SPEED_MODE_MASK | SPEED_CTRL); | ||
| 124 | val |= SPEED_MODE_GEN2 << HALF_RATE_SHIFT | | ||
| 125 | SPEED_MODE_GEN2 << PHY_CONFIG_SHIFT | | ||
| 126 | SPEED_MODE_GEN2 << GEN2_EN_SHIFT; | ||
| 127 | writel_relaxed(val, priv->base + SATA_PORT_PHYCTL); | ||
| 128 | |||
| 129 | return 0; | ||
| 130 | } | ||
| 131 | |||
| 132 | static struct phy_ops hix5hd2_sata_phy_ops = { | ||
| 133 | .init = hix5hd2_sata_phy_init, | ||
| 134 | .owner = THIS_MODULE, | ||
| 135 | }; | ||
| 136 | |||
| 137 | static int hix5hd2_sata_phy_probe(struct platform_device *pdev) | ||
| 138 | { | ||
| 139 | struct phy_provider *phy_provider; | ||
| 140 | struct device *dev = &pdev->dev; | ||
| 141 | struct resource *res; | ||
| 142 | struct phy *phy; | ||
| 143 | struct hix5hd2_priv *priv; | ||
| 144 | |||
| 145 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 146 | if (!priv) | ||
| 147 | return -ENOMEM; | ||
| 148 | |||
| 149 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 150 | priv->base = devm_ioremap(dev, res->start, resource_size(res)); | ||
| 151 | if (!priv->base) | ||
| 152 | return -ENOMEM; | ||
| 153 | |||
| 154 | priv->peri_ctrl = syscon_regmap_lookup_by_phandle(dev->of_node, | ||
| 155 | "hisilicon,peripheral-syscon"); | ||
| 156 | if (IS_ERR(priv->peri_ctrl)) | ||
| 157 | priv->peri_ctrl = NULL; | ||
| 158 | |||
| 159 | phy = devm_phy_create(dev, NULL, &hix5hd2_sata_phy_ops, NULL); | ||
| 160 | if (IS_ERR(phy)) { | ||
| 161 | dev_err(dev, "failed to create PHY\n"); | ||
| 162 | return PTR_ERR(phy); | ||
| 163 | } | ||
| 164 | |||
| 165 | phy_set_drvdata(phy, priv); | ||
| 166 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
| 167 | if (IS_ERR(phy_provider)) | ||
| 168 | return PTR_ERR(phy_provider); | ||
| 169 | |||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | |||
| 173 | static const struct of_device_id hix5hd2_sata_phy_of_match[] = { | ||
| 174 | {.compatible = "hisilicon,hix5hd2-sata-phy",}, | ||
| 175 | { }, | ||
| 176 | }; | ||
| 177 | MODULE_DEVICE_TABLE(of, hix5hd2_sata_phy_of_match); | ||
| 178 | |||
| 179 | static struct platform_driver hix5hd2_sata_phy_driver = { | ||
| 180 | .probe = hix5hd2_sata_phy_probe, | ||
| 181 | .driver = { | ||
| 182 | .name = "hix5hd2-sata-phy", | ||
| 183 | .owner = THIS_MODULE, | ||
| 184 | .of_match_table = hix5hd2_sata_phy_of_match, | ||
| 185 | } | ||
| 186 | }; | ||
| 187 | module_platform_driver(hix5hd2_sata_phy_driver); | ||
| 188 | |||
| 189 | MODULE_AUTHOR("Jiancheng Xue <xuejiancheng@huawei.com>"); | ||
| 190 | MODULE_DESCRIPTION("HISILICON HIX5HD2 SATA PHY driver"); | ||
| 191 | MODULE_ALIAS("platform:hix5hd2-sata-phy"); | ||
| 192 | MODULE_LICENSE("GPL v2"); | ||
| @@ -0,0 +1,636 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2014 STMicroelectronics – All Rights Reserved | ||
| 3 | * | ||
| 4 | * STMicroelectronics PHY driver MiPHY365 (for SoC STiH416). | ||
| 5 | * | ||
| 6 | * Authors: Alexandre Torgue <alexandre.torgue@st.com> | ||
| 7 | * Lee Jones <lee.jones@linaro.org> | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License version 2, as | ||
| 11 | * published by the Free Software Foundation. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/platform_device.h> | ||
| 16 | #include <linux/io.h> | ||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/module.h> | ||
| 19 | #include <linux/of.h> | ||
| 20 | #include <linux/of_platform.h> | ||
| 21 | #include <linux/of_address.h> | ||
| 22 | #include <linux/clk.h> | ||
| 23 | #include <linux/phy/phy.h> | ||
| 24 | #include <linux/delay.h> | ||
| 25 | #include <linux/mfd/syscon.h> | ||
| 26 | #include <linux/regmap.h> | ||
| 27 | |||
| 28 | #include <dt-bindings/phy/phy-miphy365x.h> | ||
| 29 | |||
| 30 | #define HFC_TIMEOUT 100 | ||
| 31 | |||
| 32 | #define SYSCFG_SELECT_SATA_MASK BIT(1) | ||
| 33 | #define SYSCFG_SELECT_SATA_POS 1 | ||
| 34 | |||
| 35 | /* MiPHY365x register definitions */ | ||
| 36 | #define RESET_REG 0x00 | ||
| 37 | #define RST_PLL BIT(1) | ||
| 38 | #define RST_PLL_CAL BIT(2) | ||
| 39 | #define RST_RX BIT(4) | ||
| 40 | #define RST_MACRO BIT(7) | ||
| 41 | |||
| 42 | #define STATUS_REG 0x01 | ||
| 43 | #define IDLL_RDY BIT(0) | ||
| 44 | #define PLL_RDY BIT(1) | ||
| 45 | #define DES_BIT_LOCK BIT(2) | ||
| 46 | #define DES_SYMBOL_LOCK BIT(3) | ||
| 47 | |||
| 48 | #define CTRL_REG 0x02 | ||
| 49 | #define TERM_EN BIT(0) | ||
| 50 | #define PCI_EN BIT(2) | ||
| 51 | #define DES_BIT_LOCK_EN BIT(3) | ||
| 52 | #define TX_POL BIT(5) | ||
| 53 | |||
| 54 | #define INT_CTRL_REG 0x03 | ||
| 55 | |||
| 56 | #define BOUNDARY1_REG 0x10 | ||
| 57 | #define SPDSEL_SEL BIT(0) | ||
| 58 | |||
| 59 | #define BOUNDARY3_REG 0x12 | ||
| 60 | #define TX_SPDSEL_GEN1_VAL 0 | ||
| 61 | #define TX_SPDSEL_GEN2_VAL 0x01 | ||
| 62 | #define TX_SPDSEL_GEN3_VAL 0x02 | ||
| 63 | #define RX_SPDSEL_GEN1_VAL 0 | ||
| 64 | #define RX_SPDSEL_GEN2_VAL (0x01 << 3) | ||
| 65 | #define RX_SPDSEL_GEN3_VAL (0x02 << 3) | ||
| 66 | |||
| 67 | #define PCIE_REG 0x16 | ||
| 68 | |||
| 69 | #define BUF_SEL_REG 0x20 | ||
| 70 | #define CONF_GEN_SEL_GEN3 0x02 | ||
| 71 | #define CONF_GEN_SEL_GEN2 0x01 | ||
| 72 | #define PD_VDDTFILTER BIT(4) | ||
| 73 | |||
| 74 | #define TXBUF1_REG 0x21 | ||
| 75 | #define SWING_VAL 0x04 | ||
| 76 | #define SWING_VAL_GEN1 0x03 | ||
| 77 | #define PREEMPH_VAL (0x3 << 5) | ||
| 78 | |||
| 79 | #define TXBUF2_REG 0x22 | ||
| 80 | #define TXSLEW_VAL 0x2 | ||
| 81 | #define TXSLEW_VAL_GEN1 0x4 | ||
| 82 | |||
| 83 | #define RXBUF_OFFSET_CTRL_REG 0x23 | ||
| 84 | |||
| 85 | #define RXBUF_REG 0x25 | ||
| 86 | #define SDTHRES_VAL 0x01 | ||
| 87 | #define EQ_ON3 (0x03 << 4) | ||
| 88 | #define EQ_ON1 (0x01 << 4) | ||
| 89 | |||
| 90 | #define COMP_CTRL1_REG 0x40 | ||
| 91 | #define START_COMSR BIT(0) | ||
| 92 | #define START_COMZC BIT(1) | ||
| 93 | #define COMSR_DONE BIT(2) | ||
| 94 | #define COMZC_DONE BIT(3) | ||
| 95 | #define COMP_AUTO_LOAD BIT(4) | ||
| 96 | |||
| 97 | #define COMP_CTRL2_REG 0x41 | ||
| 98 | #define COMP_2MHZ_RAT_GEN1 0x1e | ||
| 99 | #define COMP_2MHZ_RAT 0xf | ||
| 100 | |||
| 101 | #define COMP_CTRL3_REG 0x42 | ||
| 102 | #define COMSR_COMP_REF 0x33 | ||
| 103 | |||
| 104 | #define COMP_IDLL_REG 0x47 | ||
| 105 | #define COMZC_IDLL 0x2a | ||
| 106 | |||
| 107 | #define PLL_CTRL1_REG 0x50 | ||
| 108 | #define PLL_START_CAL BIT(0) | ||
| 109 | #define BUF_EN BIT(2) | ||
| 110 | #define SYNCHRO_TX BIT(3) | ||
| 111 | #define SSC_EN BIT(6) | ||
| 112 | #define CONFIG_PLL BIT(7) | ||
| 113 | |||
| 114 | #define PLL_CTRL2_REG 0x51 | ||
| 115 | #define BYPASS_PLL_CAL BIT(1) | ||
| 116 | |||
| 117 | #define PLL_RAT_REG 0x52 | ||
| 118 | |||
| 119 | #define PLL_SSC_STEP_MSB_REG 0x56 | ||
| 120 | #define PLL_SSC_STEP_MSB_VAL 0x03 | ||
| 121 | |||
| 122 | #define PLL_SSC_STEP_LSB_REG 0x57 | ||
| 123 | #define PLL_SSC_STEP_LSB_VAL 0x63 | ||
| 124 | |||
| 125 | #define PLL_SSC_PER_MSB_REG 0x58 | ||
| 126 | #define PLL_SSC_PER_MSB_VAL 0 | ||
| 127 | |||
| 128 | #define PLL_SSC_PER_LSB_REG 0x59 | ||
| 129 | #define PLL_SSC_PER_LSB_VAL 0xf1 | ||
| 130 | |||
| 131 | #define IDLL_TEST_REG 0x72 | ||
| 132 | #define START_CLK_HF BIT(6) | ||
| 133 | |||
| 134 | #define DES_BITLOCK_REG 0x86 | ||
| 135 | #define BIT_LOCK_LEVEL 0x01 | ||
| 136 | #define BIT_LOCK_CNT_512 (0x03 << 5) | ||
| 137 | |||
| 138 | struct miphy365x_phy { | ||
| 139 | struct phy *phy; | ||
| 140 | void __iomem *base; | ||
| 141 | bool pcie_tx_pol_inv; | ||
| 142 | bool sata_tx_pol_inv; | ||
| 143 | u32 sata_gen; | ||
| 144 | u64 ctrlreg; | ||
| 145 | u8 type; | ||
| 146 | }; | ||
| 147 | |||
| 148 | struct miphy365x_dev { | ||
| 149 | struct device *dev; | ||
| 150 | struct regmap *regmap; | ||
| 151 | struct mutex miphy_mutex; | ||
| 152 | struct miphy365x_phy **phys; | ||
| 153 | }; | ||
| 154 | |||
| 155 | /* | ||
| 156 | * These values are represented in Device tree. They are considered to be ABI | ||
| 157 | * and although they can be extended any existing values must not change. | ||
| 158 | */ | ||
| 159 | enum miphy_sata_gen { | ||
| 160 | SATA_GEN1 = 1, | ||
| 161 | SATA_GEN2, | ||
| 162 | SATA_GEN3 | ||
| 163 | }; | ||
| 164 | |||
| 165 | static u8 rx_tx_spd[] = { | ||
| 166 | TX_SPDSEL_GEN1_VAL | RX_SPDSEL_GEN1_VAL, | ||
| 167 | TX_SPDSEL_GEN2_VAL | RX_SPDSEL_GEN2_VAL, | ||
| 168 | TX_SPDSEL_GEN3_VAL | RX_SPDSEL_GEN3_VAL | ||
| 169 | }; | ||
| 170 | |||
| 171 | /* | ||
| 172 | * This function selects the system configuration, | ||
| 173 | * either two SATA, one SATA and one PCIe, or two PCIe lanes. | ||
| 174 | */ | ||
| 175 | static int miphy365x_set_path(struct miphy365x_phy *miphy_phy, | ||
| 176 | struct miphy365x_dev *miphy_dev) | ||
| 177 | { | ||
| 178 | bool sata = (miphy_phy->type == MIPHY_TYPE_SATA); | ||
| 179 | |||
| 180 | return regmap_update_bits(miphy_dev->regmap, | ||
| 181 | (unsigned int)miphy_phy->ctrlreg, | ||
| 182 | SYSCFG_SELECT_SATA_MASK, | ||
| 183 | sata << SYSCFG_SELECT_SATA_POS); | ||
| 184 | } | ||
| 185 | |||
| 186 | static int miphy365x_init_pcie_port(struct miphy365x_phy *miphy_phy, | ||
| 187 | struct miphy365x_dev *miphy_dev) | ||
| 188 | { | ||
| 189 | u8 val; | ||
| 190 | |||
| 191 | if (miphy_phy->pcie_tx_pol_inv) { | ||
| 192 | /* Invert Tx polarity and clear pci_txdetect_pol bit */ | ||
| 193 | val = TERM_EN | PCI_EN | DES_BIT_LOCK_EN | TX_POL; | ||
| 194 | writeb_relaxed(val, miphy_phy->base + CTRL_REG); | ||
| 195 | writeb_relaxed(0x00, miphy_phy->base + PCIE_REG); | ||
| 196 | } | ||
| 197 | |||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | |||
| 201 | static inline int miphy365x_hfc_not_rdy(struct miphy365x_phy *miphy_phy, | ||
| 202 | struct miphy365x_dev *miphy_dev) | ||
| 203 | { | ||
| 204 | unsigned long timeout = jiffies + msecs_to_jiffies(HFC_TIMEOUT); | ||
| 205 | u8 mask = IDLL_RDY | PLL_RDY; | ||
| 206 | u8 regval; | ||
| 207 | |||
| 208 | do { | ||
| 209 | regval = readb_relaxed(miphy_phy->base + STATUS_REG); | ||
| 210 | if (!(regval & mask)) | ||
| 211 | return 0; | ||
| 212 | |||
| 213 | usleep_range(2000, 2500); | ||
| 214 | } while (time_before(jiffies, timeout)); | ||
| 215 | |||
| 216 | dev_err(miphy_dev->dev, "HFC ready timeout!\n"); | ||
| 217 | return -EBUSY; | ||
| 218 | } | ||
| 219 | |||
| 220 | static inline int miphy365x_rdy(struct miphy365x_phy *miphy_phy, | ||
| 221 | struct miphy365x_dev *miphy_dev) | ||
| 222 | { | ||
| 223 | unsigned long timeout = jiffies + msecs_to_jiffies(HFC_TIMEOUT); | ||
| 224 | u8 mask = IDLL_RDY | PLL_RDY; | ||
| 225 | u8 regval; | ||
| 226 | |||
| 227 | do { | ||
| 228 | regval = readb_relaxed(miphy_phy->base + STATUS_REG); | ||
| 229 | if ((regval & mask) == mask) | ||
| 230 | return 0; | ||
| 231 | |||
| 232 | usleep_range(2000, 2500); | ||
| 233 | } while (time_before(jiffies, timeout)); | ||
| 234 | |||
| 235 | dev_err(miphy_dev->dev, "PHY not ready timeout!\n"); | ||
| 236 | return -EBUSY; | ||
| 237 | } | ||
| 238 | |||
| 239 | static inline void miphy365x_set_comp(struct miphy365x_phy *miphy_phy, | ||
| 240 | struct miphy365x_dev *miphy_dev) | ||
| 241 | { | ||
| 242 | u8 val, mask; | ||
| 243 | |||
| 244 | if (miphy_phy->sata_gen == SATA_GEN1) | ||
| 245 | writeb_relaxed(COMP_2MHZ_RAT_GEN1, | ||
| 246 | miphy_phy->base + COMP_CTRL2_REG); | ||
| 247 | else | ||
| 248 | writeb_relaxed(COMP_2MHZ_RAT, | ||
| 249 | miphy_phy->base + COMP_CTRL2_REG); | ||
| 250 | |||
| 251 | if (miphy_phy->sata_gen != SATA_GEN3) { | ||
| 252 | writeb_relaxed(COMSR_COMP_REF, | ||
| 253 | miphy_phy->base + COMP_CTRL3_REG); | ||
| 254 | /* | ||
| 255 | * Force VCO current to value defined by address 0x5A | ||
| 256 | * and disable PCIe100Mref bit | ||
| 257 | * Enable auto load compensation for pll_i_bias | ||
| 258 | */ | ||
| 259 | writeb_relaxed(BYPASS_PLL_CAL, miphy_phy->base + PLL_CTRL2_REG); | ||
| 260 | writeb_relaxed(COMZC_IDLL, miphy_phy->base + COMP_IDLL_REG); | ||
| 261 | } | ||
| 262 | |||
| 263 | /* | ||
| 264 | * Force restart compensation and enable auto load | ||
| 265 | * for Comzc_Tx, Comzc_Rx and Comsr on macro | ||
| 266 | */ | ||
| 267 | val = START_COMSR | START_COMZC | COMP_AUTO_LOAD; | ||
| 268 | writeb_relaxed(val, miphy_phy->base + COMP_CTRL1_REG); | ||
| 269 | |||
| 270 | mask = COMSR_DONE | COMZC_DONE; | ||
| 271 | while ((readb_relaxed(miphy_phy->base + COMP_CTRL1_REG) & mask) != mask) | ||
| 272 | cpu_relax(); | ||
| 273 | } | ||
| 274 | |||
| 275 | static inline void miphy365x_set_ssc(struct miphy365x_phy *miphy_phy, | ||
| 276 | struct miphy365x_dev *miphy_dev) | ||
| 277 | { | ||
| 278 | u8 val; | ||
| 279 | |||
| 280 | /* | ||
| 281 | * SSC Settings. SSC will be enabled through Link | ||
| 282 | * SSC Ampl. = 0.4% | ||
| 283 | * SSC Freq = 31KHz | ||
| 284 | */ | ||
| 285 | writeb_relaxed(PLL_SSC_STEP_MSB_VAL, | ||
| 286 | miphy_phy->base + PLL_SSC_STEP_MSB_REG); | ||
| 287 | writeb_relaxed(PLL_SSC_STEP_LSB_VAL, | ||
| 288 | miphy_phy->base + PLL_SSC_STEP_LSB_REG); | ||
| 289 | writeb_relaxed(PLL_SSC_PER_MSB_VAL, | ||
| 290 | miphy_phy->base + PLL_SSC_PER_MSB_REG); | ||
| 291 | writeb_relaxed(PLL_SSC_PER_LSB_VAL, | ||
| 292 | miphy_phy->base + PLL_SSC_PER_LSB_REG); | ||
| 293 | |||
| 294 | /* SSC Settings complete */ | ||
| 295 | if (miphy_phy->sata_gen == SATA_GEN1) { | ||
| 296 | val = PLL_START_CAL | BUF_EN | SYNCHRO_TX | CONFIG_PLL; | ||
| 297 | writeb_relaxed(val, miphy_phy->base + PLL_CTRL1_REG); | ||
| 298 | } else { | ||
| 299 | val = SSC_EN | PLL_START_CAL | BUF_EN | SYNCHRO_TX | CONFIG_PLL; | ||
| 300 | writeb_relaxed(val, miphy_phy->base + PLL_CTRL1_REG); | ||
| 301 | } | ||
| 302 | } | ||
| 303 | |||
| 304 | static int miphy365x_init_sata_port(struct miphy365x_phy *miphy_phy, | ||
| 305 | struct miphy365x_dev *miphy_dev) | ||
| 306 | { | ||
| 307 | int ret; | ||
| 308 | u8 val; | ||
| 309 | |||
| 310 | /* | ||
| 311 | * Force PHY macro reset, PLL calibration reset, PLL reset | ||
| 312 | * and assert Deserializer Reset | ||
| 313 | */ | ||
| 314 | val = RST_PLL | RST_PLL_CAL | RST_RX | RST_MACRO; | ||
| 315 | writeb_relaxed(val, miphy_phy->base + RESET_REG); | ||
| 316 | |||
| 317 | if (miphy_phy->sata_tx_pol_inv) | ||
| 318 | writeb_relaxed(TX_POL, miphy_phy->base + CTRL_REG); | ||
| 319 | |||
| 320 | /* | ||
| 321 | * Force macro1 to use rx_lspd, tx_lspd | ||
| 322 | * Force Rx_Clock on first I-DLL phase | ||
| 323 | * Force Des in HP mode on macro, rx_lspd, tx_lspd for Gen2/3 | ||
| 324 | */ | ||
| 325 | writeb_relaxed(SPDSEL_SEL, miphy_phy->base + BOUNDARY1_REG); | ||
| 326 | writeb_relaxed(START_CLK_HF, miphy_phy->base + IDLL_TEST_REG); | ||
| 327 | val = rx_tx_spd[miphy_phy->sata_gen]; | ||
| 328 | writeb_relaxed(val, miphy_phy->base + BOUNDARY3_REG); | ||
| 329 | |||
| 330 | /* Wait for HFC_READY = 0 */ | ||
| 331 | ret = miphy365x_hfc_not_rdy(miphy_phy, miphy_dev); | ||
| 332 | if (ret) | ||
| 333 | return ret; | ||
| 334 | |||
| 335 | /* Compensation Recalibration */ | ||
| 336 | miphy365x_set_comp(miphy_phy, miphy_dev); | ||
| 337 | |||
| 338 | switch (miphy_phy->sata_gen) { | ||
| 339 | case SATA_GEN3: | ||
| 340 | /* | ||
| 341 | * TX Swing target 550-600mv peak to peak diff | ||
| 342 | * Tx Slew target 90-110ps rising/falling time | ||
| 343 | * Rx Eq ON3, Sigdet threshold SDTH1 | ||
| 344 | */ | ||
| 345 | val = PD_VDDTFILTER | CONF_GEN_SEL_GEN3; | ||
| 346 | writeb_relaxed(val, miphy_phy->base + BUF_SEL_REG); | ||
| 347 | val = SWING_VAL | PREEMPH_VAL; | ||
| 348 | writeb_relaxed(val, miphy_phy->base + TXBUF1_REG); | ||
| 349 | writeb_relaxed(TXSLEW_VAL, miphy_phy->base + TXBUF2_REG); | ||
| 350 | writeb_relaxed(0x00, miphy_phy->base + RXBUF_OFFSET_CTRL_REG); | ||
| 351 | val = SDTHRES_VAL | EQ_ON3; | ||
| 352 | writeb_relaxed(val, miphy_phy->base + RXBUF_REG); | ||
| 353 | break; | ||
| 354 | case SATA_GEN2: | ||
| 355 | /* | ||
| 356 | * conf gen sel=0x1 to program Gen2 banked registers | ||
| 357 | * VDDT filter ON | ||
| 358 | * Tx Swing target 550-600mV peak-to-peak diff | ||
| 359 | * Tx Slew target 90-110 ps rising/falling time | ||
| 360 | * RX Equalization ON1, Sigdet threshold SDTH1 | ||
| 361 | */ | ||
| 362 | writeb_relaxed(CONF_GEN_SEL_GEN2, | ||
| 363 | miphy_phy->base + BUF_SEL_REG); | ||
| 364 | writeb_relaxed(SWING_VAL, miphy_phy->base + TXBUF1_REG); | ||
| 365 | writeb_relaxed(TXSLEW_VAL, miphy_phy->base + TXBUF2_REG); | ||
| 366 | val = SDTHRES_VAL | EQ_ON1; | ||
| 367 | writeb_relaxed(val, miphy_phy->base + RXBUF_REG); | ||
| 368 | break; | ||
| 369 | case SATA_GEN1: | ||
| 370 | /* | ||
| 371 | * conf gen sel = 00b to program Gen1 banked registers | ||
| 372 | * VDDT filter ON | ||
| 373 | * Tx Swing target 500-550mV peak-to-peak diff | ||
| 374 | * Tx Slew target120-140 ps rising/falling time | ||
| 375 | */ | ||
| 376 | writeb_relaxed(PD_VDDTFILTER, miphy_phy->base + BUF_SEL_REG); | ||
| 377 | writeb_relaxed(SWING_VAL_GEN1, miphy_phy->base + TXBUF1_REG); | ||
| 378 | writeb_relaxed(TXSLEW_VAL_GEN1, miphy_phy->base + TXBUF2_REG); | ||
| 379 | break; | ||
| 380 | default: | ||
| 381 | break; | ||
| 382 | } | ||
| 383 | |||
| 384 | /* Force Macro1 in partial mode & release pll cal reset */ | ||
| 385 | writeb_relaxed(RST_RX, miphy_phy->base + RESET_REG); | ||
| 386 | usleep_range(100, 150); | ||
| 387 | |||
| 388 | miphy365x_set_ssc(miphy_phy, miphy_dev); | ||
| 389 | |||
| 390 | /* Wait for phy_ready */ | ||
| 391 | ret = miphy365x_rdy(miphy_phy, miphy_dev); | ||
| 392 | if (ret) | ||
| 393 | return ret; | ||
| 394 | |||
| 395 | /* | ||
| 396 | * Enable macro1 to use rx_lspd & tx_lspd | ||
| 397 | * Release Rx_Clock on first I-DLL phase on macro1 | ||
| 398 | * Assert deserializer reset | ||
| 399 | * des_bit_lock_en is set | ||
| 400 | * bit lock detection strength | ||
| 401 | * Deassert deserializer reset | ||
| 402 | */ | ||
| 403 | writeb_relaxed(0x00, miphy_phy->base + BOUNDARY1_REG); | ||
| 404 | writeb_relaxed(0x00, miphy_phy->base + IDLL_TEST_REG); | ||
| 405 | writeb_relaxed(RST_RX, miphy_phy->base + RESET_REG); | ||
| 406 | val = miphy_phy->sata_tx_pol_inv ? | ||
| 407 | (TX_POL | DES_BIT_LOCK_EN) : DES_BIT_LOCK_EN; | ||
| 408 | writeb_relaxed(val, miphy_phy->base + CTRL_REG); | ||
| 409 | |||
| 410 | val = BIT_LOCK_CNT_512 | BIT_LOCK_LEVEL; | ||
| 411 | writeb_relaxed(val, miphy_phy->base + DES_BITLOCK_REG); | ||
| 412 | writeb_relaxed(0x00, miphy_phy->base + RESET_REG); | ||
| 413 | |||
| 414 | return 0; | ||
| 415 | } | ||
| 416 | |||
| 417 | static int miphy365x_init(struct phy *phy) | ||
| 418 | { | ||
| 419 | struct miphy365x_phy *miphy_phy = phy_get_drvdata(phy); | ||
| 420 | struct miphy365x_dev *miphy_dev = dev_get_drvdata(phy->dev.parent); | ||
| 421 | int ret = 0; | ||
| 422 | |||
| 423 | mutex_lock(&miphy_dev->miphy_mutex); | ||
| 424 | |||
| 425 | ret = miphy365x_set_path(miphy_phy, miphy_dev); | ||
| 426 | if (ret) { | ||
| 427 | mutex_unlock(&miphy_dev->miphy_mutex); | ||
| 428 | return ret; | ||
| 429 | } | ||
| 430 | |||
| 431 | /* Initialise Miphy for PCIe or SATA */ | ||
| 432 | if (miphy_phy->type == MIPHY_TYPE_PCIE) | ||
| 433 | ret = miphy365x_init_pcie_port(miphy_phy, miphy_dev); | ||
| 434 | else | ||
| 435 | ret = miphy365x_init_sata_port(miphy_phy, miphy_dev); | ||
| 436 | |||
| 437 | mutex_unlock(&miphy_dev->miphy_mutex); | ||
| 438 | |||
| 439 | return ret; | ||
| 440 | } | ||
| 441 | |||
| 442 | int miphy365x_get_addr(struct device *dev, struct miphy365x_phy *miphy_phy, | ||
| 443 | int index) | ||
| 444 | { | ||
| 445 | struct device_node *phynode = miphy_phy->phy->dev.of_node; | ||
| 446 | const char *name; | ||
| 447 | const __be32 *taddr; | ||
| 448 | int type = miphy_phy->type; | ||
| 449 | int ret; | ||
| 450 | |||
| 451 | ret = of_property_read_string_index(phynode, "reg-names", index, &name); | ||
| 452 | if (ret) { | ||
| 453 | dev_err(dev, "no reg-names property not found\n"); | ||
| 454 | return ret; | ||
| 455 | } | ||
| 456 | |||
| 457 | if (!strncmp(name, "syscfg", 6)) { | ||
| 458 | taddr = of_get_address(phynode, index, NULL, NULL); | ||
| 459 | if (!taddr) { | ||
| 460 | dev_err(dev, "failed to fetch syscfg address\n"); | ||
| 461 | return -EINVAL; | ||
| 462 | } | ||
| 463 | |||
| 464 | miphy_phy->ctrlreg = of_translate_address(phynode, taddr); | ||
| 465 | if (miphy_phy->ctrlreg == OF_BAD_ADDR) { | ||
| 466 | dev_err(dev, "failed to translate syscfg address\n"); | ||
| 467 | return -EINVAL; | ||
| 468 | } | ||
| 469 | |||
| 470 | return 0; | ||
| 471 | } | ||
| 472 | |||
| 473 | if (!((!strncmp(name, "sata", 4) && type == MIPHY_TYPE_SATA) || | ||
| 474 | (!strncmp(name, "pcie", 4) && type == MIPHY_TYPE_PCIE))) | ||
| 475 | return 0; | ||
| 476 | |||
| 477 | miphy_phy->base = of_iomap(phynode, index); | ||
| 478 | if (!miphy_phy->base) { | ||
| 479 | dev_err(dev, "Failed to map %s\n", phynode->full_name); | ||
| 480 | return -EINVAL; | ||
| 481 | } | ||
| 482 | |||
| 483 | return 0; | ||
| 484 | } | ||
| 485 | |||
| 486 | static struct phy *miphy365x_xlate(struct device *dev, | ||
| 487 | struct of_phandle_args *args) | ||
| 488 | { | ||
| 489 | struct miphy365x_dev *miphy_dev = dev_get_drvdata(dev); | ||
| 490 | struct miphy365x_phy *miphy_phy = NULL; | ||
| 491 | struct device_node *phynode = args->np; | ||
| 492 | int ret, index; | ||
| 493 | |||
| 494 | if (!of_device_is_available(phynode)) { | ||
| 495 | dev_warn(dev, "Requested PHY is disabled\n"); | ||
| 496 | return ERR_PTR(-ENODEV); | ||
| 497 | } | ||
| 498 | |||
| 499 | if (args->args_count != 1) { | ||
| 500 | dev_err(dev, "Invalid number of cells in 'phy' property\n"); | ||
| 501 | return ERR_PTR(-EINVAL); | ||
| 502 | } | ||
| 503 | |||
| 504 | for (index = 0; index < of_get_child_count(dev->of_node); index++) | ||
| 505 | if (phynode == miphy_dev->phys[index]->phy->dev.of_node) { | ||
| 506 | miphy_phy = miphy_dev->phys[index]; | ||
| 507 | break; | ||
| 508 | } | ||
| 509 | |||
| 510 | if (!miphy_phy) { | ||
| 511 | dev_err(dev, "Failed to find appropriate phy\n"); | ||
| 512 | return ERR_PTR(-EINVAL); | ||
| 513 | } | ||
| 514 | |||
| 515 | miphy_phy->type = args->args[0]; | ||
| 516 | |||
| 517 | if (!(miphy_phy->type == MIPHY_TYPE_SATA || | ||
| 518 | miphy_phy->type == MIPHY_TYPE_PCIE)) { | ||
| 519 | dev_err(dev, "Unsupported device type: %d\n", miphy_phy->type); | ||
| 520 | return ERR_PTR(-EINVAL); | ||
| 521 | } | ||
| 522 | |||
| 523 | /* Each port handles SATA and PCIE - third entry is always sysconf. */ | ||
| 524 | for (index = 0; index < 3; index++) { | ||
| 525 | ret = miphy365x_get_addr(dev, miphy_phy, index); | ||
| 526 | if (ret < 0) | ||
| 527 | return ERR_PTR(ret); | ||
| 528 | } | ||
| 529 | |||
| 530 | return miphy_phy->phy; | ||
| 531 | } | ||
| 532 | |||
| 533 | static struct phy_ops miphy365x_ops = { | ||
| 534 | .init = miphy365x_init, | ||
| 535 | .owner = THIS_MODULE, | ||
| 536 | }; | ||
| 537 | |||
| 538 | static int miphy365x_of_probe(struct device_node *phynode, | ||
| 539 | struct miphy365x_phy *miphy_phy) | ||
| 540 | { | ||
| 541 | of_property_read_u32(phynode, "st,sata-gen", &miphy_phy->sata_gen); | ||
| 542 | if (!miphy_phy->sata_gen) | ||
| 543 | miphy_phy->sata_gen = SATA_GEN1; | ||
| 544 | |||
| 545 | miphy_phy->pcie_tx_pol_inv = | ||
| 546 | of_property_read_bool(phynode, "st,pcie-tx-pol-inv"); | ||
| 547 | |||
| 548 | miphy_phy->sata_tx_pol_inv = | ||
| 549 | of_property_read_bool(phynode, "st,sata-tx-pol-inv"); | ||
| 550 | |||
| 551 | return 0; | ||
| 552 | } | ||
| 553 | |||
| 554 | static int miphy365x_probe(struct platform_device *pdev) | ||
| 555 | { | ||
| 556 | struct device_node *child, *np = pdev->dev.of_node; | ||
| 557 | struct miphy365x_dev *miphy_dev; | ||
| 558 | struct phy_provider *provider; | ||
| 559 | struct phy *phy; | ||
| 560 | int chancount, port = 0; | ||
| 561 | int ret; | ||
| 562 | |||
| 563 | miphy_dev = devm_kzalloc(&pdev->dev, sizeof(*miphy_dev), GFP_KERNEL); | ||
| 564 | if (!miphy_dev) | ||
| 565 | return -ENOMEM; | ||
| 566 | |||
| 567 | chancount = of_get_child_count(np); | ||
| 568 | miphy_dev->phys = devm_kzalloc(&pdev->dev, sizeof(phy) * chancount, | ||
| 569 | GFP_KERNEL); | ||
| 570 | if (!miphy_dev->phys) | ||
| 571 | return -ENOMEM; | ||
| 572 | |||
| 573 | miphy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); | ||
| 574 | if (IS_ERR(miphy_dev->regmap)) { | ||
| 575 | dev_err(miphy_dev->dev, "No syscfg phandle specified\n"); | ||
| 576 | return PTR_ERR(miphy_dev->regmap); | ||
| 577 | } | ||
| 578 | |||
| 579 | miphy_dev->dev = &pdev->dev; | ||
| 580 | |||
| 581 | dev_set_drvdata(&pdev->dev, miphy_dev); | ||
| 582 | |||
| 583 | mutex_init(&miphy_dev->miphy_mutex); | ||
| 584 | |||
| 585 | for_each_child_of_node(np, child) { | ||
| 586 | struct miphy365x_phy *miphy_phy; | ||
| 587 | |||
| 588 | miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy), | ||
| 589 | GFP_KERNEL); | ||
| 590 | if (!miphy_phy) | ||
| 591 | return -ENOMEM; | ||
| 592 | |||
| 593 | miphy_dev->phys[port] = miphy_phy; | ||
| 594 | |||
| 595 | phy = devm_phy_create(&pdev->dev, child, &miphy365x_ops, NULL); | ||
| 596 | if (IS_ERR(phy)) { | ||
| 597 | dev_err(&pdev->dev, "failed to create PHY\n"); | ||
| 598 | return PTR_ERR(phy); | ||
| 599 | } | ||
| 600 | |||
| 601 | miphy_dev->phys[port]->phy = phy; | ||
| 602 | |||
| 603 | ret = miphy365x_of_probe(child, miphy_phy); | ||
| 604 | if (ret) | ||
| 605 | return ret; | ||
| 606 | |||
| 607 | phy_set_drvdata(phy, miphy_dev->phys[port]); | ||
| 608 | port++; | ||
| 609 | } | ||
| 610 | |||
| 611 | provider = devm_of_phy_provider_register(&pdev->dev, miphy365x_xlate); | ||
| 612 | if (IS_ERR(provider)) | ||
| 613 | return PTR_ERR(provider); | ||
| 614 | |||
| 615 | return 0; | ||
| 616 | } | ||
| 617 | |||
| 618 | static const struct of_device_id miphy365x_of_match[] = { | ||
| 619 | { .compatible = "st,miphy365x-phy", }, | ||
| 620 | { }, | ||
| 621 | }; | ||
| 622 | MODULE_DEVICE_TABLE(of, miphy365x_of_match); | ||
| 623 | |||
| 624 | static struct platform_driver miphy365x_driver = { | ||
| 625 | .probe = miphy365x_probe, | ||
| 626 | .driver = { | ||
| 627 | .name = "miphy365x-phy", | ||
| 628 | .owner = THIS_MODULE, | ||
| 629 | .of_match_table = miphy365x_of_match, | ||
| 630 | } | ||
| 631 | }; | ||
| 632 | module_platform_driver(miphy365x_driver); | ||
| 633 | |||
| 634 | MODULE_AUTHOR("Alexandre Torgue <alexandre.torgue@st.com>"); | ||
| 635 | MODULE_DESCRIPTION("STMicroelectronics miphy365x driver"); | ||
| 636 | MODULE_LICENSE("GPL v2"); | ||
| @@ -99,7 +99,7 @@ static int phy_mvebu_sata_probe(struct platform_device *pdev) · 98 unmodified lines | |||
| 99 | if (IS_ERR(priv->clk)) | 99 | if (IS_ERR(priv->clk)) |
| 100 | return PTR_ERR(priv->clk); | 100 | return PTR_ERR(priv->clk); |
| 101 | 101 | ||
| 102 | phy = devm_phy_create(&pdev->dev, &phy_mvebu_sata_ops, NULL); | 102 | phy = devm_phy_create(&pdev->dev, NULL, &phy_mvebu_sata_ops, NULL); |
| 103 | if (IS_ERR(phy)) | 103 | if (IS_ERR(phy)) |
| 104 | return PTR_ERR(phy); | 104 | return PTR_ERR(phy); |
| 105 | 105 | ||
| @@ -26,6 +26,41 @@ · 25 unmodified lines | |||
| 26 | #include <linux/clk.h> | 26 | #include <linux/clk.h> |
| 27 | #include <linux/phy/omap_control_phy.h> | 27 | #include <linux/phy/omap_control_phy.h> |
| 28 | 28 | ||
| 29 | /** | ||
| 30 | * omap_control_pcie_pcs - set the PCS delay count | ||
| 31 | * @dev: the control module device | ||
| 32 | * @id: index of the pcie PHY (should be 1 or 2) | ||
| 33 | * @delay: 8 bit delay value | ||
| 34 | */ | ||
| 35 | void omap_control_pcie_pcs(struct device *dev, u8 id, u8 delay) | ||
| 36 | { | ||
| 37 | u32 val; | ||
| 38 | struct omap_control_phy *control_phy; | ||
| 39 | |||
| 40 | if (IS_ERR(dev) || !dev) { | ||
| 41 | pr_err("%s: invalid device\n", __func__); | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | |||
| 45 | control_phy = dev_get_drvdata(dev); | ||
| 46 | if (!control_phy) { | ||
| 47 | dev_err(dev, "%s: invalid control phy device\n", __func__); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | |||
| 51 | if (control_phy->type != OMAP_CTRL_TYPE_PCIE) { | ||
| 52 | dev_err(dev, "%s: unsupported operation\n", __func__); | ||
| 53 | return; | ||
| 54 | } | ||
| 55 | |||
| 56 | val = readl(control_phy->pcie_pcs); | ||
| 57 | val &= ~(OMAP_CTRL_PCIE_PCS_MASK << | ||
| 58 | (id * OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT)); | ||
| 59 | val |= delay << (id * OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT); | ||
| 60 | writel(val, control_phy->pcie_pcs); | ||
| 61 | } | ||
| 62 | EXPORT_SYMBOL_GPL(omap_control_pcie_pcs); | ||
| 63 | |||
| 29 | /** | 64 | /** |
| 30 | * omap_control_phy_power - power on/off the phy using control module reg | 65 | * omap_control_phy_power - power on/off the phy using control module reg |
| 31 | * @dev: the control module device | 66 | * @dev: the control module device |
| @@ -61,6 +96,7 @@ void omap_control_phy_power(struct device *dev, int on) · 29 unmodified lines | |||
| 61 | val |= OMAP_CTRL_DEV_PHY_PD; | 96 | val |= OMAP_CTRL_DEV_PHY_PD; |
| 62 | break; | 97 | break; |
| 63 | 98 | ||
| 99 | case OMAP_CTRL_TYPE_PCIE: | ||
| 64 | case OMAP_CTRL_TYPE_PIPE3: | 100 | case OMAP_CTRL_TYPE_PIPE3: |
| 65 | rate = clk_get_rate(control_phy->sys_clk); | 101 | rate = clk_get_rate(control_phy->sys_clk); |
| 66 | rate = rate/1000000; | 102 | rate = rate/1000000; |
| @@ -211,6 +247,7 @@ EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); · 144 unmodified lines | |||
| 211 | static const enum omap_control_phy_type otghs_data = OMAP_CTRL_TYPE_OTGHS; | 247 | static const enum omap_control_phy_type otghs_data = OMAP_CTRL_TYPE_OTGHS; |
| 212 | static const enum omap_control_phy_type usb2_data = OMAP_CTRL_TYPE_USB2; | 248 | static const enum omap_control_phy_type usb2_data = OMAP_CTRL_TYPE_USB2; |
| 213 | static const enum omap_control_phy_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; | 249 | static const enum omap_control_phy_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; |
| 250 | static const enum omap_control_phy_type pcie_data = OMAP_CTRL_TYPE_PCIE; | ||
| 214 | static const enum omap_control_phy_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; | 251 | static const enum omap_control_phy_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; |
| 215 | static const enum omap_control_phy_type am437usb2_data = OMAP_CTRL_TYPE_AM437USB2; | 252 | static const enum omap_control_phy_type am437usb2_data = OMAP_CTRL_TYPE_AM437USB2; |
| 216 | 253 | ||
| @@ -227,6 +264,10 @@ static const struct of_device_id omap_control_phy_id_table[] = { · 10 unmodified lines | |||
| 227 | .compatible = "ti,control-phy-pipe3", | 264 | .compatible = "ti,control-phy-pipe3", |
| 228 | .data = &pipe3_data, | 265 | .data = &pipe3_data, |
| 229 | }, | 266 | }, |
| 267 | { | ||
| 268 | .compatible = "ti,control-phy-pcie", | ||
| 269 | .data = &pcie_data, | ||
| 270 | }, | ||
| 230 | { | 271 | { |
| 231 | .compatible = "ti,control-phy-usb2-dra7", | 272 | .compatible = "ti,control-phy-usb2-dra7", |
| 232 | .data = &dra7usb2_data, | 273 | .data = &dra7usb2_data, |
| @@ -279,7 +320,8 @@ static int omap_control_phy_probe(struct platform_device *pdev) · 46 unmodified lines | |||
| 279 | } | 320 | } |
| 280 | } | 321 | } |
| 281 | 322 | ||
| 282 | if (control_phy->type == OMAP_CTRL_TYPE_PIPE3) { | 323 | if (control_phy->type == OMAP_CTRL_TYPE_PIPE3 || |
| 324 | control_phy->type == OMAP_CTRL_TYPE_PCIE) { | ||
| 283 | control_phy->sys_clk = devm_clk_get(control_phy->dev, | 325 | control_phy->sys_clk = devm_clk_get(control_phy->dev, |
| 284 | "sys_clkin"); | 326 | "sys_clkin"); |
| 285 | if (IS_ERR(control_phy->sys_clk)) { | 327 | if (IS_ERR(control_phy->sys_clk)) { |
| @@ -288,6 +330,14 @@ static int omap_control_phy_probe(struct platform_device *pdev) · 2 unmodified lines | |||
| 288 | } | 330 | } |
| 289 | } | 331 | } |
| 290 | 332 | ||
| 333 | if (control_phy->type == OMAP_CTRL_TYPE_PCIE) { | ||
| 334 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | ||
| 335 | "pcie_pcs"); | ||
| 336 | control_phy->pcie_pcs = devm_ioremap_resource(&pdev->dev, res); | ||
| 337 | if (IS_ERR(control_phy->pcie_pcs)) | ||
| 338 | return PTR_ERR(control_phy->pcie_pcs); | ||
| 339 | } | ||
| 340 | |||
| 291 | dev_set_drvdata(control_phy->dev, control_phy); | 341 | dev_set_drvdata(control_phy->dev, control_phy); |
| 292 | 342 | ||
| 293 | return 0; | 343 | return 0; |
| @@ -263,7 +263,7 @@ static int omap_usb2_probe(struct platform_device *pdev) · 262 unmodified lines | |||
| 263 | 263 | ||
| 264 | platform_set_drvdata(pdev, phy); | 264 | platform_set_drvdata(pdev, phy); |
| 265 | 265 | ||
| 266 | generic_phy = devm_phy_create(phy->dev, &ops, NULL); | 266 | generic_phy = devm_phy_create(phy->dev, NULL, &ops, NULL); |
| 267 | if (IS_ERR(generic_phy)) | 267 | if (IS_ERR(generic_phy)) |
| 268 | return PTR_ERR(generic_phy); | 268 | return PTR_ERR(generic_phy); |
| 269 | 269 | ||
| @@ -0,0 +1,289 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License version 2 and | ||
| 6 | * only version 2 as published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/io.h> | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/of.h> | ||
| 18 | #include <linux/time.h> | ||
| 19 | #include <linux/delay.h> | ||
| 20 | #include <linux/clk.h> | ||
| 21 | #include <linux/slab.h> | ||
| 22 | #include <linux/platform_device.h> | ||
| 23 | #include <linux/phy/phy.h> | ||
| 24 | |||
| 25 | /* PHY registers */ | ||
| 26 | #define UNIPHY_PLL_REFCLK_CFG 0x000 | ||
| 27 | #define UNIPHY_PLL_PWRGEN_CFG 0x014 | ||
| 28 | #define UNIPHY_PLL_GLB_CFG 0x020 | ||
| 29 | #define UNIPHY_PLL_SDM_CFG0 0x038 | ||
| 30 | #define UNIPHY_PLL_SDM_CFG1 0x03C | ||
| 31 | #define UNIPHY_PLL_SDM_CFG2 0x040 | ||
| 32 | #define UNIPHY_PLL_SDM_CFG3 0x044 | ||
| 33 | #define UNIPHY_PLL_SDM_CFG4 0x048 | ||
| 34 | #define UNIPHY_PLL_SSC_CFG0 0x04C | ||
| 35 | #define UNIPHY_PLL_SSC_CFG1 0x050 | ||
| 36 | #define UNIPHY_PLL_SSC_CFG2 0x054 | ||
| 37 | #define UNIPHY_PLL_SSC_CFG3 0x058 | ||
| 38 | #define UNIPHY_PLL_LKDET_CFG0 0x05C | ||
| 39 | #define UNIPHY_PLL_LKDET_CFG1 0x060 | ||
| 40 | #define UNIPHY_PLL_LKDET_CFG2 0x064 | ||
| 41 | #define UNIPHY_PLL_CAL_CFG0 0x06C | ||
| 42 | #define UNIPHY_PLL_CAL_CFG8 0x08C | ||
| 43 | #define UNIPHY_PLL_CAL_CFG9 0x090 | ||
| 44 | #define UNIPHY_PLL_CAL_CFG10 0x094 | ||
| 45 | #define UNIPHY_PLL_CAL_CFG11 0x098 | ||
| 46 | #define UNIPHY_PLL_STATUS 0x0C0 | ||
| 47 | |||
| 48 | #define SATA_PHY_SER_CTRL 0x100 | ||
| 49 | #define SATA_PHY_TX_DRIV_CTRL0 0x104 | ||
| 50 | #define SATA_PHY_TX_DRIV_CTRL1 0x108 | ||
| 51 | #define SATA_PHY_TX_IMCAL0 0x11C | ||
| 52 | #define SATA_PHY_TX_IMCAL2 0x124 | ||
| 53 | #define SATA_PHY_RX_IMCAL0 0x128 | ||
| 54 | #define SATA_PHY_EQUAL 0x13C | ||
| 55 | #define SATA_PHY_OOB_TERM 0x144 | ||
| 56 | #define SATA_PHY_CDR_CTRL0 0x148 | ||
| 57 | #define SATA_PHY_CDR_CTRL1 0x14C | ||
| 58 | #define SATA_PHY_CDR_CTRL2 0x150 | ||
| 59 | #define SATA_PHY_CDR_CTRL3 0x154 | ||
| 60 | #define SATA_PHY_PI_CTRL0 0x168 | ||
| 61 | #define SATA_PHY_POW_DWN_CTRL0 0x180 | ||
| 62 | #define SATA_PHY_POW_DWN_CTRL1 0x184 | ||
| 63 | #define SATA_PHY_TX_DATA_CTRL 0x188 | ||
| 64 | #define SATA_PHY_ALIGNP 0x1A4 | ||
| 65 | #define SATA_PHY_TX_IMCAL_STAT 0x1E4 | ||
| 66 | #define SATA_PHY_RX_IMCAL_STAT 0x1E8 | ||
| 67 | |||
| 68 | #define UNIPHY_PLL_LOCK BIT(0) | ||
| 69 | #define SATA_PHY_TX_CAL BIT(0) | ||
| 70 | #define SATA_PHY_RX_CAL BIT(0) | ||
| 71 | |||
| 72 | /* default timeout set to 1 sec */ | ||
| 73 | #define TIMEOUT_MS 10000 | ||
| 74 | #define DELAY_INTERVAL_US 100 | ||
| 75 | |||
| 76 | struct qcom_apq8064_sata_phy { | ||
| 77 | void __iomem *mmio; | ||
| 78 | struct clk *cfg_clk; | ||
| 79 | struct device *dev; | ||
| 80 | }; | ||
| 81 | |||
| 82 | /* Helper function to do poll and timeout */ | ||
| 83 | static int read_poll_timeout(void __iomem *addr, u32 mask) | ||
| 84 | { | ||
| 85 | unsigned long timeout = jiffies + msecs_to_jiffies(TIMEOUT_MS); | ||
| 86 | |||
| 87 | do { | ||
| 88 | if (readl_relaxed(addr) & mask) | ||
| 89 | return 0; | ||
| 90 | |||
| 91 | usleep_range(DELAY_INTERVAL_US, DELAY_INTERVAL_US + 50); | ||
| 92 | } while (!time_after(jiffies, timeout)); | ||
| 93 | |||
| 94 | return (readl_relaxed(addr) & mask) ? 0 : -ETIMEDOUT; | ||
| 95 | } | ||
| 96 | |||
| 97 | static int qcom_apq8064_sata_phy_init(struct phy *generic_phy) | ||
| 98 | { | ||
| 99 | struct qcom_apq8064_sata_phy *phy = phy_get_drvdata(generic_phy); | ||
| 100 | void __iomem *base = phy->mmio; | ||
| 101 | int ret = 0; | ||
| 102 | |||
| 103 | /* SATA phy initialization */ | ||
| 104 | writel_relaxed(0x01, base + SATA_PHY_SER_CTRL); | ||
| 105 | writel_relaxed(0xB1, base + SATA_PHY_POW_DWN_CTRL0); | ||
| 106 | /* Make sure the power down happens before power up */ | ||
| 107 | mb(); | ||
| 108 | usleep_range(10, 60); | ||
| 109 | |||
| 110 | writel_relaxed(0x01, base + SATA_PHY_POW_DWN_CTRL0); | ||
| 111 | writel_relaxed(0x3E, base + SATA_PHY_POW_DWN_CTRL1); | ||
| 112 | writel_relaxed(0x01, base + SATA_PHY_RX_IMCAL0); | ||
| 113 | writel_relaxed(0x01, base + SATA_PHY_TX_IMCAL0); | ||
| 114 | writel_relaxed(0x02, base + SATA_PHY_TX_IMCAL2); | ||
| 115 | |||
| 116 | /* Write UNIPHYPLL registers to configure PLL */ | ||
| 117 | writel_relaxed(0x04, base + UNIPHY_PLL_REFCLK_CFG); | ||
| 118 | writel_relaxed(0x00, base + UNIPHY_PLL_PWRGEN_CFG); | ||
| 119 | |||
| 120 | writel_relaxed(0x0A, base + UNIPHY_PLL_CAL_CFG0); | ||
| 121 | writel_relaxed(0xF3, base + UNIPHY_PLL_CAL_CFG8); | ||
| 122 | writel_relaxed(0x01, base + UNIPHY_PLL_CAL_CFG9); | ||
| 123 | writel_relaxed(0xED, base + UNIPHY_PLL_CAL_CFG10); | ||
| 124 | writel_relaxed(0x02, base + UNIPHY_PLL_CAL_CFG11); | ||
| 125 | |||
| 126 | writel_relaxed(0x36, base + UNIPHY_PLL_SDM_CFG0); | ||
| 127 | writel_relaxed(0x0D, base + UNIPHY_PLL_SDM_CFG1); | ||
| 128 | writel_relaxed(0xA3, base + UNIPHY_PLL_SDM_CFG2); | ||
| 129 | writel_relaxed(0xF0, base + UNIPHY_PLL_SDM_CFG3); | ||
| 130 | writel_relaxed(0x00, base + UNIPHY_PLL_SDM_CFG4); | ||
| 131 | |||
| 132 | writel_relaxed(0x19, base + UNIPHY_PLL_SSC_CFG0); | ||
| 133 | writel_relaxed(0xE1, base + UNIPHY_PLL_SSC_CFG1); | ||
| 134 | writel_relaxed(0x00, base + UNIPHY_PLL_SSC_CFG2); | ||
| 135 | writel_relaxed(0x11, base + UNIPHY_PLL_SSC_CFG3); | ||
| 136 | |||
| 137 | writel_relaxed(0x04, base + UNIPHY_PLL_LKDET_CFG0); | ||
| 138 | writel_relaxed(0xFF, base + UNIPHY_PLL_LKDET_CFG1); | ||
| 139 | |||
| 140 | writel_relaxed(0x02, base + UNIPHY_PLL_GLB_CFG); | ||
| 141 | /* make sure global config LDO power down happens before power up */ | ||
| 142 | mb(); | ||
| 143 | |||
| 144 | writel_relaxed(0x03, base + UNIPHY_PLL_GLB_CFG); | ||
| 145 | writel_relaxed(0x05, base + UNIPHY_PLL_LKDET_CFG2); | ||
| 146 | |||
| 147 | /* PLL Lock wait */ | ||
| 148 | ret = read_poll_timeout(base + UNIPHY_PLL_STATUS, UNIPHY_PLL_LOCK); | ||
| 149 | if (ret) { | ||
| 150 | dev_err(phy->dev, "poll timeout UNIPHY_PLL_STATUS\n"); | ||
| 151 | return ret; | ||
| 152 | } | ||
| 153 | |||
| 154 | /* TX Calibration */ | ||
| 155 | ret = read_poll_timeout(base + SATA_PHY_TX_IMCAL_STAT, SATA_PHY_TX_CAL); | ||
| 156 | if (ret) { | ||
| 157 | dev_err(phy->dev, "poll timeout SATA_PHY_TX_IMCAL_STAT\n"); | ||
| 158 | return ret; | ||
| 159 | } | ||
| 160 | |||
| 161 | /* RX Calibration */ | ||
| 162 | ret = read_poll_timeout(base + SATA_PHY_RX_IMCAL_STAT, SATA_PHY_RX_CAL); | ||
| 163 | if (ret) { | ||
| 164 | dev_err(phy->dev, "poll timeout SATA_PHY_RX_IMCAL_STAT\n"); | ||
| 165 | return ret; | ||
| 166 | } | ||
| 167 | |||
| 168 | /* SATA phy calibrated succesfully, power up to functional mode */ | ||
| 169 | writel_relaxed(0x3E, base + SATA_PHY_POW_DWN_CTRL1); | ||
| 170 | writel_relaxed(0x01, base + SATA_PHY_RX_IMCAL0); | ||
| 171 | writel_relaxed(0x01, base + SATA_PHY_TX_IMCAL0); | ||
| 172 | |||
| 173 | writel_relaxed(0x00, base + SATA_PHY_POW_DWN_CTRL1); | ||
| 174 | writel_relaxed(0x59, base + SATA_PHY_CDR_CTRL0); | ||
| 175 | writel_relaxed(0x04, base + SATA_PHY_CDR_CTRL1); | ||
| 176 | writel_relaxed(0x00, base + SATA_PHY_CDR_CTRL2); | ||
| 177 | writel_relaxed(0x00, base + SATA_PHY_PI_CTRL0); | ||
| 178 | writel_relaxed(0x00, base + SATA_PHY_CDR_CTRL3); | ||
| 179 | writel_relaxed(0x01, base + SATA_PHY_POW_DWN_CTRL0); | ||
| 180 | |||
| 181 | writel_relaxed(0x11, base + SATA_PHY_TX_DATA_CTRL); | ||
| 182 | writel_relaxed(0x43, base + SATA_PHY_ALIGNP); | ||
| 183 | writel_relaxed(0x04, base + SATA_PHY_OOB_TERM); | ||
| 184 | |||
| 185 | writel_relaxed(0x01, base + SATA_PHY_EQUAL); | ||
| 186 | writel_relaxed(0x09, base + SATA_PHY_TX_DRIV_CTRL0); | ||
| 187 | writel_relaxed(0x09, base + SATA_PHY_TX_DRIV_CTRL1); | ||
| 188 | |||
| 189 | return 0; | ||
| 190 | } | ||
| 191 | |||
| 192 | static int qcom_apq8064_sata_phy_exit(struct phy *generic_phy) | ||
| 193 | { | ||
| 194 | struct qcom_apq8064_sata_phy *phy = phy_get_drvdata(generic_phy); | ||
| 195 | void __iomem *base = phy->mmio; | ||
| 196 | |||
| 197 | /* Power down PHY */ | ||
| 198 | writel_relaxed(0xF8, base + SATA_PHY_POW_DWN_CTRL0); | ||
| 199 | writel_relaxed(0xFE, base + SATA_PHY_POW_DWN_CTRL1); | ||
| 200 | |||
| 201 | /* Power down PLL block */ | ||
| 202 | writel_relaxed(0x00, base + UNIPHY_PLL_GLB_CFG); | ||
| 203 | |||
| 204 | return 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | static struct phy_ops qcom_apq8064_sata_phy_ops = { | ||
| 208 | .init = qcom_apq8064_sata_phy_init, | ||
| 209 | .exit = qcom_apq8064_sata_phy_exit, | ||
| 210 | .owner = THIS_MODULE, | ||
| 211 | }; | ||
| 212 | |||
| 213 | static int qcom_apq8064_sata_phy_probe(struct platform_device *pdev) | ||
| 214 | { | ||
| 215 | struct qcom_apq8064_sata_phy *phy; | ||
| 216 | struct device *dev = &pdev->dev; | ||
| 217 | struct resource *res; | ||
| 218 | struct phy_provider *phy_provider; | ||
| 219 | struct phy *generic_phy; | ||
| 220 | int ret; | ||
| 221 | |||
| 222 | phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); | ||
| 223 | if (!phy) | ||
| 224 | return -ENOMEM; | ||
| 225 | |||
| 226 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 227 | phy->mmio = devm_ioremap_resource(dev, res); | ||
| 228 | if (IS_ERR(phy->mmio)) | ||
| 229 | return PTR_ERR(phy->mmio); | ||
| 230 | |||
| 231 | generic_phy = devm_phy_create(dev, NULL, &qcom_apq8064_sata_phy_ops, | ||
| 232 | NULL); | ||
| 233 | if (IS_ERR(generic_phy)) { | ||
| 234 | dev_err(dev, "%s: failed to create phy\n", __func__); | ||
| 235 | return PTR_ERR(generic_phy); | ||
| 236 | } | ||
| 237 | |||
| 238 | phy->dev = dev; | ||
| 239 | phy_set_drvdata(generic_phy, phy); | ||
| 240 | platform_set_drvdata(pdev, phy); | ||
| 241 | |||
| 242 | phy->cfg_clk = devm_clk_get(dev, "cfg"); | ||
| 243 | if (IS_ERR(phy->cfg_clk)) { | ||
| 244 | dev_err(dev, "Failed to get sata cfg clock\n"); | ||
| 245 | return PTR_ERR(phy->cfg_clk); | ||
| 246 | } | ||
| 247 | |||
| 248 | ret = clk_prepare_enable(phy->cfg_clk); | ||
| 249 | if (ret) | ||
| 250 | return ret; | ||
| 251 | |||
| 252 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
| 253 | if (IS_ERR(phy_provider)) { | ||
| 254 | clk_disable_unprepare(phy->cfg_clk); | ||
| 255 | dev_err(dev, "%s: failed to register phy\n", __func__); | ||
| 256 | return PTR_ERR(phy_provider); | ||
| 257 | } | ||
| 258 | |||
| 259 | return 0; | ||
| 260 | } | ||
| 261 | |||
| 262 | static int qcom_apq8064_sata_phy_remove(struct platform_device *pdev) | ||
| 263 | { | ||
| 264 | struct qcom_apq8064_sata_phy *phy = platform_get_drvdata(pdev); | ||
| 265 | |||
| 266 | clk_disable_unprepare(phy->cfg_clk); | ||
| 267 | |||
| 268 | return 0; | ||
| 269 | } | ||
| 270 | |||
| 271 | static const struct of_device_id qcom_apq8064_sata_phy_of_match[] = { | ||
| 272 | { .compatible = "qcom,apq8064-sata-phy" }, | ||
| 273 | { }, | ||
| 274 | }; | ||
| 275 | MODULE_DEVICE_TABLE(of, qcom_apq8064_sata_phy_of_match); | ||
| 276 | |||
| 277 | static struct platform_driver qcom_apq8064_sata_phy_driver = { | ||
| 278 | .probe = qcom_apq8064_sata_phy_probe, | ||
| 279 | .remove = qcom_apq8064_sata_phy_remove, | ||
| 280 | .driver = { | ||
| 281 | .name = "qcom-apq8064-sata-phy", | ||
| 282 | .owner = THIS_MODULE, | ||
| 283 | .of_match_table = qcom_apq8064_sata_phy_of_match, | ||
| 284 | } | ||
| 285 | }; | ||
| 286 | module_platform_driver(qcom_apq8064_sata_phy_driver); | ||
| 287 | |||
| 288 | MODULE_DESCRIPTION("QCOM apq8064 SATA PHY driver"); | ||
| 289 | MODULE_LICENSE("GPL v2"); | ||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License version 2 and | ||
| 6 | * only version 2 as published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/io.h> | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/of.h> | ||
| 18 | #include <linux/of_address.h> | ||
| 19 | #include <linux/time.h> | ||
| 20 | #include <linux/delay.h> | ||
| 21 | #include <linux/clk.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | #include <linux/platform_device.h> | ||
| 24 | #include <linux/phy/phy.h> | ||
| 25 | |||
| 26 | struct qcom_ipq806x_sata_phy { | ||
| 27 | void __iomem *mmio; | ||
| 28 | struct clk *cfg_clk; | ||
| 29 | struct device *dev; | ||
| 30 | }; | ||
| 31 | |||
| 32 | #define __set(v, a, b) (((v) << (b)) & GENMASK(a, b)) | ||
| 33 | |||
| 34 | #define SATA_PHY_P0_PARAM0 0x200 | ||
| 35 | #define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3(x) __set(x, 17, 12) | ||
| 36 | #define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3_MASK GENMASK(17, 12) | ||
| 37 | #define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN2(x) __set(x, 11, 6) | ||
| 38 | #define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN2_MASK GENMASK(11, 6) | ||
| 39 | #define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN1(x) __set(x, 5, 0) | ||
| 40 | #define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN1_MASK GENMASK(5, 0) | ||
| 41 | |||
| 42 | #define SATA_PHY_P0_PARAM1 0x204 | ||
| 43 | #define SATA_PHY_P0_PARAM1_RESERVED_BITS31_21(x) __set(x, 31, 21) | ||
| 44 | #define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3(x) __set(x, 20, 14) | ||
| 45 | #define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3_MASK GENMASK(20, 14) | ||
| 46 | #define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2(x) __set(x, 13, 7) | ||
| 47 | #define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2_MASK GENMASK(13, 7) | ||
| 48 | #define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1(x) __set(x, 6, 0) | ||
| 49 | #define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1_MASK GENMASK(6, 0) | ||
| 50 | |||
| 51 | #define SATA_PHY_P0_PARAM2 0x208 | ||
| 52 | #define SATA_PHY_P0_PARAM2_RX_EQ(x) __set(x, 20, 18) | ||
| 53 | #define SATA_PHY_P0_PARAM2_RX_EQ_MASK GENMASK(20, 18) | ||
| 54 | |||
| 55 | #define SATA_PHY_P0_PARAM3 0x20C | ||
| 56 | #define SATA_PHY_SSC_EN 0x8 | ||
| 57 | #define SATA_PHY_P0_PARAM4 0x210 | ||
| 58 | #define SATA_PHY_REF_SSP_EN 0x2 | ||
| 59 | #define SATA_PHY_RESET 0x1 | ||
| 60 | |||
| 61 | static int qcom_ipq806x_sata_phy_init(struct phy *generic_phy) | ||
| 62 | { | ||
| 63 | struct qcom_ipq806x_sata_phy *phy = phy_get_drvdata(generic_phy); | ||
| 64 | u32 reg; | ||
| 65 | |||
| 66 | /* Setting SSC_EN to 1 */ | ||
| 67 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM3); | ||
| 68 | reg = reg | SATA_PHY_SSC_EN; | ||
| 69 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM3); | ||
| 70 | |||
| 71 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM0) & | ||
| 72 | ~(SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3_MASK | | ||
| 73 | SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN2_MASK | | ||
| 74 | SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN1_MASK); | ||
| 75 | reg |= SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3(0xf); | ||
| 76 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM0); | ||
| 77 | |||
| 78 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM1) & | ||
| 79 | ~(SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3_MASK | | ||
| 80 | SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2_MASK | | ||
| 81 | SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1_MASK); | ||
| 82 | reg |= SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3(0x55) | | ||
| 83 | SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2(0x55) | | ||
| 84 | SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1(0x55); | ||
| 85 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM1); | ||
| 86 | |||
| 87 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM2) & | ||
| 88 | ~SATA_PHY_P0_PARAM2_RX_EQ_MASK; | ||
| 89 | reg |= SATA_PHY_P0_PARAM2_RX_EQ(0x3); | ||
| 90 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM2); | ||
| 91 | |||
| 92 | /* Setting PHY_RESET to 1 */ | ||
| 93 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 94 | reg = reg | SATA_PHY_RESET; | ||
| 95 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 96 | |||
| 97 | /* Setting REF_SSP_EN to 1 */ | ||
| 98 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 99 | reg = reg | SATA_PHY_REF_SSP_EN | SATA_PHY_RESET; | ||
| 100 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 101 | |||
| 102 | /* make sure all changes complete before we let the PHY out of reset */ | ||
| 103 | mb(); | ||
| 104 | |||
| 105 | /* sleep for max. 50us more to combine processor wakeups */ | ||
| 106 | usleep_range(20, 20 + 50); | ||
| 107 | |||
| 108 | /* Clearing PHY_RESET to 0 */ | ||
| 109 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 110 | reg = reg & ~SATA_PHY_RESET; | ||
| 111 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 112 | |||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | static int qcom_ipq806x_sata_phy_exit(struct phy *generic_phy) | ||
| 117 | { | ||
| 118 | struct qcom_ipq806x_sata_phy *phy = phy_get_drvdata(generic_phy); | ||
| 119 | u32 reg; | ||
| 120 | |||
| 121 | /* Setting PHY_RESET to 1 */ | ||
| 122 | reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 123 | reg = reg | SATA_PHY_RESET; | ||
| 124 | writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4); | ||
| 125 | |||
| 126 | return 0; | ||
| 127 | } | ||
| 128 | |||
| 129 | static struct phy_ops qcom_ipq806x_sata_phy_ops = { | ||
| 130 | .init = qcom_ipq806x_sata_phy_init, | ||
| 131 | .exit = qcom_ipq806x_sata_phy_exit, | ||
| 132 | .owner = THIS_MODULE, | ||
| 133 | }; | ||
| 134 | |||
| 135 | static int qcom_ipq806x_sata_phy_probe(struct platform_device *pdev) | ||
| 136 | { | ||
| 137 | struct qcom_ipq806x_sata_phy *phy; | ||
| 138 | struct device *dev = &pdev->dev; | ||
| 139 | struct resource *res; | ||
| 140 | struct phy_provider *phy_provider; | ||
| 141 | struct phy *generic_phy; | ||
| 142 | int ret; | ||
| 143 | |||
| 144 | phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); | ||
| 145 | if (!phy) | ||
| 146 | return -ENOMEM; | ||
| 147 | |||
| 148 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 149 | phy->mmio = devm_ioremap_resource(dev, res); | ||
| 150 | if (IS_ERR(phy->mmio)) | ||
| 151 | return PTR_ERR(phy->mmio); | ||
| 152 | |||
| 153 | generic_phy = devm_phy_create(dev, NULL, &qcom_ipq806x_sata_phy_ops, | ||
| 154 | NULL); | ||
| 155 | if (IS_ERR(generic_phy)) { | ||
| 156 | dev_err(dev, "%s: failed to create phy\n", __func__); | ||
| 157 | return PTR_ERR(generic_phy); | ||
| 158 | } | ||
| 159 | |||
| 160 | phy->dev = dev; | ||
| 161 | phy_set_drvdata(generic_phy, phy); | ||
| 162 | platform_set_drvdata(pdev, phy); | ||
| 163 | |||
| 164 | phy->cfg_clk = devm_clk_get(dev, "cfg"); | ||
| 165 | if (IS_ERR(phy->cfg_clk)) { | ||
| 166 | dev_err(dev, "Failed to get sata cfg clock\n"); | ||
| 167 | return PTR_ERR(phy->cfg_clk); | ||
| 168 | } | ||
| 169 | |||
| 170 | ret = clk_prepare_enable(phy->cfg_clk); | ||
| 171 | if (ret) | ||
| 172 | return ret; | ||
| 173 | |||
| 174 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
| 175 | if (IS_ERR(phy_provider)) { | ||
| 176 | clk_disable_unprepare(phy->cfg_clk); | ||
| 177 | dev_err(dev, "%s: failed to register phy\n", __func__); | ||
| 178 | return PTR_ERR(phy_provider); | ||
| 179 | } | ||
| 180 | |||
| 181 | return 0; | ||
| 182 | } | ||
| 183 | |||
| 184 | static int qcom_ipq806x_sata_phy_remove(struct platform_device *pdev) | ||
| 185 | { | ||
| 186 | struct qcom_ipq806x_sata_phy *phy = platform_get_drvdata(pdev); | ||
| 187 | |||
| 188 | clk_disable_unprepare(phy->cfg_clk); | ||
| 189 | |||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | |||
| 193 | static const struct of_device_id qcom_ipq806x_sata_phy_of_match[] = { | ||
| 194 | { .compatible = "qcom,ipq806x-sata-phy" }, | ||
| 195 | { }, | ||
| 196 | }; | ||
| 197 | MODULE_DEVICE_TABLE(of, qcom_ipq806x_sata_phy_of_match); | ||
| 198 | |||
| 199 | static struct platform_driver qcom_ipq806x_sata_phy_driver = { | ||
| 200 | .probe = qcom_ipq806x_sata_phy_probe, | ||
| 201 | .remove = qcom_ipq806x_sata_phy_remove, | ||
| 202 | .driver = { | ||
| 203 | .name = "qcom-ipq806x-sata-phy", | ||
| 204 | .owner = THIS_MODULE, | ||
| 205 | .of_match_table = qcom_ipq806x_sata_phy_of_match, | ||
| 206 | } | ||
| 207 | }; | ||
| 208 | module_platform_driver(qcom_ipq806x_sata_phy_driver); | ||
| 209 | |||
| 210 | MODULE_DESCRIPTION("QCOM IPQ806x SATA PHY driver"); | ||
| 211 | MODULE_LICENSE("GPL v2"); | ||
| @@ -87,6 +87,12 @@ static struct phy *samsung_usb2_phy_xlate(struct device *dev, · 86 unmodified lines | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | static const struct of_device_id samsung_usb2_phy_of_match[] = { | 89 | static const struct of_device_id samsung_usb2_phy_of_match[] = { |
| 90 | #ifdef CONFIG_PHY_EXYNOS4X12_USB2 | ||
| 91 | { | ||
| 92 | .compatible = "samsung,exynos3250-usb2-phy", | ||
| 93 | .data = &exynos3250_usb2_phy_config, | ||
| 94 | }, | ||
| 95 | #endif | ||
| 90 | #ifdef CONFIG_PHY_EXYNOS4210_USB2 | 96 | #ifdef CONFIG_PHY_EXYNOS4210_USB2 |
| 91 | { | 97 | { |
| 92 | .compatible = "samsung,exynos4210-usb2-phy", | 98 | .compatible = "samsung,exynos4210-usb2-phy", |
| @@ -190,7 +196,8 @@ static int samsung_usb2_phy_probe(struct platform_device *pdev) · 97 unmodified lines | |||
| 190 | struct samsung_usb2_phy_instance *p = &drv->instances[i]; | 196 | struct samsung_usb2_phy_instance *p = &drv->instances[i]; |
| 191 | 197 | ||
| 192 | dev_dbg(dev, "Creating phy \"%s\"\n", label); | 198 | dev_dbg(dev, "Creating phy \"%s\"\n", label); |
| 193 | p->phy = devm_phy_create(dev, &samsung_usb2_phy_ops, NULL); | 199 | p->phy = devm_phy_create(dev, NULL, &samsung_usb2_phy_ops, |
| 200 | NULL); | ||
| 194 | if (IS_ERR(p->phy)) { | 201 | if (IS_ERR(p->phy)) { |
| 195 | dev_err(drv->dev, "Failed to create usb2_phy \"%s\"\n", | 202 | dev_err(drv->dev, "Failed to create usb2_phy \"%s\"\n", |
| 196 | label); | 203 | label); |
| @@ -29,7 +29,8 @@ struct samsung_usb2_phy_instance { · 28 unmodified lines | |||
| 29 | const struct samsung_usb2_common_phy *cfg; | 29 | const struct samsung_usb2_common_phy *cfg; |
| 30 | struct phy *phy; | 30 | struct phy *phy; |
| 31 | struct samsung_usb2_phy_driver *drv; | 31 | struct samsung_usb2_phy_driver *drv; |
| 32 | bool enabled; | 32 | int int_cnt; |
| 33 | int ext_cnt; | ||
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | struct samsung_usb2_phy_driver { | 36 | struct samsung_usb2_phy_driver { |
| @@ -59,8 +60,10 @@ struct samsung_usb2_phy_config { · 23 unmodified lines | |||
| 59 | int (*rate_to_clk)(unsigned long, u32 *); | 60 | int (*rate_to_clk)(unsigned long, u32 *); |
| 60 | unsigned int num_phys; | 61 | unsigned int num_phys; |
| 61 | bool has_mode_switch; | 62 | bool has_mode_switch; |
| 63 | bool has_refclk_sel; | ||
| 62 | }; | 64 | }; |
| 63 | 65 | ||
| 66 | extern const struct samsung_usb2_phy_config exynos3250_usb2_phy_config; | ||
| 64 | extern const struct samsung_usb2_phy_config exynos4210_usb2_phy_config; | 67 | extern const struct samsung_usb2_phy_config exynos4210_usb2_phy_config; |
| 65 | extern const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config; | 68 | extern const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config; |
| 66 | extern const struct samsung_usb2_phy_config exynos5250_usb2_phy_config; | 69 | extern const struct samsung_usb2_phy_config exynos5250_usb2_phy_config; |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #include <linux/clk.h> | 24 | #include <linux/clk.h> |
| 25 | #include <linux/err.h> | ||
| 25 | #include <linux/io.h> | 26 | #include <linux/io.h> |
| 26 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> | 28 | #include <linux/module.h> |
| @@ -294,7 +295,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) · 266 unmodified lines | |||
| 294 | return PTR_ERR(phy->pmu); | 295 | return PTR_ERR(phy->pmu); |
| 295 | } | 296 | } |
| 296 | 297 | ||
| 297 | phy->phy = devm_phy_create(dev, &sun4i_usb_phy_ops, NULL); | 298 | phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops, NULL); |
| 298 | if (IS_ERR(phy->phy)) { | 299 | if (IS_ERR(phy->phy)) { |
| 299 | dev_err(dev, "failed to create PHY %d\n", i); | 300 | dev_err(dev, "failed to create PHY %d\n", i); |
| 300 | return PTR_ERR(phy->phy); | 301 | return PTR_ERR(phy->phy); |
| @@ -306,10 +307,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) · 5 unmodified lines | |||
| 306 | 307 | ||
| 307 | dev_set_drvdata(dev, data); | 308 | dev_set_drvdata(dev, data); |
| 308 | phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate); | 309 | phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate); |
| 309 | if (IS_ERR(phy_provider)) | ||
| 310 | return PTR_ERR(phy_provider); | ||
| 311 | 310 | ||
| 312 | return 0; | 311 | return PTR_ERR_OR_ZERO(phy_provider); |
| 313 | } | 312 | } |
| 314 | 313 | ||
| 315 | static const struct of_device_id sun4i_usb_phy_of_match[] = { | 314 | static const struct of_device_id sun4i_usb_phy_of_match[] = { |
| @@ -80,7 +80,9 @@ struct ti_pipe3 { · 79 unmodified lines | |||
| 80 | struct clk *wkupclk; | 80 | struct clk *wkupclk; |
| 81 | struct clk *sys_clk; | 81 | struct clk *sys_clk; |
| 82 | struct clk *refclk; | 82 | struct clk *refclk; |
| 83 | struct clk *div_clk; | ||
| 83 | struct pipe3_dpll_map *dpll_map; | 84 | struct pipe3_dpll_map *dpll_map; |
| 85 | u8 id; | ||
| 84 | }; | 86 | }; |
| 85 | 87 | ||
| 86 | static struct pipe3_dpll_map dpll_map_usb[] = { | 88 | static struct pipe3_dpll_map dpll_map_usb[] = { |
| @@ -215,6 +217,11 @@ static int ti_pipe3_init(struct phy *x) · 128 unmodified lines | |||
| 215 | u32 val; | 217 | u32 val; |
| 216 | int ret = 0; | 218 | int ret = 0; |
| 217 | 219 | ||
| 220 | if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie")) { | ||
| 221 | omap_control_pcie_pcs(phy->control_dev, phy->id, 0xF1); | ||
| 222 | return 0; | ||
| 223 | } | ||
| 224 | |||
| 218 | /* Bring it out of IDLE if it is IDLE */ | 225 | /* Bring it out of IDLE if it is IDLE */ |
| 219 | val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); | 226 | val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); |
| 220 | if (val & PLL_IDLE) { | 227 | if (val & PLL_IDLE) { |
| @@ -238,8 +245,11 @@ static int ti_pipe3_exit(struct phy *x) · 17 unmodified lines | |||
| 238 | u32 val; | 245 | u32 val; |
| 239 | unsigned long timeout; | 246 | unsigned long timeout; |
| 240 | 247 | ||
| 241 | /* SATA DPLL can't be powered down due to Errata i783 */ | 248 | /* SATA DPLL can't be powered down due to Errata i783 and PCIe |
| 242 | if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-sata")) | 249 | * does not have internal DPLL |
| 250 | */ | ||
| 251 | if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-sata") || | ||
| 252 | of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie")) | ||
| 243 | return 0; | 253 | return 0; |
| 244 | 254 | ||
| 245 | /* Put DPLL in IDLE mode */ | 255 | /* Put DPLL in IDLE mode */ |
| @@ -286,32 +296,41 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 40 unmodified lines | |||
| 286 | struct device_node *control_node; | 296 | struct device_node *control_node; |
| 287 | struct platform_device *control_pdev; | 297 | struct platform_device *control_pdev; |
| 288 | const struct of_device_id *match; | 298 | const struct of_device_id *match; |
| 289 | 299 | struct clk *clk; | |
| 290 | match = of_match_device(of_match_ptr(ti_pipe3_id_table), &pdev->dev); | ||
| 291 | if (!match) | ||
| 292 | return -EINVAL; | ||
| 293 | 300 | ||
| 294 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); | 301 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); |
| 295 | if (!phy) { | 302 | if (!phy) { |
| 296 | dev_err(&pdev->dev, "unable to alloc mem for TI PIPE3 PHY\n"); | 303 | dev_err(&pdev->dev, "unable to alloc mem for TI PIPE3 PHY\n"); |
| 297 | return -ENOMEM; | 304 | return -ENOMEM; |
| 298 | } | 305 | } |
| 306 | phy->dev = &pdev->dev; | ||
| 299 | 307 | ||
| 300 | phy->dpll_map = (struct pipe3_dpll_map *)match->data; | 308 | if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { |
| 301 | if (!phy->dpll_map) { | 309 | match = of_match_device(of_match_ptr(ti_pipe3_id_table), |
| 302 | dev_err(&pdev->dev, "no DPLL data\n"); | 310 | &pdev->dev); |
| 303 | return -EINVAL; | 311 | if (!match) |
| 304 | } | 312 | return -EINVAL; |
| 305 | 313 | ||
| 306 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll_ctrl"); | 314 | phy->dpll_map = (struct pipe3_dpll_map *)match->data; |
| 307 | phy->pll_ctrl_base = devm_ioremap_resource(&pdev->dev, res); | 315 | if (!phy->dpll_map) { |
| 308 | if (IS_ERR(phy->pll_ctrl_base)) | 316 | dev_err(&pdev->dev, "no DPLL data\n"); |
| 309 | return PTR_ERR(phy->pll_ctrl_base); | 317 | return -EINVAL; |
| 318 | } | ||
| 310 | 319 | ||
| 311 | phy->dev = &pdev->dev; | 320 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 321 | "pll_ctrl"); | ||
| 322 | phy->pll_ctrl_base = devm_ioremap_resource(&pdev->dev, res); | ||
| 323 | if (IS_ERR(phy->pll_ctrl_base)) | ||
| 324 | return PTR_ERR(phy->pll_ctrl_base); | ||
| 312 | 325 | ||
| 313 | if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) { | 326 | phy->sys_clk = devm_clk_get(phy->dev, "sysclk"); |
| 327 | if (IS_ERR(phy->sys_clk)) { | ||
| 328 | dev_err(&pdev->dev, "unable to get sysclk\n"); | ||
| 329 | return -EINVAL; | ||
| 330 | } | ||
| 331 | } | ||
| 314 | 332 | ||
| 333 | if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) { | ||
| 315 | phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); | 334 | phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); |
| 316 | if (IS_ERR(phy->wkupclk)) { | 335 | if (IS_ERR(phy->wkupclk)) { |
| 317 | dev_err(&pdev->dev, "unable to get wkupclk\n"); | 336 | dev_err(&pdev->dev, "unable to get wkupclk\n"); |
| @@ -328,10 +347,38 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 10 unmodified lines | |||
| 328 | phy->refclk = ERR_PTR(-ENODEV); | 347 | phy->refclk = ERR_PTR(-ENODEV); |
| 329 | } | 348 | } |
| 330 | 349 | ||
| 331 | phy->sys_clk = devm_clk_get(phy->dev, "sysclk"); | 350 | if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { |
| 332 | if (IS_ERR(phy->sys_clk)) { | 351 | if (of_property_read_u8(node, "id", &phy->id) < 0) |
| 333 | dev_err(&pdev->dev, "unable to get sysclk\n"); | 352 | phy->id = 1; |
| 334 | return -EINVAL; | 353 | |
| 354 | clk = devm_clk_get(phy->dev, "dpll_ref"); | ||
| 355 | if (IS_ERR(clk)) { | ||
| 356 | dev_err(&pdev->dev, "unable to get dpll ref clk\n"); | ||
| 357 | return PTR_ERR(clk); | ||
| 358 | } | ||
| 359 | clk_set_rate(clk, 1500000000); | ||
| 360 | |||
| 361 | clk = devm_clk_get(phy->dev, "dpll_ref_m2"); | ||
| 362 | if (IS_ERR(clk)) { | ||
| 363 | dev_err(&pdev->dev, "unable to get dpll ref m2 clk\n"); | ||
| 364 | return PTR_ERR(clk); | ||
| 365 | } | ||
| 366 | clk_set_rate(clk, 100000000); | ||
| 367 | |||
| 368 | clk = devm_clk_get(phy->dev, "phy-div"); | ||
| 369 | if (IS_ERR(clk)) { | ||
| 370 | dev_err(&pdev->dev, "unable to get phy-div clk\n"); | ||
| 371 | return PTR_ERR(clk); | ||
| 372 | } | ||
| 373 | clk_set_rate(clk, 100000000); | ||
| 374 | |||
| 375 | phy->div_clk = devm_clk_get(phy->dev, "div-clk"); | ||
| 376 | if (IS_ERR(phy->div_clk)) { | ||
| 377 | dev_err(&pdev->dev, "unable to get div-clk\n"); | ||
| 378 | return PTR_ERR(phy->div_clk); | ||
| 379 | } | ||
| 380 | } else { | ||
| 381 | phy->div_clk = ERR_PTR(-ENODEV); | ||
| 335 | } | 382 | } |
| 336 | 383 | ||
| 337 | control_node = of_parse_phandle(node, "ctrl-module", 0); | 384 | control_node = of_parse_phandle(node, "ctrl-module", 0); |
| @@ -353,7 +400,7 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 15 unmodified lines | |||
| 353 | platform_set_drvdata(pdev, phy); | 400 | platform_set_drvdata(pdev, phy); |
| 354 | pm_runtime_enable(phy->dev); | 401 | pm_runtime_enable(phy->dev); |
| 355 | 402 | ||
| 356 | generic_phy = devm_phy_create(phy->dev, &ops, NULL); | 403 | generic_phy = devm_phy_create(phy->dev, NULL, &ops, NULL); |
| 357 | if (IS_ERR(generic_phy)) | 404 | if (IS_ERR(generic_phy)) |
| 358 | return PTR_ERR(generic_phy); | 405 | return PTR_ERR(generic_phy); |
| 359 | 406 | ||
| @@ -387,6 +434,8 @@ static int ti_pipe3_runtime_suspend(struct device *dev) · 27 unmodified lines | |||
| 387 | clk_disable_unprepare(phy->wkupclk); | 434 | clk_disable_unprepare(phy->wkupclk); |
| 388 | if (!IS_ERR(phy->refclk)) | 435 | if (!IS_ERR(phy->refclk)) |
| 389 | clk_disable_unprepare(phy->refclk); | 436 | clk_disable_unprepare(phy->refclk); |
| 437 | if (!IS_ERR(phy->div_clk)) | ||
| 438 | clk_disable_unprepare(phy->div_clk); | ||
| 390 | 439 | ||
| 391 | return 0; | 440 | return 0; |
| 392 | } | 441 | } |
| @@ -412,8 +461,19 @@ static int ti_pipe3_runtime_resume(struct device *dev) · 19 unmodified lines | |||
| 412 | } | 461 | } |
| 413 | } | 462 | } |
| 414 | 463 | ||
| 464 | if (!IS_ERR(phy->div_clk)) { | ||
| 465 | ret = clk_prepare_enable(phy->div_clk); | ||
| 466 | if (ret) { | ||
| 467 | dev_err(phy->dev, "Failed to enable div_clk %d\n", ret); | ||
| 468 | goto err3; | ||
| 469 | } | ||
| 470 | } | ||
| 415 | return 0; | 471 | return 0; |
| 416 | 472 | ||
| 473 | err3: | ||
| 474 | if (!IS_ERR(phy->wkupclk)) | ||
| 475 | clk_disable_unprepare(phy->wkupclk); | ||
| 476 | |||
| 417 | err2: | 477 | err2: |
| 418 | if (!IS_ERR(phy->refclk)) | 478 | if (!IS_ERR(phy->refclk)) |
| 419 | clk_disable_unprepare(phy->refclk); | 479 | clk_disable_unprepare(phy->refclk); |
| @@ -446,6 +506,9 @@ static const struct of_device_id ti_pipe3_id_table[] = { · 26 unmodified lines | |||
| 446 | .compatible = "ti,phy-pipe3-sata", | 506 | .compatible = "ti,phy-pipe3-sata", |
| 447 | .data = dpll_map_sata, | 507 | .data = dpll_map_sata, |
| 448 | }, | 508 | }, |
| 509 | { | ||
| 510 | .compatible = "ti,phy-pipe3-pcie", | ||
| 511 | }, | ||
| 449 | {} | 512 | {} |
| 450 | }; | 513 | }; |
| 451 | MODULE_DEVICE_TABLE(of, ti_pipe3_id_table); | 514 | MODULE_DEVICE_TABLE(of, ti_pipe3_id_table); |
| @@ -695,7 +695,7 @@ static int twl4030_usb_probe(struct platform_device *pdev) · 694 unmodified lines | |||
| 695 | otg->set_host = twl4030_set_host; | 695 | otg->set_host = twl4030_set_host; |
| 696 | otg->set_peripheral = twl4030_set_peripheral; | 696 | otg->set_peripheral = twl4030_set_peripheral; |
| 697 | 697 | ||
| 698 | phy = devm_phy_create(twl->dev, &ops, init_data); | 698 | phy = devm_phy_create(twl->dev, NULL, &ops, init_data); |
| 699 | if (IS_ERR(phy)) { | 699 | if (IS_ERR(phy)) { |
| 700 | dev_dbg(&pdev->dev, "Failed to create PHY\n"); | 700 | dev_dbg(&pdev->dev, "Failed to create PHY\n"); |
| 701 | return PTR_ERR(phy); | 701 | return PTR_ERR(phy); |
| @@ -1707,7 +1707,7 @@ static int xgene_phy_probe(struct platform_device *pdev) · 1706 unmodified lines | |||
| 1707 | ctx->dev = &pdev->dev; | 1707 | ctx->dev = &pdev->dev; |
| 1708 | platform_set_drvdata(pdev, ctx); | 1708 | platform_set_drvdata(pdev, ctx); |
| 1709 | 1709 | ||
| 1710 | ctx->phy = devm_phy_create(ctx->dev, &xgene_phy_ops, NULL); | 1710 | ctx->phy = devm_phy_create(ctx->dev, NULL, &xgene_phy_ops, NULL); |
| 1711 | if (IS_ERR(ctx->phy)) { | 1711 | if (IS_ERR(ctx->phy)) { |
| 1712 | dev_dbg(&pdev->dev, "Failed to create PHY\n"); | 1712 | dev_dbg(&pdev->dev, "Failed to create PHY\n"); |
| 1713 | rc = PTR_ERR(ctx->phy); | 1713 | rc = PTR_ERR(ctx->phy); |
| @@ -133,6 +133,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) · 132 unmodified lines | |||
| 133 | data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); | 133 | data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); |
| 134 | if (IS_ERR(data->phy)) { | 134 | if (IS_ERR(data->phy)) { |
| 135 | ret = PTR_ERR(data->phy); | 135 | ret = PTR_ERR(data->phy); |
| 136 | /* Return -EINVAL if no usbphy is available */ | ||
| 137 | if (ret == -ENODEV) | ||
| 138 | ret = -EINVAL; | ||
| 136 | goto err_clk; | 139 | goto err_clk; |
| 137 | } | 140 | } |
| 138 | 141 | ||
| @@ -208,7 +208,7 @@ static const struct file_operations ci_requests_fops = { · 207 unmodified lines | |||
| 208 | .release = single_release, | 208 | .release = single_release, |
| 209 | }; | 209 | }; |
| 210 | 210 | ||
| 211 | int ci_otg_show(struct seq_file *s, void *unused) | 211 | static int ci_otg_show(struct seq_file *s, void *unused) |
| 212 | { | 212 | { |
| 213 | struct ci_hdrc *ci = s->private; | 213 | struct ci_hdrc *ci = s->private; |
| 214 | struct otg_fsm *fsm; | 214 | struct otg_fsm *fsm; |
| @@ -331,7 +331,7 @@ static const struct file_operations ci_role_fops = { · 116 unmodified lines | |||
| 331 | .release = single_release, | 331 | .release = single_release, |
| 332 | }; | 332 | }; |
| 333 | 333 | ||
| 334 | int ci_registers_show(struct seq_file *s, void *unused) | 334 | static int ci_registers_show(struct seq_file *s, void *unused) |
| 335 | { | 335 | { |
| 336 | struct ci_hdrc *ci = s->private; | 336 | struct ci_hdrc *ci = s->private; |
| 337 | u32 tmp_reg; | 337 | u32 tmp_reg; |
| @@ -715,7 +715,7 @@ static int usbtmc_ioctl_clear(struct usbtmc_device_data *data) · 714 unmodified lines | |||
| 715 | u8 *buffer; | 715 | u8 *buffer; |
| 716 | int rv; | 716 | int rv; |
| 717 | int n; | 717 | int n; |
| 718 | int actual; | 718 | int actual = 0; |
| 719 | int max_size; | 719 | int max_size; |
| 720 | 720 | ||
| 721 | dev = &data->intf->dev; | 721 | dev = &data->intf->dev; |
| @@ -199,6 +199,17 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, · 198 unmodified lines | |||
| 199 | if (n == 0) | 199 | if (n == 0) |
| 200 | n = 9; /* 32 ms = 2^(9-1) uframes */ | 200 | n = 9; /* 32 ms = 2^(9-1) uframes */ |
| 201 | j = 16; | 201 | j = 16; |
| 202 | |||
| 203 | /* | ||
| 204 | * Adjust bInterval for quirked devices. | ||
| 205 | * This quirk fixes bIntervals reported in | ||
| 206 | * linear microframes. | ||
| 207 | */ | ||
| 208 | if (to_usb_device(ddev)->quirks & | ||
| 209 | USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL) { | ||
| 210 | n = clamp(fls(d->bInterval), i, j); | ||
| 211 | i = j = n; | ||
| 212 | } | ||
| 202 | break; | 213 | break; |
| 203 | default: /* USB_SPEED_FULL or _LOW */ | 214 | default: /* USB_SPEED_FULL or _LOW */ |
| 204 | /* For low-speed, 10 ms is the official minimum. | 215 | /* For low-speed, 10 ms is the official minimum. |
| @@ -1509,7 +1509,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb · 1508 unmodified lines | |||
| 1509 | u = (is_in ? URB_DIR_IN : URB_DIR_OUT); | 1509 | u = (is_in ? URB_DIR_IN : URB_DIR_OUT); |
| 1510 | if (uurb->flags & USBDEVFS_URB_ISO_ASAP) | 1510 | if (uurb->flags & USBDEVFS_URB_ISO_ASAP) |
| 1511 | u |= URB_ISO_ASAP; | 1511 | u |= URB_ISO_ASAP; |
| 1512 | if (uurb->flags & USBDEVFS_URB_SHORT_NOT_OK) | 1512 | if (uurb->flags & USBDEVFS_URB_SHORT_NOT_OK && is_in) |
| 1513 | u |= URB_SHORT_NOT_OK; | 1513 | u |= URB_SHORT_NOT_OK; |
| 1514 | if (uurb->flags & USBDEVFS_URB_NO_FSBR) | 1514 | if (uurb->flags & USBDEVFS_URB_NO_FSBR) |
| 1515 | u |= URB_NO_FSBR; | 1515 | u |= URB_NO_FSBR; |
| @@ -417,10 +417,11 @@ static int usb_unbind_interface(struct device *dev) · 416 unmodified lines | |||
| 417 | */ | 417 | */ |
| 418 | lpm_disable_error = usb_unlocked_disable_lpm(udev); | 418 | lpm_disable_error = usb_unlocked_disable_lpm(udev); |
| 419 | 419 | ||
| 420 | /* Terminate all URBs for this interface unless the driver | 420 | /* |
| 421 | * supports "soft" unbinding. | 421 | * Terminate all URBs for this interface unless the driver |
| 422 | * supports "soft" unbinding and the device is still present. | ||
| 422 | */ | 423 | */ |
| 423 | if (!driver->soft_unbind) | 424 | if (!driver->soft_unbind || udev->state == USB_STATE_NOTATTACHED) |
| 424 | usb_disable_interface(udev, intf, false); | 425 | usb_disable_interface(udev, intf, false); |
| 425 | 426 | ||
| 426 | driver->disconnect(intf); | 427 | driver->disconnect(intf); |
| @@ -380,6 +380,8 @@ void usb_hcd_pci_shutdown(struct pci_dev *dev) · 379 unmodified lines | |||
| 380 | if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && | 380 | if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && |
| 381 | hcd->driver->shutdown) { | 381 | hcd->driver->shutdown) { |
| 382 | hcd->driver->shutdown(hcd); | 382 | hcd->driver->shutdown(hcd); |
| 383 | if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) | ||
| 384 | free_irq(hcd->irq, hcd); | ||
| 383 | pci_disable_device(dev); | 385 | pci_disable_device(dev); |
| 384 | } | 386 | } |
| 385 | } | 387 | } |
| @@ -855,8 +855,6 @@ static ssize_t authorized_default_show(struct device *dev, · 854 unmodified lines | |||
| 855 | struct usb_bus *usb_bus = rh_usb_dev->bus; | 855 | struct usb_bus *usb_bus = rh_usb_dev->bus; |
| 856 | struct usb_hcd *usb_hcd; | 856 | struct usb_hcd *usb_hcd; |
| 857 | 857 | ||
| 858 | if (usb_bus == NULL) /* FIXME: not sure if this case is possible */ | ||
| 859 | return -ENODEV; | ||
| 860 | usb_hcd = bus_to_hcd(usb_bus); | 858 | usb_hcd = bus_to_hcd(usb_bus); |
| 861 | return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default); | 859 | return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default); |
| 862 | } | 860 | } |
| @@ -871,8 +869,6 @@ static ssize_t authorized_default_store(struct device *dev, · 8 unmodified lines | |||
| 871 | struct usb_bus *usb_bus = rh_usb_dev->bus; | 869 | struct usb_bus *usb_bus = rh_usb_dev->bus; |
| 872 | struct usb_hcd *usb_hcd; | 870 | struct usb_hcd *usb_hcd; |
| 873 | 871 | ||
| 874 | if (usb_bus == NULL) /* FIXME: not sure if this case is possible */ | ||
| 875 | return -ENODEV; | ||
| 876 | usb_hcd = bus_to_hcd(usb_bus); | 872 | usb_hcd = bus_to_hcd(usb_bus); |
| 877 | result = sscanf(buf, "%u\n", &val); | 873 | result = sscanf(buf, "%u\n", &val); |
| 878 | if (result == 1) { | 874 | if (result == 1) { |
| @@ -2606,13 +2606,20 @@ static int hub_port_reset(struct usb_hub *hub, int port1, · 2605 unmodified lines | |||
| 2606 | /* Is a USB 3.0 port in the Inactive or Compliance Mode state? | 2606 | /* Is a USB 3.0 port in the Inactive or Compliance Mode state? |
| 2607 | * Port worm reset is required to recover | 2607 | * Port worm reset is required to recover |
| 2608 | */ | 2608 | */ |
| 2609 | static bool hub_port_warm_reset_required(struct usb_hub *hub, u16 portstatus) | 2609 | static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, |
| 2610 | u16 portstatus) | ||
| 2610 | { | 2611 | { |
| 2611 | return hub_is_superspeed(hub->hdev) && | 2612 | u16 link_state; |
| 2612 | (((portstatus & USB_PORT_STAT_LINK_STATE) == | 2613 | |
| 2613 | USB_SS_PORT_LS_SS_INACTIVE) || | 2614 | if (!hub_is_superspeed(hub->hdev)) |
| 2614 | ((portstatus & USB_PORT_STAT_LINK_STATE) == | 2615 | return false; |
| 2615 | USB_SS_PORT_LS_COMP_MOD)) ; | 2616 | |
| 2617 | if (test_bit(port1, hub->warm_reset_bits)) | ||
| 2618 | return true; | ||
| 2619 | |||
| 2620 | link_state = portstatus & USB_PORT_STAT_LINK_STATE; | ||
| 2621 | return link_state == USB_SS_PORT_LS_SS_INACTIVE | ||
| 2622 | || link_state == USB_SS_PORT_LS_COMP_MOD; | ||
| 2616 | } | 2623 | } |
| 2617 | 2624 | ||
| 2618 | static int hub_port_wait_reset(struct usb_hub *hub, int port1, | 2625 | static int hub_port_wait_reset(struct usb_hub *hub, int port1, |
| @@ -2649,7 +2656,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, · 30 unmodified lines | |||
| 2649 | if ((portstatus & USB_PORT_STAT_RESET)) | 2656 | if ((portstatus & USB_PORT_STAT_RESET)) |
| 2650 | return -EBUSY; | 2657 | return -EBUSY; |
| 2651 | 2658 | ||
| 2652 | if (hub_port_warm_reset_required(hub, portstatus)) | 2659 | if (hub_port_warm_reset_required(hub, port1, portstatus)) |
| 2653 | return -ENOTCONN; | 2660 | return -ENOTCONN; |
| 2654 | 2661 | ||
| 2655 | /* Device went away? */ | 2662 | /* Device went away? */ |
| @@ -2749,9 +2756,10 @@ static int hub_port_reset(struct usb_hub *hub, int port1, · 93 unmodified lines | |||
| 2749 | if (status < 0) | 2756 | if (status < 0) |
| 2750 | goto done; | 2757 | goto done; |
| 2751 | 2758 | ||
| 2752 | if (hub_port_warm_reset_required(hub, portstatus)) | 2759 | if (hub_port_warm_reset_required(hub, port1, portstatus)) |
| 2753 | warm = true; | 2760 | warm = true; |
| 2754 | } | 2761 | } |
| 2762 | clear_bit(port1, hub->warm_reset_bits); | ||
| 2755 | 2763 | ||
| 2756 | /* Reset the port */ | 2764 | /* Reset the port */ |
| 2757 | for (i = 0; i < PORT_RESET_TRIES; i++) { | 2765 | for (i = 0; i < PORT_RESET_TRIES; i++) { |
| @@ -2788,7 +2796,8 @@ static int hub_port_reset(struct usb_hub *hub, int port1, · 30 unmodified lines | |||
| 2788 | &portstatus, &portchange) < 0) | 2796 | &portstatus, &portchange) < 0) |
| 2789 | goto done; | 2797 | goto done; |
| 2790 | 2798 | ||
| 2791 | if (!hub_port_warm_reset_required(hub, portstatus)) | 2799 | if (!hub_port_warm_reset_required(hub, port1, |
| 2800 | portstatus)) | ||
| 2792 | goto done; | 2801 | goto done; |
| 2793 | 2802 | ||
| 2794 | /* | 2803 | /* |
| @@ -2875,8 +2884,13 @@ static int check_port_resume_type(struct usb_device *udev, · 80 unmodified lines | |||
| 2875 | { | 2884 | { |
| 2876 | struct usb_port *port_dev = hub->ports[port1 - 1]; | 2885 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
| 2877 | 2886 | ||
| 2887 | /* Is a warm reset needed to recover the connection? */ | ||
| 2888 | if (status == 0 && udev->reset_resume | ||
| 2889 | && hub_port_warm_reset_required(hub, port1, portstatus)) { | ||
| 2890 | /* pass */; | ||
| 2891 | } | ||
| 2878 | /* Is the device still present? */ | 2892 | /* Is the device still present? */ |
| 2879 | if (status || port_is_suspended(hub, portstatus) || | 2893 | else if (status || port_is_suspended(hub, portstatus) || |
| 2880 | !port_is_power_on(hub, portstatus) || | 2894 | !port_is_power_on(hub, portstatus) || |
| 2881 | !(portstatus & USB_PORT_STAT_CONNECTION)) { | 2895 | !(portstatus & USB_PORT_STAT_CONNECTION)) { |
| 2882 | if (status >= 0) | 2896 | if (status >= 0) |
| @@ -3263,6 +3277,43 @@ static int finish_port_resume(struct usb_device *udev) · 380 unmodified lines | |||
| 3263 | return status; | 3277 | return status; |
| 3264 | } | 3278 | } |
| 3265 | 3279 | ||
| 3280 | /* | ||
| 3281 | * There are some SS USB devices which take longer time for link training. | ||
| 3282 | * XHCI specs 4.19.4 says that when Link training is successful, port | ||
| 3283 | * sets CSC bit to 1. So if SW reads port status before successful link | ||
| 3284 | * training, then it will not find device to be present. | ||
| 3285 | * USB Analyzer log with such buggy devices show that in some cases | ||
| 3286 | * device switch on the RX termination after long delay of host enabling | ||
| 3287 | * the VBUS. In few other cases it has been seen that device fails to | ||
| 3288 | * negotiate link training in first attempt. It has been | ||
| 3289 | * reported till now that few devices take as long as 2000 ms to train | ||
| 3290 | * the link after host enabling its VBUS and termination. Following | ||
| 3291 | * routine implements a 2000 ms timeout for link training. If in a case | ||
| 3292 | * link trains before timeout, loop will exit earlier. | ||
| 3293 | * | ||
| 3294 | * FIXME: If a device was connected before suspend, but was removed | ||
| 3295 | * while system was asleep, then the loop in the following routine will | ||
| 3296 | * only exit at timeout. | ||
| 3297 | * | ||
| 3298 | * This routine should only be called when persist is enabled for a SS | ||
| 3299 | * device. | ||
| 3300 | */ | ||
| 3301 | static int wait_for_ss_port_enable(struct usb_device *udev, | ||
| 3302 | struct usb_hub *hub, int *port1, | ||
| 3303 | u16 *portchange, u16 *portstatus) | ||
| 3304 | { | ||
| 3305 | int status = 0, delay_ms = 0; | ||
| 3306 | |||
| 3307 | while (delay_ms < 2000) { | ||
| 3308 | if (status || *portstatus & USB_PORT_STAT_CONNECTION) | ||
| 3309 | break; | ||
| 3310 | msleep(20); | ||
| 3311 | delay_ms += 20; | ||
| 3312 | status = hub_port_status(hub, *port1, portstatus, portchange); | ||
| 3313 | } | ||
| 3314 | return status; | ||
| 3315 | } | ||
| 3316 | |||
| 3266 | /* | 3317 | /* |
| 3267 | * usb_port_resume - re-activate a suspended usb device's upstream port | 3318 | * usb_port_resume - re-activate a suspended usb device's upstream port |
| 3268 | * @udev: device to re-activate, not a root hub | 3319 | * @udev: device to re-activate, not a root hub |
| @@ -3359,6 +3410,10 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) · 90 unmodified lines | |||
| 3359 | } | 3410 | } |
| 3360 | } | 3411 | } |
| 3361 | 3412 | ||
| 3413 | if (udev->persist_enabled && hub_is_superspeed(hub->hdev)) | ||
| 3414 | status = wait_for_ss_port_enable(udev, hub, &port1, &portchange, | ||
| 3415 | &portstatus); | ||
| 3416 | |||
| 3362 | status = check_port_resume_type(udev, | 3417 | status = check_port_resume_type(udev, |
| 3363 | hub, port1, status, portchange, portstatus); | 3418 | hub, port1, status, portchange, portstatus); |
| 3364 | if (status == 0) | 3419 | if (status == 0) |
| @@ -3879,7 +3934,8 @@ int usb_disable_lpm(struct usb_device *udev) · 514 unmodified lines | |||
| 3879 | 3934 | ||
| 3880 | if (!udev || !udev->parent || | 3935 | if (!udev || !udev->parent || |
| 3881 | udev->speed != USB_SPEED_SUPER || | 3936 | udev->speed != USB_SPEED_SUPER || |
| 3882 | !udev->lpm_capable) | 3937 | !udev->lpm_capable || |
| 3938 | udev->state < USB_STATE_DEFAULT) | ||
| 3883 | return 0; | 3939 | return 0; |
| 3884 | 3940 | ||
| 3885 | hcd = bus_to_hcd(udev->bus); | 3941 | hcd = bus_to_hcd(udev->bus); |
| @@ -3935,7 +3991,8 @@ void usb_enable_lpm(struct usb_device *udev) · 49 unmodified lines | |||
| 3935 | 3991 | ||
| 3936 | if (!udev || !udev->parent || | 3992 | if (!udev || !udev->parent || |
| 3937 | udev->speed != USB_SPEED_SUPER || | 3993 | udev->speed != USB_SPEED_SUPER || |
| 3938 | !udev->lpm_capable) | 3994 | !udev->lpm_capable || |
| 3995 | udev->state < USB_STATE_DEFAULT) | ||
| 3939 | return; | 3996 | return; |
| 3940 | 3997 | ||
| 3941 | udev->lpm_disable_count--; | 3998 | udev->lpm_disable_count--; |
| @@ -4550,6 +4607,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 608 unmodified lines | |||
| 4550 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | 4607 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); |
| 4551 | struct usb_port *port_dev = hub->ports[port1 - 1]; | 4608 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
| 4552 | struct usb_device *udev = port_dev->child; | 4609 | struct usb_device *udev = port_dev->child; |
| 4610 | static int unreliable_port = -1; | ||
| 4553 | 4611 | ||
| 4554 | /* Disconnect any existing devices under this port */ | 4612 | /* Disconnect any existing devices under this port */ |
| 4555 | if (udev) { | 4613 | if (udev) { |
| @@ -4570,10 +4628,14 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 14 unmodified lines | |||
| 4570 | USB_PORT_STAT_C_ENABLE)) { | 4628 | USB_PORT_STAT_C_ENABLE)) { |
| 4571 | status = hub_port_debounce_be_stable(hub, port1); | 4629 | status = hub_port_debounce_be_stable(hub, port1); |
| 4572 | if (status < 0) { | 4630 | if (status < 0) { |
| 4573 | if (status != -ENODEV && printk_ratelimit()) | 4631 | if (status != -ENODEV && |
| 4574 | dev_err(&port_dev->dev, | 4632 | port1 != unreliable_port && |
| 4575 | "connect-debounce failed\n"); | 4633 | printk_ratelimit()) |
| 4634 | dev_err(&udev->dev, "connect-debounce failed, port %d disabled\n", | ||
| 4635 | port1); | ||
| 4636 | |||
| 4576 | portstatus &= ~USB_PORT_STAT_CONNECTION; | 4637 | portstatus &= ~USB_PORT_STAT_CONNECTION; |
| 4638 | unreliable_port = port1; | ||
| 4577 | } else { | 4639 | } else { |
| 4578 | portstatus = status; | 4640 | portstatus = status; |
| 4579 | } | 4641 | } |
| @@ -4889,7 +4951,7 @@ static void port_event(struct usb_hub *hub, int port1) · 309 unmodified lines | |||
| 4889 | * Warm reset a USB3 protocol port if it's in | 4951 | * Warm reset a USB3 protocol port if it's in |
| 4890 | * SS.Inactive state. | 4952 | * SS.Inactive state. |
| 4891 | */ | 4953 | */ |
| 4892 | if (hub_port_warm_reset_required(hub, portstatus)) { | 4954 | if (hub_port_warm_reset_required(hub, port1, portstatus)) { |
| 4893 | dev_dbg(&port_dev->dev, "do warm reset\n"); | 4955 | dev_dbg(&port_dev->dev, "do warm reset\n"); |
| 4894 | if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION) | 4956 | if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION) |
| 4895 | || udev->state == USB_STATE_NOTATTACHED) { | 4957 | || udev->state == USB_STATE_NOTATTACHED) { |
| @@ -52,6 +52,8 @@ struct usb_hub { · 51 unmodified lines | |||
| 52 | unsigned long power_bits[1]; /* ports that are powered */ | 52 | unsigned long power_bits[1]; /* ports that are powered */ |
| 53 | unsigned long child_usage_bits[1]; /* ports powered on for | 53 | unsigned long child_usage_bits[1]; /* ports powered on for |
| 54 | children */ | 54 | children */ |
| 55 | unsigned long warm_reset_bits[1]; /* ports requesting warm | ||
| 56 | reset recovery */ | ||
| 55 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | 57 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ |
| 56 | #error event_bits[] is too short! | 58 | #error event_bits[] is too short! |
| 57 | #endif | 59 | #endif |
| @@ -103,16 +103,19 @@ static int usb_port_runtime_resume(struct device *dev) · 102 unmodified lines | |||
| 103 | msleep(hub_power_on_good_delay(hub)); | 103 | msleep(hub_power_on_good_delay(hub)); |
| 104 | if (udev && !retval) { | 104 | if (udev && !retval) { |
| 105 | /* | 105 | /* |
| 106 | * Attempt to wait for usb hub port to be reconnected in order | 106 | * Our preference is to simply wait for the port to reconnect, |
| 107 | * to make the resume procedure successful. The device may have | 107 | * as that is the lowest latency method to restart the port. |
| 108 | * disconnected while the port was powered off, so ignore the | 108 | * However, there are cases where toggling port power results in |
| 109 | * return status. | 109 | * the host port and the device port getting out of sync causing |
| 110 | * a link training live lock. Upon timeout, flag the port as | ||
| 111 | * needing warm reset recovery (to be performed later by | ||
| 112 | * usb_port_resume() as requested via usb_wakeup_notification()) | ||
| 110 | */ | 113 | */ |
| 111 | retval = hub_port_debounce_be_connected(hub, port1); | 114 | if (hub_port_debounce_be_connected(hub, port1) < 0) { |
| 112 | if (retval < 0) | 115 | dev_dbg(&port_dev->dev, "reconnect timeout\n"); |
| 113 | dev_dbg(&port_dev->dev, "can't get reconnection after setting port power on, status %d\n", | 116 | if (hub_is_superspeed(hdev)) |
| 114 | retval); | 117 | set_bit(port1, hub->warm_reset_bits); |
| 115 | retval = 0; | 118 | } |
| 116 | 119 | ||
| 117 | /* Force the child awake to revalidate after the power loss. */ | 120 | /* Force the child awake to revalidate after the power loss. */ |
| 118 | if (!test_and_set_bit(port1, hub->child_usage_bits)) { | 121 | if (!test_and_set_bit(port1, hub->child_usage_bits)) { |
| @@ -145,6 +145,10 @@ static const struct usb_device_id usb_quirk_list[] = { · 144 unmodified lines | |||
| 145 | /* SKYMEDI USB_DRIVE */ | 145 | /* SKYMEDI USB_DRIVE */ |
| 146 | { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME }, | 146 | { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME }, |
| 147 | 147 | ||
| 148 | /* Razer - Razer Blade Keyboard */ | ||
| 149 | { USB_DEVICE(0x1532, 0x0116), .driver_info = | ||
| 150 | USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, | ||
| 151 | |||
| 148 | /* BUILDWIN Photo Frame */ | 152 | /* BUILDWIN Photo Frame */ |
| 149 | { USB_DEVICE(0x1908, 0x1315), .driver_info = | 153 | { USB_DEVICE(0x1908, 0x1315), .driver_info = |
| 150 | USB_QUIRK_HONOR_BNUMINTERFACES }, | 154 | USB_QUIRK_HONOR_BNUMINTERFACES }, |
| @@ -152,6 +156,9 @@ static const struct usb_device_id usb_quirk_list[] = { · 1 unmodified line | |||
| 152 | /* INTEL VALUE SSD */ | 156 | /* INTEL VALUE SSD */ |
| 153 | { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME }, | 157 | { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME }, |
| 154 | 158 | ||
| 159 | /* USB3503 */ | ||
| 160 | { USB_DEVICE(0x0424, 0x3503), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
| 161 | |||
| 155 | { } /* terminating entry must be last */ | 162 | { } /* terminating entry must be last */ |
| 156 | }; | 163 | }; |
| 157 | 164 | ||
| @@ -454,6 +454,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) · 453 unmodified lines | |||
| 454 | URB_FREE_BUFFER); | 454 | URB_FREE_BUFFER); |
| 455 | switch (xfertype) { | 455 | switch (xfertype) { |
| 456 | case USB_ENDPOINT_XFER_BULK: | 456 | case USB_ENDPOINT_XFER_BULK: |
| 457 | case USB_ENDPOINT_XFER_INT: | ||
| 457 | if (is_out) | 458 | if (is_out) |
| 458 | allowed |= URB_ZERO_PACKET; | 459 | allowed |= URB_ZERO_PACKET; |
| 459 | /* FALLTHROUGH */ | 460 | /* FALLTHROUGH */ |
| @@ -501,6 +501,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, · 500 unmodified lines | |||
| 501 | } | 501 | } |
| 502 | return dev; | 502 | return dev; |
| 503 | } | 503 | } |
| 504 | EXPORT_SYMBOL_GPL(usb_alloc_dev); | ||
| 504 | 505 | ||
| 505 | /** | 506 | /** |
| 506 | * usb_get_dev - increments the reference count of the usb device structure | 507 | * usb_get_dev - increments the reference count of the usb device structure |
| @@ -1,6 +1,4 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * linux/drivers/usb/gadget/s3c-hsotg.c | ||
| 3 | * | ||
| 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. | 2 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com | 3 | * http://www.samsung.com |
| 6 | * | 4 | * |
| @@ -1022,7 +1020,8 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); · 1015 unmodified lines | |||
| 1022 | * | 1020 | * |
| 1023 | * Set stall for ep0 as response for setup request. | 1021 | * Set stall for ep0 as response for setup request. |
| 1024 | */ | 1022 | */ |
| 1025 | static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) { | 1023 | static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) |
| 1024 | { | ||
| 1026 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; | 1025 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
| 1027 | u32 reg; | 1026 | u32 reg; |
| 1028 | u32 ctrl; | 1027 | u32 ctrl; |
| @@ -1994,7 +1993,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, · 965 unmodified lines | |||
| 1994 | s3c_hsotg_complete_request(hsotg, ep, req, | 1993 | s3c_hsotg_complete_request(hsotg, ep, req, |
| 1995 | result); | 1994 | result); |
| 1996 | } | 1995 | } |
| 1997 | if(hsotg->dedicated_fifos) | 1996 | if (hsotg->dedicated_fifos) |
| 1998 | if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) | 1997 | if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) |
| 1999 | s3c_hsotg_txfifo_flush(hsotg, ep->index); | 1998 | s3c_hsotg_txfifo_flush(hsotg, ep->index); |
| 2000 | } | 1999 | } |
| @@ -3390,10 +3389,8 @@ static int s3c_hsotg_probe(struct platform_device *pdev) · 1389 unmodified lines | |||
| 3390 | int i; | 3389 | int i; |
| 3391 | 3390 | ||
| 3392 | hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); | 3391 | hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); |
| 3393 | if (!hsotg) { | 3392 | if (!hsotg) |
| 3394 | dev_err(dev, "cannot get memory\n"); | ||
| 3395 | return -ENOMEM; | 3393 | return -ENOMEM; |
| 3396 | } | ||
| 3397 | 3394 | ||
| 3398 | /* | 3395 | /* |
| 3399 | * Attempt to find a generic PHY, then look for an old style | 3396 | * Attempt to find a generic PHY, then look for an old style |
| @@ -3512,7 +3509,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev) · 112 unmodified lines | |||
| 3512 | eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), | 3509 | eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), |
| 3513 | GFP_KERNEL); | 3510 | GFP_KERNEL); |
| 3514 | if (!eps) { | 3511 | if (!eps) { |
| 3515 | dev_err(dev, "cannot get memory\n"); | ||
| 3516 | ret = -ENOMEM; | 3512 | ret = -ENOMEM; |
| 3517 | goto err_supplies; | 3513 | goto err_supplies; |
| 3518 | } | 3514 | } |
| @@ -93,4 +93,11 @@ config USB_DWC3_VERBOSE · 92 unmodified lines | |||
| 93 | help | 93 | help |
| 94 | Say Y here to enable verbose debugging messages on DWC3 Driver. | 94 | Say Y here to enable verbose debugging messages on DWC3 Driver. |
| 95 | 95 | ||
| 96 | config DWC3_HOST_USB3_LPM_ENABLE | ||
| 97 | bool "Enable USB3 LPM Capability" | ||
| 98 | depends on USB_DWC3_HOST=y || USB_DWC3_DUAL_ROLE=y | ||
| 99 | default n | ||
| 100 | help | ||
| 101 | Select this when you want to enable USB3 LPM with dwc3 xhci host. | ||
| 102 | |||
| 96 | endif | 103 | endif |
| @@ -386,6 +386,13 @@ static int dwc3_core_init(struct dwc3 *dwc) · 385 unmodified lines | |||
| 386 | } | 386 | } |
| 387 | dwc->revision = reg; | 387 | dwc->revision = reg; |
| 388 | 388 | ||
| 389 | /* Handle USB2.0-only core configuration */ | ||
| 390 | if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == | ||
| 391 | DWC3_GHWPARAMS3_SSPHY_IFC_DIS) { | ||
| 392 | if (dwc->maximum_speed == USB_SPEED_SUPER) | ||
| 393 | dwc->maximum_speed = USB_SPEED_HIGH; | ||
| 394 | } | ||
| 395 | |||
| 389 | /* issue device SoftReset too */ | 396 | /* issue device SoftReset too */ |
| 390 | timeout = jiffies + msecs_to_jiffies(500); | 397 | timeout = jiffies + msecs_to_jiffies(500); |
| 391 | dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); | 398 | dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); |
| @@ -656,6 +663,31 @@ static int dwc3_probe(struct platform_device *pdev) · 264 unmodified lines | |||
| 656 | return -ENODEV; | 663 | return -ENODEV; |
| 657 | } | 664 | } |
| 658 | 665 | ||
| 666 | dwc->xhci_resources[0].start = res->start; | ||
| 667 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + | ||
| 668 | DWC3_XHCI_REGS_END; | ||
| 669 | dwc->xhci_resources[0].flags = res->flags; | ||
| 670 | dwc->xhci_resources[0].name = res->name; | ||
| 671 | |||
| 672 | res->start += DWC3_GLOBALS_REGS_START; | ||
| 673 | |||
| 674 | /* | ||
| 675 | * Request memory region but exclude xHCI regs, | ||
| 676 | * since it will be requested by the xhci-plat driver. | ||
| 677 | */ | ||
| 678 | regs = devm_ioremap_resource(dev, res); | ||
| 679 | if (IS_ERR(regs)) | ||
| 680 | return PTR_ERR(regs); | ||
| 681 | |||
| 682 | dwc->regs = regs; | ||
| 683 | dwc->regs_size = resource_size(res); | ||
| 684 | /* | ||
| 685 | * restore res->start back to its original value so that, | ||
| 686 | * in case the probe is deferred, we don't end up getting error in | ||
| 687 | * request the memory region the next time probe is called. | ||
| 688 | */ | ||
| 689 | res->start -= DWC3_GLOBALS_REGS_START; | ||
| 690 | |||
| 659 | if (node) { | 691 | if (node) { |
| 660 | dwc->maximum_speed = of_usb_get_maximum_speed(node); | 692 | dwc->maximum_speed = of_usb_get_maximum_speed(node); |
| 661 | 693 | ||
| @@ -676,28 +708,9 @@ static int dwc3_probe(struct platform_device *pdev) · 14 unmodified lines | |||
| 676 | if (ret) | 708 | if (ret) |
| 677 | return ret; | 709 | return ret; |
| 678 | 710 | ||
| 679 | dwc->xhci_resources[0].start = res->start; | ||
| 680 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + | ||
| 681 | DWC3_XHCI_REGS_END; | ||
| 682 | dwc->xhci_resources[0].flags = res->flags; | ||
| 683 | dwc->xhci_resources[0].name = res->name; | ||
| 684 | |||
| 685 | res->start += DWC3_GLOBALS_REGS_START; | ||
| 686 | |||
| 687 | /* | ||
| 688 | * Request memory region but exclude xHCI regs, | ||
| 689 | * since it will be requested by the xhci-plat driver. | ||
| 690 | */ | ||
| 691 | regs = devm_ioremap_resource(dev, res); | ||
| 692 | if (IS_ERR(regs)) | ||
| 693 | return PTR_ERR(regs); | ||
| 694 | |||
| 695 | spin_lock_init(&dwc->lock); | 711 | spin_lock_init(&dwc->lock); |
| 696 | platform_set_drvdata(pdev, dwc); | 712 | platform_set_drvdata(pdev, dwc); |
| 697 | 713 | ||
| 698 | dwc->regs = regs; | ||
| 699 | dwc->regs_size = resource_size(res); | ||
| 700 | |||
| 701 | dev->dma_mask = dev->parent->dma_mask; | 714 | dev->dma_mask = dev->parent->dma_mask; |
| 702 | dev->dma_parms = dev->parent->dma_parms; | 715 | dev->dma_parms = dev->parent->dma_parms; |
| 703 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); | 716 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); |
| @@ -191,6 +191,19 @@ · 190 unmodified lines | |||
| 191 | #define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24) | 191 | #define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24) |
| 192 | #define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3) | 192 | #define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3) |
| 193 | 193 | ||
| 194 | /* Global HWPARAMS3 Register */ | ||
| 195 | #define DWC3_GHWPARAMS3_SSPHY_IFC(n) ((n) & 3) | ||
| 196 | #define DWC3_GHWPARAMS3_SSPHY_IFC_DIS 0 | ||
| 197 | #define DWC3_GHWPARAMS3_SSPHY_IFC_ENA 1 | ||
| 198 | #define DWC3_GHWPARAMS3_HSPHY_IFC(n) (((n) & (3 << 2)) >> 2) | ||
| 199 | #define DWC3_GHWPARAMS3_HSPHY_IFC_DIS 0 | ||
| 200 | #define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI 1 | ||
| 201 | #define DWC3_GHWPARAMS3_HSPHY_IFC_ULPI 2 | ||
| 202 | #define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI 3 | ||
| 203 | #define DWC3_GHWPARAMS3_FSPHY_IFC(n) (((n) & (3 << 4)) >> 4) | ||
| 204 | #define DWC3_GHWPARAMS3_FSPHY_IFC_DIS 0 | ||
| 205 | #define DWC3_GHWPARAMS3_FSPHY_IFC_ENA 1 | ||
| 206 | |||
| 194 | /* Global HWPARAMS4 Register */ | 207 | /* Global HWPARAMS4 Register */ |
| 195 | #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13) | 208 | #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13) |
| 196 | #define DWC3_MAX_HIBER_SCRATCHBUFS 15 | 209 | #define DWC3_MAX_HIBER_SCRATCHBUFS 15 |
| @@ -77,10 +77,6 @@ · 76 unmodified lines | |||
| 77 | #define USBOTGSS_DEV_EBC_EN 0x0110 | 77 | #define USBOTGSS_DEV_EBC_EN 0x0110 |
| 78 | #define USBOTGSS_DEBUG_OFFSET 0x0600 | 78 | #define USBOTGSS_DEBUG_OFFSET 0x0600 |
| 79 | 79 | ||
| 80 | /* REVISION REGISTER */ | ||
| 81 | #define USBOTGSS_REVISION_XMAJOR(reg) ((reg >> 8) & 0x7) | ||
| 82 | #define USBOTGSS_REVISION_XMAJOR1 1 | ||
| 83 | #define USBOTGSS_REVISION_XMAJOR2 2 | ||
| 84 | /* SYSCONFIG REGISTER */ | 80 | /* SYSCONFIG REGISTER */ |
| 85 | #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) | 81 | #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) |
| 86 | 82 | ||
| @@ -129,7 +125,6 @@ struct dwc3_omap { · 42 unmodified lines | |||
| 129 | u32 irq_eoi_offset; | 125 | u32 irq_eoi_offset; |
| 130 | u32 debug_offset; | 126 | u32 debug_offset; |
| 131 | u32 irq0_offset; | 127 | u32 irq0_offset; |
| 132 | u32 revision; | ||
| 133 | 128 | ||
| 134 | u32 dma_status:1; | 129 | u32 dma_status:1; |
| 135 | 130 | ||
| @@ -383,6 +378,87 @@ static int dwc3_omap_vbus_notifier(struct notifier_block *nb, · 247 unmodified lines | |||
| 383 | return NOTIFY_DONE; | 378 | return NOTIFY_DONE; |
| 384 | } | 379 | } |
| 385 | 380 | ||
| 381 | static void dwc3_omap_map_offset(struct dwc3_omap *omap) | ||
| 382 | { | ||
| 383 | struct device_node *node = omap->dev->of_node; | ||
| 384 | |||
| 385 | /* | ||
| 386 | * Differentiate between OMAP5 and AM437x. | ||
| 387 | * | ||
| 388 | * For OMAP5(ES2.0) and AM437x wrapper revision is same, even | ||
| 389 | * though there are changes in wrapper register offsets. | ||
| 390 | * | ||
| 391 | * Using dt compatible to differentiate AM437x. | ||
| 392 | */ | ||
| 393 | if (of_device_is_compatible(node, "ti,am437x-dwc3")) { | ||
| 394 | omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; | ||
| 395 | omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; | ||
| 396 | omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; | ||
| 397 | omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; | ||
| 398 | omap->debug_offset = USBOTGSS_DEBUG_OFFSET; | ||
| 399 | } | ||
| 400 | } | ||
| 401 | |||
| 402 | static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap) | ||
| 403 | { | ||
| 404 | u32 reg; | ||
| 405 | struct device_node *node = omap->dev->of_node; | ||
| 406 | int utmi_mode = 0; | ||
| 407 | |||
| 408 | reg = dwc3_omap_read_utmi_status(omap); | ||
| 409 | |||
| 410 | of_property_read_u32(node, "utmi-mode", &utmi_mode); | ||
| 411 | |||
| 412 | switch (utmi_mode) { | ||
| 413 | case DWC3_OMAP_UTMI_MODE_SW: | ||
| 414 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | ||
| 415 | break; | ||
| 416 | case DWC3_OMAP_UTMI_MODE_HW: | ||
| 417 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | ||
| 418 | break; | ||
| 419 | default: | ||
| 420 | dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode); | ||
| 421 | } | ||
| 422 | |||
| 423 | dwc3_omap_write_utmi_status(omap, reg); | ||
| 424 | } | ||
| 425 | |||
| 426 | static int dwc3_omap_extcon_register(struct dwc3_omap *omap) | ||
| 427 | { | ||
| 428 | u32 ret; | ||
| 429 | struct device_node *node = omap->dev->of_node; | ||
| 430 | struct extcon_dev *edev; | ||
| 431 | |||
| 432 | if (of_property_read_bool(node, "extcon")) { | ||
| 433 | edev = extcon_get_edev_by_phandle(omap->dev, 0); | ||
| 434 | if (IS_ERR(edev)) { | ||
| 435 | dev_vdbg(omap->dev, "couldn't get extcon device\n"); | ||
| 436 | return -EPROBE_DEFER; | ||
| 437 | } | ||
| 438 | |||
| 439 | omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier; | ||
| 440 | ret = extcon_register_interest(&omap->extcon_vbus_dev, | ||
| 441 | edev->name, "USB", | ||
| 442 | &omap->vbus_nb); | ||
| 443 | if (ret < 0) | ||
| 444 | dev_vdbg(omap->dev, "failed to register notifier for USB\n"); | ||
| 445 | |||
| 446 | omap->id_nb.notifier_call = dwc3_omap_id_notifier; | ||
| 447 | ret = extcon_register_interest(&omap->extcon_id_dev, | ||
| 448 | edev->name, "USB-HOST", | ||
| 449 | &omap->id_nb); | ||
| 450 | if (ret < 0) | ||
| 451 | dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n"); | ||
| 452 | |||
| 453 | if (extcon_get_cable_state(edev, "USB") == true) | ||
| 454 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID); | ||
| 455 | if (extcon_get_cable_state(edev, "USB-HOST") == true) | ||
| 456 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND); | ||
| 457 | } | ||
| 458 | |||
| 459 | return 0; | ||
| 460 | } | ||
| 461 | |||
| 386 | static int dwc3_omap_probe(struct platform_device *pdev) | 462 | static int dwc3_omap_probe(struct platform_device *pdev) |
| 387 | { | 463 | { |
| 388 | struct device_node *node = pdev->dev.of_node; | 464 | struct device_node *node = pdev->dev.of_node; |
| @@ -390,15 +466,11 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 1 unmodified line | |||
| 390 | struct dwc3_omap *omap; | 466 | struct dwc3_omap *omap; |
| 391 | struct resource *res; | 467 | struct resource *res; |
| 392 | struct device *dev = &pdev->dev; | 468 | struct device *dev = &pdev->dev; |
| 393 | struct extcon_dev *edev; | ||
| 394 | struct regulator *vbus_reg = NULL; | 469 | struct regulator *vbus_reg = NULL; |
| 395 | 470 | ||
| 396 | int ret; | 471 | int ret; |
| 397 | int irq; | 472 | int irq; |
| 398 | 473 | ||
| 399 | int utmi_mode = 0; | ||
| 400 | int x_major; | ||
| 401 | |||
| 402 | u32 reg; | 474 | u32 reg; |
| 403 | 475 | ||
| 404 | void __iomem *base; | 476 | void __iomem *base; |
| @@ -448,58 +520,8 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 43 unmodified lines | |||
| 448 | goto err0; | 520 | goto err0; |
| 449 | } | 521 | } |
| 450 | 522 | ||
| 451 | reg = dwc3_omap_readl(omap->base, USBOTGSS_REVISION); | 523 | dwc3_omap_map_offset(omap); |
| 452 | omap->revision = reg; | 524 | dwc3_omap_set_utmi_mode(omap); |
| 453 | x_major = USBOTGSS_REVISION_XMAJOR(reg); | ||
| 454 | |||
| 455 | /* Differentiate between OMAP5 and AM437x */ | ||
| 456 | switch (x_major) { | ||
| 457 | case USBOTGSS_REVISION_XMAJOR1: | ||
| 458 | case USBOTGSS_REVISION_XMAJOR2: | ||
| 459 | omap->irq_eoi_offset = 0; | ||
| 460 | omap->irq0_offset = 0; | ||
| 461 | omap->irqmisc_offset = 0; | ||
| 462 | omap->utmi_otg_offset = 0; | ||
| 463 | omap->debug_offset = 0; | ||
| 464 | break; | ||
| 465 | default: | ||
| 466 | /* Default to the latest revision */ | ||
| 467 | omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; | ||
| 468 | omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; | ||
| 469 | omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; | ||
| 470 | omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; | ||
| 471 | omap->debug_offset = USBOTGSS_DEBUG_OFFSET; | ||
| 472 | break; | ||
| 473 | } | ||
| 474 | |||
| 475 | /* For OMAP5(ES2.0) and AM437x x_major is 2 even though there are | ||
| 476 | * changes in wrapper registers, Using dt compatible for aegis | ||
| 477 | */ | ||
| 478 | |||
| 479 | if (of_device_is_compatible(node, "ti,am437x-dwc3")) { | ||
| 480 | omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; | ||
| 481 | omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; | ||
| 482 | omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; | ||
| 483 | omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; | ||
| 484 | omap->debug_offset = USBOTGSS_DEBUG_OFFSET; | ||
| 485 | } | ||
| 486 | |||
| 487 | reg = dwc3_omap_read_utmi_status(omap); | ||
| 488 | |||
| 489 | of_property_read_u32(node, "utmi-mode", &utmi_mode); | ||
| 490 | |||
| 491 | switch (utmi_mode) { | ||
| 492 | case DWC3_OMAP_UTMI_MODE_SW: | ||
| 493 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | ||
| 494 | break; | ||
| 495 | case DWC3_OMAP_UTMI_MODE_HW: | ||
| 496 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | ||
| 497 | break; | ||
| 498 | default: | ||
| 499 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode); | ||
| 500 | } | ||
| 501 | |||
| 502 | dwc3_omap_write_utmi_status(omap, reg); | ||
| 503 | 525 | ||
| 504 | /* check the DMA Status */ | 526 | /* check the DMA Status */ |
| 505 | reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); | 527 | reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); |
| @@ -515,31 +537,9 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 9 unmodified lines | |||
| 515 | 537 | ||
| 516 | dwc3_omap_enable_irqs(omap); | 538 | dwc3_omap_enable_irqs(omap); |
| 517 | 539 | ||
| 518 | if (of_property_read_bool(node, "extcon")) { | 540 | ret = dwc3_omap_extcon_register(omap); |
| 519 | edev = extcon_get_edev_by_phandle(dev, 0); | 541 | if (ret < 0) |
| 520 | if (IS_ERR(edev)) { | 542 | goto err2; |
| 521 | dev_vdbg(dev, "couldn't get extcon device\n"); | ||
| 522 | ret = -EPROBE_DEFER; | ||
| 523 | goto err2; | ||
| 524 | } | ||
| 525 | |||
| 526 | omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier; | ||
| 527 | ret = extcon_register_interest(&omap->extcon_vbus_dev, | ||
| 528 | edev->name, "USB", &omap->vbus_nb); | ||
| 529 | if (ret < 0) | ||
| 530 | dev_vdbg(dev, "failed to register notifier for USB\n"); | ||
| 531 | omap->id_nb.notifier_call = dwc3_omap_id_notifier; | ||
| 532 | ret = extcon_register_interest(&omap->extcon_id_dev, edev->name, | ||
| 533 | "USB-HOST", &omap->id_nb); | ||
| 534 | if (ret < 0) | ||
| 535 | dev_vdbg(dev, | ||
| 536 | "failed to register notifier for USB-HOST\n"); | ||
| 537 | |||
| 538 | if (extcon_get_cable_state(edev, "USB") == true) | ||
| 539 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID); | ||
| 540 | if (extcon_get_cable_state(edev, "USB-HOST") == true) | ||
| 541 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND); | ||
| 542 | } | ||
| 543 | 543 | ||
| 544 | ret = of_platform_populate(node, NULL, NULL, dev); | 544 | ret = of_platform_populate(node, NULL, NULL, dev); |
| 545 | if (ret) { | 545 | if (ret) { |
| @@ -1971,8 +1971,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, · 1970 unmodified lines | |||
| 1971 | } | 1971 | } |
| 1972 | 1972 | ||
| 1973 | static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc, | 1973 | static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc, |
| 1974 | struct dwc3_ep *dep, const struct dwc3_event_depevt *event, | 1974 | struct dwc3_ep *dep, const struct dwc3_event_depevt *event) |
| 1975 | int start_new) | ||
| 1976 | { | 1975 | { |
| 1977 | unsigned status = 0; | 1976 | unsigned status = 0; |
| 1978 | int clean_busy; | 1977 | int clean_busy; |
| @@ -2039,7 +2038,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, · 60 unmodified lines | |||
| 2039 | return; | 2038 | return; |
| 2040 | } | 2039 | } |
| 2041 | 2040 | ||
| 2042 | dwc3_endpoint_transfer_complete(dwc, dep, event, 1); | 2041 | dwc3_endpoint_transfer_complete(dwc, dep, event); |
| 2043 | break; | 2042 | break; |
| 2044 | case DWC3_DEPEVT_XFERINPROGRESS: | 2043 | case DWC3_DEPEVT_XFERINPROGRESS: |
| 2045 | if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) { | 2044 | if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) { |
| @@ -2048,7 +2047,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, · 2 unmodified lines | |||
| 2048 | return; | 2047 | return; |
| 2049 | } | 2048 | } |
| 2050 | 2049 | ||
| 2051 | dwc3_endpoint_transfer_complete(dwc, dep, event, 0); | 2050 | dwc3_endpoint_transfer_complete(dwc, dep, event); |
| 2052 | break; | 2051 | break; |
| 2053 | case DWC3_DEPEVT_XFERNOTREADY: | 2052 | case DWC3_DEPEVT_XFERNOTREADY: |
| 2054 | if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { | 2053 | if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { |
| @@ -16,12 +16,14 @@ · 15 unmodified lines | |||
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/usb/xhci_pdriver.h> | ||
| 19 | 20 | ||
| 20 | #include "core.h" | 21 | #include "core.h" |
| 21 | 22 | ||
| 22 | int dwc3_host_init(struct dwc3 *dwc) | 23 | int dwc3_host_init(struct dwc3 *dwc) |
| 23 | { | 24 | { |
| 24 | struct platform_device *xhci; | 25 | struct platform_device *xhci; |
| 26 | struct usb_xhci_pdata pdata; | ||
| 25 | int ret; | 27 | int ret; |
| 26 | 28 | ||
| 27 | xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); | 29 | xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); |
| @@ -46,6 +48,18 @@ int dwc3_host_init(struct dwc3 *dwc) · 18 unmodified lines | |||
| 46 | goto err1; | 48 | goto err1; |
| 47 | } | 49 | } |
| 48 | 50 | ||
| 51 | memset(&pdata, 0, sizeof(pdata)); | ||
| 52 | |||
| 53 | #ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE | ||
| 54 | pdata.usb3_lpm_capable = 1; | ||
| 55 | #endif | ||
| 56 | |||
| 57 | ret = platform_device_add_data(xhci, &pdata, sizeof(pdata)); | ||
| 58 | if (ret) { | ||
| 59 | dev_err(dwc->dev, "couldn't add platform data to xHCI device\n"); | ||
| 60 | goto err1; | ||
| 61 | } | ||
| 62 | |||
| 49 | ret = platform_device_add(xhci); | 63 | ret = platform_device_add(xhci); |
| 50 | if (ret) { | 64 | if (ret) { |
| 51 | dev_err(dwc->dev, "failed to register xHCI device\n"); | 65 | dev_err(dwc->dev, "failed to register xHCI device\n"); |
| @@ -127,368 +127,7 @@ config USB_GADGET_STORAGE_NUM_BUFFERS · 126 unmodified lines | |||
| 127 | a module parameter as well. | 127 | a module parameter as well. |
| 128 | If unsure, say 2. | 128 | If unsure, say 2. |
| 129 | 129 | ||
| 130 | # | 130 | source "drivers/usb/gadget/udc/Kconfig" |
| 131 | # USB Peripheral Controller Support | ||
| 132 | # | ||
| 133 | # The order here is alphabetical, except that integrated controllers go | ||
| 134 | # before discrete ones so they will be the initial/default value: | ||
| 135 | # - integrated/SOC controllers first | ||
| 136 | # - licensed IP used in both SOC and discrete versions | ||
| 137 | # - discrete ones (including all PCI-only controllers) | ||
| 138 | # - debug/dummy gadget+hcd is last. | ||
| 139 | # | ||
| 140 | menu "USB Peripheral Controller" | ||
| 141 | |||
| 142 | # | ||
| 143 | # Integrated controllers | ||
| 144 | # | ||
| 145 | |||
| 146 | config USB_AT91 | ||
| 147 | tristate "Atmel AT91 USB Device Port" | ||
| 148 | depends on ARCH_AT91 | ||
| 149 | help | ||
| 150 | Many Atmel AT91 processors (such as the AT91RM2000) have a | ||
| 151 | full speed USB Device Port with support for five configurable | ||
| 152 | endpoints (plus endpoint zero). | ||
| 153 | |||
| 154 | Say "y" to link the driver statically, or "m" to build a | ||
| 155 | dynamically linked module called "at91_udc" and force all | ||
| 156 | gadget drivers to also be dynamically linked. | ||
| 157 | |||
| 158 | config USB_LPC32XX | ||
| 159 | tristate "LPC32XX USB Peripheral Controller" | ||
| 160 | depends on ARCH_LPC32XX && I2C | ||
| 161 | select USB_ISP1301 | ||
| 162 | help | ||
| 163 | This option selects the USB device controller in the LPC32xx SoC. | ||
| 164 | |||
| 165 | Say "y" to link the driver statically, or "m" to build a | ||
| 166 | dynamically linked module called "lpc32xx_udc" and force all | ||
| 167 | gadget drivers to also be dynamically linked. | ||
| 168 | |||
| 169 | config USB_ATMEL_USBA | ||
| 170 | tristate "Atmel USBA" | ||
| 171 | depends on AVR32 || ARCH_AT91 | ||
| 172 | help | ||
| 173 | USBA is the integrated high-speed USB Device controller on | ||
| 174 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. | ||
| 175 | |||
| 176 | config USB_BCM63XX_UDC | ||
| 177 | tristate "Broadcom BCM63xx Peripheral Controller" | ||
| 178 | depends on BCM63XX | ||
| 179 | help | ||
| 180 | Many Broadcom BCM63xx chipsets (such as the BCM6328) have a | ||
| 181 | high speed USB Device Port with support for four fixed endpoints | ||
| 182 | (plus endpoint zero). | ||
| 183 | |||
| 184 | Say "y" to link the driver statically, or "m" to build a | ||
| 185 | dynamically linked module called "bcm63xx_udc". | ||
| 186 | |||
| 187 | config USB_FSL_USB2 | ||
| 188 | tristate "Freescale Highspeed USB DR Peripheral Controller" | ||
| 189 | depends on FSL_SOC || ARCH_MXC | ||
| 190 | select USB_FSL_MPH_DR_OF if OF | ||
| 191 | help | ||
| 192 | Some of Freescale PowerPC and i.MX processors have a High Speed | ||
| 193 | Dual-Role(DR) USB controller, which supports device mode. | ||
| 194 | |||
| 195 | The number of programmable endpoints is different through | ||
| 196 | SOC revisions. | ||
| 197 | |||
| 198 | Say "y" to link the driver statically, or "m" to build a | ||
| 199 | dynamically linked module called "fsl_usb2_udc" and force | ||
| 200 | all gadget drivers to also be dynamically linked. | ||
| 201 | |||
| 202 | config USB_FUSB300 | ||
| 203 | tristate "Faraday FUSB300 USB Peripheral Controller" | ||
| 204 | depends on !PHYS_ADDR_T_64BIT && HAS_DMA | ||
| 205 | help | ||
| 206 | Faraday usb device controller FUSB300 driver | ||
| 207 | |||
| 208 | config USB_FOTG210_UDC | ||
| 209 | depends on HAS_DMA | ||
| 210 | tristate "Faraday FOTG210 USB Peripheral Controller" | ||
| 211 | help | ||
| 212 | Faraday USB2.0 OTG controller which can be configured as | ||
| 213 | high speed or full speed USB device. This driver supppors | ||
| 214 | Bulk Transfer so far. | ||
| 215 | |||
| 216 | Say "y" to link the driver statically, or "m" to build a | ||
| 217 | dynamically linked module called "fotg210_udc". | ||
| 218 | |||
| 219 | config USB_GR_UDC | ||
| 220 | tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" | ||
| 221 | depends on HAS_DMA | ||
| 222 | help | ||
| 223 | Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB | ||
| 224 | VHDL IP core library. | ||
| 225 | |||
| 226 | config USB_OMAP | ||
| 227 | tristate "OMAP USB Device Controller" | ||
| 228 | depends on ARCH_OMAP1 | ||
| 229 | depends on ISP1301_OMAP || !(MACH_OMAP_H2 || MACH_OMAP_H3) | ||
| 230 | help | ||
| 231 | Many Texas Instruments OMAP processors have flexible full | ||
| 232 | speed USB device controllers, with support for up to 30 | ||
| 233 | endpoints (plus endpoint zero). This driver supports the | ||
| 234 | controller in the OMAP 1611, and should work with controllers | ||
| 235 | in other OMAP processors too, given minor tweaks. | ||
| 236 | |||
| 237 | Say "y" to link the driver statically, or "m" to build a | ||
| 238 | dynamically linked module called "omap_udc" and force all | ||
| 239 | gadget drivers to also be dynamically linked. | ||
| 240 | |||
| 241 | config USB_PXA25X | ||
| 242 | tristate "PXA 25x or IXP 4xx" | ||
| 243 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX | ||
| 244 | help | ||
| 245 | Intel's PXA 25x series XScale ARM-5TE processors include | ||
| 246 | an integrated full speed USB 1.1 device controller. The | ||
| 247 | controller in the IXP 4xx series is register-compatible. | ||
| 248 | |||
| 249 | It has fifteen fixed-function endpoints, as well as endpoint | ||
| 250 | zero (for control transfers). | ||
| 251 | |||
| 252 | Say "y" to link the driver statically, or "m" to build a | ||
| 253 | dynamically linked module called "pxa25x_udc" and force all | ||
| 254 | gadget drivers to also be dynamically linked. | ||
| 255 | |||
| 256 | # if there's only one gadget driver, using only two bulk endpoints, | ||
| 257 | # don't waste memory for the other endpoints | ||
| 258 | config USB_PXA25X_SMALL | ||
| 259 | depends on USB_PXA25X | ||
| 260 | bool | ||
| 261 | default n if USB_ETH_RNDIS | ||
| 262 | default y if USB_ZERO | ||
| 263 | default y if USB_ETH | ||
| 264 | default y if USB_G_SERIAL | ||
| 265 | |||
| 266 | config USB_R8A66597 | ||
| 267 | tristate "Renesas R8A66597 USB Peripheral Controller" | ||
| 268 | depends on HAS_DMA | ||
| 269 | help | ||
| 270 | R8A66597 is a discrete USB host and peripheral controller chip that | ||
| 271 | supports both full and high speed USB 2.0 data transfers. | ||
| 272 | It has nine configurable endpoints, and endpoint zero. | ||
| 273 | |||
| 274 | Say "y" to link the driver statically, or "m" to build a | ||
| 275 | dynamically linked module called "r8a66597_udc" and force all | ||
| 276 | gadget drivers to also be dynamically linked. | ||
| 277 | |||
| 278 | config USB_RENESAS_USBHS_UDC | ||
| 279 | tristate 'Renesas USBHS controller' | ||
| 280 | depends on USB_RENESAS_USBHS | ||
| 281 | help | ||
| 282 | Renesas USBHS is a discrete USB host and peripheral controller chip | ||
| 283 | that supports both full and high speed USB 2.0 data transfers. | ||
| 284 | It has nine or more configurable endpoints, and endpoint zero. | ||
| 285 | |||
| 286 | Say "y" to link the driver statically, or "m" to build a | ||
| 287 | dynamically linked module called "renesas_usbhs" and force all | ||
| 288 | gadget drivers to also be dynamically linked. | ||
| 289 | |||
| 290 | config USB_PXA27X | ||
| 291 | tristate "PXA 27x" | ||
| 292 | help | ||
| 293 | Intel's PXA 27x series XScale ARM v5TE processors include | ||
| 294 | an integrated full speed USB 1.1 device controller. | ||
| 295 | |||
| 296 | It has up to 23 endpoints, as well as endpoint zero (for | ||
| 297 | control transfers). | ||
| 298 | |||
| 299 | Say "y" to link the driver statically, or "m" to build a | ||
| 300 | dynamically linked module called "pxa27x_udc" and force all | ||
| 301 | gadget drivers to also be dynamically linked. | ||
| 302 | |||
| 303 | config USB_S3C2410 | ||
| 304 | tristate "S3C2410 USB Device Controller" | ||
| 305 | depends on ARCH_S3C24XX | ||
| 306 | help | ||
| 307 | Samsung's S3C2410 is an ARM-4 processor with an integrated | ||
| 308 | full speed USB 1.1 device controller. It has 4 configurable | ||
| 309 | endpoints, as well as endpoint zero (for control transfers). | ||
| 310 | |||
| 311 | This driver has been tested on the S3C2410, S3C2412, and | ||
| 312 | S3C2440 processors. | ||
| 313 | |||
| 314 | config USB_S3C2410_DEBUG | ||
| 315 | boolean "S3C2410 udc debug messages" | ||
| 316 | depends on USB_S3C2410 | ||
| 317 | |||
| 318 | config USB_S3C_HSUDC | ||
| 319 | tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller" | ||
| 320 | depends on ARCH_S3C24XX | ||
| 321 | help | ||
| 322 | Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC | ||
| 323 | integrated with dual speed USB 2.0 device controller. It has | ||
| 324 | 8 endpoints, as well as endpoint zero. | ||
| 325 | |||
| 326 | This driver has been tested on S3C2416 and S3C2450 processors. | ||
| 327 | |||
| 328 | config USB_MV_UDC | ||
| 329 | tristate "Marvell USB2.0 Device Controller" | ||
| 330 | depends on HAS_DMA | ||
| 331 | help | ||
| 332 | Marvell Socs (including PXA and MMP series) include a high speed | ||
| 333 | USB2.0 OTG controller, which can be configured as high speed or | ||
| 334 | full speed USB peripheral. | ||
| 335 | |||
| 336 | config USB_MV_U3D | ||
| 337 | depends on HAS_DMA | ||
| 338 | tristate "MARVELL PXA2128 USB 3.0 controller" | ||
| 339 | help | ||
| 340 | MARVELL PXA2128 Processor series include a super speed USB3.0 device | ||
| 341 | controller, which support super speed USB peripheral. | ||
| 342 | |||
| 343 | # | ||
| 344 | # Controllers available in both integrated and discrete versions | ||
| 345 | # | ||
| 346 | |||
| 347 | config USB_M66592 | ||
| 348 | tristate "Renesas M66592 USB Peripheral Controller" | ||
| 349 | help | ||
| 350 | M66592 is a discrete USB peripheral controller chip that | ||
| 351 | supports both full and high speed USB 2.0 data transfers. | ||
| 352 | It has seven configurable endpoints, and endpoint zero. | ||
| 353 | |||
| 354 | Say "y" to link the driver statically, or "m" to build a | ||
| 355 | dynamically linked module called "m66592_udc" and force all | ||
| 356 | gadget drivers to also be dynamically linked. | ||
| 357 | |||
| 358 | # | ||
| 359 | # Controllers available only in discrete form (and all PCI controllers) | ||
| 360 | # | ||
| 361 | |||
| 362 | config USB_AMD5536UDC | ||
| 363 | tristate "AMD5536 UDC" | ||
| 364 | depends on PCI | ||
| 365 | help | ||
| 366 | The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. | ||
| 367 | It is a USB Highspeed DMA capable USB device controller. Beside ep0 | ||
| 368 | it provides 4 IN and 4 OUT endpoints (bulk or interrupt type). | ||
| 369 | The UDC port supports OTG operation, and may be used as a host port | ||
| 370 | if it's not being used to implement peripheral or OTG roles. | ||
| 371 | |||
| 372 | Say "y" to link the driver statically, or "m" to build a | ||
| 373 | dynamically linked module called "amd5536udc" and force all | ||
| 374 | gadget drivers to also be dynamically linked. | ||
| 375 | |||
| 376 | config USB_FSL_QE | ||
| 377 | tristate "Freescale QE/CPM USB Device Controller" | ||
| 378 | depends on FSL_SOC && (QUICC_ENGINE || CPM) | ||
| 379 | help | ||
| 380 | Some of Freescale PowerPC processors have a Full Speed | ||
| 381 | QE/CPM2 USB controller, which support device mode with 4 | ||
| 382 | programmable endpoints. This driver supports the | ||
| 383 | controller in the MPC8360 and MPC8272, and should work with | ||
| 384 | controllers having QE or CPM2, given minor tweaks. | ||
| 385 | |||
| 386 | Set CONFIG_USB_GADGET to "m" to build this driver as a | ||
| 387 | dynamically linked module called "fsl_qe_udc". | ||
| 388 | |||
| 389 | config USB_NET2272 | ||
| 390 | tristate "PLX NET2272" | ||
| 391 | help | ||
| 392 | PLX NET2272 is a USB peripheral controller which supports | ||
| 393 | both full and high speed USB 2.0 data transfers. | ||
| 394 | |||
| 395 | It has three configurable endpoints, as well as endpoint zero | ||
| 396 | (for control transfer). | ||
| 397 | Say "y" to link the driver statically, or "m" to build a | ||
| 398 | dynamically linked module called "net2272" and force all | ||
| 399 | gadget drivers to also be dynamically linked. | ||
| 400 | |||
| 401 | config USB_NET2272_DMA | ||
| 402 | boolean "Support external DMA controller" | ||
| 403 | depends on USB_NET2272 && HAS_DMA | ||
| 404 | help | ||
| 405 | The NET2272 part can optionally support an external DMA | ||
| 406 | controller, but your board has to have support in the | ||
| 407 | driver itself. | ||
| 408 | |||
| 409 | If unsure, say "N" here. The driver works fine in PIO mode. | ||
| 410 | |||
| 411 | config USB_NET2280 | ||
| 412 | tristate "NetChip 228x" | ||
| 413 | depends on PCI | ||
| 414 | help | ||
| 415 | NetChip 2280 / 2282 is a PCI based USB peripheral controller which | ||
| 416 | supports both full and high speed USB 2.0 data transfers. | ||
| 417 | |||
| 418 | It has six configurable endpoints, as well as endpoint zero | ||
| 419 | (for control transfers) and several endpoints with dedicated | ||
| 420 | functions. | ||
| 421 | |||
| 422 | Say "y" to link the driver statically, or "m" to build a | ||
| 423 | dynamically linked module called "net2280" and force all | ||
| 424 | gadget drivers to also be dynamically linked. | ||
| 425 | |||
| 426 | config USB_GOKU | ||
| 427 | tristate "Toshiba TC86C001 'Goku-S'" | ||
| 428 | depends on PCI | ||
| 429 | help | ||
| 430 | The Toshiba TC86C001 is a PCI device which includes controllers | ||
| 431 | for full speed USB devices, IDE, I2C, SIO, plus a USB host (OHCI). | ||
| 432 | |||
| 433 | The device controller has three configurable (bulk or interrupt) | ||
| 434 | endpoints, plus endpoint zero (for control transfers). | ||
| 435 | |||
| 436 | Say "y" to link the driver statically, or "m" to build a | ||
| 437 | dynamically linked module called "goku_udc" and to force all | ||
| 438 | gadget drivers to also be dynamically linked. | ||
| 439 | |||
| 440 | config USB_EG20T | ||
| 441 | tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" | ||
| 442 | depends on PCI | ||
| 443 | help | ||
| 444 | This is a USB device driver for EG20T PCH. | ||
| 445 | EG20T PCH is the platform controller hub that is used in Intel's | ||
| 446 | general embedded platform. EG20T PCH has USB device interface. | ||
| 447 | Using this interface, it is able to access system devices connected | ||
| 448 | to USB device. | ||
| 449 | This driver enables USB device function. | ||
| 450 | USB device is a USB peripheral controller which | ||
| 451 | supports both full and high speed USB 2.0 data transfers. | ||
| 452 | This driver supports both control transfer and bulk transfer modes. | ||
| 453 | This driver dose not support interrupt transfer or isochronous | ||
| 454 | transfer modes. | ||
| 455 | |||
| 456 | This driver also can be used for LAPIS Semiconductor's ML7213 which is | ||
| 457 | for IVI(In-Vehicle Infotainment) use. | ||
| 458 | ML7831 is for general purpose use. | ||
| 459 | ML7213/ML7831 is companion chip for Intel Atom E6xx series. | ||
| 460 | ML7213/ML7831 is completely compatible for Intel EG20T PCH. | ||
| 461 | |||
| 462 | # | ||
| 463 | # LAST -- dummy/emulated controller | ||
| 464 | # | ||
| 465 | |||
| 466 | config USB_DUMMY_HCD | ||
| 467 | tristate "Dummy HCD (DEVELOPMENT)" | ||
| 468 | depends on USB=y || (USB=m && USB_GADGET=m) | ||
| 469 | help | ||
| 470 | This host controller driver emulates USB, looping all data transfer | ||
| 471 | requests back to a USB "gadget driver" in the same host. The host | ||
| 472 | side is the master; the gadget side is the slave. Gadget drivers | ||
| 473 | can be high, full, or low speed; and they have access to endpoints | ||
| 474 | like those from NET2280, PXA2xx, or SA1100 hardware. | ||
| 475 | |||
| 476 | This may help in some stages of creating a driver to embed in a | ||
| 477 | Linux device, since it lets you debug several parts of the gadget | ||
| 478 | driver without its hardware or drivers being involved. | ||
| 479 | |||
| 480 | Since such a gadget side driver needs to interoperate with a host | ||
| 481 | side Linux-USB device driver, this may help to debug both sides | ||
| 482 | of a USB protocol stack. | ||
| 483 | |||
| 484 | Say "y" to link the driver statically, or "m" to build a | ||
| 485 | dynamically linked module called "dummy_hcd" and force all | ||
| 486 | gadget drivers to also be dynamically linked. | ||
| 487 | |||
| 488 | # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears | ||
| 489 | # first and will be selected by default. | ||
| 490 | |||
| 491 | endmenu | ||
| 492 | 131 | ||
| 493 | # | 132 | # |
| 494 | # USB Gadget Drivers | 133 | # USB Gadget Drivers |
| @@ -714,466 +353,7 @@ config USB_CONFIGFS_F_FS · 219 unmodified lines | |||
| 714 | implemented in kernel space (for instance Ethernet, serial or | 353 | implemented in kernel space (for instance Ethernet, serial or |
| 715 | mass storage) and other are implemented in user space. | 354 | mass storage) and other are implemented in user space. |
| 716 | 355 | ||
| 717 | config USB_ZERO | 356 | source "drivers/usb/gadget/legacy/Kconfig" |
| 718 | tristate "Gadget Zero (DEVELOPMENT)" | ||
| 719 | select USB_LIBCOMPOSITE | ||
| 720 | select USB_F_SS_LB | ||
| 721 | help | ||
| 722 | Gadget Zero is a two-configuration device. It either sinks and | ||
| 723 | sources bulk data; or it loops back a configurable number of | ||
| 724 | transfers. It also implements control requests, for "chapter 9" | ||
| 725 | conformance. The driver needs only two bulk-capable endpoints, so | ||
| 726 | it can work on top of most device-side usb controllers. It's | ||
| 727 | useful for testing, and is also a working example showing how | ||
| 728 | USB "gadget drivers" can be written. | ||
| 729 | |||
| 730 | Make this be the first driver you try using on top of any new | ||
| 731 | USB peripheral controller driver. Then you can use host-side | ||
| 732 | test software, like the "usbtest" driver, to put your hardware | ||
| 733 | and its driver through a basic set of functional tests. | ||
| 734 | |||
| 735 | Gadget Zero also works with the host-side "usb-skeleton" driver, | ||
| 736 | and with many kinds of host-side test software. You may need | ||
| 737 | to tweak product and vendor IDs before host software knows about | ||
| 738 | this device, and arrange to select an appropriate configuration. | ||
| 739 | |||
| 740 | Say "y" to link the driver statically, or "m" to build a | ||
| 741 | dynamically linked module called "g_zero". | ||
| 742 | |||
| 743 | config USB_ZERO_HNPTEST | ||
| 744 | boolean "HNP Test Device" | ||
| 745 | depends on USB_ZERO && USB_OTG | ||
| 746 | help | ||
| 747 | You can configure this device to enumerate using the device | ||
| 748 | identifiers of the USB-OTG test device. That means that when | ||
| 749 | this gadget connects to another OTG device, with this one using | ||
| 750 | the "B-Peripheral" role, that device will use HNP to let this | ||
| 751 | one serve as the USB host instead (in the "B-Host" role). | ||
| 752 | |||
| 753 | config USB_AUDIO | ||
| 754 | tristate "Audio Gadget" | ||
| 755 | depends on SND | ||
| 756 | select USB_LIBCOMPOSITE | ||
| 757 | select SND_PCM | ||
| 758 | help | ||
| 759 | This Gadget Audio driver is compatible with USB Audio Class | ||
| 760 | specification 2.0. It implements 1 AudioControl interface, | ||
| 761 | 1 AudioStreaming Interface each for USB-OUT and USB-IN. | ||
| 762 | Number of channels, sample rate and sample size can be | ||
| 763 | specified as module parameters. | ||
| 764 | This driver doesn't expect any real Audio codec to be present | ||
| 765 | on the device - the audio streams are simply sinked to and | ||
| 766 | sourced from a virtual ALSA sound card created. The user-space | ||
| 767 | application may choose to do whatever it wants with the data | ||
| 768 | received from the USB Host and choose to provide whatever it | ||
| 769 | wants as audio data to the USB Host. | ||
| 770 | |||
| 771 | Say "y" to link the driver statically, or "m" to build a | ||
| 772 | dynamically linked module called "g_audio". | ||
| 773 | |||
| 774 | config GADGET_UAC1 | ||
| 775 | bool "UAC 1.0 (Legacy)" | ||
| 776 | depends on USB_AUDIO | ||
| 777 | help | ||
| 778 | If you instead want older UAC Spec-1.0 driver that also has audio | ||
| 779 | paths hardwired to the Audio codec chip on-board and doesn't work | ||
| 780 | without one. | ||
| 781 | |||
| 782 | config USB_ETH | ||
| 783 | tristate "Ethernet Gadget (with CDC Ethernet support)" | ||
| 784 | depends on NET | ||
| 785 | select USB_LIBCOMPOSITE | ||
| 786 | select USB_U_ETHER | ||
| 787 | select USB_F_ECM | ||
| 788 | select USB_F_SUBSET | ||
| 789 | select CRC32 | ||
| 790 | help | ||
| 791 | This driver implements Ethernet style communication, in one of | ||
| 792 | several ways: | ||
| 793 | |||
| 794 | - The "Communication Device Class" (CDC) Ethernet Control Model. | ||
| 795 | That protocol is often avoided with pure Ethernet adapters, in | ||
| 796 | favor of simpler vendor-specific hardware, but is widely | ||
| 797 | supported by firmware for smart network devices. | ||
| 798 | |||
| 799 | - On hardware can't implement that protocol, a simple CDC subset | ||
| 800 | is used, placing fewer demands on USB. | ||
| 801 | |||
| 802 | - CDC Ethernet Emulation Model (EEM) is a newer standard that has | ||
| 803 | a simpler interface that can be used by more USB hardware. | ||
| 804 | |||
| 805 | RNDIS support is an additional option, more demanding than than | ||
| 806 | subset. | ||
| 807 | |||
| 808 | Within the USB device, this gadget driver exposes a network device | ||
| 809 | "usbX", where X depends on what other networking devices you have. | ||
| 810 | Treat it like a two-node Ethernet link: host, and gadget. | ||
| 811 | |||
| 812 | The Linux-USB host-side "usbnet" driver interoperates with this | ||
| 813 | driver, so that deep I/O queues can be supported. On 2.4 kernels, | ||
| 814 | use "CDCEther" instead, if you're using the CDC option. That CDC | ||
| 815 | mode should also interoperate with standard CDC Ethernet class | ||
| 816 | drivers on other host operating systems. | ||
| 817 | |||
| 818 | Say "y" to link the driver statically, or "m" to build a | ||
| 819 | dynamically linked module called "g_ether". | ||
| 820 | |||
| 821 | config USB_ETH_RNDIS | ||
| 822 | bool "RNDIS support" | ||
| 823 | depends on USB_ETH | ||
| 824 | select USB_LIBCOMPOSITE | ||
| 825 | select USB_F_RNDIS | ||
| 826 | default y | ||
| 827 | help | ||
| 828 | Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, | ||
| 829 | and Microsoft provides redistributable binary RNDIS drivers for | ||
| 830 | older versions of Windows. | ||
| 831 | |||
| 832 | If you say "y" here, the Ethernet gadget driver will try to provide | ||
| 833 | a second device configuration, supporting RNDIS to talk to such | ||
| 834 | Microsoft USB hosts. | ||
| 835 | |||
| 836 | To make MS-Windows work with this, use Documentation/usb/linux.inf | ||
| 837 | as the "driver info file". For versions of MS-Windows older than | ||
| 838 | XP, you'll need to download drivers from Microsoft's website; a URL | ||
| 839 | is given in comments found in that info file. | ||
| 840 | |||
| 841 | config USB_ETH_EEM | ||
| 842 | bool "Ethernet Emulation Model (EEM) support" | ||
| 843 | depends on USB_ETH | ||
| 844 | select USB_LIBCOMPOSITE | ||
| 845 | select USB_F_EEM | ||
| 846 | default n | ||
| 847 | help | ||
| 848 | CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM | ||
| 849 | and therefore can be supported by more hardware. Technically ECM and | ||
| 850 | EEM are designed for different applications. The ECM model extends | ||
| 851 | the network interface to the target (e.g. a USB cable modem), and the | ||
| 852 | EEM model is for mobile devices to communicate with hosts using | ||
| 853 | ethernet over USB. For Linux gadgets, however, the interface with | ||
| 854 | the host is the same (a usbX device), so the differences are minimal. | ||
| 855 | |||
| 856 | If you say "y" here, the Ethernet gadget driver will use the EEM | ||
| 857 | protocol rather than ECM. If unsure, say "n". | ||
| 858 | |||
| 859 | config USB_G_NCM | ||
| 860 | tristate "Network Control Model (NCM) support" | ||
| 861 | depends on NET | ||
| 862 | select USB_LIBCOMPOSITE | ||
| 863 | select USB_U_ETHER | ||
| 864 | select USB_F_NCM | ||
| 865 | select CRC32 | ||
| 866 | help | ||
| 867 | This driver implements USB CDC NCM subclass standard. NCM is | ||
| 868 | an advanced protocol for Ethernet encapsulation, allows grouping | ||
| 869 | of several ethernet frames into one USB transfer and different | ||
| 870 | alignment possibilities. | ||
| 871 | |||
| 872 | Say "y" to link the driver statically, or "m" to build a | ||
| 873 | dynamically linked module called "g_ncm". | ||
| 874 | |||
| 875 | config USB_GADGETFS | ||
| 876 | tristate "Gadget Filesystem" | ||
| 877 | help | ||
| 878 | This driver provides a filesystem based API that lets user mode | ||
| 879 | programs implement a single-configuration USB device, including | ||
| 880 | endpoint I/O and control requests that don't relate to enumeration. | ||
| 881 | All endpoints, transfer speeds, and transfer types supported by | ||
| 882 | the hardware are available, through read() and write() calls. | ||
| 883 | |||
| 884 | Say "y" to link the driver statically, or "m" to build a | ||
| 885 | dynamically linked module called "gadgetfs". | ||
| 886 | |||
| 887 | config USB_FUNCTIONFS | ||
| 888 | tristate "Function Filesystem" | ||
| 889 | select USB_LIBCOMPOSITE | ||
| 890 | select USB_F_FS | ||
| 891 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) | ||
| 892 | help | ||
| 893 | The Function Filesystem (FunctionFS) lets one create USB | ||
| 894 | composite functions in user space in the same way GadgetFS | ||
| 895 | lets one create USB gadgets in user space. This allows creation | ||
| 896 | of composite gadgets such that some of the functions are | ||
| 897 | implemented in kernel space (for instance Ethernet, serial or | ||
| 898 | mass storage) and other are implemented in user space. | ||
| 899 | |||
| 900 | If you say "y" or "m" here you will be able what kind of | ||
| 901 | configurations the gadget will provide. | ||
| 902 | |||
| 903 | Say "y" to link the driver statically, or "m" to build | ||
| 904 | a dynamically linked module called "g_ffs". | ||
| 905 | |||
| 906 | config USB_FUNCTIONFS_ETH | ||
| 907 | bool "Include configuration with CDC ECM (Ethernet)" | ||
| 908 | depends on USB_FUNCTIONFS && NET | ||
| 909 | select USB_U_ETHER | ||
| 910 | select USB_F_ECM | ||
| 911 | select USB_F_SUBSET | ||
| 912 | help | ||
| 913 | Include a configuration with CDC ECM function (Ethernet) and the | ||
| 914 | Function Filesystem. | ||
| 915 | |||
| 916 | config USB_FUNCTIONFS_RNDIS | ||
| 917 | bool "Include configuration with RNDIS (Ethernet)" | ||
| 918 | depends on USB_FUNCTIONFS && NET | ||
| 919 | select USB_U_ETHER | ||
| 920 | select USB_F_RNDIS | ||
| 921 | help | ||
| 922 | Include a configuration with RNDIS function (Ethernet) and the Filesystem. | ||
| 923 | |||
| 924 | config USB_FUNCTIONFS_GENERIC | ||
| 925 | bool "Include 'pure' configuration" | ||
| 926 | depends on USB_FUNCTIONFS | ||
| 927 | help | ||
| 928 | Include a configuration with the Function Filesystem alone with | ||
| 929 | no Ethernet interface. | ||
| 930 | |||
| 931 | config USB_MASS_STORAGE | ||
| 932 | tristate "Mass Storage Gadget" | ||
| 933 | depends on BLOCK | ||
| 934 | select USB_LIBCOMPOSITE | ||
| 935 | select USB_F_MASS_STORAGE | ||
| 936 | help | ||
| 937 | The Mass Storage Gadget acts as a USB Mass Storage disk drive. | ||
| 938 | As its storage repository it can use a regular file or a block | ||
| 939 | device (in much the same way as the "loop" device driver), | ||
| 940 | specified as a module parameter or sysfs option. | ||
| 941 | |||
| 942 | This driver is a replacement for now removed File-backed | ||
| 943 | Storage Gadget (g_file_storage). | ||
| 944 | |||
| 945 | Say "y" to link the driver statically, or "m" to build | ||
| 946 | a dynamically linked module called "g_mass_storage". | ||
| 947 | |||
| 948 | config USB_GADGET_TARGET | ||
| 949 | tristate "USB Gadget Target Fabric Module" | ||
| 950 | depends on TARGET_CORE | ||
| 951 | select USB_LIBCOMPOSITE | ||
| 952 | help | ||
| 953 | This fabric is an USB gadget. Two USB protocols are supported that is | ||
| 954 | BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is | ||
| 955 | advertised on alternative interface 0 (primary) and UAS is on | ||
| 956 | alternative interface 1. Both protocols can work on USB2.0 and USB3.0. | ||
| 957 | UAS utilizes the USB 3.0 feature called streams support. | ||
| 958 | |||
| 959 | config USB_G_SERIAL | ||
| 960 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" | ||
| 961 | depends on TTY | ||
| 962 | select USB_U_SERIAL | ||
| 963 | select USB_F_ACM | ||
| 964 | select USB_F_SERIAL | ||
| 965 | select USB_F_OBEX | ||
| 966 | select USB_LIBCOMPOSITE | ||
| 967 | help | ||
| 968 | The Serial Gadget talks to the Linux-USB generic serial driver. | ||
| 969 | This driver supports a CDC-ACM module option, which can be used | ||
| 970 | to interoperate with MS-Windows hosts or with the Linux-USB | ||
| 971 | "cdc-acm" driver. | ||
| 972 | |||
| 973 | This driver also supports a CDC-OBEX option. You will need a | ||
| 974 | user space OBEX server talking to /dev/ttyGS*, since the kernel | ||
| 975 | itself doesn't implement the OBEX protocol. | ||
| 976 | |||
| 977 | Say "y" to link the driver statically, or "m" to build a | ||
| 978 | dynamically linked module called "g_serial". | ||
| 979 | |||
| 980 | For more information, see Documentation/usb/gadget_serial.txt | ||
| 981 | which includes instructions and a "driver info file" needed to | ||
| 982 | make MS-Windows work with CDC ACM. | ||
| 983 | |||
| 984 | config USB_MIDI_GADGET | ||
| 985 | tristate "MIDI Gadget" | ||
| 986 | depends on SND | ||
| 987 | select USB_LIBCOMPOSITE | ||
| 988 | select SND_RAWMIDI | ||
| 989 | help | ||
| 990 | The MIDI Gadget acts as a USB Audio device, with one MIDI | ||
| 991 | input and one MIDI output. These MIDI jacks appear as | ||
| 992 | a sound "card" in the ALSA sound system. Other MIDI | ||
| 993 | connections can then be made on the gadget system, using | ||
| 994 | ALSA's aconnect utility etc. | ||
| 995 | |||
| 996 | Say "y" to link the driver statically, or "m" to build a | ||
| 997 | dynamically linked module called "g_midi". | ||
| 998 | |||
| 999 | config USB_G_PRINTER | ||
| 1000 | tristate "Printer Gadget" | ||
| 1001 | select USB_LIBCOMPOSITE | ||
| 1002 | help | ||
| 1003 | The Printer Gadget channels data between the USB host and a | ||
| 1004 | userspace program driving the print engine. The user space | ||
| 1005 | program reads and writes the device file /dev/g_printer to | ||
| 1006 | receive or send printer data. It can use ioctl calls to | ||
| 1007 | the device file to get or set printer status. | ||
| 1008 | |||
| 1009 | Say "y" to link the driver statically, or "m" to build a | ||
| 1010 | dynamically linked module called "g_printer". | ||
| 1011 | |||
| 1012 | For more information, see Documentation/usb/gadget_printer.txt | ||
| 1013 | which includes sample code for accessing the device file. | ||
| 1014 | |||
| 1015 | if TTY | ||
| 1016 | |||
| 1017 | config USB_CDC_COMPOSITE | ||
| 1018 | tristate "CDC Composite Device (Ethernet and ACM)" | ||
| 1019 | depends on NET | ||
| 1020 | select USB_LIBCOMPOSITE | ||
| 1021 | select USB_U_SERIAL | ||
| 1022 | select USB_U_ETHER | ||
| 1023 | select USB_F_ACM | ||
| 1024 | select USB_F_ECM | ||
| 1025 | help | ||
| 1026 | This driver provides two functions in one configuration: | ||
| 1027 | a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link. | ||
| 1028 | |||
| 1029 | This driver requires four bulk and two interrupt endpoints, | ||
| 1030 | plus the ability to handle altsettings. Not all peripheral | ||
| 1031 | controllers are that capable. | ||
| 1032 | |||
| 1033 | Say "y" to link the driver statically, or "m" to build a | ||
| 1034 | dynamically linked module. | ||
| 1035 | |||
| 1036 | config USB_G_NOKIA | ||
| 1037 | tristate "Nokia composite gadget" | ||
| 1038 | depends on PHONET | ||
| 1039 | select USB_LIBCOMPOSITE | ||
| 1040 | select USB_U_SERIAL | ||
| 1041 | select USB_U_ETHER | ||
| 1042 | select USB_F_ACM | ||
| 1043 | select USB_F_OBEX | ||
| 1044 | select USB_F_PHONET | ||
| 1045 | select USB_F_ECM | ||
| 1046 | help | ||
| 1047 | The Nokia composite gadget provides support for acm, obex | ||
| 1048 | and phonet in only one composite gadget driver. | ||
| 1049 | |||
| 1050 | It's only really useful for N900 hardware. If you're building | ||
| 1051 | a kernel for N900, say Y or M here. If unsure, say N. | ||
| 1052 | |||
| 1053 | config USB_G_ACM_MS | ||
| 1054 | tristate "CDC Composite Device (ACM and mass storage)" | ||
| 1055 | depends on BLOCK | ||
| 1056 | select USB_LIBCOMPOSITE | ||
| 1057 | select USB_U_SERIAL | ||
| 1058 | select USB_F_ACM | ||
| 1059 | select USB_F_MASS_STORAGE | ||
| 1060 | help | ||
| 1061 | This driver provides two functions in one configuration: | ||
| 1062 | a mass storage, and a CDC ACM (serial port) link. | ||
| 1063 | |||
| 1064 | Say "y" to link the driver statically, or "m" to build a | ||
| 1065 | dynamically linked module called "g_acm_ms". | ||
| 1066 | |||
| 1067 | config USB_G_MULTI | ||
| 1068 | tristate "Multifunction Composite Gadget" | ||
| 1069 | depends on BLOCK && NET | ||
| 1070 | select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS | ||
| 1071 | select USB_LIBCOMPOSITE | ||
| 1072 | select USB_U_SERIAL | ||
| 1073 | select USB_U_ETHER | ||
| 1074 | select USB_F_ACM | ||
| 1075 | select USB_F_MASS_STORAGE | ||
| 1076 | help | ||
| 1077 | The Multifunction Composite Gadget provides Ethernet (RNDIS | ||
| 1078 | and/or CDC Ethernet), mass storage and ACM serial link | ||
| 1079 | interfaces. | ||
| 1080 | |||
| 1081 | You will be asked to choose which of the two configurations is | ||
| 1082 | to be available in the gadget. At least one configuration must | ||
| 1083 | be chosen to make the gadget usable. Selecting more than one | ||
| 1084 | configuration will prevent Windows from automatically detecting | ||
| 1085 | the gadget as a composite gadget, so an INF file will be needed to | ||
| 1086 | use the gadget. | ||
| 1087 | |||
| 1088 | Say "y" to link the driver statically, or "m" to build a | ||
| 1089 | dynamically linked module called "g_multi". | ||
| 1090 | |||
| 1091 | config USB_G_MULTI_RNDIS | ||
| 1092 | bool "RNDIS + CDC Serial + Storage configuration" | ||
| 1093 | depends on USB_G_MULTI | ||
| 1094 | select USB_F_RNDIS | ||
| 1095 | default y | ||
| 1096 | help | ||
| 1097 | This option enables a configuration with RNDIS, CDC Serial and | ||
| 1098 | Mass Storage functions available in the Multifunction Composite | ||
| 1099 | Gadget. This is the configuration dedicated for Windows since RNDIS | ||
| 1100 | is Microsoft's protocol. | ||
| 1101 | |||
| 1102 | If unsure, say "y". | ||
| 1103 | |||
| 1104 | config USB_G_MULTI_CDC | ||
| 1105 | bool "CDC Ethernet + CDC Serial + Storage configuration" | ||
| 1106 | depends on USB_G_MULTI | ||
| 1107 | default n | ||
| 1108 | select USB_F_ECM | ||
| 1109 | help | ||
| 1110 | This option enables a configuration with CDC Ethernet (ECM), CDC | ||
| 1111 | Serial and Mass Storage functions available in the Multifunction | ||
| 1112 | Composite Gadget. | ||
| 1113 | |||
| 1114 | If unsure, say "y". | ||
| 1115 | |||
| 1116 | endif # TTY | ||
| 1117 | |||
| 1118 | config USB_G_HID | ||
| 1119 | tristate "HID Gadget" | ||
| 1120 | select USB_LIBCOMPOSITE | ||
| 1121 | help | ||
| 1122 | The HID gadget driver provides generic emulation of USB | ||
| 1123 | Human Interface Devices (HID). | ||
| 1124 | |||
| 1125 | For more information, see Documentation/usb/gadget_hid.txt which | ||
| 1126 | includes sample code for accessing the device files. | ||
| 1127 | |||
| 1128 | Say "y" to link the driver statically, or "m" to build a | ||
| 1129 | dynamically linked module called "g_hid". | ||
| 1130 | |||
| 1131 | # Standalone / single function gadgets | ||
| 1132 | config USB_G_DBGP | ||
| 1133 | tristate "EHCI Debug Device Gadget" | ||
| 1134 | depends on TTY | ||
| 1135 | select USB_LIBCOMPOSITE | ||
| 1136 | help | ||
| 1137 | This gadget emulates an EHCI Debug device. This is useful when you want | ||
| 1138 | to interact with an EHCI Debug Port. | ||
| 1139 | |||
| 1140 | Say "y" to link the driver statically, or "m" to build a | ||
| 1141 | dynamically linked module called "g_dbgp". | ||
| 1142 | |||
| 1143 | if USB_G_DBGP | ||
| 1144 | choice | ||
| 1145 | prompt "EHCI Debug Device mode" | ||
| 1146 | default USB_G_DBGP_SERIAL | ||
| 1147 | |||
| 1148 | config USB_G_DBGP_PRINTK | ||
| 1149 | depends on USB_G_DBGP | ||
| 1150 | bool "printk" | ||
| 1151 | help | ||
| 1152 | Directly printk() received data. No interaction. | ||
| 1153 | |||
| 1154 | config USB_G_DBGP_SERIAL | ||
| 1155 | depends on USB_G_DBGP | ||
| 1156 | select USB_U_SERIAL | ||
| 1157 | bool "serial" | ||
| 1158 | help | ||
| 1159 | Userland can interact using /dev/ttyGSxxx. | ||
| 1160 | endchoice | ||
| 1161 | endif | ||
| 1162 | |||
| 1163 | # put drivers that need isochronous transfer support (for audio | ||
| 1164 | # or video class gadget drivers), or specific hardware, here. | ||
| 1165 | config USB_G_WEBCAM | ||
| 1166 | tristate "USB Webcam Gadget" | ||
| 1167 | depends on VIDEO_DEV | ||
| 1168 | select USB_LIBCOMPOSITE | ||
| 1169 | select VIDEOBUF2_VMALLOC | ||
| 1170 | help | ||
| 1171 | The Webcam Gadget acts as a composite USB Audio and Video Class | ||
| 1172 | device. It provides a userspace API to process UVC control requests | ||
| 1173 | and stream video data to the host. | ||
| 1174 | |||
| 1175 | Say "y" to link the driver statically, or "m" to build a | ||
| 1176 | dynamically linked module called "g_webcam". | ||
| 1177 | 357 | ||
| 1178 | endchoice | 358 | endchoice |
| 1179 | 359 | ||
| @@ -1,105 +1,12 @@ | |||
| 1 | # | 1 | # |
| 2 | # USB peripheral controller drivers | 2 | # USB peripheral controller drivers |
| 3 | # | 3 | # |
| 4 | ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG | 4 | subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG |
| 5 | ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG | 5 | subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG |
| 6 | ccflags-y += -I$(PWD)/drivers/usb/gadget/udc | ||
| 6 | 7 | ||
| 7 | obj-$(CONFIG_USB_GADGET) += udc-core.o | ||
| 8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o | 8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o |
| 9 | libcomposite-y := usbstring.o config.o epautoconf.o | 9 | libcomposite-y := usbstring.o config.o epautoconf.o |
| 10 | libcomposite-y += composite.o functions.o configfs.o u_f.o | 10 | libcomposite-y += composite.o functions.o configfs.o u_f.o |
| 11 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | ||
| 12 | obj-$(CONFIG_USB_NET2272) += net2272.o | ||
| 13 | obj-$(CONFIG_USB_NET2280) += net2280.o | ||
| 14 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o | ||
| 15 | obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o | ||
| 16 | obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o | ||
| 17 | obj-$(CONFIG_USB_GOKU) += goku_udc.o | ||
| 18 | obj-$(CONFIG_USB_OMAP) += omap_udc.o | ||
| 19 | obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o | ||
| 20 | obj-$(CONFIG_USB_AT91) += at91_udc.o | ||
| 21 | obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o | ||
| 22 | obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o | ||
| 23 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o | ||
| 24 | fsl_usb2_udc-y := fsl_udc_core.o | ||
| 25 | fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o | ||
| 26 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | ||
| 27 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | ||
| 28 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | ||
| 29 | obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o | ||
| 30 | obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o | ||
| 31 | obj-$(CONFIG_USB_EG20T) += pch_udc.o | ||
| 32 | obj-$(CONFIG_USB_MV_UDC) += mv_udc.o | ||
| 33 | mv_udc-y := mv_udc_core.o | ||
| 34 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | ||
| 35 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o | ||
| 36 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | ||
| 37 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o | ||
| 38 | 11 | ||
| 39 | # USB Functions | 12 | obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/ |
| 40 | usb_f_acm-y := f_acm.o | ||
| 41 | obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o | ||
| 42 | usb_f_ss_lb-y := f_loopback.o f_sourcesink.o | ||
| 43 | obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o | ||
| 44 | obj-$(CONFIG_USB_U_SERIAL) += u_serial.o | ||
| 45 | usb_f_serial-y := f_serial.o | ||
| 46 | obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o | ||
| 47 | usb_f_obex-y := f_obex.o | ||
| 48 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o | ||
| 49 | obj-$(CONFIG_USB_U_ETHER) += u_ether.o | ||
| 50 | usb_f_ncm-y := f_ncm.o | ||
| 51 | obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o | ||
| 52 | usb_f_ecm-y := f_ecm.o | ||
| 53 | obj-$(CONFIG_USB_F_ECM) += usb_f_ecm.o | ||
| 54 | usb_f_phonet-y := f_phonet.o | ||
| 55 | obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o | ||
| 56 | usb_f_eem-y := f_eem.o | ||
| 57 | obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o | ||
| 58 | usb_f_ecm_subset-y := f_subset.o | ||
| 59 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o | ||
| 60 | usb_f_rndis-y := f_rndis.o rndis.o | ||
| 61 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o | ||
| 62 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o | ||
| 63 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | ||
| 64 | usb_f_fs-y := f_fs.o | ||
| 65 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o | ||
| 66 | |||
| 67 | # | ||
| 68 | # USB gadget drivers | ||
| 69 | # | ||
| 70 | g_zero-y := zero.o | ||
| 71 | g_audio-y := audio.o | ||
| 72 | g_ether-y := ether.o | ||
| 73 | g_serial-y := serial.o | ||
| 74 | g_midi-y := gmidi.o | ||
| 75 | gadgetfs-y := inode.o | ||
| 76 | g_mass_storage-y := mass_storage.o | ||
| 77 | g_printer-y := printer.o | ||
| 78 | g_cdc-y := cdc2.o | ||
| 79 | g_multi-y := multi.o | ||
| 80 | g_hid-y := hid.o | ||
| 81 | g_dbgp-y := dbgp.o | ||
| 82 | g_nokia-y := nokia.o | ||
| 83 | g_webcam-y := webcam.o | ||
| 84 | g_ncm-y := ncm.o | ||
| 85 | g_acm_ms-y := acm_ms.o | ||
| 86 | g_tcm_usb_gadget-y := tcm_usb_gadget.o | ||
| 87 | |||
| 88 | obj-$(CONFIG_USB_ZERO) += g_zero.o | ||
| 89 | obj-$(CONFIG_USB_AUDIO) += g_audio.o | ||
| 90 | obj-$(CONFIG_USB_ETH) += g_ether.o | ||
| 91 | obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o | ||
| 92 | obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o | ||
| 93 | obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o | ||
| 94 | obj-$(CONFIG_USB_G_SERIAL) += g_serial.o | ||
| 95 | obj-$(CONFIG_USB_G_PRINTER) += g_printer.o | ||
| 96 | obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o | ||
| 97 | obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o | ||
| 98 | obj-$(CONFIG_USB_G_HID) += g_hid.o | ||
| 99 | obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o | ||
| 100 | obj-$(CONFIG_USB_G_MULTI) += g_multi.o | ||
| 101 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o | ||
| 102 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o | ||
| 103 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o | ||
| 104 | obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o | ||
| 105 | obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o | ||
| @@ -1956,6 +1956,7 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) · 1955 unmodified lines | |||
| 1956 | } | 1956 | } |
| 1957 | if (cdev->req) { | 1957 | if (cdev->req) { |
| 1958 | kfree(cdev->req->buf); | 1958 | kfree(cdev->req->buf); |
| 1959 | usb_ep_dequeue(cdev->gadget->ep0, cdev->req); | ||
| 1959 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); | 1960 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); |
| 1960 | } | 1961 | } |
| 1961 | cdev->next_string_id = 0; | 1962 | cdev->next_string_id = 0; |
| @@ -1021,12 +1021,10 @@ static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop, · 1020 unmodified lines | |||
| 1021 | 1021 | ||
| 1022 | if (page[len - 1] == '\n' || page[len - 1] == '\0') | 1022 | if (page[len - 1] == '\n' || page[len - 1] == '\0') |
| 1023 | --len; | 1023 | --len; |
| 1024 | new_data = kzalloc(len, GFP_KERNEL); | 1024 | new_data = kmemdup(page, len, GFP_KERNEL); |
| 1025 | if (!new_data) | 1025 | if (!new_data) |
| 1026 | return -ENOMEM; | 1026 | return -ENOMEM; |
| 1027 | 1027 | ||
| 1028 | memcpy(new_data, page, len); | ||
| 1029 | |||
| 1030 | if (desc->opts_mutex) | 1028 | if (desc->opts_mutex) |
| 1031 | mutex_lock(desc->opts_mutex); | 1029 | mutex_lock(desc->opts_mutex); |
| 1032 | kfree(ext_prop->data); | 1030 | kfree(ext_prop->data); |
| @@ -0,0 +1,34 @@ | |||
| 1 | # | ||
| 2 | # USB peripheral controller drivers | ||
| 3 | # | ||
| 4 | |||
| 5 | ccflags-y := -I$(PWD)/drivers/usb/gadget/ | ||
| 6 | ccflags-y += -I$(PWD)/drivers/usb/gadget/udc/ | ||
| 7 | |||
| 8 | # USB Functions | ||
| 9 | usb_f_acm-y := f_acm.o | ||
| 10 | obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o | ||
| 11 | usb_f_ss_lb-y := f_loopback.o f_sourcesink.o | ||
| 12 | obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o | ||
| 13 | obj-$(CONFIG_USB_U_SERIAL) += u_serial.o | ||
| 14 | usb_f_serial-y := f_serial.o | ||
| 15 | obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o | ||
| 16 | usb_f_obex-y := f_obex.o | ||
| 17 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o | ||
| 18 | obj-$(CONFIG_USB_U_ETHER) += u_ether.o | ||
| 19 | usb_f_ncm-y := f_ncm.o | ||
| 20 | obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o | ||
| 21 | usb_f_ecm-y := f_ecm.o | ||
| 22 | obj-$(CONFIG_USB_F_ECM) += usb_f_ecm.o | ||
| 23 | usb_f_phonet-y := f_phonet.o | ||
| 24 | obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o | ||
| 25 | usb_f_eem-y := f_eem.o | ||
| 26 | obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o | ||
| 27 | usb_f_ecm_subset-y := f_subset.o | ||
| 28 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o | ||
| 29 | usb_f_rndis-y := f_rndis.o rndis.o | ||
| 30 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o | ||
| 31 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o | ||
| 32 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | ||
| 33 | usb_f_fs-y := f_fs.o | ||
| 34 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o | ||
File renamed without changes.
File renamed without changes.
| @@ -355,20 +355,18 @@ static struct sk_buff *eem_wrap(struct gether *port, struct sk_buff *skb) · 354 unmodified lines | |||
| 355 | int padlen = 0; | 355 | int padlen = 0; |
| 356 | u16 len = skb->len; | 356 | u16 len = skb->len; |
| 357 | 357 | ||
| 358 | if (!skb_cloned(skb)) { | 358 | int headroom = skb_headroom(skb); |
| 359 | int headroom = skb_headroom(skb); | 359 | int tailroom = skb_tailroom(skb); |
| 360 | int tailroom = skb_tailroom(skb); | ||
| 361 | 360 | ||
| 362 | /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0, | 361 | /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0, |
| 363 | * stick two bytes of zero-length EEM packet on the end. | 362 | * stick two bytes of zero-length EEM packet on the end. |
| 364 | */ | 363 | */ |
| 365 | if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0) | 364 | if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0) |
| 366 | padlen += 2; | 365 | padlen += 2; |
| 367 | 366 | ||
| 368 | if ((tailroom >= (ETH_FCS_LEN + padlen)) && | 367 | if ((tailroom >= (ETH_FCS_LEN + padlen)) && |
| 369 | (headroom >= EEM_HLEN)) | 368 | (headroom >= EEM_HLEN) && !skb_cloned(skb)) |
| 370 | goto done; | 369 | goto done; |
| 371 | } | ||
| 372 | 370 | ||
| 373 | skb2 = skb_copy_expand(skb, EEM_HLEN, ETH_FCS_LEN + padlen, GFP_ATOMIC); | 371 | skb2 = skb_copy_expand(skb, EEM_HLEN, ETH_FCS_LEN + padlen, GFP_ATOMIC); |
| 374 | dev_kfree_skb_any(skb); | 372 | dev_kfree_skb_any(skb); |
| @@ -34,6 +34,7 @@ · 33 unmodified lines | |||
| 34 | 34 | ||
| 35 | #include "u_fs.h" | 35 | #include "u_fs.h" |
| 36 | #include "u_f.h" | 36 | #include "u_f.h" |
| 37 | #include "u_os_desc.h" | ||
| 37 | #include "configfs.h" | 38 | #include "configfs.h" |
| 38 | 39 | ||
| 39 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ | 40 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ |
| @@ -1646,13 +1647,22 @@ enum ffs_entity_type { · 1606 unmodified lines | |||
| 1646 | FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT | 1647 | FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT |
| 1647 | }; | 1648 | }; |
| 1648 | 1649 | ||
| 1650 | enum ffs_os_desc_type { | ||
| 1651 | FFS_OS_DESC, FFS_OS_DESC_EXT_COMPAT, FFS_OS_DESC_EXT_PROP | ||
| 1652 | }; | ||
| 1653 | |||
| 1649 | typedef int (*ffs_entity_callback)(enum ffs_entity_type entity, | 1654 | typedef int (*ffs_entity_callback)(enum ffs_entity_type entity, |
| 1650 | u8 *valuep, | 1655 | u8 *valuep, |
| 1651 | struct usb_descriptor_header *desc, | 1656 | struct usb_descriptor_header *desc, |
| 1652 | void *priv); | 1657 | void *priv); |
| 1653 | 1658 | ||
| 1654 | static int __must_check ffs_do_desc(char *data, unsigned len, | 1659 | typedef int (*ffs_os_desc_callback)(enum ffs_os_desc_type entity, |
| 1655 | ffs_entity_callback entity, void *priv) | 1660 | struct usb_os_desc_header *h, void *data, |
| 1661 | unsigned len, void *priv); | ||
| 1662 | |||
| 1663 | static int __must_check ffs_do_single_desc(char *data, unsigned len, | ||
| 1664 | ffs_entity_callback entity, | ||
| 1665 | void *priv) | ||
| 1656 | { | 1666 | { |
| 1657 | struct usb_descriptor_header *_ds = (void *)data; | 1667 | struct usb_descriptor_header *_ds = (void *)data; |
| 1658 | u8 length; | 1668 | u8 length; |
| @@ -1804,7 +1814,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, · 145 unmodified lines | |||
| 1804 | if (!data) | 1814 | if (!data) |
| 1805 | return _len - len; | 1815 | return _len - len; |
| 1806 | 1816 | ||
| 1807 | ret = ffs_do_desc(data, len, entity, priv); | 1817 | ret = ffs_do_single_desc(data, len, entity, priv); |
| 1808 | if (unlikely(ret < 0)) { | 1818 | if (unlikely(ret < 0)) { |
| 1809 | pr_debug("%s returns %d\n", __func__, ret); | 1819 | pr_debug("%s returns %d\n", __func__, ret); |
| 1810 | return ret; | 1820 | return ret; |
| @@ -1857,11 +1867,191 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, · 46 unmodified lines | |||
| 1857 | return 0; | 1867 | return 0; |
| 1858 | } | 1868 | } |
| 1859 | 1869 | ||
| 1870 | static int __ffs_do_os_desc_header(enum ffs_os_desc_type *next_type, | ||
| 1871 | struct usb_os_desc_header *desc) | ||
| 1872 | { | ||
| 1873 | u16 bcd_version = le16_to_cpu(desc->bcdVersion); | ||
| 1874 | u16 w_index = le16_to_cpu(desc->wIndex); | ||
| 1875 | |||
| 1876 | if (bcd_version != 1) { | ||
| 1877 | pr_vdebug("unsupported os descriptors version: %d", | ||
| 1878 | bcd_version); | ||
| 1879 | return -EINVAL; | ||
| 1880 | } | ||
| 1881 | switch (w_index) { | ||
| 1882 | case 0x4: | ||
| 1883 | *next_type = FFS_OS_DESC_EXT_COMPAT; | ||
| 1884 | break; | ||
| 1885 | case 0x5: | ||
| 1886 | *next_type = FFS_OS_DESC_EXT_PROP; | ||
| 1887 | break; | ||
| 1888 | default: | ||
| 1889 | pr_vdebug("unsupported os descriptor type: %d", w_index); | ||
| 1890 | return -EINVAL; | ||
| 1891 | } | ||
| 1892 | |||
| 1893 | return sizeof(*desc); | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | /* | ||
| 1897 | * Process all extended compatibility/extended property descriptors | ||
| 1898 | * of a feature descriptor | ||
| 1899 | */ | ||
| 1900 | static int __must_check ffs_do_single_os_desc(char *data, unsigned len, | ||
| 1901 | enum ffs_os_desc_type type, | ||
| 1902 | u16 feature_count, | ||
| 1903 | ffs_os_desc_callback entity, | ||
| 1904 | void *priv, | ||
| 1905 | struct usb_os_desc_header *h) | ||
| 1906 | { | ||
| 1907 | int ret; | ||
| 1908 | const unsigned _len = len; | ||
| 1909 | |||
| 1910 | ENTER(); | ||
| 1911 | |||
| 1912 | /* loop over all ext compat/ext prop descriptors */ | ||
| 1913 | while (feature_count--) { | ||
| 1914 | ret = entity(type, h, data, len, priv); | ||
| 1915 | if (unlikely(ret < 0)) { | ||
| 1916 | pr_debug("bad OS descriptor, type: %d\n", type); | ||
| 1917 | return ret; | ||
| 1918 | } | ||
| 1919 | data += ret; | ||
| 1920 | len -= ret; | ||
| 1921 | } | ||
| 1922 | return _len - len; | ||
| 1923 | } | ||
| 1924 | |||
| 1925 | /* Process a number of complete Feature Descriptors (Ext Compat or Ext Prop) */ | ||
| 1926 | static int __must_check ffs_do_os_descs(unsigned count, | ||
| 1927 | char *data, unsigned len, | ||
| 1928 | ffs_os_desc_callback entity, void *priv) | ||
| 1929 | { | ||
| 1930 | const unsigned _len = len; | ||
| 1931 | unsigned long num = 0; | ||
| 1932 | |||
| 1933 | ENTER(); | ||
| 1934 | |||
| 1935 | for (num = 0; num < count; ++num) { | ||
| 1936 | int ret; | ||
| 1937 | enum ffs_os_desc_type type; | ||
| 1938 | u16 feature_count; | ||
| 1939 | struct usb_os_desc_header *desc = (void *)data; | ||
| 1940 | |||
| 1941 | if (len < sizeof(*desc)) | ||
| 1942 | return -EINVAL; | ||
| 1943 | |||
| 1944 | /* | ||
| 1945 | * Record "descriptor" entity. | ||
| 1946 | * Process dwLength, bcdVersion, wIndex, get b/wCount. | ||
| 1947 | * Move the data pointer to the beginning of extended | ||
| 1948 | * compatibilities proper or extended properties proper | ||
| 1949 | * portions of the data | ||
| 1950 | */ | ||
| 1951 | if (le32_to_cpu(desc->dwLength) > len) | ||
| 1952 | return -EINVAL; | ||
| 1953 | |||
| 1954 | ret = __ffs_do_os_desc_header(&type, desc); | ||
| 1955 | if (unlikely(ret < 0)) { | ||
| 1956 | pr_debug("entity OS_DESCRIPTOR(%02lx); ret = %d\n", | ||
| 1957 | num, ret); | ||
| 1958 | return ret; | ||
| 1959 | } | ||
| 1960 | /* | ||
| 1961 | * 16-bit hex "?? 00" Little Endian looks like 8-bit hex "??" | ||
| 1962 | */ | ||
| 1963 | feature_count = le16_to_cpu(desc->wCount); | ||
| 1964 | if (type == FFS_OS_DESC_EXT_COMPAT && | ||
| 1965 | (feature_count > 255 || desc->Reserved)) | ||
| 1966 | return -EINVAL; | ||
| 1967 | len -= ret; | ||
| 1968 | data += ret; | ||
| 1969 | |||
| 1970 | /* | ||
| 1971 | * Process all function/property descriptors | ||
| 1972 | * of this Feature Descriptor | ||
| 1973 | */ | ||
| 1974 | ret = ffs_do_single_os_desc(data, len, type, | ||
| 1975 | feature_count, entity, priv, desc); | ||
| 1976 | if (unlikely(ret < 0)) { | ||
| 1977 | pr_debug("%s returns %d\n", __func__, ret); | ||
| 1978 | return ret; | ||
| 1979 | } | ||
| 1980 | |||
| 1981 | len -= ret; | ||
| 1982 | data += ret; | ||
| 1983 | } | ||
| 1984 | return _len - len; | ||
| 1985 | } | ||
| 1986 | |||
| 1987 | /** | ||
| 1988 | * Validate contents of the buffer from userspace related to OS descriptors. | ||
| 1989 | */ | ||
| 1990 | static int __ffs_data_do_os_desc(enum ffs_os_desc_type type, | ||
| 1991 | struct usb_os_desc_header *h, void *data, | ||
| 1992 | unsigned len, void *priv) | ||
| 1993 | { | ||
| 1994 | struct ffs_data *ffs = priv; | ||
| 1995 | u8 length; | ||
| 1996 | |||
| 1997 | ENTER(); | ||
| 1998 | |||
| 1999 | switch (type) { | ||
| 2000 | case FFS_OS_DESC_EXT_COMPAT: { | ||
| 2001 | struct usb_ext_compat_desc *d = data; | ||
| 2002 | int i; | ||
| 2003 | |||
| 2004 | if (len < sizeof(*d) || | ||
| 2005 | d->bFirstInterfaceNumber >= ffs->interfaces_count || | ||
| 2006 | d->Reserved1) | ||
| 2007 | return -EINVAL; | ||
| 2008 | for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i) | ||
| 2009 | if (d->Reserved2[i]) | ||
| 2010 | return -EINVAL; | ||
| 2011 | |||
| 2012 | length = sizeof(struct usb_ext_compat_desc); | ||
| 2013 | } | ||
| 2014 | break; | ||
| 2015 | case FFS_OS_DESC_EXT_PROP: { | ||
| 2016 | struct usb_ext_prop_desc *d = data; | ||
| 2017 | u32 type, pdl; | ||
| 2018 | u16 pnl; | ||
| 2019 | |||
| 2020 | if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) | ||
| 2021 | return -EINVAL; | ||
| 2022 | length = le32_to_cpu(d->dwSize); | ||
| 2023 | type = le32_to_cpu(d->dwPropertyDataType); | ||
| 2024 | if (type < USB_EXT_PROP_UNICODE || | ||
| 2025 | type > USB_EXT_PROP_UNICODE_MULTI) { | ||
| 2026 | pr_vdebug("unsupported os descriptor property type: %d", | ||
| 2027 | type); | ||
| 2028 | return -EINVAL; | ||
| 2029 | } | ||
| 2030 | pnl = le16_to_cpu(d->wPropertyNameLength); | ||
| 2031 | pdl = le32_to_cpu(*(u32 *)((u8 *)data + 10 + pnl)); | ||
| 2032 | if (length != 14 + pnl + pdl) { | ||
| 2033 | pr_vdebug("invalid os descriptor length: %d pnl:%d pdl:%d (descriptor %d)\n", | ||
| 2034 | length, pnl, pdl, type); | ||
| 2035 | return -EINVAL; | ||
| 2036 | } | ||
| 2037 | ++ffs->ms_os_descs_ext_prop_count; | ||
| 2038 | /* property name reported to the host as "WCHAR"s */ | ||
| 2039 | ffs->ms_os_descs_ext_prop_name_len += pnl * 2; | ||
| 2040 | ffs->ms_os_descs_ext_prop_data_len += pdl; | ||
| 2041 | } | ||
| 2042 | break; | ||
| 2043 | default: | ||
| 2044 | pr_vdebug("unknown descriptor: %d\n", type); | ||
| 2045 | return -EINVAL; | ||
| 2046 | } | ||
| 2047 | return length; | ||
| 2048 | } | ||
| 2049 | |||
| 1860 | static int __ffs_data_got_descs(struct ffs_data *ffs, | 2050 | static int __ffs_data_got_descs(struct ffs_data *ffs, |
| 1861 | char *const _data, size_t len) | 2051 | char *const _data, size_t len) |
| 1862 | { | 2052 | { |
| 1863 | char *data = _data, *raw_descs; | 2053 | char *data = _data, *raw_descs; |
| 1864 | unsigned counts[3], flags; | 2054 | unsigned os_descs_count = 0, counts[3], flags; |
| 1865 | int ret = -EINVAL, i; | 2055 | int ret = -EINVAL, i; |
| 1866 | 2056 | ||
| 1867 | ENTER(); | 2057 | ENTER(); |
| @@ -1879,7 +2069,8 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 11 unmodified lines | |||
| 1879 | flags = get_unaligned_le32(data + 8); | 2069 | flags = get_unaligned_le32(data + 8); |
| 1880 | if (flags & ~(FUNCTIONFS_HAS_FS_DESC | | 2070 | if (flags & ~(FUNCTIONFS_HAS_FS_DESC | |
| 1881 | FUNCTIONFS_HAS_HS_DESC | | 2071 | FUNCTIONFS_HAS_HS_DESC | |
| 1882 | FUNCTIONFS_HAS_SS_DESC)) { | 2072 | FUNCTIONFS_HAS_SS_DESC | |
| 2073 | FUNCTIONFS_HAS_MS_OS_DESC)) { | ||
| 1883 | ret = -ENOSYS; | 2074 | ret = -ENOSYS; |
| 1884 | goto error; | 2075 | goto error; |
| 1885 | } | 2076 | } |
| @@ -1902,6 +2093,11 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 16 unmodified lines | |||
| 1902 | len -= 4; | 2093 | len -= 4; |
| 1903 | } | 2094 | } |
| 1904 | } | 2095 | } |
| 2096 | if (flags & (1 << i)) { | ||
| 2097 | os_descs_count = get_unaligned_le32(data); | ||
| 2098 | data += 4; | ||
| 2099 | len -= 4; | ||
| 2100 | }; | ||
| 1905 | 2101 | ||
| 1906 | /* Read descriptors */ | 2102 | /* Read descriptors */ |
| 1907 | raw_descs = data; | 2103 | raw_descs = data; |
| @@ -1915,6 +2111,14 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 7 unmodified lines | |||
| 1915 | data += ret; | 2111 | data += ret; |
| 1916 | len -= ret; | 2112 | len -= ret; |
| 1917 | } | 2113 | } |
| 2114 | if (os_descs_count) { | ||
| 2115 | ret = ffs_do_os_descs(os_descs_count, data, len, | ||
| 2116 | __ffs_data_do_os_desc, ffs); | ||
| 2117 | if (ret < 0) | ||
| 2118 | goto error; | ||
| 2119 | data += ret; | ||
| 2120 | len -= ret; | ||
| 2121 | } | ||
| 1918 | 2122 | ||
| 1919 | if (raw_descs == data || len) { | 2123 | if (raw_descs == data || len) { |
| 1920 | ret = -EINVAL; | 2124 | ret = -EINVAL; |
| @@ -1927,6 +2131,7 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 6 unmodified lines | |||
| 1927 | ffs->fs_descs_count = counts[0]; | 2131 | ffs->fs_descs_count = counts[0]; |
| 1928 | ffs->hs_descs_count = counts[1]; | 2132 | ffs->hs_descs_count = counts[1]; |
| 1929 | ffs->ss_descs_count = counts[2]; | 2133 | ffs->ss_descs_count = counts[2]; |
| 2134 | ffs->ms_os_descs_count = os_descs_count; | ||
| 1930 | 2135 | ||
| 1931 | return 0; | 2136 | return 0; |
| 1932 | 2137 | ||
| @@ -2268,6 +2473,85 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, · 335 unmodified lines | |||
| 2268 | return 0; | 2473 | return 0; |
| 2269 | } | 2474 | } |
| 2270 | 2475 | ||
| 2476 | static int __ffs_func_bind_do_os_desc(enum ffs_os_desc_type type, | ||
| 2477 | struct usb_os_desc_header *h, void *data, | ||
| 2478 | unsigned len, void *priv) | ||
| 2479 | { | ||
| 2480 | struct ffs_function *func = priv; | ||
| 2481 | u8 length = 0; | ||
| 2482 | |||
| 2483 | switch (type) { | ||
| 2484 | case FFS_OS_DESC_EXT_COMPAT: { | ||
| 2485 | struct usb_ext_compat_desc *desc = data; | ||
| 2486 | struct usb_os_desc_table *t; | ||
| 2487 | |||
| 2488 | t = &func->function.os_desc_table[desc->bFirstInterfaceNumber]; | ||
| 2489 | t->if_id = func->interfaces_nums[desc->bFirstInterfaceNumber]; | ||
| 2490 | memcpy(t->os_desc->ext_compat_id, &desc->CompatibleID, | ||
| 2491 | ARRAY_SIZE(desc->CompatibleID) + | ||
| 2492 | ARRAY_SIZE(desc->SubCompatibleID)); | ||
| 2493 | length = sizeof(*desc); | ||
| 2494 | } | ||
| 2495 | break; | ||
| 2496 | case FFS_OS_DESC_EXT_PROP: { | ||
| 2497 | struct usb_ext_prop_desc *desc = data; | ||
| 2498 | struct usb_os_desc_table *t; | ||
| 2499 | struct usb_os_desc_ext_prop *ext_prop; | ||
| 2500 | char *ext_prop_name; | ||
| 2501 | char *ext_prop_data; | ||
| 2502 | |||
| 2503 | t = &func->function.os_desc_table[h->interface]; | ||
| 2504 | t->if_id = func->interfaces_nums[h->interface]; | ||
| 2505 | |||
| 2506 | ext_prop = func->ffs->ms_os_descs_ext_prop_avail; | ||
| 2507 | func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); | ||
| 2508 | |||
| 2509 | ext_prop->type = le32_to_cpu(desc->dwPropertyDataType); | ||
| 2510 | ext_prop->name_len = le16_to_cpu(desc->wPropertyNameLength); | ||
| 2511 | ext_prop->data_len = le32_to_cpu(*(u32 *) | ||
| 2512 | usb_ext_prop_data_len_ptr(data, ext_prop->name_len)); | ||
| 2513 | length = ext_prop->name_len + ext_prop->data_len + 14; | ||
| 2514 | |||
| 2515 | ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; | ||
| 2516 | func->ffs->ms_os_descs_ext_prop_name_avail += | ||
| 2517 | ext_prop->name_len; | ||
| 2518 | |||
| 2519 | ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; | ||
| 2520 | func->ffs->ms_os_descs_ext_prop_data_avail += | ||
| 2521 | ext_prop->data_len; | ||
| 2522 | memcpy(ext_prop_data, | ||
| 2523 | usb_ext_prop_data_ptr(data, ext_prop->name_len), | ||
| 2524 | ext_prop->data_len); | ||
| 2525 | /* unicode data reported to the host as "WCHAR"s */ | ||
| 2526 | switch (ext_prop->type) { | ||
| 2527 | case USB_EXT_PROP_UNICODE: | ||
| 2528 | case USB_EXT_PROP_UNICODE_ENV: | ||
| 2529 | case USB_EXT_PROP_UNICODE_LINK: | ||
| 2530 | case USB_EXT_PROP_UNICODE_MULTI: | ||
| 2531 | ext_prop->data_len *= 2; | ||
| 2532 | break; | ||
| 2533 | } | ||
| 2534 | ext_prop->data = ext_prop_data; | ||
| 2535 | |||
| 2536 | memcpy(ext_prop_name, usb_ext_prop_name_ptr(data), | ||
| 2537 | ext_prop->name_len); | ||
| 2538 | /* property name reported to the host as "WCHAR"s */ | ||
| 2539 | ext_prop->name_len *= 2; | ||
| 2540 | ext_prop->name = ext_prop_name; | ||
| 2541 | |||
| 2542 | t->os_desc->ext_prop_len += | ||
| 2543 | ext_prop->name_len + ext_prop->data_len + 14; | ||
| 2544 | ++t->os_desc->ext_prop_count; | ||
| 2545 | list_add_tail(&ext_prop->entry, &t->os_desc->ext_prop); | ||
| 2546 | } | ||
| 2547 | break; | ||
| 2548 | default: | ||
| 2549 | pr_vdebug("unknown descriptor: %d\n", type); | ||
| 2550 | } | ||
| 2551 | |||
| 2552 | return length; | ||
| 2553 | } | ||
| 2554 | |||
| 2271 | static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f, | 2555 | static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f, |
| 2272 | struct usb_configuration *c) | 2556 | struct usb_configuration *c) |
| 2273 | { | 2557 | { |
| @@ -2329,7 +2613,7 @@ static int _ffs_func_bind(struct usb_configuration *c, · 55 unmodified lines | |||
| 2329 | const int super = gadget_is_superspeed(func->gadget) && | 2613 | const int super = gadget_is_superspeed(func->gadget) && |
| 2330 | func->ffs->ss_descs_count; | 2614 | func->ffs->ss_descs_count; |
| 2331 | 2615 | ||
| 2332 | int fs_len, hs_len, ret; | 2616 | int fs_len, hs_len, ss_len, ret, i; |
| 2333 | 2617 | ||
| 2334 | /* Make it a single chunk, less management later on */ | 2618 | /* Make it a single chunk, less management later on */ |
| 2335 | vla_group(d); | 2619 | vla_group(d); |
| @@ -2341,6 +2625,18 @@ static int _ffs_func_bind(struct usb_configuration *c, · 5 unmodified lines | |||
| 2341 | vla_item_with_sz(d, struct usb_descriptor_header *, ss_descs, | 2625 | vla_item_with_sz(d, struct usb_descriptor_header *, ss_descs, |
| 2342 | super ? ffs->ss_descs_count + 1 : 0); | 2626 | super ? ffs->ss_descs_count + 1 : 0); |
| 2343 | vla_item_with_sz(d, short, inums, ffs->interfaces_count); | 2627 | vla_item_with_sz(d, short, inums, ffs->interfaces_count); |
| 2628 | vla_item_with_sz(d, struct usb_os_desc_table, os_desc_table, | ||
| 2629 | c->cdev->use_os_string ? ffs->interfaces_count : 0); | ||
| 2630 | vla_item_with_sz(d, char[16], ext_compat, | ||
| 2631 | c->cdev->use_os_string ? ffs->interfaces_count : 0); | ||
| 2632 | vla_item_with_sz(d, struct usb_os_desc, os_desc, | ||
| 2633 | c->cdev->use_os_string ? ffs->interfaces_count : 0); | ||
| 2634 | vla_item_with_sz(d, struct usb_os_desc_ext_prop, ext_prop, | ||
| 2635 | ffs->ms_os_descs_ext_prop_count); | ||
| 2636 | vla_item_with_sz(d, char, ext_prop_name, | ||
| 2637 | ffs->ms_os_descs_ext_prop_name_len); | ||
| 2638 | vla_item_with_sz(d, char, ext_prop_data, | ||
| 2639 | ffs->ms_os_descs_ext_prop_data_len); | ||
| 2344 | vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); | 2640 | vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); |
| 2345 | char *vlabuf; | 2641 | char *vlabuf; |
| 2346 | 2642 | ||
| @@ -2351,12 +2647,16 @@ static int _ffs_func_bind(struct usb_configuration *c, · 4 unmodified lines | |||
| 2351 | return -ENOTSUPP; | 2647 | return -ENOTSUPP; |
| 2352 | 2648 | ||
| 2353 | /* Allocate a single chunk, less management later on */ | 2649 | /* Allocate a single chunk, less management later on */ |
| 2354 | vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); | 2650 | vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL); |
| 2355 | if (unlikely(!vlabuf)) | 2651 | if (unlikely(!vlabuf)) |
| 2356 | return -ENOMEM; | 2652 | return -ENOMEM; |
| 2357 | 2653 | ||
| 2358 | /* Zero */ | 2654 | ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); |
| 2359 | memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz); | 2655 | ffs->ms_os_descs_ext_prop_name_avail = |
| 2656 | vla_ptr(vlabuf, d, ext_prop_name); | ||
| 2657 | ffs->ms_os_descs_ext_prop_data_avail = | ||
| 2658 | vla_ptr(vlabuf, d, ext_prop_data); | ||
| 2659 | |||
| 2360 | /* Copy descriptors */ | 2660 | /* Copy descriptors */ |
| 2361 | memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, | 2661 | memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, |
| 2362 | ffs->raw_descs_length); | 2662 | ffs->raw_descs_length); |
| @@ -2410,12 +2710,16 @@ static int _ffs_func_bind(struct usb_configuration *c, · 47 unmodified lines | |||
| 2410 | 2710 | ||
| 2411 | if (likely(super)) { | 2711 | if (likely(super)) { |
| 2412 | func->function.ss_descriptors = vla_ptr(vlabuf, d, ss_descs); | 2712 | func->function.ss_descriptors = vla_ptr(vlabuf, d, ss_descs); |
| 2413 | ret = ffs_do_descs(ffs->ss_descs_count, | 2713 | ss_len = ffs_do_descs(ffs->ss_descs_count, |
| 2414 | vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len, | 2714 | vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len, |
| 2415 | d_raw_descs__sz - fs_len - hs_len, | 2715 | d_raw_descs__sz - fs_len - hs_len, |
| 2416 | __ffs_func_bind_do_descs, func); | 2716 | __ffs_func_bind_do_descs, func); |
| 2417 | if (unlikely(ret < 0)) | 2717 | if (unlikely(ss_len < 0)) { |
| 2718 | ret = ss_len; | ||
| 2418 | goto error; | 2719 | goto error; |
| 2720 | } | ||
| 2721 | } else { | ||
| 2722 | ss_len = 0; | ||
| 2419 | } | 2723 | } |
| 2420 | 2724 | ||
| 2421 | /* | 2725 | /* |
| @@ -2431,6 +2735,28 @@ static int _ffs_func_bind(struct usb_configuration *c, · 9 unmodified lines | |||
| 2431 | if (unlikely(ret < 0)) | 2735 | if (unlikely(ret < 0)) |
| 2432 | goto error; | 2736 | goto error; |
| 2433 | 2737 | ||
| 2738 | func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table); | ||
| 2739 | if (c->cdev->use_os_string) | ||
| 2740 | for (i = 0; i < ffs->interfaces_count; ++i) { | ||
| 2741 | struct usb_os_desc *desc; | ||
| 2742 | |||
| 2743 | desc = func->function.os_desc_table[i].os_desc = | ||
| 2744 | vla_ptr(vlabuf, d, os_desc) + | ||
| 2745 | i * sizeof(struct usb_os_desc); | ||
| 2746 | desc->ext_compat_id = | ||
| 2747 | vla_ptr(vlabuf, d, ext_compat) + i * 16; | ||
| 2748 | INIT_LIST_HEAD(&desc->ext_prop); | ||
| 2749 | } | ||
| 2750 | ret = ffs_do_os_descs(ffs->ms_os_descs_count, | ||
| 2751 | vla_ptr(vlabuf, d, raw_descs) + | ||
| 2752 | fs_len + hs_len + ss_len, | ||
| 2753 | d_raw_descs__sz - fs_len - hs_len - ss_len, | ||
| 2754 | __ffs_func_bind_do_os_desc, func); | ||
| 2755 | if (unlikely(ret < 0)) | ||
| 2756 | goto error; | ||
| 2757 | func->function.os_desc_n = | ||
| 2758 | c->cdev->use_os_string ? ffs->interfaces_count : 0; | ||
| 2759 | |||
| 2434 | /* And we're done */ | 2760 | /* And we're done */ |
| 2435 | ffs_event_add(ffs, FUNCTIONFS_BIND); | 2761 | ffs_event_add(ffs, FUNCTIONFS_BIND); |
| 2436 | return 0; | 2762 | return 0; |
| @@ -2901,12 +3227,12 @@ static void *ffs_acquire_dev(const char *dev_name) · 464 unmodified lines | |||
| 2901 | 3227 | ||
| 2902 | ffs_dev = _ffs_find_dev(dev_name); | 3228 | ffs_dev = _ffs_find_dev(dev_name); |
| 2903 | if (!ffs_dev) | 3229 | if (!ffs_dev) |
| 2904 | ffs_dev = ERR_PTR(-ENODEV); | 3230 | ffs_dev = ERR_PTR(-ENOENT); |
| 2905 | else if (ffs_dev->mounted) | 3231 | else if (ffs_dev->mounted) |
| 2906 | ffs_dev = ERR_PTR(-EBUSY); | 3232 | ffs_dev = ERR_PTR(-EBUSY); |
| 2907 | else if (ffs_dev->ffs_acquire_dev_callback && | 3233 | else if (ffs_dev->ffs_acquire_dev_callback && |
| 2908 | ffs_dev->ffs_acquire_dev_callback(ffs_dev)) | 3234 | ffs_dev->ffs_acquire_dev_callback(ffs_dev)) |
| 2909 | ffs_dev = ERR_PTR(-ENODEV); | 3235 | ffs_dev = ERR_PTR(-ENOENT); |
| 2910 | else | 3236 | else |
| 2911 | ffs_dev->mounted = true; | 3237 | ffs_dev->mounted = true; |
| 2912 | 3238 | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -68,6 +68,18 @@ struct f_ncm { · 67 unmodified lines | |||
| 68 | * callback and ethernet open/close | 68 | * callback and ethernet open/close |
| 69 | */ | 69 | */ |
| 70 | spinlock_t lock; | 70 | spinlock_t lock; |
| 71 | |||
| 72 | struct net_device *netdev; | ||
| 73 | |||
| 74 | /* For multi-frame NDP TX */ | ||
| 75 | struct sk_buff *skb_tx_data; | ||
| 76 | struct sk_buff *skb_tx_ndp; | ||
| 77 | u16 ndp_dgram_count; | ||
| 78 | bool timer_force_tx; | ||
| 79 | struct tasklet_struct tx_tasklet; | ||
| 80 | struct hrtimer task_timer; | ||
| 81 | |||
| 82 | bool timer_stopping; | ||
| 71 | }; | 83 | }; |
| 72 | 84 | ||
| 73 | static inline struct f_ncm *func_to_ncm(struct usb_function *f) | 85 | static inline struct f_ncm *func_to_ncm(struct usb_function *f) |
| @@ -92,15 +104,20 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g) · 18 unmodified lines | |||
| 92 | * If the host can group frames, allow it to do that, 16K is selected, | 104 | * If the host can group frames, allow it to do that, 16K is selected, |
| 93 | * because it's used by default by the current linux host driver | 105 | * because it's used by default by the current linux host driver |
| 94 | */ | 106 | */ |
| 95 | #define NTB_DEFAULT_IN_SIZE USB_CDC_NCM_NTB_MIN_IN_SIZE | 107 | #define NTB_DEFAULT_IN_SIZE 16384 |
| 96 | #define NTB_OUT_SIZE 16384 | 108 | #define NTB_OUT_SIZE 16384 |
| 97 | 109 | ||
| 98 | /* | 110 | /* Allocation for storing the NDP, 32 should suffice for a |
| 99 | * skbs of size less than that will not be aligned | 111 | * 16k packet. This allows a maximum of 32 * 507 Byte packets to |
| 100 | * to NCM's dwNtbInMaxSize to save bus bandwidth | 112 | * be transmitted in a single 16kB skb, though when sending full size |
| 113 | * packets this limit will be plenty. | ||
| 114 | * Smaller packets are not likely to be trying to maximize the | ||
| 115 | * throughput and will be mstly sending smaller infrequent frames. | ||
| 101 | */ | 116 | */ |
| 117 | #define TX_MAX_NUM_DPE 32 | ||
| 102 | 118 | ||
| 103 | #define MAX_TX_NONFIXED (512 * 3) | 119 | /* Delay for the transmit to wait before sending an unfilled NTB frame. */ |
| 120 | #define TX_TIMEOUT_NSECS 300000 | ||
| 104 | 121 | ||
| 105 | #define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \ | 122 | #define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \ |
| 106 | USB_CDC_NCM_NTB32_SUPPORTED) | 123 | USB_CDC_NCM_NTB32_SUPPORTED) |
| @@ -355,14 +372,15 @@ struct ndp_parser_opts { · 248 unmodified lines | |||
| 355 | u32 ndp_sign; | 372 | u32 ndp_sign; |
| 356 | unsigned nth_size; | 373 | unsigned nth_size; |
| 357 | unsigned ndp_size; | 374 | unsigned ndp_size; |
| 375 | unsigned dpe_size; | ||
| 358 | unsigned ndplen_align; | 376 | unsigned ndplen_align; |
| 359 | /* sizes in u16 units */ | 377 | /* sizes in u16 units */ |
| 360 | unsigned dgram_item_len; /* index or length */ | 378 | unsigned dgram_item_len; /* index or length */ |
| 361 | unsigned block_length; | 379 | unsigned block_length; |
| 362 | unsigned fp_index; | 380 | unsigned ndp_index; |
| 363 | unsigned reserved1; | 381 | unsigned reserved1; |
| 364 | unsigned reserved2; | 382 | unsigned reserved2; |
| 365 | unsigned next_fp_index; | 383 | unsigned next_ndp_index; |
| 366 | }; | 384 | }; |
| 367 | 385 | ||
| 368 | #define INIT_NDP16_OPTS { \ | 386 | #define INIT_NDP16_OPTS { \ |
| @@ -370,13 +388,14 @@ struct ndp_parser_opts { · 1 unmodified line | |||
| 370 | .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, \ | 388 | .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, \ |
| 371 | .nth_size = sizeof(struct usb_cdc_ncm_nth16), \ | 389 | .nth_size = sizeof(struct usb_cdc_ncm_nth16), \ |
| 372 | .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \ | 390 | .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \ |
| 391 | .dpe_size = sizeof(struct usb_cdc_ncm_dpe16), \ | ||
| 373 | .ndplen_align = 4, \ | 392 | .ndplen_align = 4, \ |
| 374 | .dgram_item_len = 1, \ | 393 | .dgram_item_len = 1, \ |
| 375 | .block_length = 1, \ | 394 | .block_length = 1, \ |
| 376 | .fp_index = 1, \ | 395 | .ndp_index = 1, \ |
| 377 | .reserved1 = 0, \ | 396 | .reserved1 = 0, \ |
| 378 | .reserved2 = 0, \ | 397 | .reserved2 = 0, \ |
| 379 | .next_fp_index = 1, \ | 398 | .next_ndp_index = 1, \ |
| 380 | } | 399 | } |
| 381 | 400 | ||
| 382 | 401 | ||
| @@ -385,13 +404,14 @@ struct ndp_parser_opts { · 2 unmodified lines | |||
| 385 | .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, \ | 404 | .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, \ |
| 386 | .nth_size = sizeof(struct usb_cdc_ncm_nth32), \ | 405 | .nth_size = sizeof(struct usb_cdc_ncm_nth32), \ |
| 387 | .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \ | 406 | .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \ |
| 407 | .dpe_size = sizeof(struct usb_cdc_ncm_dpe32), \ | ||
| 388 | .ndplen_align = 8, \ | 408 | .ndplen_align = 8, \ |
| 389 | .dgram_item_len = 2, \ | 409 | .dgram_item_len = 2, \ |
| 390 | .block_length = 2, \ | 410 | .block_length = 2, \ |
| 391 | .fp_index = 2, \ | 411 | .ndp_index = 2, \ |
| 392 | .reserved1 = 1, \ | 412 | .reserved1 = 1, \ |
| 393 | .reserved2 = 2, \ | 413 | .reserved2 = 2, \ |
| 394 | .next_fp_index = 2, \ | 414 | .next_ndp_index = 2, \ |
| 395 | } | 415 | } |
| 396 | 416 | ||
| 397 | static const struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; | 417 | static const struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; |
| @@ -803,6 +823,8 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 405 unmodified lines | |||
| 803 | 823 | ||
| 804 | if (ncm->port.in_ep->driver_data) { | 824 | if (ncm->port.in_ep->driver_data) { |
| 805 | DBG(cdev, "reset ncm\n"); | 825 | DBG(cdev, "reset ncm\n"); |
| 826 | ncm->timer_stopping = true; | ||
| 827 | ncm->netdev = NULL; | ||
| 806 | gether_disconnect(&ncm->port); | 828 | gether_disconnect(&ncm->port); |
| 807 | ncm_reset_values(ncm); | 829 | ncm_reset_values(ncm); |
| 808 | } | 830 | } |
| @@ -839,6 +861,8 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 30 unmodified lines | |||
| 839 | net = gether_connect(&ncm->port); | 861 | net = gether_connect(&ncm->port); |
| 840 | if (IS_ERR(net)) | 862 | if (IS_ERR(net)) |
| 841 | return PTR_ERR(net); | 863 | return PTR_ERR(net); |
| 864 | ncm->netdev = net; | ||
| 865 | ncm->timer_stopping = false; | ||
| 842 | } | 866 | } |
| 843 | 867 | ||
| 844 | spin_lock(&ncm->lock); | 868 | spin_lock(&ncm->lock); |
| @@ -865,95 +889,232 @@ static int ncm_get_alt(struct usb_function *f, unsigned intf) · 20 unmodified lines | |||
| 865 | return ncm->port.in_ep->driver_data ? 1 : 0; | 889 | return ncm->port.in_ep->driver_data ? 1 : 0; |
| 866 | } | 890 | } |
| 867 | 891 | ||
| 892 | static struct sk_buff *package_for_tx(struct f_ncm *ncm) | ||
| 893 | { | ||
| 894 | __le16 *ntb_iter; | ||
| 895 | struct sk_buff *skb2 = NULL; | ||
| 896 | unsigned ndp_pad; | ||
| 897 | unsigned ndp_index; | ||
| 898 | unsigned new_len; | ||
| 899 | |||
| 900 | const struct ndp_parser_opts *opts = ncm->parser_opts; | ||
| 901 | const int ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment); | ||
| 902 | const int dgram_idx_len = 2 * 2 * opts->dgram_item_len; | ||
| 903 | |||
| 904 | /* Stop the timer */ | ||
| 905 | hrtimer_try_to_cancel(&ncm->task_timer); | ||
| 906 | |||
| 907 | ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - | ||
| 908 | ncm->skb_tx_data->len; | ||
| 909 | ndp_index = ncm->skb_tx_data->len + ndp_pad; | ||
| 910 | new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; | ||
| 911 | |||
| 912 | /* Set the final BlockLength and wNdpIndex */ | ||
| 913 | ntb_iter = (void *) ncm->skb_tx_data->data; | ||
| 914 | /* Increment pointer to BlockLength */ | ||
| 915 | ntb_iter += 2 + 1 + 1; | ||
| 916 | put_ncm(&ntb_iter, opts->block_length, new_len); | ||
| 917 | put_ncm(&ntb_iter, opts->ndp_index, ndp_index); | ||
| 918 | |||
| 919 | /* Set the final NDP wLength */ | ||
| 920 | new_len = opts->ndp_size + | ||
| 921 | (ncm->ndp_dgram_count * dgram_idx_len); | ||
| 922 | ncm->ndp_dgram_count = 0; | ||
| 923 | /* Increment from start to wLength */ | ||
| 924 | ntb_iter = (void *) ncm->skb_tx_ndp->data; | ||
| 925 | ntb_iter += 2; | ||
| 926 | put_unaligned_le16(new_len, ntb_iter); | ||
| 927 | |||
| 928 | /* Merge the skbs */ | ||
| 929 | swap(skb2, ncm->skb_tx_data); | ||
| 930 | if (ncm->skb_tx_data) { | ||
| 931 | dev_kfree_skb_any(ncm->skb_tx_data); | ||
| 932 | ncm->skb_tx_data = NULL; | ||
| 933 | } | ||
| 934 | |||
| 935 | /* Insert NDP alignment. */ | ||
| 936 | ntb_iter = (void *) skb_put(skb2, ndp_pad); | ||
| 937 | memset(ntb_iter, 0, ndp_pad); | ||
| 938 | |||
| 939 | /* Copy NTB across. */ | ||
| 940 | ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len); | ||
| 941 | memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); | ||
| 942 | dev_kfree_skb_any(ncm->skb_tx_ndp); | ||
| 943 | ncm->skb_tx_ndp = NULL; | ||
| 944 | |||
| 945 | /* Insert zero'd datagram. */ | ||
| 946 | ntb_iter = (void *) skb_put(skb2, dgram_idx_len); | ||
| 947 | memset(ntb_iter, 0, dgram_idx_len); | ||
| 948 | |||
| 949 | return skb2; | ||
| 950 | } | ||
| 951 | |||
| 868 | static struct sk_buff *ncm_wrap_ntb(struct gether *port, | 952 | static struct sk_buff *ncm_wrap_ntb(struct gether *port, |
| 869 | struct sk_buff *skb) | 953 | struct sk_buff *skb) |
| 870 | { | 954 | { |
| 871 | struct f_ncm *ncm = func_to_ncm(&port->func); | 955 | struct f_ncm *ncm = func_to_ncm(&port->func); |
| 872 | struct sk_buff *skb2; | 956 | struct sk_buff *skb2 = NULL; |
| 873 | int ncb_len = 0; | 957 | int ncb_len = 0; |
| 874 | __le16 *tmp; | 958 | __le16 *ntb_data; |
| 875 | int div; | 959 | __le16 *ntb_ndp; |
| 876 | int rem; | 960 | int dgram_pad; |
| 877 | int pad; | 961 | |
| 878 | int ndp_align; | ||
| 879 | int ndp_pad; | ||
| 880 | unsigned max_size = ncm->port.fixed_in_len; | 962 | unsigned max_size = ncm->port.fixed_in_len; |
| 881 | const struct ndp_parser_opts *opts = ncm->parser_opts; | 963 | const struct ndp_parser_opts *opts = ncm->parser_opts; |
| 882 | unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; | 964 | const int ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment); |
| 883 | 965 | const int div = le16_to_cpu(ntb_parameters.wNdpInDivisor); | |
| 884 | div = le16_to_cpu(ntb_parameters.wNdpInDivisor); | 966 | const int rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder); |
| 885 | rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder); | 967 | const int dgram_idx_len = 2 * 2 * opts->dgram_item_len; |
| 886 | ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment); | ||
| 887 | 968 | ||
| 888 | ncb_len += opts->nth_size; | 969 | if (!skb && !ncm->skb_tx_data) |
| 889 | ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len; | ||
| 890 | ncb_len += ndp_pad; | ||
| 891 | ncb_len += opts->ndp_size; | ||
| 892 | ncb_len += 2 * 2 * opts->dgram_item_len; /* Datagram entry */ | ||
| 893 | ncb_len += 2 * 2 * opts->dgram_item_len; /* Zero datagram entry */ | ||
| 894 | pad = ALIGN(ncb_len, div) + rem - ncb_len; | ||
| 895 | ncb_len += pad; | ||
| 896 | |||
| 897 | if (ncb_len + skb->len + crc_len > max_size) { | ||
| 898 | dev_kfree_skb_any(skb); | ||
| 899 | return NULL; | 970 | return NULL; |
| 900 | } | ||
| 901 | 971 | ||
| 902 | skb2 = skb_copy_expand(skb, ncb_len, | 972 | if (skb) { |
| 903 | max_size - skb->len - ncb_len - crc_len, | 973 | /* Add the CRC if required up front */ |
| 904 | GFP_ATOMIC); | 974 | if (ncm->is_crc) { |
| 905 | dev_kfree_skb_any(skb); | 975 | uint32_t crc; |
| 906 | if (!skb2) | 976 | __le16 *crc_pos; |
| 907 | return NULL; | 977 | |
| 978 | crc = ~crc32_le(~0, | ||
| 979 | skb->data, | ||
| 980 | skb->len); | ||
| 981 | crc_pos = (void *) skb_put(skb, sizeof(uint32_t)); | ||
| 982 | put_unaligned_le32(crc, crc_pos); | ||
| 983 | } | ||
| 908 | 984 | ||
| 909 | skb = skb2; | 985 | /* If the new skb is too big for the current NCM NTB then |
| 986 | * set the current stored skb to be sent now and clear it | ||
| 987 | * ready for new data. | ||
| 988 | * NOTE: Assume maximum align for speed of calculation. | ||
| 989 | */ | ||
| 990 | if (ncm->skb_tx_data | ||
| 991 | && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE | ||
| 992 | || (ncm->skb_tx_data->len + | ||
| 993 | div + rem + skb->len + | ||
| 994 | ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) | ||
| 995 | > max_size)) { | ||
| 996 | skb2 = package_for_tx(ncm); | ||
| 997 | if (!skb2) | ||
| 998 | goto err; | ||
| 999 | } | ||
| 910 | 1000 | ||
| 911 | tmp = (void *) skb_push(skb, ncb_len); | 1001 | if (!ncm->skb_tx_data) { |
| 912 | memset(tmp, 0, ncb_len); | 1002 | ncb_len = opts->nth_size; |
| 1003 | dgram_pad = ALIGN(ncb_len, div) + rem - ncb_len; | ||
| 1004 | ncb_len += dgram_pad; | ||
| 913 | 1005 | ||
| 914 | put_unaligned_le32(opts->nth_sign, tmp); /* dwSignature */ | 1006 | /* Create a new skb for the NTH and datagrams. */ |
| 915 | tmp += 2; | 1007 | ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); |
| 916 | /* wHeaderLength */ | 1008 | if (!ncm->skb_tx_data) |
| 917 | put_unaligned_le16(opts->nth_size, tmp++); | 1009 | goto err; |
| 918 | tmp++; /* skip wSequence */ | ||
| 919 | put_ncm(&tmp, opts->block_length, skb->len); /* (d)wBlockLength */ | ||
| 920 | /* (d)wFpIndex */ | ||
| 921 | /* the first pointer is right after the NTH + align */ | ||
| 922 | put_ncm(&tmp, opts->fp_index, opts->nth_size + ndp_pad); | ||
| 923 | 1010 | ||
| 924 | tmp = (void *)tmp + ndp_pad; | 1011 | ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len); |
| 1012 | memset(ntb_data, 0, ncb_len); | ||
| 1013 | /* dwSignature */ | ||
| 1014 | put_unaligned_le32(opts->nth_sign, ntb_data); | ||
| 1015 | ntb_data += 2; | ||
| 1016 | /* wHeaderLength */ | ||
| 1017 | put_unaligned_le16(opts->nth_size, ntb_data++); | ||
| 1018 | |||
| 1019 | /* Allocate an skb for storing the NDP, | ||
| 1020 | * TX_MAX_NUM_DPE should easily suffice for a | ||
| 1021 | * 16k packet. | ||
| 1022 | */ | ||
| 1023 | ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size | ||
| 1024 | + opts->dpe_size | ||
| 1025 | * TX_MAX_NUM_DPE), | ||
| 1026 | GFP_ATOMIC); | ||
| 1027 | if (!ncm->skb_tx_ndp) | ||
| 1028 | goto err; | ||
| 1029 | ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, | ||
| 1030 | opts->ndp_size); | ||
| 1031 | memset(ntb_ndp, 0, ncb_len); | ||
| 1032 | /* dwSignature */ | ||
| 1033 | put_unaligned_le32(ncm->ndp_sign, ntb_ndp); | ||
| 1034 | ntb_ndp += 2; | ||
| 925 | 1035 | ||
| 926 | /* NDP */ | 1036 | /* There is always a zeroed entry */ |
| 927 | put_unaligned_le32(ncm->ndp_sign, tmp); /* dwSignature */ | 1037 | ncm->ndp_dgram_count = 1; |
| 928 | tmp += 2; | ||
| 929 | /* wLength */ | ||
| 930 | put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++); | ||
| 931 | 1038 | ||
| 932 | tmp += opts->reserved1; | 1039 | /* Note: we skip opts->next_ndp_index */ |
| 933 | tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */ | 1040 | } |
| 934 | tmp += opts->reserved2; | ||
| 935 | 1041 | ||
| 936 | if (ncm->is_crc) { | 1042 | /* Delay the timer. */ |
| 937 | uint32_t crc; | 1043 | hrtimer_start(&ncm->task_timer, |
| 1044 | ktime_set(0, TX_TIMEOUT_NSECS), | ||
| 1045 | HRTIMER_MODE_REL); | ||
| 1046 | |||
| 1047 | /* Add the datagram position entries */ | ||
| 1048 | ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, dgram_idx_len); | ||
| 1049 | memset(ntb_ndp, 0, dgram_idx_len); | ||
| 1050 | |||
| 1051 | ncb_len = ncm->skb_tx_data->len; | ||
| 1052 | dgram_pad = ALIGN(ncb_len, div) + rem - ncb_len; | ||
| 1053 | ncb_len += dgram_pad; | ||
| 1054 | |||
| 1055 | /* (d)wDatagramIndex */ | ||
| 1056 | put_ncm(&ntb_ndp, opts->dgram_item_len, ncb_len); | ||
| 1057 | /* (d)wDatagramLength */ | ||
| 1058 | put_ncm(&ntb_ndp, opts->dgram_item_len, skb->len); | ||
| 1059 | ncm->ndp_dgram_count++; | ||
| 1060 | |||
| 1061 | /* Add the new data to the skb */ | ||
| 1062 | ntb_data = (void *) skb_put(ncm->skb_tx_data, dgram_pad); | ||
| 1063 | memset(ntb_data, 0, dgram_pad); | ||
| 1064 | ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len); | ||
| 1065 | memcpy(ntb_data, skb->data, skb->len); | ||
| 1066 | dev_kfree_skb_any(skb); | ||
| 1067 | skb = NULL; | ||
| 938 | 1068 | ||
| 939 | crc = ~crc32_le(~0, | 1069 | } else if (ncm->skb_tx_data && ncm->timer_force_tx) { |
| 940 | skb->data + ncb_len, | 1070 | /* If the tx was requested because of a timeout then send */ |
| 941 | skb->len - ncb_len); | 1071 | skb2 = package_for_tx(ncm); |
| 942 | put_unaligned_le32(crc, skb->data + skb->len); | 1072 | if (!skb2) |
| 943 | skb_put(skb, crc_len); | 1073 | goto err; |
| 944 | } | 1074 | } |
| 945 | 1075 | ||
| 946 | /* (d)wDatagramIndex[0] */ | 1076 | return skb2; |
| 947 | put_ncm(&tmp, opts->dgram_item_len, ncb_len); | ||
| 948 | /* (d)wDatagramLength[0] */ | ||
| 949 | put_ncm(&tmp, opts->dgram_item_len, skb->len - ncb_len); | ||
| 950 | /* (d)wDatagramIndex[1] and (d)wDatagramLength[1] already zeroed */ | ||
| 951 | 1077 | ||
| 952 | if (skb->len > MAX_TX_NONFIXED) | 1078 | err: |
| 953 | memset(skb_put(skb, max_size - skb->len), | 1079 | ncm->netdev->stats.tx_dropped++; |
| 954 | 0, max_size - skb->len); | 1080 | |
| 1081 | if (skb) | ||
| 1082 | dev_kfree_skb_any(skb); | ||
| 1083 | if (ncm->skb_tx_data) | ||
| 1084 | dev_kfree_skb_any(ncm->skb_tx_data); | ||
| 1085 | if (ncm->skb_tx_ndp) | ||
| 1086 | dev_kfree_skb_any(ncm->skb_tx_ndp); | ||
| 955 | 1087 | ||
| 956 | return skb; | 1088 | return NULL; |
| 1089 | } | ||
| 1090 | |||
| 1091 | /* | ||
| 1092 | * This transmits the NTB if there are frames waiting. | ||
| 1093 | */ | ||
| 1094 | static void ncm_tx_tasklet(unsigned long data) | ||
| 1095 | { | ||
| 1096 | struct f_ncm *ncm = (void *)data; | ||
| 1097 | |||
| 1098 | if (ncm->timer_stopping) | ||
| 1099 | return; | ||
| 1100 | |||
| 1101 | /* Only send if data is available. */ | ||
| 1102 | if (ncm->skb_tx_data) { | ||
| 1103 | ncm->timer_force_tx = true; | ||
| 1104 | ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev); | ||
| 1105 | ncm->timer_force_tx = false; | ||
| 1106 | } | ||
| 1107 | } | ||
| 1108 | |||
| 1109 | /* | ||
| 1110 | * The transmit should only be run if no skb data has been sent | ||
| 1111 | * for a certain duration. | ||
| 1112 | */ | ||
| 1113 | static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data) | ||
| 1114 | { | ||
| 1115 | struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); | ||
| 1116 | tasklet_schedule(&ncm->tx_tasklet); | ||
| 1117 | return HRTIMER_NORESTART; | ||
| 957 | } | 1118 | } |
| 958 | 1119 | ||
| 959 | static int ncm_unwrap_ntb(struct gether *port, | 1120 | static int ncm_unwrap_ntb(struct gether *port, |
| @@ -963,6 +1124,7 @@ static int ncm_unwrap_ntb(struct gether *port, · 3 unmodified lines | |||
| 963 | struct f_ncm *ncm = func_to_ncm(&port->func); | 1124 | struct f_ncm *ncm = func_to_ncm(&port->func); |
| 964 | __le16 *tmp = (void *) skb->data; | 1125 | __le16 *tmp = (void *) skb->data; |
| 965 | unsigned index, index2; | 1126 | unsigned index, index2; |
| 1127 | int ndp_index; | ||
| 966 | unsigned dg_len, dg_len2; | 1128 | unsigned dg_len, dg_len2; |
| 967 | unsigned ndp_len; | 1129 | unsigned ndp_len; |
| 968 | struct sk_buff *skb2; | 1130 | struct sk_buff *skb2; |
| @@ -995,91 +1157,101 @@ static int ncm_unwrap_ntb(struct gether *port, · 26 unmodified lines | |||
| 995 | goto err; | 1157 | goto err; |
| 996 | } | 1158 | } |
| 997 | 1159 | ||
| 998 | index = get_ncm(&tmp, opts->fp_index); | 1160 | ndp_index = get_ncm(&tmp, opts->ndp_index); |
| 999 | /* NCM 3.2 */ | ||
| 1000 | if (((index % 4) != 0) && (index < opts->nth_size)) { | ||
| 1001 | INFO(port->func.config->cdev, "Bad index: %x\n", | ||
| 1002 | index); | ||
| 1003 | goto err; | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | /* walk through NDP */ | ||
| 1007 | tmp = ((void *)skb->data) + index; | ||
| 1008 | if (get_unaligned_le32(tmp) != ncm->ndp_sign) { | ||
| 1009 | INFO(port->func.config->cdev, "Wrong NDP SIGN\n"); | ||
| 1010 | goto err; | ||
| 1011 | } | ||
| 1012 | tmp += 2; | ||
| 1013 | |||
| 1014 | ndp_len = get_unaligned_le16(tmp++); | ||
| 1015 | /* | ||
| 1016 | * NCM 3.3.1 | ||
| 1017 | * entry is 2 items | ||
| 1018 | * item size is 16/32 bits, opts->dgram_item_len * 2 bytes | ||
| 1019 | * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry | ||
| 1020 | */ | ||
| 1021 | if ((ndp_len < opts->ndp_size + 2 * 2 * (opts->dgram_item_len * 2)) | ||
| 1022 | || (ndp_len % opts->ndplen_align != 0)) { | ||
| 1023 | INFO(port->func.config->cdev, "Bad NDP length: %x\n", ndp_len); | ||
| 1024 | goto err; | ||
| 1025 | } | ||
| 1026 | tmp += opts->reserved1; | ||
| 1027 | tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */ | ||
| 1028 | tmp += opts->reserved2; | ||
| 1029 | |||
| 1030 | ndp_len -= opts->ndp_size; | ||
| 1031 | index2 = get_ncm(&tmp, opts->dgram_item_len); | ||
| 1032 | dg_len2 = get_ncm(&tmp, opts->dgram_item_len); | ||
| 1033 | dgram_counter = 0; | ||
| 1034 | 1161 | ||
| 1162 | /* Run through all the NDP's in the NTB */ | ||
| 1035 | do { | 1163 | do { |
| 1036 | index = index2; | 1164 | /* NCM 3.2 */ |
| 1037 | dg_len = dg_len2; | 1165 | if (((ndp_index % 4) != 0) && |
| 1038 | if (dg_len < 14 + crc_len) { /* ethernet header + crc */ | 1166 | (ndp_index < opts->nth_size)) { |
| 1039 | INFO(port->func.config->cdev, "Bad dgram length: %x\n", | 1167 | INFO(port->func.config->cdev, "Bad index: %#X\n", |
| 1040 | dg_len); | 1168 | ndp_index); |
| 1041 | goto err; | 1169 | goto err; |
| 1042 | } | 1170 | } |
| 1043 | if (ncm->is_crc) { | 1171 | |
| 1044 | uint32_t crc, crc2; | 1172 | /* walk through NDP */ |
| 1045 | 1173 | tmp = (void *)(skb->data + ndp_index); | |
| 1046 | crc = get_unaligned_le32(skb->data + | 1174 | if (get_unaligned_le32(tmp) != ncm->ndp_sign) { |
| 1047 | index + dg_len - crc_len); | 1175 | INFO(port->func.config->cdev, "Wrong NDP SIGN\n"); |
| 1048 | crc2 = ~crc32_le(~0, | 1176 | goto err; |
| 1049 | skb->data + index, | ||
| 1050 | dg_len - crc_len); | ||
| 1051 | if (crc != crc2) { | ||
| 1052 | INFO(port->func.config->cdev, "Bad CRC\n"); | ||
| 1053 | goto err; | ||
| 1054 | } | ||
| 1055 | } | 1177 | } |
| 1178 | tmp += 2; | ||
| 1056 | 1179 | ||
| 1180 | ndp_len = get_unaligned_le16(tmp++); | ||
| 1181 | /* | ||
| 1182 | * NCM 3.3.1 | ||
| 1183 | * entry is 2 items | ||
| 1184 | * item size is 16/32 bits, opts->dgram_item_len * 2 bytes | ||
| 1185 | * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry | ||
| 1186 | * Each entry is a dgram index and a dgram length. | ||
| 1187 | */ | ||
| 1188 | if ((ndp_len < opts->ndp_size | ||
| 1189 | + 2 * 2 * (opts->dgram_item_len * 2)) | ||
| 1190 | || (ndp_len % opts->ndplen_align != 0)) { | ||
| 1191 | INFO(port->func.config->cdev, "Bad NDP length: %#X\n", | ||
| 1192 | ndp_len); | ||
| 1193 | goto err; | ||
| 1194 | } | ||
| 1195 | tmp += opts->reserved1; | ||
| 1196 | /* Check for another NDP (d)wNextNdpIndex */ | ||
| 1197 | ndp_index = get_ncm(&tmp, opts->next_ndp_index); | ||
| 1198 | tmp += opts->reserved2; | ||
| 1199 | |||
| 1200 | ndp_len -= opts->ndp_size; | ||
| 1057 | index2 = get_ncm(&tmp, opts->dgram_item_len); | 1201 | index2 = get_ncm(&tmp, opts->dgram_item_len); |
| 1058 | dg_len2 = get_ncm(&tmp, opts->dgram_item_len); | 1202 | dg_len2 = get_ncm(&tmp, opts->dgram_item_len); |
| 1203 | dgram_counter = 0; | ||
| 1204 | |||
| 1205 | do { | ||
| 1206 | index = index2; | ||
| 1207 | dg_len = dg_len2; | ||
| 1208 | if (dg_len < 14 + crc_len) { /* ethernet hdr + crc */ | ||
| 1209 | INFO(port->func.config->cdev, | ||
| 1210 | "Bad dgram length: %#X\n", dg_len); | ||
| 1211 | goto err; | ||
| 1212 | } | ||
| 1213 | if (ncm->is_crc) { | ||
| 1214 | uint32_t crc, crc2; | ||
| 1215 | |||
| 1216 | crc = get_unaligned_le32(skb->data + | ||
| 1217 | index + dg_len - | ||
| 1218 | crc_len); | ||
| 1219 | crc2 = ~crc32_le(~0, | ||
| 1220 | skb->data + index, | ||
| 1221 | dg_len - crc_len); | ||
| 1222 | if (crc != crc2) { | ||
| 1223 | INFO(port->func.config->cdev, | ||
| 1224 | "Bad CRC\n"); | ||
| 1225 | goto err; | ||
| 1226 | } | ||
| 1227 | } | ||
| 1228 | |||
| 1229 | index2 = get_ncm(&tmp, opts->dgram_item_len); | ||
| 1230 | dg_len2 = get_ncm(&tmp, opts->dgram_item_len); | ||
| 1059 | 1231 | ||
| 1060 | if (index2 == 0 || dg_len2 == 0) { | 1232 | /* |
| 1061 | skb2 = skb; | 1233 | * Copy the data into a new skb. |
| 1062 | } else { | 1234 | * This ensures the truesize is correct |
| 1063 | skb2 = skb_clone(skb, GFP_ATOMIC); | 1235 | */ |
| 1236 | skb2 = netdev_alloc_skb_ip_align(ncm->netdev, | ||
| 1237 | dg_len - crc_len); | ||
| 1064 | if (skb2 == NULL) | 1238 | if (skb2 == NULL) |
| 1065 | goto err; | 1239 | goto err; |
| 1066 | } | 1240 | memcpy(skb_put(skb2, dg_len - crc_len), |
| 1241 | skb->data + index, dg_len - crc_len); | ||
| 1067 | 1242 | ||
| 1068 | if (!skb_pull(skb2, index)) { | 1243 | skb_queue_tail(list, skb2); |
| 1069 | ret = -EOVERFLOW; | ||
| 1070 | goto err; | ||
| 1071 | } | ||
| 1072 | 1244 | ||
| 1073 | skb_trim(skb2, dg_len - crc_len); | 1245 | ndp_len -= 2 * (opts->dgram_item_len * 2); |
| 1074 | skb_queue_tail(list, skb2); | ||
| 1075 | 1246 | ||
| 1076 | ndp_len -= 2 * (opts->dgram_item_len * 2); | 1247 | dgram_counter++; |
| 1077 | 1248 | ||
| 1078 | dgram_counter++; | 1249 | if (index2 == 0 || dg_len2 == 0) |
| 1250 | break; | ||
| 1251 | } while (ndp_len > 2 * (opts->dgram_item_len * 2)); | ||
| 1252 | } while (ndp_index); | ||
| 1079 | 1253 | ||
| 1080 | if (index2 == 0 || dg_len2 == 0) | 1254 | dev_kfree_skb_any(skb); |
| 1081 | break; | ||
| 1082 | } while (ndp_len > 2 * (opts->dgram_item_len * 2)); /* zero entry */ | ||
| 1083 | 1255 | ||
| 1084 | VDBG(port->func.config->cdev, | 1256 | VDBG(port->func.config->cdev, |
| 1085 | "Parsed NTB with %d frames\n", dgram_counter); | 1257 | "Parsed NTB with %d frames\n", dgram_counter); |
| @@ -1097,8 +1269,11 @@ static void ncm_disable(struct usb_function *f) · 11 unmodified lines | |||
| 1097 | 1269 | ||
| 1098 | DBG(cdev, "ncm deactivated\n"); | 1270 | DBG(cdev, "ncm deactivated\n"); |
| 1099 | 1271 | ||
| 1100 | if (ncm->port.in_ep->driver_data) | 1272 | if (ncm->port.in_ep->driver_data) { |
| 1273 | ncm->timer_stopping = true; | ||
| 1274 | ncm->netdev = NULL; | ||
| 1101 | gether_disconnect(&ncm->port); | 1275 | gether_disconnect(&ncm->port); |
| 1276 | } | ||
| 1102 | 1277 | ||
| 1103 | if (ncm->notify->driver_data) { | 1278 | if (ncm->notify->driver_data) { |
| 1104 | usb_ep_disable(ncm->notify); | 1279 | usb_ep_disable(ncm->notify); |
| @@ -1267,6 +1442,10 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f) · 162 unmodified lines | |||
| 1267 | ncm->port.open = ncm_open; | 1442 | ncm->port.open = ncm_open; |
| 1268 | ncm->port.close = ncm_close; | 1443 | ncm->port.close = ncm_close; |
| 1269 | 1444 | ||
| 1445 | tasklet_init(&ncm->tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm); | ||
| 1446 | hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
| 1447 | ncm->task_timer.function = ncm_tx_timeout; | ||
| 1448 | |||
| 1270 | DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n", | 1449 | DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n", |
| 1271 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 1450 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
| 1272 | ncm->port.in_ep->name, ncm->port.out_ep->name, | 1451 | ncm->port.in_ep->name, ncm->port.out_ep->name, |
| @@ -1380,6 +1559,10 @@ static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) · 107 unmodified lines | |||
| 1380 | 1559 | ||
| 1381 | DBG(c->cdev, "ncm unbind\n"); | 1560 | DBG(c->cdev, "ncm unbind\n"); |
| 1382 | 1561 | ||
| 1562 | hrtimer_cancel(&ncm->task_timer); | ||
| 1563 | tasklet_kill(&ncm->tx_tasklet); | ||
| 1564 | |||
| 1565 | ncm_string_defs[0].id = 0; | ||
| 1383 | usb_free_all_descriptors(f); | 1566 | usb_free_all_descriptors(f); |
| 1384 | 1567 | ||
| 1385 | kfree(ncm->notify_req->buf); | 1568 | kfree(ncm->notify_req->buf); |
| @@ -1416,6 +1599,7 @@ static struct usb_function *ncm_alloc(struct usb_function_instance *fi) · 30 unmodified lines | |||
| 1416 | ncm->port.ioport = netdev_priv(opts->net); | 1599 | ncm->port.ioport = netdev_priv(opts->net); |
| 1417 | mutex_unlock(&opts->lock); | 1600 | mutex_unlock(&opts->lock); |
| 1418 | ncm->port.is_fixed = true; | 1601 | ncm->port.is_fixed = true; |
| 1602 | ncm->port.supports_multi_frame = true; | ||
| 1419 | 1603 | ||
| 1420 | ncm->port.func.name = "cdc_network"; | 1604 | ncm->port.func.name = "cdc_network"; |
| 1421 | /* descriptors are per-instance copies */ | 1605 | /* descriptors are per-instance copies */ |
File renamed without changes.
File renamed without changes.
| @@ -727,6 +727,10 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) · 726 unmodified lines | |||
| 727 | rndis_control_intf.bInterfaceNumber = status; | 727 | rndis_control_intf.bInterfaceNumber = status; |
| 728 | rndis_union_desc.bMasterInterface0 = status; | 728 | rndis_union_desc.bMasterInterface0 = status; |
| 729 | 729 | ||
| 730 | if (cdev->use_os_string) | ||
| 731 | f->os_desc_table[0].if_id = | ||
| 732 | rndis_iad_descriptor.bFirstInterface; | ||
| 733 | |||
| 730 | status = usb_interface_id(c, f); | 734 | status = usb_interface_id(c, f); |
| 731 | if (status < 0) | 735 | if (status < 0) |
| 732 | goto fail; | 736 | goto fail; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -348,14 +348,34 @@ static int uac2_pcm_open(struct snd_pcm_substream *substream) · 347 unmodified lines | |||
| 348 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 348 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 349 | spin_lock_init(&uac2->p_prm.lock); | 349 | spin_lock_init(&uac2->p_prm.lock); |
| 350 | runtime->hw.rate_min = p_srate; | 350 | runtime->hw.rate_min = p_srate; |
| 351 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; /* ! p_ssize ! */ | 351 | switch (p_ssize) { |
| 352 | case 3: | ||
| 353 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE; | ||
| 354 | break; | ||
| 355 | case 4: | ||
| 356 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; | ||
| 357 | break; | ||
| 358 | default: | ||
| 359 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; | ||
| 360 | break; | ||
| 361 | } | ||
| 352 | runtime->hw.channels_min = num_channels(p_chmask); | 362 | runtime->hw.channels_min = num_channels(p_chmask); |
| 353 | runtime->hw.period_bytes_min = 2 * uac2->p_prm.max_psize | 363 | runtime->hw.period_bytes_min = 2 * uac2->p_prm.max_psize |
| 354 | / runtime->hw.periods_min; | 364 | / runtime->hw.periods_min; |
| 355 | } else { | 365 | } else { |
| 356 | spin_lock_init(&uac2->c_prm.lock); | 366 | spin_lock_init(&uac2->c_prm.lock); |
| 357 | runtime->hw.rate_min = c_srate; | 367 | runtime->hw.rate_min = c_srate; |
| 358 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; /* ! c_ssize ! */ | 368 | switch (c_ssize) { |
| 369 | case 3: | ||
| 370 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE; | ||
| 371 | break; | ||
| 372 | case 4: | ||
| 373 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; | ||
| 374 | break; | ||
| 375 | default: | ||
| 376 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; | ||
| 377 | break; | ||
| 378 | } | ||
| 359 | runtime->hw.channels_min = num_channels(c_chmask); | 379 | runtime->hw.channels_min = num_channels(c_chmask); |
| 360 | runtime->hw.period_bytes_min = 2 * uac2->c_prm.max_psize | 380 | runtime->hw.period_bytes_min = 2 * uac2->c_prm.max_psize |
| 361 | / runtime->hw.periods_min; | 381 | / runtime->hw.periods_min; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -483,7 +483,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 482 unmodified lines | |||
| 483 | struct net_device *net) | 483 | struct net_device *net) |
| 484 | { | 484 | { |
| 485 | struct eth_dev *dev = netdev_priv(net); | 485 | struct eth_dev *dev = netdev_priv(net); |
| 486 | int length = skb->len; | 486 | int length = 0; |
| 487 | int retval; | 487 | int retval; |
| 488 | struct usb_request *req = NULL; | 488 | struct usb_request *req = NULL; |
| 489 | unsigned long flags; | 489 | unsigned long flags; |
| @@ -500,13 +500,13 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 10 unmodified lines | |||
| 500 | } | 500 | } |
| 501 | spin_unlock_irqrestore(&dev->lock, flags); | 501 | spin_unlock_irqrestore(&dev->lock, flags); |
| 502 | 502 | ||
| 503 | if (!in) { | 503 | if (skb && !in) { |
| 504 | dev_kfree_skb_any(skb); | 504 | dev_kfree_skb_any(skb); |
| 505 | return NETDEV_TX_OK; | 505 | return NETDEV_TX_OK; |
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | /* apply outgoing CDC or RNDIS filters */ | 508 | /* apply outgoing CDC or RNDIS filters */ |
| 509 | if (!is_promisc(cdc_filter)) { | 509 | if (skb && !is_promisc(cdc_filter)) { |
| 510 | u8 *dest = skb->data; | 510 | u8 *dest = skb->data; |
| 511 | 511 | ||
| 512 | if (is_multicast_ether_addr(dest)) { | 512 | if (is_multicast_ether_addr(dest)) { |
| @@ -557,11 +557,17 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 44 unmodified lines | |||
| 557 | if (dev->port_usb) | 557 | if (dev->port_usb) |
| 558 | skb = dev->wrap(dev->port_usb, skb); | 558 | skb = dev->wrap(dev->port_usb, skb); |
| 559 | spin_unlock_irqrestore(&dev->lock, flags); | 559 | spin_unlock_irqrestore(&dev->lock, flags); |
| 560 | if (!skb) | 560 | if (!skb) { |
| 561 | /* Multi frame CDC protocols may store the frame for | ||
| 562 | * later which is not a dropped frame. | ||
| 563 | */ | ||
| 564 | if (dev->port_usb->supports_multi_frame) | ||
| 565 | goto multiframe; | ||
| 561 | goto drop; | 566 | goto drop; |
| 562 | 567 | } | |
| 563 | length = skb->len; | ||
| 564 | } | 568 | } |
| 569 | |||
| 570 | length = skb->len; | ||
| 565 | req->buf = skb->data; | 571 | req->buf = skb->data; |
| 566 | req->context = skb; | 572 | req->context = skb; |
| 567 | req->complete = tx_complete; | 573 | req->complete = tx_complete; |
| @@ -604,6 +610,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 36 unmodified lines | |||
| 604 | dev_kfree_skb_any(skb); | 610 | dev_kfree_skb_any(skb); |
| 605 | drop: | 611 | drop: |
| 606 | dev->net->stats.tx_dropped++; | 612 | dev->net->stats.tx_dropped++; |
| 613 | multiframe: | ||
| 607 | spin_lock_irqsave(&dev->req_lock, flags); | 614 | spin_lock_irqsave(&dev->req_lock, flags); |
| 608 | if (list_empty(&dev->tx_reqs)) | 615 | if (list_empty(&dev->tx_reqs)) |
| 609 | netif_start_queue(net); | 616 | netif_start_queue(net); |
| @@ -18,6 +18,7 @@ · 17 unmodified lines | |||
| 18 | #include <linux/if_ether.h> | 18 | #include <linux/if_ether.h> |
| 19 | #include <linux/usb/composite.h> | 19 | #include <linux/usb/composite.h> |
| 20 | #include <linux/usb/cdc.h> | 20 | #include <linux/usb/cdc.h> |
| 21 | #include <linux/netdevice.h> | ||
| 21 | 22 | ||
| 22 | #include "gadget_chips.h" | 23 | #include "gadget_chips.h" |
| 23 | 24 | ||
| @@ -74,6 +75,7 @@ struct gether { · 50 unmodified lines | |||
| 74 | bool is_fixed; | 75 | bool is_fixed; |
| 75 | u32 fixed_out_len; | 76 | u32 fixed_out_len; |
| 76 | u32 fixed_in_len; | 77 | u32 fixed_in_len; |
| 78 | bool supports_multi_frame; | ||
| 77 | struct sk_buff *(*wrap)(struct gether *port, | 79 | struct sk_buff *(*wrap)(struct gether *port, |
| 78 | struct sk_buff *skb); | 80 | struct sk_buff *skb); |
| 79 | int (*unwrap)(struct gether *port, | 81 | int (*unwrap)(struct gether *port, |
File renamed without changes.
| @@ -216,6 +216,13 @@ struct ffs_data { · 215 unmodified lines | |||
| 216 | unsigned fs_descs_count; | 216 | unsigned fs_descs_count; |
| 217 | unsigned hs_descs_count; | 217 | unsigned hs_descs_count; |
| 218 | unsigned ss_descs_count; | 218 | unsigned ss_descs_count; |
| 219 | unsigned ms_os_descs_count; | ||
| 220 | unsigned ms_os_descs_ext_prop_count; | ||
| 221 | unsigned ms_os_descs_ext_prop_name_len; | ||
| 222 | unsigned ms_os_descs_ext_prop_data_len; | ||
| 223 | void *ms_os_descs_ext_prop_avail; | ||
| 224 | void *ms_os_descs_ext_prop_name_avail; | ||
| 225 | void *ms_os_descs_ext_prop_data_avail; | ||
| 219 | 226 | ||
| 220 | unsigned short strings_count; | 227 | unsigned short strings_count; |
| 221 | unsigned short interfaces_count; | 228 | unsigned short interfaces_count; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -0,0 +1,475 @@ | |||
| 1 | # | ||
| 2 | # USB Gadget support on a system involves | ||
| 3 | # (a) a peripheral controller, and | ||
| 4 | # (b) the gadget driver using it. | ||
| 5 | # | ||
| 6 | # NOTE: Gadget support ** DOES NOT ** depend on host-side CONFIG_USB !! | ||
| 7 | # | ||
| 8 | # - Host systems (like PCs) need CONFIG_USB (with "A" jacks). | ||
| 9 | # - Peripherals (like PDAs) need CONFIG_USB_GADGET (with "B" jacks). | ||
| 10 | # - Some systems have both kinds of controllers. | ||
| 11 | # | ||
| 12 | # With help from a special transceiver and a "Mini-AB" jack, systems with | ||
| 13 | # both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG). | ||
| 14 | # | ||
| 15 | |||
| 16 | config USB_ZERO | ||
| 17 | tristate "Gadget Zero (DEVELOPMENT)" | ||
| 18 | select USB_LIBCOMPOSITE | ||
| 19 | select USB_F_SS_LB | ||
| 20 | help | ||
| 21 | Gadget Zero is a two-configuration device. It either sinks and | ||
| 22 | sources bulk data; or it loops back a configurable number of | ||
| 23 | transfers. It also implements control requests, for "chapter 9" | ||
| 24 | conformance. The driver needs only two bulk-capable endpoints, so | ||
| 25 | it can work on top of most device-side usb controllers. It's | ||
| 26 | useful for testing, and is also a working example showing how | ||
| 27 | USB "gadget drivers" can be written. | ||
| 28 | |||
| 29 | Make this be the first driver you try using on top of any new | ||
| 30 | USB peripheral controller driver. Then you can use host-side | ||
| 31 | test software, like the "usbtest" driver, to put your hardware | ||
| 32 | and its driver through a basic set of functional tests. | ||
| 33 | |||
| 34 | Gadget Zero also works with the host-side "usb-skeleton" driver, | ||
| 35 | and with many kinds of host-side test software. You may need | ||
| 36 | to tweak product and vendor IDs before host software knows about | ||
| 37 | this device, and arrange to select an appropriate configuration. | ||
| 38 | |||
| 39 | Say "y" to link the driver statically, or "m" to build a | ||
| 40 | dynamically linked module called "g_zero". | ||
| 41 | |||
| 42 | config USB_ZERO_HNPTEST | ||
| 43 | boolean "HNP Test Device" | ||
| 44 | depends on USB_ZERO && USB_OTG | ||
| 45 | help | ||
| 46 | You can configure this device to enumerate using the device | ||
| 47 | identifiers of the USB-OTG test device. That means that when | ||
| 48 | this gadget connects to another OTG device, with this one using | ||
| 49 | the "B-Peripheral" role, that device will use HNP to let this | ||
| 50 | one serve as the USB host instead (in the "B-Host" role). | ||
| 51 | |||
| 52 | config USB_AUDIO | ||
| 53 | tristate "Audio Gadget" | ||
| 54 | depends on SND | ||
| 55 | select USB_LIBCOMPOSITE | ||
| 56 | select SND_PCM | ||
| 57 | help | ||
| 58 | This Gadget Audio driver is compatible with USB Audio Class | ||
| 59 | specification 2.0. It implements 1 AudioControl interface, | ||
| 60 | 1 AudioStreaming Interface each for USB-OUT and USB-IN. | ||
| 61 | Number of channels, sample rate and sample size can be | ||
| 62 | specified as module parameters. | ||
| 63 | This driver doesn't expect any real Audio codec to be present | ||
| 64 | on the device - the audio streams are simply sinked to and | ||
| 65 | sourced from a virtual ALSA sound card created. The user-space | ||
| 66 | application may choose to do whatever it wants with the data | ||
| 67 | received from the USB Host and choose to provide whatever it | ||
| 68 | wants as audio data to the USB Host. | ||
| 69 | |||
| 70 | Say "y" to link the driver statically, or "m" to build a | ||
| 71 | dynamically linked module called "g_audio". | ||
| 72 | |||
| 73 | config GADGET_UAC1 | ||
| 74 | bool "UAC 1.0 (Legacy)" | ||
| 75 | depends on USB_AUDIO | ||
| 76 | help | ||
| 77 | If you instead want older UAC Spec-1.0 driver that also has audio | ||
| 78 | paths hardwired to the Audio codec chip on-board and doesn't work | ||
| 79 | without one. | ||
| 80 | |||
| 81 | config USB_ETH | ||
| 82 | tristate "Ethernet Gadget (with CDC Ethernet support)" | ||
| 83 | depends on NET | ||
| 84 | select USB_LIBCOMPOSITE | ||
| 85 | select USB_U_ETHER | ||
| 86 | select USB_F_ECM | ||
| 87 | select USB_F_SUBSET | ||
| 88 | select CRC32 | ||
| 89 | help | ||
| 90 | This driver implements Ethernet style communication, in one of | ||
| 91 | several ways: | ||
| 92 | |||
| 93 | - The "Communication Device Class" (CDC) Ethernet Control Model. | ||
| 94 | That protocol is often avoided with pure Ethernet adapters, in | ||
| 95 | favor of simpler vendor-specific hardware, but is widely | ||
| 96 | supported by firmware for smart network devices. | ||
| 97 | |||
| 98 | - On hardware can't implement that protocol, a simple CDC subset | ||
| 99 | is used, placing fewer demands on USB. | ||
| 100 | |||
| 101 | - CDC Ethernet Emulation Model (EEM) is a newer standard that has | ||
| 102 | a simpler interface that can be used by more USB hardware. | ||
| 103 | |||
| 104 | RNDIS support is an additional option, more demanding than than | ||
| 105 | subset. | ||
| 106 | |||
| 107 | Within the USB device, this gadget driver exposes a network device | ||
| 108 | "usbX", where X depends on what other networking devices you have. | ||
| 109 | Treat it like a two-node Ethernet link: host, and gadget. | ||
| 110 | |||
| 111 | The Linux-USB host-side "usbnet" driver interoperates with this | ||
| 112 | driver, so that deep I/O queues can be supported. On 2.4 kernels, | ||
| 113 | use "CDCEther" instead, if you're using the CDC option. That CDC | ||
| 114 | mode should also interoperate with standard CDC Ethernet class | ||
| 115 | drivers on other host operating systems. | ||
| 116 | |||
| 117 | Say "y" to link the driver statically, or "m" to build a | ||
| 118 | dynamically linked module called "g_ether". | ||
| 119 | |||
| 120 | config USB_ETH_RNDIS | ||
| 121 | bool "RNDIS support" | ||
| 122 | depends on USB_ETH | ||
| 123 | select USB_LIBCOMPOSITE | ||
| 124 | select USB_F_RNDIS | ||
| 125 | default y | ||
| 126 | help | ||
| 127 | Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, | ||
| 128 | and Microsoft provides redistributable binary RNDIS drivers for | ||
| 129 | older versions of Windows. | ||
| 130 | |||
| 131 | If you say "y" here, the Ethernet gadget driver will try to provide | ||
| 132 | a second device configuration, supporting RNDIS to talk to such | ||
| 133 | Microsoft USB hosts. | ||
| 134 | |||
| 135 | To make MS-Windows work with this, use Documentation/usb/linux.inf | ||
| 136 | as the "driver info file". For versions of MS-Windows older than | ||
| 137 | XP, you'll need to download drivers from Microsoft's website; a URL | ||
| 138 | is given in comments found in that info file. | ||
| 139 | |||
| 140 | config USB_ETH_EEM | ||
| 141 | bool "Ethernet Emulation Model (EEM) support" | ||
| 142 | depends on USB_ETH | ||
| 143 | select USB_LIBCOMPOSITE | ||
| 144 | select USB_F_EEM | ||
| 145 | default n | ||
| 146 | help | ||
| 147 | CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM | ||
| 148 | and therefore can be supported by more hardware. Technically ECM and | ||
| 149 | EEM are designed for different applications. The ECM model extends | ||
| 150 | the network interface to the target (e.g. a USB cable modem), and the | ||
| 151 | EEM model is for mobile devices to communicate with hosts using | ||
| 152 | ethernet over USB. For Linux gadgets, however, the interface with | ||
| 153 | the host is the same (a usbX device), so the differences are minimal. | ||
| 154 | |||
| 155 | If you say "y" here, the Ethernet gadget driver will use the EEM | ||
| 156 | protocol rather than ECM. If unsure, say "n". | ||
| 157 | |||
| 158 | config USB_G_NCM | ||
| 159 | tristate "Network Control Model (NCM) support" | ||
| 160 | depends on NET | ||
| 161 | select USB_LIBCOMPOSITE | ||
| 162 | select USB_U_ETHER | ||
| 163 | select USB_F_NCM | ||
| 164 | select CRC32 | ||
| 165 | help | ||
| 166 | This driver implements USB CDC NCM subclass standard. NCM is | ||
| 167 | an advanced protocol for Ethernet encapsulation, allows grouping | ||
| 168 | of several ethernet frames into one USB transfer and different | ||
| 169 | alignment possibilities. | ||
| 170 | |||
| 171 | Say "y" to link the driver statically, or "m" to build a | ||
| 172 | dynamically linked module called "g_ncm". | ||
| 173 | |||
| 174 | config USB_GADGETFS | ||
| 175 | tristate "Gadget Filesystem" | ||
| 176 | help | ||
| 177 | This driver provides a filesystem based API that lets user mode | ||
| 178 | programs implement a single-configuration USB device, including | ||
| 179 | endpoint I/O and control requests that don't relate to enumeration. | ||
| 180 | All endpoints, transfer speeds, and transfer types supported by | ||
| 181 | the hardware are available, through read() and write() calls. | ||
| 182 | |||
| 183 | Say "y" to link the driver statically, or "m" to build a | ||
| 184 | dynamically linked module called "gadgetfs". | ||
| 185 | |||
| 186 | config USB_FUNCTIONFS | ||
| 187 | tristate "Function Filesystem" | ||
| 188 | select USB_LIBCOMPOSITE | ||
| 189 | select USB_F_FS | ||
| 190 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) | ||
| 191 | help | ||
| 192 | The Function Filesystem (FunctionFS) lets one create USB | ||
| 193 | composite functions in user space in the same way GadgetFS | ||
| 194 | lets one create USB gadgets in user space. This allows creation | ||
| 195 | of composite gadgets such that some of the functions are | ||
| 196 | implemented in kernel space (for instance Ethernet, serial or | ||
| 197 | mass storage) and other are implemented in user space. | ||
| 198 | |||
| 199 | If you say "y" or "m" here you will be able what kind of | ||
| 200 | configurations the gadget will provide. | ||
| 201 | |||
| 202 | Say "y" to link the driver statically, or "m" to build | ||
| 203 | a dynamically linked module called "g_ffs". | ||
| 204 | |||
| 205 | config USB_FUNCTIONFS_ETH | ||
| 206 | bool "Include configuration with CDC ECM (Ethernet)" | ||
| 207 | depends on USB_FUNCTIONFS && NET | ||
| 208 | select USB_U_ETHER | ||
| 209 | select USB_F_ECM | ||
| 210 | select USB_F_SUBSET | ||
| 211 | help | ||
| 212 | Include a configuration with CDC ECM function (Ethernet) and the | ||
| 213 | Function Filesystem. | ||
| 214 | |||
| 215 | config USB_FUNCTIONFS_RNDIS | ||
| 216 | bool "Include configuration with RNDIS (Ethernet)" | ||
| 217 | depends on USB_FUNCTIONFS && NET | ||
| 218 | select USB_U_ETHER | ||
| 219 | select USB_F_RNDIS | ||
| 220 | help | ||
| 221 | Include a configuration with RNDIS function (Ethernet) and the Filesystem. | ||
| 222 | |||
| 223 | config USB_FUNCTIONFS_GENERIC | ||
| 224 | bool "Include 'pure' configuration" | ||
| 225 | depends on USB_FUNCTIONFS | ||
| 226 | help | ||
| 227 | Include a configuration with the Function Filesystem alone with | ||
| 228 | no Ethernet interface. | ||
| 229 | |||
| 230 | config USB_MASS_STORAGE | ||
| 231 | tristate "Mass Storage Gadget" | ||
| 232 | depends on BLOCK | ||
| 233 | select USB_LIBCOMPOSITE | ||
| 234 | select USB_F_MASS_STORAGE | ||
| 235 | help | ||
| 236 | The Mass Storage Gadget acts as a USB Mass Storage disk drive. | ||
| 237 | As its storage repository it can use a regular file or a block | ||
| 238 | device (in much the same way as the "loop" device driver), | ||
| 239 | specified as a module parameter or sysfs option. | ||
| 240 | |||
| 241 | This driver is a replacement for now removed File-backed | ||
| 242 | Storage Gadget (g_file_storage). | ||
| 243 | |||
| 244 | Say "y" to link the driver statically, or "m" to build | ||
| 245 | a dynamically linked module called "g_mass_storage". | ||
| 246 | |||
| 247 | config USB_GADGET_TARGET | ||
| 248 | tristate "USB Gadget Target Fabric Module" | ||
| 249 | depends on TARGET_CORE | ||
| 250 | select USB_LIBCOMPOSITE | ||
| 251 | help | ||
| 252 | This fabric is an USB gadget. Two USB protocols are supported that is | ||
| 253 | BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is | ||
| 254 | advertised on alternative interface 0 (primary) and UAS is on | ||
| 255 | alternative interface 1. Both protocols can work on USB2.0 and USB3.0. | ||
| 256 | UAS utilizes the USB 3.0 feature called streams support. | ||
| 257 | |||
| 258 | config USB_G_SERIAL | ||
| 259 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" | ||
| 260 | depends on TTY | ||
| 261 | select USB_U_SERIAL | ||
| 262 | select USB_F_ACM | ||
| 263 | select USB_F_SERIAL | ||
| 264 | select USB_F_OBEX | ||
| 265 | select USB_LIBCOMPOSITE | ||
| 266 | help | ||
| 267 | The Serial Gadget talks to the Linux-USB generic serial driver. | ||
| 268 | This driver supports a CDC-ACM module option, which can be used | ||
| 269 | to interoperate with MS-Windows hosts or with the Linux-USB | ||
| 270 | "cdc-acm" driver. | ||
| 271 | |||
| 272 | This driver also supports a CDC-OBEX option. You will need a | ||
| 273 | user space OBEX server talking to /dev/ttyGS*, since the kernel | ||
| 274 | itself doesn't implement the OBEX protocol. | ||
| 275 | |||
| 276 | Say "y" to link the driver statically, or "m" to build a | ||
| 277 | dynamically linked module called "g_serial". | ||
| 278 | |||
| 279 | For more information, see Documentation/usb/gadget_serial.txt | ||
| 280 | which includes instructions and a "driver info file" needed to | ||
| 281 | make MS-Windows work with CDC ACM. | ||
| 282 | |||
| 283 | config USB_MIDI_GADGET | ||
| 284 | tristate "MIDI Gadget" | ||
| 285 | depends on SND | ||
| 286 | select USB_LIBCOMPOSITE | ||
| 287 | select SND_RAWMIDI | ||
| 288 | help | ||
| 289 | The MIDI Gadget acts as a USB Audio device, with one MIDI | ||
| 290 | input and one MIDI output. These MIDI jacks appear as | ||
| 291 | a sound "card" in the ALSA sound system. Other MIDI | ||
| 292 | connections can then be made on the gadget system, using | ||
| 293 | ALSA's aconnect utility etc. | ||
| 294 | |||
| 295 | Say "y" to link the driver statically, or "m" to build a | ||
| 296 | dynamically linked module called "g_midi". | ||
| 297 | |||
| 298 | config USB_G_PRINTER | ||
| 299 | tristate "Printer Gadget" | ||
| 300 | select USB_LIBCOMPOSITE | ||
| 301 | help | ||
| 302 | The Printer Gadget channels data between the USB host and a | ||
| 303 | userspace program driving the print engine. The user space | ||
| 304 | program reads and writes the device file /dev/g_printer to | ||
| 305 | receive or send printer data. It can use ioctl calls to | ||
| 306 | the device file to get or set printer status. | ||
| 307 | |||
| 308 | Say "y" to link the driver statically, or "m" to build a | ||
| 309 | dynamically linked module called "g_printer". | ||
| 310 | |||
| 311 | For more information, see Documentation/usb/gadget_printer.txt | ||
| 312 | which includes sample code for accessing the device file. | ||
| 313 | |||
| 314 | if TTY | ||
| 315 | |||
| 316 | config USB_CDC_COMPOSITE | ||
| 317 | tristate "CDC Composite Device (Ethernet and ACM)" | ||
| 318 | depends on NET | ||
| 319 | select USB_LIBCOMPOSITE | ||
| 320 | select USB_U_SERIAL | ||
| 321 | select USB_U_ETHER | ||
| 322 | select USB_F_ACM | ||
| 323 | select USB_F_ECM | ||
| 324 | help | ||
| 325 | This driver provides two functions in one configuration: | ||
| 326 | a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link. | ||
| 327 | |||
| 328 | This driver requires four bulk and two interrupt endpoints, | ||
| 329 | plus the ability to handle altsettings. Not all peripheral | ||
| 330 | controllers are that capable. | ||
| 331 | |||
| 332 | Say "y" to link the driver statically, or "m" to build a | ||
| 333 | dynamically linked module. | ||
| 334 | |||
| 335 | config USB_G_NOKIA | ||
| 336 | tristate "Nokia composite gadget" | ||
| 337 | depends on PHONET | ||
| 338 | select USB_LIBCOMPOSITE | ||
| 339 | select USB_U_SERIAL | ||
| 340 | select USB_U_ETHER | ||
| 341 | select USB_F_ACM | ||
| 342 | select USB_F_OBEX | ||
| 343 | select USB_F_PHONET | ||
| 344 | select USB_F_ECM | ||
| 345 | help | ||
| 346 | The Nokia composite gadget provides support for acm, obex | ||
| 347 | and phonet in only one composite gadget driver. | ||
| 348 | |||
| 349 | It's only really useful for N900 hardware. If you're building | ||
| 350 | a kernel for N900, say Y or M here. If unsure, say N. | ||
| 351 | |||
| 352 | config USB_G_ACM_MS | ||
| 353 | tristate "CDC Composite Device (ACM and mass storage)" | ||
| 354 | depends on BLOCK | ||
| 355 | select USB_LIBCOMPOSITE | ||
| 356 | select USB_U_SERIAL | ||
| 357 | select USB_F_ACM | ||
| 358 | select USB_F_MASS_STORAGE | ||
| 359 | help | ||
| 360 | This driver provides two functions in one configuration: | ||
| 361 | a mass storage, and a CDC ACM (serial port) link. | ||
| 362 | |||
| 363 | Say "y" to link the driver statically, or "m" to build a | ||
| 364 | dynamically linked module called "g_acm_ms". | ||
| 365 | |||
| 366 | config USB_G_MULTI | ||
| 367 | tristate "Multifunction Composite Gadget" | ||
| 368 | depends on BLOCK && NET | ||
| 369 | select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS | ||
| 370 | select USB_LIBCOMPOSITE | ||
| 371 | select USB_U_SERIAL | ||
| 372 | select USB_U_ETHER | ||
| 373 | select USB_F_ACM | ||
| 374 | select USB_F_MASS_STORAGE | ||
| 375 | help | ||
| 376 | The Multifunction Composite Gadget provides Ethernet (RNDIS | ||
| 377 | and/or CDC Ethernet), mass storage and ACM serial link | ||
| 378 | interfaces. | ||
| 379 | |||
| 380 | You will be asked to choose which of the two configurations is | ||
| 381 | to be available in the gadget. At least one configuration must | ||
| 382 | be chosen to make the gadget usable. Selecting more than one | ||
| 383 | configuration will prevent Windows from automatically detecting | ||
| 384 | the gadget as a composite gadget, so an INF file will be needed to | ||
| 385 | use the gadget. | ||
| 386 | |||
| 387 | Say "y" to link the driver statically, or "m" to build a | ||
| 388 | dynamically linked module called "g_multi". | ||
| 389 | |||
| 390 | config USB_G_MULTI_RNDIS | ||
| 391 | bool "RNDIS + CDC Serial + Storage configuration" | ||
| 392 | depends on USB_G_MULTI | ||
| 393 | select USB_F_RNDIS | ||
| 394 | default y | ||
| 395 | help | ||
| 396 | This option enables a configuration with RNDIS, CDC Serial and | ||
| 397 | Mass Storage functions available in the Multifunction Composite | ||
| 398 | Gadget. This is the configuration dedicated for Windows since RNDIS | ||
| 399 | is Microsoft's protocol. | ||
| 400 | |||
| 401 | If unsure, say "y". | ||
| 402 | |||
| 403 | config USB_G_MULTI_CDC | ||
| 404 | bool "CDC Ethernet + CDC Serial + Storage configuration" | ||
| 405 | depends on USB_G_MULTI | ||
| 406 | default n | ||
| 407 | select USB_F_ECM | ||
| 408 | help | ||
| 409 | This option enables a configuration with CDC Ethernet (ECM), CDC | ||
| 410 | Serial and Mass Storage functions available in the Multifunction | ||
| 411 | Composite Gadget. | ||
| 412 | |||
| 413 | If unsure, say "y". | ||
| 414 | |||
| 415 | endif # TTY | ||
| 416 | |||
| 417 | config USB_G_HID | ||
| 418 | tristate "HID Gadget" | ||
| 419 | select USB_LIBCOMPOSITE | ||
| 420 | help | ||
| 421 | The HID gadget driver provides generic emulation of USB | ||
| 422 | Human Interface Devices (HID). | ||
| 423 | |||
| 424 | For more information, see Documentation/usb/gadget_hid.txt which | ||
| 425 | includes sample code for accessing the device files. | ||
| 426 | |||
| 427 | Say "y" to link the driver statically, or "m" to build a | ||
| 428 | dynamically linked module called "g_hid". | ||
| 429 | |||
| 430 | # Standalone / single function gadgets | ||
| 431 | config USB_G_DBGP | ||
| 432 | tristate "EHCI Debug Device Gadget" | ||
| 433 | depends on TTY | ||
| 434 | select USB_LIBCOMPOSITE | ||
| 435 | help | ||
| 436 | This gadget emulates an EHCI Debug device. This is useful when you want | ||
| 437 | to interact with an EHCI Debug Port. | ||
| 438 | |||
| 439 | Say "y" to link the driver statically, or "m" to build a | ||
| 440 | dynamically linked module called "g_dbgp". | ||
| 441 | |||
| 442 | if USB_G_DBGP | ||
| 443 | choice | ||
| 444 | prompt "EHCI Debug Device mode" | ||
| 445 | default USB_G_DBGP_SERIAL | ||
| 446 | |||
| 447 | config USB_G_DBGP_PRINTK | ||
| 448 | depends on USB_G_DBGP | ||
| 449 | bool "printk" | ||
| 450 | help | ||
| 451 | Directly printk() received data. No interaction. | ||
| 452 | |||
| 453 | config USB_G_DBGP_SERIAL | ||
| 454 | depends on USB_G_DBGP | ||
| 455 | select USB_U_SERIAL | ||
| 456 | bool "serial" | ||
| 457 | help | ||
| 458 | Userland can interact using /dev/ttyGSxxx. | ||
| 459 | endchoice | ||
| 460 | endif | ||
| 461 | |||
| 462 | # put drivers that need isochronous transfer support (for audio | ||
| 463 | # or video class gadget drivers), or specific hardware, here. | ||
| 464 | config USB_G_WEBCAM | ||
| 465 | tristate "USB Webcam Gadget" | ||
| 466 | depends on VIDEO_DEV | ||
| 467 | select USB_LIBCOMPOSITE | ||
| 468 | select VIDEOBUF2_VMALLOC | ||
| 469 | help | ||
| 470 | The Webcam Gadget acts as a composite USB Audio and Video Class | ||
| 471 | device. It provides a userspace API to process UVC control requests | ||
| 472 | and stream video data to the host. | ||
| 473 | |||
| 474 | Say "y" to link the driver statically, or "m" to build a | ||
| 475 | dynamically linked module called "g_webcam". | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | # | ||
| 2 | # USB gadget drivers | ||
| 3 | # | ||
| 4 | |||
| 5 | ccflags-y := -I$(PWD)/drivers/usb/gadget/ | ||
| 6 | ccflags-y += -I$(PWD)/drivers/usb/gadget/udc/ | ||
| 7 | ccflags-y += -I$(PWD)/drivers/usb/gadget/function/ | ||
| 8 | |||
| 9 | g_zero-y := zero.o | ||
| 10 | g_audio-y := audio.o | ||
| 11 | g_ether-y := ether.o | ||
| 12 | g_serial-y := serial.o | ||
| 13 | g_midi-y := gmidi.o | ||
| 14 | gadgetfs-y := inode.o | ||
| 15 | g_mass_storage-y := mass_storage.o | ||
| 16 | g_printer-y := printer.o | ||
| 17 | g_cdc-y := cdc2.o | ||
| 18 | g_multi-y := multi.o | ||
| 19 | g_hid-y := hid.o | ||
| 20 | g_dbgp-y := dbgp.o | ||
| 21 | g_nokia-y := nokia.o | ||
| 22 | g_webcam-y := webcam.o | ||
| 23 | g_ncm-y := ncm.o | ||
| 24 | g_acm_ms-y := acm_ms.o | ||
| 25 | g_tcm_usb_gadget-y := tcm_usb_gadget.o | ||
| 26 | |||
| 27 | obj-$(CONFIG_USB_ZERO) += g_zero.o | ||
| 28 | obj-$(CONFIG_USB_AUDIO) += g_audio.o | ||
| 29 | obj-$(CONFIG_USB_ETH) += g_ether.o | ||
| 30 | obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o | ||
| 31 | obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o | ||
| 32 | obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o | ||
| 33 | obj-$(CONFIG_USB_G_SERIAL) += g_serial.o | ||
| 34 | obj-$(CONFIG_USB_G_PRINTER) += g_printer.o | ||
| 35 | obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o | ||
| 36 | obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o | ||
| 37 | obj-$(CONFIG_USB_G_HID) += g_hid.o | ||
| 38 | obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o | ||
| 39 | obj-$(CONFIG_USB_G_MULTI) += g_multi.o | ||
| 40 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o | ||
| 41 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o | ||
| 42 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o | ||
| 43 | obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o | ||
| 44 | obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o | ||
| @@ -267,18 +267,8 @@ static __refdata struct usb_composite_driver acm_ms_driver = { · 266 unmodified lines | |||
| 267 | .unbind = __exit_p(acm_ms_unbind), | 267 | .unbind = __exit_p(acm_ms_unbind), |
| 268 | }; | 268 | }; |
| 269 | 269 | ||
| 270 | module_usb_composite_driver(acm_ms_driver); | ||
| 271 | |||
| 270 | MODULE_DESCRIPTION(DRIVER_DESC); | 272 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 271 | MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>"); | 273 | MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>"); |
| 272 | MODULE_LICENSE("GPL v2"); | 274 | MODULE_LICENSE("GPL v2"); |
| 273 | |||
| 274 | static int __init init(void) | ||
| 275 | { | ||
| 276 | return usb_composite_probe(&acm_ms_driver); | ||
| 277 | } | ||
| 278 | module_init(init); | ||
| 279 | |||
| 280 | static void __exit cleanup(void) | ||
| 281 | { | ||
| 282 | usb_composite_unregister(&acm_ms_driver); | ||
| 283 | } | ||
| 284 | module_exit(cleanup); | ||
| @@ -172,17 +172,7 @@ static __refdata struct usb_composite_driver audio_driver = { · 171 unmodified lines | |||
| 172 | .unbind = __exit_p(audio_unbind), | 172 | .unbind = __exit_p(audio_unbind), |
| 173 | }; | 173 | }; |
| 174 | 174 | ||
| 175 | static int __init init(void) | 175 | module_usb_composite_driver(audio_driver); |
| 176 | { | ||
| 177 | return usb_composite_probe(&audio_driver); | ||
| 178 | } | ||
| 179 | module_init(init); | ||
| 180 | |||
| 181 | static void __exit cleanup(void) | ||
| 182 | { | ||
| 183 | usb_composite_unregister(&audio_driver); | ||
| 184 | } | ||
| 185 | module_exit(cleanup); | ||
| 186 | 176 | ||
| 187 | MODULE_DESCRIPTION(DRIVER_DESC); | 177 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 188 | MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>"); | 178 | MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>"); |
| @@ -231,18 +231,8 @@ static __refdata struct usb_composite_driver cdc_driver = { · 230 unmodified lines | |||
| 231 | .unbind = __exit_p(cdc_unbind), | 231 | .unbind = __exit_p(cdc_unbind), |
| 232 | }; | 232 | }; |
| 233 | 233 | ||
| 234 | module_usb_composite_driver(cdc_driver); | ||
| 235 | |||
| 234 | MODULE_DESCRIPTION(DRIVER_DESC); | 236 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 235 | MODULE_AUTHOR("David Brownell"); | 237 | MODULE_AUTHOR("David Brownell"); |
| 236 | MODULE_LICENSE("GPL"); | 238 | MODULE_LICENSE("GPL"); |
| 237 | |||
| 238 | static int __init init(void) | ||
| 239 | { | ||
| 240 | return usb_composite_probe(&cdc_driver); | ||
| 241 | } | ||
| 242 | module_init(init); | ||
| 243 | |||
| 244 | static void __exit cleanup(void) | ||
| 245 | { | ||
| 246 | usb_composite_unregister(&cdc_driver); | ||
| 247 | } | ||
| 248 | module_exit(cleanup); | ||
File renamed without changes.
| @@ -475,18 +475,8 @@ static __refdata struct usb_composite_driver eth_driver = { · 474 unmodified lines | |||
| 475 | .unbind = __exit_p(eth_unbind), | 475 | .unbind = __exit_p(eth_unbind), |
| 476 | }; | 476 | }; |
| 477 | 477 | ||
| 478 | module_usb_composite_driver(eth_driver); | ||
| 479 | |||
| 478 | MODULE_DESCRIPTION(PREFIX DRIVER_DESC); | 480 | MODULE_DESCRIPTION(PREFIX DRIVER_DESC); |
| 479 | MODULE_AUTHOR("David Brownell, Benedikt Spanger"); | 481 | MODULE_AUTHOR("David Brownell, Benedikt Spanger"); |
| 480 | MODULE_LICENSE("GPL"); | 482 | MODULE_LICENSE("GPL"); |
| 481 | |||
| 482 | static int __init init(void) | ||
| 483 | { | ||
| 484 | return usb_composite_probe(ð_driver); | ||
| 485 | } | ||
| 486 | module_init(init); | ||
| 487 | |||
| 488 | static void __exit cleanup(void) | ||
| 489 | { | ||
| 490 | usb_composite_unregister(ð_driver); | ||
| 491 | } | ||
| 492 | module_exit(cleanup); | ||
| @@ -276,7 +276,7 @@ module_exit(gfs_exit); · 275 unmodified lines | |||
| 276 | static void *functionfs_acquire_dev(struct ffs_dev *dev) | 276 | static void *functionfs_acquire_dev(struct ffs_dev *dev) |
| 277 | { | 277 | { |
| 278 | if (!try_module_get(THIS_MODULE)) | 278 | if (!try_module_get(THIS_MODULE)) |
| 279 | return ERR_PTR(-ENODEV); | 279 | return ERR_PTR(-ENOENT); |
| 280 | 280 | ||
| 281 | return 0; | 281 | return 0; |
| 282 | } | 282 | } |
| @@ -163,15 +163,4 @@ static __refdata struct usb_composite_driver midi_driver = { · 162 unmodified lines | |||
| 163 | .unbind = __exit_p(midi_unbind), | 163 | .unbind = __exit_p(midi_unbind), |
| 164 | }; | 164 | }; |
| 165 | 165 | ||
| 166 | static int __init midi_init(void) | 166 | module_usb_composite_driver(midi_driver); |
| 167 | { | ||
| 168 | return usb_composite_probe(&midi_driver); | ||
| 169 | } | ||
| 170 | module_init(midi_init); | ||
| 171 | |||
| 172 | static void __exit midi_cleanup(void) | ||
| 173 | { | ||
| 174 | usb_composite_unregister(&midi_driver); | ||
| 175 | } | ||
| 176 | module_exit(midi_cleanup); | ||
| 177 | |||
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -507,15 +507,4 @@ static __refdata struct usb_composite_driver multi_driver = { · 506 unmodified lines | |||
| 507 | .needs_serial = 1, | 507 | .needs_serial = 1, |
| 508 | }; | 508 | }; |
| 509 | 509 | ||
| 510 | 510 | module_usb_composite_driver(multi_driver); | |
| 511 | static int __init multi_init(void) | ||
| 512 | { | ||
| 513 | return usb_composite_probe(&multi_driver); | ||
| 514 | } | ||
| 515 | module_init(multi_init); | ||
| 516 | |||
| 517 | static void __exit multi_exit(void) | ||
| 518 | { | ||
| 519 | usb_composite_unregister(&multi_driver); | ||
| 520 | } | ||
| 521 | module_exit(multi_exit); | ||
| @@ -204,18 +204,8 @@ static __refdata struct usb_composite_driver ncm_driver = { · 203 unmodified lines | |||
| 204 | .unbind = __exit_p(gncm_unbind), | 204 | .unbind = __exit_p(gncm_unbind), |
| 205 | }; | 205 | }; |
| 206 | 206 | ||
| 207 | module_usb_composite_driver(ncm_driver); | ||
| 208 | |||
| 207 | MODULE_DESCRIPTION(DRIVER_DESC); | 209 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 208 | MODULE_AUTHOR("Yauheni Kaliuta"); | 210 | MODULE_AUTHOR("Yauheni Kaliuta"); |
| 209 | MODULE_LICENSE("GPL"); | 211 | MODULE_LICENSE("GPL"); |
| 210 | |||
| 211 | static int __init init(void) | ||
| 212 | { | ||
| 213 | return usb_composite_probe(&ncm_driver); | ||
| 214 | } | ||
| 215 | module_init(init); | ||
| 216 | |||
| 217 | static void __exit cleanup(void) | ||
| 218 | { | ||
| 219 | usb_composite_unregister(&ncm_driver); | ||
| 220 | } | ||
| 221 | module_exit(cleanup); | ||
| @@ -347,14 +347,4 @@ static __refdata struct usb_composite_driver nokia_driver = { · 346 unmodified lines | |||
| 347 | .unbind = __exit_p(nokia_unbind), | 347 | .unbind = __exit_p(nokia_unbind), |
| 348 | }; | 348 | }; |
| 349 | 349 | ||
| 350 | static int __init nokia_init(void) | 350 | module_usb_composite_driver(nokia_driver); |
| 351 | { | ||
| 352 | return usb_composite_probe(&nokia_driver); | ||
| 353 | } | ||
| 354 | module_init(nokia_init); | ||
| 355 | |||
| 356 | static void __exit nokia_cleanup(void) | ||
| 357 | { | ||
| 358 | usb_composite_unregister(&nokia_driver); | ||
| 359 | } | ||
| 360 | module_exit(nokia_cleanup); | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -390,20 +390,7 @@ static __refdata struct usb_composite_driver webcam_driver = { · 389 unmodified lines | |||
| 390 | .unbind = webcam_unbind, | 390 | .unbind = webcam_unbind, |
| 391 | }; | 391 | }; |
| 392 | 392 | ||
| 393 | static int __init | 393 | module_usb_composite_driver(webcam_driver); |
| 394 | webcam_init(void) | ||
| 395 | { | ||
| 396 | return usb_composite_probe(&webcam_driver); | ||
| 397 | } | ||
| 398 | |||
| 399 | static void __exit | ||
| 400 | webcam_cleanup(void) | ||
| 401 | { | ||
| 402 | usb_composite_unregister(&webcam_driver); | ||
| 403 | } | ||
| 404 | |||
| 405 | module_init(webcam_init); | ||
| 406 | module_exit(webcam_cleanup); | ||
| 407 | 394 | ||
| 408 | MODULE_AUTHOR("Laurent Pinchart"); | 395 | MODULE_AUTHOR("Laurent Pinchart"); |
| 409 | MODULE_DESCRIPTION("Webcam Video Gadget"); | 396 | MODULE_DESCRIPTION("Webcam Video Gadget"); |
| @@ -411,17 +411,7 @@ static __refdata struct usb_composite_driver zero_driver = { · 410 unmodified lines | |||
| 411 | .resume = zero_resume, | 411 | .resume = zero_resume, |
| 412 | }; | 412 | }; |
| 413 | 413 | ||
| 414 | module_usb_composite_driver(zero_driver); | ||
| 415 | |||
| 414 | MODULE_AUTHOR("David Brownell"); | 416 | MODULE_AUTHOR("David Brownell"); |
| 415 | MODULE_LICENSE("GPL"); | 417 | MODULE_LICENSE("GPL"); |
| 416 | |||
| 417 | static int __init init(void) | ||
| 418 | { | ||
| 419 | return usb_composite_probe(&zero_driver); | ||
| 420 | } | ||
| 421 | module_init(init); | ||
| 422 | |||
| 423 | static void __exit cleanup(void) | ||
| 424 | { | ||
| 425 | usb_composite_unregister(&zero_driver); | ||
| 426 | } | ||
| 427 | module_exit(cleanup); | ||
| @@ -1,2905 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Driver for the PLX NET2280 USB device controller. | ||
| 3 | * Specs and errata are available from <http://www.plxtech.com>. | ||
| 4 | * | ||
| 5 | * PLX Technology Inc. (formerly NetChip Technology) supported the | ||
| 6 | * development of this driver. | ||
| 7 | * | ||
| 8 | * | ||
| 9 | * CODE STATUS HIGHLIGHTS | ||
| 10 | * | ||
| 11 | * This driver should work well with most "gadget" drivers, including | ||
| 12 | * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers | ||
| 13 | * as well as Gadget Zero and Gadgetfs. | ||
| 14 | * | ||
| 15 | * DMA is enabled by default. Drivers using transfer queues might use | ||
| 16 | * DMA chaining to remove IRQ latencies between transfers. (Except when | ||
| 17 | * short OUT transfers happen.) Drivers can use the req->no_interrupt | ||
| 18 | * hint to completely eliminate some IRQs, if a later IRQ is guaranteed | ||
| 19 | * and DMA chaining is enabled. | ||
| 20 | * | ||
| 21 | * Note that almost all the errata workarounds here are only needed for | ||
| 22 | * rev1 chips. Rev1a silicon (0110) fixes almost all of them. | ||
| 23 | */ | ||
| 24 | |||
| 25 | /* | ||
| 26 | * Copyright (C) 2003 David Brownell | ||
| 27 | * Copyright (C) 2003-2005 PLX Technology, Inc. | ||
| 28 | * | ||
| 29 | * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility | ||
| 30 | * with 2282 chip | ||
| 31 | * | ||
| 32 | * This program is free software; you can redistribute it and/or modify | ||
| 33 | * it under the terms of the GNU General Public License as published by | ||
| 34 | * the Free Software Foundation; either version 2 of the License, or | ||
| 35 | * (at your option) any later version. | ||
| 36 | */ | ||
| 37 | |||
| 38 | #undef DEBUG /* messages on error and most fault paths */ | ||
| 39 | #undef VERBOSE /* extra debug messages (success too) */ | ||
| 40 | |||
| 41 | #include <linux/module.h> | ||
| 42 | #include <linux/pci.h> | ||
| 43 | #include <linux/dma-mapping.h> | ||
| 44 | #include <linux/kernel.h> | ||
| 45 | #include <linux/delay.h> | ||
| 46 | #include <linux/ioport.h> | ||
| 47 | #include <linux/slab.h> | ||
| 48 | #include <linux/errno.h> | ||
| 49 | #include <linux/init.h> | ||
| 50 | #include <linux/timer.h> | ||
| 51 | #include <linux/list.h> | ||
| 52 | #include <linux/interrupt.h> | ||
| 53 | #include <linux/moduleparam.h> | ||
| 54 | #include <linux/device.h> | ||
| 55 | #include <linux/usb/ch9.h> | ||
| 56 | #include <linux/usb/gadget.h> | ||
| 57 | #include <linux/prefetch.h> | ||
| 58 | |||
| 59 | #include <asm/byteorder.h> | ||
| 60 | #include <asm/io.h> | ||
| 61 | #include <asm/irq.h> | ||
| 62 | #include <asm/unaligned.h> | ||
| 63 | |||
| 64 | |||
| 65 | #define DRIVER_DESC "PLX NET228x USB Peripheral Controller" | ||
| 66 | #define DRIVER_VERSION "2005 Sept 27" | ||
| 67 | |||
| 68 | #define EP_DONTUSE 13 /* nonzero */ | ||
| 69 | |||
| 70 | #define USE_RDK_LEDS /* GPIO pins control three LEDs */ | ||
| 71 | |||
| 72 | |||
| 73 | static const char driver_name [] = "net2280"; | ||
| 74 | static const char driver_desc [] = DRIVER_DESC; | ||
| 75 | |||
| 76 | static const char ep0name [] = "ep0"; | ||
| 77 | static const char *const ep_name [] = { | ||
| 78 | ep0name, | ||
| 79 | "ep-a", "ep-b", "ep-c", "ep-d", | ||
| 80 | "ep-e", "ep-f", | ||
| 81 | }; | ||
| 82 | |||
| 83 | /* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO) | ||
| 84 | * use_dma_chaining -- dma descriptor queueing gives even more irq reduction | ||
| 85 | * | ||
| 86 | * The net2280 DMA engines are not tightly integrated with their FIFOs; | ||
| 87 | * not all cases are (yet) handled well in this driver or the silicon. | ||
| 88 | * Some gadget drivers work better with the dma support here than others. | ||
| 89 | * These two parameters let you use PIO or more aggressive DMA. | ||
| 90 | */ | ||
| 91 | static bool use_dma = 1; | ||
| 92 | static bool use_dma_chaining = 0; | ||
| 93 | |||
| 94 | /* "modprobe net2280 use_dma=n" etc */ | ||
| 95 | module_param (use_dma, bool, S_IRUGO); | ||
| 96 | module_param (use_dma_chaining, bool, S_IRUGO); | ||
| 97 | |||
| 98 | |||
| 99 | /* mode 0 == ep-{a,b,c,d} 1K fifo each | ||
| 100 | * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable | ||
| 101 | * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable | ||
| 102 | */ | ||
| 103 | static ushort fifo_mode = 0; | ||
| 104 | |||
| 105 | /* "modprobe net2280 fifo_mode=1" etc */ | ||
| 106 | module_param (fifo_mode, ushort, 0644); | ||
| 107 | |||
| 108 | /* enable_suspend -- When enabled, the driver will respond to | ||
| 109 | * USB suspend requests by powering down the NET2280. Otherwise, | ||
| 110 | * USB suspend requests will be ignored. This is acceptable for | ||
| 111 | * self-powered devices | ||
| 112 | */ | ||
| 113 | static bool enable_suspend = 0; | ||
| 114 | |||
| 115 | /* "modprobe net2280 enable_suspend=1" etc */ | ||
| 116 | module_param (enable_suspend, bool, S_IRUGO); | ||
| 117 | |||
| 118 | /* force full-speed operation */ | ||
| 119 | static bool full_speed; | ||
| 120 | module_param(full_speed, bool, 0444); | ||
| 121 | MODULE_PARM_DESC(full_speed, "force full-speed mode -- for testing only!"); | ||
| 122 | |||
| 123 | #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") | ||
| 124 | |||
| 125 | #if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG) | ||
| 126 | static char *type_string (u8 bmAttributes) | ||
| 127 | { | ||
| 128 | switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { | ||
| 129 | case USB_ENDPOINT_XFER_BULK: return "bulk"; | ||
| 130 | case USB_ENDPOINT_XFER_ISOC: return "iso"; | ||
| 131 | case USB_ENDPOINT_XFER_INT: return "intr"; | ||
| 132 | } | ||
| 133 | return "control"; | ||
| 134 | } | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #include "net2280.h" | ||
| 138 | |||
| 139 | #define valid_bit cpu_to_le32 (1 << VALID_BIT) | ||
| 140 | #define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE) | ||
| 141 | |||
| 142 | /*-------------------------------------------------------------------------*/ | ||
| 143 | |||
| 144 | static int | ||
| 145 | net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | ||
| 146 | { | ||
| 147 | struct net2280 *dev; | ||
| 148 | struct net2280_ep *ep; | ||
| 149 | u32 max, tmp; | ||
| 150 | unsigned long flags; | ||
| 151 | |||
| 152 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 153 | if (!_ep || !desc || ep->desc || _ep->name == ep0name | ||
| 154 | || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
| 155 | return -EINVAL; | ||
| 156 | dev = ep->dev; | ||
| 157 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 158 | return -ESHUTDOWN; | ||
| 159 | |||
| 160 | /* erratum 0119 workaround ties up an endpoint number */ | ||
| 161 | if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) | ||
| 162 | return -EDOM; | ||
| 163 | |||
| 164 | /* sanity check ep-e/ep-f since their fifos are small */ | ||
| 165 | max = usb_endpoint_maxp (desc) & 0x1fff; | ||
| 166 | if (ep->num > 4 && max > 64) | ||
| 167 | return -ERANGE; | ||
| 168 | |||
| 169 | spin_lock_irqsave (&dev->lock, flags); | ||
| 170 | _ep->maxpacket = max & 0x7ff; | ||
| 171 | ep->desc = desc; | ||
| 172 | |||
| 173 | /* ep_reset() has already been called */ | ||
| 174 | ep->stopped = 0; | ||
| 175 | ep->wedged = 0; | ||
| 176 | ep->out_overflow = 0; | ||
| 177 | |||
| 178 | /* set speed-dependent max packet; may kick in high bandwidth */ | ||
| 179 | set_idx_reg (dev->regs, REG_EP_MAXPKT (dev, ep->num), max); | ||
| 180 | |||
| 181 | /* FIFO lines can't go to different packets. PIO is ok, so | ||
| 182 | * use it instead of troublesome (non-bulk) multi-packet DMA. | ||
| 183 | */ | ||
| 184 | if (ep->dma && (max % 4) != 0 && use_dma_chaining) { | ||
| 185 | DEBUG (ep->dev, "%s, no dma for maxpacket %d\n", | ||
| 186 | ep->ep.name, ep->ep.maxpacket); | ||
| 187 | ep->dma = NULL; | ||
| 188 | } | ||
| 189 | |||
| 190 | /* set type, direction, address; reset fifo counters */ | ||
| 191 | writel ((1 << FIFO_FLUSH), &ep->regs->ep_stat); | ||
| 192 | tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | ||
| 193 | if (tmp == USB_ENDPOINT_XFER_INT) { | ||
| 194 | /* erratum 0105 workaround prevents hs NYET */ | ||
| 195 | if (dev->chiprev == 0100 | ||
| 196 | && dev->gadget.speed == USB_SPEED_HIGH | ||
| 197 | && !(desc->bEndpointAddress & USB_DIR_IN)) | ||
| 198 | writel ((1 << CLEAR_NAK_OUT_PACKETS_MODE), | ||
| 199 | &ep->regs->ep_rsp); | ||
| 200 | } else if (tmp == USB_ENDPOINT_XFER_BULK) { | ||
| 201 | /* catch some particularly blatant driver bugs */ | ||
| 202 | if ((dev->gadget.speed == USB_SPEED_HIGH | ||
| 203 | && max != 512) | ||
| 204 | || (dev->gadget.speed == USB_SPEED_FULL | ||
| 205 | && max > 64)) { | ||
| 206 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 207 | return -ERANGE; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0; | ||
| 211 | tmp <<= ENDPOINT_TYPE; | ||
| 212 | tmp |= desc->bEndpointAddress; | ||
| 213 | tmp |= (4 << ENDPOINT_BYTE_COUNT); /* default full fifo lines */ | ||
| 214 | tmp |= 1 << ENDPOINT_ENABLE; | ||
| 215 | wmb (); | ||
| 216 | |||
| 217 | /* for OUT transfers, block the rx fifo until a read is posted */ | ||
| 218 | ep->is_in = (tmp & USB_DIR_IN) != 0; | ||
| 219 | if (!ep->is_in) | ||
| 220 | writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 221 | else if (dev->pdev->device != 0x2280) { | ||
| 222 | /* Added for 2282, Don't use nak packets on an in endpoint, | ||
| 223 | * this was ignored on 2280 | ||
| 224 | */ | ||
| 225 | writel ((1 << CLEAR_NAK_OUT_PACKETS) | ||
| 226 | | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); | ||
| 227 | } | ||
| 228 | |||
| 229 | writel (tmp, &ep->regs->ep_cfg); | ||
| 230 | |||
| 231 | /* enable irqs */ | ||
| 232 | if (!ep->dma) { /* pio, per-packet */ | ||
| 233 | tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0); | ||
| 234 | writel (tmp, &dev->regs->pciirqenb0); | ||
| 235 | |||
| 236 | tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) | ||
| 237 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE); | ||
| 238 | if (dev->pdev->device == 0x2280) | ||
| 239 | tmp |= readl (&ep->regs->ep_irqenb); | ||
| 240 | writel (tmp, &ep->regs->ep_irqenb); | ||
| 241 | } else { /* dma, per-request */ | ||
| 242 | tmp = (1 << (8 + ep->num)); /* completion */ | ||
| 243 | tmp |= readl (&dev->regs->pciirqenb1); | ||
| 244 | writel (tmp, &dev->regs->pciirqenb1); | ||
| 245 | |||
| 246 | /* for short OUT transfers, dma completions can't | ||
| 247 | * advance the queue; do it pio-style, by hand. | ||
| 248 | * NOTE erratum 0112 workaround #2 | ||
| 249 | */ | ||
| 250 | if ((desc->bEndpointAddress & USB_DIR_IN) == 0) { | ||
| 251 | tmp = (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE); | ||
| 252 | writel (tmp, &ep->regs->ep_irqenb); | ||
| 253 | |||
| 254 | tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0); | ||
| 255 | writel (tmp, &dev->regs->pciirqenb0); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | tmp = desc->bEndpointAddress; | ||
| 260 | DEBUG (dev, "enabled %s (ep%d%s-%s) %s max %04x\n", | ||
| 261 | _ep->name, tmp & 0x0f, DIR_STRING (tmp), | ||
| 262 | type_string (desc->bmAttributes), | ||
| 263 | ep->dma ? "dma" : "pio", max); | ||
| 264 | |||
| 265 | /* pci writes may still be posted */ | ||
| 266 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 267 | return 0; | ||
| 268 | } | ||
| 269 | |||
| 270 | static int handshake (u32 __iomem *ptr, u32 mask, u32 done, int usec) | ||
| 271 | { | ||
| 272 | u32 result; | ||
| 273 | |||
| 274 | do { | ||
| 275 | result = readl (ptr); | ||
| 276 | if (result == ~(u32)0) /* "device unplugged" */ | ||
| 277 | return -ENODEV; | ||
| 278 | result &= mask; | ||
| 279 | if (result == done) | ||
| 280 | return 0; | ||
| 281 | udelay (1); | ||
| 282 | usec--; | ||
| 283 | } while (usec > 0); | ||
| 284 | return -ETIMEDOUT; | ||
| 285 | } | ||
| 286 | |||
| 287 | static const struct usb_ep_ops net2280_ep_ops; | ||
| 288 | |||
| 289 | static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) | ||
| 290 | { | ||
| 291 | u32 tmp; | ||
| 292 | |||
| 293 | ep->desc = NULL; | ||
| 294 | INIT_LIST_HEAD (&ep->queue); | ||
| 295 | |||
| 296 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); | ||
| 297 | ep->ep.ops = &net2280_ep_ops; | ||
| 298 | |||
| 299 | /* disable the dma, irqs, endpoint... */ | ||
| 300 | if (ep->dma) { | ||
| 301 | writel (0, &ep->dma->dmactl); | ||
| 302 | writel ( (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT) | ||
| 303 | | (1 << DMA_TRANSACTION_DONE_INTERRUPT) | ||
| 304 | | (1 << DMA_ABORT) | ||
| 305 | , &ep->dma->dmastat); | ||
| 306 | |||
| 307 | tmp = readl (®s->pciirqenb0); | ||
| 308 | tmp &= ~(1 << ep->num); | ||
| 309 | writel (tmp, ®s->pciirqenb0); | ||
| 310 | } else { | ||
| 311 | tmp = readl (®s->pciirqenb1); | ||
| 312 | tmp &= ~(1 << (8 + ep->num)); /* completion */ | ||
| 313 | writel (tmp, ®s->pciirqenb1); | ||
| 314 | } | ||
| 315 | writel (0, &ep->regs->ep_irqenb); | ||
| 316 | |||
| 317 | /* init to our chosen defaults, notably so that we NAK OUT | ||
| 318 | * packets until the driver queues a read (+note erratum 0112) | ||
| 319 | */ | ||
| 320 | if (!ep->is_in || ep->dev->pdev->device == 0x2280) { | ||
| 321 | tmp = (1 << SET_NAK_OUT_PACKETS_MODE) | ||
| 322 | | (1 << SET_NAK_OUT_PACKETS) | ||
| 323 | | (1 << CLEAR_EP_HIDE_STATUS_PHASE) | ||
| 324 | | (1 << CLEAR_INTERRUPT_MODE); | ||
| 325 | } else { | ||
| 326 | /* added for 2282 */ | ||
| 327 | tmp = (1 << CLEAR_NAK_OUT_PACKETS_MODE) | ||
| 328 | | (1 << CLEAR_NAK_OUT_PACKETS) | ||
| 329 | | (1 << CLEAR_EP_HIDE_STATUS_PHASE) | ||
| 330 | | (1 << CLEAR_INTERRUPT_MODE); | ||
| 331 | } | ||
| 332 | |||
| 333 | if (ep->num != 0) { | ||
| 334 | tmp |= (1 << CLEAR_ENDPOINT_TOGGLE) | ||
| 335 | | (1 << CLEAR_ENDPOINT_HALT); | ||
| 336 | } | ||
| 337 | writel (tmp, &ep->regs->ep_rsp); | ||
| 338 | |||
| 339 | /* scrub most status bits, and flush any fifo state */ | ||
| 340 | if (ep->dev->pdev->device == 0x2280) | ||
| 341 | tmp = (1 << FIFO_OVERFLOW) | ||
| 342 | | (1 << FIFO_UNDERFLOW); | ||
| 343 | else | ||
| 344 | tmp = 0; | ||
| 345 | |||
| 346 | writel (tmp | (1 << TIMEOUT) | ||
| 347 | | (1 << USB_STALL_SENT) | ||
| 348 | | (1 << USB_IN_NAK_SENT) | ||
| 349 | | (1 << USB_IN_ACK_RCVD) | ||
| 350 | | (1 << USB_OUT_PING_NAK_SENT) | ||
| 351 | | (1 << USB_OUT_ACK_SENT) | ||
| 352 | | (1 << FIFO_FLUSH) | ||
| 353 | | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT) | ||
| 354 | | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) | ||
| 355 | | (1 << DATA_PACKET_RECEIVED_INTERRUPT) | ||
| 356 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) | ||
| 357 | | (1 << DATA_OUT_PING_TOKEN_INTERRUPT) | ||
| 358 | | (1 << DATA_IN_TOKEN_INTERRUPT) | ||
| 359 | , &ep->regs->ep_stat); | ||
| 360 | |||
| 361 | /* fifo size is handled separately */ | ||
| 362 | } | ||
| 363 | |||
| 364 | static void nuke (struct net2280_ep *); | ||
| 365 | |||
| 366 | static int net2280_disable (struct usb_ep *_ep) | ||
| 367 | { | ||
| 368 | struct net2280_ep *ep; | ||
| 369 | unsigned long flags; | ||
| 370 | |||
| 371 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 372 | if (!_ep || !ep->desc || _ep->name == ep0name) | ||
| 373 | return -EINVAL; | ||
| 374 | |||
| 375 | spin_lock_irqsave (&ep->dev->lock, flags); | ||
| 376 | nuke (ep); | ||
| 377 | ep_reset (ep->dev->regs, ep); | ||
| 378 | |||
| 379 | VDEBUG (ep->dev, "disabled %s %s\n", | ||
| 380 | ep->dma ? "dma" : "pio", _ep->name); | ||
| 381 | |||
| 382 | /* synch memory views with the device */ | ||
| 383 | (void) readl (&ep->regs->ep_cfg); | ||
| 384 | |||
| 385 | if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4) | ||
| 386 | ep->dma = &ep->dev->dma [ep->num - 1]; | ||
| 387 | |||
| 388 | spin_unlock_irqrestore (&ep->dev->lock, flags); | ||
| 389 | return 0; | ||
| 390 | } | ||
| 391 | |||
| 392 | /*-------------------------------------------------------------------------*/ | ||
| 393 | |||
| 394 | static struct usb_request * | ||
| 395 | net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags) | ||
| 396 | { | ||
| 397 | struct net2280_ep *ep; | ||
| 398 | struct net2280_request *req; | ||
| 399 | |||
| 400 | if (!_ep) | ||
| 401 | return NULL; | ||
| 402 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 403 | |||
| 404 | req = kzalloc(sizeof(*req), gfp_flags); | ||
| 405 | if (!req) | ||
| 406 | return NULL; | ||
| 407 | |||
| 408 | INIT_LIST_HEAD (&req->queue); | ||
| 409 | |||
| 410 | /* this dma descriptor may be swapped with the previous dummy */ | ||
| 411 | if (ep->dma) { | ||
| 412 | struct net2280_dma *td; | ||
| 413 | |||
| 414 | td = pci_pool_alloc (ep->dev->requests, gfp_flags, | ||
| 415 | &req->td_dma); | ||
| 416 | if (!td) { | ||
| 417 | kfree (req); | ||
| 418 | return NULL; | ||
| 419 | } | ||
| 420 | td->dmacount = 0; /* not VALID */ | ||
| 421 | td->dmadesc = td->dmaaddr; | ||
| 422 | req->td = td; | ||
| 423 | } | ||
| 424 | return &req->req; | ||
| 425 | } | ||
| 426 | |||
| 427 | static void | ||
| 428 | net2280_free_request (struct usb_ep *_ep, struct usb_request *_req) | ||
| 429 | { | ||
| 430 | struct net2280_ep *ep; | ||
| 431 | struct net2280_request *req; | ||
| 432 | |||
| 433 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 434 | if (!_ep || !_req) | ||
| 435 | return; | ||
| 436 | |||
| 437 | req = container_of (_req, struct net2280_request, req); | ||
| 438 | WARN_ON (!list_empty (&req->queue)); | ||
| 439 | if (req->td) | ||
| 440 | pci_pool_free (ep->dev->requests, req->td, req->td_dma); | ||
| 441 | kfree (req); | ||
| 442 | } | ||
| 443 | |||
| 444 | /*-------------------------------------------------------------------------*/ | ||
| 445 | |||
| 446 | /* load a packet into the fifo we use for usb IN transfers. | ||
| 447 | * works for all endpoints. | ||
| 448 | * | ||
| 449 | * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo | ||
| 450 | * at a time, but this code is simpler because it knows it only writes | ||
| 451 | * one packet. ep-a..ep-d should use dma instead. | ||
| 452 | */ | ||
| 453 | static void | ||
| 454 | write_fifo (struct net2280_ep *ep, struct usb_request *req) | ||
| 455 | { | ||
| 456 | struct net2280_ep_regs __iomem *regs = ep->regs; | ||
| 457 | u8 *buf; | ||
| 458 | u32 tmp; | ||
| 459 | unsigned count, total; | ||
| 460 | |||
| 461 | /* INVARIANT: fifo is currently empty. (testable) */ | ||
| 462 | |||
| 463 | if (req) { | ||
| 464 | buf = req->buf + req->actual; | ||
| 465 | prefetch (buf); | ||
| 466 | total = req->length - req->actual; | ||
| 467 | } else { | ||
| 468 | total = 0; | ||
| 469 | buf = NULL; | ||
| 470 | } | ||
| 471 | |||
| 472 | /* write just one packet at a time */ | ||
| 473 | count = ep->ep.maxpacket; | ||
| 474 | if (count > total) /* min() cannot be used on a bitfield */ | ||
| 475 | count = total; | ||
| 476 | |||
| 477 | VDEBUG (ep->dev, "write %s fifo (IN) %d bytes%s req %p\n", | ||
| 478 | ep->ep.name, count, | ||
| 479 | (count != ep->ep.maxpacket) ? " (short)" : "", | ||
| 480 | req); | ||
| 481 | while (count >= 4) { | ||
| 482 | /* NOTE be careful if you try to align these. fifo lines | ||
| 483 | * should normally be full (4 bytes) and successive partial | ||
| 484 | * lines are ok only in certain cases. | ||
| 485 | */ | ||
| 486 | tmp = get_unaligned ((u32 *)buf); | ||
| 487 | cpu_to_le32s (&tmp); | ||
| 488 | writel (tmp, ®s->ep_data); | ||
| 489 | buf += 4; | ||
| 490 | count -= 4; | ||
| 491 | } | ||
| 492 | |||
| 493 | /* last fifo entry is "short" unless we wrote a full packet. | ||
| 494 | * also explicitly validate last word in (periodic) transfers | ||
| 495 | * when maxpacket is not a multiple of 4 bytes. | ||
| 496 | */ | ||
| 497 | if (count || total < ep->ep.maxpacket) { | ||
| 498 | tmp = count ? get_unaligned ((u32 *)buf) : count; | ||
| 499 | cpu_to_le32s (&tmp); | ||
| 500 | set_fifo_bytecount (ep, count & 0x03); | ||
| 501 | writel (tmp, ®s->ep_data); | ||
| 502 | } | ||
| 503 | |||
| 504 | /* pci writes may still be posted */ | ||
| 505 | } | ||
| 506 | |||
| 507 | /* work around erratum 0106: PCI and USB race over the OUT fifo. | ||
| 508 | * caller guarantees chiprev 0100, out endpoint is NAKing, and | ||
| 509 | * there's no real data in the fifo. | ||
| 510 | * | ||
| 511 | * NOTE: also used in cases where that erratum doesn't apply: | ||
| 512 | * where the host wrote "too much" data to us. | ||
| 513 | */ | ||
| 514 | static void out_flush (struct net2280_ep *ep) | ||
| 515 | { | ||
| 516 | u32 __iomem *statp; | ||
| 517 | u32 tmp; | ||
| 518 | |||
| 519 | ASSERT_OUT_NAKING (ep); | ||
| 520 | |||
| 521 | statp = &ep->regs->ep_stat; | ||
| 522 | writel ( (1 << DATA_OUT_PING_TOKEN_INTERRUPT) | ||
| 523 | | (1 << DATA_PACKET_RECEIVED_INTERRUPT) | ||
| 524 | , statp); | ||
| 525 | writel ((1 << FIFO_FLUSH), statp); | ||
| 526 | mb (); | ||
| 527 | tmp = readl (statp); | ||
| 528 | if (tmp & (1 << DATA_OUT_PING_TOKEN_INTERRUPT) | ||
| 529 | /* high speed did bulk NYET; fifo isn't filling */ | ||
| 530 | && ep->dev->gadget.speed == USB_SPEED_FULL) { | ||
| 531 | unsigned usec; | ||
| 532 | |||
| 533 | usec = 50; /* 64 byte bulk/interrupt */ | ||
| 534 | handshake (statp, (1 << USB_OUT_PING_NAK_SENT), | ||
| 535 | (1 << USB_OUT_PING_NAK_SENT), usec); | ||
| 536 | /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */ | ||
| 537 | } | ||
| 538 | } | ||
| 539 | |||
| 540 | /* unload packet(s) from the fifo we use for usb OUT transfers. | ||
| 541 | * returns true iff the request completed, because of short packet | ||
| 542 | * or the request buffer having filled with full packets. | ||
| 543 | * | ||
| 544 | * for ep-a..ep-d this will read multiple packets out when they | ||
| 545 | * have been accepted. | ||
| 546 | */ | ||
| 547 | static int | ||
| 548 | read_fifo (struct net2280_ep *ep, struct net2280_request *req) | ||
| 549 | { | ||
| 550 | struct net2280_ep_regs __iomem *regs = ep->regs; | ||
| 551 | u8 *buf = req->req.buf + req->req.actual; | ||
| 552 | unsigned count, tmp, is_short; | ||
| 553 | unsigned cleanup = 0, prevent = 0; | ||
| 554 | |||
| 555 | /* erratum 0106 ... packets coming in during fifo reads might | ||
| 556 | * be incompletely rejected. not all cases have workarounds. | ||
| 557 | */ | ||
| 558 | if (ep->dev->chiprev == 0x0100 | ||
| 559 | && ep->dev->gadget.speed == USB_SPEED_FULL) { | ||
| 560 | udelay (1); | ||
| 561 | tmp = readl (&ep->regs->ep_stat); | ||
| 562 | if ((tmp & (1 << NAK_OUT_PACKETS))) | ||
| 563 | cleanup = 1; | ||
| 564 | else if ((tmp & (1 << FIFO_FULL))) { | ||
| 565 | start_out_naking (ep); | ||
| 566 | prevent = 1; | ||
| 567 | } | ||
| 568 | /* else: hope we don't see the problem */ | ||
| 569 | } | ||
| 570 | |||
| 571 | /* never overflow the rx buffer. the fifo reads packets until | ||
| 572 | * it sees a short one; we might not be ready for them all. | ||
| 573 | */ | ||
| 574 | prefetchw (buf); | ||
| 575 | count = readl (®s->ep_avail); | ||
| 576 | if (unlikely (count == 0)) { | ||
| 577 | udelay (1); | ||
| 578 | tmp = readl (&ep->regs->ep_stat); | ||
| 579 | count = readl (®s->ep_avail); | ||
| 580 | /* handled that data already? */ | ||
| 581 | if (count == 0 && (tmp & (1 << NAK_OUT_PACKETS)) == 0) | ||
| 582 | return 0; | ||
| 583 | } | ||
| 584 | |||
| 585 | tmp = req->req.length - req->req.actual; | ||
| 586 | if (count > tmp) { | ||
| 587 | /* as with DMA, data overflow gets flushed */ | ||
| 588 | if ((tmp % ep->ep.maxpacket) != 0) { | ||
| 589 | ERROR (ep->dev, | ||
| 590 | "%s out fifo %d bytes, expected %d\n", | ||
| 591 | ep->ep.name, count, tmp); | ||
| 592 | req->req.status = -EOVERFLOW; | ||
| 593 | cleanup = 1; | ||
| 594 | /* NAK_OUT_PACKETS will be set, so flushing is safe; | ||
| 595 | * the next read will start with the next packet | ||
| 596 | */ | ||
| 597 | } /* else it's a ZLP, no worries */ | ||
| 598 | count = tmp; | ||
| 599 | } | ||
| 600 | req->req.actual += count; | ||
| 601 | |||
| 602 | is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0); | ||
| 603 | |||
| 604 | VDEBUG (ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n", | ||
| 605 | ep->ep.name, count, is_short ? " (short)" : "", | ||
| 606 | cleanup ? " flush" : "", prevent ? " nak" : "", | ||
| 607 | req, req->req.actual, req->req.length); | ||
| 608 | |||
| 609 | while (count >= 4) { | ||
| 610 | tmp = readl (®s->ep_data); | ||
| 611 | cpu_to_le32s (&tmp); | ||
| 612 | put_unaligned (tmp, (u32 *)buf); | ||
| 613 | buf += 4; | ||
| 614 | count -= 4; | ||
| 615 | } | ||
| 616 | if (count) { | ||
| 617 | tmp = readl (®s->ep_data); | ||
| 618 | /* LE conversion is implicit here: */ | ||
| 619 | do { | ||
| 620 | *buf++ = (u8) tmp; | ||
| 621 | tmp >>= 8; | ||
| 622 | } while (--count); | ||
| 623 | } | ||
| 624 | if (cleanup) | ||
| 625 | out_flush (ep); | ||
| 626 | if (prevent) { | ||
| 627 | writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 628 | (void) readl (&ep->regs->ep_rsp); | ||
| 629 | } | ||
| 630 | |||
| 631 | return is_short || ((req->req.actual == req->req.length) | ||
| 632 | && !req->req.zero); | ||
| 633 | } | ||
| 634 | |||
| 635 | /* fill out dma descriptor to match a given request */ | ||
| 636 | static void | ||
| 637 | fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid) | ||
| 638 | { | ||
| 639 | struct net2280_dma *td = req->td; | ||
| 640 | u32 dmacount = req->req.length; | ||
| 641 | |||
| 642 | /* don't let DMA continue after a short OUT packet, | ||
| 643 | * so overruns can't affect the next transfer. | ||
| 644 | * in case of overruns on max-size packets, we can't | ||
| 645 | * stop the fifo from filling but we can flush it. | ||
| 646 | */ | ||
| 647 | if (ep->is_in) | ||
| 648 | dmacount |= (1 << DMA_DIRECTION); | ||
| 649 | if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) | ||
| 650 | || ep->dev->pdev->device != 0x2280) | ||
| 651 | dmacount |= (1 << END_OF_CHAIN); | ||
| 652 | |||
| 653 | req->valid = valid; | ||
| 654 | if (valid) | ||
| 655 | dmacount |= (1 << VALID_BIT); | ||
| 656 | if (likely(!req->req.no_interrupt || !use_dma_chaining)) | ||
| 657 | dmacount |= (1 << DMA_DONE_INTERRUPT_ENABLE); | ||
| 658 | |||
| 659 | /* td->dmadesc = previously set by caller */ | ||
| 660 | td->dmaaddr = cpu_to_le32 (req->req.dma); | ||
| 661 | |||
| 662 | /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */ | ||
| 663 | wmb (); | ||
| 664 | td->dmacount = cpu_to_le32(dmacount); | ||
| 665 | } | ||
| 666 | |||
| 667 | static const u32 dmactl_default = | ||
| 668 | (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT) | ||
| 669 | | (1 << DMA_CLEAR_COUNT_ENABLE) | ||
| 670 | /* erratum 0116 workaround part 1 (use POLLING) */ | ||
| 671 | | (POLL_100_USEC << DESCRIPTOR_POLLING_RATE) | ||
| 672 | | (1 << DMA_VALID_BIT_POLLING_ENABLE) | ||
| 673 | | (1 << DMA_VALID_BIT_ENABLE) | ||
| 674 | | (1 << DMA_SCATTER_GATHER_ENABLE) | ||
| 675 | /* erratum 0116 workaround part 2 (no AUTOSTART) */ | ||
| 676 | | (1 << DMA_ENABLE); | ||
| 677 | |||
| 678 | static inline void spin_stop_dma (struct net2280_dma_regs __iomem *dma) | ||
| 679 | { | ||
| 680 | handshake (&dma->dmactl, (1 << DMA_ENABLE), 0, 50); | ||
| 681 | } | ||
| 682 | |||
| 683 | static inline void stop_dma (struct net2280_dma_regs __iomem *dma) | ||
| 684 | { | ||
| 685 | writel (readl (&dma->dmactl) & ~(1 << DMA_ENABLE), &dma->dmactl); | ||
| 686 | spin_stop_dma (dma); | ||
| 687 | } | ||
| 688 | |||
| 689 | static void start_queue (struct net2280_ep *ep, u32 dmactl, u32 td_dma) | ||
| 690 | { | ||
| 691 | struct net2280_dma_regs __iomem *dma = ep->dma; | ||
| 692 | unsigned int tmp = (1 << VALID_BIT) | (ep->is_in << DMA_DIRECTION); | ||
| 693 | |||
| 694 | if (ep->dev->pdev->device != 0x2280) | ||
| 695 | tmp |= (1 << END_OF_CHAIN); | ||
| 696 | |||
| 697 | writel (tmp, &dma->dmacount); | ||
| 698 | writel (readl (&dma->dmastat), &dma->dmastat); | ||
| 699 | |||
| 700 | writel (td_dma, &dma->dmadesc); | ||
| 701 | writel (dmactl, &dma->dmactl); | ||
| 702 | |||
| 703 | /* erratum 0116 workaround part 3: pci arbiter away from net2280 */ | ||
| 704 | (void) readl (&ep->dev->pci->pcimstctl); | ||
| 705 | |||
| 706 | writel ((1 << DMA_START), &dma->dmastat); | ||
| 707 | |||
| 708 | if (!ep->is_in) | ||
| 709 | stop_out_naking (ep); | ||
| 710 | } | ||
| 711 | |||
| 712 | static void start_dma (struct net2280_ep *ep, struct net2280_request *req) | ||
| 713 | { | ||
| 714 | u32 tmp; | ||
| 715 | struct net2280_dma_regs __iomem *dma = ep->dma; | ||
| 716 | |||
| 717 | /* FIXME can't use DMA for ZLPs */ | ||
| 718 | |||
| 719 | /* on this path we "know" there's no dma active (yet) */ | ||
| 720 | WARN_ON (readl (&dma->dmactl) & (1 << DMA_ENABLE)); | ||
| 721 | writel (0, &ep->dma->dmactl); | ||
| 722 | |||
| 723 | /* previous OUT packet might have been short */ | ||
| 724 | if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat)) | ||
| 725 | & (1 << NAK_OUT_PACKETS)) != 0) { | ||
| 726 | writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT), | ||
| 727 | &ep->regs->ep_stat); | ||
| 728 | |||
| 729 | tmp = readl (&ep->regs->ep_avail); | ||
| 730 | if (tmp) { | ||
| 731 | writel (readl (&dma->dmastat), &dma->dmastat); | ||
| 732 | |||
| 733 | /* transfer all/some fifo data */ | ||
| 734 | writel (req->req.dma, &dma->dmaaddr); | ||
| 735 | tmp = min (tmp, req->req.length); | ||
| 736 | |||
| 737 | /* dma irq, faking scatterlist status */ | ||
| 738 | req->td->dmacount = cpu_to_le32 (req->req.length - tmp); | ||
| 739 | writel ((1 << DMA_DONE_INTERRUPT_ENABLE) | ||
| 740 | | tmp, &dma->dmacount); | ||
| 741 | req->td->dmadesc = 0; | ||
| 742 | req->valid = 1; | ||
| 743 | |||
| 744 | writel ((1 << DMA_ENABLE), &dma->dmactl); | ||
| 745 | writel ((1 << DMA_START), &dma->dmastat); | ||
| 746 | return; | ||
| 747 | } | ||
| 748 | } | ||
| 749 | |||
| 750 | tmp = dmactl_default; | ||
| 751 | |||
| 752 | /* force packet boundaries between dma requests, but prevent the | ||
| 753 | * controller from automagically writing a last "short" packet | ||
| 754 | * (zero length) unless the driver explicitly said to do that. | ||
| 755 | */ | ||
| 756 | if (ep->is_in) { | ||
| 757 | if (likely ((req->req.length % ep->ep.maxpacket) != 0 | ||
| 758 | || req->req.zero)) { | ||
| 759 | tmp |= (1 << DMA_FIFO_VALIDATE); | ||
| 760 | ep->in_fifo_validate = 1; | ||
| 761 | } else | ||
| 762 | ep->in_fifo_validate = 0; | ||
| 763 | } | ||
| 764 | |||
| 765 | /* init req->td, pointing to the current dummy */ | ||
| 766 | req->td->dmadesc = cpu_to_le32 (ep->td_dma); | ||
| 767 | fill_dma_desc (ep, req, 1); | ||
| 768 | |||
| 769 | if (!use_dma_chaining) | ||
| 770 | req->td->dmacount |= cpu_to_le32 (1 << END_OF_CHAIN); | ||
| 771 | |||
| 772 | start_queue (ep, tmp, req->td_dma); | ||
| 773 | } | ||
| 774 | |||
| 775 | static inline void | ||
| 776 | queue_dma (struct net2280_ep *ep, struct net2280_request *req, int valid) | ||
| 777 | { | ||
| 778 | struct net2280_dma *end; | ||
| 779 | dma_addr_t tmp; | ||
| 780 | |||
| 781 | /* swap new dummy for old, link; fill and maybe activate */ | ||
| 782 | end = ep->dummy; | ||
| 783 | ep->dummy = req->td; | ||
| 784 | req->td = end; | ||
| 785 | |||
| 786 | tmp = ep->td_dma; | ||
| 787 | ep->td_dma = req->td_dma; | ||
| 788 | req->td_dma = tmp; | ||
| 789 | |||
| 790 | end->dmadesc = cpu_to_le32 (ep->td_dma); | ||
| 791 | |||
| 792 | fill_dma_desc (ep, req, valid); | ||
| 793 | } | ||
| 794 | |||
| 795 | static void | ||
| 796 | done (struct net2280_ep *ep, struct net2280_request *req, int status) | ||
| 797 | { | ||
| 798 | struct net2280 *dev; | ||
| 799 | unsigned stopped = ep->stopped; | ||
| 800 | |||
| 801 | list_del_init (&req->queue); | ||
| 802 | |||
| 803 | if (req->req.status == -EINPROGRESS) | ||
| 804 | req->req.status = status; | ||
| 805 | else | ||
| 806 | status = req->req.status; | ||
| 807 | |||
| 808 | dev = ep->dev; | ||
| 809 | if (ep->dma) | ||
| 810 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); | ||
| 811 | |||
| 812 | if (status && status != -ESHUTDOWN) | ||
| 813 | VDEBUG (dev, "complete %s req %p stat %d len %u/%u\n", | ||
| 814 | ep->ep.name, &req->req, status, | ||
| 815 | req->req.actual, req->req.length); | ||
| 816 | |||
| 817 | /* don't modify queue heads during completion callback */ | ||
| 818 | ep->stopped = 1; | ||
| 819 | spin_unlock (&dev->lock); | ||
| 820 | req->req.complete (&ep->ep, &req->req); | ||
| 821 | spin_lock (&dev->lock); | ||
| 822 | ep->stopped = stopped; | ||
| 823 | } | ||
| 824 | |||
| 825 | /*-------------------------------------------------------------------------*/ | ||
| 826 | |||
| 827 | static int | ||
| 828 | net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | ||
| 829 | { | ||
| 830 | struct net2280_request *req; | ||
| 831 | struct net2280_ep *ep; | ||
| 832 | struct net2280 *dev; | ||
| 833 | unsigned long flags; | ||
| 834 | |||
| 835 | /* we always require a cpu-view buffer, so that we can | ||
| 836 | * always use pio (as fallback or whatever). | ||
| 837 | */ | ||
| 838 | req = container_of (_req, struct net2280_request, req); | ||
| 839 | if (!_req || !_req->complete || !_req->buf | ||
| 840 | || !list_empty (&req->queue)) | ||
| 841 | return -EINVAL; | ||
| 842 | if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) | ||
| 843 | return -EDOM; | ||
| 844 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 845 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 846 | return -EINVAL; | ||
| 847 | dev = ep->dev; | ||
| 848 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 849 | return -ESHUTDOWN; | ||
| 850 | |||
| 851 | /* FIXME implement PIO fallback for ZLPs with DMA */ | ||
| 852 | if (ep->dma && _req->length == 0) | ||
| 853 | return -EOPNOTSUPP; | ||
| 854 | |||
| 855 | /* set up dma mapping in case the caller didn't */ | ||
| 856 | if (ep->dma) { | ||
| 857 | int ret; | ||
| 858 | |||
| 859 | ret = usb_gadget_map_request(&dev->gadget, _req, | ||
| 860 | ep->is_in); | ||
| 861 | if (ret) | ||
| 862 | return ret; | ||
| 863 | } | ||
| 864 | |||
| 865 | #if 0 | ||
| 866 | VDEBUG (dev, "%s queue req %p, len %d buf %p\n", | ||
| 867 | _ep->name, _req, _req->length, _req->buf); | ||
| 868 | #endif | ||
| 869 | |||
| 870 | spin_lock_irqsave (&dev->lock, flags); | ||
| 871 | |||
| 872 | _req->status = -EINPROGRESS; | ||
| 873 | _req->actual = 0; | ||
| 874 | |||
| 875 | /* kickstart this i/o queue? */ | ||
| 876 | if (list_empty (&ep->queue) && !ep->stopped) { | ||
| 877 | /* use DMA if the endpoint supports it, else pio */ | ||
| 878 | if (ep->dma) | ||
| 879 | start_dma (ep, req); | ||
| 880 | else { | ||
| 881 | /* maybe there's no control data, just status ack */ | ||
| 882 | if (ep->num == 0 && _req->length == 0) { | ||
| 883 | allow_status (ep); | ||
| 884 | done (ep, req, 0); | ||
| 885 | VDEBUG (dev, "%s status ack\n", ep->ep.name); | ||
| 886 | goto done; | ||
| 887 | } | ||
| 888 | |||
| 889 | /* PIO ... stuff the fifo, or unblock it. */ | ||
| 890 | if (ep->is_in) | ||
| 891 | write_fifo (ep, _req); | ||
| 892 | else if (list_empty (&ep->queue)) { | ||
| 893 | u32 s; | ||
| 894 | |||
| 895 | /* OUT FIFO might have packet(s) buffered */ | ||
| 896 | s = readl (&ep->regs->ep_stat); | ||
| 897 | if ((s & (1 << FIFO_EMPTY)) == 0) { | ||
| 898 | /* note: _req->short_not_ok is | ||
| 899 | * ignored here since PIO _always_ | ||
| 900 | * stops queue advance here, and | ||
| 901 | * _req->status doesn't change for | ||
| 902 | * short reads (only _req->actual) | ||
| 903 | */ | ||
| 904 | if (read_fifo (ep, req)) { | ||
| 905 | done (ep, req, 0); | ||
| 906 | if (ep->num == 0) | ||
| 907 | allow_status (ep); | ||
| 908 | /* don't queue it */ | ||
| 909 | req = NULL; | ||
| 910 | } else | ||
| 911 | s = readl (&ep->regs->ep_stat); | ||
| 912 | } | ||
| 913 | |||
| 914 | /* don't NAK, let the fifo fill */ | ||
| 915 | if (req && (s & (1 << NAK_OUT_PACKETS))) | ||
| 916 | writel ((1 << CLEAR_NAK_OUT_PACKETS), | ||
| 917 | &ep->regs->ep_rsp); | ||
| 918 | } | ||
| 919 | } | ||
| 920 | |||
| 921 | } else if (ep->dma) { | ||
| 922 | int valid = 1; | ||
| 923 | |||
| 924 | if (ep->is_in) { | ||
| 925 | int expect; | ||
| 926 | |||
| 927 | /* preventing magic zlps is per-engine state, not | ||
| 928 | * per-transfer; irq logic must recover hiccups. | ||
| 929 | */ | ||
| 930 | expect = likely (req->req.zero | ||
| 931 | || (req->req.length % ep->ep.maxpacket) != 0); | ||
| 932 | if (expect != ep->in_fifo_validate) | ||
| 933 | valid = 0; | ||
| 934 | } | ||
| 935 | queue_dma (ep, req, valid); | ||
| 936 | |||
| 937 | } /* else the irq handler advances the queue. */ | ||
| 938 | |||
| 939 | ep->responded = 1; | ||
| 940 | if (req) | ||
| 941 | list_add_tail (&req->queue, &ep->queue); | ||
| 942 | done: | ||
| 943 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 944 | |||
| 945 | /* pci writes may still be posted */ | ||
| 946 | return 0; | ||
| 947 | } | ||
| 948 | |||
| 949 | static inline void | ||
| 950 | dma_done ( | ||
| 951 | struct net2280_ep *ep, | ||
| 952 | struct net2280_request *req, | ||
| 953 | u32 dmacount, | ||
| 954 | int status | ||
| 955 | ) | ||
| 956 | { | ||
| 957 | req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount); | ||
| 958 | done (ep, req, status); | ||
| 959 | } | ||
| 960 | |||
| 961 | static void restart_dma (struct net2280_ep *ep); | ||
| 962 | |||
| 963 | static void scan_dma_completions (struct net2280_ep *ep) | ||
| 964 | { | ||
| 965 | /* only look at descriptors that were "naturally" retired, | ||
| 966 | * so fifo and list head state won't matter | ||
| 967 | */ | ||
| 968 | while (!list_empty (&ep->queue)) { | ||
| 969 | struct net2280_request *req; | ||
| 970 | u32 tmp; | ||
| 971 | |||
| 972 | req = list_entry (ep->queue.next, | ||
| 973 | struct net2280_request, queue); | ||
| 974 | if (!req->valid) | ||
| 975 | break; | ||
| 976 | rmb (); | ||
| 977 | tmp = le32_to_cpup (&req->td->dmacount); | ||
| 978 | if ((tmp & (1 << VALID_BIT)) != 0) | ||
| 979 | break; | ||
| 980 | |||
| 981 | /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short" | ||
| 982 | * cases where DMA must be aborted; this code handles | ||
| 983 | * all non-abort DMA completions. | ||
| 984 | */ | ||
| 985 | if (unlikely (req->td->dmadesc == 0)) { | ||
| 986 | /* paranoia */ | ||
| 987 | tmp = readl (&ep->dma->dmacount); | ||
| 988 | if (tmp & DMA_BYTE_COUNT_MASK) | ||
| 989 | break; | ||
| 990 | /* single transfer mode */ | ||
| 991 | dma_done (ep, req, tmp, 0); | ||
| 992 | break; | ||
| 993 | } else if (!ep->is_in | ||
| 994 | && (req->req.length % ep->ep.maxpacket) != 0) { | ||
| 995 | tmp = readl (&ep->regs->ep_stat); | ||
| 996 | |||
| 997 | /* AVOID TROUBLE HERE by not issuing short reads from | ||
| 998 | * your gadget driver. That helps avoids errata 0121, | ||
| 999 | * 0122, and 0124; not all cases trigger the warning. | ||
| 1000 | */ | ||
| 1001 | if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) { | ||
| 1002 | WARNING (ep->dev, "%s lost packet sync!\n", | ||
| 1003 | ep->ep.name); | ||
| 1004 | req->req.status = -EOVERFLOW; | ||
| 1005 | } else if ((tmp = readl (&ep->regs->ep_avail)) != 0) { | ||
| 1006 | /* fifo gets flushed later */ | ||
| 1007 | ep->out_overflow = 1; | ||
| 1008 | DEBUG (ep->dev, "%s dma, discard %d len %d\n", | ||
| 1009 | ep->ep.name, tmp, | ||
| 1010 | req->req.length); | ||
| 1011 | req->req.status = -EOVERFLOW; | ||
| 1012 | } | ||
| 1013 | } | ||
| 1014 | dma_done (ep, req, tmp, 0); | ||
| 1015 | } | ||
| 1016 | } | ||
| 1017 | |||
| 1018 | static void restart_dma (struct net2280_ep *ep) | ||
| 1019 | { | ||
| 1020 | struct net2280_request *req; | ||
| 1021 | u32 dmactl = dmactl_default; | ||
| 1022 | |||
| 1023 | if (ep->stopped) | ||
| 1024 | return; | ||
| 1025 | req = list_entry (ep->queue.next, struct net2280_request, queue); | ||
| 1026 | |||
| 1027 | if (!use_dma_chaining) { | ||
| 1028 | start_dma (ep, req); | ||
| 1029 | return; | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | /* the 2280 will be processing the queue unless queue hiccups after | ||
| 1033 | * the previous transfer: | ||
| 1034 | * IN: wanted automagic zlp, head doesn't (or vice versa) | ||
| 1035 | * DMA_FIFO_VALIDATE doesn't init from dma descriptors. | ||
| 1036 | * OUT: was "usb-short", we must restart. | ||
| 1037 | */ | ||
| 1038 | if (ep->is_in && !req->valid) { | ||
| 1039 | struct net2280_request *entry, *prev = NULL; | ||
| 1040 | int reqmode, done = 0; | ||
| 1041 | |||
| 1042 | DEBUG (ep->dev, "%s dma hiccup td %p\n", ep->ep.name, req->td); | ||
| 1043 | ep->in_fifo_validate = likely (req->req.zero | ||
| 1044 | || (req->req.length % ep->ep.maxpacket) != 0); | ||
| 1045 | if (ep->in_fifo_validate) | ||
| 1046 | dmactl |= (1 << DMA_FIFO_VALIDATE); | ||
| 1047 | list_for_each_entry (entry, &ep->queue, queue) { | ||
| 1048 | __le32 dmacount; | ||
| 1049 | |||
| 1050 | if (entry == req) | ||
| 1051 | continue; | ||
| 1052 | dmacount = entry->td->dmacount; | ||
| 1053 | if (!done) { | ||
| 1054 | reqmode = likely (entry->req.zero | ||
| 1055 | || (entry->req.length | ||
| 1056 | % ep->ep.maxpacket) != 0); | ||
| 1057 | if (reqmode == ep->in_fifo_validate) { | ||
| 1058 | entry->valid = 1; | ||
| 1059 | dmacount |= valid_bit; | ||
| 1060 | entry->td->dmacount = dmacount; | ||
| 1061 | prev = entry; | ||
| 1062 | continue; | ||
| 1063 | } else { | ||
| 1064 | /* force a hiccup */ | ||
| 1065 | prev->td->dmacount |= dma_done_ie; | ||
| 1066 | done = 1; | ||
| 1067 | } | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | /* walk the rest of the queue so unlinks behave */ | ||
| 1071 | entry->valid = 0; | ||
| 1072 | dmacount &= ~valid_bit; | ||
| 1073 | entry->td->dmacount = dmacount; | ||
| 1074 | prev = entry; | ||
| 1075 | } | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | writel (0, &ep->dma->dmactl); | ||
| 1079 | start_queue (ep, dmactl, req->td_dma); | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | static void abort_dma (struct net2280_ep *ep) | ||
| 1083 | { | ||
| 1084 | /* abort the current transfer */ | ||
| 1085 | if (likely (!list_empty (&ep->queue))) { | ||
| 1086 | /* FIXME work around errata 0121, 0122, 0124 */ | ||
| 1087 | writel ((1 << DMA_ABORT), &ep->dma->dmastat); | ||
| 1088 | spin_stop_dma (ep->dma); | ||
| 1089 | } else | ||
| 1090 | stop_dma (ep->dma); | ||
| 1091 | scan_dma_completions (ep); | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | /* dequeue ALL requests */ | ||
| 1095 | static void nuke (struct net2280_ep *ep) | ||
| 1096 | { | ||
| 1097 | struct net2280_request *req; | ||
| 1098 | |||
| 1099 | /* called with spinlock held */ | ||
| 1100 | ep->stopped = 1; | ||
| 1101 | if (ep->dma) | ||
| 1102 | abort_dma (ep); | ||
| 1103 | while (!list_empty (&ep->queue)) { | ||
| 1104 | req = list_entry (ep->queue.next, | ||
| 1105 | struct net2280_request, | ||
| 1106 | queue); | ||
| 1107 | done (ep, req, -ESHUTDOWN); | ||
| 1108 | } | ||
| 1109 | } | ||
| 1110 | |||
| 1111 | /* dequeue JUST ONE request */ | ||
| 1112 | static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req) | ||
| 1113 | { | ||
| 1114 | struct net2280_ep *ep; | ||
| 1115 | struct net2280_request *req; | ||
| 1116 | unsigned long flags; | ||
| 1117 | u32 dmactl; | ||
| 1118 | int stopped; | ||
| 1119 | |||
| 1120 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 1121 | if (!_ep || (!ep->desc && ep->num != 0) || !_req) | ||
| 1122 | return -EINVAL; | ||
| 1123 | |||
| 1124 | spin_lock_irqsave (&ep->dev->lock, flags); | ||
| 1125 | stopped = ep->stopped; | ||
| 1126 | |||
| 1127 | /* quiesce dma while we patch the queue */ | ||
| 1128 | dmactl = 0; | ||
| 1129 | ep->stopped = 1; | ||
| 1130 | if (ep->dma) { | ||
| 1131 | dmactl = readl (&ep->dma->dmactl); | ||
| 1132 | /* WARNING erratum 0127 may kick in ... */ | ||
| 1133 | stop_dma (ep->dma); | ||
| 1134 | scan_dma_completions (ep); | ||
| 1135 | } | ||
| 1136 | |||
| 1137 | /* make sure it's still queued on this endpoint */ | ||
| 1138 | list_for_each_entry (req, &ep->queue, queue) { | ||
| 1139 | if (&req->req == _req) | ||
| 1140 | break; | ||
| 1141 | } | ||
| 1142 | if (&req->req != _req) { | ||
| 1143 | spin_unlock_irqrestore (&ep->dev->lock, flags); | ||
| 1144 | return -EINVAL; | ||
| 1145 | } | ||
| 1146 | |||
| 1147 | /* queue head may be partially complete. */ | ||
| 1148 | if (ep->queue.next == &req->queue) { | ||
| 1149 | if (ep->dma) { | ||
| 1150 | DEBUG (ep->dev, "unlink (%s) dma\n", _ep->name); | ||
| 1151 | _req->status = -ECONNRESET; | ||
| 1152 | abort_dma (ep); | ||
| 1153 | if (likely (ep->queue.next == &req->queue)) { | ||
| 1154 | // NOTE: misreports single-transfer mode | ||
| 1155 | req->td->dmacount = 0; /* invalidate */ | ||
| 1156 | dma_done (ep, req, | ||
| 1157 | readl (&ep->dma->dmacount), | ||
| 1158 | -ECONNRESET); | ||
| 1159 | } | ||
| 1160 | } else { | ||
| 1161 | DEBUG (ep->dev, "unlink (%s) pio\n", _ep->name); | ||
| 1162 | done (ep, req, -ECONNRESET); | ||
| 1163 | } | ||
| 1164 | req = NULL; | ||
| 1165 | |||
| 1166 | /* patch up hardware chaining data */ | ||
| 1167 | } else if (ep->dma && use_dma_chaining) { | ||
| 1168 | if (req->queue.prev == ep->queue.next) { | ||
| 1169 | writel (le32_to_cpu (req->td->dmadesc), | ||
| 1170 | &ep->dma->dmadesc); | ||
| 1171 | if (req->td->dmacount & dma_done_ie) | ||
| 1172 | writel (readl (&ep->dma->dmacount) | ||
| 1173 | | le32_to_cpu(dma_done_ie), | ||
| 1174 | &ep->dma->dmacount); | ||
| 1175 | } else { | ||
| 1176 | struct net2280_request *prev; | ||
| 1177 | |||
| 1178 | prev = list_entry (req->queue.prev, | ||
| 1179 | struct net2280_request, queue); | ||
| 1180 | prev->td->dmadesc = req->td->dmadesc; | ||
| 1181 | if (req->td->dmacount & dma_done_ie) | ||
| 1182 | prev->td->dmacount |= dma_done_ie; | ||
| 1183 | } | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | if (req) | ||
| 1187 | done (ep, req, -ECONNRESET); | ||
| 1188 | ep->stopped = stopped; | ||
| 1189 | |||
| 1190 | if (ep->dma) { | ||
| 1191 | /* turn off dma on inactive queues */ | ||
| 1192 | if (list_empty (&ep->queue)) | ||
| 1193 | stop_dma (ep->dma); | ||
| 1194 | else if (!ep->stopped) { | ||
| 1195 | /* resume current request, or start new one */ | ||
| 1196 | if (req) | ||
| 1197 | writel (dmactl, &ep->dma->dmactl); | ||
| 1198 | else | ||
| 1199 | start_dma (ep, list_entry (ep->queue.next, | ||
| 1200 | struct net2280_request, queue)); | ||
| 1201 | } | ||
| 1202 | } | ||
| 1203 | |||
| 1204 | spin_unlock_irqrestore (&ep->dev->lock, flags); | ||
| 1205 | return 0; | ||
| 1206 | } | ||
| 1207 | |||
| 1208 | /*-------------------------------------------------------------------------*/ | ||
| 1209 | |||
| 1210 | static int net2280_fifo_status (struct usb_ep *_ep); | ||
| 1211 | |||
| 1212 | static int | ||
| 1213 | net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) | ||
| 1214 | { | ||
| 1215 | struct net2280_ep *ep; | ||
| 1216 | unsigned long flags; | ||
| 1217 | int retval = 0; | ||
| 1218 | |||
| 1219 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 1220 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 1221 | return -EINVAL; | ||
| 1222 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1223 | return -ESHUTDOWN; | ||
| 1224 | if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03) | ||
| 1225 | == USB_ENDPOINT_XFER_ISOC) | ||
| 1226 | return -EINVAL; | ||
| 1227 | |||
| 1228 | spin_lock_irqsave (&ep->dev->lock, flags); | ||
| 1229 | if (!list_empty (&ep->queue)) | ||
| 1230 | retval = -EAGAIN; | ||
| 1231 | else if (ep->is_in && value && net2280_fifo_status (_ep) != 0) | ||
| 1232 | retval = -EAGAIN; | ||
| 1233 | else { | ||
| 1234 | VDEBUG (ep->dev, "%s %s %s\n", _ep->name, | ||
| 1235 | value ? "set" : "clear", | ||
| 1236 | wedged ? "wedge" : "halt"); | ||
| 1237 | /* set/clear, then synch memory views with the device */ | ||
| 1238 | if (value) { | ||
| 1239 | if (ep->num == 0) | ||
| 1240 | ep->dev->protocol_stall = 1; | ||
| 1241 | else | ||
| 1242 | set_halt (ep); | ||
| 1243 | if (wedged) | ||
| 1244 | ep->wedged = 1; | ||
| 1245 | } else { | ||
| 1246 | clear_halt (ep); | ||
| 1247 | ep->wedged = 0; | ||
| 1248 | } | ||
| 1249 | (void) readl (&ep->regs->ep_rsp); | ||
| 1250 | } | ||
| 1251 | spin_unlock_irqrestore (&ep->dev->lock, flags); | ||
| 1252 | |||
| 1253 | return retval; | ||
| 1254 | } | ||
| 1255 | |||
| 1256 | static int | ||
| 1257 | net2280_set_halt(struct usb_ep *_ep, int value) | ||
| 1258 | { | ||
| 1259 | return net2280_set_halt_and_wedge(_ep, value, 0); | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | static int | ||
| 1263 | net2280_set_wedge(struct usb_ep *_ep) | ||
| 1264 | { | ||
| 1265 | if (!_ep || _ep->name == ep0name) | ||
| 1266 | return -EINVAL; | ||
| 1267 | return net2280_set_halt_and_wedge(_ep, 1, 1); | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | static int | ||
| 1271 | net2280_fifo_status (struct usb_ep *_ep) | ||
| 1272 | { | ||
| 1273 | struct net2280_ep *ep; | ||
| 1274 | u32 avail; | ||
| 1275 | |||
| 1276 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 1277 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 1278 | return -ENODEV; | ||
| 1279 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1280 | return -ESHUTDOWN; | ||
| 1281 | |||
| 1282 | avail = readl (&ep->regs->ep_avail) & ((1 << 12) - 1); | ||
| 1283 | if (avail > ep->fifo_size) | ||
| 1284 | return -EOVERFLOW; | ||
| 1285 | if (ep->is_in) | ||
| 1286 | avail = ep->fifo_size - avail; | ||
| 1287 | return avail; | ||
| 1288 | } | ||
| 1289 | |||
| 1290 | static void | ||
| 1291 | net2280_fifo_flush (struct usb_ep *_ep) | ||
| 1292 | { | ||
| 1293 | struct net2280_ep *ep; | ||
| 1294 | |||
| 1295 | ep = container_of (_ep, struct net2280_ep, ep); | ||
| 1296 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 1297 | return; | ||
| 1298 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1299 | return; | ||
| 1300 | |||
| 1301 | writel ((1 << FIFO_FLUSH), &ep->regs->ep_stat); | ||
| 1302 | (void) readl (&ep->regs->ep_rsp); | ||
| 1303 | } | ||
| 1304 | |||
| 1305 | static const struct usb_ep_ops net2280_ep_ops = { | ||
| 1306 | .enable = net2280_enable, | ||
| 1307 | .disable = net2280_disable, | ||
| 1308 | |||
| 1309 | .alloc_request = net2280_alloc_request, | ||
| 1310 | .free_request = net2280_free_request, | ||
| 1311 | |||
| 1312 | .queue = net2280_queue, | ||
| 1313 | .dequeue = net2280_dequeue, | ||
| 1314 | |||
| 1315 | .set_halt = net2280_set_halt, | ||
| 1316 | .set_wedge = net2280_set_wedge, | ||
| 1317 | .fifo_status = net2280_fifo_status, | ||
| 1318 | .fifo_flush = net2280_fifo_flush, | ||
| 1319 | }; | ||
| 1320 | |||
| 1321 | /*-------------------------------------------------------------------------*/ | ||
| 1322 | |||
| 1323 | static int net2280_get_frame (struct usb_gadget *_gadget) | ||
| 1324 | { | ||
| 1325 | struct net2280 *dev; | ||
| 1326 | unsigned long flags; | ||
| 1327 | u16 retval; | ||
| 1328 | |||
| 1329 | if (!_gadget) | ||
| 1330 | return -ENODEV; | ||
| 1331 | dev = container_of (_gadget, struct net2280, gadget); | ||
| 1332 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1333 | retval = get_idx_reg (dev->regs, REG_FRAME) & 0x03ff; | ||
| 1334 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1335 | return retval; | ||
| 1336 | } | ||
| 1337 | |||
| 1338 | static int net2280_wakeup (struct usb_gadget *_gadget) | ||
| 1339 | { | ||
| 1340 | struct net2280 *dev; | ||
| 1341 | u32 tmp; | ||
| 1342 | unsigned long flags; | ||
| 1343 | |||
| 1344 | if (!_gadget) | ||
| 1345 | return 0; | ||
| 1346 | dev = container_of (_gadget, struct net2280, gadget); | ||
| 1347 | |||
| 1348 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1349 | tmp = readl (&dev->usb->usbctl); | ||
| 1350 | if (tmp & (1 << DEVICE_REMOTE_WAKEUP_ENABLE)) | ||
| 1351 | writel (1 << GENERATE_RESUME, &dev->usb->usbstat); | ||
| 1352 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1353 | |||
| 1354 | /* pci writes may still be posted */ | ||
| 1355 | return 0; | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | static int net2280_set_selfpowered (struct usb_gadget *_gadget, int value) | ||
| 1359 | { | ||
| 1360 | struct net2280 *dev; | ||
| 1361 | u32 tmp; | ||
| 1362 | unsigned long flags; | ||
| 1363 | |||
| 1364 | if (!_gadget) | ||
| 1365 | return 0; | ||
| 1366 | dev = container_of (_gadget, struct net2280, gadget); | ||
| 1367 | |||
| 1368 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1369 | tmp = readl (&dev->usb->usbctl); | ||
| 1370 | if (value) | ||
| 1371 | tmp |= (1 << SELF_POWERED_STATUS); | ||
| 1372 | else | ||
| 1373 | tmp &= ~(1 << SELF_POWERED_STATUS); | ||
| 1374 | writel (tmp, &dev->usb->usbctl); | ||
| 1375 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1376 | |||
| 1377 | return 0; | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | static int net2280_pullup(struct usb_gadget *_gadget, int is_on) | ||
| 1381 | { | ||
| 1382 | struct net2280 *dev; | ||
| 1383 | u32 tmp; | ||
| 1384 | unsigned long flags; | ||
| 1385 | |||
| 1386 | if (!_gadget) | ||
| 1387 | return -ENODEV; | ||
| 1388 | dev = container_of (_gadget, struct net2280, gadget); | ||
| 1389 | |||
| 1390 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1391 | tmp = readl (&dev->usb->usbctl); | ||
| 1392 | dev->softconnect = (is_on != 0); | ||
| 1393 | if (is_on) | ||
| 1394 | tmp |= (1 << USB_DETECT_ENABLE); | ||
| 1395 | else | ||
| 1396 | tmp &= ~(1 << USB_DETECT_ENABLE); | ||
| 1397 | writel (tmp, &dev->usb->usbctl); | ||
| 1398 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1399 | |||
| 1400 | return 0; | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | static int net2280_start(struct usb_gadget *_gadget, | ||
| 1404 | struct usb_gadget_driver *driver); | ||
| 1405 | static int net2280_stop(struct usb_gadget *_gadget, | ||
| 1406 | struct usb_gadget_driver *driver); | ||
| 1407 | |||
| 1408 | static const struct usb_gadget_ops net2280_ops = { | ||
| 1409 | .get_frame = net2280_get_frame, | ||
| 1410 | .wakeup = net2280_wakeup, | ||
| 1411 | .set_selfpowered = net2280_set_selfpowered, | ||
| 1412 | .pullup = net2280_pullup, | ||
| 1413 | .udc_start = net2280_start, | ||
| 1414 | .udc_stop = net2280_stop, | ||
| 1415 | }; | ||
| 1416 | |||
| 1417 | /*-------------------------------------------------------------------------*/ | ||
| 1418 | |||
| 1419 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
| 1420 | |||
| 1421 | /* FIXME move these into procfs, and use seq_file. | ||
| 1422 | * Sysfs _still_ doesn't behave for arbitrarily sized files, | ||
| 1423 | * and also doesn't help products using this with 2.4 kernels. | ||
| 1424 | */ | ||
| 1425 | |||
| 1426 | /* "function" sysfs attribute */ | ||
| 1427 | static ssize_t function_show(struct device *_dev, struct device_attribute *attr, | ||
| 1428 | char *buf) | ||
| 1429 | { | ||
| 1430 | struct net2280 *dev = dev_get_drvdata (_dev); | ||
| 1431 | |||
| 1432 | if (!dev->driver | ||
| 1433 | || !dev->driver->function | ||
| 1434 | || strlen (dev->driver->function) > PAGE_SIZE) | ||
| 1435 | return 0; | ||
| 1436 | return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function); | ||
| 1437 | } | ||
| 1438 | static DEVICE_ATTR_RO(function); | ||
| 1439 | |||
| 1440 | static ssize_t registers_show(struct device *_dev, | ||
| 1441 | struct device_attribute *attr, char *buf) | ||
| 1442 | { | ||
| 1443 | struct net2280 *dev; | ||
| 1444 | char *next; | ||
| 1445 | unsigned size, t; | ||
| 1446 | unsigned long flags; | ||
| 1447 | int i; | ||
| 1448 | u32 t1, t2; | ||
| 1449 | const char *s; | ||
| 1450 | |||
| 1451 | dev = dev_get_drvdata (_dev); | ||
| 1452 | next = buf; | ||
| 1453 | size = PAGE_SIZE; | ||
| 1454 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1455 | |||
| 1456 | if (dev->driver) | ||
| 1457 | s = dev->driver->driver.name; | ||
| 1458 | else | ||
| 1459 | s = "(none)"; | ||
| 1460 | |||
| 1461 | /* Main Control Registers */ | ||
| 1462 | t = scnprintf (next, size, "%s version " DRIVER_VERSION | ||
| 1463 | ", chiprev %04x, dma %s\n\n" | ||
| 1464 | "devinit %03x fifoctl %08x gadget '%s'\n" | ||
| 1465 | "pci irqenb0 %02x irqenb1 %08x " | ||
| 1466 | "irqstat0 %04x irqstat1 %08x\n", | ||
| 1467 | driver_name, dev->chiprev, | ||
| 1468 | use_dma | ||
| 1469 | ? (use_dma_chaining ? "chaining" : "enabled") | ||
| 1470 | : "disabled", | ||
| 1471 | readl (&dev->regs->devinit), | ||
| 1472 | readl (&dev->regs->fifoctl), | ||
| 1473 | s, | ||
| 1474 | readl (&dev->regs->pciirqenb0), | ||
| 1475 | readl (&dev->regs->pciirqenb1), | ||
| 1476 | readl (&dev->regs->irqstat0), | ||
| 1477 | readl (&dev->regs->irqstat1)); | ||
| 1478 | size -= t; | ||
| 1479 | next += t; | ||
| 1480 | |||
| 1481 | /* USB Control Registers */ | ||
| 1482 | t1 = readl (&dev->usb->usbctl); | ||
| 1483 | t2 = readl (&dev->usb->usbstat); | ||
| 1484 | if (t1 & (1 << VBUS_PIN)) { | ||
| 1485 | if (t2 & (1 << HIGH_SPEED)) | ||
| 1486 | s = "high speed"; | ||
| 1487 | else if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1488 | s = "powered"; | ||
| 1489 | else | ||
| 1490 | s = "full speed"; | ||
| 1491 | /* full speed bit (6) not working?? */ | ||
| 1492 | } else | ||
| 1493 | s = "not attached"; | ||
| 1494 | t = scnprintf (next, size, | ||
| 1495 | "stdrsp %08x usbctl %08x usbstat %08x " | ||
| 1496 | "addr 0x%02x (%s)\n", | ||
| 1497 | readl (&dev->usb->stdrsp), t1, t2, | ||
| 1498 | readl (&dev->usb->ouraddr), s); | ||
| 1499 | size -= t; | ||
| 1500 | next += t; | ||
| 1501 | |||
| 1502 | /* PCI Master Control Registers */ | ||
| 1503 | |||
| 1504 | /* DMA Control Registers */ | ||
| 1505 | |||
| 1506 | /* Configurable EP Control Registers */ | ||
| 1507 | for (i = 0; i < 7; i++) { | ||
| 1508 | struct net2280_ep *ep; | ||
| 1509 | |||
| 1510 | ep = &dev->ep [i]; | ||
| 1511 | if (i && !ep->desc) | ||
| 1512 | continue; | ||
| 1513 | |||
| 1514 | t1 = readl (&ep->regs->ep_cfg); | ||
| 1515 | t2 = readl (&ep->regs->ep_rsp) & 0xff; | ||
| 1516 | t = scnprintf (next, size, | ||
| 1517 | "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s" | ||
| 1518 | "irqenb %02x\n", | ||
| 1519 | ep->ep.name, t1, t2, | ||
| 1520 | (t2 & (1 << CLEAR_NAK_OUT_PACKETS)) | ||
| 1521 | ? "NAK " : "", | ||
| 1522 | (t2 & (1 << CLEAR_EP_HIDE_STATUS_PHASE)) | ||
| 1523 | ? "hide " : "", | ||
| 1524 | (t2 & (1 << CLEAR_EP_FORCE_CRC_ERROR)) | ||
| 1525 | ? "CRC " : "", | ||
| 1526 | (t2 & (1 << CLEAR_INTERRUPT_MODE)) | ||
| 1527 | ? "interrupt " : "", | ||
| 1528 | (t2 & (1<<CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)) | ||
| 1529 | ? "status " : "", | ||
| 1530 | (t2 & (1 << CLEAR_NAK_OUT_PACKETS_MODE)) | ||
| 1531 | ? "NAKmode " : "", | ||
| 1532 | (t2 & (1 << CLEAR_ENDPOINT_TOGGLE)) | ||
| 1533 | ? "DATA1 " : "DATA0 ", | ||
| 1534 | (t2 & (1 << CLEAR_ENDPOINT_HALT)) | ||
| 1535 | ? "HALT " : "", | ||
| 1536 | readl (&ep->regs->ep_irqenb)); | ||
| 1537 | size -= t; | ||
| 1538 | next += t; | ||
| 1539 | |||
| 1540 | t = scnprintf (next, size, | ||
| 1541 | "\tstat %08x avail %04x " | ||
| 1542 | "(ep%d%s-%s)%s\n", | ||
| 1543 | readl (&ep->regs->ep_stat), | ||
| 1544 | readl (&ep->regs->ep_avail), | ||
| 1545 | t1 & 0x0f, DIR_STRING (t1), | ||
| 1546 | type_string (t1 >> 8), | ||
| 1547 | ep->stopped ? "*" : ""); | ||
| 1548 | size -= t; | ||
| 1549 | next += t; | ||
| 1550 | |||
| 1551 | if (!ep->dma) | ||
| 1552 | continue; | ||
| 1553 | |||
| 1554 | t = scnprintf (next, size, | ||
| 1555 | " dma\tctl %08x stat %08x count %08x\n" | ||
| 1556 | "\taddr %08x desc %08x\n", | ||
| 1557 | readl (&ep->dma->dmactl), | ||
| 1558 | readl (&ep->dma->dmastat), | ||
| 1559 | readl (&ep->dma->dmacount), | ||
| 1560 | readl (&ep->dma->dmaaddr), | ||
| 1561 | readl (&ep->dma->dmadesc)); | ||
| 1562 | size -= t; | ||
| 1563 | next += t; | ||
| 1564 | |||
| 1565 | } | ||
| 1566 | |||
| 1567 | /* Indexed Registers */ | ||
| 1568 | // none yet | ||
| 1569 | |||
| 1570 | /* Statistics */ | ||
| 1571 | t = scnprintf (next, size, "\nirqs: "); | ||
| 1572 | size -= t; | ||
| 1573 | next += t; | ||
| 1574 | for (i = 0; i < 7; i++) { | ||
| 1575 | struct net2280_ep *ep; | ||
| 1576 | |||
| 1577 | ep = &dev->ep [i]; | ||
| 1578 | if (i && !ep->irqs) | ||
| 1579 | continue; | ||
| 1580 | t = scnprintf (next, size, " %s/%lu", ep->ep.name, ep->irqs); | ||
| 1581 | size -= t; | ||
| 1582 | next += t; | ||
| 1583 | |||
| 1584 | } | ||
| 1585 | t = scnprintf (next, size, "\n"); | ||
| 1586 | size -= t; | ||
| 1587 | next += t; | ||
| 1588 | |||
| 1589 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1590 | |||
| 1591 | return PAGE_SIZE - size; | ||
| 1592 | } | ||
| 1593 | static DEVICE_ATTR_RO(registers); | ||
| 1594 | |||
| 1595 | static ssize_t queues_show(struct device *_dev, struct device_attribute *attr, | ||
| 1596 | char *buf) | ||
| 1597 | { | ||
| 1598 | struct net2280 *dev; | ||
| 1599 | char *next; | ||
| 1600 | unsigned size; | ||
| 1601 | unsigned long flags; | ||
| 1602 | int i; | ||
| 1603 | |||
| 1604 | dev = dev_get_drvdata (_dev); | ||
| 1605 | next = buf; | ||
| 1606 | size = PAGE_SIZE; | ||
| 1607 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1608 | |||
| 1609 | for (i = 0; i < 7; i++) { | ||
| 1610 | struct net2280_ep *ep = &dev->ep [i]; | ||
| 1611 | struct net2280_request *req; | ||
| 1612 | int t; | ||
| 1613 | |||
| 1614 | if (i != 0) { | ||
| 1615 | const struct usb_endpoint_descriptor *d; | ||
| 1616 | |||
| 1617 | d = ep->desc; | ||
| 1618 | if (!d) | ||
| 1619 | continue; | ||
| 1620 | t = d->bEndpointAddress; | ||
| 1621 | t = scnprintf (next, size, | ||
| 1622 | "\n%s (ep%d%s-%s) max %04x %s fifo %d\n", | ||
| 1623 | ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK, | ||
| 1624 | (t & USB_DIR_IN) ? "in" : "out", | ||
| 1625 | ({ char *val; | ||
| 1626 | switch (d->bmAttributes & 0x03) { | ||
| 1627 | case USB_ENDPOINT_XFER_BULK: | ||
| 1628 | val = "bulk"; break; | ||
| 1629 | case USB_ENDPOINT_XFER_INT: | ||
| 1630 | val = "intr"; break; | ||
| 1631 | default: | ||
| 1632 | val = "iso"; break; | ||
| 1633 | } val; }), | ||
| 1634 | usb_endpoint_maxp (d) & 0x1fff, | ||
| 1635 | ep->dma ? "dma" : "pio", ep->fifo_size | ||
| 1636 | ); | ||
| 1637 | } else /* ep0 should only have one transfer queued */ | ||
| 1638 | t = scnprintf (next, size, "ep0 max 64 pio %s\n", | ||
| 1639 | ep->is_in ? "in" : "out"); | ||
| 1640 | if (t <= 0 || t > size) | ||
| 1641 | goto done; | ||
| 1642 | size -= t; | ||
| 1643 | next += t; | ||
| 1644 | |||
| 1645 | if (list_empty (&ep->queue)) { | ||
| 1646 | t = scnprintf (next, size, "\t(nothing queued)\n"); | ||
| 1647 | if (t <= 0 || t > size) | ||
| 1648 | goto done; | ||
| 1649 | size -= t; | ||
| 1650 | next += t; | ||
| 1651 | continue; | ||
| 1652 | } | ||
| 1653 | list_for_each_entry (req, &ep->queue, queue) { | ||
| 1654 | if (ep->dma && req->td_dma == readl (&ep->dma->dmadesc)) | ||
| 1655 | t = scnprintf (next, size, | ||
| 1656 | "\treq %p len %d/%d " | ||
| 1657 | "buf %p (dmacount %08x)\n", | ||
| 1658 | &req->req, req->req.actual, | ||
| 1659 | req->req.length, req->req.buf, | ||
| 1660 | readl (&ep->dma->dmacount)); | ||
| 1661 | else | ||
| 1662 | t = scnprintf (next, size, | ||
| 1663 | "\treq %p len %d/%d buf %p\n", | ||
| 1664 | &req->req, req->req.actual, | ||
| 1665 | req->req.length, req->req.buf); | ||
| 1666 | if (t <= 0 || t > size) | ||
| 1667 | goto done; | ||
| 1668 | size -= t; | ||
| 1669 | next += t; | ||
| 1670 | |||
| 1671 | if (ep->dma) { | ||
| 1672 | struct net2280_dma *td; | ||
| 1673 | |||
| 1674 | td = req->td; | ||
| 1675 | t = scnprintf (next, size, "\t td %08x " | ||
| 1676 | " count %08x buf %08x desc %08x\n", | ||
| 1677 | (u32) req->td_dma, | ||
| 1678 | le32_to_cpu (td->dmacount), | ||
| 1679 | le32_to_cpu (td->dmaaddr), | ||
| 1680 | le32_to_cpu (td->dmadesc)); | ||
| 1681 | if (t <= 0 || t > size) | ||
| 1682 | goto done; | ||
| 1683 | size -= t; | ||
| 1684 | next += t; | ||
| 1685 | } | ||
| 1686 | } | ||
| 1687 | } | ||
| 1688 | |||
| 1689 | done: | ||
| 1690 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1691 | return PAGE_SIZE - size; | ||
| 1692 | } | ||
| 1693 | static DEVICE_ATTR_RO(queues); | ||
| 1694 | |||
| 1695 | |||
| 1696 | #else | ||
| 1697 | |||
| 1698 | #define device_create_file(a,b) (0) | ||
| 1699 | #define device_remove_file(a,b) do { } while (0) | ||
| 1700 | |||
| 1701 | #endif | ||
| 1702 | |||
| 1703 | /*-------------------------------------------------------------------------*/ | ||
| 1704 | |||
| 1705 | /* another driver-specific mode might be a request type doing dma | ||
| 1706 | * to/from another device fifo instead of to/from memory. | ||
| 1707 | */ | ||
| 1708 | |||
| 1709 | static void set_fifo_mode (struct net2280 *dev, int mode) | ||
| 1710 | { | ||
| 1711 | /* keeping high bits preserves BAR2 */ | ||
| 1712 | writel ((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl); | ||
| 1713 | |||
| 1714 | /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */ | ||
| 1715 | INIT_LIST_HEAD (&dev->gadget.ep_list); | ||
| 1716 | list_add_tail (&dev->ep [1].ep.ep_list, &dev->gadget.ep_list); | ||
| 1717 | list_add_tail (&dev->ep [2].ep.ep_list, &dev->gadget.ep_list); | ||
| 1718 | switch (mode) { | ||
| 1719 | case 0: | ||
| 1720 | list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list); | ||
| 1721 | list_add_tail (&dev->ep [4].ep.ep_list, &dev->gadget.ep_list); | ||
| 1722 | dev->ep [1].fifo_size = dev->ep [2].fifo_size = 1024; | ||
| 1723 | break; | ||
| 1724 | case 1: | ||
| 1725 | dev->ep [1].fifo_size = dev->ep [2].fifo_size = 2048; | ||
| 1726 | break; | ||
| 1727 | case 2: | ||
| 1728 | list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list); | ||
| 1729 | dev->ep [1].fifo_size = 2048; | ||
| 1730 | dev->ep [2].fifo_size = 1024; | ||
| 1731 | break; | ||
| 1732 | } | ||
| 1733 | /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */ | ||
| 1734 | list_add_tail (&dev->ep [5].ep.ep_list, &dev->gadget.ep_list); | ||
| 1735 | list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); | ||
| 1736 | } | ||
| 1737 | |||
| 1738 | /* keeping it simple: | ||
| 1739 | * - one bus driver, initted first; | ||
| 1740 | * - one function driver, initted second | ||
| 1741 | * | ||
| 1742 | * most of the work to support multiple net2280 controllers would | ||
| 1743 | * be to associate this gadget driver (yes?) with all of them, or | ||
| 1744 | * perhaps to bind specific drivers to specific devices. | ||
| 1745 | */ | ||
| 1746 | |||
| 1747 | static void usb_reset (struct net2280 *dev) | ||
| 1748 | { | ||
| 1749 | u32 tmp; | ||
| 1750 | |||
| 1751 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
| 1752 | (void) readl (&dev->usb->usbctl); | ||
| 1753 | |||
| 1754 | net2280_led_init (dev); | ||
| 1755 | |||
| 1756 | /* disable automatic responses, and irqs */ | ||
| 1757 | writel (0, &dev->usb->stdrsp); | ||
| 1758 | writel (0, &dev->regs->pciirqenb0); | ||
| 1759 | writel (0, &dev->regs->pciirqenb1); | ||
| 1760 | |||
| 1761 | /* clear old dma and irq state */ | ||
| 1762 | for (tmp = 0; tmp < 4; tmp++) { | ||
| 1763 | struct net2280_ep *ep = &dev->ep [tmp + 1]; | ||
| 1764 | |||
| 1765 | if (ep->dma) | ||
| 1766 | abort_dma (ep); | ||
| 1767 | } | ||
| 1768 | writel (~0, &dev->regs->irqstat0), | ||
| 1769 | writel (~(1 << SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1), | ||
| 1770 | |||
| 1771 | /* reset, and enable pci */ | ||
| 1772 | tmp = readl (&dev->regs->devinit) | ||
| 1773 | | (1 << PCI_ENABLE) | ||
| 1774 | | (1 << FIFO_SOFT_RESET) | ||
| 1775 | | (1 << USB_SOFT_RESET) | ||
| 1776 | | (1 << M8051_RESET); | ||
| 1777 | writel (tmp, &dev->regs->devinit); | ||
| 1778 | |||
| 1779 | /* standard fifo and endpoint allocations */ | ||
| 1780 | set_fifo_mode (dev, (fifo_mode <= 2) ? fifo_mode : 0); | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | static void usb_reinit (struct net2280 *dev) | ||
| 1784 | { | ||
| 1785 | u32 tmp; | ||
| 1786 | int init_dma; | ||
| 1787 | |||
| 1788 | /* use_dma changes are ignored till next device re-init */ | ||
| 1789 | init_dma = use_dma; | ||
| 1790 | |||
| 1791 | /* basic endpoint init */ | ||
| 1792 | for (tmp = 0; tmp < 7; tmp++) { | ||
| 1793 | struct net2280_ep *ep = &dev->ep [tmp]; | ||
| 1794 | |||
| 1795 | ep->ep.name = ep_name [tmp]; | ||
| 1796 | ep->dev = dev; | ||
| 1797 | ep->num = tmp; | ||
| 1798 | |||
| 1799 | if (tmp > 0 && tmp <= 4) { | ||
| 1800 | ep->fifo_size = 1024; | ||
| 1801 | if (init_dma) | ||
| 1802 | ep->dma = &dev->dma [tmp - 1]; | ||
| 1803 | } else | ||
| 1804 | ep->fifo_size = 64; | ||
| 1805 | ep->regs = &dev->epregs [tmp]; | ||
| 1806 | ep_reset (dev->regs, ep); | ||
| 1807 | } | ||
| 1808 | usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64); | ||
| 1809 | usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64); | ||
| 1810 | usb_ep_set_maxpacket_limit(&dev->ep [6].ep, 64); | ||
| 1811 | |||
| 1812 | dev->gadget.ep0 = &dev->ep [0].ep; | ||
| 1813 | dev->ep [0].stopped = 0; | ||
| 1814 | INIT_LIST_HEAD (&dev->gadget.ep0->ep_list); | ||
| 1815 | |||
| 1816 | /* we want to prevent lowlevel/insecure access from the USB host, | ||
| 1817 | * but erratum 0119 means this enable bit is ignored | ||
| 1818 | */ | ||
| 1819 | for (tmp = 0; tmp < 5; tmp++) | ||
| 1820 | writel (EP_DONTUSE, &dev->dep [tmp].dep_cfg); | ||
| 1821 | } | ||
| 1822 | |||
| 1823 | static void ep0_start (struct net2280 *dev) | ||
| 1824 | { | ||
| 1825 | writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE) | ||
| 1826 | | (1 << CLEAR_NAK_OUT_PACKETS) | ||
| 1827 | | (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) | ||
| 1828 | , &dev->epregs [0].ep_rsp); | ||
| 1829 | |||
| 1830 | /* | ||
| 1831 | * hardware optionally handles a bunch of standard requests | ||
| 1832 | * that the API hides from drivers anyway. have it do so. | ||
| 1833 | * endpoint status/features are handled in software, to | ||
| 1834 | * help pass tests for some dubious behavior. | ||
| 1835 | */ | ||
| 1836 | writel ( (1 << SET_TEST_MODE) | ||
| 1837 | | (1 << SET_ADDRESS) | ||
| 1838 | | (1 << DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP) | ||
| 1839 | | (1 << GET_DEVICE_STATUS) | ||
| 1840 | | (1 << GET_INTERFACE_STATUS) | ||
| 1841 | , &dev->usb->stdrsp); | ||
| 1842 | writel ( (1 << USB_ROOT_PORT_WAKEUP_ENABLE) | ||
| 1843 | | (1 << SELF_POWERED_USB_DEVICE) | ||
| 1844 | | (1 << REMOTE_WAKEUP_SUPPORT) | ||
| 1845 | | (dev->softconnect << USB_DETECT_ENABLE) | ||
| 1846 | | (1 << SELF_POWERED_STATUS) | ||
| 1847 | , &dev->usb->usbctl); | ||
| 1848 | |||
| 1849 | /* enable irqs so we can see ep0 and general operation */ | ||
| 1850 | writel ( (1 << SETUP_PACKET_INTERRUPT_ENABLE) | ||
| 1851 | | (1 << ENDPOINT_0_INTERRUPT_ENABLE) | ||
| 1852 | , &dev->regs->pciirqenb0); | ||
| 1853 | writel ( (1 << PCI_INTERRUPT_ENABLE) | ||
| 1854 | | (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE) | ||
| 1855 | | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE) | ||
| 1856 | | (1 << PCI_RETRY_ABORT_INTERRUPT_ENABLE) | ||
| 1857 | | (1 << VBUS_INTERRUPT_ENABLE) | ||
| 1858 | | (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE) | ||
| 1859 | | (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) | ||
| 1860 | , &dev->regs->pciirqenb1); | ||
| 1861 | |||
| 1862 | /* don't leave any writes posted */ | ||
| 1863 | (void) readl (&dev->usb->usbctl); | ||
| 1864 | } | ||
| 1865 | |||
| 1866 | /* when a driver is successfully registered, it will receive | ||
| 1867 | * control requests including set_configuration(), which enables | ||
| 1868 | * non-control requests. then usb traffic follows until a | ||
| 1869 | * disconnect is reported. then a host may connect again, or | ||
| 1870 | * the driver might get unbound. | ||
| 1871 | */ | ||
| 1872 | static int net2280_start(struct usb_gadget *_gadget, | ||
| 1873 | struct usb_gadget_driver *driver) | ||
| 1874 | { | ||
| 1875 | struct net2280 *dev; | ||
| 1876 | int retval; | ||
| 1877 | unsigned i; | ||
| 1878 | |||
| 1879 | /* insist on high speed support from the driver, since | ||
| 1880 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) | ||
| 1881 | * "must not be used in normal operation" | ||
| 1882 | */ | ||
| 1883 | if (!driver || driver->max_speed < USB_SPEED_HIGH | ||
| 1884 | || !driver->setup) | ||
| 1885 | return -EINVAL; | ||
| 1886 | |||
| 1887 | dev = container_of (_gadget, struct net2280, gadget); | ||
| 1888 | |||
| 1889 | for (i = 0; i < 7; i++) | ||
| 1890 | dev->ep [i].irqs = 0; | ||
| 1891 | |||
| 1892 | /* hook up the driver ... */ | ||
| 1893 | dev->softconnect = 1; | ||
| 1894 | driver->driver.bus = NULL; | ||
| 1895 | dev->driver = driver; | ||
| 1896 | |||
| 1897 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); | ||
| 1898 | if (retval) goto err_unbind; | ||
| 1899 | retval = device_create_file (&dev->pdev->dev, &dev_attr_queues); | ||
| 1900 | if (retval) goto err_func; | ||
| 1901 | |||
| 1902 | /* Enable force-full-speed testing mode, if desired */ | ||
| 1903 | if (full_speed) | ||
| 1904 | writel(1 << FORCE_FULL_SPEED_MODE, &dev->usb->xcvrdiag); | ||
| 1905 | |||
| 1906 | /* ... then enable host detection and ep0; and we're ready | ||
| 1907 | * for set_configuration as well as eventual disconnect. | ||
| 1908 | */ | ||
| 1909 | net2280_led_active (dev, 1); | ||
| 1910 | ep0_start (dev); | ||
| 1911 | |||
| 1912 | DEBUG (dev, "%s ready, usbctl %08x stdrsp %08x\n", | ||
| 1913 | driver->driver.name, | ||
| 1914 | readl (&dev->usb->usbctl), | ||
| 1915 | readl (&dev->usb->stdrsp)); | ||
| 1916 | |||
| 1917 | /* pci writes may still be posted */ | ||
| 1918 | return 0; | ||
| 1919 | |||
| 1920 | err_func: | ||
| 1921 | device_remove_file (&dev->pdev->dev, &dev_attr_function); | ||
| 1922 | err_unbind: | ||
| 1923 | dev->driver = NULL; | ||
| 1924 | return retval; | ||
| 1925 | } | ||
| 1926 | |||
| 1927 | static void | ||
| 1928 | stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) | ||
| 1929 | { | ||
| 1930 | int i; | ||
| 1931 | |||
| 1932 | /* don't disconnect if it's not connected */ | ||
| 1933 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1934 | driver = NULL; | ||
| 1935 | |||
| 1936 | /* stop hardware; prevent new request submissions; | ||
| 1937 | * and kill any outstanding requests. | ||
| 1938 | */ | ||
| 1939 | usb_reset (dev); | ||
| 1940 | for (i = 0; i < 7; i++) | ||
| 1941 | nuke (&dev->ep [i]); | ||
| 1942 | |||
| 1943 | /* report disconnect; the driver is already quiesced */ | ||
| 1944 | if (driver) { | ||
| 1945 | spin_unlock(&dev->lock); | ||
| 1946 | driver->disconnect(&dev->gadget); | ||
| 1947 | spin_lock(&dev->lock); | ||
| 1948 | } | ||
| 1949 | |||
| 1950 | usb_reinit (dev); | ||
| 1951 | } | ||
| 1952 | |||
| 1953 | static int net2280_stop(struct usb_gadget *_gadget, | ||
| 1954 | struct usb_gadget_driver *driver) | ||
| 1955 | { | ||
| 1956 | struct net2280 *dev; | ||
| 1957 | unsigned long flags; | ||
| 1958 | |||
| 1959 | dev = container_of (_gadget, struct net2280, gadget); | ||
| 1960 | |||
| 1961 | spin_lock_irqsave (&dev->lock, flags); | ||
| 1962 | stop_activity (dev, driver); | ||
| 1963 | spin_unlock_irqrestore (&dev->lock, flags); | ||
| 1964 | |||
| 1965 | dev->driver = NULL; | ||
| 1966 | |||
| 1967 | net2280_led_active (dev, 0); | ||
| 1968 | |||
| 1969 | /* Disable full-speed test mode */ | ||
| 1970 | writel(0, &dev->usb->xcvrdiag); | ||
| 1971 | |||
| 1972 | device_remove_file (&dev->pdev->dev, &dev_attr_function); | ||
| 1973 | device_remove_file (&dev->pdev->dev, &dev_attr_queues); | ||
| 1974 | |||
| 1975 | DEBUG(dev, "unregistered driver '%s'\n", | ||
| 1976 | driver ? driver->driver.name : ""); | ||
| 1977 | |||
| 1978 | return 0; | ||
| 1979 | } | ||
| 1980 | |||
| 1981 | /*-------------------------------------------------------------------------*/ | ||
| 1982 | |||
| 1983 | /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq. | ||
| 1984 | * also works for dma-capable endpoints, in pio mode or just | ||
| 1985 | * to manually advance the queue after short OUT transfers. | ||
| 1986 | */ | ||
| 1987 | static void handle_ep_small (struct net2280_ep *ep) | ||
| 1988 | { | ||
| 1989 | struct net2280_request *req; | ||
| 1990 | u32 t; | ||
| 1991 | /* 0 error, 1 mid-data, 2 done */ | ||
| 1992 | int mode = 1; | ||
| 1993 | |||
| 1994 | if (!list_empty (&ep->queue)) | ||
| 1995 | req = list_entry (ep->queue.next, | ||
| 1996 | struct net2280_request, queue); | ||
| 1997 | else | ||
| 1998 | req = NULL; | ||
| 1999 | |||
| 2000 | /* ack all, and handle what we care about */ | ||
| 2001 | t = readl (&ep->regs->ep_stat); | ||
| 2002 | ep->irqs++; | ||
| 2003 | #if 0 | ||
| 2004 | VDEBUG (ep->dev, "%s ack ep_stat %08x, req %p\n", | ||
| 2005 | ep->ep.name, t, req ? &req->req : 0); | ||
| 2006 | #endif | ||
| 2007 | if (!ep->is_in || ep->dev->pdev->device == 0x2280) | ||
| 2008 | writel (t & ~(1 << NAK_OUT_PACKETS), &ep->regs->ep_stat); | ||
| 2009 | else | ||
| 2010 | /* Added for 2282 */ | ||
| 2011 | writel (t, &ep->regs->ep_stat); | ||
| 2012 | |||
| 2013 | /* for ep0, monitor token irqs to catch data stage length errors | ||
| 2014 | * and to synchronize on status. | ||
| 2015 | * | ||
| 2016 | * also, to defer reporting of protocol stalls ... here's where | ||
| 2017 | * data or status first appears, handling stalls here should never | ||
| 2018 | * cause trouble on the host side.. | ||
| 2019 | * | ||
| 2020 | * control requests could be slightly faster without token synch for | ||
| 2021 | * status, but status can jam up that way. | ||
| 2022 | */ | ||
| 2023 | if (unlikely (ep->num == 0)) { | ||
| 2024 | if (ep->is_in) { | ||
| 2025 | /* status; stop NAKing */ | ||
| 2026 | if (t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) { | ||
| 2027 | if (ep->dev->protocol_stall) { | ||
| 2028 | ep->stopped = 1; | ||
| 2029 | set_halt (ep); | ||
| 2030 | } | ||
| 2031 | if (!req) | ||
| 2032 | allow_status (ep); | ||
| 2033 | mode = 2; | ||
| 2034 | /* reply to extra IN data tokens with a zlp */ | ||
| 2035 | } else if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) { | ||
| 2036 | if (ep->dev->protocol_stall) { | ||
| 2037 | ep->stopped = 1; | ||
| 2038 | set_halt (ep); | ||
| 2039 | mode = 2; | ||
| 2040 | } else if (ep->responded && | ||
| 2041 | !req && !ep->stopped) | ||
| 2042 | write_fifo (ep, NULL); | ||
| 2043 | } | ||
| 2044 | } else { | ||
| 2045 | /* status; stop NAKing */ | ||
| 2046 | if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) { | ||
| 2047 | if (ep->dev->protocol_stall) { | ||
| 2048 | ep->stopped = 1; | ||
| 2049 | set_halt (ep); | ||
| 2050 | } | ||
| 2051 | mode = 2; | ||
| 2052 | /* an extra OUT token is an error */ | ||
| 2053 | } else if (((t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) | ||
| 2054 | && req | ||
| 2055 | && req->req.actual == req->req.length) | ||
| 2056 | || (ep->responded && !req)) { | ||
| 2057 | ep->dev->protocol_stall = 1; | ||
| 2058 | set_halt (ep); | ||
| 2059 | ep->stopped = 1; | ||
| 2060 | if (req) | ||
| 2061 | done (ep, req, -EOVERFLOW); | ||
| 2062 | req = NULL; | ||
| 2063 | } | ||
| 2064 | } | ||
| 2065 | } | ||
| 2066 | |||
| 2067 | if (unlikely (!req)) | ||
| 2068 | return; | ||
| 2069 | |||
| 2070 | /* manual DMA queue advance after short OUT */ | ||
| 2071 | if (likely (ep->dma)) { | ||
| 2072 | if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) { | ||
| 2073 | u32 count; | ||
| 2074 | int stopped = ep->stopped; | ||
| 2075 | |||
| 2076 | /* TRANSFERRED works around OUT_DONE erratum 0112. | ||
| 2077 | * we expect (N <= maxpacket) bytes; host wrote M. | ||
| 2078 | * iff (M < N) we won't ever see a DMA interrupt. | ||
| 2079 | */ | ||
| 2080 | ep->stopped = 1; | ||
| 2081 | for (count = 0; ; t = readl (&ep->regs->ep_stat)) { | ||
| 2082 | |||
| 2083 | /* any preceding dma transfers must finish. | ||
| 2084 | * dma handles (M >= N), may empty the queue | ||
| 2085 | */ | ||
| 2086 | scan_dma_completions (ep); | ||
| 2087 | if (unlikely (list_empty (&ep->queue) | ||
| 2088 | || ep->out_overflow)) { | ||
| 2089 | req = NULL; | ||
| 2090 | break; | ||
| 2091 | } | ||
| 2092 | req = list_entry (ep->queue.next, | ||
| 2093 | struct net2280_request, queue); | ||
| 2094 | |||
| 2095 | /* here either (M < N), a "real" short rx; | ||
| 2096 | * or (M == N) and the queue didn't empty | ||
| 2097 | */ | ||
| 2098 | if (likely (t & (1 << FIFO_EMPTY))) { | ||
| 2099 | count = readl (&ep->dma->dmacount); | ||
| 2100 | count &= DMA_BYTE_COUNT_MASK; | ||
| 2101 | if (readl (&ep->dma->dmadesc) | ||
| 2102 | != req->td_dma) | ||
| 2103 | req = NULL; | ||
| 2104 | break; | ||
| 2105 | } | ||
| 2106 | udelay(1); | ||
| 2107 | } | ||
| 2108 | |||
| 2109 | /* stop DMA, leave ep NAKing */ | ||
| 2110 | writel ((1 << DMA_ABORT), &ep->dma->dmastat); | ||
| 2111 | spin_stop_dma (ep->dma); | ||
| 2112 | |||
| 2113 | if (likely (req)) { | ||
| 2114 | req->td->dmacount = 0; | ||
| 2115 | t = readl (&ep->regs->ep_avail); | ||
| 2116 | dma_done (ep, req, count, | ||
| 2117 | (ep->out_overflow || t) | ||
| 2118 | ? -EOVERFLOW : 0); | ||
| 2119 | } | ||
| 2120 | |||
| 2121 | /* also flush to prevent erratum 0106 trouble */ | ||
| 2122 | if (unlikely (ep->out_overflow | ||
| 2123 | || (ep->dev->chiprev == 0x0100 | ||
| 2124 | && ep->dev->gadget.speed | ||
| 2125 | == USB_SPEED_FULL))) { | ||
| 2126 | out_flush (ep); | ||
| 2127 | ep->out_overflow = 0; | ||
| 2128 | } | ||
| 2129 | |||
| 2130 | /* (re)start dma if needed, stop NAKing */ | ||
| 2131 | ep->stopped = stopped; | ||
| 2132 | if (!list_empty (&ep->queue)) | ||
| 2133 | restart_dma (ep); | ||
| 2134 | } else | ||
| 2135 | DEBUG (ep->dev, "%s dma ep_stat %08x ??\n", | ||
| 2136 | ep->ep.name, t); | ||
| 2137 | return; | ||
| 2138 | |||
| 2139 | /* data packet(s) received (in the fifo, OUT) */ | ||
| 2140 | } else if (t & (1 << DATA_PACKET_RECEIVED_INTERRUPT)) { | ||
| 2141 | if (read_fifo (ep, req) && ep->num != 0) | ||
| 2142 | mode = 2; | ||
| 2143 | |||
| 2144 | /* data packet(s) transmitted (IN) */ | ||
| 2145 | } else if (t & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)) { | ||
| 2146 | unsigned len; | ||
| 2147 | |||
| 2148 | len = req->req.length - req->req.actual; | ||
| 2149 | if (len > ep->ep.maxpacket) | ||
| 2150 | len = ep->ep.maxpacket; | ||
| 2151 | req->req.actual += len; | ||
| 2152 | |||
| 2153 | /* if we wrote it all, we're usually done */ | ||
| 2154 | if (req->req.actual == req->req.length) { | ||
| 2155 | if (ep->num == 0) { | ||
| 2156 | /* send zlps until the status stage */ | ||
| 2157 | } else if (!req->req.zero || len != ep->ep.maxpacket) | ||
| 2158 | mode = 2; | ||
| 2159 | } | ||
| 2160 | |||
| 2161 | /* there was nothing to do ... */ | ||
| 2162 | } else if (mode == 1) | ||
| 2163 | return; | ||
| 2164 | |||
| 2165 | /* done */ | ||
| 2166 | if (mode == 2) { | ||
| 2167 | /* stream endpoints often resubmit/unlink in completion */ | ||
| 2168 | done (ep, req, 0); | ||
| 2169 | |||
| 2170 | /* maybe advance queue to next request */ | ||
| 2171 | if (ep->num == 0) { | ||
| 2172 | /* NOTE: net2280 could let gadget driver start the | ||
| 2173 | * status stage later. since not all controllers let | ||
| 2174 | * them control that, the api doesn't (yet) allow it. | ||
| 2175 | */ | ||
| 2176 | if (!ep->stopped) | ||
| 2177 | allow_status (ep); | ||
| 2178 | req = NULL; | ||
| 2179 | } else { | ||
| 2180 | if (!list_empty (&ep->queue) && !ep->stopped) | ||
| 2181 | req = list_entry (ep->queue.next, | ||
| 2182 | struct net2280_request, queue); | ||
| 2183 | else | ||
| 2184 | req = NULL; | ||
| 2185 | if (req && !ep->is_in) | ||
| 2186 | stop_out_naking (ep); | ||
| 2187 | } | ||
| 2188 | } | ||
| 2189 | |||
| 2190 | /* is there a buffer for the next packet? | ||
| 2191 | * for best streaming performance, make sure there is one. | ||
| 2192 | */ | ||
| 2193 | if (req && !ep->stopped) { | ||
| 2194 | |||
| 2195 | /* load IN fifo with next packet (may be zlp) */ | ||
| 2196 | if (t & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)) | ||
| 2197 | write_fifo (ep, &req->req); | ||
| 2198 | } | ||
| 2199 | } | ||
| 2200 | |||
| 2201 | static struct net2280_ep * | ||
| 2202 | get_ep_by_addr (struct net2280 *dev, u16 wIndex) | ||
| 2203 | { | ||
| 2204 | struct net2280_ep *ep; | ||
| 2205 | |||
| 2206 | if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) | ||
| 2207 | return &dev->ep [0]; | ||
| 2208 | list_for_each_entry (ep, &dev->gadget.ep_list, ep.ep_list) { | ||
| 2209 | u8 bEndpointAddress; | ||
| 2210 | |||
| 2211 | if (!ep->desc) | ||
| 2212 | continue; | ||
| 2213 | bEndpointAddress = ep->desc->bEndpointAddress; | ||
| 2214 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) | ||
| 2215 | continue; | ||
| 2216 | if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f)) | ||
| 2217 | return ep; | ||
| 2218 | } | ||
| 2219 | return NULL; | ||
| 2220 | } | ||
| 2221 | |||
| 2222 | static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | ||
| 2223 | { | ||
| 2224 | struct net2280_ep *ep; | ||
| 2225 | u32 num, scratch; | ||
| 2226 | |||
| 2227 | /* most of these don't need individual acks */ | ||
| 2228 | stat &= ~(1 << INTA_ASSERTED); | ||
| 2229 | if (!stat) | ||
| 2230 | return; | ||
| 2231 | // DEBUG (dev, "irqstat0 %04x\n", stat); | ||
| 2232 | |||
| 2233 | /* starting a control request? */ | ||
| 2234 | if (unlikely (stat & (1 << SETUP_PACKET_INTERRUPT))) { | ||
| 2235 | union { | ||
| 2236 | u32 raw [2]; | ||
| 2237 | struct usb_ctrlrequest r; | ||
| 2238 | } u; | ||
| 2239 | int tmp; | ||
| 2240 | struct net2280_request *req; | ||
| 2241 | |||
| 2242 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) { | ||
| 2243 | if (readl (&dev->usb->usbstat) & (1 << HIGH_SPEED)) | ||
| 2244 | dev->gadget.speed = USB_SPEED_HIGH; | ||
| 2245 | else | ||
| 2246 | dev->gadget.speed = USB_SPEED_FULL; | ||
| 2247 | net2280_led_speed (dev, dev->gadget.speed); | ||
| 2248 | DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed)); | ||
| 2249 | } | ||
| 2250 | |||
| 2251 | ep = &dev->ep [0]; | ||
| 2252 | ep->irqs++; | ||
| 2253 | |||
| 2254 | /* make sure any leftover request state is cleared */ | ||
| 2255 | stat &= ~(1 << ENDPOINT_0_INTERRUPT); | ||
| 2256 | while (!list_empty (&ep->queue)) { | ||
| 2257 | req = list_entry (ep->queue.next, | ||
| 2258 | struct net2280_request, queue); | ||
| 2259 | done (ep, req, (req->req.actual == req->req.length) | ||
| 2260 | ? 0 : -EPROTO); | ||
| 2261 | } | ||
| 2262 | ep->stopped = 0; | ||
| 2263 | dev->protocol_stall = 0; | ||
| 2264 | |||
| 2265 | if (ep->dev->pdev->device == 0x2280) | ||
| 2266 | tmp = (1 << FIFO_OVERFLOW) | ||
| 2267 | | (1 << FIFO_UNDERFLOW); | ||
| 2268 | else | ||
| 2269 | tmp = 0; | ||
| 2270 | |||
| 2271 | writel (tmp | (1 << TIMEOUT) | ||
| 2272 | | (1 << USB_STALL_SENT) | ||
| 2273 | | (1 << USB_IN_NAK_SENT) | ||
| 2274 | | (1 << USB_IN_ACK_RCVD) | ||
| 2275 | | (1 << USB_OUT_PING_NAK_SENT) | ||
| 2276 | | (1 << USB_OUT_ACK_SENT) | ||
| 2277 | | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT) | ||
| 2278 | | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) | ||
| 2279 | | (1 << DATA_PACKET_RECEIVED_INTERRUPT) | ||
| 2280 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) | ||
| 2281 | | (1 << DATA_OUT_PING_TOKEN_INTERRUPT) | ||
| 2282 | | (1 << DATA_IN_TOKEN_INTERRUPT) | ||
| 2283 | , &ep->regs->ep_stat); | ||
| 2284 | u.raw [0] = readl (&dev->usb->setup0123); | ||
| 2285 | u.raw [1] = readl (&dev->usb->setup4567); | ||
| 2286 | |||
| 2287 | cpu_to_le32s (&u.raw [0]); | ||
| 2288 | cpu_to_le32s (&u.raw [1]); | ||
| 2289 | |||
| 2290 | tmp = 0; | ||
| 2291 | |||
| 2292 | #define w_value le16_to_cpu(u.r.wValue) | ||
| 2293 | #define w_index le16_to_cpu(u.r.wIndex) | ||
| 2294 | #define w_length le16_to_cpu(u.r.wLength) | ||
| 2295 | |||
| 2296 | /* ack the irq */ | ||
| 2297 | writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0); | ||
| 2298 | stat ^= (1 << SETUP_PACKET_INTERRUPT); | ||
| 2299 | |||
| 2300 | /* watch control traffic at the token level, and force | ||
| 2301 | * synchronization before letting the status stage happen. | ||
| 2302 | * FIXME ignore tokens we'll NAK, until driver responds. | ||
| 2303 | * that'll mean a lot less irqs for some drivers. | ||
| 2304 | */ | ||
| 2305 | ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0; | ||
| 2306 | if (ep->is_in) { | ||
| 2307 | scratch = (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) | ||
| 2308 | | (1 << DATA_OUT_PING_TOKEN_INTERRUPT) | ||
| 2309 | | (1 << DATA_IN_TOKEN_INTERRUPT); | ||
| 2310 | stop_out_naking (ep); | ||
| 2311 | } else | ||
| 2312 | scratch = (1 << DATA_PACKET_RECEIVED_INTERRUPT) | ||
| 2313 | | (1 << DATA_OUT_PING_TOKEN_INTERRUPT) | ||
| 2314 | | (1 << DATA_IN_TOKEN_INTERRUPT); | ||
| 2315 | writel (scratch, &dev->epregs [0].ep_irqenb); | ||
| 2316 | |||
| 2317 | /* we made the hardware handle most lowlevel requests; | ||
| 2318 | * everything else goes uplevel to the gadget code. | ||
| 2319 | */ | ||
| 2320 | ep->responded = 1; | ||
| 2321 | switch (u.r.bRequest) { | ||
| 2322 | case USB_REQ_GET_STATUS: { | ||
| 2323 | struct net2280_ep *e; | ||
| 2324 | __le32 status; | ||
| 2325 | |||
| 2326 | /* hw handles device and interface status */ | ||
| 2327 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) | ||
| 2328 | goto delegate; | ||
| 2329 | if ((e = get_ep_by_addr (dev, w_index)) == NULL | ||
| 2330 | || w_length > 2) | ||
| 2331 | goto do_stall; | ||
| 2332 | |||
| 2333 | if (readl (&e->regs->ep_rsp) | ||
| 2334 | & (1 << SET_ENDPOINT_HALT)) | ||
| 2335 | status = cpu_to_le32 (1); | ||
| 2336 | else | ||
| 2337 | status = cpu_to_le32 (0); | ||
| 2338 | |||
| 2339 | /* don't bother with a request object! */ | ||
| 2340 | writel (0, &dev->epregs [0].ep_irqenb); | ||
| 2341 | set_fifo_bytecount (ep, w_length); | ||
| 2342 | writel ((__force u32)status, &dev->epregs [0].ep_data); | ||
| 2343 | allow_status (ep); | ||
| 2344 | VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status); | ||
| 2345 | goto next_endpoints; | ||
| 2346 | } | ||
| 2347 | break; | ||
| 2348 | case USB_REQ_CLEAR_FEATURE: { | ||
| 2349 | struct net2280_ep *e; | ||
| 2350 | |||
| 2351 | /* hw handles device features */ | ||
| 2352 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) | ||
| 2353 | goto delegate; | ||
| 2354 | if (w_value != USB_ENDPOINT_HALT | ||
| 2355 | || w_length != 0) | ||
| 2356 | goto do_stall; | ||
| 2357 | if ((e = get_ep_by_addr (dev, w_index)) == NULL) | ||
| 2358 | goto do_stall; | ||
| 2359 | if (e->wedged) { | ||
| 2360 | VDEBUG(dev, "%s wedged, halt not cleared\n", | ||
| 2361 | ep->ep.name); | ||
| 2362 | } else { | ||
| 2363 | VDEBUG(dev, "%s clear halt\n", ep->ep.name); | ||
| 2364 | clear_halt(e); | ||
| 2365 | } | ||
| 2366 | allow_status (ep); | ||
| 2367 | goto next_endpoints; | ||
| 2368 | } | ||
| 2369 | break; | ||
| 2370 | case USB_REQ_SET_FEATURE: { | ||
| 2371 | struct net2280_ep *e; | ||
| 2372 | |||
| 2373 | /* hw handles device features */ | ||
| 2374 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) | ||
| 2375 | goto delegate; | ||
| 2376 | if (w_value != USB_ENDPOINT_HALT | ||
| 2377 | || w_length != 0) | ||
| 2378 | goto do_stall; | ||
| 2379 | if ((e = get_ep_by_addr (dev, w_index)) == NULL) | ||
| 2380 | goto do_stall; | ||
| 2381 | if (e->ep.name == ep0name) | ||
| 2382 | goto do_stall; | ||
| 2383 | set_halt (e); | ||
| 2384 | allow_status (ep); | ||
| 2385 | VDEBUG (dev, "%s set halt\n", ep->ep.name); | ||
| 2386 | goto next_endpoints; | ||
| 2387 | } | ||
| 2388 | break; | ||
| 2389 | default: | ||
| 2390 | delegate: | ||
| 2391 | VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x " | ||
| 2392 | "ep_cfg %08x\n", | ||
| 2393 | u.r.bRequestType, u.r.bRequest, | ||
| 2394 | w_value, w_index, w_length, | ||
| 2395 | readl (&ep->regs->ep_cfg)); | ||
| 2396 | ep->responded = 0; | ||
| 2397 | spin_unlock (&dev->lock); | ||
| 2398 | tmp = dev->driver->setup (&dev->gadget, &u.r); | ||
| 2399 | spin_lock (&dev->lock); | ||
| 2400 | } | ||
| 2401 | |||
| 2402 | /* stall ep0 on error */ | ||
| 2403 | if (tmp < 0) { | ||
| 2404 | do_stall: | ||
| 2405 | VDEBUG (dev, "req %02x.%02x protocol STALL; stat %d\n", | ||
| 2406 | u.r.bRequestType, u.r.bRequest, tmp); | ||
| 2407 | dev->protocol_stall = 1; | ||
| 2408 | } | ||
| 2409 | |||
| 2410 | /* some in/out token irq should follow; maybe stall then. | ||
| 2411 | * driver must queue a request (even zlp) or halt ep0 | ||
| 2412 | * before the host times out. | ||
| 2413 | */ | ||
| 2414 | } | ||
| 2415 | |||
| 2416 | #undef w_value | ||
| 2417 | #undef w_index | ||
| 2418 | #undef w_length | ||
| 2419 | |||
| 2420 | next_endpoints: | ||
| 2421 | /* endpoint data irq ? */ | ||
| 2422 | scratch = stat & 0x7f; | ||
| 2423 | stat &= ~0x7f; | ||
| 2424 | for (num = 0; scratch; num++) { | ||
| 2425 | u32 t; | ||
| 2426 | |||
| 2427 | /* do this endpoint's FIFO and queue need tending? */ | ||
| 2428 | t = 1 << num; | ||
| 2429 | if ((scratch & t) == 0) | ||
| 2430 | continue; | ||
| 2431 | scratch ^= t; | ||
| 2432 | |||
| 2433 | ep = &dev->ep [num]; | ||
| 2434 | handle_ep_small (ep); | ||
| 2435 | } | ||
| 2436 | |||
| 2437 | if (stat) | ||
| 2438 | DEBUG (dev, "unhandled irqstat0 %08x\n", stat); | ||
| 2439 | } | ||
| 2440 | |||
| 2441 | #define DMA_INTERRUPTS ( \ | ||
| 2442 | (1 << DMA_D_INTERRUPT) \ | ||
| 2443 | | (1 << DMA_C_INTERRUPT) \ | ||
| 2444 | | (1 << DMA_B_INTERRUPT) \ | ||
| 2445 | | (1 << DMA_A_INTERRUPT)) | ||
| 2446 | #define PCI_ERROR_INTERRUPTS ( \ | ||
| 2447 | (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT) \ | ||
| 2448 | | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT) \ | ||
| 2449 | | (1 << PCI_RETRY_ABORT_INTERRUPT)) | ||
| 2450 | |||
| 2451 | static void handle_stat1_irqs (struct net2280 *dev, u32 stat) | ||
| 2452 | { | ||
| 2453 | struct net2280_ep *ep; | ||
| 2454 | u32 tmp, num, mask, scratch; | ||
| 2455 | |||
| 2456 | /* after disconnect there's nothing else to do! */ | ||
| 2457 | tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT); | ||
| 2458 | mask = (1 << HIGH_SPEED) | (1 << FULL_SPEED); | ||
| 2459 | |||
| 2460 | /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set. | ||
| 2461 | * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and | ||
| 2462 | * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT | ||
| 2463 | * only indicates a change in the reset state). | ||
| 2464 | */ | ||
| 2465 | if (stat & tmp) { | ||
| 2466 | writel (tmp, &dev->regs->irqstat1); | ||
| 2467 | if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) | ||
| 2468 | && ((readl (&dev->usb->usbstat) & mask) | ||
| 2469 | == 0)) | ||
| 2470 | || ((readl (&dev->usb->usbctl) | ||
| 2471 | & (1 << VBUS_PIN)) == 0) | ||
| 2472 | ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) { | ||
| 2473 | DEBUG (dev, "disconnect %s\n", | ||
| 2474 | dev->driver->driver.name); | ||
| 2475 | stop_activity (dev, dev->driver); | ||
| 2476 | ep0_start (dev); | ||
| 2477 | return; | ||
| 2478 | } | ||
| 2479 | stat &= ~tmp; | ||
| 2480 | |||
| 2481 | /* vBUS can bounce ... one of many reasons to ignore the | ||
| 2482 | * notion of hotplug events on bus connect/disconnect! | ||
| 2483 | */ | ||
| 2484 | if (!stat) | ||
| 2485 | return; | ||
| 2486 | } | ||
| 2487 | |||
| 2488 | /* NOTE: chip stays in PCI D0 state for now, but it could | ||
| 2489 | * enter D1 to save more power | ||
| 2490 | */ | ||
| 2491 | tmp = (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT); | ||
| 2492 | if (stat & tmp) { | ||
| 2493 | writel (tmp, &dev->regs->irqstat1); | ||
| 2494 | if (stat & (1 << SUSPEND_REQUEST_INTERRUPT)) { | ||
| 2495 | if (dev->driver->suspend) | ||
| 2496 | dev->driver->suspend (&dev->gadget); | ||
| 2497 | if (!enable_suspend) | ||
| 2498 | stat &= ~(1 << SUSPEND_REQUEST_INTERRUPT); | ||
| 2499 | } else { | ||
| 2500 | if (dev->driver->resume) | ||
| 2501 | dev->driver->resume (&dev->gadget); | ||
| 2502 | /* at high speed, note erratum 0133 */ | ||
| 2503 | } | ||
| 2504 | stat &= ~tmp; | ||
| 2505 | } | ||
| 2506 | |||
| 2507 | /* clear any other status/irqs */ | ||
| 2508 | if (stat) | ||
| 2509 | writel (stat, &dev->regs->irqstat1); | ||
| 2510 | |||
| 2511 | /* some status we can just ignore */ | ||
| 2512 | if (dev->pdev->device == 0x2280) | ||
| 2513 | stat &= ~((1 << CONTROL_STATUS_INTERRUPT) | ||
| 2514 | | (1 << SUSPEND_REQUEST_INTERRUPT) | ||
| 2515 | | (1 << RESUME_INTERRUPT) | ||
| 2516 | | (1 << SOF_INTERRUPT)); | ||
| 2517 | else | ||
| 2518 | stat &= ~((1 << CONTROL_STATUS_INTERRUPT) | ||
| 2519 | | (1 << RESUME_INTERRUPT) | ||
| 2520 | | (1 << SOF_DOWN_INTERRUPT) | ||
| 2521 | | (1 << SOF_INTERRUPT)); | ||
| 2522 | |||
| 2523 | if (!stat) | ||
| 2524 | return; | ||
| 2525 | // DEBUG (dev, "irqstat1 %08x\n", stat); | ||
| 2526 | |||
| 2527 | /* DMA status, for ep-{a,b,c,d} */ | ||
| 2528 | scratch = stat & DMA_INTERRUPTS; | ||
| 2529 | stat &= ~DMA_INTERRUPTS; | ||
| 2530 | scratch >>= 9; | ||
| 2531 | for (num = 0; scratch; num++) { | ||
| 2532 | struct net2280_dma_regs __iomem *dma; | ||
| 2533 | |||
| 2534 | tmp = 1 << num; | ||
| 2535 | if ((tmp & scratch) == 0) | ||
| 2536 | continue; | ||
| 2537 | scratch ^= tmp; | ||
| 2538 | |||
| 2539 | ep = &dev->ep [num + 1]; | ||
| 2540 | dma = ep->dma; | ||
| 2541 | |||
| 2542 | if (!dma) | ||
| 2543 | continue; | ||
| 2544 | |||
| 2545 | /* clear ep's dma status */ | ||
| 2546 | tmp = readl (&dma->dmastat); | ||
| 2547 | writel (tmp, &dma->dmastat); | ||
| 2548 | |||
| 2549 | /* chaining should stop on abort, short OUT from fifo, | ||
| 2550 | * or (stat0 codepath) short OUT transfer. | ||
| 2551 | */ | ||
| 2552 | if (!use_dma_chaining) { | ||
| 2553 | if ((tmp & (1 << DMA_TRANSACTION_DONE_INTERRUPT)) | ||
| 2554 | == 0) { | ||
| 2555 | DEBUG (ep->dev, "%s no xact done? %08x\n", | ||
| 2556 | ep->ep.name, tmp); | ||
| 2557 | continue; | ||
| 2558 | } | ||
| 2559 | stop_dma (ep->dma); | ||
| 2560 | } | ||
| 2561 | |||
| 2562 | /* OUT transfers terminate when the data from the | ||
| 2563 | * host is in our memory. Process whatever's done. | ||
| 2564 | * On this path, we know transfer's last packet wasn't | ||
| 2565 | * less than req->length. NAK_OUT_PACKETS may be set, | ||
| 2566 | * or the FIFO may already be holding new packets. | ||
| 2567 | * | ||
| 2568 | * IN transfers can linger in the FIFO for a very | ||
| 2569 | * long time ... we ignore that for now, accounting | ||
| 2570 | * precisely (like PIO does) needs per-packet irqs | ||
| 2571 | */ | ||
| 2572 | scan_dma_completions (ep); | ||
| 2573 | |||
| 2574 | /* disable dma on inactive queues; else maybe restart */ | ||
| 2575 | if (list_empty (&ep->queue)) { | ||
| 2576 | if (use_dma_chaining) | ||
| 2577 | stop_dma (ep->dma); | ||
| 2578 | } else { | ||
| 2579 | tmp = readl (&dma->dmactl); | ||
| 2580 | if (!use_dma_chaining | ||
| 2581 | || (tmp & (1 << DMA_ENABLE)) == 0) | ||
| 2582 | restart_dma (ep); | ||
| 2583 | else if (ep->is_in && use_dma_chaining) { | ||
| 2584 | struct net2280_request *req; | ||
| 2585 | __le32 dmacount; | ||
| 2586 | |||
| 2587 | /* the descriptor at the head of the chain | ||
| 2588 | * may still have VALID_BIT clear; that's | ||
| 2589 | * used to trigger changing DMA_FIFO_VALIDATE | ||
| 2590 | * (affects automagic zlp writes). | ||
| 2591 | */ | ||
| 2592 | req = list_entry (ep->queue.next, | ||
| 2593 | struct net2280_request, queue); | ||
| 2594 | dmacount = req->td->dmacount; | ||
| 2595 | dmacount &= cpu_to_le32 ( | ||
| 2596 | (1 << VALID_BIT) | ||
| 2597 | | DMA_BYTE_COUNT_MASK); | ||
| 2598 | if (dmacount && (dmacount & valid_bit) == 0) | ||
| 2599 | restart_dma (ep); | ||
| 2600 | } | ||
| 2601 | } | ||
| 2602 | ep->irqs++; | ||
| 2603 | } | ||
| 2604 | |||
| 2605 | /* NOTE: there are other PCI errors we might usefully notice. | ||
| 2606 | * if they appear very often, here's where to try recovering. | ||
| 2607 | */ | ||
| 2608 | if (stat & PCI_ERROR_INTERRUPTS) { | ||
| 2609 | ERROR (dev, "pci dma error; stat %08x\n", stat); | ||
| 2610 | stat &= ~PCI_ERROR_INTERRUPTS; | ||
| 2611 | /* these are fatal errors, but "maybe" they won't | ||
| 2612 | * happen again ... | ||
| 2613 | */ | ||
| 2614 | stop_activity (dev, dev->driver); | ||
| 2615 | ep0_start (dev); | ||
| 2616 | stat = 0; | ||
| 2617 | } | ||
| 2618 | |||
| 2619 | if (stat) | ||
| 2620 | DEBUG (dev, "unhandled irqstat1 %08x\n", stat); | ||
| 2621 | } | ||
| 2622 | |||
| 2623 | static irqreturn_t net2280_irq (int irq, void *_dev) | ||
| 2624 | { | ||
| 2625 | struct net2280 *dev = _dev; | ||
| 2626 | |||
| 2627 | /* shared interrupt, not ours */ | ||
| 2628 | if (!(readl(&dev->regs->irqstat0) & (1 << INTA_ASSERTED))) | ||
| 2629 | return IRQ_NONE; | ||
| 2630 | |||
| 2631 | spin_lock (&dev->lock); | ||
| 2632 | |||
| 2633 | /* handle disconnect, dma, and more */ | ||
| 2634 | handle_stat1_irqs (dev, readl (&dev->regs->irqstat1)); | ||
| 2635 | |||
| 2636 | /* control requests and PIO */ | ||
| 2637 | handle_stat0_irqs (dev, readl (&dev->regs->irqstat0)); | ||
| 2638 | |||
| 2639 | spin_unlock (&dev->lock); | ||
| 2640 | |||
| 2641 | return IRQ_HANDLED; | ||
| 2642 | } | ||
| 2643 | |||
| 2644 | /*-------------------------------------------------------------------------*/ | ||
| 2645 | |||
| 2646 | static void gadget_release (struct device *_dev) | ||
| 2647 | { | ||
| 2648 | struct net2280 *dev = dev_get_drvdata (_dev); | ||
| 2649 | |||
| 2650 | kfree (dev); | ||
| 2651 | } | ||
| 2652 | |||
| 2653 | /* tear down the binding between this driver and the pci device */ | ||
| 2654 | |||
| 2655 | static void net2280_remove (struct pci_dev *pdev) | ||
| 2656 | { | ||
| 2657 | struct net2280 *dev = pci_get_drvdata (pdev); | ||
| 2658 | |||
| 2659 | usb_del_gadget_udc(&dev->gadget); | ||
| 2660 | |||
| 2661 | BUG_ON(dev->driver); | ||
| 2662 | |||
| 2663 | /* then clean up the resources we allocated during probe() */ | ||
| 2664 | net2280_led_shutdown (dev); | ||
| 2665 | if (dev->requests) { | ||
| 2666 | int i; | ||
| 2667 | for (i = 1; i < 5; i++) { | ||
| 2668 | if (!dev->ep [i].dummy) | ||
| 2669 | continue; | ||
| 2670 | pci_pool_free (dev->requests, dev->ep [i].dummy, | ||
| 2671 | dev->ep [i].td_dma); | ||
| 2672 | } | ||
| 2673 | pci_pool_destroy (dev->requests); | ||
| 2674 | } | ||
| 2675 | if (dev->got_irq) | ||
| 2676 | free_irq (pdev->irq, dev); | ||
| 2677 | if (dev->regs) | ||
| 2678 | iounmap (dev->regs); | ||
| 2679 | if (dev->region) | ||
| 2680 | release_mem_region (pci_resource_start (pdev, 0), | ||
| 2681 | pci_resource_len (pdev, 0)); | ||
| 2682 | if (dev->enabled) | ||
| 2683 | pci_disable_device (pdev); | ||
| 2684 | device_remove_file (&pdev->dev, &dev_attr_registers); | ||
| 2685 | |||
| 2686 | INFO (dev, "unbind\n"); | ||
| 2687 | } | ||
| 2688 | |||
| 2689 | /* wrap this driver around the specified device, but | ||
| 2690 | * don't respond over USB until a gadget driver binds to us. | ||
| 2691 | */ | ||
| 2692 | |||
| 2693 | static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | ||
| 2694 | { | ||
| 2695 | struct net2280 *dev; | ||
| 2696 | unsigned long resource, len; | ||
| 2697 | void __iomem *base = NULL; | ||
| 2698 | int retval, i; | ||
| 2699 | |||
| 2700 | /* alloc, and start init */ | ||
| 2701 | dev = kzalloc (sizeof *dev, GFP_KERNEL); | ||
| 2702 | if (dev == NULL){ | ||
| 2703 | retval = -ENOMEM; | ||
| 2704 | goto done; | ||
| 2705 | } | ||
| 2706 | |||
| 2707 | pci_set_drvdata (pdev, dev); | ||
| 2708 | spin_lock_init (&dev->lock); | ||
| 2709 | dev->pdev = pdev; | ||
| 2710 | dev->gadget.ops = &net2280_ops; | ||
| 2711 | dev->gadget.max_speed = USB_SPEED_HIGH; | ||
| 2712 | |||
| 2713 | /* the "gadget" abstracts/virtualizes the controller */ | ||
| 2714 | dev->gadget.name = driver_name; | ||
| 2715 | |||
| 2716 | /* now all the pci goodies ... */ | ||
| 2717 | if (pci_enable_device (pdev) < 0) { | ||
| 2718 | retval = -ENODEV; | ||
| 2719 | goto done; | ||
| 2720 | } | ||
| 2721 | dev->enabled = 1; | ||
| 2722 | |||
| 2723 | /* BAR 0 holds all the registers | ||
| 2724 | * BAR 1 is 8051 memory; unused here (note erratum 0103) | ||
| 2725 | * BAR 2 is fifo memory; unused here | ||
| 2726 | */ | ||
| 2727 | resource = pci_resource_start (pdev, 0); | ||
| 2728 | len = pci_resource_len (pdev, 0); | ||
| 2729 | if (!request_mem_region (resource, len, driver_name)) { | ||
| 2730 | DEBUG (dev, "controller already in use\n"); | ||
| 2731 | retval = -EBUSY; | ||
| 2732 | goto done; | ||
| 2733 | } | ||
| 2734 | dev->region = 1; | ||
| 2735 | |||
| 2736 | /* FIXME provide firmware download interface to put | ||
| 2737 | * 8051 code into the chip, e.g. to turn on PCI PM. | ||
| 2738 | */ | ||
| 2739 | |||
| 2740 | base = ioremap_nocache (resource, len); | ||
| 2741 | if (base == NULL) { | ||
| 2742 | DEBUG (dev, "can't map memory\n"); | ||
| 2743 | retval = -EFAULT; | ||
| 2744 | goto done; | ||
| 2745 | } | ||
| 2746 | dev->regs = (struct net2280_regs __iomem *) base; | ||
| 2747 | dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080); | ||
| 2748 | dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100); | ||
| 2749 | dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180); | ||
| 2750 | dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200); | ||
| 2751 | dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300); | ||
| 2752 | |||
| 2753 | /* put into initial config, link up all endpoints */ | ||
| 2754 | writel (0, &dev->usb->usbctl); | ||
| 2755 | usb_reset (dev); | ||
| 2756 | usb_reinit (dev); | ||
| 2757 | |||
| 2758 | /* irq setup after old hardware is cleaned up */ | ||
| 2759 | if (!pdev->irq) { | ||
| 2760 | ERROR (dev, "No IRQ. Check PCI setup!\n"); | ||
| 2761 | retval = -ENODEV; | ||
| 2762 | goto done; | ||
| 2763 | } | ||
| 2764 | |||
| 2765 | if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev) | ||
| 2766 | != 0) { | ||
| 2767 | ERROR (dev, "request interrupt %d failed\n", pdev->irq); | ||
| 2768 | retval = -EBUSY; | ||
| 2769 | goto done; | ||
| 2770 | } | ||
| 2771 | dev->got_irq = 1; | ||
| 2772 | |||
| 2773 | /* DMA setup */ | ||
| 2774 | /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */ | ||
| 2775 | dev->requests = pci_pool_create ("requests", pdev, | ||
| 2776 | sizeof (struct net2280_dma), | ||
| 2777 | 0 /* no alignment requirements */, | ||
| 2778 | 0 /* or page-crossing issues */); | ||
| 2779 | if (!dev->requests) { | ||
| 2780 | DEBUG (dev, "can't get request pool\n"); | ||
| 2781 | retval = -ENOMEM; | ||
| 2782 | goto done; | ||
| 2783 | } | ||
| 2784 | for (i = 1; i < 5; i++) { | ||
| 2785 | struct net2280_dma *td; | ||
| 2786 | |||
| 2787 | td = pci_pool_alloc (dev->requests, GFP_KERNEL, | ||
| 2788 | &dev->ep [i].td_dma); | ||
| 2789 | if (!td) { | ||
| 2790 | DEBUG (dev, "can't get dummy %d\n", i); | ||
| 2791 | retval = -ENOMEM; | ||
| 2792 | goto done; | ||
| 2793 | } | ||
| 2794 | td->dmacount = 0; /* not VALID */ | ||
| 2795 | td->dmadesc = td->dmaaddr; | ||
| 2796 | dev->ep [i].dummy = td; | ||
| 2797 | } | ||
| 2798 | |||
| 2799 | /* enable lower-overhead pci memory bursts during DMA */ | ||
| 2800 | writel ( (1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) | ||
| 2801 | // 256 write retries may not be enough... | ||
| 2802 | // | (1 << PCI_RETRY_ABORT_ENABLE) | ||
| 2803 | | (1 << DMA_READ_MULTIPLE_ENABLE) | ||
| 2804 | | (1 << DMA_READ_LINE_ENABLE) | ||
| 2805 | , &dev->pci->pcimstctl); | ||
| 2806 | /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */ | ||
| 2807 | pci_set_master (pdev); | ||
| 2808 | pci_try_set_mwi (pdev); | ||
| 2809 | |||
| 2810 | /* ... also flushes any posted pci writes */ | ||
| 2811 | dev->chiprev = get_idx_reg (dev->regs, REG_CHIPREV) & 0xffff; | ||
| 2812 | |||
| 2813 | /* done */ | ||
| 2814 | INFO (dev, "%s\n", driver_desc); | ||
| 2815 | INFO (dev, "irq %d, pci mem %p, chip rev %04x\n", | ||
| 2816 | pdev->irq, base, dev->chiprev); | ||
| 2817 | INFO (dev, "version: " DRIVER_VERSION "; dma %s\n", | ||
| 2818 | use_dma | ||
| 2819 | ? (use_dma_chaining ? "chaining" : "enabled") | ||
| 2820 | : "disabled"); | ||
| 2821 | retval = device_create_file (&pdev->dev, &dev_attr_registers); | ||
| 2822 | if (retval) goto done; | ||
| 2823 | |||
| 2824 | retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, | ||
| 2825 | gadget_release); | ||
| 2826 | if (retval) | ||
| 2827 | goto done; | ||
| 2828 | return 0; | ||
| 2829 | |||
| 2830 | done: | ||
| 2831 | if (dev) | ||
| 2832 | net2280_remove (pdev); | ||
| 2833 | return retval; | ||
| 2834 | } | ||
| 2835 | |||
| 2836 | /* make sure the board is quiescent; otherwise it will continue | ||
| 2837 | * generating IRQs across the upcoming reboot. | ||
| 2838 | */ | ||
| 2839 | |||
| 2840 | static void net2280_shutdown (struct pci_dev *pdev) | ||
| 2841 | { | ||
| 2842 | struct net2280 *dev = pci_get_drvdata (pdev); | ||
| 2843 | |||
| 2844 | /* disable IRQs */ | ||
| 2845 | writel (0, &dev->regs->pciirqenb0); | ||
| 2846 | writel (0, &dev->regs->pciirqenb1); | ||
| 2847 | |||
| 2848 | /* disable the pullup so the host will think we're gone */ | ||
| 2849 | writel (0, &dev->usb->usbctl); | ||
| 2850 | |||
| 2851 | /* Disable full-speed test mode */ | ||
| 2852 | writel(0, &dev->usb->xcvrdiag); | ||
| 2853 | } | ||
| 2854 | |||
| 2855 | |||
| 2856 | /*-------------------------------------------------------------------------*/ | ||
| 2857 | |||
| 2858 | static const struct pci_device_id pci_ids [] = { { | ||
| 2859 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
| 2860 | .class_mask = ~0, | ||
| 2861 | .vendor = 0x17cc, | ||
| 2862 | .device = 0x2280, | ||
| 2863 | .subvendor = PCI_ANY_ID, | ||
| 2864 | .subdevice = PCI_ANY_ID, | ||
| 2865 | }, { | ||
| 2866 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
| 2867 | .class_mask = ~0, | ||
| 2868 | .vendor = 0x17cc, | ||
| 2869 | .device = 0x2282, | ||
| 2870 | .subvendor = PCI_ANY_ID, | ||
| 2871 | .subdevice = PCI_ANY_ID, | ||
| 2872 | |||
| 2873 | }, { /* end: all zeroes */ } | ||
| 2874 | }; | ||
| 2875 | MODULE_DEVICE_TABLE (pci, pci_ids); | ||
| 2876 | |||
| 2877 | /* pci driver glue; this is a "new style" PCI driver module */ | ||
| 2878 | static struct pci_driver net2280_pci_driver = { | ||
| 2879 | .name = (char *) driver_name, | ||
| 2880 | .id_table = pci_ids, | ||
| 2881 | |||
| 2882 | .probe = net2280_probe, | ||
| 2883 | .remove = net2280_remove, | ||
| 2884 | .shutdown = net2280_shutdown, | ||
| 2885 | |||
| 2886 | /* FIXME add power management support */ | ||
| 2887 | }; | ||
| 2888 | |||
| 2889 | MODULE_DESCRIPTION (DRIVER_DESC); | ||
| 2890 | MODULE_AUTHOR ("David Brownell"); | ||
| 2891 | MODULE_LICENSE ("GPL"); | ||
| 2892 | |||
| 2893 | static int __init init (void) | ||
| 2894 | { | ||
| 2895 | if (!use_dma) | ||
| 2896 | use_dma_chaining = 0; | ||
| 2897 | return pci_register_driver (&net2280_pci_driver); | ||
| 2898 | } | ||
| 2899 | module_init (init); | ||
| 2900 | |||
| 2901 | static void __exit cleanup (void) | ||
| 2902 | { | ||
| 2903 | pci_unregister_driver (&net2280_pci_driver); | ||
| 2904 | } | ||
| 2905 | module_exit (cleanup); | ||
| @@ -1,308 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * NetChip 2280 high/full speed USB device controller. | ||
| 3 | * Unlike many such controllers, this one talks PCI. | ||
| 4 | */ | ||
| 5 | |||
| 6 | /* | ||
| 7 | * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com) | ||
| 8 | * Copyright (C) 2003 David Brownell | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License as published by | ||
| 12 | * the Free Software Foundation; either version 2 of the License, or | ||
| 13 | * (at your option) any later version. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <linux/usb/net2280.h> | ||
| 17 | |||
| 18 | /*-------------------------------------------------------------------------*/ | ||
| 19 | |||
| 20 | #ifdef __KERNEL__ | ||
| 21 | |||
| 22 | /* indexed registers [11.10] are accessed indirectly | ||
| 23 | * caller must own the device lock. | ||
| 24 | */ | ||
| 25 | |||
| 26 | static inline u32 | ||
| 27 | get_idx_reg (struct net2280_regs __iomem *regs, u32 index) | ||
| 28 | { | ||
| 29 | writel (index, ®s->idxaddr); | ||
| 30 | /* NOTE: synchs device/cpu memory views */ | ||
| 31 | return readl (®s->idxdata); | ||
| 32 | } | ||
| 33 | |||
| 34 | static inline void | ||
| 35 | set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value) | ||
| 36 | { | ||
| 37 | writel (index, ®s->idxaddr); | ||
| 38 | writel (value, ®s->idxdata); | ||
| 39 | /* posted, may not be visible yet */ | ||
| 40 | } | ||
| 41 | |||
| 42 | #endif /* __KERNEL__ */ | ||
| 43 | |||
| 44 | |||
| 45 | #define REG_DIAG 0x0 | ||
| 46 | #define RETRY_COUNTER 16 | ||
| 47 | #define FORCE_PCI_SERR 11 | ||
| 48 | #define FORCE_PCI_INTERRUPT 10 | ||
| 49 | #define FORCE_USB_INTERRUPT 9 | ||
| 50 | #define FORCE_CPU_INTERRUPT 8 | ||
| 51 | #define ILLEGAL_BYTE_ENABLES 5 | ||
| 52 | #define FAST_TIMES 4 | ||
| 53 | #define FORCE_RECEIVE_ERROR 2 | ||
| 54 | #define FORCE_TRANSMIT_CRC_ERROR 0 | ||
| 55 | #define REG_FRAME 0x02 /* from last sof */ | ||
| 56 | #define REG_CHIPREV 0x03 /* in bcd */ | ||
| 57 | #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */ | ||
| 58 | |||
| 59 | #define CHIPREV_1 0x0100 | ||
| 60 | #define CHIPREV_1A 0x0110 | ||
| 61 | |||
| 62 | #ifdef __KERNEL__ | ||
| 63 | |||
| 64 | /* ep a-f highspeed and fullspeed maxpacket, addresses | ||
| 65 | * computed from ep->num | ||
| 66 | */ | ||
| 67 | #define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \ | ||
| 68 | (((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1)) | ||
| 69 | |||
| 70 | /*-------------------------------------------------------------------------*/ | ||
| 71 | |||
| 72 | /* [8.3] for scatter/gather i/o | ||
| 73 | * use struct net2280_dma_regs bitfields | ||
| 74 | */ | ||
| 75 | struct net2280_dma { | ||
| 76 | __le32 dmacount; | ||
| 77 | __le32 dmaaddr; /* the buffer */ | ||
| 78 | __le32 dmadesc; /* next dma descriptor */ | ||
| 79 | __le32 _reserved; | ||
| 80 | } __attribute__ ((aligned (16))); | ||
| 81 | |||
| 82 | /*-------------------------------------------------------------------------*/ | ||
| 83 | |||
| 84 | /* DRIVER DATA STRUCTURES and UTILITIES */ | ||
| 85 | |||
| 86 | struct net2280_ep { | ||
| 87 | struct usb_ep ep; | ||
| 88 | struct net2280_ep_regs __iomem *regs; | ||
| 89 | struct net2280_dma_regs __iomem *dma; | ||
| 90 | struct net2280_dma *dummy; | ||
| 91 | dma_addr_t td_dma; /* of dummy */ | ||
| 92 | struct net2280 *dev; | ||
| 93 | unsigned long irqs; | ||
| 94 | |||
| 95 | /* analogous to a host-side qh */ | ||
| 96 | struct list_head queue; | ||
| 97 | const struct usb_endpoint_descriptor *desc; | ||
| 98 | unsigned num : 8, | ||
| 99 | fifo_size : 12, | ||
| 100 | in_fifo_validate : 1, | ||
| 101 | out_overflow : 1, | ||
| 102 | stopped : 1, | ||
| 103 | wedged : 1, | ||
| 104 | is_in : 1, | ||
| 105 | is_iso : 1, | ||
| 106 | responded : 1; | ||
| 107 | }; | ||
| 108 | |||
| 109 | static inline void allow_status (struct net2280_ep *ep) | ||
| 110 | { | ||
| 111 | /* ep0 only */ | ||
| 112 | writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) | ||
| 113 | | (1 << CLEAR_NAK_OUT_PACKETS) | ||
| 114 | | (1 << CLEAR_NAK_OUT_PACKETS_MODE) | ||
| 115 | , &ep->regs->ep_rsp); | ||
| 116 | ep->stopped = 1; | ||
| 117 | } | ||
| 118 | |||
| 119 | /* count (<= 4) bytes in the next fifo write will be valid */ | ||
| 120 | static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count) | ||
| 121 | { | ||
| 122 | writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg); | ||
| 123 | } | ||
| 124 | |||
| 125 | struct net2280_request { | ||
| 126 | struct usb_request req; | ||
| 127 | struct net2280_dma *td; | ||
| 128 | dma_addr_t td_dma; | ||
| 129 | struct list_head queue; | ||
| 130 | unsigned mapped : 1, | ||
| 131 | valid : 1; | ||
| 132 | }; | ||
| 133 | |||
| 134 | struct net2280 { | ||
| 135 | /* each pci device provides one gadget, several endpoints */ | ||
| 136 | struct usb_gadget gadget; | ||
| 137 | spinlock_t lock; | ||
| 138 | struct net2280_ep ep [7]; | ||
| 139 | struct usb_gadget_driver *driver; | ||
| 140 | unsigned enabled : 1, | ||
| 141 | protocol_stall : 1, | ||
| 142 | softconnect : 1, | ||
| 143 | got_irq : 1, | ||
| 144 | region : 1; | ||
| 145 | u16 chiprev; | ||
| 146 | |||
| 147 | /* pci state used to access those endpoints */ | ||
| 148 | struct pci_dev *pdev; | ||
| 149 | struct net2280_regs __iomem *regs; | ||
| 150 | struct net2280_usb_regs __iomem *usb; | ||
| 151 | struct net2280_pci_regs __iomem *pci; | ||
| 152 | struct net2280_dma_regs __iomem *dma; | ||
| 153 | struct net2280_dep_regs __iomem *dep; | ||
| 154 | struct net2280_ep_regs __iomem *epregs; | ||
| 155 | |||
| 156 | struct pci_pool *requests; | ||
| 157 | // statistics... | ||
| 158 | }; | ||
| 159 | |||
| 160 | static inline void set_halt (struct net2280_ep *ep) | ||
| 161 | { | ||
| 162 | /* ep0 and bulk/intr endpoints */ | ||
| 163 | writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) | ||
| 164 | /* set NAK_OUT for erratum 0114 */ | ||
| 165 | | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS) | ||
| 166 | | (1 << SET_ENDPOINT_HALT) | ||
| 167 | , &ep->regs->ep_rsp); | ||
| 168 | } | ||
| 169 | |||
| 170 | static inline void clear_halt (struct net2280_ep *ep) | ||
| 171 | { | ||
| 172 | /* ep0 and bulk/intr endpoints */ | ||
| 173 | writel ( (1 << CLEAR_ENDPOINT_HALT) | ||
| 174 | | (1 << CLEAR_ENDPOINT_TOGGLE) | ||
| 175 | /* unless the gadget driver left a short packet in the | ||
| 176 | * fifo, this reverses the erratum 0114 workaround. | ||
| 177 | */ | ||
| 178 | | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS) | ||
| 179 | , &ep->regs->ep_rsp); | ||
| 180 | } | ||
| 181 | |||
| 182 | #ifdef USE_RDK_LEDS | ||
| 183 | |||
| 184 | static inline void net2280_led_init (struct net2280 *dev) | ||
| 185 | { | ||
| 186 | /* LED3 (green) is on during USB activity. note erratum 0113. */ | ||
| 187 | writel ((1 << GPIO3_LED_SELECT) | ||
| 188 | | (1 << GPIO3_OUTPUT_ENABLE) | ||
| 189 | | (1 << GPIO2_OUTPUT_ENABLE) | ||
| 190 | | (1 << GPIO1_OUTPUT_ENABLE) | ||
| 191 | | (1 << GPIO0_OUTPUT_ENABLE) | ||
| 192 | , &dev->regs->gpioctl); | ||
| 193 | } | ||
| 194 | |||
| 195 | /* indicate speed with bi-color LED 0/1 */ | ||
| 196 | static inline | ||
| 197 | void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed) | ||
| 198 | { | ||
| 199 | u32 val = readl (&dev->regs->gpioctl); | ||
| 200 | switch (speed) { | ||
| 201 | case USB_SPEED_HIGH: /* green */ | ||
| 202 | val &= ~(1 << GPIO0_DATA); | ||
| 203 | val |= (1 << GPIO1_DATA); | ||
| 204 | break; | ||
| 205 | case USB_SPEED_FULL: /* red */ | ||
| 206 | val &= ~(1 << GPIO1_DATA); | ||
| 207 | val |= (1 << GPIO0_DATA); | ||
| 208 | break; | ||
| 209 | default: /* (off/black) */ | ||
| 210 | val &= ~((1 << GPIO1_DATA) | (1 << GPIO0_DATA)); | ||
| 211 | break; | ||
| 212 | } | ||
| 213 | writel (val, &dev->regs->gpioctl); | ||
| 214 | } | ||
| 215 | |||
| 216 | /* indicate power with LED 2 */ | ||
| 217 | static inline void net2280_led_active (struct net2280 *dev, int is_active) | ||
| 218 | { | ||
| 219 | u32 val = readl (&dev->regs->gpioctl); | ||
| 220 | |||
| 221 | // FIXME this LED never seems to turn on. | ||
| 222 | if (is_active) | ||
| 223 | val |= GPIO2_DATA; | ||
| 224 | else | ||
| 225 | val &= ~GPIO2_DATA; | ||
| 226 | writel (val, &dev->regs->gpioctl); | ||
| 227 | } | ||
| 228 | static inline void net2280_led_shutdown (struct net2280 *dev) | ||
| 229 | { | ||
| 230 | /* turn off all four GPIO*_DATA bits */ | ||
| 231 | writel (readl (&dev->regs->gpioctl) & ~0x0f, | ||
| 232 | &dev->regs->gpioctl); | ||
| 233 | } | ||
| 234 | |||
| 235 | #else | ||
| 236 | |||
| 237 | #define net2280_led_init(dev) do { } while (0) | ||
| 238 | #define net2280_led_speed(dev, speed) do { } while (0) | ||
| 239 | #define net2280_led_shutdown(dev) do { } while (0) | ||
| 240 | |||
| 241 | #endif | ||
| 242 | |||
| 243 | /*-------------------------------------------------------------------------*/ | ||
| 244 | |||
| 245 | #define xprintk(dev,level,fmt,args...) \ | ||
| 246 | printk(level "%s %s: " fmt , driver_name , \ | ||
| 247 | pci_name(dev->pdev) , ## args) | ||
| 248 | |||
| 249 | #ifdef DEBUG | ||
| 250 | #undef DEBUG | ||
| 251 | #define DEBUG(dev,fmt,args...) \ | ||
| 252 | xprintk(dev , KERN_DEBUG , fmt , ## args) | ||
| 253 | #else | ||
| 254 | #define DEBUG(dev,fmt,args...) \ | ||
| 255 | do { } while (0) | ||
| 256 | #endif /* DEBUG */ | ||
| 257 | |||
| 258 | #ifdef VERBOSE | ||
| 259 | #define VDEBUG DEBUG | ||
| 260 | #else | ||
| 261 | #define VDEBUG(dev,fmt,args...) \ | ||
| 262 | do { } while (0) | ||
| 263 | #endif /* VERBOSE */ | ||
| 264 | |||
| 265 | #define ERROR(dev,fmt,args...) \ | ||
| 266 | xprintk(dev , KERN_ERR , fmt , ## args) | ||
| 267 | #define WARNING(dev,fmt,args...) \ | ||
| 268 | xprintk(dev , KERN_WARNING , fmt , ## args) | ||
| 269 | #define INFO(dev,fmt,args...) \ | ||
| 270 | xprintk(dev , KERN_INFO , fmt , ## args) | ||
| 271 | |||
| 272 | /*-------------------------------------------------------------------------*/ | ||
| 273 | |||
| 274 | static inline void start_out_naking (struct net2280_ep *ep) | ||
| 275 | { | ||
| 276 | /* NOTE: hardware races lurk here, and PING protocol issues */ | ||
| 277 | writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 278 | /* synch with device */ | ||
| 279 | readl (&ep->regs->ep_rsp); | ||
| 280 | } | ||
| 281 | |||
| 282 | #ifdef DEBUG | ||
| 283 | static inline void assert_out_naking (struct net2280_ep *ep, const char *where) | ||
| 284 | { | ||
| 285 | u32 tmp = readl (&ep->regs->ep_stat); | ||
| 286 | |||
| 287 | if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) { | ||
| 288 | DEBUG (ep->dev, "%s %s %08x !NAK\n", | ||
| 289 | ep->ep.name, where, tmp); | ||
| 290 | writel ((1 << SET_NAK_OUT_PACKETS), | ||
| 291 | &ep->regs->ep_rsp); | ||
| 292 | } | ||
| 293 | } | ||
| 294 | #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__func__) | ||
| 295 | #else | ||
| 296 | #define ASSERT_OUT_NAKING(ep) do {} while (0) | ||
| 297 | #endif | ||
| 298 | |||
| 299 | static inline void stop_out_naking (struct net2280_ep *ep) | ||
| 300 | { | ||
| 301 | u32 tmp; | ||
| 302 | |||
| 303 | tmp = readl (&ep->regs->ep_stat); | ||
| 304 | if ((tmp & (1 << NAK_OUT_PACKETS)) != 0) | ||
| 305 | writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 306 | } | ||
| 307 | |||
| 308 | #endif /* __KERNEL__ */ | ||
| @@ -35,27 +35,63 @@ · 34 unmodified lines | |||
| 35 | #define USB_EXT_PROP_UNICODE_LINK 6 | 35 | #define USB_EXT_PROP_UNICODE_LINK 6 |
| 36 | #define USB_EXT_PROP_UNICODE_MULTI 7 | 36 | #define USB_EXT_PROP_UNICODE_MULTI 7 |
| 37 | 37 | ||
| 38 | static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset) | ||
| 39 | { | ||
| 40 | return buf + offset; | ||
| 41 | } | ||
| 42 | |||
| 43 | static inline u8 *usb_ext_prop_size_ptr(u8 *buf) | ||
| 44 | { | ||
| 45 | return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE); | ||
| 46 | } | ||
| 47 | |||
| 48 | static inline u8 *usb_ext_prop_type_ptr(u8 *buf) | ||
| 49 | { | ||
| 50 | return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE); | ||
| 51 | } | ||
| 52 | |||
| 53 | static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf) | ||
| 54 | { | ||
| 55 | return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH); | ||
| 56 | } | ||
| 57 | |||
| 58 | static inline u8 *usb_ext_prop_name_ptr(u8 *buf) | ||
| 59 | { | ||
| 60 | return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME); | ||
| 61 | } | ||
| 62 | |||
| 63 | static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off) | ||
| 64 | { | ||
| 65 | return __usb_ext_prop_ptr(buf, | ||
| 66 | USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off); | ||
| 67 | } | ||
| 68 | |||
| 69 | static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off) | ||
| 70 | { | ||
| 71 | return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off); | ||
| 72 | } | ||
| 73 | |||
| 38 | static inline void usb_ext_prop_put_size(u8 *buf, int dw_size) | 74 | static inline void usb_ext_prop_put_size(u8 *buf, int dw_size) |
| 39 | { | 75 | { |
| 40 | put_unaligned_le32(dw_size, &buf[USB_EXT_PROP_DW_SIZE]); | 76 | put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf)); |
| 41 | } | 77 | } |
| 42 | 78 | ||
| 43 | static inline void usb_ext_prop_put_type(u8 *buf, int type) | 79 | static inline void usb_ext_prop_put_type(u8 *buf, int type) |
| 44 | { | 80 | { |
| 45 | put_unaligned_le32(type, &buf[USB_EXT_PROP_DW_PROPERTY_DATA_TYPE]); | 81 | put_unaligned_le32(type, usb_ext_prop_type_ptr(buf)); |
| 46 | } | 82 | } |
| 47 | 83 | ||
| 48 | static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) | 84 | static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) |
| 49 | { | 85 | { |
| 50 | int result; | 86 | int result; |
| 51 | 87 | ||
| 52 | put_unaligned_le16(pnl, &buf[USB_EXT_PROP_W_PROPERTY_NAME_LENGTH]); | 88 | put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf)); |
| 53 | result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN, | 89 | result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN, |
| 54 | (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_NAME], pnl - 2); | 90 | (wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2); |
| 55 | if (result < 0) | 91 | if (result < 0) |
| 56 | return result; | 92 | return result; |
| 57 | 93 | ||
| 58 | put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl]); | 94 | put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]); |
| 59 | 95 | ||
| 60 | return pnl; | 96 | return pnl; |
| 61 | } | 97 | } |
| @@ -63,26 +99,23 @@ static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) · 1 unmodified line | |||
| 63 | static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, | 99 | static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, |
| 64 | int data_len) | 100 | int data_len) |
| 65 | { | 101 | { |
| 66 | put_unaligned_le32(data_len, | 102 | put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl)); |
| 67 | &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); | 103 | memcpy(usb_ext_prop_data_ptr(buf, pnl), data, data_len); |
| 68 | memcpy(&buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], data, data_len); | ||
| 69 | } | 104 | } |
| 70 | 105 | ||
| 71 | static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, | 106 | static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, |
| 72 | int data_len) | 107 | int data_len) |
| 73 | { | 108 | { |
| 74 | int result; | 109 | int result; |
| 75 | put_unaligned_le32(data_len, | 110 | put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl)); |
| 76 | &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); | ||
| 77 | |||
| 78 | result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN, | 111 | result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN, |
| 79 | (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], | 112 | (wchar_t *) usb_ext_prop_data_ptr(buf, pnl), |
| 80 | data_len - 2); | 113 | data_len - 2); |
| 81 | if (result < 0) | 114 | if (result < 0) |
| 82 | return result; | 115 | return result; |
| 83 | 116 | ||
| 84 | put_unaligned_le16(0, | 117 | put_unaligned_le16(0, |
| 85 | &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len]); | 118 | &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]); |
| 86 | 119 | ||
| 87 | return data_len; | 120 | return data_len; |
| 88 | } | 121 | } |
| @@ -0,0 +1,385 @@ | |||
| 1 | # | ||
| 2 | # USB Gadget support on a system involves | ||
| 3 | # (a) a peripheral controller, and | ||
| 4 | # (b) the gadget driver using it. | ||
| 5 | # | ||
| 6 | # NOTE: Gadget support ** DOES NOT ** depend on host-side CONFIG_USB !! | ||
| 7 | # | ||
| 8 | # - Host systems (like PCs) need CONFIG_USB (with "A" jacks). | ||
| 9 | # - Peripherals (like PDAs) need CONFIG_USB_GADGET (with "B" jacks). | ||
| 10 | # - Some systems have both kinds of controllers. | ||
| 11 | # | ||
| 12 | # With help from a special transceiver and a "Mini-AB" jack, systems with | ||
| 13 | # both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG). | ||
| 14 | # | ||
| 15 | |||
| 16 | # | ||
| 17 | # USB Peripheral Controller Support | ||
| 18 | # | ||
| 19 | # The order here is alphabetical, except that integrated controllers go | ||
| 20 | # before discrete ones so they will be the initial/default value: | ||
| 21 | # - integrated/SOC controllers first | ||
| 22 | # - licensed IP used in both SOC and discrete versions | ||
| 23 | # - discrete ones (including all PCI-only controllers) | ||
| 24 | # - debug/dummy gadget+hcd is last. | ||
| 25 | # | ||
| 26 | menu "USB Peripheral Controller" | ||
| 27 | |||
| 28 | # | ||
| 29 | # Integrated controllers | ||
| 30 | # | ||
| 31 | |||
| 32 | config USB_AT91 | ||
| 33 | tristate "Atmel AT91 USB Device Port" | ||
| 34 | depends on ARCH_AT91 | ||
| 35 | help | ||
| 36 | Many Atmel AT91 processors (such as the AT91RM2000) have a | ||
| 37 | full speed USB Device Port with support for five configurable | ||
| 38 | endpoints (plus endpoint zero). | ||
| 39 | |||
| 40 | Say "y" to link the driver statically, or "m" to build a | ||
| 41 | dynamically linked module called "at91_udc" and force all | ||
| 42 | gadget drivers to also be dynamically linked. | ||
| 43 | |||
| 44 | config USB_LPC32XX | ||
| 45 | tristate "LPC32XX USB Peripheral Controller" | ||
| 46 | depends on ARCH_LPC32XX && I2C | ||
| 47 | select USB_ISP1301 | ||
| 48 | help | ||
| 49 | This option selects the USB device controller in the LPC32xx SoC. | ||
| 50 | |||
| 51 | Say "y" to link the driver statically, or "m" to build a | ||
| 52 | dynamically linked module called "lpc32xx_udc" and force all | ||
| 53 | gadget drivers to also be dynamically linked. | ||
| 54 | |||
| 55 | config USB_ATMEL_USBA | ||
| 56 | tristate "Atmel USBA" | ||
| 57 | depends on AVR32 || ARCH_AT91 | ||
| 58 | help | ||
| 59 | USBA is the integrated high-speed USB Device controller on | ||
| 60 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. | ||
| 61 | |||
| 62 | config USB_BCM63XX_UDC | ||
| 63 | tristate "Broadcom BCM63xx Peripheral Controller" | ||
| 64 | depends on BCM63XX | ||
| 65 | help | ||
| 66 | Many Broadcom BCM63xx chipsets (such as the BCM6328) have a | ||
| 67 | high speed USB Device Port with support for four fixed endpoints | ||
| 68 | (plus endpoint zero). | ||
| 69 | |||
| 70 | Say "y" to link the driver statically, or "m" to build a | ||
| 71 | dynamically linked module called "bcm63xx_udc". | ||
| 72 | |||
| 73 | config USB_FSL_USB2 | ||
| 74 | tristate "Freescale Highspeed USB DR Peripheral Controller" | ||
| 75 | depends on FSL_SOC || ARCH_MXC | ||
| 76 | select USB_FSL_MPH_DR_OF if OF | ||
| 77 | help | ||
| 78 | Some of Freescale PowerPC and i.MX processors have a High Speed | ||
| 79 | Dual-Role(DR) USB controller, which supports device mode. | ||
| 80 | |||
| 81 | The number of programmable endpoints is different through | ||
| 82 | SOC revisions. | ||
| 83 | |||
| 84 | Say "y" to link the driver statically, or "m" to build a | ||
| 85 | dynamically linked module called "fsl_usb2_udc" and force | ||
| 86 | all gadget drivers to also be dynamically linked. | ||
| 87 | |||
| 88 | config USB_FUSB300 | ||
| 89 | tristate "Faraday FUSB300 USB Peripheral Controller" | ||
| 90 | depends on !PHYS_ADDR_T_64BIT && HAS_DMA | ||
| 91 | help | ||
| 92 | Faraday usb device controller FUSB300 driver | ||
| 93 | |||
| 94 | config USB_FOTG210_UDC | ||
| 95 | depends on HAS_DMA | ||
| 96 | tristate "Faraday FOTG210 USB Peripheral Controller" | ||
| 97 | help | ||
| 98 | Faraday USB2.0 OTG controller which can be configured as | ||
| 99 | high speed or full speed USB device. This driver supppors | ||
| 100 | Bulk Transfer so far. | ||
| 101 | |||
| 102 | Say "y" to link the driver statically, or "m" to build a | ||
| 103 | dynamically linked module called "fotg210_udc". | ||
| 104 | |||
| 105 | config USB_GR_UDC | ||
| 106 | tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" | ||
| 107 | depends on HAS_DMA | ||
| 108 | help | ||
| 109 | Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB | ||
| 110 | VHDL IP core library. | ||
| 111 | |||
| 112 | config USB_OMAP | ||
| 113 | tristate "OMAP USB Device Controller" | ||
| 114 | depends on ARCH_OMAP1 | ||
| 115 | depends on ISP1301_OMAP || !(MACH_OMAP_H2 || MACH_OMAP_H3) | ||
| 116 | help | ||
| 117 | Many Texas Instruments OMAP processors have flexible full | ||
| 118 | speed USB device controllers, with support for up to 30 | ||
| 119 | endpoints (plus endpoint zero). This driver supports the | ||
| 120 | controller in the OMAP 1611, and should work with controllers | ||
| 121 | in other OMAP processors too, given minor tweaks. | ||
| 122 | |||
| 123 | Say "y" to link the driver statically, or "m" to build a | ||
| 124 | dynamically linked module called "omap_udc" and force all | ||
| 125 | gadget drivers to also be dynamically linked. | ||
| 126 | |||
| 127 | config USB_PXA25X | ||
| 128 | tristate "PXA 25x or IXP 4xx" | ||
| 129 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX | ||
| 130 | help | ||
| 131 | Intel's PXA 25x series XScale ARM-5TE processors include | ||
| 132 | an integrated full speed USB 1.1 device controller. The | ||
| 133 | controller in the IXP 4xx series is register-compatible. | ||
| 134 | |||
| 135 | It has fifteen fixed-function endpoints, as well as endpoint | ||
| 136 | zero (for control transfers). | ||
| 137 | |||
| 138 | Say "y" to link the driver statically, or "m" to build a | ||
| 139 | dynamically linked module called "pxa25x_udc" and force all | ||
| 140 | gadget drivers to also be dynamically linked. | ||
| 141 | |||
| 142 | # if there's only one gadget driver, using only two bulk endpoints, | ||
| 143 | # don't waste memory for the other endpoints | ||
| 144 | config USB_PXA25X_SMALL | ||
| 145 | depends on USB_PXA25X | ||
| 146 | bool | ||
| 147 | default n if USB_ETH_RNDIS | ||
| 148 | default y if USB_ZERO | ||
| 149 | default y if USB_ETH | ||
| 150 | default y if USB_G_SERIAL | ||
| 151 | |||
| 152 | config USB_R8A66597 | ||
| 153 | tristate "Renesas R8A66597 USB Peripheral Controller" | ||
| 154 | depends on HAS_DMA | ||
| 155 | help | ||
| 156 | R8A66597 is a discrete USB host and peripheral controller chip that | ||
| 157 | supports both full and high speed USB 2.0 data transfers. | ||
| 158 | It has nine configurable endpoints, and endpoint zero. | ||
| 159 | |||
| 160 | Say "y" to link the driver statically, or "m" to build a | ||
| 161 | dynamically linked module called "r8a66597_udc" and force all | ||
| 162 | gadget drivers to also be dynamically linked. | ||
| 163 | |||
| 164 | config USB_RENESAS_USBHS_UDC | ||
| 165 | tristate 'Renesas USBHS controller' | ||
| 166 | depends on USB_RENESAS_USBHS | ||
| 167 | help | ||
| 168 | Renesas USBHS is a discrete USB host and peripheral controller chip | ||
| 169 | that supports both full and high speed USB 2.0 data transfers. | ||
| 170 | It has nine or more configurable endpoints, and endpoint zero. | ||
| 171 | |||
| 172 | Say "y" to link the driver statically, or "m" to build a | ||
| 173 | dynamically linked module called "renesas_usbhs" and force all | ||
| 174 | gadget drivers to also be dynamically linked. | ||
| 175 | |||
| 176 | config USB_PXA27X | ||
| 177 | tristate "PXA 27x" | ||
| 178 | help | ||
| 179 | Intel's PXA 27x series XScale ARM v5TE processors include | ||
| 180 | an integrated full speed USB 1.1 device controller. | ||
| 181 | |||
| 182 | It has up to 23 endpoints, as well as endpoint zero (for | ||
| 183 | control transfers). | ||
| 184 | |||
| 185 | Say "y" to link the driver statically, or "m" to build a | ||
| 186 | dynamically linked module called "pxa27x_udc" and force all | ||
| 187 | gadget drivers to also be dynamically linked. | ||
| 188 | |||
| 189 | config USB_S3C2410 | ||
| 190 | tristate "S3C2410 USB Device Controller" | ||
| 191 | depends on ARCH_S3C24XX | ||
| 192 | help | ||
| 193 | Samsung's S3C2410 is an ARM-4 processor with an integrated | ||
| 194 | full speed USB 1.1 device controller. It has 4 configurable | ||
| 195 | endpoints, as well as endpoint zero (for control transfers). | ||
| 196 | |||
| 197 | This driver has been tested on the S3C2410, S3C2412, and | ||
| 198 | S3C2440 processors. | ||
| 199 | |||
| 200 | config USB_S3C2410_DEBUG | ||
| 201 | boolean "S3C2410 udc debug messages" | ||
| 202 | depends on USB_S3C2410 | ||
| 203 | |||
| 204 | config USB_S3C_HSUDC | ||
| 205 | tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller" | ||
| 206 | depends on ARCH_S3C24XX | ||
| 207 | help | ||
| 208 | Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC | ||
| 209 | integrated with dual speed USB 2.0 device controller. It has | ||
| 210 | 8 endpoints, as well as endpoint zero. | ||
| 211 | |||
| 212 | This driver has been tested on S3C2416 and S3C2450 processors. | ||
| 213 | |||
| 214 | config USB_MV_UDC | ||
| 215 | tristate "Marvell USB2.0 Device Controller" | ||
| 216 | depends on HAS_DMA | ||
| 217 | help | ||
| 218 | Marvell Socs (including PXA and MMP series) include a high speed | ||
| 219 | USB2.0 OTG controller, which can be configured as high speed or | ||
| 220 | full speed USB peripheral. | ||
| 221 | |||
| 222 | config USB_MV_U3D | ||
| 223 | depends on HAS_DMA | ||
| 224 | tristate "MARVELL PXA2128 USB 3.0 controller" | ||
| 225 | help | ||
| 226 | MARVELL PXA2128 Processor series include a super speed USB3.0 device | ||
| 227 | controller, which support super speed USB peripheral. | ||
| 228 | |||
| 229 | # | ||
| 230 | # Controllers available in both integrated and discrete versions | ||
| 231 | # | ||
| 232 | |||
| 233 | config USB_M66592 | ||
| 234 | tristate "Renesas M66592 USB Peripheral Controller" | ||
| 235 | help | ||
| 236 | M66592 is a discrete USB peripheral controller chip that | ||
| 237 | supports both full and high speed USB 2.0 data transfers. | ||
| 238 | It has seven configurable endpoints, and endpoint zero. | ||
| 239 | |||
| 240 | Say "y" to link the driver statically, or "m" to build a | ||
| 241 | dynamically linked module called "m66592_udc" and force all | ||
| 242 | gadget drivers to also be dynamically linked. | ||
| 243 | |||
| 244 | # | ||
| 245 | # Controllers available only in discrete form (and all PCI controllers) | ||
| 246 | # | ||
| 247 | |||
| 248 | config USB_AMD5536UDC | ||
| 249 | tristate "AMD5536 UDC" | ||
| 250 | depends on PCI | ||
| 251 | help | ||
| 252 | The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. | ||
| 253 | It is a USB Highspeed DMA capable USB device controller. Beside ep0 | ||
| 254 | it provides 4 IN and 4 OUT endpoints (bulk or interrupt type). | ||
| 255 | The UDC port supports OTG operation, and may be used as a host port | ||
| 256 | if it's not being used to implement peripheral or OTG roles. | ||
| 257 | |||
| 258 | Say "y" to link the driver statically, or "m" to build a | ||
| 259 | dynamically linked module called "amd5536udc" and force all | ||
| 260 | gadget drivers to also be dynamically linked. | ||
| 261 | |||
| 262 | config USB_FSL_QE | ||
| 263 | tristate "Freescale QE/CPM USB Device Controller" | ||
| 264 | depends on FSL_SOC && (QUICC_ENGINE || CPM) | ||
| 265 | help | ||
| 266 | Some of Freescale PowerPC processors have a Full Speed | ||
| 267 | QE/CPM2 USB controller, which support device mode with 4 | ||
| 268 | programmable endpoints. This driver supports the | ||
| 269 | controller in the MPC8360 and MPC8272, and should work with | ||
| 270 | controllers having QE or CPM2, given minor tweaks. | ||
| 271 | |||
| 272 | Set CONFIG_USB_GADGET to "m" to build this driver as a | ||
| 273 | dynamically linked module called "fsl_qe_udc". | ||
| 274 | |||
| 275 | config USB_NET2272 | ||
| 276 | tristate "PLX NET2272" | ||
| 277 | help | ||
| 278 | PLX NET2272 is a USB peripheral controller which supports | ||
| 279 | both full and high speed USB 2.0 data transfers. | ||
| 280 | |||
| 281 | It has three configurable endpoints, as well as endpoint zero | ||
| 282 | (for control transfer). | ||
| 283 | Say "y" to link the driver statically, or "m" to build a | ||
| 284 | dynamically linked module called "net2272" and force all | ||
| 285 | gadget drivers to also be dynamically linked. | ||
| 286 | |||
| 287 | config USB_NET2272_DMA | ||
| 288 | boolean "Support external DMA controller" | ||
| 289 | depends on USB_NET2272 && HAS_DMA | ||
| 290 | help | ||
| 291 | The NET2272 part can optionally support an external DMA | ||
| 292 | controller, but your board has to have support in the | ||
| 293 | driver itself. | ||
| 294 | |||
| 295 | If unsure, say "N" here. The driver works fine in PIO mode. | ||
| 296 | |||
| 297 | config USB_NET2280 | ||
| 298 | tristate "NetChip 228x / PLX USB338x" | ||
| 299 | depends on PCI | ||
| 300 | help | ||
| 301 | NetChip 2280 / 2282 is a PCI based USB peripheral controller which | ||
| 302 | supports both full and high speed USB 2.0 data transfers. | ||
| 303 | |||
| 304 | It has six configurable endpoints, as well as endpoint zero | ||
| 305 | (for control transfers) and several endpoints with dedicated | ||
| 306 | functions. | ||
| 307 | |||
| 308 | PLX 3380 / 3382 is a PCIe based USB peripheral controller which | ||
| 309 | supports full, high speed USB 2.0 and super speed USB 3.0 | ||
| 310 | data transfers. | ||
| 311 | |||
| 312 | It has eight configurable endpoints, as well as endpoint zero | ||
| 313 | (for control transfers) and several endpoints with dedicated | ||
| 314 | functions. | ||
| 315 | |||
| 316 | Say "y" to link the driver statically, or "m" to build a | ||
| 317 | dynamically linked module called "net2280" and force all | ||
| 318 | gadget drivers to also be dynamically linked. | ||
| 319 | |||
| 320 | config USB_GOKU | ||
| 321 | tristate "Toshiba TC86C001 'Goku-S'" | ||
| 322 | depends on PCI | ||
| 323 | help | ||
| 324 | The Toshiba TC86C001 is a PCI device which includes controllers | ||
| 325 | for full speed USB devices, IDE, I2C, SIO, plus a USB host (OHCI). | ||
| 326 | |||
| 327 | The device controller has three configurable (bulk or interrupt) | ||
| 328 | endpoints, plus endpoint zero (for control transfers). | ||
| 329 | |||
| 330 | Say "y" to link the driver statically, or "m" to build a | ||
| 331 | dynamically linked module called "goku_udc" and to force all | ||
| 332 | gadget drivers to also be dynamically linked. | ||
| 333 | |||
| 334 | config USB_EG20T | ||
| 335 | tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" | ||
| 336 | depends on PCI | ||
| 337 | help | ||
| 338 | This is a USB device driver for EG20T PCH. | ||
| 339 | EG20T PCH is the platform controller hub that is used in Intel's | ||
| 340 | general embedded platform. EG20T PCH has USB device interface. | ||
| 341 | Using this interface, it is able to access system devices connected | ||
| 342 | to USB device. | ||
| 343 | This driver enables USB device function. | ||
| 344 | USB device is a USB peripheral controller which | ||
| 345 | supports both full and high speed USB 2.0 data transfers. | ||
| 346 | This driver supports both control transfer and bulk transfer modes. | ||
| 347 | This driver dose not support interrupt transfer or isochronous | ||
| 348 | transfer modes. | ||
| 349 | |||
| 350 | This driver also can be used for LAPIS Semiconductor's ML7213 which is | ||
| 351 | for IVI(In-Vehicle Infotainment) use. | ||
| 352 | ML7831 is for general purpose use. | ||
| 353 | ML7213/ML7831 is companion chip for Intel Atom E6xx series. | ||
| 354 | ML7213/ML7831 is completely compatible for Intel EG20T PCH. | ||
| 355 | |||
| 356 | # | ||
| 357 | # LAST -- dummy/emulated controller | ||
| 358 | # | ||
| 359 | |||
| 360 | config USB_DUMMY_HCD | ||
| 361 | tristate "Dummy HCD (DEVELOPMENT)" | ||
| 362 | depends on USB=y || (USB=m && USB_GADGET=m) | ||
| 363 | help | ||
| 364 | This host controller driver emulates USB, looping all data transfer | ||
| 365 | requests back to a USB "gadget driver" in the same host. The host | ||
| 366 | side is the master; the gadget side is the slave. Gadget drivers | ||
| 367 | can be high, full, or low speed; and they have access to endpoints | ||
| 368 | like those from NET2280, PXA2xx, or SA1100 hardware. | ||
| 369 | |||
| 370 | This may help in some stages of creating a driver to embed in a | ||
| 371 | Linux device, since it lets you debug several parts of the gadget | ||
| 372 | driver without its hardware or drivers being involved. | ||
| 373 | |||
| 374 | Since such a gadget side driver needs to interoperate with a host | ||
| 375 | side Linux-USB device driver, this may help to debug both sides | ||
| 376 | of a USB protocol stack. | ||
| 377 | |||
| 378 | Say "y" to link the driver statically, or "m" to build a | ||
| 379 | dynamically linked module called "dummy_hcd" and force all | ||
| 380 | gadget drivers to also be dynamically linked. | ||
| 381 | |||
| 382 | # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears | ||
| 383 | # first and will be selected by default. | ||
| 384 | |||
| 385 | endmenu | ||
| @@ -0,0 +1,31 @@ | |||
| 1 | # | ||
| 2 | # USB peripheral controller drivers | ||
| 3 | # | ||
| 4 | obj-$(CONFIG_USB_GADGET) += udc-core.o | ||
| 5 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | ||
| 6 | obj-$(CONFIG_USB_NET2272) += net2272.o | ||
| 7 | obj-$(CONFIG_USB_NET2280) += net2280.o | ||
| 8 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o | ||
| 9 | obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o | ||
| 10 | obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o | ||
| 11 | obj-$(CONFIG_USB_GOKU) += goku_udc.o | ||
| 12 | obj-$(CONFIG_USB_OMAP) += omap_udc.o | ||
| 13 | obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o | ||
| 14 | obj-$(CONFIG_USB_AT91) += at91_udc.o | ||
| 15 | obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o | ||
| 16 | obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o | ||
| 17 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o | ||
| 18 | fsl_usb2_udc-y := fsl_udc_core.o | ||
| 19 | fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o | ||
| 20 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | ||
| 21 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | ||
| 22 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | ||
| 23 | obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o | ||
| 24 | obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o | ||
| 25 | obj-$(CONFIG_USB_EG20T) += pch_udc.o | ||
| 26 | obj-$(CONFIG_USB_MV_UDC) += mv_udc.o | ||
| 27 | mv_udc-y := mv_udc_core.o | ||
| 28 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | ||
| 29 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o | ||
| 30 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | ||
| 31 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -1979,7 +1979,7 @@ static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, · 1978 unmodified lines | |||
| 1979 | return eps; | 1979 | return eps; |
| 1980 | } | 1980 | } |
| 1981 | 1981 | ||
| 1982 | static int __init usba_udc_probe(struct platform_device *pdev) | 1982 | static int usba_udc_probe(struct platform_device *pdev) |
| 1983 | { | 1983 | { |
| 1984 | struct resource *regs, *fifo; | 1984 | struct resource *regs, *fifo; |
| 1985 | struct clk *pclk, *hclk; | 1985 | struct clk *pclk, *hclk; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -18,6 +18,8 @@ · 17 unmodified lines | |||
| 18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/io.h> | 19 | #include <linux/io.h> |
| 20 | 20 | ||
| 21 | #include "fsl_usb2_udc.h" | ||
| 22 | |||
| 21 | static struct clk *mxc_ahb_clk; | 23 | static struct clk *mxc_ahb_clk; |
| 22 | static struct clk *mxc_per_clk; | 24 | static struct clk *mxc_per_clk; |
| 23 | static struct clk *mxc_ipg_clk; | 25 | static struct clk *mxc_ipg_clk; |
| @@ -2539,7 +2539,7 @@ static int qe_udc_probe(struct platform_device *ofdev) · 2538 unmodified lines | |||
| 2539 | goto err2; | 2539 | goto err2; |
| 2540 | 2540 | ||
| 2541 | /* create a buf for ZLP send, need to remain zeroed */ | 2541 | /* create a buf for ZLP send, need to remain zeroed */ |
| 2542 | udc->nullbuf = kzalloc(256, GFP_KERNEL); | 2542 | udc->nullbuf = devm_kzalloc(&ofdev->dev, 256, GFP_KERNEL); |
| 2543 | if (udc->nullbuf == NULL) { | 2543 | if (udc->nullbuf == NULL) { |
| 2544 | dev_err(udc->dev, "cannot alloc nullbuf\n"); | 2544 | dev_err(udc->dev, "cannot alloc nullbuf\n"); |
| 2545 | ret = -ENOMEM; | 2545 | ret = -ENOMEM; |
| @@ -2547,10 +2547,10 @@ static int qe_udc_probe(struct platform_device *ofdev) · 1 unmodified line | |||
| 2547 | } | 2547 | } |
| 2548 | 2548 | ||
| 2549 | /* buffer for data of get_status request */ | 2549 | /* buffer for data of get_status request */ |
| 2550 | udc->statusbuf = kzalloc(2, GFP_KERNEL); | 2550 | udc->statusbuf = devm_kzalloc(&ofdev->dev, 2, GFP_KERNEL); |
| 2551 | if (udc->statusbuf == NULL) { | 2551 | if (udc->statusbuf == NULL) { |
| 2552 | ret = -ENOMEM; | 2552 | ret = -ENOMEM; |
| 2553 | goto err4; | 2553 | goto err3; |
| 2554 | } | 2554 | } |
| 2555 | 2555 | ||
| 2556 | udc->nullp = virt_to_phys((void *)udc->nullbuf); | 2556 | udc->nullp = virt_to_phys((void *)udc->nullbuf); |
| @@ -2581,13 +2581,13 @@ static int qe_udc_probe(struct platform_device *ofdev) · 24 unmodified lines | |||
| 2581 | if (ret) { | 2581 | if (ret) { |
| 2582 | dev_err(udc->dev, "cannot request irq %d err %d\n", | 2582 | dev_err(udc->dev, "cannot request irq %d err %d\n", |
| 2583 | udc->usb_irq, ret); | 2583 | udc->usb_irq, ret); |
| 2584 | goto err5; | 2584 | goto err4; |
| 2585 | } | 2585 | } |
| 2586 | 2586 | ||
| 2587 | ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget, | 2587 | ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget, |
| 2588 | qe_udc_release); | 2588 | qe_udc_release); |
| 2589 | if (ret) | 2589 | if (ret) |
| 2590 | goto err6; | 2590 | goto err5; |
| 2591 | 2591 | ||
| 2592 | platform_set_drvdata(ofdev, udc); | 2592 | platform_set_drvdata(ofdev, udc); |
| 2593 | dev_info(udc->dev, | 2593 | dev_info(udc->dev, |
| @@ -2595,9 +2595,9 @@ static int qe_udc_probe(struct platform_device *ofdev) · 1 unmodified line | |||
| 2595 | (udc->soc_type == PORT_QE) ? "QE" : "CPM"); | 2595 | (udc->soc_type == PORT_QE) ? "QE" : "CPM"); |
| 2596 | return 0; | 2596 | return 0; |
| 2597 | 2597 | ||
| 2598 | err6: | ||
| 2599 | free_irq(udc->usb_irq, udc); | ||
| 2600 | err5: | 2598 | err5: |
| 2599 | free_irq(udc->usb_irq, udc); | ||
| 2600 | err4: | ||
| 2601 | irq_dispose_mapping(udc->usb_irq); | 2601 | irq_dispose_mapping(udc->usb_irq); |
| 2602 | err_noirq: | 2602 | err_noirq: |
| 2603 | if (udc->nullmap) { | 2603 | if (udc->nullmap) { |
| @@ -2610,9 +2610,6 @@ err_noirq: · 6 unmodified lines | |||
| 2610 | udc->nullp, 256, | 2610 | udc->nullp, 256, |
| 2611 | DMA_TO_DEVICE); | 2611 | DMA_TO_DEVICE); |
| 2612 | } | 2612 | } |
| 2613 | kfree(udc->statusbuf); | ||
| 2614 | err4: | ||
| 2615 | kfree(udc->nullbuf); | ||
| 2616 | err3: | 2613 | err3: |
| 2617 | ep = &udc->eps[0]; | 2614 | ep = &udc->eps[0]; |
| 2618 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | 2615 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); |
| @@ -2660,8 +2657,6 @@ static int qe_udc_remove(struct platform_device *ofdev) · 41 unmodified lines | |||
| 2660 | udc->nullp, 256, | 2657 | udc->nullp, 256, |
| 2661 | DMA_TO_DEVICE); | 2658 | DMA_TO_DEVICE); |
| 2662 | } | 2659 | } |
| 2663 | kfree(udc->statusbuf); | ||
| 2664 | kfree(udc->nullbuf); | ||
| 2665 | 2660 | ||
| 2666 | ep = &udc->eps[0]; | 2661 | ep = &udc->eps[0]; |
| 2667 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | 2662 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); |
File renamed without changes.
| @@ -59,9 +59,9 @@ · 58 unmodified lines | |||
| 59 | static const char driver_name[] = "fsl-usb2-udc"; | 59 | static const char driver_name[] = "fsl-usb2-udc"; |
| 60 | static const char driver_desc[] = DRIVER_DESC; | 60 | static const char driver_desc[] = DRIVER_DESC; |
| 61 | 61 | ||
| 62 | static struct usb_dr_device *dr_regs; | 62 | static struct usb_dr_device __iomem *dr_regs; |
| 63 | 63 | ||
| 64 | static struct usb_sys_interface *usb_sys_regs; | 64 | static struct usb_sys_interface __iomem *usb_sys_regs; |
| 65 | 65 | ||
| 66 | /* it is initialized in probe() */ | 66 | /* it is initialized in probe() */ |
| 67 | static struct fsl_udc *udc_controller = NULL; | 67 | static struct fsl_udc *udc_controller = NULL; |
| @@ -159,6 +159,8 @@ static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata) {} · 91 unmodified lines | |||
| 159 | * request is still in progress. | 159 | * request is still in progress. |
| 160 | *--------------------------------------------------------------*/ | 160 | *--------------------------------------------------------------*/ |
| 161 | static void done(struct fsl_ep *ep, struct fsl_req *req, int status) | 161 | static void done(struct fsl_ep *ep, struct fsl_req *req, int status) |
| 162 | __releases(ep->udc->lock) | ||
| 163 | __acquires(ep->udc->lock) | ||
| 162 | { | 164 | { |
| 163 | struct fsl_udc *udc = NULL; | 165 | struct fsl_udc *udc = NULL; |
| 164 | unsigned char stopped = ep->stopped; | 166 | unsigned char stopped = ep->stopped; |
| @@ -1392,6 +1394,8 @@ stall: · 1227 unmodified lines | |||
| 1392 | 1394 | ||
| 1393 | static void setup_received_irq(struct fsl_udc *udc, | 1395 | static void setup_received_irq(struct fsl_udc *udc, |
| 1394 | struct usb_ctrlrequest *setup) | 1396 | struct usb_ctrlrequest *setup) |
| 1397 | __releases(udc->lock) | ||
| 1398 | __acquires(udc->lock) | ||
| 1395 | { | 1399 | { |
| 1396 | u16 wValue = le16_to_cpu(setup->wValue); | 1400 | u16 wValue = le16_to_cpu(setup->wValue); |
| 1397 | u16 wIndex = le16_to_cpu(setup->wIndex); | 1401 | u16 wIndex = le16_to_cpu(setup->wIndex); |
| @@ -1957,8 +1961,7 @@ static int fsl_udc_start(struct usb_gadget *g, · 559 unmodified lines | |||
| 1957 | &udc_controller->gadget); | 1961 | &udc_controller->gadget); |
| 1958 | if (retval < 0) { | 1962 | if (retval < 0) { |
| 1959 | ERR("can't bind to transceiver\n"); | 1963 | ERR("can't bind to transceiver\n"); |
| 1960 | driver->unbind(&udc_controller->gadget); | 1964 | udc_controller->driver = NULL; |
| 1961 | udc_controller->driver = 0; | ||
| 1962 | return retval; | 1965 | return retval; |
| 1963 | } | 1966 | } |
| 1964 | } | 1967 | } |
| @@ -2246,7 +2249,7 @@ static void fsl_udc_release(struct device *dev) · 281 unmodified lines | |||
| 2246 | * init resource for globle controller | 2249 | * init resource for globle controller |
| 2247 | * Return the udc handle on success or NULL on failure | 2250 | * Return the udc handle on success or NULL on failure |
| 2248 | ------------------------------------------------------------------*/ | 2251 | ------------------------------------------------------------------*/ |
| 2249 | static int __init struct_udc_setup(struct fsl_udc *udc, | 2252 | static int struct_udc_setup(struct fsl_udc *udc, |
| 2250 | struct platform_device *pdev) | 2253 | struct platform_device *pdev) |
| 2251 | { | 2254 | { |
| 2252 | struct fsl_usb2_platform_data *pdata; | 2255 | struct fsl_usb2_platform_data *pdata; |
| @@ -2298,7 +2301,7 @@ static int __init struct_udc_setup(struct fsl_udc *udc, · 45 unmodified lines | |||
| 2298 | * ep0out is not used so do nothing here | 2301 | * ep0out is not used so do nothing here |
| 2299 | * ep0in should be taken care | 2302 | * ep0in should be taken care |
| 2300 | *--------------------------------------------------------------*/ | 2303 | *--------------------------------------------------------------*/ |
| 2301 | static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index, | 2304 | static int struct_ep_setup(struct fsl_udc *udc, unsigned char index, |
| 2302 | char *name, int link) | 2305 | char *name, int link) |
| 2303 | { | 2306 | { |
| 2304 | struct fsl_ep *ep = &udc->eps[index]; | 2307 | struct fsl_ep *ep = &udc->eps[index]; |
| @@ -2331,7 +2334,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index, · 26 unmodified lines | |||
| 2331 | * all intialization operations implemented here except enabling usb_intr reg | 2334 | * all intialization operations implemented here except enabling usb_intr reg |
| 2332 | * board setup should have been done in the platform code | 2335 | * board setup should have been done in the platform code |
| 2333 | */ | 2336 | */ |
| 2334 | static int __init fsl_udc_probe(struct platform_device *pdev) | 2337 | static int fsl_udc_probe(struct platform_device *pdev) |
| 2335 | { | 2338 | { |
| 2336 | struct fsl_usb2_platform_data *pdata; | 2339 | struct fsl_usb2_platform_data *pdata; |
| 2337 | struct resource *res; | 2340 | struct resource *res; |
| @@ -2380,7 +2383,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev) · 42 unmodified lines | |||
| 2380 | goto err_release_mem_region; | 2383 | goto err_release_mem_region; |
| 2381 | } | 2384 | } |
| 2382 | 2385 | ||
| 2383 | pdata->regs = (void *)dr_regs; | 2386 | pdata->regs = (void __iomem *)dr_regs; |
| 2384 | 2387 | ||
| 2385 | /* | 2388 | /* |
| 2386 | * do platform specific init: check the clock, grab/config pins, etc. | 2389 | * do platform specific init: check the clock, grab/config pins, etc. |
| @@ -12,6 +12,9 @@ · 11 unmodified lines | |||
| 12 | #ifndef __FSL_USB2_UDC_H | 12 | #ifndef __FSL_USB2_UDC_H |
| 13 | #define __FSL_USB2_UDC_H | 13 | #define __FSL_USB2_UDC_H |
| 14 | 14 | ||
| 15 | #include <linux/usb/ch9.h> | ||
| 16 | #include <linux/usb/gadget.h> | ||
| 17 | |||
| 15 | /* ### define USB registers here | 18 | /* ### define USB registers here |
| 16 | */ | 19 | */ |
| 17 | #define USB_MAX_CTRL_PAYLOAD 64 | 20 | #define USB_MAX_CTRL_PAYLOAD 64 |
| @@ -1325,8 +1325,6 @@ static int fusb300_udc_stop(struct usb_gadget *g, · 1324 unmodified lines | |||
| 1325 | { | 1325 | { |
| 1326 | struct fusb300 *fusb300 = to_fusb300(g); | 1326 | struct fusb300 *fusb300 = to_fusb300(g); |
| 1327 | 1327 | ||
| 1328 | driver->unbind(&fusb300->gadget); | ||
| 1329 | |||
| 1330 | init_controller(fusb300); | 1328 | init_controller(fusb300); |
| 1331 | fusb300->driver = NULL; | 1329 | fusb300->driver = NULL; |
| 1332 | 1330 | ||
| @@ -1359,7 +1357,7 @@ static int __exit fusb300_remove(struct platform_device *pdev) · 26 unmodified lines | |||
| 1359 | return 0; | 1357 | return 0; |
| 1360 | } | 1358 | } |
| 1361 | 1359 | ||
| 1362 | static int __init fusb300_probe(struct platform_device *pdev) | 1360 | static int fusb300_probe(struct platform_device *pdev) |
| 1363 | { | 1361 | { |
| 1364 | struct resource *res, *ires, *ires1; | 1362 | struct resource *res, *ires, *ires1; |
| 1365 | void __iomem *reg = NULL; | 1363 | void __iomem *reg = NULL; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -2213,7 +2213,7 @@ out: · 2212 unmodified lines | |||
| 2213 | return retval; | 2213 | return retval; |
| 2214 | } | 2214 | } |
| 2215 | 2215 | ||
| 2216 | static struct of_device_id gr_match[] = { | 2216 | static const struct of_device_id gr_match[] = { |
| 2217 | {.name = "GAISLER_USBDC"}, | 2217 | {.name = "GAISLER_USBDC"}, |
| 2218 | {.name = "01_021"}, | 2218 | {.name = "01_021"}, |
| 2219 | {}, | 2219 | {}, |
File renamed without changes.
| @@ -3036,7 +3036,7 @@ struct lpc32xx_usbd_cfg lpc32xx_usbddata = { · 3035 unmodified lines | |||
| 3036 | 3036 | ||
| 3037 | static u64 lpc32xx_usbd_dmamask = ~(u32) 0x7F; | 3037 | static u64 lpc32xx_usbd_dmamask = ~(u32) 0x7F; |
| 3038 | 3038 | ||
| 3039 | static int __init lpc32xx_udc_probe(struct platform_device *pdev) | 3039 | static int lpc32xx_udc_probe(struct platform_device *pdev) |
| 3040 | { | 3040 | { |
| 3041 | struct device *dev = &pdev->dev; | 3041 | struct device *dev = &pdev->dev; |
| 3042 | struct lpc32xx_udc *udc; | 3042 | struct lpc32xx_udc *udc; |
| @@ -3045,11 +3045,10 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev) · 2 unmodified lines | |||
| 3045 | dma_addr_t dma_handle; | 3045 | dma_addr_t dma_handle; |
| 3046 | struct device_node *isp1301_node; | 3046 | struct device_node *isp1301_node; |
| 3047 | 3047 | ||
| 3048 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); | 3048 | udc = kmemdup(&controller_template, sizeof(*udc), GFP_KERNEL); |
| 3049 | if (!udc) | 3049 | if (!udc) |
| 3050 | return -ENOMEM; | 3050 | return -ENOMEM; |
| 3051 | 3051 | ||
| 3052 | memcpy(udc, &controller_template, sizeof(*udc)); | ||
| 3053 | for (i = 0; i <= 15; i++) | 3052 | for (i = 0; i <= 15; i++) |
| 3054 | udc->ep[i].udc = udc; | 3053 | udc->ep[i].udc = udc; |
| 3055 | udc->gadget.ep0 = &udc->ep[0].ep; | 3054 | udc->gadget.ep0 = &udc->ep[0].ep; |
| @@ -3397,7 +3396,7 @@ static int lpc32xx_udc_resume(struct platform_device *pdev) · 341 unmodified lines | |||
| 3397 | #endif | 3396 | #endif |
| 3398 | 3397 | ||
| 3399 | #ifdef CONFIG_OF | 3398 | #ifdef CONFIG_OF |
| 3400 | static struct of_device_id lpc32xx_udc_of_match[] = { | 3399 | static const struct of_device_id lpc32xx_udc_of_match[] = { |
| 3401 | { .compatible = "nxp,lpc3220-udc", }, | 3400 | { .compatible = "nxp,lpc3220-udc", }, |
| 3402 | { }, | 3401 | { }, |
| 3403 | }; | 3402 | }; |
| @@ -1492,8 +1492,6 @@ static int m66592_udc_stop(struct usb_gadget *g, · 1491 unmodified lines | |||
| 1492 | 1492 | ||
| 1493 | m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); | 1493 | m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); |
| 1494 | 1494 | ||
| 1495 | driver->unbind(&m66592->gadget); | ||
| 1496 | |||
| 1497 | init_controller(m66592); | 1495 | init_controller(m66592); |
| 1498 | disable_controller(m66592); | 1496 | disable_controller(m66592); |
| 1499 | 1497 | ||
| @@ -1553,7 +1551,7 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) · 53 unmodified lines | |||
| 1553 | { | 1551 | { |
| 1554 | } | 1552 | } |
| 1555 | 1553 | ||
| 1556 | static int __init m66592_probe(struct platform_device *pdev) | 1554 | static int m66592_probe(struct platform_device *pdev) |
| 1557 | { | 1555 | { |
| 1558 | struct resource *res, *ires; | 1556 | struct resource *res, *ires; |
| 1559 | void __iomem *reg = NULL; | 1557 | void __iomem *reg = NULL; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
| @@ -332,7 +332,7 @@ static int queue_dtd(struct mv_ep *ep, struct mv_req *req) · 331 unmodified lines | |||
| 332 | /* clear active and halt bit, in case set from a previous error */ | 332 | /* clear active and halt bit, in case set from a previous error */ |
| 333 | dqh->size_ioc_int_sts &= ~(DTD_STATUS_ACTIVE | DTD_STATUS_HALTED); | 333 | dqh->size_ioc_int_sts &= ~(DTD_STATUS_ACTIVE | DTD_STATUS_HALTED); |
| 334 | 334 | ||
| 335 | /* Ensure that updates to the QH will occure before priming. */ | 335 | /* Ensure that updates to the QH will occur before priming. */ |
| 336 | wmb(); | 336 | wmb(); |
| 337 | 337 | ||
| 338 | /* Prime the Endpoint */ | 338 | /* Prime the Endpoint */ |
| @@ -1656,7 +1656,7 @@ static void handle_setup_packet(struct mv_udc *udc, u8 ep_num, · 1317 unmodified lines | |||
| 1656 | dev_dbg(&udc->dev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", | 1656 | dev_dbg(&udc->dev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", |
| 1657 | setup->bRequestType, setup->bRequest, | 1657 | setup->bRequestType, setup->bRequest, |
| 1658 | setup->wValue, setup->wIndex, setup->wLength); | 1658 | setup->wValue, setup->wIndex, setup->wLength); |
| 1659 | /* We process some stardard setup requests here */ | 1659 | /* We process some standard setup requests here */ |
| 1660 | if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | 1660 | if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
| 1661 | switch (setup->bRequest) { | 1661 | switch (setup->bRequest) { |
| 1662 | case USB_REQ_GET_STATUS: | 1662 | case USB_REQ_GET_STATUS: |
| @@ -1453,7 +1453,7 @@ static int net2272_start(struct usb_gadget *_gadget, · 1452 unmodified lines | |||
| 1453 | struct net2272 *dev; | 1453 | struct net2272 *dev; |
| 1454 | unsigned i; | 1454 | unsigned i; |
| 1455 | 1455 | ||
| 1456 | if (!driver || !driver->unbind || !driver->setup || | 1456 | if (!driver || !driver->setup || |
| 1457 | driver->max_speed != USB_SPEED_HIGH) | 1457 | driver->max_speed != USB_SPEED_HIGH) |
| 1458 | return -EINVAL; | 1458 | return -EINVAL; |
| 1459 | 1459 | ||
File renamed without changes.
| @@ -0,0 +1,3827 @@ | |||
| 1 | /* | ||
| 2 | * Driver for the PLX NET2280 USB device controller. | ||
| 3 | * Specs and errata are available from <http://www.plxtech.com>. | ||
| 4 | * | ||
| 5 | * PLX Technology Inc. (formerly NetChip Technology) supported the | ||
| 6 | * development of this driver. | ||
| 7 | * | ||
| 8 | * | ||
| 9 | * CODE STATUS HIGHLIGHTS | ||
| 10 | * | ||
| 11 | * This driver should work well with most "gadget" drivers, including | ||
| 12 | * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers | ||
| 13 | * as well as Gadget Zero and Gadgetfs. | ||
| 14 | * | ||
| 15 | * DMA is enabled by default. Drivers using transfer queues might use | ||
| 16 | * DMA chaining to remove IRQ latencies between transfers. (Except when | ||
| 17 | * short OUT transfers happen.) Drivers can use the req->no_interrupt | ||
| 18 | * hint to completely eliminate some IRQs, if a later IRQ is guaranteed | ||
| 19 | * and DMA chaining is enabled. | ||
| 20 | * | ||
| 21 | * MSI is enabled by default. The legacy IRQ is used if MSI couldn't | ||
| 22 | * be enabled. | ||
| 23 | * | ||
| 24 | * Note that almost all the errata workarounds here are only needed for | ||
| 25 | * rev1 chips. Rev1a silicon (0110) fixes almost all of them. | ||
| 26 | */ | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Copyright (C) 2003 David Brownell | ||
| 30 | * Copyright (C) 2003-2005 PLX Technology, Inc. | ||
| 31 | * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS | ||
| 32 | * | ||
| 33 | * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility | ||
| 34 | * with 2282 chip | ||
| 35 | * | ||
| 36 | * Modified Ricardo Ribalda Qtechnology AS to provide compatibility | ||
| 37 | * with usb 338x chip. Based on PLX driver | ||
| 38 | * | ||
| 39 | * This program is free software; you can redistribute it and/or modify | ||
| 40 | * it under the terms of the GNU General Public License as published by | ||
| 41 | * the Free Software Foundation; either version 2 of the License, or | ||
| 42 | * (at your option) any later version. | ||
| 43 | */ | ||
| 44 | |||
| 45 | #include <linux/module.h> | ||
| 46 | #include <linux/pci.h> | ||
| 47 | #include <linux/dma-mapping.h> | ||
| 48 | #include <linux/kernel.h> | ||
| 49 | #include <linux/delay.h> | ||
| 50 | #include <linux/ioport.h> | ||
| 51 | #include <linux/slab.h> | ||
| 52 | #include <linux/errno.h> | ||
| 53 | #include <linux/init.h> | ||
| 54 | #include <linux/timer.h> | ||
| 55 | #include <linux/list.h> | ||
| 56 | #include <linux/interrupt.h> | ||
| 57 | #include <linux/moduleparam.h> | ||
| 58 | #include <linux/device.h> | ||
| 59 | #include <linux/usb/ch9.h> | ||
| 60 | #include <linux/usb/gadget.h> | ||
| 61 | #include <linux/prefetch.h> | ||
| 62 | #include <linux/io.h> | ||
| 63 | |||
| 64 | #include <asm/byteorder.h> | ||
| 65 | #include <asm/irq.h> | ||
| 66 | #include <asm/unaligned.h> | ||
| 67 | |||
| 68 | #define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller" | ||
| 69 | #define DRIVER_VERSION "2005 Sept 27/v3.0" | ||
| 70 | |||
| 71 | #define EP_DONTUSE 13 /* nonzero */ | ||
| 72 | |||
| 73 | #define USE_RDK_LEDS /* GPIO pins control three LEDs */ | ||
| 74 | |||
| 75 | |||
| 76 | static const char driver_name[] = "net2280"; | ||
| 77 | static const char driver_desc[] = DRIVER_DESC; | ||
| 78 | |||
| 79 | static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 }; | ||
| 80 | static const char ep0name[] = "ep0"; | ||
| 81 | static const char *const ep_name[] = { | ||
| 82 | ep0name, | ||
| 83 | "ep-a", "ep-b", "ep-c", "ep-d", | ||
| 84 | "ep-e", "ep-f", "ep-g", "ep-h", | ||
| 85 | }; | ||
| 86 | |||
| 87 | /* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO) | ||
| 88 | * use_dma_chaining -- dma descriptor queueing gives even more irq reduction | ||
| 89 | * | ||
| 90 | * The net2280 DMA engines are not tightly integrated with their FIFOs; | ||
| 91 | * not all cases are (yet) handled well in this driver or the silicon. | ||
| 92 | * Some gadget drivers work better with the dma support here than others. | ||
| 93 | * These two parameters let you use PIO or more aggressive DMA. | ||
| 94 | */ | ||
| 95 | static bool use_dma = true; | ||
| 96 | static bool use_dma_chaining; | ||
| 97 | static bool use_msi = true; | ||
| 98 | |||
| 99 | /* "modprobe net2280 use_dma=n" etc */ | ||
| 100 | module_param(use_dma, bool, 0444); | ||
| 101 | module_param(use_dma_chaining, bool, 0444); | ||
| 102 | module_param(use_msi, bool, 0444); | ||
| 103 | |||
| 104 | /* mode 0 == ep-{a,b,c,d} 1K fifo each | ||
| 105 | * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable | ||
| 106 | * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable | ||
| 107 | */ | ||
| 108 | static ushort fifo_mode; | ||
| 109 | |||
| 110 | /* "modprobe net2280 fifo_mode=1" etc */ | ||
| 111 | module_param(fifo_mode, ushort, 0644); | ||
| 112 | |||
| 113 | /* enable_suspend -- When enabled, the driver will respond to | ||
| 114 | * USB suspend requests by powering down the NET2280. Otherwise, | ||
| 115 | * USB suspend requests will be ignored. This is acceptable for | ||
| 116 | * self-powered devices | ||
| 117 | */ | ||
| 118 | static bool enable_suspend; | ||
| 119 | |||
| 120 | /* "modprobe net2280 enable_suspend=1" etc */ | ||
| 121 | module_param(enable_suspend, bool, 0444); | ||
| 122 | |||
| 123 | /* force full-speed operation */ | ||
| 124 | static bool full_speed; | ||
| 125 | module_param(full_speed, bool, 0444); | ||
| 126 | MODULE_PARM_DESC(full_speed, "force full-speed mode -- for testing only!"); | ||
| 127 | |||
| 128 | #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") | ||
| 129 | |||
| 130 | static char *type_string(u8 bmAttributes) | ||
| 131 | { | ||
| 132 | switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { | ||
| 133 | case USB_ENDPOINT_XFER_BULK: return "bulk"; | ||
| 134 | case USB_ENDPOINT_XFER_ISOC: return "iso"; | ||
| 135 | case USB_ENDPOINT_XFER_INT: return "intr"; | ||
| 136 | } | ||
| 137 | return "control"; | ||
| 138 | } | ||
| 139 | |||
| 140 | #include "net2280.h" | ||
| 141 | |||
| 142 | #define valid_bit cpu_to_le32(BIT(VALID_BIT)) | ||
| 143 | #define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE)) | ||
| 144 | |||
| 145 | /*-------------------------------------------------------------------------*/ | ||
| 146 | static inline void enable_pciirqenb(struct net2280_ep *ep) | ||
| 147 | { | ||
| 148 | u32 tmp = readl(&ep->dev->regs->pciirqenb0); | ||
| 149 | |||
| 150 | if (ep->dev->quirks & PLX_LEGACY) | ||
| 151 | tmp |= BIT(ep->num); | ||
| 152 | else | ||
| 153 | tmp |= BIT(ep_bit[ep->num]); | ||
| 154 | writel(tmp, &ep->dev->regs->pciirqenb0); | ||
| 155 | |||
| 156 | return; | ||
| 157 | } | ||
| 158 | |||
| 159 | static int | ||
| 160 | net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | ||
| 161 | { | ||
| 162 | struct net2280 *dev; | ||
| 163 | struct net2280_ep *ep; | ||
| 164 | u32 max, tmp; | ||
| 165 | unsigned long flags; | ||
| 166 | static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 }; | ||
| 167 | |||
| 168 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 169 | if (!_ep || !desc || ep->desc || _ep->name == ep0name || | ||
| 170 | desc->bDescriptorType != USB_DT_ENDPOINT) | ||
| 171 | return -EINVAL; | ||
| 172 | dev = ep->dev; | ||
| 173 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 174 | return -ESHUTDOWN; | ||
| 175 | |||
| 176 | /* erratum 0119 workaround ties up an endpoint number */ | ||
| 177 | if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) | ||
| 178 | return -EDOM; | ||
| 179 | |||
| 180 | if (dev->quirks & PLX_SUPERSPEED) { | ||
| 181 | if ((desc->bEndpointAddress & 0x0f) >= 0x0c) | ||
| 182 | return -EDOM; | ||
| 183 | ep->is_in = !!usb_endpoint_dir_in(desc); | ||
| 184 | if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) | ||
| 185 | return -EINVAL; | ||
| 186 | } | ||
| 187 | |||
| 188 | /* sanity check ep-e/ep-f since their fifos are small */ | ||
| 189 | max = usb_endpoint_maxp(desc) & 0x1fff; | ||
| 190 | if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) | ||
| 191 | return -ERANGE; | ||
| 192 | |||
| 193 | spin_lock_irqsave(&dev->lock, flags); | ||
| 194 | _ep->maxpacket = max & 0x7ff; | ||
| 195 | ep->desc = desc; | ||
| 196 | |||
| 197 | /* ep_reset() has already been called */ | ||
| 198 | ep->stopped = 0; | ||
| 199 | ep->wedged = 0; | ||
| 200 | ep->out_overflow = 0; | ||
| 201 | |||
| 202 | /* set speed-dependent max packet; may kick in high bandwidth */ | ||
| 203 | set_max_speed(ep, max); | ||
| 204 | |||
| 205 | /* FIFO lines can't go to different packets. PIO is ok, so | ||
| 206 | * use it instead of troublesome (non-bulk) multi-packet DMA. | ||
| 207 | */ | ||
| 208 | if (ep->dma && (max % 4) != 0 && use_dma_chaining) { | ||
| 209 | ep_dbg(ep->dev, "%s, no dma for maxpacket %d\n", | ||
| 210 | ep->ep.name, ep->ep.maxpacket); | ||
| 211 | ep->dma = NULL; | ||
| 212 | } | ||
| 213 | |||
| 214 | /* set type, direction, address; reset fifo counters */ | ||
| 215 | writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); | ||
| 216 | tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | ||
| 217 | if (tmp == USB_ENDPOINT_XFER_INT) { | ||
| 218 | /* erratum 0105 workaround prevents hs NYET */ | ||
| 219 | if (dev->chiprev == 0100 && | ||
| 220 | dev->gadget.speed == USB_SPEED_HIGH && | ||
| 221 | !(desc->bEndpointAddress & USB_DIR_IN)) | ||
| 222 | writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE), | ||
| 223 | &ep->regs->ep_rsp); | ||
| 224 | } else if (tmp == USB_ENDPOINT_XFER_BULK) { | ||
| 225 | /* catch some particularly blatant driver bugs */ | ||
| 226 | if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) || | ||
| 227 | (dev->gadget.speed == USB_SPEED_HIGH && max != 512) || | ||
| 228 | (dev->gadget.speed == USB_SPEED_FULL && max > 64)) { | ||
| 229 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 230 | return -ERANGE; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); | ||
| 234 | /* Enable this endpoint */ | ||
| 235 | if (dev->quirks & PLX_LEGACY) { | ||
| 236 | tmp <<= ENDPOINT_TYPE; | ||
| 237 | tmp |= desc->bEndpointAddress; | ||
| 238 | /* default full fifo lines */ | ||
| 239 | tmp |= (4 << ENDPOINT_BYTE_COUNT); | ||
| 240 | tmp |= BIT(ENDPOINT_ENABLE); | ||
| 241 | ep->is_in = (tmp & USB_DIR_IN) != 0; | ||
| 242 | } else { | ||
| 243 | /* In Legacy mode, only OUT endpoints are used */ | ||
| 244 | if (dev->enhanced_mode && ep->is_in) { | ||
| 245 | tmp <<= IN_ENDPOINT_TYPE; | ||
| 246 | tmp |= BIT(IN_ENDPOINT_ENABLE); | ||
| 247 | /* Not applicable to Legacy */ | ||
| 248 | tmp |= BIT(ENDPOINT_DIRECTION); | ||
| 249 | } else { | ||
| 250 | tmp <<= OUT_ENDPOINT_TYPE; | ||
| 251 | tmp |= BIT(OUT_ENDPOINT_ENABLE); | ||
| 252 | tmp |= (ep->is_in << ENDPOINT_DIRECTION); | ||
| 253 | } | ||
| 254 | |||
| 255 | tmp |= usb_endpoint_num(desc); | ||
| 256 | tmp |= (ep->ep.maxburst << MAX_BURST_SIZE); | ||
| 257 | } | ||
| 258 | |||
| 259 | /* Make sure all the registers are written before ep_rsp*/ | ||
| 260 | wmb(); | ||
| 261 | |||
| 262 | /* for OUT transfers, block the rx fifo until a read is posted */ | ||
| 263 | if (!ep->is_in) | ||
| 264 | writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 265 | else if (!(dev->quirks & PLX_2280)) { | ||
| 266 | /* Added for 2282, Don't use nak packets on an in endpoint, | ||
| 267 | * this was ignored on 2280 | ||
| 268 | */ | ||
| 269 | writel(BIT(CLEAR_NAK_OUT_PACKETS) | | ||
| 270 | BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); | ||
| 271 | } | ||
| 272 | |||
| 273 | writel(tmp, &ep->cfg->ep_cfg); | ||
| 274 | |||
| 275 | /* enable irqs */ | ||
| 276 | if (!ep->dma) { /* pio, per-packet */ | ||
| 277 | enable_pciirqenb(ep); | ||
| 278 | |||
| 279 | tmp = BIT(DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) | | ||
| 280 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE); | ||
| 281 | if (dev->quirks & PLX_2280) | ||
| 282 | tmp |= readl(&ep->regs->ep_irqenb); | ||
| 283 | writel(tmp, &ep->regs->ep_irqenb); | ||
| 284 | } else { /* dma, per-request */ | ||
| 285 | tmp = BIT((8 + ep->num)); /* completion */ | ||
| 286 | tmp |= readl(&dev->regs->pciirqenb1); | ||
| 287 | writel(tmp, &dev->regs->pciirqenb1); | ||
| 288 | |||
| 289 | /* for short OUT transfers, dma completions can't | ||
| 290 | * advance the queue; do it pio-style, by hand. | ||
| 291 | * NOTE erratum 0112 workaround #2 | ||
| 292 | */ | ||
| 293 | if ((desc->bEndpointAddress & USB_DIR_IN) == 0) { | ||
| 294 | tmp = BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE); | ||
| 295 | writel(tmp, &ep->regs->ep_irqenb); | ||
| 296 | |||
| 297 | enable_pciirqenb(ep); | ||
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 301 | tmp = desc->bEndpointAddress; | ||
| 302 | ep_dbg(dev, "enabled %s (ep%d%s-%s) %s max %04x\n", | ||
| 303 | _ep->name, tmp & 0x0f, DIR_STRING(tmp), | ||
| 304 | type_string(desc->bmAttributes), | ||
| 305 | ep->dma ? "dma" : "pio", max); | ||
| 306 | |||
| 307 | /* pci writes may still be posted */ | ||
| 308 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 309 | return 0; | ||
| 310 | } | ||
| 311 | |||
| 312 | static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) | ||
| 313 | { | ||
| 314 | u32 result; | ||
| 315 | |||
| 316 | do { | ||
| 317 | result = readl(ptr); | ||
| 318 | if (result == ~(u32)0) /* "device unplugged" */ | ||
| 319 | return -ENODEV; | ||
| 320 | result &= mask; | ||
| 321 | if (result == done) | ||
| 322 | return 0; | ||
| 323 | udelay(1); | ||
| 324 | usec--; | ||
| 325 | } while (usec > 0); | ||
| 326 | return -ETIMEDOUT; | ||
| 327 | } | ||
| 328 | |||
| 329 | static const struct usb_ep_ops net2280_ep_ops; | ||
| 330 | |||
| 331 | static void ep_reset_228x(struct net2280_regs __iomem *regs, | ||
| 332 | struct net2280_ep *ep) | ||
| 333 | { | ||
| 334 | u32 tmp; | ||
| 335 | |||
| 336 | ep->desc = NULL; | ||
| 337 | INIT_LIST_HEAD(&ep->queue); | ||
| 338 | |||
| 339 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); | ||
| 340 | ep->ep.ops = &net2280_ep_ops; | ||
| 341 | |||
| 342 | /* disable the dma, irqs, endpoint... */ | ||
| 343 | if (ep->dma) { | ||
| 344 | writel(0, &ep->dma->dmactl); | ||
| 345 | writel(BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) | | ||
| 346 | BIT(DMA_TRANSACTION_DONE_INTERRUPT) | | ||
| 347 | BIT(DMA_ABORT), | ||
| 348 | &ep->dma->dmastat); | ||
| 349 | |||
| 350 | tmp = readl(®s->pciirqenb0); | ||
| 351 | tmp &= ~BIT(ep->num); | ||
| 352 | writel(tmp, ®s->pciirqenb0); | ||
| 353 | } else { | ||
| 354 | tmp = readl(®s->pciirqenb1); | ||
| 355 | tmp &= ~BIT((8 + ep->num)); /* completion */ | ||
| 356 | writel(tmp, ®s->pciirqenb1); | ||
| 357 | } | ||
| 358 | writel(0, &ep->regs->ep_irqenb); | ||
| 359 | |||
| 360 | /* init to our chosen defaults, notably so that we NAK OUT | ||
| 361 | * packets until the driver queues a read (+note erratum 0112) | ||
| 362 | */ | ||
| 363 | if (!ep->is_in || (ep->dev->quirks & PLX_2280)) { | ||
| 364 | tmp = BIT(SET_NAK_OUT_PACKETS_MODE) | | ||
| 365 | BIT(SET_NAK_OUT_PACKETS) | | ||
| 366 | BIT(CLEAR_EP_HIDE_STATUS_PHASE) | | ||
| 367 | BIT(CLEAR_INTERRUPT_MODE); | ||
| 368 | } else { | ||
| 369 | /* added for 2282 */ | ||
| 370 | tmp = BIT(CLEAR_NAK_OUT_PACKETS_MODE) | | ||
| 371 | BIT(CLEAR_NAK_OUT_PACKETS) | | ||
| 372 | BIT(CLEAR_EP_HIDE_STATUS_PHASE) | | ||
| 373 | BIT(CLEAR_INTERRUPT_MODE); | ||
| 374 | } | ||
| 375 | |||
| 376 | if (ep->num != 0) { | ||
| 377 | tmp |= BIT(CLEAR_ENDPOINT_TOGGLE) | | ||
| 378 | BIT(CLEAR_ENDPOINT_HALT); | ||
| 379 | } | ||
| 380 | writel(tmp, &ep->regs->ep_rsp); | ||
| 381 | |||
| 382 | /* scrub most status bits, and flush any fifo state */ | ||
| 383 | if (ep->dev->quirks & PLX_2280) | ||
| 384 | tmp = BIT(FIFO_OVERFLOW) | | ||
| 385 | BIT(FIFO_UNDERFLOW); | ||
| 386 | else | ||
| 387 | tmp = 0; | ||
| 388 | |||
| 389 | writel(tmp | BIT(TIMEOUT) | | ||
| 390 | BIT(USB_STALL_SENT) | | ||
| 391 | BIT(USB_IN_NAK_SENT) | | ||
| 392 | BIT(USB_IN_ACK_RCVD) | | ||
| 393 | BIT(USB_OUT_PING_NAK_SENT) | | ||
| 394 | BIT(USB_OUT_ACK_SENT) | | ||
| 395 | BIT(FIFO_FLUSH) | | ||
| 396 | BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) | | ||
| 397 | BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) | | ||
| 398 | BIT(DATA_PACKET_RECEIVED_INTERRUPT) | | ||
| 399 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | | ||
| 400 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | | ||
| 401 | BIT(DATA_IN_TOKEN_INTERRUPT), | ||
| 402 | &ep->regs->ep_stat); | ||
| 403 | |||
| 404 | /* fifo size is handled separately */ | ||
| 405 | } | ||
| 406 | |||
| 407 | static void ep_reset_338x(struct net2280_regs __iomem *regs, | ||
| 408 | struct net2280_ep *ep) | ||
| 409 | { | ||
| 410 | u32 tmp, dmastat; | ||
| 411 | |||
| 412 | ep->desc = NULL; | ||
| 413 | INIT_LIST_HEAD(&ep->queue); | ||
| 414 | |||
| 415 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); | ||
| 416 | ep->ep.ops = &net2280_ep_ops; | ||
| 417 | |||
| 418 | /* disable the dma, irqs, endpoint... */ | ||
| 419 | if (ep->dma) { | ||
| 420 | writel(0, &ep->dma->dmactl); | ||
| 421 | writel(BIT(DMA_ABORT_DONE_INTERRUPT) | | ||
| 422 | BIT(DMA_PAUSE_DONE_INTERRUPT) | | ||
| 423 | BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) | | ||
| 424 | BIT(DMA_TRANSACTION_DONE_INTERRUPT), | ||
| 425 | /* | BIT(DMA_ABORT), */ | ||
| 426 | &ep->dma->dmastat); | ||
| 427 | |||
| 428 | dmastat = readl(&ep->dma->dmastat); | ||
| 429 | if (dmastat == 0x5002) { | ||
| 430 | ep_warn(ep->dev, "The dmastat return = %x!!\n", | ||
| 431 | dmastat); | ||
| 432 | writel(0x5a, &ep->dma->dmastat); | ||
| 433 | } | ||
| 434 | |||
| 435 | tmp = readl(®s->pciirqenb0); | ||
| 436 | tmp &= ~BIT(ep_bit[ep->num]); | ||
| 437 | writel(tmp, ®s->pciirqenb0); | ||
| 438 | } else { | ||
| 439 | if (ep->num < 5) { | ||
| 440 | tmp = readl(®s->pciirqenb1); | ||
| 441 | tmp &= ~BIT((8 + ep->num)); /* completion */ | ||
| 442 | writel(tmp, ®s->pciirqenb1); | ||
| 443 | } | ||
| 444 | } | ||
| 445 | writel(0, &ep->regs->ep_irqenb); | ||
| 446 | |||
| 447 | writel(BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) | | ||
| 448 | BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) | | ||
| 449 | BIT(FIFO_OVERFLOW) | | ||
| 450 | BIT(DATA_PACKET_RECEIVED_INTERRUPT) | | ||
| 451 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | | ||
| 452 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | | ||
| 453 | BIT(DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat); | ||
| 454 | } | ||
| 455 | |||
| 456 | static void nuke(struct net2280_ep *); | ||
| 457 | |||
| 458 | static int net2280_disable(struct usb_ep *_ep) | ||
| 459 | { | ||
| 460 | struct net2280_ep *ep; | ||
| 461 | unsigned long flags; | ||
| 462 | |||
| 463 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 464 | if (!_ep || !ep->desc || _ep->name == ep0name) | ||
| 465 | return -EINVAL; | ||
| 466 | |||
| 467 | spin_lock_irqsave(&ep->dev->lock, flags); | ||
| 468 | nuke(ep); | ||
| 469 | |||
| 470 | if (ep->dev->quirks & PLX_SUPERSPEED) | ||
| 471 | ep_reset_338x(ep->dev->regs, ep); | ||
| 472 | else | ||
| 473 | ep_reset_228x(ep->dev->regs, ep); | ||
| 474 | |||
| 475 | ep_vdbg(ep->dev, "disabled %s %s\n", | ||
| 476 | ep->dma ? "dma" : "pio", _ep->name); | ||
| 477 | |||
| 478 | /* synch memory views with the device */ | ||
| 479 | (void)readl(&ep->cfg->ep_cfg); | ||
| 480 | |||
| 481 | if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4) | ||
| 482 | ep->dma = &ep->dev->dma[ep->num - 1]; | ||
| 483 | |||
| 484 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
| 485 | return 0; | ||
| 486 | } | ||
| 487 | |||
| 488 | /*-------------------------------------------------------------------------*/ | ||
| 489 | |||
| 490 | static struct usb_request | ||
| 491 | *net2280_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | ||
| 492 | { | ||
| 493 | struct net2280_ep *ep; | ||
| 494 | struct net2280_request *req; | ||
| 495 | |||
| 496 | if (!_ep) | ||
| 497 | return NULL; | ||
| 498 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 499 | |||
| 500 | req = kzalloc(sizeof(*req), gfp_flags); | ||
| 501 | if (!req) | ||
| 502 | return NULL; | ||
| 503 | |||
| 504 | INIT_LIST_HEAD(&req->queue); | ||
| 505 | |||
| 506 | /* this dma descriptor may be swapped with the previous dummy */ | ||
| 507 | if (ep->dma) { | ||
| 508 | struct net2280_dma *td; | ||
| 509 | |||
| 510 | td = pci_pool_alloc(ep->dev->requests, gfp_flags, | ||
| 511 | &req->td_dma); | ||
| 512 | if (!td) { | ||
| 513 | kfree(req); | ||
| 514 | return NULL; | ||
| 515 | } | ||
| 516 | td->dmacount = 0; /* not VALID */ | ||
| 517 | td->dmadesc = td->dmaaddr; | ||
| 518 | req->td = td; | ||
| 519 | } | ||
| 520 | return &req->req; | ||
| 521 | } | ||
| 522 | |||
| 523 | static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
| 524 | { | ||
| 525 | struct net2280_ep *ep; | ||
| 526 | struct net2280_request *req; | ||
| 527 | |||
| 528 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 529 | if (!_ep || !_req) | ||
| 530 | return; | ||
| 531 | |||
| 532 | req = container_of(_req, struct net2280_request, req); | ||
| 533 | WARN_ON(!list_empty(&req->queue)); | ||
| 534 | if (req->td) | ||
| 535 | pci_pool_free(ep->dev->requests, req->td, req->td_dma); | ||
| 536 | kfree(req); | ||
| 537 | } | ||
| 538 | |||
| 539 | /*-------------------------------------------------------------------------*/ | ||
| 540 | |||
| 541 | /* load a packet into the fifo we use for usb IN transfers. | ||
| 542 | * works for all endpoints. | ||
| 543 | * | ||
| 544 | * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo | ||
| 545 | * at a time, but this code is simpler because it knows it only writes | ||
| 546 | * one packet. ep-a..ep-d should use dma instead. | ||
| 547 | */ | ||
| 548 | static void write_fifo(struct net2280_ep *ep, struct usb_request *req) | ||
| 549 | { | ||
| 550 | struct net2280_ep_regs __iomem *regs = ep->regs; | ||
| 551 | u8 *buf; | ||
| 552 | u32 tmp; | ||
| 553 | unsigned count, total; | ||
| 554 | |||
| 555 | /* INVARIANT: fifo is currently empty. (testable) */ | ||
| 556 | |||
| 557 | if (req) { | ||
| 558 | buf = req->buf + req->actual; | ||
| 559 | prefetch(buf); | ||
| 560 | total = req->length - req->actual; | ||
| 561 | } else { | ||
| 562 | total = 0; | ||
| 563 | buf = NULL; | ||
| 564 | } | ||
| 565 | |||
| 566 | /* write just one packet at a time */ | ||
| 567 | count = ep->ep.maxpacket; | ||
| 568 | if (count > total) /* min() cannot be used on a bitfield */ | ||
| 569 | count = total; | ||
| 570 | |||
| 571 | ep_vdbg(ep->dev, "write %s fifo (IN) %d bytes%s req %p\n", | ||
| 572 | ep->ep.name, count, | ||
| 573 | (count != ep->ep.maxpacket) ? " (short)" : "", | ||
| 574 | req); | ||
| 575 | while (count >= 4) { | ||
| 576 | /* NOTE be careful if you try to align these. fifo lines | ||
| 577 | * should normally be full (4 bytes) and successive partial | ||
| 578 | * lines are ok only in certain cases. | ||
| 579 | */ | ||
| 580 | tmp = get_unaligned((u32 *)buf); | ||
| 581 | cpu_to_le32s(&tmp); | ||
| 582 | writel(tmp, ®s->ep_data); | ||
| 583 | buf += 4; | ||
| 584 | count -= 4; | ||
| 585 | } | ||
| 586 | |||
| 587 | /* last fifo entry is "short" unless we wrote a full packet. | ||
| 588 | * also explicitly validate last word in (periodic) transfers | ||
| 589 | * when maxpacket is not a multiple of 4 bytes. | ||
| 590 | */ | ||
| 591 | if (count || total < ep->ep.maxpacket) { | ||
| 592 | tmp = count ? get_unaligned((u32 *)buf) : count; | ||
| 593 | cpu_to_le32s(&tmp); | ||
| 594 | set_fifo_bytecount(ep, count & 0x03); | ||
| 595 | writel(tmp, ®s->ep_data); | ||
| 596 | } | ||
| 597 | |||
| 598 | /* pci writes may still be posted */ | ||
| 599 | } | ||
| 600 | |||
| 601 | /* work around erratum 0106: PCI and USB race over the OUT fifo. | ||
| 602 | * caller guarantees chiprev 0100, out endpoint is NAKing, and | ||
| 603 | * there's no real data in the fifo. | ||
| 604 | * | ||
| 605 | * NOTE: also used in cases where that erratum doesn't apply: | ||
| 606 | * where the host wrote "too much" data to us. | ||
| 607 | */ | ||
| 608 | static void out_flush(struct net2280_ep *ep) | ||
| 609 | { | ||
| 610 | u32 __iomem *statp; | ||
| 611 | u32 tmp; | ||
| 612 | |||
| 613 | ASSERT_OUT_NAKING(ep); | ||
| 614 | |||
| 615 | statp = &ep->regs->ep_stat; | ||
| 616 | writel(BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | | ||
| 617 | BIT(DATA_PACKET_RECEIVED_INTERRUPT), | ||
| 618 | statp); | ||
| 619 | writel(BIT(FIFO_FLUSH), statp); | ||
| 620 | /* Make sure that stap is written */ | ||
| 621 | mb(); | ||
| 622 | tmp = readl(statp); | ||
| 623 | if (tmp & BIT(DATA_OUT_PING_TOKEN_INTERRUPT) && | ||
| 624 | /* high speed did bulk NYET; fifo isn't filling */ | ||
| 625 | ep->dev->gadget.speed == USB_SPEED_FULL) { | ||
| 626 | unsigned usec; | ||
| 627 | |||
| 628 | usec = 50; /* 64 byte bulk/interrupt */ | ||
| 629 | handshake(statp, BIT(USB_OUT_PING_NAK_SENT), | ||
| 630 | BIT(USB_OUT_PING_NAK_SENT), usec); | ||
| 631 | /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */ | ||
| 632 | } | ||
| 633 | } | ||
| 634 | |||
| 635 | /* unload packet(s) from the fifo we use for usb OUT transfers. | ||
| 636 | * returns true iff the request completed, because of short packet | ||
| 637 | * or the request buffer having filled with full packets. | ||
| 638 | * | ||
| 639 | * for ep-a..ep-d this will read multiple packets out when they | ||
| 640 | * have been accepted. | ||
| 641 | */ | ||
| 642 | static int read_fifo(struct net2280_ep *ep, struct net2280_request *req) | ||
| 643 | { | ||
| 644 | struct net2280_ep_regs __iomem *regs = ep->regs; | ||
| 645 | u8 *buf = req->req.buf + req->req.actual; | ||
| 646 | unsigned count, tmp, is_short; | ||
| 647 | unsigned cleanup = 0, prevent = 0; | ||
| 648 | |||
| 649 | /* erratum 0106 ... packets coming in during fifo reads might | ||
| 650 | * be incompletely rejected. not all cases have workarounds. | ||
| 651 | */ | ||
| 652 | if (ep->dev->chiprev == 0x0100 && | ||
| 653 | ep->dev->gadget.speed == USB_SPEED_FULL) { | ||
| 654 | udelay(1); | ||
| 655 | tmp = readl(&ep->regs->ep_stat); | ||
| 656 | if ((tmp & BIT(NAK_OUT_PACKETS))) | ||
| 657 | cleanup = 1; | ||
| 658 | else if ((tmp & BIT(FIFO_FULL))) { | ||
| 659 | start_out_naking(ep); | ||
| 660 | prevent = 1; | ||
| 661 | } | ||
| 662 | /* else: hope we don't see the problem */ | ||
| 663 | } | ||
| 664 | |||
| 665 | /* never overflow the rx buffer. the fifo reads packets until | ||
| 666 | * it sees a short one; we might not be ready for them all. | ||
| 667 | */ | ||
| 668 | prefetchw(buf); | ||
| 669 | count = readl(®s->ep_avail); | ||
| 670 | if (unlikely(count == 0)) { | ||
| 671 | udelay(1); | ||
| 672 | tmp = readl(&ep->regs->ep_stat); | ||
| 673 | count = readl(®s->ep_avail); | ||
| 674 | /* handled that data already? */ | ||
| 675 | if (count == 0 && (tmp & BIT(NAK_OUT_PACKETS)) == 0) | ||
| 676 | return 0; | ||
| 677 | } | ||
| 678 | |||
| 679 | tmp = req->req.length - req->req.actual; | ||
| 680 | if (count > tmp) { | ||
| 681 | /* as with DMA, data overflow gets flushed */ | ||
| 682 | if ((tmp % ep->ep.maxpacket) != 0) { | ||
| 683 | ep_err(ep->dev, | ||
| 684 | "%s out fifo %d bytes, expected %d\n", | ||
| 685 | ep->ep.name, count, tmp); | ||
| 686 | req->req.status = -EOVERFLOW; | ||
| 687 | cleanup = 1; | ||
| 688 | /* NAK_OUT_PACKETS will be set, so flushing is safe; | ||
| 689 | * the next read will start with the next packet | ||
| 690 | */ | ||
| 691 | } /* else it's a ZLP, no worries */ | ||
| 692 | count = tmp; | ||
| 693 | } | ||
| 694 | req->req.actual += count; | ||
| 695 | |||
| 696 | is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0); | ||
| 697 | |||
| 698 | ep_vdbg(ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n", | ||
| 699 | ep->ep.name, count, is_short ? " (short)" : "", | ||
| 700 | cleanup ? " flush" : "", prevent ? " nak" : "", | ||
| 701 | req, req->req.actual, req->req.length); | ||
| 702 | |||
| 703 | while (count >= 4) { | ||
| 704 | tmp = readl(®s->ep_data); | ||
| 705 | cpu_to_le32s(&tmp); | ||
| 706 | put_unaligned(tmp, (u32 *)buf); | ||
| 707 | buf += 4; | ||
| 708 | count -= 4; | ||
| 709 | } | ||
| 710 | if (count) { | ||
| 711 | tmp = readl(®s->ep_data); | ||
| 712 | /* LE conversion is implicit here: */ | ||
| 713 | do { | ||
| 714 | *buf++ = (u8) tmp; | ||
| 715 | tmp >>= 8; | ||
| 716 | } while (--count); | ||
| 717 | } | ||
| 718 | if (cleanup) | ||
| 719 | out_flush(ep); | ||
| 720 | if (prevent) { | ||
| 721 | writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 722 | (void) readl(&ep->regs->ep_rsp); | ||
| 723 | } | ||
| 724 | |||
| 725 | return is_short || ((req->req.actual == req->req.length) && | ||
| 726 | !req->req.zero); | ||
| 727 | } | ||
| 728 | |||
| 729 | /* fill out dma descriptor to match a given request */ | ||
| 730 | static void fill_dma_desc(struct net2280_ep *ep, | ||
| 731 | struct net2280_request *req, int valid) | ||
| 732 | { | ||
| 733 | struct net2280_dma *td = req->td; | ||
| 734 | u32 dmacount = req->req.length; | ||
| 735 | |||
| 736 | /* don't let DMA continue after a short OUT packet, | ||
| 737 | * so overruns can't affect the next transfer. | ||
| 738 | * in case of overruns on max-size packets, we can't | ||
| 739 | * stop the fifo from filling but we can flush it. | ||
| 740 | */ | ||
| 741 | if (ep->is_in) | ||
| 742 | dmacount |= BIT(DMA_DIRECTION); | ||
| 743 | if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) || | ||
| 744 | !(ep->dev->quirks & PLX_2280)) | ||
| 745 | dmacount |= BIT(END_OF_CHAIN); | ||
| 746 | |||
| 747 | req->valid = valid; | ||
| 748 | if (valid) | ||
| 749 | dmacount |= BIT(VALID_BIT); | ||
| 750 | if (likely(!req->req.no_interrupt || !use_dma_chaining)) | ||
| 751 | dmacount |= BIT(DMA_DONE_INTERRUPT_ENABLE); | ||
| 752 | |||
| 753 | /* td->dmadesc = previously set by caller */ | ||
| 754 | td->dmaaddr = cpu_to_le32 (req->req.dma); | ||
| 755 | |||
| 756 | /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */ | ||
| 757 | wmb(); | ||
| 758 | td->dmacount = cpu_to_le32(dmacount); | ||
| 759 | } | ||
| 760 | |||
| 761 | static const u32 dmactl_default = | ||
| 762 | BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) | | ||
| 763 | BIT(DMA_CLEAR_COUNT_ENABLE) | | ||
| 764 | /* erratum 0116 workaround part 1 (use POLLING) */ | ||
| 765 | (POLL_100_USEC << DESCRIPTOR_POLLING_RATE) | | ||
| 766 | BIT(DMA_VALID_BIT_POLLING_ENABLE) | | ||
| 767 | BIT(DMA_VALID_BIT_ENABLE) | | ||
| 768 | BIT(DMA_SCATTER_GATHER_ENABLE) | | ||
| 769 | /* erratum 0116 workaround part 2 (no AUTOSTART) */ | ||
| 770 | BIT(DMA_ENABLE); | ||
| 771 | |||
| 772 | static inline void spin_stop_dma(struct net2280_dma_regs __iomem *dma) | ||
| 773 | { | ||
| 774 | handshake(&dma->dmactl, BIT(DMA_ENABLE), 0, 50); | ||
| 775 | } | ||
| 776 | |||
| 777 | static inline void stop_dma(struct net2280_dma_regs __iomem *dma) | ||
| 778 | { | ||
| 779 | writel(readl(&dma->dmactl) & ~BIT(DMA_ENABLE), &dma->dmactl); | ||
| 780 | spin_stop_dma(dma); | ||
| 781 | } | ||
| 782 | |||
| 783 | static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma) | ||
| 784 | { | ||
| 785 | struct net2280_dma_regs __iomem *dma = ep->dma; | ||
| 786 | unsigned int tmp = BIT(VALID_BIT) | (ep->is_in << DMA_DIRECTION); | ||
| 787 | |||
| 788 | if (!(ep->dev->quirks & PLX_2280)) | ||
| 789 | tmp |= BIT(END_OF_CHAIN); | ||
| 790 | |||
| 791 | writel(tmp, &dma->dmacount); | ||
| 792 | writel(readl(&dma->dmastat), &dma->dmastat); | ||
| 793 | |||
| 794 | writel(td_dma, &dma->dmadesc); | ||
| 795 | if (ep->dev->quirks & PLX_SUPERSPEED) | ||
| 796 | dmactl |= BIT(DMA_REQUEST_OUTSTANDING); | ||
| 797 | writel(dmactl, &dma->dmactl); | ||
| 798 | |||
| 799 | /* erratum 0116 workaround part 3: pci arbiter away from net2280 */ | ||
| 800 | (void) readl(&ep->dev->pci->pcimstctl); | ||
| 801 | |||
| 802 | writel(BIT(DMA_START), &dma->dmastat); | ||
| 803 | |||
| 804 | if (!ep->is_in) | ||
| 805 | stop_out_naking(ep); | ||
| 806 | } | ||
| 807 | |||
| 808 | static void start_dma(struct net2280_ep *ep, struct net2280_request *req) | ||
| 809 | { | ||
| 810 | u32 tmp; | ||
| 811 | struct net2280_dma_regs __iomem *dma = ep->dma; | ||
| 812 | |||
| 813 | /* FIXME can't use DMA for ZLPs */ | ||
| 814 | |||
| 815 | /* on this path we "know" there's no dma active (yet) */ | ||
| 816 | WARN_ON(readl(&dma->dmactl) & BIT(DMA_ENABLE)); | ||
| 817 | writel(0, &ep->dma->dmactl); | ||
| 818 | |||
| 819 | /* previous OUT packet might have been short */ | ||
| 820 | if (!ep->is_in && (readl(&ep->regs->ep_stat) & | ||
| 821 | BIT(NAK_OUT_PACKETS))) { | ||
| 822 | writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT), | ||
| 823 | &ep->regs->ep_stat); | ||
| 824 | |||
| 825 | tmp = readl(&ep->regs->ep_avail); | ||
| 826 | if (tmp) { | ||
| 827 | writel(readl(&dma->dmastat), &dma->dmastat); | ||
| 828 | |||
| 829 | /* transfer all/some fifo data */ | ||
| 830 | writel(req->req.dma, &dma->dmaaddr); | ||
| 831 | tmp = min(tmp, req->req.length); | ||
| 832 | |||
| 833 | /* dma irq, faking scatterlist status */ | ||
| 834 | req->td->dmacount = cpu_to_le32(req->req.length - tmp); | ||
| 835 | writel(BIT(DMA_DONE_INTERRUPT_ENABLE) | tmp, | ||
| 836 | &dma->dmacount); | ||
| 837 | req->td->dmadesc = 0; | ||
| 838 | req->valid = 1; | ||
| 839 | |||
| 840 | writel(BIT(DMA_ENABLE), &dma->dmactl); | ||
| 841 | writel(BIT(DMA_START), &dma->dmastat); | ||
| 842 | return; | ||
| 843 | } | ||
| 844 | } | ||
| 845 | |||
| 846 | tmp = dmactl_default; | ||
| 847 | |||
| 848 | /* force packet boundaries between dma requests, but prevent the | ||
| 849 | * controller from automagically writing a last "short" packet | ||
| 850 | * (zero length) unless the driver explicitly said to do that. | ||
| 851 | */ | ||
| 852 | if (ep->is_in) { | ||
| 853 | if (likely((req->req.length % ep->ep.maxpacket) || | ||
| 854 | req->req.zero)){ | ||
| 855 | tmp |= BIT(DMA_FIFO_VALIDATE); | ||
| 856 | ep->in_fifo_validate = 1; | ||
| 857 | } else | ||
| 858 | ep->in_fifo_validate = 0; | ||
| 859 | } | ||
| 860 | |||
| 861 | /* init req->td, pointing to the current dummy */ | ||
| 862 | req->td->dmadesc = cpu_to_le32 (ep->td_dma); | ||
| 863 | fill_dma_desc(ep, req, 1); | ||
| 864 | |||
| 865 | if (!use_dma_chaining) | ||
| 866 | req->td->dmacount |= cpu_to_le32(BIT(END_OF_CHAIN)); | ||
| 867 | |||
| 868 | start_queue(ep, tmp, req->td_dma); | ||
| 869 | } | ||
| 870 | |||
| 871 | static inline void resume_dma(struct net2280_ep *ep) | ||
| 872 | { | ||
| 873 | writel(readl(&ep->dma->dmactl) | BIT(DMA_ENABLE), &ep->dma->dmactl); | ||
| 874 | |||
| 875 | ep->dma_started = true; | ||
| 876 | } | ||
| 877 | |||
| 878 | static inline void ep_stop_dma(struct net2280_ep *ep) | ||
| 879 | { | ||
| 880 | writel(readl(&ep->dma->dmactl) & ~BIT(DMA_ENABLE), &ep->dma->dmactl); | ||
| 881 | spin_stop_dma(ep->dma); | ||
| 882 | |||
| 883 | ep->dma_started = false; | ||
| 884 | } | ||
| 885 | |||
| 886 | static inline void | ||
| 887 | queue_dma(struct net2280_ep *ep, struct net2280_request *req, int valid) | ||
| 888 | { | ||
| 889 | struct net2280_dma *end; | ||
| 890 | dma_addr_t tmp; | ||
| 891 | |||
| 892 | /* swap new dummy for old, link; fill and maybe activate */ | ||
| 893 | end = ep->dummy; | ||
| 894 | ep->dummy = req->td; | ||
| 895 | req->td = end; | ||
| 896 | |||
| 897 | tmp = ep->td_dma; | ||
| 898 | ep->td_dma = req->td_dma; | ||
| 899 | req->td_dma = tmp; | ||
| 900 | |||
| 901 | end->dmadesc = cpu_to_le32 (ep->td_dma); | ||
| 902 | |||
| 903 | fill_dma_desc(ep, req, valid); | ||
| 904 | } | ||
| 905 | |||
| 906 | static void | ||
| 907 | done(struct net2280_ep *ep, struct net2280_request *req, int status) | ||
| 908 | { | ||
| 909 | struct net2280 *dev; | ||
| 910 | unsigned stopped = ep->stopped; | ||
| 911 | |||
| 912 | list_del_init(&req->queue); | ||
| 913 | |||
| 914 | if (req->req.status == -EINPROGRESS) | ||
| 915 | req->req.status = status; | ||
| 916 | else | ||
| 917 | status = req->req.status; | ||
| 918 | |||
| 919 | dev = ep->dev; | ||
| 920 | if (ep->dma) | ||
| 921 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); | ||
| 922 | |||
| 923 | if (status && status != -ESHUTDOWN) | ||
| 924 | ep_vdbg(dev, "complete %s req %p stat %d len %u/%u\n", | ||
| 925 | ep->ep.name, &req->req, status, | ||
| 926 | req->req.actual, req->req.length); | ||
| 927 | |||
| 928 | /* don't modify queue heads during completion callback */ | ||
| 929 | ep->stopped = 1; | ||
| 930 | spin_unlock(&dev->lock); | ||
| 931 | req->req.complete(&ep->ep, &req->req); | ||
| 932 | spin_lock(&dev->lock); | ||
| 933 | ep->stopped = stopped; | ||
| 934 | } | ||
| 935 | |||
| 936 | /*-------------------------------------------------------------------------*/ | ||
| 937 | |||
| 938 | static int | ||
| 939 | net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | ||
| 940 | { | ||
| 941 | struct net2280_request *req; | ||
| 942 | struct net2280_ep *ep; | ||
| 943 | struct net2280 *dev; | ||
| 944 | unsigned long flags; | ||
| 945 | |||
| 946 | /* we always require a cpu-view buffer, so that we can | ||
| 947 | * always use pio (as fallback or whatever). | ||
| 948 | */ | ||
| 949 | req = container_of(_req, struct net2280_request, req); | ||
| 950 | if (!_req || !_req->complete || !_req->buf || | ||
| 951 | !list_empty(&req->queue)) | ||
| 952 | return -EINVAL; | ||
| 953 | if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) | ||
| 954 | return -EDOM; | ||
| 955 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 956 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 957 | return -EINVAL; | ||
| 958 | dev = ep->dev; | ||
| 959 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 960 | return -ESHUTDOWN; | ||
| 961 | |||
| 962 | /* FIXME implement PIO fallback for ZLPs with DMA */ | ||
| 963 | if (ep->dma && _req->length == 0) | ||
| 964 | return -EOPNOTSUPP; | ||
| 965 | |||
| 966 | /* set up dma mapping in case the caller didn't */ | ||
| 967 | if (ep->dma) { | ||
| 968 | int ret; | ||
| 969 | |||
| 970 | ret = usb_gadget_map_request(&dev->gadget, _req, | ||
| 971 | ep->is_in); | ||
| 972 | if (ret) | ||
| 973 | return ret; | ||
| 974 | } | ||
| 975 | |||
| 976 | #if 0 | ||
| 977 | ep_vdbg(dev, "%s queue req %p, len %d buf %p\n", | ||
| 978 | _ep->name, _req, _req->length, _req->buf); | ||
| 979 | #endif | ||
| 980 | |||
| 981 | spin_lock_irqsave(&dev->lock, flags); | ||
| 982 | |||
| 983 | _req->status = -EINPROGRESS; | ||
| 984 | _req->actual = 0; | ||
| 985 | |||
| 986 | /* kickstart this i/o queue? */ | ||
| 987 | if (list_empty(&ep->queue) && !ep->stopped) { | ||
| 988 | /* DMA request while EP halted */ | ||
| 989 | if (ep->dma && | ||
| 990 | (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)) && | ||
| 991 | (dev->quirks & PLX_SUPERSPEED)) { | ||
| 992 | int valid = 1; | ||
| 993 | if (ep->is_in) { | ||
| 994 | int expect; | ||
| 995 | expect = likely(req->req.zero || | ||
| 996 | ((req->req.length % | ||
| 997 | ep->ep.maxpacket) != 0)); | ||
| 998 | if (expect != ep->in_fifo_validate) | ||
| 999 | valid = 0; | ||
| 1000 | } | ||
| 1001 | queue_dma(ep, req, valid); | ||
| 1002 | } | ||
| 1003 | /* use DMA if the endpoint supports it, else pio */ | ||
| 1004 | else if (ep->dma) | ||
| 1005 | start_dma(ep, req); | ||
| 1006 | else { | ||
| 1007 | /* maybe there's no control data, just status ack */ | ||
| 1008 | if (ep->num == 0 && _req->length == 0) { | ||
| 1009 | allow_status(ep); | ||
| 1010 | done(ep, req, 0); | ||
| 1011 | ep_vdbg(dev, "%s status ack\n", ep->ep.name); | ||
| 1012 | goto done; | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | /* PIO ... stuff the fifo, or unblock it. */ | ||
| 1016 | if (ep->is_in) | ||
| 1017 | write_fifo(ep, _req); | ||
| 1018 | else if (list_empty(&ep->queue)) { | ||
| 1019 | u32 s; | ||
| 1020 | |||
| 1021 | /* OUT FIFO might have packet(s) buffered */ | ||
| 1022 | s = readl(&ep->regs->ep_stat); | ||
| 1023 | if ((s & BIT(FIFO_EMPTY)) == 0) { | ||
| 1024 | /* note: _req->short_not_ok is | ||
| 1025 | * ignored here since PIO _always_ | ||
| 1026 | * stops queue advance here, and | ||
| 1027 | * _req->status doesn't change for | ||
| 1028 | * short reads (only _req->actual) | ||
| 1029 | */ | ||
| 1030 | if (read_fifo(ep, req) && | ||
| 1031 | ep->num == 0) { | ||
| 1032 | done(ep, req, 0); | ||
| 1033 | allow_status(ep); | ||
| 1034 | /* don't queue it */ | ||
| 1035 | req = NULL; | ||
| 1036 | } else if (read_fifo(ep, req) && | ||
| 1037 | ep->num != 0) { | ||
| 1038 | done(ep, req, 0); | ||
| 1039 | req = NULL; | ||
| 1040 | } else | ||
| 1041 | s = readl(&ep->regs->ep_stat); | ||
| 1042 | } | ||
| 1043 | |||
| 1044 | /* don't NAK, let the fifo fill */ | ||
| 1045 | if (req && (s & BIT(NAK_OUT_PACKETS))) | ||
| 1046 | writel(BIT(CLEAR_NAK_OUT_PACKETS), | ||
| 1047 | &ep->regs->ep_rsp); | ||
| 1048 | } | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | } else if (ep->dma) { | ||
| 1052 | int valid = 1; | ||
| 1053 | |||
| 1054 | if (ep->is_in) { | ||
| 1055 | int expect; | ||
| 1056 | |||
| 1057 | /* preventing magic zlps is per-engine state, not | ||
| 1058 | * per-transfer; irq logic must recover hiccups. | ||
| 1059 | */ | ||
| 1060 | expect = likely(req->req.zero || | ||
| 1061 | (req->req.length % ep->ep.maxpacket)); | ||
| 1062 | if (expect != ep->in_fifo_validate) | ||
| 1063 | valid = 0; | ||
| 1064 | } | ||
| 1065 | queue_dma(ep, req, valid); | ||
| 1066 | |||
| 1067 | } /* else the irq handler advances the queue. */ | ||
| 1068 | |||
| 1069 | ep->responded = 1; | ||
| 1070 | if (req) | ||
| 1071 | list_add_tail(&req->queue, &ep->queue); | ||
| 1072 | done: | ||
| 1073 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1074 | |||
| 1075 | /* pci writes may still be posted */ | ||
| 1076 | return 0; | ||
| 1077 | } | ||
| 1078 | |||
| 1079 | static inline void | ||
| 1080 | dma_done(struct net2280_ep *ep, struct net2280_request *req, u32 dmacount, | ||
| 1081 | int status) | ||
| 1082 | { | ||
| 1083 | req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount); | ||
| 1084 | done(ep, req, status); | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | static void restart_dma(struct net2280_ep *ep); | ||
| 1088 | |||
| 1089 | static void scan_dma_completions(struct net2280_ep *ep) | ||
| 1090 | { | ||
| 1091 | /* only look at descriptors that were "naturally" retired, | ||
| 1092 | * so fifo and list head state won't matter | ||
| 1093 | */ | ||
| 1094 | while (!list_empty(&ep->queue)) { | ||
| 1095 | struct net2280_request *req; | ||
| 1096 | u32 tmp; | ||
| 1097 | |||
| 1098 | req = list_entry(ep->queue.next, | ||
| 1099 | struct net2280_request, queue); | ||
| 1100 | if (!req->valid) | ||
| 1101 | break; | ||
| 1102 | rmb(); | ||
| 1103 | tmp = le32_to_cpup(&req->td->dmacount); | ||
| 1104 | if ((tmp & BIT(VALID_BIT)) != 0) | ||
| 1105 | break; | ||
| 1106 | |||
| 1107 | /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short" | ||
| 1108 | * cases where DMA must be aborted; this code handles | ||
| 1109 | * all non-abort DMA completions. | ||
| 1110 | */ | ||
| 1111 | if (unlikely(req->td->dmadesc == 0)) { | ||
| 1112 | /* paranoia */ | ||
| 1113 | tmp = readl(&ep->dma->dmacount); | ||
| 1114 | if (tmp & DMA_BYTE_COUNT_MASK) | ||
| 1115 | break; | ||
| 1116 | /* single transfer mode */ | ||
| 1117 | dma_done(ep, req, tmp, 0); | ||
| 1118 | break; | ||
| 1119 | } else if (!ep->is_in && | ||
| 1120 | (req->req.length % ep->ep.maxpacket) != 0) { | ||
| 1121 | tmp = readl(&ep->regs->ep_stat); | ||
| 1122 | if (ep->dev->quirks & PLX_SUPERSPEED) | ||
| 1123 | return dma_done(ep, req, tmp, 0); | ||
| 1124 | |||
| 1125 | /* AVOID TROUBLE HERE by not issuing short reads from | ||
| 1126 | * your gadget driver. That helps avoids errata 0121, | ||
| 1127 | * 0122, and 0124; not all cases trigger the warning. | ||
| 1128 | */ | ||
| 1129 | if ((tmp & BIT(NAK_OUT_PACKETS)) == 0) { | ||
| 1130 | ep_warn(ep->dev, "%s lost packet sync!\n", | ||
| 1131 | ep->ep.name); | ||
| 1132 | req->req.status = -EOVERFLOW; | ||
| 1133 | } else { | ||
| 1134 | tmp = readl(&ep->regs->ep_avail); | ||
| 1135 | if (tmp) { | ||
| 1136 | /* fifo gets flushed later */ | ||
| 1137 | ep->out_overflow = 1; | ||
| 1138 | ep_dbg(ep->dev, | ||
| 1139 | "%s dma, discard %d len %d\n", | ||
| 1140 | ep->ep.name, tmp, | ||
| 1141 | req->req.length); | ||
| 1142 | req->req.status = -EOVERFLOW; | ||
| 1143 | } | ||
| 1144 | } | ||
| 1145 | } | ||
| 1146 | dma_done(ep, req, tmp, 0); | ||
| 1147 | } | ||
| 1148 | } | ||
| 1149 | |||
| 1150 | static void restart_dma(struct net2280_ep *ep) | ||
| 1151 | { | ||
| 1152 | struct net2280_request *req; | ||
| 1153 | u32 dmactl = dmactl_default; | ||
| 1154 | |||
| 1155 | if (ep->stopped) | ||
| 1156 | return; | ||
| 1157 | req = list_entry(ep->queue.next, struct net2280_request, queue); | ||
| 1158 | |||
| 1159 | if (!use_dma_chaining) { | ||
| 1160 | start_dma(ep, req); | ||
| 1161 | return; | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | /* the 2280 will be processing the queue unless queue hiccups after | ||
| 1165 | * the previous transfer: | ||
| 1166 | * IN: wanted automagic zlp, head doesn't (or vice versa) | ||
| 1167 | * DMA_FIFO_VALIDATE doesn't init from dma descriptors. | ||
| 1168 | * OUT: was "usb-short", we must restart. | ||
| 1169 | */ | ||
| 1170 | if (ep->is_in && !req->valid) { | ||
| 1171 | struct net2280_request *entry, *prev = NULL; | ||
| 1172 | int reqmode, done = 0; | ||
| 1173 | |||
| 1174 | ep_dbg(ep->dev, "%s dma hiccup td %p\n", ep->ep.name, req->td); | ||
| 1175 | ep->in_fifo_validate = likely(req->req.zero || | ||
| 1176 | (req->req.length % ep->ep.maxpacket) != 0); | ||
| 1177 | if (ep->in_fifo_validate) | ||
| 1178 | dmactl |= BIT(DMA_FIFO_VALIDATE); | ||
| 1179 | list_for_each_entry(entry, &ep->queue, queue) { | ||
| 1180 | __le32 dmacount; | ||
| 1181 | |||
| 1182 | if (entry == req) | ||
| 1183 | continue; | ||
| 1184 | dmacount = entry->td->dmacount; | ||
| 1185 | if (!done) { | ||
| 1186 | reqmode = likely(entry->req.zero || | ||
| 1187 | (entry->req.length % ep->ep.maxpacket)); | ||
| 1188 | if (reqmode == ep->in_fifo_validate) { | ||
| 1189 | entry->valid = 1; | ||
| 1190 | dmacount |= valid_bit; | ||
| 1191 | entry->td->dmacount = dmacount; | ||
| 1192 | prev = entry; | ||
| 1193 | continue; | ||
| 1194 | } else { | ||
| 1195 | /* force a hiccup */ | ||
| 1196 | prev->td->dmacount |= dma_done_ie; | ||
| 1197 | done = 1; | ||
| 1198 | } | ||
| 1199 | } | ||
| 1200 | |||
| 1201 | /* walk the rest of the queue so unlinks behave */ | ||
| 1202 | entry->valid = 0; | ||
| 1203 | dmacount &= ~valid_bit; | ||
| 1204 | entry->td->dmacount = dmacount; | ||
| 1205 | prev = entry; | ||
| 1206 | } | ||
| 1207 | } | ||
| 1208 | |||
| 1209 | writel(0, &ep->dma->dmactl); | ||
| 1210 | start_queue(ep, dmactl, req->td_dma); | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | static void abort_dma_228x(struct net2280_ep *ep) | ||
| 1214 | { | ||
| 1215 | /* abort the current transfer */ | ||
| 1216 | if (likely(!list_empty(&ep->queue))) { | ||
| 1217 | /* FIXME work around errata 0121, 0122, 0124 */ | ||
| 1218 | writel(BIT(DMA_ABORT), &ep->dma->dmastat); | ||
| 1219 | spin_stop_dma(ep->dma); | ||
| 1220 | } else | ||
| 1221 | stop_dma(ep->dma); | ||
| 1222 | scan_dma_completions(ep); | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | static void abort_dma_338x(struct net2280_ep *ep) | ||
| 1226 | { | ||
| 1227 | writel(BIT(DMA_ABORT), &ep->dma->dmastat); | ||
| 1228 | spin_stop_dma(ep->dma); | ||
| 1229 | } | ||
| 1230 | |||
| 1231 | static void abort_dma(struct net2280_ep *ep) | ||
| 1232 | { | ||
| 1233 | if (ep->dev->quirks & PLX_LEGACY) | ||
| 1234 | return abort_dma_228x(ep); | ||
| 1235 | return abort_dma_338x(ep); | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | /* dequeue ALL requests */ | ||
| 1239 | static void nuke(struct net2280_ep *ep) | ||
| 1240 | { | ||
| 1241 | struct net2280_request *req; | ||
| 1242 | |||
| 1243 | /* called with spinlock held */ | ||
| 1244 | ep->stopped = 1; | ||
| 1245 | if (ep->dma) | ||
| 1246 | abort_dma(ep); | ||
| 1247 | while (!list_empty(&ep->queue)) { | ||
| 1248 | req = list_entry(ep->queue.next, | ||
| 1249 | struct net2280_request, | ||
| 1250 | queue); | ||
| 1251 | done(ep, req, -ESHUTDOWN); | ||
| 1252 | } | ||
| 1253 | } | ||
| 1254 | |||
| 1255 | /* dequeue JUST ONE request */ | ||
| 1256 | static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
| 1257 | { | ||
| 1258 | struct net2280_ep *ep; | ||
| 1259 | struct net2280_request *req; | ||
| 1260 | unsigned long flags; | ||
| 1261 | u32 dmactl; | ||
| 1262 | int stopped; | ||
| 1263 | |||
| 1264 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 1265 | if (!_ep || (!ep->desc && ep->num != 0) || !_req) | ||
| 1266 | return -EINVAL; | ||
| 1267 | |||
| 1268 | spin_lock_irqsave(&ep->dev->lock, flags); | ||
| 1269 | stopped = ep->stopped; | ||
| 1270 | |||
| 1271 | /* quiesce dma while we patch the queue */ | ||
| 1272 | dmactl = 0; | ||
| 1273 | ep->stopped = 1; | ||
| 1274 | if (ep->dma) { | ||
| 1275 | dmactl = readl(&ep->dma->dmactl); | ||
| 1276 | /* WARNING erratum 0127 may kick in ... */ | ||
| 1277 | stop_dma(ep->dma); | ||
| 1278 | scan_dma_completions(ep); | ||
| 1279 | } | ||
| 1280 | |||
| 1281 | /* make sure it's still queued on this endpoint */ | ||
| 1282 | list_for_each_entry(req, &ep->queue, queue) { | ||
| 1283 | if (&req->req == _req) | ||
| 1284 | break; | ||
| 1285 | } | ||
| 1286 | if (&req->req != _req) { | ||
| 1287 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
| 1288 | return -EINVAL; | ||
| 1289 | } | ||
| 1290 | |||
| 1291 | /* queue head may be partially complete. */ | ||
| 1292 | if (ep->queue.next == &req->queue) { | ||
| 1293 | if (ep->dma) { | ||
| 1294 | ep_dbg(ep->dev, "unlink (%s) dma\n", _ep->name); | ||
| 1295 | _req->status = -ECONNRESET; | ||
| 1296 | abort_dma(ep); | ||
| 1297 | if (likely(ep->queue.next == &req->queue)) { | ||
| 1298 | /* NOTE: misreports single-transfer mode*/ | ||
| 1299 | req->td->dmacount = 0; /* invalidate */ | ||
| 1300 | dma_done(ep, req, | ||
| 1301 | readl(&ep->dma->dmacount), | ||
| 1302 | -ECONNRESET); | ||
| 1303 | } | ||
| 1304 | } else { | ||
| 1305 | ep_dbg(ep->dev, "unlink (%s) pio\n", _ep->name); | ||
| 1306 | done(ep, req, -ECONNRESET); | ||
| 1307 | } | ||
| 1308 | req = NULL; | ||
| 1309 | |||
| 1310 | /* patch up hardware chaining data */ | ||
| 1311 | } else if (ep->dma && use_dma_chaining) { | ||
| 1312 | if (req->queue.prev == ep->queue.next) { | ||
| 1313 | writel(le32_to_cpu(req->td->dmadesc), | ||
| 1314 | &ep->dma->dmadesc); | ||
| 1315 | if (req->td->dmacount & dma_done_ie) | ||
| 1316 | writel(readl(&ep->dma->dmacount) | | ||
| 1317 | le32_to_cpu(dma_done_ie), | ||
| 1318 | &ep->dma->dmacount); | ||
| 1319 | } else { | ||
| 1320 | struct net2280_request *prev; | ||
| 1321 | |||
| 1322 | prev = list_entry(req->queue.prev, | ||
| 1323 | struct net2280_request, queue); | ||
| 1324 | prev->td->dmadesc = req->td->dmadesc; | ||
| 1325 | if (req->td->dmacount & dma_done_ie) | ||
| 1326 | prev->td->dmacount |= dma_done_ie; | ||
| 1327 | } | ||
| 1328 | } | ||
| 1329 | |||
| 1330 | if (req) | ||
| 1331 | done(ep, req, -ECONNRESET); | ||
| 1332 | ep->stopped = stopped; | ||
| 1333 | |||
| 1334 | if (ep->dma) { | ||
| 1335 | /* turn off dma on inactive queues */ | ||
| 1336 | if (list_empty(&ep->queue)) | ||
| 1337 | stop_dma(ep->dma); | ||
| 1338 | else if (!ep->stopped) { | ||
| 1339 | /* resume current request, or start new one */ | ||
| 1340 | if (req) | ||
| 1341 | writel(dmactl, &ep->dma->dmactl); | ||
| 1342 | else | ||
| 1343 | start_dma(ep, list_entry(ep->queue.next, | ||
| 1344 | struct net2280_request, queue)); | ||
| 1345 | } | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
| 1349 | return 0; | ||
| 1350 | } | ||
| 1351 | |||
| 1352 | /*-------------------------------------------------------------------------*/ | ||
| 1353 | |||
| 1354 | static int net2280_fifo_status(struct usb_ep *_ep); | ||
| 1355 | |||
| 1356 | static int | ||
| 1357 | net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) | ||
| 1358 | { | ||
| 1359 | struct net2280_ep *ep; | ||
| 1360 | unsigned long flags; | ||
| 1361 | int retval = 0; | ||
| 1362 | |||
| 1363 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 1364 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 1365 | return -EINVAL; | ||
| 1366 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1367 | return -ESHUTDOWN; | ||
| 1368 | if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03) | ||
| 1369 | == USB_ENDPOINT_XFER_ISOC) | ||
| 1370 | return -EINVAL; | ||
| 1371 | |||
| 1372 | spin_lock_irqsave(&ep->dev->lock, flags); | ||
| 1373 | if (!list_empty(&ep->queue)) | ||
| 1374 | retval = -EAGAIN; | ||
| 1375 | else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) | ||
| 1376 | retval = -EAGAIN; | ||
| 1377 | else { | ||
| 1378 | ep_vdbg(ep->dev, "%s %s %s\n", _ep->name, | ||
| 1379 | value ? "set" : "clear", | ||
| 1380 | wedged ? "wedge" : "halt"); | ||
| 1381 | /* set/clear, then synch memory views with the device */ | ||
| 1382 | if (value) { | ||
| 1383 | if (ep->num == 0) | ||
| 1384 | ep->dev->protocol_stall = 1; | ||
| 1385 | else | ||
| 1386 | set_halt(ep); | ||
| 1387 | if (wedged) | ||
| 1388 | ep->wedged = 1; | ||
| 1389 | } else { | ||
| 1390 | clear_halt(ep); | ||
| 1391 | if (ep->dev->quirks & PLX_SUPERSPEED && | ||
| 1392 | !list_empty(&ep->queue) && ep->td_dma) | ||
| 1393 | restart_dma(ep); | ||
| 1394 | ep->wedged = 0; | ||
| 1395 | } | ||
| 1396 | (void) readl(&ep->regs->ep_rsp); | ||
| 1397 | } | ||
| 1398 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
| 1399 | |||
| 1400 | return retval; | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | static int net2280_set_halt(struct usb_ep *_ep, int value) | ||
| 1404 | { | ||
| 1405 | return net2280_set_halt_and_wedge(_ep, value, 0); | ||
| 1406 | } | ||
| 1407 | |||
| 1408 | static int net2280_set_wedge(struct usb_ep *_ep) | ||
| 1409 | { | ||
| 1410 | if (!_ep || _ep->name == ep0name) | ||
| 1411 | return -EINVAL; | ||
| 1412 | return net2280_set_halt_and_wedge(_ep, 1, 1); | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | static int net2280_fifo_status(struct usb_ep *_ep) | ||
| 1416 | { | ||
| 1417 | struct net2280_ep *ep; | ||
| 1418 | u32 avail; | ||
| 1419 | |||
| 1420 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 1421 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 1422 | return -ENODEV; | ||
| 1423 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1424 | return -ESHUTDOWN; | ||
| 1425 | |||
| 1426 | avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1); | ||
| 1427 | if (avail > ep->fifo_size) | ||
| 1428 | return -EOVERFLOW; | ||
| 1429 | if (ep->is_in) | ||
| 1430 | avail = ep->fifo_size - avail; | ||
| 1431 | return avail; | ||
| 1432 | } | ||
| 1433 | |||
| 1434 | static void net2280_fifo_flush(struct usb_ep *_ep) | ||
| 1435 | { | ||
| 1436 | struct net2280_ep *ep; | ||
| 1437 | |||
| 1438 | ep = container_of(_ep, struct net2280_ep, ep); | ||
| 1439 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
| 1440 | return; | ||
| 1441 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1442 | return; | ||
| 1443 | |||
| 1444 | writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); | ||
| 1445 | (void) readl(&ep->regs->ep_rsp); | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | static const struct usb_ep_ops net2280_ep_ops = { | ||
| 1449 | .enable = net2280_enable, | ||
| 1450 | .disable = net2280_disable, | ||
| 1451 | |||
| 1452 | .alloc_request = net2280_alloc_request, | ||
| 1453 | .free_request = net2280_free_request, | ||
| 1454 | |||
| 1455 | .queue = net2280_queue, | ||
| 1456 | .dequeue = net2280_dequeue, | ||
| 1457 | |||
| 1458 | .set_halt = net2280_set_halt, | ||
| 1459 | .set_wedge = net2280_set_wedge, | ||
| 1460 | .fifo_status = net2280_fifo_status, | ||
| 1461 | .fifo_flush = net2280_fifo_flush, | ||
| 1462 | }; | ||
| 1463 | |||
| 1464 | /*-------------------------------------------------------------------------*/ | ||
| 1465 | |||
| 1466 | static int net2280_get_frame(struct usb_gadget *_gadget) | ||
| 1467 | { | ||
| 1468 | struct net2280 *dev; | ||
| 1469 | unsigned long flags; | ||
| 1470 | u16 retval; | ||
| 1471 | |||
| 1472 | if (!_gadget) | ||
| 1473 | return -ENODEV; | ||
| 1474 | dev = container_of(_gadget, struct net2280, gadget); | ||
| 1475 | spin_lock_irqsave(&dev->lock, flags); | ||
| 1476 | retval = get_idx_reg(dev->regs, REG_FRAME) & 0x03ff; | ||
| 1477 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1478 | return retval; | ||
| 1479 | } | ||
| 1480 | |||
| 1481 | static int net2280_wakeup(struct usb_gadget *_gadget) | ||
| 1482 | { | ||
| 1483 | struct net2280 *dev; | ||
| 1484 | u32 tmp; | ||
| 1485 | unsigned long flags; | ||
| 1486 | |||
| 1487 | if (!_gadget) | ||
| 1488 | return 0; | ||
| 1489 | dev = container_of(_gadget, struct net2280, gadget); | ||
| 1490 | |||
| 1491 | spin_lock_irqsave(&dev->lock, flags); | ||
| 1492 | tmp = readl(&dev->usb->usbctl); | ||
| 1493 | if (tmp & BIT(DEVICE_REMOTE_WAKEUP_ENABLE)) | ||
| 1494 | writel(BIT(GENERATE_RESUME), &dev->usb->usbstat); | ||
| 1495 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1496 | |||
| 1497 | /* pci writes may still be posted */ | ||
| 1498 | return 0; | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | static int net2280_set_selfpowered(struct usb_gadget *_gadget, int value) | ||
| 1502 | { | ||
| 1503 | struct net2280 *dev; | ||
| 1504 | u32 tmp; | ||
| 1505 | unsigned long flags; | ||
| 1506 | |||
| 1507 | if (!_gadget) | ||
| 1508 | return 0; | ||
| 1509 | dev = container_of(_gadget, struct net2280, gadget); | ||
| 1510 | |||
| 1511 | spin_lock_irqsave(&dev->lock, flags); | ||
| 1512 | tmp = readl(&dev->usb->usbctl); | ||
| 1513 | if (value) { | ||
| 1514 | tmp |= BIT(SELF_POWERED_STATUS); | ||
| 1515 | dev->selfpowered = 1; | ||
| 1516 | } else { | ||
| 1517 | tmp &= ~BIT(SELF_POWERED_STATUS); | ||
| 1518 | dev->selfpowered = 0; | ||
| 1519 | } | ||
| 1520 | writel(tmp, &dev->usb->usbctl); | ||
| 1521 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1522 | |||
| 1523 | return 0; | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | static int net2280_pullup(struct usb_gadget *_gadget, int is_on) | ||
| 1527 | { | ||
| 1528 | struct net2280 *dev; | ||
| 1529 | u32 tmp; | ||
| 1530 | unsigned long flags; | ||
| 1531 | |||
| 1532 | if (!_gadget) | ||
| 1533 | return -ENODEV; | ||
| 1534 | dev = container_of(_gadget, struct net2280, gadget); | ||
| 1535 | |||
| 1536 | spin_lock_irqsave(&dev->lock, flags); | ||
| 1537 | tmp = readl(&dev->usb->usbctl); | ||
| 1538 | dev->softconnect = (is_on != 0); | ||
| 1539 | if (is_on) | ||
| 1540 | tmp |= BIT(USB_DETECT_ENABLE); | ||
| 1541 | else | ||
| 1542 | tmp &= ~BIT(USB_DETECT_ENABLE); | ||
| 1543 | writel(tmp, &dev->usb->usbctl); | ||
| 1544 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1545 | |||
| 1546 | return 0; | ||
| 1547 | } | ||
| 1548 | |||
| 1549 | static int net2280_start(struct usb_gadget *_gadget, | ||
| 1550 | struct usb_gadget_driver *driver); | ||
| 1551 | static int net2280_stop(struct usb_gadget *_gadget, | ||
| 1552 | struct usb_gadget_driver *driver); | ||
| 1553 | |||
| 1554 | static const struct usb_gadget_ops net2280_ops = { | ||
| 1555 | .get_frame = net2280_get_frame, | ||
| 1556 | .wakeup = net2280_wakeup, | ||
| 1557 | .set_selfpowered = net2280_set_selfpowered, | ||
| 1558 | .pullup = net2280_pullup, | ||
| 1559 | .udc_start = net2280_start, | ||
| 1560 | .udc_stop = net2280_stop, | ||
| 1561 | }; | ||
| 1562 | |||
| 1563 | /*-------------------------------------------------------------------------*/ | ||
| 1564 | |||
| 1565 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
| 1566 | |||
| 1567 | /* FIXME move these into procfs, and use seq_file. | ||
| 1568 | * Sysfs _still_ doesn't behave for arbitrarily sized files, | ||
| 1569 | * and also doesn't help products using this with 2.4 kernels. | ||
| 1570 | */ | ||
| 1571 | |||
| 1572 | /* "function" sysfs attribute */ | ||
| 1573 | static ssize_t function_show(struct device *_dev, struct device_attribute *attr, | ||
| 1574 | char *buf) | ||
| 1575 | { | ||
| 1576 | struct net2280 *dev = dev_get_drvdata(_dev); | ||
| 1577 | |||
| 1578 | if (!dev->driver || !dev->driver->function || | ||
| 1579 | strlen(dev->driver->function) > PAGE_SIZE) | ||
| 1580 | return 0; | ||
| 1581 | return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->function); | ||
| 1582 | } | ||
| 1583 | static DEVICE_ATTR_RO(function); | ||
| 1584 | |||
| 1585 | static ssize_t registers_show(struct device *_dev, | ||
| 1586 | struct device_attribute *attr, char *buf) | ||
| 1587 | { | ||
| 1588 | struct net2280 *dev; | ||
| 1589 | char *next; | ||
| 1590 | unsigned size, t; | ||
| 1591 | unsigned long flags; | ||
| 1592 | int i; | ||
| 1593 | u32 t1, t2; | ||
| 1594 | const char *s; | ||
| 1595 | |||
| 1596 | dev = dev_get_drvdata(_dev); | ||
| 1597 | next = buf; | ||
| 1598 | size = PAGE_SIZE; | ||
| 1599 | spin_lock_irqsave(&dev->lock, flags); | ||
| 1600 | |||
| 1601 | if (dev->driver) | ||
| 1602 | s = dev->driver->driver.name; | ||
| 1603 | else | ||
| 1604 | s = "(none)"; | ||
| 1605 | |||
| 1606 | /* Main Control Registers */ | ||
| 1607 | t = scnprintf(next, size, "%s version " DRIVER_VERSION | ||
| 1608 | ", chiprev %04x, dma %s\n\n" | ||
| 1609 | "devinit %03x fifoctl %08x gadget '%s'\n" | ||
| 1610 | "pci irqenb0 %02x irqenb1 %08x " | ||
| 1611 | "irqstat0 %04x irqstat1 %08x\n", | ||
| 1612 | driver_name, dev->chiprev, | ||
| 1613 | use_dma | ||
| 1614 | ? (use_dma_chaining ? "chaining" : "enabled") | ||
| 1615 | : "disabled", | ||
| 1616 | readl(&dev->regs->devinit), | ||
| 1617 | readl(&dev->regs->fifoctl), | ||
| 1618 | s, | ||
| 1619 | readl(&dev->regs->pciirqenb0), | ||
| 1620 | readl(&dev->regs->pciirqenb1), | ||
| 1621 | readl(&dev->regs->irqstat0), | ||
| 1622 | readl(&dev->regs->irqstat1)); | ||
| 1623 | size -= t; | ||
| 1624 | next += t; | ||
| 1625 | |||
| 1626 | /* USB Control Registers */ | ||
| 1627 | t1 = readl(&dev->usb->usbctl); | ||
| 1628 | t2 = readl(&dev->usb->usbstat); | ||
| 1629 | if (t1 & BIT(VBUS_PIN)) { | ||
| 1630 | if (t2 & BIT(HIGH_SPEED)) | ||
| 1631 | s = "high speed"; | ||
| 1632 | else if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 1633 | s = "powered"; | ||
| 1634 | else | ||
| 1635 | s = "full speed"; | ||
| 1636 | /* full speed bit (6) not working?? */ | ||
| 1637 | } else | ||
| 1638 | s = "not attached"; | ||
| 1639 | t = scnprintf(next, size, | ||
| 1640 | "stdrsp %08x usbctl %08x usbstat %08x " | ||
| 1641 | "addr 0x%02x (%s)\n", | ||
| 1642 | readl(&dev->usb->stdrsp), t1, t2, | ||
| 1643 | readl(&dev->usb->ouraddr), s); | ||
| 1644 | size -= t; | ||
| 1645 | next += t; | ||
| 1646 | |||
| 1647 | /* PCI Master Control Registers */ | ||
| 1648 | |||
| 1649 | /* DMA Control Registers */ | ||
| 1650 | |||
| 1651 | /* Configurable EP Control Registers */ | ||
| 1652 | for (i = 0; i < dev->n_ep; i++) { | ||
| 1653 | struct net2280_ep *ep; | ||
| 1654 | |||
| 1655 | ep = &dev->ep[i]; | ||
| 1656 | if (i && !ep->desc) | ||
| 1657 | continue; | ||
| 1658 | |||
| 1659 | t1 = readl(&ep->cfg->ep_cfg); | ||
| 1660 | t2 = readl(&ep->regs->ep_rsp) & 0xff; | ||
| 1661 | t = scnprintf(next, size, | ||
| 1662 | "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s" | ||
| 1663 | "irqenb %02x\n", | ||
| 1664 | ep->ep.name, t1, t2, | ||
| 1665 | (t2 & BIT(CLEAR_NAK_OUT_PACKETS)) | ||
| 1666 | ? "NAK " : "", | ||
| 1667 | (t2 & BIT(CLEAR_EP_HIDE_STATUS_PHASE)) | ||
| 1668 | ? "hide " : "", | ||
| 1669 | (t2 & BIT(CLEAR_EP_FORCE_CRC_ERROR)) | ||
| 1670 | ? "CRC " : "", | ||
| 1671 | (t2 & BIT(CLEAR_INTERRUPT_MODE)) | ||
| 1672 | ? "interrupt " : "", | ||
| 1673 | (t2 & BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)) | ||
| 1674 | ? "status " : "", | ||
| 1675 | (t2 & BIT(CLEAR_NAK_OUT_PACKETS_MODE)) | ||
| 1676 | ? "NAKmode " : "", | ||
| 1677 | (t2 & BIT(CLEAR_ENDPOINT_TOGGLE)) | ||
| 1678 | ? "DATA1 " : "DATA0 ", | ||
| 1679 | (t2 & BIT(CLEAR_ENDPOINT_HALT)) | ||
| 1680 | ? "HALT " : "", | ||
| 1681 | readl(&ep->regs->ep_irqenb)); | ||
| 1682 | size -= t; | ||
| 1683 | next += t; | ||
| 1684 | |||
| 1685 | t = scnprintf(next, size, | ||
| 1686 | "\tstat %08x avail %04x " | ||
| 1687 | "(ep%d%s-%s)%s\n", | ||
| 1688 | readl(&ep->regs->ep_stat), | ||
| 1689 | readl(&ep->regs->ep_avail), | ||
| 1690 | t1 & 0x0f, DIR_STRING(t1), | ||
| 1691 | type_string(t1 >> 8), | ||
| 1692 | ep->stopped ? "*" : ""); | ||
| 1693 | size -= t; | ||
| 1694 | next += t; | ||
| 1695 | |||
| 1696 | if (!ep->dma) | ||
| 1697 | continue; | ||
| 1698 | |||
| 1699 | t = scnprintf(next, size, | ||
| 1700 | " dma\tctl %08x stat %08x count %08x\n" | ||
| 1701 | "\taddr %08x desc %08x\n", | ||
| 1702 | readl(&ep->dma->dmactl), | ||
| 1703 | readl(&ep->dma->dmastat), | ||
| 1704 | readl(&ep->dma->dmacount), | ||
| 1705 | readl(&ep->dma->dmaaddr), | ||
| 1706 | readl(&ep->dma->dmadesc)); | ||
| 1707 | size -= t; | ||
| 1708 | next += t; | ||
| 1709 | |||
| 1710 | } | ||
| 1711 | |||
| 1712 | /* Indexed Registers (none yet) */ | ||
| 1713 | |||
| 1714 | /* Statistics */ | ||
| 1715 | t = scnprintf(next, size, "\nirqs: "); | ||
| 1716 | size -= t; | ||
| 1717 | next += t; | ||
| 1718 | for (i = 0; i < dev->n_ep; i++) { | ||
| 1719 | struct net2280_ep *ep; | ||
| 1720 | |||
| 1721 | ep = &dev->ep[i]; | ||
| 1722 | if (i && !ep->irqs) | ||
| 1723 | continue; | ||
| 1724 | t = scnprintf(next, size, " %s/%lu", ep->ep.name, ep->irqs); | ||
| 1725 | size -= t; | ||
| 1726 | next += t; | ||
| 1727 | |||
| 1728 | } | ||
| 1729 | t = scnprintf(next, size, "\n"); | ||
| 1730 | size -= t; | ||
| 1731 | next += t; | ||
| 1732 | |||
| 1733 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1734 | |||
| 1735 | return PAGE_SIZE - size; | ||
| 1736 | } | ||
| 1737 | static DEVICE_ATTR_RO(registers); | ||
| 1738 | |||
| 1739 | static ssize_t queues_show(struct device *_dev, struct device_attribute *attr, | ||
| 1740 | char *buf) | ||
| 1741 | { | ||
| 1742 | struct net2280 *dev; | ||
| 1743 | char *next; | ||
| 1744 | unsigned size; | ||
| 1745 | unsigned long flags; | ||
| 1746 | int i; | ||
| 1747 | |||
| 1748 | dev = dev_get_drvdata(_dev); | ||
| 1749 | next = buf; | ||
| 1750 | size = PAGE_SIZE; | ||
| 1751 | spin_lock_irqsave(&dev->lock, flags); | ||
| 1752 | |||
| 1753 | for (i = 0; i < dev->n_ep; i++) { | ||
| 1754 | struct net2280_ep *ep = &dev->ep[i]; | ||
| 1755 | struct net2280_request *req; | ||
| 1756 | int t; | ||
| 1757 | |||
| 1758 | if (i != 0) { | ||
| 1759 | const struct usb_endpoint_descriptor *d; | ||
| 1760 | |||
| 1761 | d = ep->desc; | ||
| 1762 | if (!d) | ||
| 1763 | continue; | ||
| 1764 | t = d->bEndpointAddress; | ||
| 1765 | t = scnprintf(next, size, | ||
| 1766 | "\n%s (ep%d%s-%s) max %04x %s fifo %d\n", | ||
| 1767 | ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK, | ||
| 1768 | (t & USB_DIR_IN) ? "in" : "out", | ||
| 1769 | type_string(d->bmAttributes), | ||
| 1770 | usb_endpoint_maxp(d) & 0x1fff, | ||
| 1771 | ep->dma ? "dma" : "pio", ep->fifo_size | ||
| 1772 | ); | ||
| 1773 | } else /* ep0 should only have one transfer queued */ | ||
| 1774 | t = scnprintf(next, size, "ep0 max 64 pio %s\n", | ||
| 1775 | ep->is_in ? "in" : "out"); | ||
| 1776 | if (t <= 0 || t > size) | ||
| 1777 | goto done; | ||
| 1778 | size -= t; | ||
| 1779 | next += t; | ||
| 1780 | |||
| 1781 | if (list_empty(&ep->queue)) { | ||
| 1782 | t = scnprintf(next, size, "\t(nothing queued)\n"); | ||
| 1783 | if (t <= 0 || t > size) | ||
| 1784 | goto done; | ||
| 1785 | size -= t; | ||
| 1786 | next += t; | ||
| 1787 | continue; | ||
| 1788 | } | ||
| 1789 | list_for_each_entry(req, &ep->queue, queue) { | ||
| 1790 | if (ep->dma && req->td_dma == readl(&ep->dma->dmadesc)) | ||
| 1791 | t = scnprintf(next, size, | ||
| 1792 | "\treq %p len %d/%d " | ||
| 1793 | "buf %p (dmacount %08x)\n", | ||
| 1794 | &req->req, req->req.actual, | ||
| 1795 | req->req.length, req->req.buf, | ||
| 1796 | readl(&ep->dma->dmacount)); | ||
| 1797 | else | ||
| 1798 | t = scnprintf(next, size, | ||
| 1799 | "\treq %p len %d/%d buf %p\n", | ||
| 1800 | &req->req, req->req.actual, | ||
| 1801 | req->req.length, req->req.buf); | ||
| 1802 | if (t <= 0 || t > size) | ||
| 1803 | goto done; | ||
| 1804 | size -= t; | ||
| 1805 | next += t; | ||
| 1806 | |||
| 1807 | if (ep->dma) { | ||
| 1808 | struct net2280_dma *td; | ||
| 1809 | |||
| 1810 | td = req->td; | ||
| 1811 | t = scnprintf(next, size, "\t td %08x " | ||
| 1812 | " count %08x buf %08x desc %08x\n", | ||
| 1813 | (u32) req->td_dma, | ||
| 1814 | le32_to_cpu(td->dmacount), | ||
| 1815 | le32_to_cpu(td->dmaaddr), | ||
| 1816 | le32_to_cpu(td->dmadesc)); | ||
| 1817 | if (t <= 0 || t > size) | ||
| 1818 | goto done; | ||
| 1819 | size -= t; | ||
| 1820 | next += t; | ||
| 1821 | } | ||
| 1822 | } | ||
| 1823 | } | ||
| 1824 | |||
| 1825 | done: | ||
| 1826 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 1827 | return PAGE_SIZE - size; | ||
| 1828 | } | ||
| 1829 | static DEVICE_ATTR_RO(queues); | ||
| 1830 | |||
| 1831 | |||
| 1832 | #else | ||
| 1833 | |||
| 1834 | #define device_create_file(a, b) (0) | ||
| 1835 | #define device_remove_file(a, b) do { } while (0) | ||
| 1836 | |||
| 1837 | #endif | ||
| 1838 | |||
| 1839 | /*-------------------------------------------------------------------------*/ | ||
| 1840 | |||
| 1841 | /* another driver-specific mode might be a request type doing dma | ||
| 1842 | * to/from another device fifo instead of to/from memory. | ||
| 1843 | */ | ||
| 1844 | |||
| 1845 | static void set_fifo_mode(struct net2280 *dev, int mode) | ||
| 1846 | { | ||
| 1847 | /* keeping high bits preserves BAR2 */ | ||
| 1848 | writel((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl); | ||
| 1849 | |||
| 1850 | /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */ | ||
| 1851 | INIT_LIST_HEAD(&dev->gadget.ep_list); | ||
| 1852 | list_add_tail(&dev->ep[1].ep.ep_list, &dev->gadget.ep_list); | ||
| 1853 | list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list); | ||
| 1854 | switch (mode) { | ||
| 1855 | case 0: | ||
| 1856 | list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list); | ||
| 1857 | list_add_tail(&dev->ep[4].ep.ep_list, &dev->gadget.ep_list); | ||
| 1858 | dev->ep[1].fifo_size = dev->ep[2].fifo_size = 1024; | ||
| 1859 | break; | ||
| 1860 | case 1: | ||
| 1861 | dev->ep[1].fifo_size = dev->ep[2].fifo_size = 2048; | ||
| 1862 | break; | ||
| 1863 | case 2: | ||
| 1864 | list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list); | ||
| 1865 | dev->ep[1].fifo_size = 2048; | ||
| 1866 | dev->ep[2].fifo_size = 1024; | ||
| 1867 | break; | ||
| 1868 | } | ||
| 1869 | /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */ | ||
| 1870 | list_add_tail(&dev->ep[5].ep.ep_list, &dev->gadget.ep_list); | ||
| 1871 | list_add_tail(&dev->ep[6].ep.ep_list, &dev->gadget.ep_list); | ||
| 1872 | } | ||
| 1873 | |||
| 1874 | static void defect7374_disable_data_eps(struct net2280 *dev) | ||
| 1875 | { | ||
| 1876 | /* | ||
| 1877 | * For Defect 7374, disable data EPs (and more): | ||
| 1878 | * - This phase undoes the earlier phase of the Defect 7374 workaround, | ||
| 1879 | * returing ep regs back to normal. | ||
| 1880 | */ | ||
| 1881 | struct net2280_ep *ep; | ||
| 1882 | int i; | ||
| 1883 | unsigned char ep_sel; | ||
| 1884 | u32 tmp_reg; | ||
| 1885 | |||
| 1886 | for (i = 1; i < 5; i++) { | ||
| 1887 | ep = &dev->ep[i]; | ||
| 1888 | writel(0, &ep->cfg->ep_cfg); | ||
| 1889 | } | ||
| 1890 | |||
| 1891 | /* CSROUT, CSRIN, PCIOUT, PCIIN, STATIN, RCIN */ | ||
| 1892 | for (i = 0; i < 6; i++) | ||
| 1893 | writel(0, &dev->dep[i].dep_cfg); | ||
| 1894 | |||
| 1895 | for (ep_sel = 0; ep_sel <= 21; ep_sel++) { | ||
| 1896 | /* Select an endpoint for subsequent operations: */ | ||
| 1897 | tmp_reg = readl(&dev->plregs->pl_ep_ctrl); | ||
| 1898 | writel(((tmp_reg & ~0x1f) | ep_sel), &dev->plregs->pl_ep_ctrl); | ||
| 1899 | |||
| 1900 | if (ep_sel < 2 || (ep_sel > 9 && ep_sel < 14) || | ||
| 1901 | ep_sel == 18 || ep_sel == 20) | ||
| 1902 | continue; | ||
| 1903 | |||
| 1904 | /* Change settings on some selected endpoints */ | ||
| 1905 | tmp_reg = readl(&dev->plregs->pl_ep_cfg_4); | ||
| 1906 | tmp_reg &= ~BIT(NON_CTRL_IN_TOLERATE_BAD_DIR); | ||
| 1907 | writel(tmp_reg, &dev->plregs->pl_ep_cfg_4); | ||
| 1908 | tmp_reg = readl(&dev->plregs->pl_ep_ctrl); | ||
| 1909 | tmp_reg |= BIT(EP_INITIALIZED); | ||
| 1910 | writel(tmp_reg, &dev->plregs->pl_ep_ctrl); | ||
| 1911 | } | ||
| 1912 | } | ||
| 1913 | |||
| 1914 | static void defect7374_enable_data_eps_zero(struct net2280 *dev) | ||
| 1915 | { | ||
| 1916 | u32 tmp = 0, tmp_reg; | ||
| 1917 | u32 fsmvalue, scratch; | ||
| 1918 | int i; | ||
| 1919 | unsigned char ep_sel; | ||
| 1920 | |||
| 1921 | scratch = get_idx_reg(dev->regs, SCRATCH); | ||
| 1922 | fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD); | ||
| 1923 | scratch &= ~(0xf << DEFECT7374_FSM_FIELD); | ||
| 1924 | |||
| 1925 | /*See if firmware needs to set up for workaround*/ | ||
| 1926 | if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) { | ||
| 1927 | ep_warn(dev, "Operate Defect 7374 workaround soft this time"); | ||
| 1928 | ep_warn(dev, "It will operate on cold-reboot and SS connect"); | ||
| 1929 | |||
| 1930 | /*GPEPs:*/ | ||
| 1931 | tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_DIRECTION) | | ||
| 1932 | (2 << OUT_ENDPOINT_TYPE) | (2 << IN_ENDPOINT_TYPE) | | ||
| 1933 | ((dev->enhanced_mode) ? | ||
| 1934 | BIT(OUT_ENDPOINT_ENABLE) : BIT(ENDPOINT_ENABLE)) | | ||
| 1935 | BIT(IN_ENDPOINT_ENABLE)); | ||
| 1936 | |||
| 1937 | for (i = 1; i < 5; i++) | ||
| 1938 | writel(tmp, &dev->ep[i].cfg->ep_cfg); | ||
| 1939 | |||
| 1940 | /* CSRIN, PCIIN, STATIN, RCIN*/ | ||
| 1941 | tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_ENABLE)); | ||
| 1942 | writel(tmp, &dev->dep[1].dep_cfg); | ||
| 1943 | writel(tmp, &dev->dep[3].dep_cfg); | ||
| 1944 | writel(tmp, &dev->dep[4].dep_cfg); | ||
| 1945 | writel(tmp, &dev->dep[5].dep_cfg); | ||
| 1946 | |||
| 1947 | /*Implemented for development and debug. | ||
| 1948 | * Can be refined/tuned later.*/ | ||
| 1949 | for (ep_sel = 0; ep_sel <= 21; ep_sel++) { | ||
| 1950 | /* Select an endpoint for subsequent operations: */ | ||
| 1951 | tmp_reg = readl(&dev->plregs->pl_ep_ctrl); | ||
| 1952 | writel(((tmp_reg & ~0x1f) | ep_sel), | ||
| 1953 | &dev->plregs->pl_ep_ctrl); | ||
| 1954 | |||
| 1955 | if (ep_sel == 1) { | ||
| 1956 | tmp = | ||
| 1957 | (readl(&dev->plregs->pl_ep_ctrl) | | ||
| 1958 | BIT(CLEAR_ACK_ERROR_CODE) | 0); | ||
| 1959 | writel(tmp, &dev->plregs->pl_ep_ctrl); | ||
| 1960 | continue; | ||
| 1961 | } | ||
| 1962 | |||
| 1963 | if (ep_sel == 0 || (ep_sel > 9 && ep_sel < 14) || | ||
| 1964 | ep_sel == 18 || ep_sel == 20) | ||
| 1965 | continue; | ||
| 1966 | |||
| 1967 | tmp = (readl(&dev->plregs->pl_ep_cfg_4) | | ||
| 1968 | BIT(NON_CTRL_IN_TOLERATE_BAD_DIR) | 0); | ||
| 1969 | writel(tmp, &dev->plregs->pl_ep_cfg_4); | ||
| 1970 | |||
| 1971 | tmp = readl(&dev->plregs->pl_ep_ctrl) & | ||
| 1972 | ~BIT(EP_INITIALIZED); | ||
| 1973 | writel(tmp, &dev->plregs->pl_ep_ctrl); | ||
| 1974 | |||
| 1975 | } | ||
| 1976 | |||
| 1977 | /* Set FSM to focus on the first Control Read: | ||
| 1978 | * - Tip: Connection speed is known upon the first | ||
| 1979 | * setup request.*/ | ||
| 1980 | scratch |= DEFECT7374_FSM_WAITING_FOR_CONTROL_READ; | ||
| 1981 | set_idx_reg(dev->regs, SCRATCH, scratch); | ||
| 1982 | |||
| 1983 | } else{ | ||
| 1984 | ep_warn(dev, "Defect 7374 workaround soft will NOT operate"); | ||
| 1985 | ep_warn(dev, "It will operate on cold-reboot and SS connect"); | ||
| 1986 | } | ||
| 1987 | } | ||
| 1988 | |||
| 1989 | /* keeping it simple: | ||
| 1990 | * - one bus driver, initted first; | ||
| 1991 | * - one function driver, initted second | ||
| 1992 | * | ||
| 1993 | * most of the work to support multiple net2280 controllers would | ||
| 1994 | * be to associate this gadget driver (yes?) with all of them, or | ||
| 1995 | * perhaps to bind specific drivers to specific devices. | ||
| 1996 | */ | ||
| 1997 | |||
| 1998 | static void usb_reset_228x(struct net2280 *dev) | ||
| 1999 | { | ||
| 2000 | u32 tmp; | ||
| 2001 | |||
| 2002 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
| 2003 | (void) readl(&dev->usb->usbctl); | ||
| 2004 | |||
| 2005 | net2280_led_init(dev); | ||
| 2006 | |||
| 2007 | /* disable automatic responses, and irqs */ | ||
| 2008 | writel(0, &dev->usb->stdrsp); | ||
| 2009 | writel(0, &dev->regs->pciirqenb0); | ||
| 2010 | writel(0, &dev->regs->pciirqenb1); | ||
| 2011 | |||
| 2012 | /* clear old dma and irq state */ | ||
| 2013 | for (tmp = 0; tmp < 4; tmp++) { | ||
| 2014 | struct net2280_ep *ep = &dev->ep[tmp + 1]; | ||
| 2015 | if (ep->dma) | ||
| 2016 | abort_dma(ep); | ||
| 2017 | } | ||
| 2018 | |||
| 2019 | writel(~0, &dev->regs->irqstat0), | ||
| 2020 | writel(~(u32)BIT(SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1), | ||
| 2021 | |||
| 2022 | /* reset, and enable pci */ | ||
| 2023 | tmp = readl(&dev->regs->devinit) | | ||
| 2024 | BIT(PCI_ENABLE) | | ||
| 2025 | BIT(FIFO_SOFT_RESET) | | ||
| 2026 | BIT(USB_SOFT_RESET) | | ||
| 2027 | BIT(M8051_RESET); | ||
| 2028 | writel(tmp, &dev->regs->devinit); | ||
| 2029 | |||
| 2030 | /* standard fifo and endpoint allocations */ | ||
| 2031 | set_fifo_mode(dev, (fifo_mode <= 2) ? fifo_mode : 0); | ||
| 2032 | } | ||
| 2033 | |||
| 2034 | static void usb_reset_338x(struct net2280 *dev) | ||
| 2035 | { | ||
| 2036 | u32 tmp; | ||
| 2037 | u32 fsmvalue; | ||
| 2038 | |||
| 2039 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
| 2040 | (void)readl(&dev->usb->usbctl); | ||
| 2041 | |||
| 2042 | net2280_led_init(dev); | ||
| 2043 | |||
| 2044 | fsmvalue = get_idx_reg(dev->regs, SCRATCH) & | ||
| 2045 | (0xf << DEFECT7374_FSM_FIELD); | ||
| 2046 | |||
| 2047 | /* See if firmware needs to set up for workaround: */ | ||
| 2048 | if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) { | ||
| 2049 | ep_info(dev, "%s: Defect 7374 FsmValue 0x%08x\n", __func__, | ||
| 2050 | fsmvalue); | ||
| 2051 | } else { | ||
| 2052 | /* disable automatic responses, and irqs */ | ||
| 2053 | writel(0, &dev->usb->stdrsp); | ||
| 2054 | writel(0, &dev->regs->pciirqenb0); | ||
| 2055 | writel(0, &dev->regs->pciirqenb1); | ||
| 2056 | } | ||
| 2057 | |||
| 2058 | /* clear old dma and irq state */ | ||
| 2059 | for (tmp = 0; tmp < 4; tmp++) { | ||
| 2060 | struct net2280_ep *ep = &dev->ep[tmp + 1]; | ||
| 2061 | |||
| 2062 | if (ep->dma) | ||
| 2063 | abort_dma(ep); | ||
| 2064 | } | ||
| 2065 | |||
| 2066 | writel(~0, &dev->regs->irqstat0), writel(~0, &dev->regs->irqstat1); | ||
| 2067 | |||
| 2068 | if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) { | ||
| 2069 | /* reset, and enable pci */ | ||
| 2070 | tmp = readl(&dev->regs->devinit) | | ||
| 2071 | BIT(PCI_ENABLE) | | ||
| 2072 | BIT(FIFO_SOFT_RESET) | | ||
| 2073 | BIT(USB_SOFT_RESET) | | ||
| 2074 | BIT(M8051_RESET); | ||
| 2075 | |||
| 2076 | writel(tmp, &dev->regs->devinit); | ||
| 2077 | } | ||
| 2078 | |||
| 2079 | /* always ep-{1,2,3,4} ... maybe not ep-3 or ep-4 */ | ||
| 2080 | INIT_LIST_HEAD(&dev->gadget.ep_list); | ||
| 2081 | |||
| 2082 | for (tmp = 1; tmp < dev->n_ep; tmp++) | ||
| 2083 | list_add_tail(&dev->ep[tmp].ep.ep_list, &dev->gadget.ep_list); | ||
| 2084 | |||
| 2085 | } | ||
| 2086 | |||
| 2087 | static void usb_reset(struct net2280 *dev) | ||
| 2088 | { | ||
| 2089 | if (dev->quirks & PLX_LEGACY) | ||
| 2090 | return usb_reset_228x(dev); | ||
| 2091 | return usb_reset_338x(dev); | ||
| 2092 | } | ||
| 2093 | |||
| 2094 | static void usb_reinit_228x(struct net2280 *dev) | ||
| 2095 | { | ||
| 2096 | u32 tmp; | ||
| 2097 | int init_dma; | ||
| 2098 | |||
| 2099 | /* use_dma changes are ignored till next device re-init */ | ||
| 2100 | init_dma = use_dma; | ||
| 2101 | |||
| 2102 | /* basic endpoint init */ | ||
| 2103 | for (tmp = 0; tmp < 7; tmp++) { | ||
| 2104 | struct net2280_ep *ep = &dev->ep[tmp]; | ||
| 2105 | |||
| 2106 | ep->ep.name = ep_name[tmp]; | ||
| 2107 | ep->dev = dev; | ||
| 2108 | ep->num = tmp; | ||
| 2109 | |||
| 2110 | if (tmp > 0 && tmp <= 4) { | ||
| 2111 | ep->fifo_size = 1024; | ||
| 2112 | if (init_dma) | ||
| 2113 | ep->dma = &dev->dma[tmp - 1]; | ||
| 2114 | } else | ||
| 2115 | ep->fifo_size = 64; | ||
| 2116 | ep->regs = &dev->epregs[tmp]; | ||
| 2117 | ep->cfg = &dev->epregs[tmp]; | ||
| 2118 | ep_reset_228x(dev->regs, ep); | ||
| 2119 | } | ||
| 2120 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64); | ||
| 2121 | usb_ep_set_maxpacket_limit(&dev->ep[5].ep, 64); | ||
| 2122 | usb_ep_set_maxpacket_limit(&dev->ep[6].ep, 64); | ||
| 2123 | |||
| 2124 | dev->gadget.ep0 = &dev->ep[0].ep; | ||
| 2125 | dev->ep[0].stopped = 0; | ||
| 2126 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); | ||
| 2127 | |||
| 2128 | /* we want to prevent lowlevel/insecure access from the USB host, | ||
| 2129 | * but erratum 0119 means this enable bit is ignored | ||
| 2130 | */ | ||
| 2131 | for (tmp = 0; tmp < 5; tmp++) | ||
| 2132 | writel(EP_DONTUSE, &dev->dep[tmp].dep_cfg); | ||
| 2133 | } | ||
| 2134 | |||
| 2135 | static void usb_reinit_338x(struct net2280 *dev) | ||
| 2136 | { | ||
| 2137 | int init_dma; | ||
| 2138 | int i; | ||
| 2139 | u32 tmp, val; | ||
| 2140 | u32 fsmvalue; | ||
| 2141 | static const u32 ne[9] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 }; | ||
| 2142 | static const u32 ep_reg_addr[9] = { 0x00, 0xC0, 0x00, 0xC0, 0x00, | ||
| 2143 | 0x00, 0xC0, 0x00, 0xC0 }; | ||
| 2144 | |||
| 2145 | /* use_dma changes are ignored till next device re-init */ | ||
| 2146 | init_dma = use_dma; | ||
| 2147 | |||
| 2148 | /* basic endpoint init */ | ||
| 2149 | for (i = 0; i < dev->n_ep; i++) { | ||
| 2150 | struct net2280_ep *ep = &dev->ep[i]; | ||
| 2151 | |||
| 2152 | ep->ep.name = ep_name[i]; | ||
| 2153 | ep->dev = dev; | ||
| 2154 | ep->num = i; | ||
| 2155 | |||
| 2156 | if (i > 0 && i <= 4 && init_dma) | ||
| 2157 | ep->dma = &dev->dma[i - 1]; | ||
| 2158 | |||
| 2159 | if (dev->enhanced_mode) { | ||
| 2160 | ep->cfg = &dev->epregs[ne[i]]; | ||
| 2161 | ep->regs = (struct net2280_ep_regs __iomem *) | ||
| 2162 | (((void __iomem *)&dev->epregs[ne[i]]) + | ||
| 2163 | ep_reg_addr[i]); | ||
| 2164 | ep->fiforegs = &dev->fiforegs[i]; | ||
| 2165 | } else { | ||
| 2166 | ep->cfg = &dev->epregs[i]; | ||
| 2167 | ep->regs = &dev->epregs[i]; | ||
| 2168 | ep->fiforegs = &dev->fiforegs[i]; | ||
| 2169 | } | ||
| 2170 | |||
| 2171 | ep->fifo_size = (i != 0) ? 2048 : 512; | ||
| 2172 | |||
| 2173 | ep_reset_338x(dev->regs, ep); | ||
| 2174 | } | ||
| 2175 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 512); | ||
| 2176 | |||
| 2177 | dev->gadget.ep0 = &dev->ep[0].ep; | ||
| 2178 | dev->ep[0].stopped = 0; | ||
| 2179 | |||
| 2180 | /* Link layer set up */ | ||
| 2181 | fsmvalue = get_idx_reg(dev->regs, SCRATCH) & | ||
| 2182 | (0xf << DEFECT7374_FSM_FIELD); | ||
| 2183 | |||
| 2184 | /* See if driver needs to set up for workaround: */ | ||
| 2185 | if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) | ||
| 2186 | ep_info(dev, "%s: Defect 7374 FsmValue %08x\n", | ||
| 2187 | __func__, fsmvalue); | ||
| 2188 | else { | ||
| 2189 | tmp = readl(&dev->usb_ext->usbctl2) & | ||
| 2190 | ~(BIT(U1_ENABLE) | BIT(U2_ENABLE) | BIT(LTM_ENABLE)); | ||
| 2191 | writel(tmp, &dev->usb_ext->usbctl2); | ||
| 2192 | } | ||
| 2193 | |||
| 2194 | /* Hardware Defect and Workaround */ | ||
| 2195 | val = readl(&dev->ll_lfps_regs->ll_lfps_5); | ||
| 2196 | val &= ~(0xf << TIMER_LFPS_6US); | ||
| 2197 | val |= 0x5 << TIMER_LFPS_6US; | ||
| 2198 | writel(val, &dev->ll_lfps_regs->ll_lfps_5); | ||
| 2199 | |||
| 2200 | val = readl(&dev->ll_lfps_regs->ll_lfps_6); | ||
| 2201 | val &= ~(0xffff << TIMER_LFPS_80US); | ||
| 2202 | val |= 0x0100 << TIMER_LFPS_80US; | ||
| 2203 | writel(val, &dev->ll_lfps_regs->ll_lfps_6); | ||
| 2204 | |||
| 2205 | /* | ||
| 2206 | * AA_AB Errata. Issue 4. Workaround for SuperSpeed USB | ||
| 2207 | * Hot Reset Exit Handshake may Fail in Specific Case using | ||
| 2208 | * Default Register Settings. Workaround for Enumeration test. | ||
| 2209 | */ | ||
| 2210 | val = readl(&dev->ll_tsn_regs->ll_tsn_counters_2); | ||
| 2211 | val &= ~(0x1f << HOT_TX_NORESET_TS2); | ||
| 2212 | val |= 0x10 << HOT_TX_NORESET_TS2; | ||
| 2213 | writel(val, &dev->ll_tsn_regs->ll_tsn_counters_2); | ||
| 2214 | |||
| 2215 | val = readl(&dev->ll_tsn_regs->ll_tsn_counters_3); | ||
| 2216 | val &= ~(0x1f << HOT_RX_RESET_TS2); | ||
| 2217 | val |= 0x3 << HOT_RX_RESET_TS2; | ||
| 2218 | writel(val, &dev->ll_tsn_regs->ll_tsn_counters_3); | ||
| 2219 | |||
| 2220 | /* | ||
| 2221 | * Set Recovery Idle to Recover bit: | ||
| 2222 | * - On SS connections, setting Recovery Idle to Recover Fmw improves | ||
| 2223 | * link robustness with various hosts and hubs. | ||
| 2224 | * - It is safe to set for all connection speeds; all chip revisions. | ||
| 2225 | * - R-M-W to leave other bits undisturbed. | ||
| 2226 | * - Reference PLX TT-7372 | ||
| 2227 | */ | ||
| 2228 | val = readl(&dev->ll_chicken_reg->ll_tsn_chicken_bit); | ||
| 2229 | val |= BIT(RECOVERY_IDLE_TO_RECOVER_FMW); | ||
| 2230 | writel(val, &dev->ll_chicken_reg->ll_tsn_chicken_bit); | ||
| 2231 | |||
| 2232 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); | ||
| 2233 | |||
| 2234 | /* disable dedicated endpoints */ | ||
| 2235 | writel(0x0D, &dev->dep[0].dep_cfg); | ||
| 2236 | writel(0x0D, &dev->dep[1].dep_cfg); | ||
| 2237 | writel(0x0E, &dev->dep[2].dep_cfg); | ||
| 2238 | writel(0x0E, &dev->dep[3].dep_cfg); | ||
| 2239 | writel(0x0F, &dev->dep[4].dep_cfg); | ||
| 2240 | writel(0x0C, &dev->dep[5].dep_cfg); | ||
| 2241 | } | ||
| 2242 | |||
| 2243 | static void usb_reinit(struct net2280 *dev) | ||
| 2244 | { | ||
| 2245 | if (dev->quirks & PLX_LEGACY) | ||
| 2246 | return usb_reinit_228x(dev); | ||
| 2247 | return usb_reinit_338x(dev); | ||
| 2248 | } | ||
| 2249 | |||
| 2250 | static void ep0_start_228x(struct net2280 *dev) | ||
| 2251 | { | ||
| 2252 | writel(BIT(CLEAR_EP_HIDE_STATUS_PHASE) | | ||
| 2253 | BIT(CLEAR_NAK_OUT_PACKETS) | | ||
| 2254 | BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE), | ||
| 2255 | &dev->epregs[0].ep_rsp); | ||
| 2256 | |||
| 2257 | /* | ||
| 2258 | * hardware optionally handles a bunch of standard requests | ||
| 2259 | * that the API hides from drivers anyway. have it do so. | ||
| 2260 | * endpoint status/features are handled in software, to | ||
| 2261 | * help pass tests for some dubious behavior. | ||
| 2262 | */ | ||
| 2263 | writel(BIT(SET_TEST_MODE) | | ||
| 2264 | BIT(SET_ADDRESS) | | ||
| 2265 | BIT(DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP) | | ||
| 2266 | BIT(GET_DEVICE_STATUS) | | ||
| 2267 | BIT(GET_INTERFACE_STATUS), | ||
| 2268 | &dev->usb->stdrsp); | ||
| 2269 | writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) | | ||
| 2270 | BIT(SELF_POWERED_USB_DEVICE) | | ||
| 2271 | BIT(REMOTE_WAKEUP_SUPPORT) | | ||
| 2272 | (dev->softconnect << USB_DETECT_ENABLE) | | ||
| 2273 | BIT(SELF_POWERED_STATUS), | ||
| 2274 | &dev->usb->usbctl); | ||
| 2275 | |||
| 2276 | /* enable irqs so we can see ep0 and general operation */ | ||
| 2277 | writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) | | ||
| 2278 | BIT(ENDPOINT_0_INTERRUPT_ENABLE), | ||
| 2279 | &dev->regs->pciirqenb0); | ||
| 2280 | writel(BIT(PCI_INTERRUPT_ENABLE) | | ||
| 2281 | BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE) | | ||
| 2282 | BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE) | | ||
| 2283 | BIT(PCI_RETRY_ABORT_INTERRUPT_ENABLE) | | ||
| 2284 | BIT(VBUS_INTERRUPT_ENABLE) | | ||
| 2285 | BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) | | ||
| 2286 | BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE), | ||
| 2287 | &dev->regs->pciirqenb1); | ||
| 2288 | |||
| 2289 | /* don't leave any writes posted */ | ||
| 2290 | (void) readl(&dev->usb->usbctl); | ||
| 2291 | } | ||
| 2292 | |||
| 2293 | static void ep0_start_338x(struct net2280 *dev) | ||
| 2294 | { | ||
| 2295 | u32 fsmvalue; | ||
| 2296 | |||
| 2297 | fsmvalue = get_idx_reg(dev->regs, SCRATCH) & | ||
| 2298 | (0xf << DEFECT7374_FSM_FIELD); | ||
| 2299 | |||
| 2300 | if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) | ||
| 2301 | ep_info(dev, "%s: Defect 7374 FsmValue %08x\n", __func__, | ||
| 2302 | fsmvalue); | ||
| 2303 | else | ||
| 2304 | writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE) | | ||
| 2305 | BIT(SET_EP_HIDE_STATUS_PHASE), | ||
| 2306 | &dev->epregs[0].ep_rsp); | ||
| 2307 | |||
| 2308 | /* | ||
| 2309 | * hardware optionally handles a bunch of standard requests | ||
| 2310 | * that the API hides from drivers anyway. have it do so. | ||
| 2311 | * endpoint status/features are handled in software, to | ||
| 2312 | * help pass tests for some dubious behavior. | ||
| 2313 | */ | ||
| 2314 | writel(BIT(SET_ISOCHRONOUS_DELAY) | | ||
| 2315 | BIT(SET_SEL) | | ||
| 2316 | BIT(SET_TEST_MODE) | | ||
| 2317 | BIT(SET_ADDRESS) | | ||
| 2318 | BIT(GET_INTERFACE_STATUS) | | ||
| 2319 | BIT(GET_DEVICE_STATUS), | ||
| 2320 | &dev->usb->stdrsp); | ||
| 2321 | dev->wakeup_enable = 1; | ||
| 2322 | writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) | | ||
| 2323 | (dev->softconnect << USB_DETECT_ENABLE) | | ||
| 2324 | BIT(DEVICE_REMOTE_WAKEUP_ENABLE), | ||
| 2325 | &dev->usb->usbctl); | ||
| 2326 | |||
| 2327 | /* enable irqs so we can see ep0 and general operation */ | ||
| 2328 | writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) | | ||
| 2329 | BIT(ENDPOINT_0_INTERRUPT_ENABLE), | ||
| 2330 | &dev->regs->pciirqenb0); | ||
| 2331 | writel(BIT(PCI_INTERRUPT_ENABLE) | | ||
| 2332 | BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) | | ||
| 2333 | BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) | | ||
| 2334 | BIT(VBUS_INTERRUPT_ENABLE), | ||
| 2335 | &dev->regs->pciirqenb1); | ||
| 2336 | |||
| 2337 | /* don't leave any writes posted */ | ||
| 2338 | (void)readl(&dev->usb->usbctl); | ||
| 2339 | } | ||
| 2340 | |||
| 2341 | static void ep0_start(struct net2280 *dev) | ||
| 2342 | { | ||
| 2343 | if (dev->quirks & PLX_LEGACY) | ||
| 2344 | return ep0_start_228x(dev); | ||
| 2345 | return ep0_start_338x(dev); | ||
| 2346 | } | ||
| 2347 | |||
| 2348 | /* when a driver is successfully registered, it will receive | ||
| 2349 | * control requests including set_configuration(), which enables | ||
| 2350 | * non-control requests. then usb traffic follows until a | ||
| 2351 | * disconnect is reported. then a host may connect again, or | ||
| 2352 | * the driver might get unbound. | ||
| 2353 | */ | ||
| 2354 | static int net2280_start(struct usb_gadget *_gadget, | ||
| 2355 | struct usb_gadget_driver *driver) | ||
| 2356 | { | ||
| 2357 | struct net2280 *dev; | ||
| 2358 | int retval; | ||
| 2359 | unsigned i; | ||
| 2360 | |||
| 2361 | /* insist on high speed support from the driver, since | ||
| 2362 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) | ||
| 2363 | * "must not be used in normal operation" | ||
| 2364 | */ | ||
| 2365 | if (!driver || driver->max_speed < USB_SPEED_HIGH || | ||
| 2366 | !driver->setup) | ||
| 2367 | return -EINVAL; | ||
| 2368 | |||
| 2369 | dev = container_of(_gadget, struct net2280, gadget); | ||
| 2370 | |||
| 2371 | for (i = 0; i < dev->n_ep; i++) | ||
| 2372 | dev->ep[i].irqs = 0; | ||
| 2373 | |||
| 2374 | /* hook up the driver ... */ | ||
| 2375 | dev->softconnect = 1; | ||
| 2376 | driver->driver.bus = NULL; | ||
| 2377 | dev->driver = driver; | ||
| 2378 | |||
| 2379 | retval = device_create_file(&dev->pdev->dev, &dev_attr_function); | ||
| 2380 | if (retval) | ||
| 2381 | goto err_unbind; | ||
| 2382 | retval = device_create_file(&dev->pdev->dev, &dev_attr_queues); | ||
| 2383 | if (retval) | ||
| 2384 | goto err_func; | ||
| 2385 | |||
| 2386 | /* Enable force-full-speed testing mode, if desired */ | ||
| 2387 | if (full_speed && (dev->quirks & PLX_LEGACY)) | ||
| 2388 | writel(BIT(FORCE_FULL_SPEED_MODE), &dev->usb->xcvrdiag); | ||
| 2389 | |||
| 2390 | /* ... then enable host detection and ep0; and we're ready | ||
| 2391 | * for set_configuration as well as eventual disconnect. | ||
| 2392 | */ | ||
| 2393 | net2280_led_active(dev, 1); | ||
| 2394 | |||
| 2395 | if (dev->quirks & PLX_SUPERSPEED) | ||
| 2396 | defect7374_enable_data_eps_zero(dev); | ||
| 2397 | |||
| 2398 | ep0_start(dev); | ||
| 2399 | |||
| 2400 | ep_dbg(dev, "%s ready, usbctl %08x stdrsp %08x\n", | ||
| 2401 | driver->driver.name, | ||
| 2402 | readl(&dev->usb->usbctl), | ||
| 2403 | readl(&dev->usb->stdrsp)); | ||
| 2404 | |||
| 2405 | /* pci writes may still be posted */ | ||
| 2406 | return 0; | ||
| 2407 | |||
| 2408 | err_func: | ||
| 2409 | device_remove_file(&dev->pdev->dev, &dev_attr_function); | ||
| 2410 | err_unbind: | ||
| 2411 | dev->driver = NULL; | ||
| 2412 | return retval; | ||
| 2413 | } | ||
| 2414 | |||
| 2415 | static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver) | ||
| 2416 | { | ||
| 2417 | int i; | ||
| 2418 | |||
| 2419 | /* don't disconnect if it's not connected */ | ||
| 2420 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
| 2421 | driver = NULL; | ||
| 2422 | |||
| 2423 | /* stop hardware; prevent new request submissions; | ||
| 2424 | * and kill any outstanding requests. | ||
| 2425 | */ | ||
| 2426 | usb_reset(dev); | ||
| 2427 | for (i = 0; i < dev->n_ep; i++) | ||
| 2428 | nuke(&dev->ep[i]); | ||
| 2429 | |||
| 2430 | /* report disconnect; the driver is already quiesced */ | ||
| 2431 | if (driver) { | ||
| 2432 | spin_unlock(&dev->lock); | ||
| 2433 | driver->disconnect(&dev->gadget); | ||
| 2434 | spin_lock(&dev->lock); | ||
| 2435 | } | ||
| 2436 | |||
| 2437 | usb_reinit(dev); | ||
| 2438 | } | ||
| 2439 | |||
| 2440 | static int net2280_stop(struct usb_gadget *_gadget, | ||
| 2441 | struct usb_gadget_driver *driver) | ||
| 2442 | { | ||
| 2443 | struct net2280 *dev; | ||
| 2444 | unsigned long flags; | ||
| 2445 | |||
| 2446 | dev = container_of(_gadget, struct net2280, gadget); | ||
| 2447 | |||
| 2448 | spin_lock_irqsave(&dev->lock, flags); | ||
| 2449 | stop_activity(dev, driver); | ||
| 2450 | spin_unlock_irqrestore(&dev->lock, flags); | ||
| 2451 | |||
| 2452 | dev->driver = NULL; | ||
| 2453 | |||
| 2454 | net2280_led_active(dev, 0); | ||
| 2455 | |||
| 2456 | /* Disable full-speed test mode */ | ||
| 2457 | if (dev->quirks & PLX_LEGACY) | ||
| 2458 | writel(0, &dev->usb->xcvrdiag); | ||
| 2459 | |||
| 2460 | device_remove_file(&dev->pdev->dev, &dev_attr_function); | ||
| 2461 | device_remove_file(&dev->pdev->dev, &dev_attr_queues); | ||
| 2462 | |||
| 2463 | ep_dbg(dev, "unregistered driver '%s'\n", | ||
| 2464 | driver ? driver->driver.name : ""); | ||
| 2465 | |||
| 2466 | return 0; | ||
| 2467 | } | ||
| 2468 | |||
| 2469 | /*-------------------------------------------------------------------------*/ | ||
| 2470 | |||
| 2471 | /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq. | ||
| 2472 | * also works for dma-capable endpoints, in pio mode or just | ||
| 2473 | * to manually advance the queue after short OUT transfers. | ||
| 2474 | */ | ||
| 2475 | static void handle_ep_small(struct net2280_ep *ep) | ||
| 2476 | { | ||
| 2477 | struct net2280_request *req; | ||
| 2478 | u32 t; | ||
| 2479 | /* 0 error, 1 mid-data, 2 done */ | ||
| 2480 | int mode = 1; | ||
| 2481 | |||
| 2482 | if (!list_empty(&ep->queue)) | ||
| 2483 | req = list_entry(ep->queue.next, | ||
| 2484 | struct net2280_request, queue); | ||
| 2485 | else | ||
| 2486 | req = NULL; | ||
| 2487 | |||
| 2488 | /* ack all, and handle what we care about */ | ||
| 2489 | t = readl(&ep->regs->ep_stat); | ||
| 2490 | ep->irqs++; | ||
| 2491 | #if 0 | ||
| 2492 | ep_vdbg(ep->dev, "%s ack ep_stat %08x, req %p\n", | ||
| 2493 | ep->ep.name, t, req ? &req->req : 0); | ||
| 2494 | #endif | ||
| 2495 | if (!ep->is_in || (ep->dev->quirks & PLX_2280)) | ||
| 2496 | writel(t & ~BIT(NAK_OUT_PACKETS), &ep->regs->ep_stat); | ||
| 2497 | else | ||
| 2498 | /* Added for 2282 */ | ||
| 2499 | writel(t, &ep->regs->ep_stat); | ||
| 2500 | |||
| 2501 | /* for ep0, monitor token irqs to catch data stage length errors | ||
| 2502 | * and to synchronize on status. | ||
| 2503 | * | ||
| 2504 | * also, to defer reporting of protocol stalls ... here's where | ||
| 2505 | * data or status first appears, handling stalls here should never | ||
| 2506 | * cause trouble on the host side.. | ||
| 2507 | * | ||
| 2508 | * control requests could be slightly faster without token synch for | ||
| 2509 | * status, but status can jam up that way. | ||
| 2510 | */ | ||
| 2511 | if (unlikely(ep->num == 0)) { | ||
| 2512 | if (ep->is_in) { | ||
| 2513 | /* status; stop NAKing */ | ||
| 2514 | if (t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) { | ||
| 2515 | if (ep->dev->protocol_stall) { | ||
| 2516 | ep->stopped = 1; | ||
| 2517 | set_halt(ep); | ||
| 2518 | } | ||
| 2519 | if (!req) | ||
| 2520 | allow_status(ep); | ||
| 2521 | mode = 2; | ||
| 2522 | /* reply to extra IN data tokens with a zlp */ | ||
| 2523 | } else if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) { | ||
| 2524 | if (ep->dev->protocol_stall) { | ||
| 2525 | ep->stopped = 1; | ||
| 2526 | set_halt(ep); | ||
| 2527 | mode = 2; | ||
| 2528 | } else if (ep->responded && | ||
| 2529 | !req && !ep->stopped) | ||
| 2530 | write_fifo(ep, NULL); | ||
| 2531 | } | ||
| 2532 | } else { | ||
| 2533 | /* status; stop NAKing */ | ||
| 2534 | if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) { | ||
| 2535 | if (ep->dev->protocol_stall) { | ||
| 2536 | ep->stopped = 1; | ||
| 2537 | set_halt(ep); | ||
| 2538 | } | ||
| 2539 | mode = 2; | ||
| 2540 | /* an extra OUT token is an error */ | ||
| 2541 | } else if (((t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) && | ||
| 2542 | req && | ||
| 2543 | req->req.actual == req->req.length) || | ||
| 2544 | (ep->responded && !req)) { | ||
| 2545 | ep->dev->protocol_stall = 1; | ||
| 2546 | set_halt(ep); | ||
| 2547 | ep->stopped = 1; | ||
| 2548 | if (req) | ||
| 2549 | done(ep, req, -EOVERFLOW); | ||
| 2550 | req = NULL; | ||
| 2551 | } | ||
| 2552 | } | ||
| 2553 | } | ||
| 2554 | |||
| 2555 | if (unlikely(!req)) | ||
| 2556 | return; | ||
| 2557 | |||
| 2558 | /* manual DMA queue advance after short OUT */ | ||
| 2559 | if (likely(ep->dma)) { | ||
| 2560 | if (t & BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT)) { | ||
| 2561 | u32 count; | ||
| 2562 | int stopped = ep->stopped; | ||
| 2563 | |||
| 2564 | /* TRANSFERRED works around OUT_DONE erratum 0112. | ||
| 2565 | * we expect (N <= maxpacket) bytes; host wrote M. | ||
| 2566 | * iff (M < N) we won't ever see a DMA interrupt. | ||
| 2567 | */ | ||
| 2568 | ep->stopped = 1; | ||
| 2569 | for (count = 0; ; t = readl(&ep->regs->ep_stat)) { | ||
| 2570 | |||
| 2571 | /* any preceding dma transfers must finish. | ||
| 2572 | * dma handles (M >= N), may empty the queue | ||
| 2573 | */ | ||
| 2574 | scan_dma_completions(ep); | ||
| 2575 | if (unlikely(list_empty(&ep->queue) || | ||
| 2576 | ep->out_overflow)) { | ||
| 2577 | req = NULL; | ||
| 2578 | break; | ||
| 2579 | } | ||
| 2580 | req = list_entry(ep->queue.next, | ||
| 2581 | struct net2280_request, queue); | ||
| 2582 | |||
| 2583 | /* here either (M < N), a "real" short rx; | ||
| 2584 | * or (M == N) and the queue didn't empty | ||
| 2585 | */ | ||
| 2586 | if (likely(t & BIT(FIFO_EMPTY))) { | ||
| 2587 | count = readl(&ep->dma->dmacount); | ||
| 2588 | count &= DMA_BYTE_COUNT_MASK; | ||
| 2589 | if (readl(&ep->dma->dmadesc) | ||
| 2590 | != req->td_dma) | ||
| 2591 | req = NULL; | ||
| 2592 | break; | ||
| 2593 | } | ||
| 2594 | udelay(1); | ||
| 2595 | } | ||
| 2596 | |||
| 2597 | /* stop DMA, leave ep NAKing */ | ||
| 2598 | writel(BIT(DMA_ABORT), &ep->dma->dmastat); | ||
| 2599 | spin_stop_dma(ep->dma); | ||
| 2600 | |||
| 2601 | if (likely(req)) { | ||
| 2602 | req->td->dmacount = 0; | ||
| 2603 | t = readl(&ep->regs->ep_avail); | ||
| 2604 | dma_done(ep, req, count, | ||
| 2605 | (ep->out_overflow || t) | ||
| 2606 | ? -EOVERFLOW : 0); | ||
| 2607 | } | ||
| 2608 | |||
| 2609 | /* also flush to prevent erratum 0106 trouble */ | ||
| 2610 | if (unlikely(ep->out_overflow || | ||
| 2611 | (ep->dev->chiprev == 0x0100 && | ||
| 2612 | ep->dev->gadget.speed | ||
| 2613 | == USB_SPEED_FULL))) { | ||
| 2614 | out_flush(ep); | ||
| 2615 | ep->out_overflow = 0; | ||
| 2616 | } | ||
| 2617 | |||
| 2618 | /* (re)start dma if needed, stop NAKing */ | ||
| 2619 | ep->stopped = stopped; | ||
| 2620 | if (!list_empty(&ep->queue)) | ||
| 2621 | restart_dma(ep); | ||
| 2622 | } else | ||
| 2623 | ep_dbg(ep->dev, "%s dma ep_stat %08x ??\n", | ||
| 2624 | ep->ep.name, t); | ||
| 2625 | return; | ||
| 2626 | |||
| 2627 | /* data packet(s) received (in the fifo, OUT) */ | ||
| 2628 | } else if (t & BIT(DATA_PACKET_RECEIVED_INTERRUPT)) { | ||
| 2629 | if (read_fifo(ep, req) && ep->num != 0) | ||
| 2630 | mode = 2; | ||
| 2631 | |||
| 2632 | /* data packet(s) transmitted (IN) */ | ||
| 2633 | } else if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) { | ||
| 2634 | unsigned len; | ||
| 2635 | |||
| 2636 | len = req->req.length - req->req.actual; | ||
| 2637 | if (len > ep->ep.maxpacket) | ||
| 2638 | len = ep->ep.maxpacket; | ||
| 2639 | req->req.actual += len; | ||
| 2640 | |||
| 2641 | /* if we wrote it all, we're usually done */ | ||
| 2642 | /* send zlps until the status stage */ | ||
| 2643 | if ((req->req.actual == req->req.length) && | ||
| 2644 | (!req->req.zero || len != ep->ep.maxpacket) && ep->num) | ||
| 2645 | mode = 2; | ||
| 2646 | |||
| 2647 | /* there was nothing to do ... */ | ||
| 2648 | } else if (mode == 1) | ||
| 2649 | return; | ||
| 2650 | |||
| 2651 | /* done */ | ||
| 2652 | if (mode == 2) { | ||
| 2653 | /* stream endpoints often resubmit/unlink in completion */ | ||
| 2654 | done(ep, req, 0); | ||
| 2655 | |||
| 2656 | /* maybe advance queue to next request */ | ||
| 2657 | if (ep->num == 0) { | ||
| 2658 | /* NOTE: net2280 could let gadget driver start the | ||
| 2659 | * status stage later. since not all controllers let | ||
| 2660 | * them control that, the api doesn't (yet) allow it. | ||
| 2661 | */ | ||
| 2662 | if (!ep->stopped) | ||
| 2663 | allow_status(ep); | ||
| 2664 | req = NULL; | ||
| 2665 | } else { | ||
| 2666 | if (!list_empty(&ep->queue) && !ep->stopped) | ||
| 2667 | req = list_entry(ep->queue.next, | ||
| 2668 | struct net2280_request, queue); | ||
| 2669 | else | ||
| 2670 | req = NULL; | ||
| 2671 | if (req && !ep->is_in) | ||
| 2672 | stop_out_naking(ep); | ||
| 2673 | } | ||
| 2674 | } | ||
| 2675 | |||
| 2676 | /* is there a buffer for the next packet? | ||
| 2677 | * for best streaming performance, make sure there is one. | ||
| 2678 | */ | ||
| 2679 | if (req && !ep->stopped) { | ||
| 2680 | |||
| 2681 | /* load IN fifo with next packet (may be zlp) */ | ||
| 2682 | if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) | ||
| 2683 | write_fifo(ep, &req->req); | ||
| 2684 | } | ||
| 2685 | } | ||
| 2686 | |||
| 2687 | static struct net2280_ep *get_ep_by_addr(struct net2280 *dev, u16 wIndex) | ||
| 2688 | { | ||
| 2689 | struct net2280_ep *ep; | ||
| 2690 | |||
| 2691 | if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) | ||
| 2692 | return &dev->ep[0]; | ||
| 2693 | list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) { | ||
| 2694 | u8 bEndpointAddress; | ||
| 2695 | |||
| 2696 | if (!ep->desc) | ||
| 2697 | continue; | ||
| 2698 | bEndpointAddress = ep->desc->bEndpointAddress; | ||
| 2699 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) | ||
| 2700 | continue; | ||
| 2701 | if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f)) | ||
| 2702 | return ep; | ||
| 2703 | } | ||
| 2704 | return NULL; | ||
| 2705 | } | ||
| 2706 | |||
| 2707 | static void defect7374_workaround(struct net2280 *dev, struct usb_ctrlrequest r) | ||
| 2708 | { | ||
| 2709 | u32 scratch, fsmvalue; | ||
| 2710 | u32 ack_wait_timeout, state; | ||
| 2711 | |||
| 2712 | /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */ | ||
| 2713 | scratch = get_idx_reg(dev->regs, SCRATCH); | ||
| 2714 | fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD); | ||
| 2715 | scratch &= ~(0xf << DEFECT7374_FSM_FIELD); | ||
| 2716 | |||
| 2717 | if (!((fsmvalue == DEFECT7374_FSM_WAITING_FOR_CONTROL_READ) && | ||
| 2718 | (r.bRequestType & USB_DIR_IN))) | ||
| 2719 | return; | ||
| 2720 | |||
| 2721 | /* This is the first Control Read for this connection: */ | ||
| 2722 | if (!(readl(&dev->usb->usbstat) & BIT(SUPER_SPEED_MODE))) { | ||
| 2723 | /* | ||
| 2724 | * Connection is NOT SS: | ||
| 2725 | * - Connection must be FS or HS. | ||
| 2726 | * - This FSM state should allow workaround software to | ||
| 2727 | * run after the next USB connection. | ||
| 2728 | */ | ||
| 2729 | scratch |= DEFECT7374_FSM_NON_SS_CONTROL_READ; | ||
| 2730 | goto restore_data_eps; | ||
| 2731 | } | ||
| 2732 | |||
| 2733 | /* Connection is SS: */ | ||
| 2734 | for (ack_wait_timeout = 0; | ||
| 2735 | ack_wait_timeout < DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS; | ||
| 2736 | ack_wait_timeout++) { | ||
| 2737 | |||
| 2738 | state = readl(&dev->plregs->pl_ep_status_1) | ||
| 2739 | & (0xff << STATE); | ||
| 2740 | if ((state >= (ACK_GOOD_NORMAL << STATE)) && | ||
| 2741 | (state <= (ACK_GOOD_MORE_ACKS_TO_COME << STATE))) { | ||
| 2742 | scratch |= DEFECT7374_FSM_SS_CONTROL_READ; | ||
| 2743 | break; | ||
| 2744 | } | ||
| 2745 | |||
| 2746 | /* | ||
| 2747 | * We have not yet received host's Data Phase ACK | ||
| 2748 | * - Wait and try again. | ||
| 2749 | */ | ||
| 2750 | udelay(DEFECT_7374_PROCESSOR_WAIT_TIME); | ||
| 2751 | |||
| 2752 | continue; | ||
| 2753 | } | ||
| 2754 | |||
| 2755 | |||
| 2756 | if (ack_wait_timeout >= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS) { | ||
| 2757 | ep_err(dev, "FAIL: Defect 7374 workaround waited but failed " | ||
| 2758 | "to detect SS host's data phase ACK."); | ||
| 2759 | ep_err(dev, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16" | ||
| 2760 | "got 0x%2.2x.\n", state >> STATE); | ||
| 2761 | } else { | ||
| 2762 | ep_warn(dev, "INFO: Defect 7374 workaround waited about\n" | ||
| 2763 | "%duSec for Control Read Data Phase ACK\n", | ||
| 2764 | DEFECT_7374_PROCESSOR_WAIT_TIME * ack_wait_timeout); | ||
| 2765 | } | ||
| 2766 | |||
| 2767 | restore_data_eps: | ||
| 2768 | /* | ||
| 2769 | * Restore data EPs to their pre-workaround settings (disabled, | ||
| 2770 | * initialized, and other details). | ||
| 2771 | */ | ||
| 2772 | defect7374_disable_data_eps(dev); | ||
| 2773 | |||
| 2774 | set_idx_reg(dev->regs, SCRATCH, scratch); | ||
| 2775 | |||
| 2776 | return; | ||
| 2777 | } | ||
| 2778 | |||
| 2779 | static void ep_stall(struct net2280_ep *ep, int stall) | ||
| 2780 | { | ||
| 2781 | struct net2280 *dev = ep->dev; | ||
| 2782 | u32 val; | ||
| 2783 | static const u32 ep_pl[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 }; | ||
| 2784 | |||
| 2785 | if (stall) { | ||
| 2786 | writel(BIT(SET_ENDPOINT_HALT) | | ||
| 2787 | /* BIT(SET_NAK_PACKETS) | */ | ||
| 2788 | BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE), | ||
| 2789 | &ep->regs->ep_rsp); | ||
| 2790 | ep->is_halt = 1; | ||
| 2791 | } else { | ||
| 2792 | if (dev->gadget.speed == USB_SPEED_SUPER) { | ||
| 2793 | /* | ||
| 2794 | * Workaround for SS SeqNum not cleared via | ||
| 2795 | * Endpoint Halt (Clear) bit. select endpoint | ||
| 2796 | */ | ||
| 2797 | val = readl(&dev->plregs->pl_ep_ctrl); | ||
| 2798 | val = (val & ~0x1f) | ep_pl[ep->num]; | ||
| 2799 | writel(val, &dev->plregs->pl_ep_ctrl); | ||
| 2800 | |||
| 2801 | val |= BIT(SEQUENCE_NUMBER_RESET); | ||
| 2802 | writel(val, &dev->plregs->pl_ep_ctrl); | ||
| 2803 | } | ||
| 2804 | val = readl(&ep->regs->ep_rsp); | ||
| 2805 | val |= BIT(CLEAR_ENDPOINT_HALT) | | ||
| 2806 | BIT(CLEAR_ENDPOINT_TOGGLE); | ||
| 2807 | writel(val, | ||
| 2808 | /* | BIT(CLEAR_NAK_PACKETS),*/ | ||
| 2809 | &ep->regs->ep_rsp); | ||
| 2810 | ep->is_halt = 0; | ||
| 2811 | val = readl(&ep->regs->ep_rsp); | ||
| 2812 | } | ||
| 2813 | } | ||
| 2814 | |||
| 2815 | static void ep_stdrsp(struct net2280_ep *ep, int value, int wedged) | ||
| 2816 | { | ||
| 2817 | /* set/clear, then synch memory views with the device */ | ||
| 2818 | if (value) { | ||
| 2819 | ep->stopped = 1; | ||
| 2820 | if (ep->num == 0) | ||
| 2821 | ep->dev->protocol_stall = 1; | ||
| 2822 | else { | ||
| 2823 | if (ep->dma) | ||
| 2824 | ep_stop_dma(ep); | ||
| 2825 | ep_stall(ep, true); | ||
| 2826 | } | ||
| 2827 | |||
| 2828 | if (wedged) | ||
| 2829 | ep->wedged = 1; | ||
| 2830 | } else { | ||
| 2831 | ep->stopped = 0; | ||
| 2832 | ep->wedged = 0; | ||
| 2833 | |||
| 2834 | ep_stall(ep, false); | ||
| 2835 | |||
| 2836 | /* Flush the queue */ | ||
| 2837 | if (!list_empty(&ep->queue)) { | ||
| 2838 | struct net2280_request *req = | ||
| 2839 | list_entry(ep->queue.next, struct net2280_request, | ||
| 2840 | queue); | ||
| 2841 | if (ep->dma) | ||
| 2842 | resume_dma(ep); | ||
| 2843 | else { | ||
| 2844 | if (ep->is_in) | ||
| 2845 | write_fifo(ep, &req->req); | ||
| 2846 | else { | ||
| 2847 | if (read_fifo(ep, req)) | ||
| 2848 | done(ep, req, 0); | ||
| 2849 | } | ||
| 2850 | } | ||
| 2851 | } | ||
| 2852 | } | ||
| 2853 | } | ||
| 2854 | |||
| 2855 | static void handle_stat0_irqs_superspeed(struct net2280 *dev, | ||
| 2856 | struct net2280_ep *ep, struct usb_ctrlrequest r) | ||
| 2857 | { | ||
| 2858 | int tmp = 0; | ||
| 2859 | |||
| 2860 | #define w_value le16_to_cpu(r.wValue) | ||
| 2861 | #define w_index le16_to_cpu(r.wIndex) | ||
| 2862 | #define w_length le16_to_cpu(r.wLength) | ||
| 2863 | |||
| 2864 | switch (r.bRequest) { | ||
| 2865 | struct net2280_ep *e; | ||
| 2866 | u16 status; | ||
| 2867 | |||
| 2868 | case USB_REQ_SET_CONFIGURATION: | ||
| 2869 | dev->addressed_state = !w_value; | ||
| 2870 | goto usb3_delegate; | ||
| 2871 | |||
| 2872 | case USB_REQ_GET_STATUS: | ||
| 2873 | switch (r.bRequestType) { | ||
| 2874 | case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE): | ||
| 2875 | status = dev->wakeup_enable ? 0x02 : 0x00; | ||
| 2876 | if (dev->selfpowered) | ||
| 2877 | status |= BIT(0); | ||
| 2878 | status |= (dev->u1_enable << 2 | dev->u2_enable << 3 | | ||
| 2879 | dev->ltm_enable << 4); | ||
| 2880 | writel(0, &dev->epregs[0].ep_irqenb); | ||
| 2881 | set_fifo_bytecount(ep, sizeof(status)); | ||
| 2882 | writel((__force u32) status, &dev->epregs[0].ep_data); | ||
| 2883 | allow_status_338x(ep); | ||
| 2884 | break; | ||
| 2885 | |||
| 2886 | case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): | ||
| 2887 | e = get_ep_by_addr(dev, w_index); | ||
| 2888 | if (!e) | ||
| 2889 | goto do_stall3; | ||
| 2890 | status = readl(&e->regs->ep_rsp) & | ||
| 2891 | BIT(CLEAR_ENDPOINT_HALT); | ||
| 2892 | writel(0, &dev->epregs[0].ep_irqenb); | ||
| 2893 | set_fifo_bytecount(ep, sizeof(status)); | ||
| 2894 | writel((__force u32) status, &dev->epregs[0].ep_data); | ||
| 2895 | allow_status_338x(ep); | ||
| 2896 | break; | ||
| 2897 | |||
| 2898 | default: | ||
| 2899 | goto usb3_delegate; | ||
| 2900 | } | ||
| 2901 | break; | ||
| 2902 | |||
| 2903 | case USB_REQ_CLEAR_FEATURE: | ||
| 2904 | switch (r.bRequestType) { | ||
| 2905 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE): | ||
| 2906 | if (!dev->addressed_state) { | ||
| 2907 | switch (w_value) { | ||
| 2908 | case USB_DEVICE_U1_ENABLE: | ||
| 2909 | dev->u1_enable = 0; | ||
| 2910 | writel(readl(&dev->usb_ext->usbctl2) & | ||
| 2911 | ~BIT(U1_ENABLE), | ||
| 2912 | &dev->usb_ext->usbctl2); | ||
| 2913 | allow_status_338x(ep); | ||
| 2914 | goto next_endpoints3; | ||
| 2915 | |||
| 2916 | case USB_DEVICE_U2_ENABLE: | ||
| 2917 | dev->u2_enable = 0; | ||
| 2918 | writel(readl(&dev->usb_ext->usbctl2) & | ||
| 2919 | ~BIT(U2_ENABLE), | ||
| 2920 | &dev->usb_ext->usbctl2); | ||
| 2921 | allow_status_338x(ep); | ||
| 2922 | goto next_endpoints3; | ||
| 2923 | |||
| 2924 | case USB_DEVICE_LTM_ENABLE: | ||
| 2925 | dev->ltm_enable = 0; | ||
| 2926 | writel(readl(&dev->usb_ext->usbctl2) & | ||
| 2927 | ~BIT(LTM_ENABLE), | ||
| 2928 | &dev->usb_ext->usbctl2); | ||
| 2929 | allow_status_338x(ep); | ||
| 2930 | goto next_endpoints3; | ||
| 2931 | |||
| 2932 | default: | ||
| 2933 | break; | ||
| 2934 | } | ||
| 2935 | } | ||
| 2936 | if (w_value == USB_DEVICE_REMOTE_WAKEUP) { | ||
| 2937 | dev->wakeup_enable = 0; | ||
| 2938 | writel(readl(&dev->usb->usbctl) & | ||
| 2939 | ~BIT(DEVICE_REMOTE_WAKEUP_ENABLE), | ||
| 2940 | &dev->usb->usbctl); | ||
| 2941 | allow_status_338x(ep); | ||
| 2942 | break; | ||
| 2943 | } | ||
| 2944 | goto usb3_delegate; | ||
| 2945 | |||
| 2946 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): | ||
| 2947 | e = get_ep_by_addr(dev, w_index); | ||
| 2948 | if (!e) | ||
| 2949 | goto do_stall3; | ||
| 2950 | if (w_value != USB_ENDPOINT_HALT) | ||
| 2951 | goto do_stall3; | ||
| 2952 | ep_vdbg(dev, "%s clear halt\n", e->ep.name); | ||
| 2953 | ep_stall(e, false); | ||
| 2954 | if (!list_empty(&e->queue) && e->td_dma) | ||
| 2955 | restart_dma(e); | ||
| 2956 | allow_status(ep); | ||
| 2957 | ep->stopped = 1; | ||
| 2958 | break; | ||
| 2959 | |||
| 2960 | default: | ||
| 2961 | goto usb3_delegate; | ||
| 2962 | } | ||
| 2963 | break; | ||
| 2964 | case USB_REQ_SET_FEATURE: | ||
| 2965 | switch (r.bRequestType) { | ||
| 2966 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE): | ||
| 2967 | if (!dev->addressed_state) { | ||
| 2968 | switch (w_value) { | ||
| 2969 | case USB_DEVICE_U1_ENABLE: | ||
| 2970 | dev->u1_enable = 1; | ||
| 2971 | writel(readl(&dev->usb_ext->usbctl2) | | ||
| 2972 | BIT(U1_ENABLE), | ||
| 2973 | &dev->usb_ext->usbctl2); | ||
| 2974 | allow_status_338x(ep); | ||
| 2975 | goto next_endpoints3; | ||
| 2976 | |||
| 2977 | case USB_DEVICE_U2_ENABLE: | ||
| 2978 | dev->u2_enable = 1; | ||
| 2979 | writel(readl(&dev->usb_ext->usbctl2) | | ||
| 2980 | BIT(U2_ENABLE), | ||
| 2981 | &dev->usb_ext->usbctl2); | ||
| 2982 | allow_status_338x(ep); | ||
| 2983 | goto next_endpoints3; | ||
| 2984 | |||
| 2985 | case USB_DEVICE_LTM_ENABLE: | ||
| 2986 | dev->ltm_enable = 1; | ||
| 2987 | writel(readl(&dev->usb_ext->usbctl2) | | ||
| 2988 | BIT(LTM_ENABLE), | ||
| 2989 | &dev->usb_ext->usbctl2); | ||
| 2990 | allow_status_338x(ep); | ||
| 2991 | goto next_endpoints3; | ||
| 2992 | default: | ||
| 2993 | break; | ||
| 2994 | } | ||
| 2995 | } | ||
| 2996 | |||
| 2997 | if (w_value == USB_DEVICE_REMOTE_WAKEUP) { | ||
| 2998 | dev->wakeup_enable = 1; | ||
| 2999 | writel(readl(&dev->usb->usbctl) | | ||
| 3000 | BIT(DEVICE_REMOTE_WAKEUP_ENABLE), | ||
| 3001 | &dev->usb->usbctl); | ||
| 3002 | allow_status_338x(ep); | ||
| 3003 | break; | ||
| 3004 | } | ||
| 3005 | goto usb3_delegate; | ||
| 3006 | |||
| 3007 | case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): | ||
| 3008 | e = get_ep_by_addr(dev, w_index); | ||
| 3009 | if (!e || (w_value != USB_ENDPOINT_HALT)) | ||
| 3010 | goto do_stall3; | ||
| 3011 | ep_stdrsp(e, true, false); | ||
| 3012 | allow_status_338x(ep); | ||
| 3013 | break; | ||
| 3014 | |||
| 3015 | default: | ||
| 3016 | goto usb3_delegate; | ||
| 3017 | } | ||
| 3018 | |||
| 3019 | break; | ||
| 3020 | default: | ||
| 3021 | |||
| 3022 | usb3_delegate: | ||
| 3023 | ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n", | ||
| 3024 | r.bRequestType, r.bRequest, | ||
| 3025 | w_value, w_index, w_length, | ||
| 3026 | readl(&ep->cfg->ep_cfg)); | ||
| 3027 | |||
| 3028 | ep->responded = 0; | ||
| 3029 | spin_unlock(&dev->lock); | ||
| 3030 | tmp = dev->driver->setup(&dev->gadget, &r); | ||
| 3031 | spin_lock(&dev->lock); | ||
| 3032 | } | ||
| 3033 | do_stall3: | ||
| 3034 | if (tmp < 0) { | ||
| 3035 | ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n", | ||
| 3036 | r.bRequestType, r.bRequest, tmp); | ||
| 3037 | dev->protocol_stall = 1; | ||
| 3038 | /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */ | ||
| 3039 | ep_stall(ep, true); | ||
| 3040 | } | ||
| 3041 | |||
| 3042 | next_endpoints3: | ||
| 3043 | |||
| 3044 | #undef w_value | ||
| 3045 | #undef w_index | ||
| 3046 | #undef w_length | ||
| 3047 | |||
| 3048 | return; | ||
| 3049 | } | ||
| 3050 | |||
| 3051 | static void handle_stat0_irqs(struct net2280 *dev, u32 stat) | ||
| 3052 | { | ||
| 3053 | struct net2280_ep *ep; | ||
| 3054 | u32 num, scratch; | ||
| 3055 | |||
| 3056 | /* most of these don't need individual acks */ | ||
| 3057 | stat &= ~BIT(INTA_ASSERTED); | ||
| 3058 | if (!stat) | ||
| 3059 | return; | ||
| 3060 | /* ep_dbg(dev, "irqstat0 %04x\n", stat); */ | ||
| 3061 | |||
| 3062 | /* starting a control request? */ | ||
| 3063 | if (unlikely(stat & BIT(SETUP_PACKET_INTERRUPT))) { | ||
| 3064 | union { | ||
| 3065 | u32 raw[2]; | ||
| 3066 | struct usb_ctrlrequest r; | ||
| 3067 | } u; | ||
| 3068 | int tmp; | ||
| 3069 | struct net2280_request *req; | ||
| 3070 | |||
| 3071 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) { | ||
| 3072 | u32 val = readl(&dev->usb->usbstat); | ||
| 3073 | if (val & BIT(SUPER_SPEED)) { | ||
| 3074 | dev->gadget.speed = USB_SPEED_SUPER; | ||
| 3075 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, | ||
| 3076 | EP0_SS_MAX_PACKET_SIZE); | ||
| 3077 | } else if (val & BIT(HIGH_SPEED)) { | ||
| 3078 | dev->gadget.speed = USB_SPEED_HIGH; | ||
| 3079 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, | ||
| 3080 | EP0_HS_MAX_PACKET_SIZE); | ||
| 3081 | } else { | ||
| 3082 | dev->gadget.speed = USB_SPEED_FULL; | ||
| 3083 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, | ||
| 3084 | EP0_HS_MAX_PACKET_SIZE); | ||
| 3085 | } | ||
| 3086 | net2280_led_speed(dev, dev->gadget.speed); | ||
| 3087 | ep_dbg(dev, "%s\n", | ||
| 3088 | usb_speed_string(dev->gadget.speed)); | ||
| 3089 | } | ||
| 3090 | |||
| 3091 | ep = &dev->ep[0]; | ||
| 3092 | ep->irqs++; | ||
| 3093 | |||
| 3094 | /* make sure any leftover request state is cleared */ | ||
| 3095 | stat &= ~BIT(ENDPOINT_0_INTERRUPT); | ||
| 3096 | while (!list_empty(&ep->queue)) { | ||
| 3097 | req = list_entry(ep->queue.next, | ||
| 3098 | struct net2280_request, queue); | ||
| 3099 | done(ep, req, (req->req.actual == req->req.length) | ||
| 3100 | ? 0 : -EPROTO); | ||
| 3101 | } | ||
| 3102 | ep->stopped = 0; | ||
| 3103 | dev->protocol_stall = 0; | ||
| 3104 | if (dev->quirks & PLX_SUPERSPEED) | ||
| 3105 | ep->is_halt = 0; | ||
| 3106 | else{ | ||
| 3107 | if (ep->dev->quirks & PLX_2280) | ||
| 3108 | tmp = BIT(FIFO_OVERFLOW) | | ||
| 3109 | BIT(FIFO_UNDERFLOW); | ||
| 3110 | else | ||
| 3111 | tmp = 0; | ||
| 3112 | |||
| 3113 | writel(tmp | BIT(TIMEOUT) | | ||
| 3114 | BIT(USB_STALL_SENT) | | ||
| 3115 | BIT(USB_IN_NAK_SENT) | | ||
| 3116 | BIT(USB_IN_ACK_RCVD) | | ||
| 3117 | BIT(USB_OUT_PING_NAK_SENT) | | ||
| 3118 | BIT(USB_OUT_ACK_SENT) | | ||
| 3119 | BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) | | ||
| 3120 | BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) | | ||
| 3121 | BIT(DATA_PACKET_RECEIVED_INTERRUPT) | | ||
| 3122 | BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | | ||
| 3123 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | | ||
| 3124 | BIT(DATA_IN_TOKEN_INTERRUPT), | ||
| 3125 | &ep->regs->ep_stat); | ||
| 3126 | } | ||
| 3127 | u.raw[0] = readl(&dev->usb->setup0123); | ||
| 3128 | u.raw[1] = readl(&dev->usb->setup4567); | ||
| 3129 | |||
| 3130 | cpu_to_le32s(&u.raw[0]); | ||
| 3131 | cpu_to_le32s(&u.raw[1]); | ||
| 3132 | |||
| 3133 | if (dev->quirks & PLX_SUPERSPEED) | ||
| 3134 | defect7374_workaround(dev, u.r); | ||
| 3135 | |||
| 3136 | tmp = 0; | ||
| 3137 | |||
| 3138 | #define w_value le16_to_cpu(u.r.wValue) | ||
| 3139 | #define w_index le16_to_cpu(u.r.wIndex) | ||
| 3140 | #define w_length le16_to_cpu(u.r.wLength) | ||
| 3141 | |||
| 3142 | /* ack the irq */ | ||
| 3143 | writel(BIT(SETUP_PACKET_INTERRUPT), &dev->regs->irqstat0); | ||
| 3144 | stat ^= BIT(SETUP_PACKET_INTERRUPT); | ||
| 3145 | |||
| 3146 | /* watch control traffic at the token level, and force | ||
| 3147 | * synchronization before letting the status stage happen. | ||
| 3148 | * FIXME ignore tokens we'll NAK, until driver responds. | ||
| 3149 | * that'll mean a lot less irqs for some drivers. | ||
| 3150 | */ | ||
| 3151 | ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0; | ||
| 3152 | if (ep->is_in) { | ||
| 3153 | scratch = BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | | ||
| 3154 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | | ||
| 3155 | BIT(DATA_IN_TOKEN_INTERRUPT); | ||
| 3156 | stop_out_naking(ep); | ||
| 3157 | } else | ||
| 3158 | scratch = BIT(DATA_PACKET_RECEIVED_INTERRUPT) | | ||
| 3159 | BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | | ||
| 3160 | BIT(DATA_IN_TOKEN_INTERRUPT); | ||
| 3161 | writel(scratch, &dev->epregs[0].ep_irqenb); | ||
| 3162 | |||
| 3163 | /* we made the hardware handle most lowlevel requests; | ||
| 3164 | * everything else goes uplevel to the gadget code. | ||
| 3165 | */ | ||
| 3166 | ep->responded = 1; | ||
| 3167 | |||
| 3168 | if (dev->gadget.speed == USB_SPEED_SUPER) { | ||
| 3169 | handle_stat0_irqs_superspeed(dev, ep, u.r); | ||
| 3170 | goto next_endpoints; | ||
| 3171 | } | ||
| 3172 | |||
| 3173 | switch (u.r.bRequest) { | ||
| 3174 | case USB_REQ_GET_STATUS: { | ||
| 3175 | struct net2280_ep *e; | ||
| 3176 | __le32 status; | ||
| 3177 | |||
| 3178 | /* hw handles device and interface status */ | ||
| 3179 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) | ||
| 3180 | goto delegate; | ||
| 3181 | e = get_ep_by_addr(dev, w_index); | ||
| 3182 | if (!e || w_length > 2) | ||
| 3183 | goto do_stall; | ||
| 3184 | |||
| 3185 | if (readl(&e->regs->ep_rsp) & BIT(SET_ENDPOINT_HALT)) | ||
| 3186 | status = cpu_to_le32(1); | ||
| 3187 | else | ||
| 3188 | status = cpu_to_le32(0); | ||
| 3189 | |||
| 3190 | /* don't bother with a request object! */ | ||
| 3191 | writel(0, &dev->epregs[0].ep_irqenb); | ||
| 3192 | set_fifo_bytecount(ep, w_length); | ||
| 3193 | writel((__force u32)status, &dev->epregs[0].ep_data); | ||
| 3194 | allow_status(ep); | ||
| 3195 | ep_vdbg(dev, "%s stat %02x\n", ep->ep.name, status); | ||
| 3196 | goto next_endpoints; | ||
| 3197 | } | ||
| 3198 | break; | ||
| 3199 | case USB_REQ_CLEAR_FEATURE: { | ||
| 3200 | struct net2280_ep *e; | ||
| 3201 | |||
| 3202 | /* hw handles device features */ | ||
| 3203 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) | ||
| 3204 | goto delegate; | ||
| 3205 | if (w_value != USB_ENDPOINT_HALT || w_length != 0) | ||
| 3206 | goto do_stall; | ||
| 3207 | e = get_ep_by_addr(dev, w_index); | ||
| 3208 | if (!e) | ||
| 3209 | goto do_stall; | ||
| 3210 | if (e->wedged) { | ||
| 3211 | ep_vdbg(dev, "%s wedged, halt not cleared\n", | ||
| 3212 | ep->ep.name); | ||
| 3213 | } else { | ||
| 3214 | ep_vdbg(dev, "%s clear halt\n", e->ep.name); | ||
| 3215 | clear_halt(e); | ||
| 3216 | if ((ep->dev->quirks & PLX_SUPERSPEED) && | ||
| 3217 | !list_empty(&e->queue) && e->td_dma) | ||
| 3218 | restart_dma(e); | ||
| 3219 | } | ||
| 3220 | allow_status(ep); | ||
| 3221 | goto next_endpoints; | ||
| 3222 | } | ||
| 3223 | break; | ||
| 3224 | case USB_REQ_SET_FEATURE: { | ||
| 3225 | struct net2280_ep *e; | ||
| 3226 | |||
| 3227 | /* hw handles device features */ | ||
| 3228 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) | ||
| 3229 | goto delegate; | ||
| 3230 | if (w_value != USB_ENDPOINT_HALT || w_length != 0) | ||
| 3231 | goto do_stall; | ||
| 3232 | e = get_ep_by_addr(dev, w_index); | ||
| 3233 | if (!e) | ||
| 3234 | goto do_stall; | ||
| 3235 | if (e->ep.name == ep0name) | ||
| 3236 | goto do_stall; | ||
| 3237 | set_halt(e); | ||
| 3238 | if ((dev->quirks & PLX_SUPERSPEED) && e->dma) | ||
| 3239 | abort_dma(e); | ||
| 3240 | allow_status(ep); | ||
| 3241 | ep_vdbg(dev, "%s set halt\n", ep->ep.name); | ||
| 3242 | goto next_endpoints; | ||
| 3243 | } | ||
| 3244 | break; | ||
| 3245 | default: | ||
| 3246 | delegate: | ||
| 3247 | ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x " | ||
| 3248 | "ep_cfg %08x\n", | ||
| 3249 | u.r.bRequestType, u.r.bRequest, | ||
| 3250 | w_value, w_index, w_length, | ||
| 3251 | readl(&ep->cfg->ep_cfg)); | ||
| 3252 | ep->responded = 0; | ||
| 3253 | spin_unlock(&dev->lock); | ||
| 3254 | tmp = dev->driver->setup(&dev->gadget, &u.r); | ||
| 3255 | spin_lock(&dev->lock); | ||
| 3256 | } | ||
| 3257 | |||
| 3258 | /* stall ep0 on error */ | ||
| 3259 | if (tmp < 0) { | ||
| 3260 | do_stall: | ||
| 3261 | ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n", | ||
| 3262 | u.r.bRequestType, u.r.bRequest, tmp); | ||
| 3263 | dev->protocol_stall = 1; | ||
| 3264 | } | ||
| 3265 | |||
| 3266 | /* some in/out token irq should follow; maybe stall then. | ||
| 3267 | * driver must queue a request (even zlp) or halt ep0 | ||
| 3268 | * before the host times out. | ||
| 3269 | */ | ||
| 3270 | } | ||
| 3271 | |||
| 3272 | #undef w_value | ||
| 3273 | #undef w_index | ||
| 3274 | #undef w_length | ||
| 3275 | |||
| 3276 | next_endpoints: | ||
| 3277 | /* endpoint data irq ? */ | ||
| 3278 | scratch = stat & 0x7f; | ||
| 3279 | stat &= ~0x7f; | ||
| 3280 | for (num = 0; scratch; num++) { | ||
| 3281 | u32 t; | ||
| 3282 | |||
| 3283 | /* do this endpoint's FIFO and queue need tending? */ | ||
| 3284 | t = BIT(num); | ||
| 3285 | if ((scratch & t) == 0) | ||
| 3286 | continue; | ||
| 3287 | scratch ^= t; | ||
| 3288 | |||
| 3289 | ep = &dev->ep[num]; | ||
| 3290 | handle_ep_small(ep); | ||
| 3291 | } | ||
| 3292 | |||
| 3293 | if (stat) | ||
| 3294 | ep_dbg(dev, "unhandled irqstat0 %08x\n", stat); | ||
| 3295 | } | ||
| 3296 | |||
| 3297 | #define DMA_INTERRUPTS (BIT(DMA_D_INTERRUPT) | \ | ||
| 3298 | BIT(DMA_C_INTERRUPT) | \ | ||
| 3299 | BIT(DMA_B_INTERRUPT) | \ | ||
| 3300 | BIT(DMA_A_INTERRUPT)) | ||
| 3301 | #define PCI_ERROR_INTERRUPTS ( \ | ||
| 3302 | BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT) | \ | ||
| 3303 | BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT) | \ | ||
| 3304 | BIT(PCI_RETRY_ABORT_INTERRUPT)) | ||
| 3305 | |||
| 3306 | static void handle_stat1_irqs(struct net2280 *dev, u32 stat) | ||
| 3307 | { | ||
| 3308 | struct net2280_ep *ep; | ||
| 3309 | u32 tmp, num, mask, scratch; | ||
| 3310 | |||
| 3311 | /* after disconnect there's nothing else to do! */ | ||
| 3312 | tmp = BIT(VBUS_INTERRUPT) | BIT(ROOT_PORT_RESET_INTERRUPT); | ||
| 3313 | mask = BIT(SUPER_SPEED) | BIT(HIGH_SPEED) | BIT(FULL_SPEED); | ||
| 3314 | |||
| 3315 | /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set. | ||
| 3316 | * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and | ||
| 3317 | * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT | ||
| 3318 | * only indicates a change in the reset state). | ||
| 3319 | */ | ||
| 3320 | if (stat & tmp) { | ||
| 3321 | writel(tmp, &dev->regs->irqstat1); | ||
| 3322 | if ((((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) && | ||
| 3323 | (readl(&dev->usb->usbstat) & mask)) || | ||
| 3324 | ((readl(&dev->usb->usbctl) & | ||
| 3325 | BIT(VBUS_PIN)) == 0)) && | ||
| 3326 | (dev->gadget.speed != USB_SPEED_UNKNOWN)) { | ||
| 3327 | ep_dbg(dev, "disconnect %s\n", | ||
| 3328 | dev->driver->driver.name); | ||
| 3329 | stop_activity(dev, dev->driver); | ||
| 3330 | ep0_start(dev); | ||
| 3331 | return; | ||
| 3332 | } | ||
| 3333 | stat &= ~tmp; | ||
| 3334 | |||
| 3335 | /* vBUS can bounce ... one of many reasons to ignore the | ||
| 3336 | * notion of hotplug events on bus connect/disconnect! | ||
| 3337 | */ | ||
| 3338 | if (!stat) | ||
| 3339 | return; | ||
| 3340 | } | ||
| 3341 | |||
| 3342 | /* NOTE: chip stays in PCI D0 state for now, but it could | ||
| 3343 | * enter D1 to save more power | ||
| 3344 | */ | ||
| 3345 | tmp = BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT); | ||
| 3346 | if (stat & tmp) { | ||
| 3347 | writel(tmp, &dev->regs->irqstat1); | ||
| 3348 | if (stat & BIT(SUSPEND_REQUEST_INTERRUPT)) { | ||
| 3349 | if (dev->driver->suspend) | ||
| 3350 | dev->driver->suspend(&dev->gadget); | ||
| 3351 | if (!enable_suspend) | ||
| 3352 | stat &= ~BIT(SUSPEND_REQUEST_INTERRUPT); | ||
| 3353 | } else { | ||
| 3354 | if (dev->driver->resume) | ||
| 3355 | dev->driver->resume(&dev->gadget); | ||
| 3356 | /* at high speed, note erratum 0133 */ | ||
| 3357 | } | ||
| 3358 | stat &= ~tmp; | ||
| 3359 | } | ||
| 3360 | |||
| 3361 | /* clear any other status/irqs */ | ||
| 3362 | if (stat) | ||
| 3363 | writel(stat, &dev->regs->irqstat1); | ||
| 3364 | |||
| 3365 | /* some status we can just ignore */ | ||
| 3366 | if (dev->quirks & PLX_2280) | ||
| 3367 | stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) | | ||
| 3368 | BIT(SUSPEND_REQUEST_INTERRUPT) | | ||
| 3369 | BIT(RESUME_INTERRUPT) | | ||
| 3370 | BIT(SOF_INTERRUPT)); | ||
| 3371 | else | ||
| 3372 | stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) | | ||
| 3373 | BIT(RESUME_INTERRUPT) | | ||
| 3374 | BIT(SOF_DOWN_INTERRUPT) | | ||
| 3375 | BIT(SOF_INTERRUPT)); | ||
| 3376 | |||
| 3377 | if (!stat) | ||
| 3378 | return; | ||
| 3379 | /* ep_dbg(dev, "irqstat1 %08x\n", stat);*/ | ||
| 3380 | |||
| 3381 | /* DMA status, for ep-{a,b,c,d} */ | ||
| 3382 | scratch = stat & DMA_INTERRUPTS; | ||
| 3383 | stat &= ~DMA_INTERRUPTS; | ||
| 3384 | scratch >>= 9; | ||
| 3385 | for (num = 0; scratch; num++) { | ||
| 3386 | struct net2280_dma_regs __iomem *dma; | ||
| 3387 | |||
| 3388 | tmp = BIT(num); | ||
| 3389 | if ((tmp & scratch) == 0) | ||
| 3390 | continue; | ||
| 3391 | scratch ^= tmp; | ||
| 3392 | |||
| 3393 | ep = &dev->ep[num + 1]; | ||
| 3394 | dma = ep->dma; | ||
| 3395 | |||
| 3396 | if (!dma) | ||
| 3397 | continue; | ||
| 3398 | |||
| 3399 | /* clear ep's dma status */ | ||
| 3400 | tmp = readl(&dma->dmastat); | ||
| 3401 | writel(tmp, &dma->dmastat); | ||
| 3402 | |||
| 3403 | /* dma sync*/ | ||
| 3404 | if (dev->quirks & PLX_SUPERSPEED) { | ||
| 3405 | u32 r_dmacount = readl(&dma->dmacount); | ||
| 3406 | if (!ep->is_in && (r_dmacount & 0x00FFFFFF) && | ||
| 3407 | (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) | ||
| 3408 | continue; | ||
| 3409 | } | ||
| 3410 | |||
| 3411 | /* chaining should stop on abort, short OUT from fifo, | ||
| 3412 | * or (stat0 codepath) short OUT transfer. | ||
| 3413 | */ | ||
| 3414 | if (!use_dma_chaining) { | ||
| 3415 | if (!(tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) { | ||
| 3416 | ep_dbg(ep->dev, "%s no xact done? %08x\n", | ||
| 3417 | ep->ep.name, tmp); | ||
| 3418 | continue; | ||
| 3419 | } | ||
| 3420 | stop_dma(ep->dma); | ||
| 3421 | } | ||
| 3422 | |||
| 3423 | /* OUT transfers terminate when the data from the | ||
| 3424 | * host is in our memory. Process whatever's done. | ||
| 3425 | * On this path, we know transfer's last packet wasn't | ||
| 3426 | * less than req->length. NAK_OUT_PACKETS may be set, | ||
| 3427 | * or the FIFO may already be holding new packets. | ||
| 3428 | * | ||
| 3429 | * IN transfers can linger in the FIFO for a very | ||
| 3430 | * long time ... we ignore that for now, accounting | ||
| 3431 | * precisely (like PIO does) needs per-packet irqs | ||
| 3432 | */ | ||
| 3433 | scan_dma_completions(ep); | ||
| 3434 | |||
| 3435 | /* disable dma on inactive queues; else maybe restart */ | ||
| 3436 | if (list_empty(&ep->queue)) { | ||
| 3437 | if (use_dma_chaining) | ||
| 3438 | stop_dma(ep->dma); | ||
| 3439 | } else { | ||
| 3440 | tmp = readl(&dma->dmactl); | ||
| 3441 | if (!use_dma_chaining || (tmp & BIT(DMA_ENABLE)) == 0) | ||
| 3442 | restart_dma(ep); | ||
| 3443 | else if (ep->is_in && use_dma_chaining) { | ||
| 3444 | struct net2280_request *req; | ||
| 3445 | __le32 dmacount; | ||
| 3446 | |||
| 3447 | /* the descriptor at the head of the chain | ||
| 3448 | * may still have VALID_BIT clear; that's | ||
| 3449 | * used to trigger changing DMA_FIFO_VALIDATE | ||
| 3450 | * (affects automagic zlp writes). | ||
| 3451 | */ | ||
| 3452 | req = list_entry(ep->queue.next, | ||
| 3453 | struct net2280_request, queue); | ||
| 3454 | dmacount = req->td->dmacount; | ||
| 3455 | dmacount &= cpu_to_le32(BIT(VALID_BIT) | | ||
| 3456 | DMA_BYTE_COUNT_MASK); | ||
| 3457 | if (dmacount && (dmacount & valid_bit) == 0) | ||
| 3458 | restart_dma(ep); | ||
| 3459 | } | ||
| 3460 | } | ||
| 3461 | ep->irqs++; | ||
| 3462 | } | ||
| 3463 | |||
| 3464 | /* NOTE: there are other PCI errors we might usefully notice. | ||
| 3465 | * if they appear very often, here's where to try recovering. | ||
| 3466 | */ | ||
| 3467 | if (stat & PCI_ERROR_INTERRUPTS) { | ||
| 3468 | ep_err(dev, "pci dma error; stat %08x\n", stat); | ||
| 3469 | stat &= ~PCI_ERROR_INTERRUPTS; | ||
| 3470 | /* these are fatal errors, but "maybe" they won't | ||
| 3471 | * happen again ... | ||
| 3472 | */ | ||
| 3473 | stop_activity(dev, dev->driver); | ||
| 3474 | ep0_start(dev); | ||
| 3475 | stat = 0; | ||
| 3476 | } | ||
| 3477 | |||
| 3478 | if (stat) | ||
| 3479 | ep_dbg(dev, "unhandled irqstat1 %08x\n", stat); | ||
| 3480 | } | ||
| 3481 | |||
| 3482 | static irqreturn_t net2280_irq(int irq, void *_dev) | ||
| 3483 | { | ||
| 3484 | struct net2280 *dev = _dev; | ||
| 3485 | |||
| 3486 | /* shared interrupt, not ours */ | ||
| 3487 | if ((dev->quirks & PLX_LEGACY) && | ||
| 3488 | (!(readl(&dev->regs->irqstat0) & BIT(INTA_ASSERTED)))) | ||
| 3489 | return IRQ_NONE; | ||
| 3490 | |||
| 3491 | spin_lock(&dev->lock); | ||
| 3492 | |||
| 3493 | /* handle disconnect, dma, and more */ | ||
| 3494 | handle_stat1_irqs(dev, readl(&dev->regs->irqstat1)); | ||
| 3495 | |||
| 3496 | /* control requests and PIO */ | ||
| 3497 | handle_stat0_irqs(dev, readl(&dev->regs->irqstat0)); | ||
| 3498 | |||
| 3499 | if (dev->quirks & PLX_SUPERSPEED) { | ||
| 3500 | /* re-enable interrupt to trigger any possible new interrupt */ | ||
| 3501 | u32 pciirqenb1 = readl(&dev->regs->pciirqenb1); | ||
| 3502 | writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1); | ||
| 3503 | writel(pciirqenb1, &dev->regs->pciirqenb1); | ||
| 3504 | } | ||
| 3505 | |||
| 3506 | spin_unlock(&dev->lock); | ||
| 3507 | |||
| 3508 | return IRQ_HANDLED; | ||
| 3509 | } | ||
| 3510 | |||
| 3511 | /*-------------------------------------------------------------------------*/ | ||
| 3512 | |||
| 3513 | static void gadget_release(struct device *_dev) | ||
| 3514 | { | ||
| 3515 | struct net2280 *dev = dev_get_drvdata(_dev); | ||
| 3516 | |||
| 3517 | kfree(dev); | ||
| 3518 | } | ||
| 3519 | |||
| 3520 | /* tear down the binding between this driver and the pci device */ | ||
| 3521 | |||
| 3522 | static void net2280_remove(struct pci_dev *pdev) | ||
| 3523 | { | ||
| 3524 | struct net2280 *dev = pci_get_drvdata(pdev); | ||
| 3525 | |||
| 3526 | usb_del_gadget_udc(&dev->gadget); | ||
| 3527 | |||
| 3528 | BUG_ON(dev->driver); | ||
| 3529 | |||
| 3530 | /* then clean up the resources we allocated during probe() */ | ||
| 3531 | net2280_led_shutdown(dev); | ||
| 3532 | if (dev->requests) { | ||
| 3533 | int i; | ||
| 3534 | for (i = 1; i < 5; i++) { | ||
| 3535 | if (!dev->ep[i].dummy) | ||
| 3536 | continue; | ||
| 3537 | pci_pool_free(dev->requests, dev->ep[i].dummy, | ||
| 3538 | dev->ep[i].td_dma); | ||
| 3539 | } | ||
| 3540 | pci_pool_destroy(dev->requests); | ||
| 3541 | } | ||
| 3542 | if (dev->got_irq) | ||
| 3543 | free_irq(pdev->irq, dev); | ||
| 3544 | if (use_msi && dev->quirks & PLX_SUPERSPEED) | ||
| 3545 | pci_disable_msi(pdev); | ||
| 3546 | if (dev->regs) | ||
| 3547 | iounmap(dev->regs); | ||
| 3548 | if (dev->region) | ||
| 3549 | release_mem_region(pci_resource_start(pdev, 0), | ||
| 3550 | pci_resource_len(pdev, 0)); | ||
| 3551 | if (dev->enabled) | ||
| 3552 | pci_disable_device(pdev); | ||
| 3553 | device_remove_file(&pdev->dev, &dev_attr_registers); | ||
| 3554 | |||
| 3555 | ep_info(dev, "unbind\n"); | ||
| 3556 | } | ||
| 3557 | |||
| 3558 | /* wrap this driver around the specified device, but | ||
| 3559 | * don't respond over USB until a gadget driver binds to us. | ||
| 3560 | */ | ||
| 3561 | |||
| 3562 | static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) | ||
| 3563 | { | ||
| 3564 | struct net2280 *dev; | ||
| 3565 | unsigned long resource, len; | ||
| 3566 | void __iomem *base = NULL; | ||
| 3567 | int retval, i; | ||
| 3568 | |||
| 3569 | if (!use_dma) | ||
| 3570 | use_dma_chaining = 0; | ||
| 3571 | |||
| 3572 | /* alloc, and start init */ | ||
| 3573 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
| 3574 | if (dev == NULL) { | ||
| 3575 | retval = -ENOMEM; | ||
| 3576 | goto done; | ||
| 3577 | } | ||
| 3578 | |||
| 3579 | pci_set_drvdata(pdev, dev); | ||
| 3580 | spin_lock_init(&dev->lock); | ||
| 3581 | dev->quirks = id->driver_data; | ||
| 3582 | dev->pdev = pdev; | ||
| 3583 | dev->gadget.ops = &net2280_ops; | ||
| 3584 | dev->gadget.max_speed = (dev->quirks & PLX_SUPERSPEED) ? | ||
| 3585 | USB_SPEED_SUPER : USB_SPEED_HIGH; | ||
| 3586 | |||
| 3587 | /* the "gadget" abstracts/virtualizes the controller */ | ||
| 3588 | dev->gadget.name = driver_name; | ||
| 3589 | |||
| 3590 | /* now all the pci goodies ... */ | ||
| 3591 | if (pci_enable_device(pdev) < 0) { | ||
| 3592 | retval = -ENODEV; | ||
| 3593 | goto done; | ||
| 3594 | } | ||
| 3595 | dev->enabled = 1; | ||
| 3596 | |||
| 3597 | /* BAR 0 holds all the registers | ||
| 3598 | * BAR 1 is 8051 memory; unused here (note erratum 0103) | ||
| 3599 | * BAR 2 is fifo memory; unused here | ||
| 3600 | */ | ||
| 3601 | resource = pci_resource_start(pdev, 0); | ||
| 3602 | len = pci_resource_len(pdev, 0); | ||
| 3603 | if (!request_mem_region(resource, len, driver_name)) { | ||
| 3604 | ep_dbg(dev, "controller already in use\n"); | ||
| 3605 | retval = -EBUSY; | ||
| 3606 | goto done; | ||
| 3607 | } | ||
| 3608 | dev->region = 1; | ||
| 3609 | |||
| 3610 | /* FIXME provide firmware download interface to put | ||
| 3611 | * 8051 code into the chip, e.g. to turn on PCI PM. | ||
| 3612 | */ | ||
| 3613 | |||
| 3614 | base = ioremap_nocache(resource, len); | ||
| 3615 | if (base == NULL) { | ||
| 3616 | ep_dbg(dev, "can't map memory\n"); | ||
| 3617 | retval = -EFAULT; | ||
| 3618 | goto done; | ||
| 3619 | } | ||
| 3620 | dev->regs = (struct net2280_regs __iomem *) base; | ||
| 3621 | dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080); | ||
| 3622 | dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100); | ||
| 3623 | dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180); | ||
| 3624 | dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200); | ||
| 3625 | dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300); | ||
| 3626 | |||
| 3627 | if (dev->quirks & PLX_SUPERSPEED) { | ||
| 3628 | u32 fsmvalue; | ||
| 3629 | u32 usbstat; | ||
| 3630 | dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *) | ||
| 3631 | (base + 0x00b4); | ||
| 3632 | dev->fiforegs = (struct usb338x_fifo_regs __iomem *) | ||
| 3633 | (base + 0x0500); | ||
| 3634 | dev->llregs = (struct usb338x_ll_regs __iomem *) | ||
| 3635 | (base + 0x0700); | ||
| 3636 | dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *) | ||
| 3637 | (base + 0x0748); | ||
| 3638 | dev->ll_tsn_regs = (struct usb338x_ll_tsn_regs __iomem *) | ||
| 3639 | (base + 0x077c); | ||
| 3640 | dev->ll_chicken_reg = (struct usb338x_ll_chi_regs __iomem *) | ||
| 3641 | (base + 0x079c); | ||
| 3642 | dev->plregs = (struct usb338x_pl_regs __iomem *) | ||
| 3643 | (base + 0x0800); | ||
| 3644 | usbstat = readl(&dev->usb->usbstat); | ||
| 3645 | dev->enhanced_mode = !!(usbstat & BIT(11)); | ||
| 3646 | dev->n_ep = (dev->enhanced_mode) ? 9 : 5; | ||
| 3647 | /* put into initial config, link up all endpoints */ | ||
| 3648 | fsmvalue = get_idx_reg(dev->regs, SCRATCH) & | ||
| 3649 | (0xf << DEFECT7374_FSM_FIELD); | ||
| 3650 | /* See if firmware needs to set up for workaround: */ | ||
| 3651 | if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) | ||
| 3652 | writel(0, &dev->usb->usbctl); | ||
| 3653 | } else{ | ||
| 3654 | dev->enhanced_mode = 0; | ||
| 3655 | dev->n_ep = 7; | ||
| 3656 | /* put into initial config, link up all endpoints */ | ||
| 3657 | writel(0, &dev->usb->usbctl); | ||
| 3658 | } | ||
| 3659 | |||
| 3660 | usb_reset(dev); | ||
| 3661 | usb_reinit(dev); | ||
| 3662 | |||
| 3663 | /* irq setup after old hardware is cleaned up */ | ||
| 3664 | if (!pdev->irq) { | ||
| 3665 | ep_err(dev, "No IRQ. Check PCI setup!\n"); | ||
| 3666 | retval = -ENODEV; | ||
| 3667 | goto done; | ||
| 3668 | } | ||
| 3669 | |||
| 3670 | if (use_msi && (dev->quirks & PLX_SUPERSPEED)) | ||
| 3671 | if (pci_enable_msi(pdev)) | ||
| 3672 | ep_err(dev, "Failed to enable MSI mode\n"); | ||
| 3673 | |||
| 3674 | if (request_irq(pdev->irq, net2280_irq, IRQF_SHARED, | ||
| 3675 | driver_name, dev)) { | ||
| 3676 | ep_err(dev, "request interrupt %d failed\n", pdev->irq); | ||
| 3677 | retval = -EBUSY; | ||
| 3678 | goto done; | ||
| 3679 | } | ||
| 3680 | dev->got_irq = 1; | ||
| 3681 | |||
| 3682 | /* DMA setup */ | ||
| 3683 | /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */ | ||
| 3684 | dev->requests = pci_pool_create("requests", pdev, | ||
| 3685 | sizeof(struct net2280_dma), | ||
| 3686 | 0 /* no alignment requirements */, | ||
| 3687 | 0 /* or page-crossing issues */); | ||
| 3688 | if (!dev->requests) { | ||
| 3689 | ep_dbg(dev, "can't get request pool\n"); | ||
| 3690 | retval = -ENOMEM; | ||
| 3691 | goto done; | ||
| 3692 | } | ||
| 3693 | for (i = 1; i < 5; i++) { | ||
| 3694 | struct net2280_dma *td; | ||
| 3695 | |||
| 3696 | td = pci_pool_alloc(dev->requests, GFP_KERNEL, | ||
| 3697 | &dev->ep[i].td_dma); | ||
| 3698 | if (!td) { | ||
| 3699 | ep_dbg(dev, "can't get dummy %d\n", i); | ||
| 3700 | retval = -ENOMEM; | ||
| 3701 | goto done; | ||
| 3702 | } | ||
| 3703 | td->dmacount = 0; /* not VALID */ | ||
| 3704 | td->dmadesc = td->dmaaddr; | ||
| 3705 | dev->ep[i].dummy = td; | ||
| 3706 | } | ||
| 3707 | |||
| 3708 | /* enable lower-overhead pci memory bursts during DMA */ | ||
| 3709 | if (dev->quirks & PLX_LEGACY) | ||
| 3710 | writel(BIT(DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) | | ||
| 3711 | /* | ||
| 3712 | * 256 write retries may not be enough... | ||
| 3713 | BIT(PCI_RETRY_ABORT_ENABLE) | | ||
| 3714 | */ | ||
| 3715 | BIT(DMA_READ_MULTIPLE_ENABLE) | | ||
| 3716 | BIT(DMA_READ_LINE_ENABLE), | ||
| 3717 | &dev->pci->pcimstctl); | ||
| 3718 | /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */ | ||
| 3719 | pci_set_master(pdev); | ||
| 3720 | pci_try_set_mwi(pdev); | ||
| 3721 | |||
| 3722 | /* ... also flushes any posted pci writes */ | ||
| 3723 | dev->chiprev = get_idx_reg(dev->regs, REG_CHIPREV) & 0xffff; | ||
| 3724 | |||
| 3725 | /* done */ | ||
| 3726 | ep_info(dev, "%s\n", driver_desc); | ||
| 3727 | ep_info(dev, "irq %d, pci mem %p, chip rev %04x\n", | ||
| 3728 | pdev->irq, base, dev->chiprev); | ||
| 3729 | ep_info(dev, "version: " DRIVER_VERSION "; dma %s %s\n", | ||
| 3730 | use_dma ? (use_dma_chaining ? "chaining" : "enabled") | ||
| 3731 | : "disabled", | ||
| 3732 | dev->enhanced_mode ? "enhanced mode" : "legacy mode"); | ||
| 3733 | retval = device_create_file(&pdev->dev, &dev_attr_registers); | ||
| 3734 | if (retval) | ||
| 3735 | goto done; | ||
| 3736 | |||
| 3737 | retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, | ||
| 3738 | gadget_release); | ||
| 3739 | if (retval) | ||
| 3740 | goto done; | ||
| 3741 | return 0; | ||
| 3742 | |||
| 3743 | done: | ||
| 3744 | if (dev) | ||
| 3745 | net2280_remove(pdev); | ||
| 3746 | return retval; | ||
| 3747 | } | ||
| 3748 | |||
| 3749 | /* make sure the board is quiescent; otherwise it will continue | ||
| 3750 | * generating IRQs across the upcoming reboot. | ||
| 3751 | */ | ||
| 3752 | |||
| 3753 | static void net2280_shutdown(struct pci_dev *pdev) | ||
| 3754 | { | ||
| 3755 | struct net2280 *dev = pci_get_drvdata(pdev); | ||
| 3756 | |||
| 3757 | /* disable IRQs */ | ||
| 3758 | writel(0, &dev->regs->pciirqenb0); | ||
| 3759 | writel(0, &dev->regs->pciirqenb1); | ||
| 3760 | |||
| 3761 | /* disable the pullup so the host will think we're gone */ | ||
| 3762 | writel(0, &dev->usb->usbctl); | ||
| 3763 | |||
| 3764 | /* Disable full-speed test mode */ | ||
| 3765 | if (dev->quirks & PLX_LEGACY) | ||
| 3766 | writel(0, &dev->usb->xcvrdiag); | ||
| 3767 | } | ||
| 3768 | |||
| 3769 | |||
| 3770 | /*-------------------------------------------------------------------------*/ | ||
| 3771 | |||
| 3772 | static const struct pci_device_id pci_ids[] = { { | ||
| 3773 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
| 3774 | .class_mask = ~0, | ||
| 3775 | .vendor = PCI_VENDOR_ID_PLX_LEGACY, | ||
| 3776 | .device = 0x2280, | ||
| 3777 | .subvendor = PCI_ANY_ID, | ||
| 3778 | .subdevice = PCI_ANY_ID, | ||
| 3779 | .driver_data = PLX_LEGACY | PLX_2280, | ||
| 3780 | }, { | ||
| 3781 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
| 3782 | .class_mask = ~0, | ||
| 3783 | .vendor = PCI_VENDOR_ID_PLX_LEGACY, | ||
| 3784 | .device = 0x2282, | ||
| 3785 | .subvendor = PCI_ANY_ID, | ||
| 3786 | .subdevice = PCI_ANY_ID, | ||
| 3787 | .driver_data = PLX_LEGACY, | ||
| 3788 | }, | ||
| 3789 | { | ||
| 3790 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
| 3791 | .class_mask = ~0, | ||
| 3792 | .vendor = PCI_VENDOR_ID_PLX, | ||
| 3793 | .device = 0x3380, | ||
| 3794 | .subvendor = PCI_ANY_ID, | ||
| 3795 | .subdevice = PCI_ANY_ID, | ||
| 3796 | .driver_data = PLX_SUPERSPEED, | ||
| 3797 | }, | ||
| 3798 | { | ||
| 3799 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
| 3800 | .class_mask = ~0, | ||
| 3801 | .vendor = PCI_VENDOR_ID_PLX, | ||
| 3802 | .device = 0x3382, | ||
| 3803 | .subvendor = PCI_ANY_ID, | ||
| 3804 | .subdevice = PCI_ANY_ID, | ||
| 3805 | .driver_data = PLX_SUPERSPEED, | ||
| 3806 | }, | ||
| 3807 | { /* end: all zeroes */ } | ||
| 3808 | }; | ||
| 3809 | MODULE_DEVICE_TABLE(pci, pci_ids); | ||
| 3810 | |||
| 3811 | /* pci driver glue; this is a "new style" PCI driver module */ | ||
| 3812 | static struct pci_driver net2280_pci_driver = { | ||
| 3813 | .name = (char *) driver_name, | ||
| 3814 | .id_table = pci_ids, | ||
| 3815 | |||
| 3816 | .probe = net2280_probe, | ||
| 3817 | .remove = net2280_remove, | ||
| 3818 | .shutdown = net2280_shutdown, | ||
| 3819 | |||
| 3820 | /* FIXME add power management support */ | ||
| 3821 | }; | ||
| 3822 | |||
| 3823 | module_pci_driver(net2280_pci_driver); | ||
| 3824 | |||
| 3825 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
| 3826 | MODULE_AUTHOR("David Brownell"); | ||
| 3827 | MODULE_LICENSE("GPL"); | ||
| @@ -0,0 +1,403 @@ | |||
| 1 | /* | ||
| 2 | * NetChip 2280 high/full speed USB device controller. | ||
| 3 | * Unlike many such controllers, this one talks PCI. | ||
| 4 | */ | ||
| 5 | |||
| 6 | /* | ||
| 7 | * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com) | ||
| 8 | * Copyright (C) 2003 David Brownell | ||
| 9 | * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or modify | ||
| 12 | * it under the terms of the GNU General Public License as published by | ||
| 13 | * the Free Software Foundation; either version 2 of the License, or | ||
| 14 | * (at your option) any later version. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/usb/net2280.h> | ||
| 18 | #include <linux/usb/usb338x.h> | ||
| 19 | |||
| 20 | /*-------------------------------------------------------------------------*/ | ||
| 21 | |||
| 22 | #ifdef __KERNEL__ | ||
| 23 | |||
| 24 | /* indexed registers [11.10] are accessed indirectly | ||
| 25 | * caller must own the device lock. | ||
| 26 | */ | ||
| 27 | |||
| 28 | static inline u32 get_idx_reg(struct net2280_regs __iomem *regs, u32 index) | ||
| 29 | { | ||
| 30 | writel(index, ®s->idxaddr); | ||
| 31 | /* NOTE: synchs device/cpu memory views */ | ||
| 32 | return readl(®s->idxdata); | ||
| 33 | } | ||
| 34 | |||
| 35 | static inline void | ||
| 36 | set_idx_reg(struct net2280_regs __iomem *regs, u32 index, u32 value) | ||
| 37 | { | ||
| 38 | writel(index, ®s->idxaddr); | ||
| 39 | writel(value, ®s->idxdata); | ||
| 40 | /* posted, may not be visible yet */ | ||
| 41 | } | ||
| 42 | |||
| 43 | #endif /* __KERNEL__ */ | ||
| 44 | |||
| 45 | #define PCI_VENDOR_ID_PLX_LEGACY 0x17cc | ||
| 46 | |||
| 47 | #define PLX_LEGACY BIT(0) | ||
| 48 | #define PLX_2280 BIT(1) | ||
| 49 | #define PLX_SUPERSPEED BIT(2) | ||
| 50 | |||
| 51 | #define REG_DIAG 0x0 | ||
| 52 | #define RETRY_COUNTER 16 | ||
| 53 | #define FORCE_PCI_SERR 11 | ||
| 54 | #define FORCE_PCI_INTERRUPT 10 | ||
| 55 | #define FORCE_USB_INTERRUPT 9 | ||
| 56 | #define FORCE_CPU_INTERRUPT 8 | ||
| 57 | #define ILLEGAL_BYTE_ENABLES 5 | ||
| 58 | #define FAST_TIMES 4 | ||
| 59 | #define FORCE_RECEIVE_ERROR 2 | ||
| 60 | #define FORCE_TRANSMIT_CRC_ERROR 0 | ||
| 61 | #define REG_FRAME 0x02 /* from last sof */ | ||
| 62 | #define REG_CHIPREV 0x03 /* in bcd */ | ||
| 63 | #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */ | ||
| 64 | |||
| 65 | #define CHIPREV_1 0x0100 | ||
| 66 | #define CHIPREV_1A 0x0110 | ||
| 67 | |||
| 68 | /* DEFECT 7374 */ | ||
| 69 | #define DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS 200 | ||
| 70 | #define DEFECT_7374_PROCESSOR_WAIT_TIME 10 | ||
| 71 | |||
| 72 | /* ep0 max packet size */ | ||
| 73 | #define EP0_SS_MAX_PACKET_SIZE 0x200 | ||
| 74 | #define EP0_HS_MAX_PACKET_SIZE 0x40 | ||
| 75 | #ifdef __KERNEL__ | ||
| 76 | |||
| 77 | /*-------------------------------------------------------------------------*/ | ||
| 78 | |||
| 79 | /* [8.3] for scatter/gather i/o | ||
| 80 | * use struct net2280_dma_regs bitfields | ||
| 81 | */ | ||
| 82 | struct net2280_dma { | ||
| 83 | __le32 dmacount; | ||
| 84 | __le32 dmaaddr; /* the buffer */ | ||
| 85 | __le32 dmadesc; /* next dma descriptor */ | ||
| 86 | __le32 _reserved; | ||
| 87 | } __aligned(16); | ||
| 88 | |||
| 89 | /*-------------------------------------------------------------------------*/ | ||
| 90 | |||
| 91 | /* DRIVER DATA STRUCTURES and UTILITIES */ | ||
| 92 | |||
| 93 | struct net2280_ep { | ||
| 94 | struct usb_ep ep; | ||
| 95 | struct net2280_ep_regs __iomem *cfg; | ||
| 96 | struct net2280_ep_regs __iomem *regs; | ||
| 97 | struct net2280_dma_regs __iomem *dma; | ||
| 98 | struct net2280_dma *dummy; | ||
| 99 | struct usb338x_fifo_regs __iomem *fiforegs; | ||
| 100 | dma_addr_t td_dma; /* of dummy */ | ||
| 101 | struct net2280 *dev; | ||
| 102 | unsigned long irqs; | ||
| 103 | unsigned is_halt:1, dma_started:1; | ||
| 104 | |||
| 105 | /* analogous to a host-side qh */ | ||
| 106 | struct list_head queue; | ||
| 107 | const struct usb_endpoint_descriptor *desc; | ||
| 108 | unsigned num : 8, | ||
| 109 | fifo_size : 12, | ||
| 110 | in_fifo_validate : 1, | ||
| 111 | out_overflow : 1, | ||
| 112 | stopped : 1, | ||
| 113 | wedged : 1, | ||
| 114 | is_in : 1, | ||
| 115 | is_iso : 1, | ||
| 116 | responded : 1; | ||
| 117 | }; | ||
| 118 | |||
| 119 | static inline void allow_status(struct net2280_ep *ep) | ||
| 120 | { | ||
| 121 | /* ep0 only */ | ||
| 122 | writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) | | ||
| 123 | BIT(CLEAR_NAK_OUT_PACKETS) | | ||
| 124 | BIT(CLEAR_NAK_OUT_PACKETS_MODE), | ||
| 125 | &ep->regs->ep_rsp); | ||
| 126 | ep->stopped = 1; | ||
| 127 | } | ||
| 128 | |||
| 129 | static void allow_status_338x(struct net2280_ep *ep) | ||
| 130 | { | ||
| 131 | /* | ||
| 132 | * Control Status Phase Handshake was set by the chip when the setup | ||
| 133 | * packet arrived. While set, the chip automatically NAKs the host's | ||
| 134 | * Status Phase tokens. | ||
| 135 | */ | ||
| 136 | writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE), &ep->regs->ep_rsp); | ||
| 137 | |||
| 138 | ep->stopped = 1; | ||
| 139 | |||
| 140 | /* TD 9.9 Halt Endpoint test. TD 9.22 set feature test. */ | ||
| 141 | ep->responded = 0; | ||
| 142 | } | ||
| 143 | |||
| 144 | struct net2280_request { | ||
| 145 | struct usb_request req; | ||
| 146 | struct net2280_dma *td; | ||
| 147 | dma_addr_t td_dma; | ||
| 148 | struct list_head queue; | ||
| 149 | unsigned mapped : 1, | ||
| 150 | valid : 1; | ||
| 151 | }; | ||
| 152 | |||
| 153 | struct net2280 { | ||
| 154 | /* each pci device provides one gadget, several endpoints */ | ||
| 155 | struct usb_gadget gadget; | ||
| 156 | spinlock_t lock; | ||
| 157 | struct net2280_ep ep[9]; | ||
| 158 | struct usb_gadget_driver *driver; | ||
| 159 | unsigned enabled : 1, | ||
| 160 | protocol_stall : 1, | ||
| 161 | softconnect : 1, | ||
| 162 | got_irq : 1, | ||
| 163 | region:1, | ||
| 164 | u1_enable:1, | ||
| 165 | u2_enable:1, | ||
| 166 | ltm_enable:1, | ||
| 167 | wakeup_enable:1, | ||
| 168 | selfpowered:1, | ||
| 169 | addressed_state:1; | ||
| 170 | u16 chiprev; | ||
| 171 | int enhanced_mode; | ||
| 172 | int n_ep; | ||
| 173 | kernel_ulong_t quirks; | ||
| 174 | |||
| 175 | |||
| 176 | /* pci state used to access those endpoints */ | ||
| 177 | struct pci_dev *pdev; | ||
| 178 | struct net2280_regs __iomem *regs; | ||
| 179 | struct net2280_usb_regs __iomem *usb; | ||
| 180 | struct usb338x_usb_ext_regs __iomem *usb_ext; | ||
| 181 | struct net2280_pci_regs __iomem *pci; | ||
| 182 | struct net2280_dma_regs __iomem *dma; | ||
| 183 | struct net2280_dep_regs __iomem *dep; | ||
| 184 | struct net2280_ep_regs __iomem *epregs; | ||
| 185 | struct usb338x_fifo_regs __iomem *fiforegs; | ||
| 186 | struct usb338x_ll_regs __iomem *llregs; | ||
| 187 | struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs; | ||
| 188 | struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs; | ||
| 189 | struct usb338x_ll_chi_regs __iomem *ll_chicken_reg; | ||
| 190 | struct usb338x_pl_regs __iomem *plregs; | ||
| 191 | |||
| 192 | struct pci_pool *requests; | ||
| 193 | /* statistics...*/ | ||
| 194 | }; | ||
| 195 | |||
| 196 | static inline void set_halt(struct net2280_ep *ep) | ||
| 197 | { | ||
| 198 | /* ep0 and bulk/intr endpoints */ | ||
| 199 | writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) | | ||
| 200 | /* set NAK_OUT for erratum 0114 */ | ||
| 201 | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS) | | ||
| 202 | BIT(SET_ENDPOINT_HALT), | ||
| 203 | &ep->regs->ep_rsp); | ||
| 204 | } | ||
| 205 | |||
| 206 | static inline void clear_halt(struct net2280_ep *ep) | ||
| 207 | { | ||
| 208 | /* ep0 and bulk/intr endpoints */ | ||
| 209 | writel(BIT(CLEAR_ENDPOINT_HALT) | | ||
| 210 | BIT(CLEAR_ENDPOINT_TOGGLE) | | ||
| 211 | /* | ||
| 212 | * unless the gadget driver left a short packet in the | ||
| 213 | * fifo, this reverses the erratum 0114 workaround. | ||
| 214 | */ | ||
| 215 | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS), | ||
| 216 | &ep->regs->ep_rsp); | ||
| 217 | } | ||
| 218 | |||
| 219 | /* | ||
| 220 | * FSM value for Defect 7374 (U1U2 Test) is managed in | ||
| 221 | * chip's SCRATCH register: | ||
| 222 | */ | ||
| 223 | #define DEFECT7374_FSM_FIELD 28 | ||
| 224 | |||
| 225 | /* Waiting for Control Read: | ||
| 226 | * - A transition to this state indicates a fresh USB connection, | ||
| 227 | * before the first Setup Packet. The connection speed is not | ||
| 228 | * known. Firmware is waiting for the first Control Read. | ||
| 229 | * - Starting state: This state can be thought of as the FSM's typical | ||
| 230 | * starting state. | ||
| 231 | * - Tip: Upon the first SS Control Read the FSM never | ||
| 232 | * returns to this state. | ||
| 233 | */ | ||
| 234 | #define DEFECT7374_FSM_WAITING_FOR_CONTROL_READ BIT(DEFECT7374_FSM_FIELD) | ||
| 235 | |||
| 236 | /* Non-SS Control Read: | ||
| 237 | * - A transition to this state indicates detection of the first HS | ||
| 238 | * or FS Control Read. | ||
| 239 | * - Tip: Upon the first SS Control Read the FSM never | ||
| 240 | * returns to this state. | ||
| 241 | */ | ||
| 242 | #define DEFECT7374_FSM_NON_SS_CONTROL_READ (2 << DEFECT7374_FSM_FIELD) | ||
| 243 | |||
| 244 | /* SS Control Read: | ||
| 245 | * - A transition to this state indicates detection of the | ||
| 246 | * first SS Control Read. | ||
| 247 | * - This state indicates workaround completion. Workarounds no longer | ||
| 248 | * need to be applied (as long as the chip remains powered up). | ||
| 249 | * - Tip: Once in this state the FSM state does not change (until | ||
| 250 | * the chip's power is lost and restored). | ||
| 251 | * - This can be thought of as the final state of the FSM; | ||
| 252 | * the FSM 'locks-up' in this state until the chip loses power. | ||
| 253 | */ | ||
| 254 | #define DEFECT7374_FSM_SS_CONTROL_READ (3 << DEFECT7374_FSM_FIELD) | ||
| 255 | |||
| 256 | #ifdef USE_RDK_LEDS | ||
| 257 | |||
| 258 | static inline void net2280_led_init(struct net2280 *dev) | ||
| 259 | { | ||
| 260 | /* LED3 (green) is on during USB activity. note erratum 0113. */ | ||
| 261 | writel(BIT(GPIO3_LED_SELECT) | | ||
| 262 | BIT(GPIO3_OUTPUT_ENABLE) | | ||
| 263 | BIT(GPIO2_OUTPUT_ENABLE) | | ||
| 264 | BIT(GPIO1_OUTPUT_ENABLE) | | ||
| 265 | BIT(GPIO0_OUTPUT_ENABLE), | ||
| 266 | &dev->regs->gpioctl); | ||
| 267 | } | ||
| 268 | |||
| 269 | /* indicate speed with bi-color LED 0/1 */ | ||
| 270 | static inline | ||
| 271 | void net2280_led_speed(struct net2280 *dev, enum usb_device_speed speed) | ||
| 272 | { | ||
| 273 | u32 val = readl(&dev->regs->gpioctl); | ||
| 274 | switch (speed) { | ||
| 275 | case USB_SPEED_SUPER: /* green + red */ | ||
| 276 | val |= BIT(GPIO0_DATA) | BIT(GPIO1_DATA); | ||
| 277 | break; | ||
| 278 | case USB_SPEED_HIGH: /* green */ | ||
| 279 | val &= ~BIT(GPIO0_DATA); | ||
| 280 | val |= BIT(GPIO1_DATA); | ||
| 281 | break; | ||
| 282 | case USB_SPEED_FULL: /* red */ | ||
| 283 | val &= ~BIT(GPIO1_DATA); | ||
| 284 | val |= BIT(GPIO0_DATA); | ||
| 285 | break; | ||
| 286 | default: /* (off/black) */ | ||
| 287 | val &= ~(BIT(GPIO1_DATA) | BIT(GPIO0_DATA)); | ||
| 288 | break; | ||
| 289 | } | ||
| 290 | writel(val, &dev->regs->gpioctl); | ||
| 291 | } | ||
| 292 | |||
| 293 | /* indicate power with LED 2 */ | ||
| 294 | static inline void net2280_led_active(struct net2280 *dev, int is_active) | ||
| 295 | { | ||
| 296 | u32 val = readl(&dev->regs->gpioctl); | ||
| 297 | |||
| 298 | /* FIXME this LED never seems to turn on.*/ | ||
| 299 | if (is_active) | ||
| 300 | val |= GPIO2_DATA; | ||
| 301 | else | ||
| 302 | val &= ~GPIO2_DATA; | ||
| 303 | writel(val, &dev->regs->gpioctl); | ||
| 304 | } | ||
| 305 | |||
| 306 | static inline void net2280_led_shutdown(struct net2280 *dev) | ||
| 307 | { | ||
| 308 | /* turn off all four GPIO*_DATA bits */ | ||
| 309 | writel(readl(&dev->regs->gpioctl) & ~0x0f, | ||
| 310 | &dev->regs->gpioctl); | ||
| 311 | } | ||
| 312 | |||
| 313 | #else | ||
| 314 | |||
| 315 | #define net2280_led_init(dev) do { } while (0) | ||
| 316 | #define net2280_led_speed(dev, speed) do { } while (0) | ||
| 317 | #define net2280_led_shutdown(dev) do { } while (0) | ||
| 318 | |||
| 319 | #endif | ||
| 320 | |||
| 321 | /*-------------------------------------------------------------------------*/ | ||
| 322 | |||
| 323 | #define ep_dbg(ndev, fmt, args...) \ | ||
| 324 | dev_dbg((&((ndev)->pdev->dev)), fmt, ##args) | ||
| 325 | |||
| 326 | #define ep_vdbg(ndev, fmt, args...) \ | ||
| 327 | dev_vdbg((&((ndev)->pdev->dev)), fmt, ##args) | ||
| 328 | |||
| 329 | #define ep_info(ndev, fmt, args...) \ | ||
| 330 | dev_info((&((ndev)->pdev->dev)), fmt, ##args) | ||
| 331 | |||
| 332 | #define ep_warn(ndev, fmt, args...) \ | ||
| 333 | dev_warn((&((ndev)->pdev->dev)), fmt, ##args) | ||
| 334 | |||
| 335 | #define ep_err(ndev, fmt, args...) \ | ||
| 336 | dev_err((&((ndev)->pdev->dev)), fmt, ##args) | ||
| 337 | |||
| 338 | /*-------------------------------------------------------------------------*/ | ||
| 339 | |||
| 340 | static inline void set_fifo_bytecount(struct net2280_ep *ep, unsigned count) | ||
| 341 | { | ||
| 342 | if (ep->dev->pdev->vendor == 0x17cc) | ||
| 343 | writeb(count, 2 + (u8 __iomem *) &ep->regs->ep_cfg); | ||
| 344 | else{ | ||
| 345 | u32 tmp = readl(&ep->cfg->ep_cfg) & | ||
| 346 | (~(0x07 << EP_FIFO_BYTE_COUNT)); | ||
| 347 | writel(tmp | (count << EP_FIFO_BYTE_COUNT), &ep->cfg->ep_cfg); | ||
| 348 | } | ||
| 349 | } | ||
| 350 | |||
| 351 | static inline void start_out_naking(struct net2280_ep *ep) | ||
| 352 | { | ||
| 353 | /* NOTE: hardware races lurk here, and PING protocol issues */ | ||
| 354 | writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 355 | /* synch with device */ | ||
| 356 | readl(&ep->regs->ep_rsp); | ||
| 357 | } | ||
| 358 | |||
| 359 | #ifdef DEBUG | ||
| 360 | static inline void assert_out_naking(struct net2280_ep *ep, const char *where) | ||
| 361 | { | ||
| 362 | u32 tmp = readl(&ep->regs->ep_stat); | ||
| 363 | |||
| 364 | if ((tmp & BIT(NAK_OUT_PACKETS)) == 0) { | ||
| 365 | ep_dbg(ep->dev, "%s %s %08x !NAK\n", | ||
| 366 | ep->ep.name, where, tmp); | ||
| 367 | writel(BIT(SET_NAK_OUT_PACKETS), | ||
| 368 | &ep->regs->ep_rsp); | ||
| 369 | } | ||
| 370 | } | ||
| 371 | #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep, __func__) | ||
| 372 | #else | ||
| 373 | #define ASSERT_OUT_NAKING(ep) do {} while (0) | ||
| 374 | #endif | ||
| 375 | |||
| 376 | static inline void stop_out_naking(struct net2280_ep *ep) | ||
| 377 | { | ||
| 378 | u32 tmp; | ||
| 379 | |||
| 380 | tmp = readl(&ep->regs->ep_stat); | ||
| 381 | if ((tmp & BIT(NAK_OUT_PACKETS)) != 0) | ||
| 382 | writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp); | ||
| 383 | } | ||
| 384 | |||
| 385 | |||
| 386 | static inline void set_max_speed(struct net2280_ep *ep, u32 max) | ||
| 387 | { | ||
| 388 | u32 reg; | ||
| 389 | static const u32 ep_enhanced[9] = { 0x10, 0x60, 0x30, 0x80, | ||
| 390 | 0x50, 0x20, 0x70, 0x40, 0x90 }; | ||
| 391 | |||
| 392 | if (ep->dev->enhanced_mode) | ||
| 393 | reg = ep_enhanced[ep->num]; | ||
| 394 | else{ | ||
| 395 | reg = (ep->num + 1) * 0x10; | ||
| 396 | if (ep->dev->gadget.speed != USB_SPEED_HIGH) | ||
| 397 | reg += 1; | ||
| 398 | } | ||
| 399 | |||
| 400 | set_idx_reg(ep->dev->regs, reg, max); | ||
| 401 | } | ||
| 402 | |||
| 403 | #endif /* __KERNEL__ */ | ||
| @@ -2079,10 +2079,7 @@ static int omap_udc_start(struct usb_gadget *g, · 2078 unmodified lines | |||
| 2079 | &udc->gadget); | 2079 | &udc->gadget); |
| 2080 | if (status < 0) { | 2080 | if (status < 0) { |
| 2081 | ERR("can't bind to transceiver\n"); | 2081 | ERR("can't bind to transceiver\n"); |
| 2082 | if (driver->unbind) { | 2082 | udc->driver = NULL; |
| 2083 | driver->unbind(&udc->gadget); | ||
| 2084 | udc->driver = NULL; | ||
| 2085 | } | ||
| 2086 | goto done; | 2083 | goto done; |
| 2087 | } | 2084 | } |
| 2088 | } else { | 2085 | } else { |
File renamed without changes.
File renamed without changes.
| @@ -16,6 +16,7 @@ · 15 unmodified lines | |||
| 16 | /* #define VERBOSE_DEBUG */ | 16 | /* #define VERBOSE_DEBUG */ |
| 17 | 17 | ||
| 18 | #include <linux/device.h> | 18 | #include <linux/device.h> |
| 19 | #include <linux/gpio.h> | ||
| 19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 20 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
| 21 | #include <linux/ioport.h> | 22 | #include <linux/ioport.h> |
| @@ -40,7 +41,6 @@ · 18 unmodified lines | |||
| 40 | 41 | ||
| 41 | #include <asm/byteorder.h> | 42 | #include <asm/byteorder.h> |
| 42 | #include <asm/dma.h> | 43 | #include <asm/dma.h> |
| 43 | #include <asm/gpio.h> | ||
| 44 | #include <asm/mach-types.h> | 44 | #include <asm/mach-types.h> |
| 45 | #include <asm/unaligned.h> | 45 | #include <asm/unaligned.h> |
| 46 | 46 | ||
| @@ -2105,11 +2105,9 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 2058 unmodified lines | |||
| 2105 | if (irq < 0) | 2105 | if (irq < 0) |
| 2106 | return -ENODEV; | 2106 | return -ENODEV; |
| 2107 | 2107 | ||
| 2108 | dev->clk = clk_get(&pdev->dev, NULL); | 2108 | dev->clk = devm_clk_get(&pdev->dev, NULL); |
| 2109 | if (IS_ERR(dev->clk)) { | 2109 | if (IS_ERR(dev->clk)) |
| 2110 | retval = PTR_ERR(dev->clk); | 2110 | return PTR_ERR(dev->clk); |
| 2111 | goto err_clk; | ||
| 2112 | } | ||
| 2113 | 2111 | ||
| 2114 | pr_debug("%s: IRQ %d%s%s\n", driver_name, irq, | 2112 | pr_debug("%s: IRQ %d%s%s\n", driver_name, irq, |
| 2115 | dev->has_cfr ? "" : " (!cfr)", | 2113 | dev->has_cfr ? "" : " (!cfr)", |
| @@ -2120,15 +2118,16 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 4 unmodified lines | |||
| 2120 | dev->dev = &pdev->dev; | 2118 | dev->dev = &pdev->dev; |
| 2121 | dev->mach = dev_get_platdata(&pdev->dev); | 2119 | dev->mach = dev_get_platdata(&pdev->dev); |
| 2122 | 2120 | ||
| 2123 | dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); | 2121 | dev->transceiver = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
| 2124 | 2122 | ||
| 2125 | if (gpio_is_valid(dev->mach->gpio_pullup)) { | 2123 | if (gpio_is_valid(dev->mach->gpio_pullup)) { |
| 2126 | if ((retval = gpio_request(dev->mach->gpio_pullup, | 2124 | retval = devm_gpio_request(&pdev->dev, dev->mach->gpio_pullup, |
| 2127 | "pca25x_udc GPIO PULLUP"))) { | 2125 | "pca25x_udc GPIO PULLUP"); |
| 2126 | if (retval) { | ||
| 2128 | dev_dbg(&pdev->dev, | 2127 | dev_dbg(&pdev->dev, |
| 2129 | "can't get pullup gpio %d, err: %d\n", | 2128 | "can't get pullup gpio %d, err: %d\n", |
| 2130 | dev->mach->gpio_pullup, retval); | 2129 | dev->mach->gpio_pullup, retval); |
| 2131 | goto err_gpio_pullup; | 2130 | goto err; |
| 2132 | } | 2131 | } |
| 2133 | gpio_direction_output(dev->mach->gpio_pullup, 0); | 2132 | gpio_direction_output(dev->mach->gpio_pullup, 0); |
| 2134 | } | 2133 | } |
| @@ -2146,30 +2145,32 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 11 unmodified lines | |||
| 2146 | dev->vbus = 0; | 2145 | dev->vbus = 0; |
| 2147 | 2146 | ||
| 2148 | /* irq setup after old hardware state is cleaned up */ | 2147 | /* irq setup after old hardware state is cleaned up */ |
| 2149 | retval = request_irq(irq, pxa25x_udc_irq, | 2148 | retval = devm_request_irq(&pdev->dev, irq, pxa25x_udc_irq, 0, |
| 2150 | 0, driver_name, dev); | 2149 | driver_name, dev); |
| 2151 | if (retval != 0) { | 2150 | if (retval != 0) { |
| 2152 | pr_err("%s: can't get irq %d, err %d\n", | 2151 | pr_err("%s: can't get irq %d, err %d\n", |
| 2153 | driver_name, irq, retval); | 2152 | driver_name, irq, retval); |
| 2154 | goto err_irq1; | 2153 | goto err; |
| 2155 | } | 2154 | } |
| 2156 | dev->got_irq = 1; | 2155 | dev->got_irq = 1; |
| 2157 | 2156 | ||
| 2158 | #ifdef CONFIG_ARCH_LUBBOCK | 2157 | #ifdef CONFIG_ARCH_LUBBOCK |
| 2159 | if (machine_is_lubbock()) { | 2158 | if (machine_is_lubbock()) { |
| 2160 | retval = request_irq(LUBBOCK_USB_DISC_IRQ, lubbock_vbus_irq, | 2159 | retval = devm_request_irq(&pdev->dev, LUBBOCK_USB_DISC_IRQ, |
| 2161 | 0, driver_name, dev); | 2160 | lubbock_vbus_irq, 0, driver_name, |
| 2161 | dev); | ||
| 2162 | if (retval != 0) { | 2162 | if (retval != 0) { |
| 2163 | pr_err("%s: can't get irq %i, err %d\n", | 2163 | pr_err("%s: can't get irq %i, err %d\n", |
| 2164 | driver_name, LUBBOCK_USB_DISC_IRQ, retval); | 2164 | driver_name, LUBBOCK_USB_DISC_IRQ, retval); |
| 2165 | goto err_irq_lub; | 2165 | goto err; |
| 2166 | } | 2166 | } |
| 2167 | retval = request_irq(LUBBOCK_USB_IRQ, lubbock_vbus_irq, | 2167 | retval = devm_request_irq(&pdev->dev, LUBBOCK_USB_IRQ, |
| 2168 | 0, driver_name, dev); | 2168 | lubbock_vbus_irq, 0, driver_name, |
| 2169 | dev); | ||
| 2169 | if (retval != 0) { | 2170 | if (retval != 0) { |
| 2170 | pr_err("%s: can't get irq %i, err %d\n", | 2171 | pr_err("%s: can't get irq %i, err %d\n", |
| 2171 | driver_name, LUBBOCK_USB_IRQ, retval); | 2172 | driver_name, LUBBOCK_USB_IRQ, retval); |
| 2172 | goto lubbock_fail0; | 2173 | goto err; |
| 2173 | } | 2174 | } |
| 2174 | } else | 2175 | } else |
| 2175 | #endif | 2176 | #endif |
| @@ -2180,22 +2181,9 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 4 unmodified lines | |||
| 2180 | return retval; | 2181 | return retval; |
| 2181 | 2182 | ||
| 2182 | remove_debug_files(dev); | 2183 | remove_debug_files(dev); |
| 2183 | #ifdef CONFIG_ARCH_LUBBOCK | 2184 | err: |
| 2184 | lubbock_fail0: | 2185 | if (!IS_ERR_OR_NULL(dev->transceiver)) |
| 2185 | free_irq(LUBBOCK_USB_DISC_IRQ, dev); | ||
| 2186 | err_irq_lub: | ||
| 2187 | free_irq(irq, dev); | ||
| 2188 | #endif | ||
| 2189 | err_irq1: | ||
| 2190 | if (gpio_is_valid(dev->mach->gpio_pullup)) | ||
| 2191 | gpio_free(dev->mach->gpio_pullup); | ||
| 2192 | err_gpio_pullup: | ||
| 2193 | if (!IS_ERR_OR_NULL(dev->transceiver)) { | ||
| 2194 | usb_put_phy(dev->transceiver); | ||
| 2195 | dev->transceiver = NULL; | 2186 | dev->transceiver = NULL; |
| 2196 | } | ||
| 2197 | clk_put(dev->clk); | ||
| 2198 | err_clk: | ||
| 2199 | return retval; | 2187 | return retval; |
| 2200 | } | 2188 | } |
| 2201 | 2189 | ||
| @@ -2217,25 +2205,8 @@ static int pxa25x_udc_remove(struct platform_device *pdev) · 15 unmodified lines | |||
| 2217 | 2205 | ||
| 2218 | remove_debug_files(dev); | 2206 | remove_debug_files(dev); |
| 2219 | 2207 | ||
| 2220 | if (dev->got_irq) { | 2208 | if (!IS_ERR_OR_NULL(dev->transceiver)) |
| 2221 | free_irq(platform_get_irq(pdev, 0), dev); | ||
| 2222 | dev->got_irq = 0; | ||
| 2223 | } | ||
| 2224 | #ifdef CONFIG_ARCH_LUBBOCK | ||
| 2225 | if (machine_is_lubbock()) { | ||
| 2226 | free_irq(LUBBOCK_USB_DISC_IRQ, dev); | ||
| 2227 | free_irq(LUBBOCK_USB_IRQ, dev); | ||
| 2228 | } | ||
| 2229 | #endif | ||
| 2230 | if (gpio_is_valid(dev->mach->gpio_pullup)) | ||
| 2231 | gpio_free(dev->mach->gpio_pullup); | ||
| 2232 | |||
| 2233 | clk_put(dev->clk); | ||
| 2234 | |||
| 2235 | if (!IS_ERR_OR_NULL(dev->transceiver)) { | ||
| 2236 | usb_put_phy(dev->transceiver); | ||
| 2237 | dev->transceiver = NULL; | 2209 | dev->transceiver = NULL; |
| 2238 | } | ||
| 2239 | 2210 | ||
| 2240 | the_controller = NULL; | 2211 | the_controller = NULL; |
| 2241 | return 0; | 2212 | return 0; |
File renamed without changes.
| @@ -2446,6 +2446,9 @@ static int pxa_udc_probe(struct platform_device *pdev) · 2445 unmodified lines | |||
| 2446 | retval = PTR_ERR(udc->clk); | 2446 | retval = PTR_ERR(udc->clk); |
| 2447 | goto err_clk; | 2447 | goto err_clk; |
| 2448 | } | 2448 | } |
| 2449 | retval = clk_prepare(udc->clk); | ||
| 2450 | if (retval) | ||
| 2451 | goto err_clk_prepare; | ||
| 2449 | 2452 | ||
| 2450 | retval = -ENOMEM; | 2453 | retval = -ENOMEM; |
| 2451 | udc->regs = ioremap(regs->start, resource_size(regs)); | 2454 | udc->regs = ioremap(regs->start, resource_size(regs)); |
| @@ -2483,6 +2486,8 @@ err_add_udc: · 31 unmodified lines | |||
| 2483 | err_irq: | 2486 | err_irq: |
| 2484 | iounmap(udc->regs); | 2487 | iounmap(udc->regs); |
| 2485 | err_map: | 2488 | err_map: |
| 2489 | clk_unprepare(udc->clk); | ||
| 2490 | err_clk_prepare: | ||
| 2486 | clk_put(udc->clk); | 2491 | clk_put(udc->clk); |
| 2487 | udc->clk = NULL; | 2492 | udc->clk = NULL; |
| 2488 | err_clk: | 2493 | err_clk: |
| @@ -2509,6 +2514,7 @@ static int pxa_udc_remove(struct platform_device *_dev) · 20 unmodified lines | |||
| 2509 | 2514 | ||
| 2510 | udc->transceiver = NULL; | 2515 | udc->transceiver = NULL; |
| 2511 | the_controller = NULL; | 2516 | the_controller = NULL; |
| 2517 | clk_unprepare(udc->clk); | ||
| 2512 | clk_put(udc->clk); | 2518 | clk_put(udc->clk); |
| 2513 | iounmap(udc->regs); | 2519 | iounmap(udc->regs); |
| 2514 | 2520 | ||
File renamed without changes.
| @@ -1826,18 +1826,12 @@ static int __exit r8a66597_remove(struct platform_device *pdev) · 1825 unmodified lines | |||
| 1826 | 1826 | ||
| 1827 | usb_del_gadget_udc(&r8a66597->gadget); | 1827 | usb_del_gadget_udc(&r8a66597->gadget); |
| 1828 | del_timer_sync(&r8a66597->timer); | 1828 | del_timer_sync(&r8a66597->timer); |
| 1829 | iounmap(r8a66597->reg); | ||
| 1830 | if (r8a66597->pdata->sudmac) | ||
| 1831 | iounmap(r8a66597->sudmac_reg); | ||
| 1832 | free_irq(platform_get_irq(pdev, 0), r8a66597); | ||
| 1833 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | 1829 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); |
| 1834 | 1830 | ||
| 1835 | if (r8a66597->pdata->on_chip) { | 1831 | if (r8a66597->pdata->on_chip) { |
| 1836 | clk_disable_unprepare(r8a66597->clk); | 1832 | clk_disable_unprepare(r8a66597->clk); |
| 1837 | clk_put(r8a66597->clk); | ||
| 1838 | } | 1833 | } |
| 1839 | 1834 | ||
| 1840 | kfree(r8a66597); | ||
| 1841 | return 0; | 1835 | return 0; |
| 1842 | } | 1836 | } |
| 1843 | 1837 | ||
| @@ -1845,28 +1839,24 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) · 1 unmodified line | |||
| 1845 | { | 1839 | { |
| 1846 | } | 1840 | } |
| 1847 | 1841 | ||
| 1848 | static int __init r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597, | 1842 | static int r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597, |
| 1849 | struct platform_device *pdev) | 1843 | struct platform_device *pdev) |
| 1850 | { | 1844 | { |
| 1851 | struct resource *res; | 1845 | struct resource *res; |
| 1852 | 1846 | ||
| 1853 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); | 1847 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); |
| 1854 | if (!res) { | 1848 | r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res); |
| 1855 | dev_err(&pdev->dev, "platform_get_resource error(sudmac).\n"); | 1849 | if (IS_ERR(r8a66597->sudmac_reg)) { |
| 1856 | return -ENODEV; | ||
| 1857 | } | ||
| 1858 | |||
| 1859 | r8a66597->sudmac_reg = ioremap(res->start, resource_size(res)); | ||
| 1860 | if (r8a66597->sudmac_reg == NULL) { | ||
| 1861 | dev_err(&pdev->dev, "ioremap error(sudmac).\n"); | 1850 | dev_err(&pdev->dev, "ioremap error(sudmac).\n"); |
| 1862 | return -ENOMEM; | 1851 | return PTR_ERR(r8a66597->sudmac_reg); |
| 1863 | } | 1852 | } |
| 1864 | 1853 | ||
| 1865 | return 0; | 1854 | return 0; |
| 1866 | } | 1855 | } |
| 1867 | 1856 | ||
| 1868 | static int __init r8a66597_probe(struct platform_device *pdev) | 1857 | static int r8a66597_probe(struct platform_device *pdev) |
| 1869 | { | 1858 | { |
| 1859 | struct device *dev = &pdev->dev; | ||
| 1870 | char clk_name[8]; | 1860 | char clk_name[8]; |
| 1871 | struct resource *res, *ires; | 1861 | struct resource *res, *ires; |
| 1872 | int irq; | 1862 | int irq; |
| @@ -1877,39 +1867,27 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 4 unmodified lines | |||
| 1877 | unsigned long irq_trigger; | 1867 | unsigned long irq_trigger; |
| 1878 | 1868 | ||
| 1879 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1869 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1880 | if (!res) { | 1870 | reg = devm_ioremap_resource(&pdev->dev, res); |
| 1881 | ret = -ENODEV; | 1871 | if (!reg) |
| 1882 | dev_err(&pdev->dev, "platform_get_resource error.\n"); | 1872 | return -ENODEV; |
| 1883 | goto clean_up; | ||
| 1884 | } | ||
| 1885 | 1873 | ||
| 1886 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 1874 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1887 | irq = ires->start; | 1875 | irq = ires->start; |
| 1888 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; | 1876 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; |
| 1889 | 1877 | ||
| 1890 | if (irq < 0) { | 1878 | if (irq < 0) { |
| 1891 | ret = -ENODEV; | 1879 | dev_err(dev, "platform_get_irq error.\n"); |
| 1892 | dev_err(&pdev->dev, "platform_get_irq error.\n"); | 1880 | return -ENODEV; |
| 1893 | goto clean_up; | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | reg = ioremap(res->start, resource_size(res)); | ||
| 1897 | if (reg == NULL) { | ||
| 1898 | ret = -ENOMEM; | ||
| 1899 | dev_err(&pdev->dev, "ioremap error.\n"); | ||
| 1900 | goto clean_up; | ||
| 1901 | } | 1881 | } |
| 1902 | 1882 | ||
| 1903 | /* initialize ucd */ | 1883 | /* initialize ucd */ |
| 1904 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); | 1884 | r8a66597 = devm_kzalloc(dev, sizeof(struct r8a66597), GFP_KERNEL); |
| 1905 | if (r8a66597 == NULL) { | 1885 | if (r8a66597 == NULL) |
| 1906 | ret = -ENOMEM; | 1886 | return -ENOMEM; |
| 1907 | goto clean_up; | ||
| 1908 | } | ||
| 1909 | 1887 | ||
| 1910 | spin_lock_init(&r8a66597->lock); | 1888 | spin_lock_init(&r8a66597->lock); |
| 1911 | platform_set_drvdata(pdev, r8a66597); | 1889 | platform_set_drvdata(pdev, r8a66597); |
| 1912 | r8a66597->pdata = dev_get_platdata(&pdev->dev); | 1890 | r8a66597->pdata = dev_get_platdata(dev); |
| 1913 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; | 1891 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; |
| 1914 | 1892 | ||
| 1915 | r8a66597->gadget.ops = &r8a66597_gadget_ops; | 1893 | r8a66597->gadget.ops = &r8a66597_gadget_ops; |
| @@ -1923,12 +1901,10 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 7 unmodified lines | |||
| 1923 | 1901 | ||
| 1924 | if (r8a66597->pdata->on_chip) { | 1902 | if (r8a66597->pdata->on_chip) { |
| 1925 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); | 1903 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); |
| 1926 | r8a66597->clk = clk_get(&pdev->dev, clk_name); | 1904 | r8a66597->clk = devm_clk_get(dev, clk_name); |
| 1927 | if (IS_ERR(r8a66597->clk)) { | 1905 | if (IS_ERR(r8a66597->clk)) { |
| 1928 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", | 1906 | dev_err(dev, "cannot get clock \"%s\"\n", clk_name); |
| 1929 | clk_name); | 1907 | return PTR_ERR(r8a66597->clk); |
| 1930 | ret = PTR_ERR(r8a66597->clk); | ||
| 1931 | goto clean_up; | ||
| 1932 | } | 1908 | } |
| 1933 | clk_prepare_enable(r8a66597->clk); | 1909 | clk_prepare_enable(r8a66597->clk); |
| 1934 | } | 1910 | } |
| @@ -1941,10 +1917,10 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 6 unmodified lines | |||
| 1941 | 1917 | ||
| 1942 | disable_controller(r8a66597); /* make sure controller is disabled */ | 1918 | disable_controller(r8a66597); /* make sure controller is disabled */ |
| 1943 | 1919 | ||
| 1944 | ret = request_irq(irq, r8a66597_irq, IRQF_SHARED, | 1920 | ret = devm_request_irq(dev, irq, r8a66597_irq, IRQF_SHARED, |
| 1945 | udc_name, r8a66597); | 1921 | udc_name, r8a66597); |
| 1946 | if (ret < 0) { | 1922 | if (ret < 0) { |
| 1947 | dev_err(&pdev->dev, "request_irq error (%d)\n", ret); | 1923 | dev_err(dev, "request_irq error (%d)\n", ret); |
| 1948 | goto clean_up2; | 1924 | goto clean_up2; |
| 1949 | } | 1925 | } |
| 1950 | 1926 | ||
| @@ -1978,37 +1954,25 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 27 unmodified lines | |||
| 1978 | GFP_KERNEL); | 1954 | GFP_KERNEL); |
| 1979 | if (r8a66597->ep0_req == NULL) { | 1955 | if (r8a66597->ep0_req == NULL) { |
| 1980 | ret = -ENOMEM; | 1956 | ret = -ENOMEM; |
| 1981 | goto clean_up3; | 1957 | goto clean_up2; |
| 1982 | } | 1958 | } |
| 1983 | r8a66597->ep0_req->complete = nop_completion; | 1959 | r8a66597->ep0_req->complete = nop_completion; |
| 1984 | 1960 | ||
| 1985 | ret = usb_add_gadget_udc(&pdev->dev, &r8a66597->gadget); | 1961 | ret = usb_add_gadget_udc(dev, &r8a66597->gadget); |
| 1986 | if (ret) | 1962 | if (ret) |
| 1987 | goto err_add_udc; | 1963 | goto err_add_udc; |
| 1988 | 1964 | ||
| 1989 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | 1965 | dev_info(dev, "version %s\n", DRIVER_VERSION); |
| 1990 | return 0; | 1966 | return 0; |
| 1991 | 1967 | ||
| 1992 | err_add_udc: | 1968 | err_add_udc: |
| 1993 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | 1969 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); |
| 1994 | clean_up3: | ||
| 1995 | free_irq(irq, r8a66597); | ||
| 1996 | clean_up2: | 1970 | clean_up2: |
| 1997 | if (r8a66597->pdata->on_chip) { | 1971 | if (r8a66597->pdata->on_chip) |
| 1998 | clk_disable_unprepare(r8a66597->clk); | 1972 | clk_disable_unprepare(r8a66597->clk); |
| 1999 | clk_put(r8a66597->clk); | 1973 | |
| 2000 | } | 1974 | if (r8a66597->ep0_req) |
| 2001 | clean_up: | 1975 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); |
| 2002 | if (r8a66597) { | ||
| 2003 | if (r8a66597->sudmac_reg) | ||
| 2004 | iounmap(r8a66597->sudmac_reg); | ||
| 2005 | if (r8a66597->ep0_req) | ||
| 2006 | r8a66597_free_request(&r8a66597->ep[0].ep, | ||
| 2007 | r8a66597->ep0_req); | ||
| 2008 | kfree(r8a66597); | ||
| 2009 | } | ||
| 2010 | if (reg) | ||
| 2011 | iounmap(reg); | ||
| 2012 | 1976 | ||
| 2013 | return ret; | 1977 | return ret; |
| 2014 | } | 1978 | } |
File renamed without changes.
File renamed without changes.
| @@ -1788,7 +1788,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) · 1787 unmodified lines | |||
| 1788 | return PTR_ERR(usb_bus_clock); | 1788 | return PTR_ERR(usb_bus_clock); |
| 1789 | } | 1789 | } |
| 1790 | 1790 | ||
| 1791 | clk_enable(usb_bus_clock); | 1791 | clk_prepare_enable(usb_bus_clock); |
| 1792 | 1792 | ||
| 1793 | udc_clock = clk_get(NULL, "usb-device"); | 1793 | udc_clock = clk_get(NULL, "usb-device"); |
| 1794 | if (IS_ERR(udc_clock)) { | 1794 | if (IS_ERR(udc_clock)) { |
| @@ -1796,7 +1796,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) · 1 unmodified line | |||
| 1796 | return PTR_ERR(udc_clock); | 1796 | return PTR_ERR(udc_clock); |
| 1797 | } | 1797 | } |
| 1798 | 1798 | ||
| 1799 | clk_enable(udc_clock); | 1799 | clk_prepare_enable(udc_clock); |
| 1800 | 1800 | ||
| 1801 | mdelay(10); | 1801 | mdelay(10); |
| 1802 | 1802 | ||
| @@ -1952,13 +1952,13 @@ static int s3c2410_udc_remove(struct platform_device *pdev) · 149 unmodified lines | |||
| 1952 | release_mem_region(rsrc_start, rsrc_len); | 1952 | release_mem_region(rsrc_start, rsrc_len); |
| 1953 | 1953 | ||
| 1954 | if (!IS_ERR(udc_clock) && udc_clock != NULL) { | 1954 | if (!IS_ERR(udc_clock) && udc_clock != NULL) { |
| 1955 | clk_disable(udc_clock); | 1955 | clk_disable_unprepare(udc_clock); |
| 1956 | clk_put(udc_clock); | 1956 | clk_put(udc_clock); |
| 1957 | udc_clock = NULL; | 1957 | udc_clock = NULL; |
| 1958 | } | 1958 | } |
| 1959 | 1959 | ||
| 1960 | if (!IS_ERR(usb_bus_clock) && usb_bus_clock != NULL) { | 1960 | if (!IS_ERR(usb_bus_clock) && usb_bus_clock != NULL) { |
| 1961 | clk_disable(usb_bus_clock); | 1961 | clk_disable_unprepare(usb_bus_clock); |
| 1962 | clk_put(usb_bus_clock); | 1962 | clk_put(usb_bus_clock); |
| 1963 | usb_bus_clock = NULL; | 1963 | usb_bus_clock = NULL; |
| 1964 | } | 1964 | } |
File renamed without changes.
File renamed without changes.
| @@ -37,6 +37,14 @@ config USB_XHCI_MVEBU · 36 unmodified lines | |||
| 37 | Say 'Y' to enable the support for the xHCI host controller | 37 | Say 'Y' to enable the support for the xHCI host controller |
| 38 | found in Marvell Armada 375/38x ARM SOCs. | 38 | found in Marvell Armada 375/38x ARM SOCs. |
| 39 | 39 | ||
| 40 | config USB_XHCI_RCAR | ||
| 41 | tristate "xHCI support for Renesas R-Car SoCs" | ||
| 42 | select USB_XHCI_PLATFORM | ||
| 43 | depends on ARCH_SHMOBILE || COMPILE_TEST | ||
| 44 | ---help--- | ||
| 45 | Say 'Y' to enable the support for the xHCI host controller | ||
| 46 | found in Renesas R-Car ARM SoCs. | ||
| 47 | |||
| 40 | endif # USB_XHCI_HCD | 48 | endif # USB_XHCI_HCD |
| 41 | 49 | ||
| 42 | config USB_EHCI_HCD | 50 | config USB_EHCI_HCD |
| @@ -22,6 +22,9 @@ ifneq ($(CONFIG_USB_XHCI_PLATFORM), ) · 21 unmodified lines | |||
| 22 | ifneq ($(CONFIG_USB_XHCI_MVEBU), ) | 22 | ifneq ($(CONFIG_USB_XHCI_MVEBU), ) |
| 23 | xhci-hcd-y += xhci-mvebu.o | 23 | xhci-hcd-y += xhci-mvebu.o |
| 24 | endif | 24 | endif |
| 25 | ifneq ($(CONFIG_USB_XHCI_RCAR), ) | ||
| 26 | xhci-hcd-y += xhci-rcar.o | ||
| 27 | endif | ||
| 25 | endif | 28 | endif |
| 26 | 29 | ||
| 27 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ | 30 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ |
| @@ -88,7 +88,7 @@ static int exynos_ehci_get_phy(struct device *dev, · 87 unmodified lines | |||
| 88 | return -EINVAL; | 88 | return -EINVAL; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | phy = devm_of_phy_get(dev, child, 0); | 91 | phy = devm_of_phy_get(dev, child, NULL); |
| 92 | of_node_put(child); | 92 | of_node_put(child); |
| 93 | if (IS_ERR(phy)) { | 93 | if (IS_ERR(phy)) { |
| 94 | ret = PTR_ERR(phy); | 94 | ret = PTR_ERR(phy); |
| @@ -209,7 +209,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags) · 208 unmodified lines | |||
| 209 | ehci->periodic = (__le32 *) | 209 | ehci->periodic = (__le32 *) |
| 210 | dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller, | 210 | dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller, |
| 211 | ehci->periodic_size * sizeof(__le32), | 211 | ehci->periodic_size * sizeof(__le32), |
| 212 | &ehci->periodic_dma, 0); | 212 | &ehci->periodic_dma, flags); |
| 213 | if (ehci->periodic == NULL) { | 213 | if (ehci->periodic == NULL) { |
| 214 | goto fail; | 214 | goto fail; |
| 215 | } | 215 | } |
| @@ -190,7 +190,7 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = { · 189 unmodified lines | |||
| 190 | .resume = ehci_msm_pm_resume, | 190 | .resume = ehci_msm_pm_resume, |
| 191 | }; | 191 | }; |
| 192 | 192 | ||
| 193 | static struct of_device_id msm_ehci_dt_match[] = { | 193 | static const struct of_device_id msm_ehci_dt_match[] = { |
| 194 | { .compatible = "qcom,ehci-host", }, | 194 | { .compatible = "qcom,ehci-host", }, |
| 195 | {} | 195 | {} |
| 196 | }; | 196 | }; |
| @@ -35,6 +35,21 @@ static const char hcd_name[] = "ehci-pci"; · 34 unmodified lines | |||
| 35 | #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70 | 35 | #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70 |
| 36 | 36 | ||
| 37 | /*-------------------------------------------------------------------------*/ | 37 | /*-------------------------------------------------------------------------*/ |
| 38 | #define PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC 0x0939 | ||
| 39 | static inline bool is_intel_quark_x1000(struct pci_dev *pdev) | ||
| 40 | { | ||
| 41 | return pdev->vendor == PCI_VENDOR_ID_INTEL && | ||
| 42 | pdev->device == PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC; | ||
| 43 | } | ||
| 44 | |||
| 45 | /* | ||
| 46 | * 0x84 is the offset of in/out threshold register, | ||
| 47 | * and it is the same offset as the register of 'hostpc'. | ||
| 48 | */ | ||
| 49 | #define intel_quark_x1000_insnreg01 hostpc | ||
| 50 | |||
| 51 | /* Maximum usable threshold value is 0x7f dwords for both IN and OUT */ | ||
| 52 | #define INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD 0x007f007f | ||
| 38 | 53 | ||
| 39 | /* called after powerup, by probe or system-pm "wakeup" */ | 54 | /* called after powerup, by probe or system-pm "wakeup" */ |
| 40 | static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) | 55 | static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) |
| @@ -50,6 +65,16 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) · 9 unmodified lines | |||
| 50 | if (!retval) | 65 | if (!retval) |
| 51 | ehci_dbg(ehci, "MWI active\n"); | 66 | ehci_dbg(ehci, "MWI active\n"); |
| 52 | 67 | ||
| 68 | /* Reset the threshold limit */ | ||
| 69 | if (is_intel_quark_x1000(pdev)) { | ||
| 70 | /* | ||
| 71 | * For the Intel QUARK X1000, raise the I/O threshold to the | ||
| 72 | * maximum usable value in order to improve performance. | ||
| 73 | */ | ||
| 74 | ehci_writel(ehci, INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD, | ||
| 75 | ehci->regs->intel_quark_x1000_insnreg01); | ||
| 76 | } | ||
| 77 | |||
| 53 | return 0; | 78 | return 0; |
| 54 | } | 79 | } |
| 55 | 80 | ||
| @@ -150,7 +150,7 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev) · 149 unmodified lines | |||
| 150 | return 0; | 150 | return 0; |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | static struct of_device_id spear_ehci_id_table[] = { | 153 | static const struct of_device_id spear_ehci_id_table[] = { |
| 154 | { .compatible = "st,spear600-ehci", }, | 154 | { .compatible = "st,spear600-ehci", }, |
| 155 | { }, | 155 | { }, |
| 156 | }; | 156 | }; |
| @@ -46,6 +46,7 @@ · 45 unmodified lines | |||
| 46 | #define DRV_NAME "tegra-ehci" | 46 | #define DRV_NAME "tegra-ehci" |
| 47 | 47 | ||
| 48 | static struct hc_driver __read_mostly tegra_ehci_hc_driver; | 48 | static struct hc_driver __read_mostly tegra_ehci_hc_driver; |
| 49 | static bool usb1_reset_attempted; | ||
| 49 | 50 | ||
| 50 | struct tegra_ehci_soc_config { | 51 | struct tegra_ehci_soc_config { |
| 51 | bool has_hostpc; | 52 | bool has_hostpc; |
| @@ -60,6 +61,61 @@ struct tegra_ehci_hcd { · 8 unmodified lines | |||
| 60 | enum tegra_usb_phy_port_speed port_speed; | 61 | enum tegra_usb_phy_port_speed port_speed; |
| 61 | }; | 62 | }; |
| 62 | 63 | ||
| 64 | /* | ||
| 65 | * The 1st USB controller contains some UTMI pad registers that are global for | ||
| 66 | * all the controllers on the chip. Those registers are also cleared when | ||
| 67 | * reset is asserted to the 1st controller. This means that the 1st controller | ||
| 68 | * can only be reset when no other controlled has finished probing. So we'll | ||
| 69 | * reset the 1st controller before doing any other setup on any of the | ||
| 70 | * controllers, and then never again. | ||
| 71 | * | ||
| 72 | * Since this is a PHY issue, the Tegra PHY driver should probably be doing | ||
| 73 | * the resetting of the USB controllers. But to keep compatibility with old | ||
| 74 | * device trees that don't have reset phandles in the PHYs, do it here. | ||
| 75 | * Those old DTs will be vulnerable to total USB breakage if the 1st EHCI | ||
| 76 | * device isn't the first one to finish probing, so warn them. | ||
| 77 | */ | ||
| 78 | static int tegra_reset_usb_controller(struct platform_device *pdev) | ||
| 79 | { | ||
| 80 | struct device_node *phy_np; | ||
| 81 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
| 82 | struct tegra_ehci_hcd *tegra = | ||
| 83 | (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; | ||
| 84 | |||
| 85 | phy_np = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0); | ||
| 86 | if (!phy_np) | ||
| 87 | return -ENOENT; | ||
| 88 | |||
| 89 | if (!usb1_reset_attempted) { | ||
| 90 | struct reset_control *usb1_reset; | ||
| 91 | |||
| 92 | usb1_reset = of_reset_control_get(phy_np, "usb"); | ||
| 93 | if (IS_ERR(usb1_reset)) { | ||
| 94 | dev_warn(&pdev->dev, | ||
| 95 | "can't get utmi-pads reset from the PHY\n"); | ||
| 96 | dev_warn(&pdev->dev, | ||
| 97 | "continuing, but please update your DT\n"); | ||
| 98 | } else { | ||
| 99 | reset_control_assert(usb1_reset); | ||
| 100 | udelay(1); | ||
| 101 | reset_control_deassert(usb1_reset); | ||
| 102 | } | ||
| 103 | |||
| 104 | reset_control_put(usb1_reset); | ||
| 105 | usb1_reset_attempted = true; | ||
| 106 | } | ||
| 107 | |||
| 108 | if (!of_property_read_bool(phy_np, "nvidia,has-utmi-pad-registers")) { | ||
| 109 | reset_control_assert(tegra->rst); | ||
| 110 | udelay(1); | ||
| 111 | reset_control_deassert(tegra->rst); | ||
| 112 | } | ||
| 113 | |||
| 114 | of_node_put(phy_np); | ||
| 115 | |||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 63 | static int tegra_ehci_internal_port_reset( | 119 | static int tegra_ehci_internal_port_reset( |
| 64 | struct ehci_hcd *ehci, | 120 | struct ehci_hcd *ehci, |
| 65 | u32 __iomem *portsc_reg | 121 | u32 __iomem *portsc_reg |
| @@ -326,7 +382,7 @@ static const struct tegra_ehci_soc_config tegra20_soc_config = { · 260 unmodified lines | |||
| 326 | .has_hostpc = false, | 382 | .has_hostpc = false, |
| 327 | }; | 383 | }; |
| 328 | 384 | ||
| 329 | static struct of_device_id tegra_ehci_of_match[] = { | 385 | static const struct of_device_id tegra_ehci_of_match[] = { |
| 330 | { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config }, | 386 | { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config }, |
| 331 | { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config }, | 387 | { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config }, |
| 332 | { }, | 388 | { }, |
| @@ -389,9 +445,9 @@ static int tegra_ehci_probe(struct platform_device *pdev) · 56 unmodified lines | |||
| 389 | if (err) | 445 | if (err) |
| 390 | goto cleanup_hcd_create; | 446 | goto cleanup_hcd_create; |
| 391 | 447 | ||
| 392 | reset_control_assert(tegra->rst); | 448 | err = tegra_reset_usb_controller(pdev); |
| 393 | udelay(1); | 449 | if (err) |
| 394 | reset_control_deassert(tegra->rst); | 450 | goto cleanup_clk_en; |
| 395 | 451 | ||
| 396 | u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); | 452 | u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); |
| 397 | if (IS_ERR(u_phy)) { | 453 | if (IS_ERR(u_phy)) { |
| @@ -479,10 +535,11 @@ static int tegra_ehci_remove(struct platform_device *pdev) · 81 unmodified lines | |||
| 479 | 535 | ||
| 480 | usb_phy_shutdown(hcd->phy); | 536 | usb_phy_shutdown(hcd->phy); |
| 481 | usb_remove_hcd(hcd); | 537 | usb_remove_hcd(hcd); |
| 482 | usb_put_hcd(hcd); | ||
| 483 | 538 | ||
| 484 | clk_disable_unprepare(tegra->clk); | 539 | clk_disable_unprepare(tegra->clk); |
| 485 | 540 | ||
| 541 | usb_put_hcd(hcd); | ||
| 542 | |||
| 486 | return 0; | 543 | return 0; |
| 487 | } | 544 | } |
| 488 | 545 | ||
| @@ -129,11 +129,7 @@ void fhci_dfs_destroy(struct fhci_hcd *fhci) · 128 unmodified lines | |||
| 129 | if (!fhci->dfs_root) | 129 | if (!fhci->dfs_root) |
| 130 | return; | 130 | return; |
| 131 | 131 | ||
| 132 | if (fhci->dfs_irq_stat) | 132 | debugfs_remove(fhci->dfs_irq_stat); |
| 133 | debugfs_remove(fhci->dfs_irq_stat); | 133 | debugfs_remove(fhci->dfs_regs); |
| 134 | |||
| 135 | if (fhci->dfs_regs) | ||
| 136 | debugfs_remove(fhci->dfs_regs); | ||
| 137 | |||
| 138 | debugfs_remove(fhci->dfs_root); | 134 | debugfs_remove(fhci->dfs_root); |
| 139 | } | 135 | } |
| @@ -5838,41 +5838,17 @@ static int fotg210_hcd_probe(struct platform_device *pdev) · 5837 unmodified lines | |||
| 5838 | goto fail_create_hcd; | 5838 | goto fail_create_hcd; |
| 5839 | } | 5839 | } |
| 5840 | 5840 | ||
| 5841 | hcd->has_tt = 1; | ||
| 5842 | |||
| 5841 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 5843 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 5842 | if (!res) { | 5844 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 5843 | dev_err(dev, | 5845 | if (IS_ERR(hcd->regs)) { |
| 5844 | "Found HC with no register addr. Check %s setup!\n", | 5846 | retval = PTR_ERR(hcd->regs); |
| 5845 | dev_name(dev)); | 5847 | goto failed; |
| 5846 | retval = -ENODEV; | ||
| 5847 | goto fail_request_resource; | ||
| 5848 | } | 5848 | } |
| 5849 | 5849 | ||
| 5850 | hcd->rsrc_start = res->start; | 5850 | hcd->rsrc_start = res->start; |
| 5851 | hcd->rsrc_len = resource_size(res); | 5851 | hcd->rsrc_len = resource_size(res); |
| 5852 | hcd->has_tt = 1; | ||
| 5853 | |||
| 5854 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | ||
| 5855 | fotg210_fotg210_hc_driver.description)) { | ||
| 5856 | dev_dbg(dev, "controller already in use\n"); | ||
| 5857 | retval = -EBUSY; | ||
| 5858 | goto fail_request_resource; | ||
| 5859 | } | ||
| 5860 | |||
| 5861 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
| 5862 | if (!res) { | ||
| 5863 | dev_err(dev, | ||
| 5864 | "Found HC with no register addr. Check %s setup!\n", | ||
| 5865 | dev_name(dev)); | ||
| 5866 | retval = -ENODEV; | ||
| 5867 | goto fail_request_resource; | ||
| 5868 | } | ||
| 5869 | |||
| 5870 | hcd->regs = ioremap_nocache(res->start, resource_size(res)); | ||
| 5871 | if (hcd->regs == NULL) { | ||
| 5872 | dev_dbg(dev, "error mapping memory\n"); | ||
| 5873 | retval = -EFAULT; | ||
| 5874 | goto fail_ioremap; | ||
| 5875 | } | ||
| 5876 | 5852 | ||
| 5877 | fotg210 = hcd_to_fotg210(hcd); | 5853 | fotg210 = hcd_to_fotg210(hcd); |
| 5878 | 5854 | ||
| @@ -5880,24 +5856,20 @@ static int fotg210_hcd_probe(struct platform_device *pdev) · 1 unmodified line | |||
| 5880 | 5856 | ||
| 5881 | retval = fotg210_setup(hcd); | 5857 | retval = fotg210_setup(hcd); |
| 5882 | if (retval) | 5858 | if (retval) |
| 5883 | goto fail_add_hcd; | 5859 | goto failed; |
| 5884 | 5860 | ||
| 5885 | fotg210_init(fotg210); | 5861 | fotg210_init(fotg210); |
| 5886 | 5862 | ||
| 5887 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 5863 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 5888 | if (retval) { | 5864 | if (retval) { |
| 5889 | dev_err(dev, "failed to add hcd with err %d\n", retval); | 5865 | dev_err(dev, "failed to add hcd with err %d\n", retval); |
| 5890 | goto fail_add_hcd; | 5866 | goto failed; |
| 5891 | } | 5867 | } |
| 5892 | device_wakeup_enable(hcd->self.controller); | 5868 | device_wakeup_enable(hcd->self.controller); |
| 5893 | 5869 | ||
| 5894 | return retval; | 5870 | return retval; |
| 5895 | 5871 | ||
| 5896 | fail_add_hcd: | 5872 | failed: |
| 5897 | iounmap(hcd->regs); | ||
| 5898 | fail_ioremap: | ||
| 5899 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 5900 | fail_request_resource: | ||
| 5901 | usb_put_hcd(hcd); | 5873 | usb_put_hcd(hcd); |
| 5902 | fail_create_hcd: | 5874 | fail_create_hcd: |
| 5903 | dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval); | 5875 | dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval); |
| @@ -5918,8 +5890,6 @@ static int fotg210_hcd_remove(struct platform_device *pdev) · 14 unmodified lines | |||
| 5918 | return 0; | 5890 | return 0; |
| 5919 | 5891 | ||
| 5920 | usb_remove_hcd(hcd); | 5892 | usb_remove_hcd(hcd); |
| 5921 | iounmap(hcd->regs); | ||
| 5922 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 5923 | usb_put_hcd(hcd); | 5893 | usb_put_hcd(hcd); |
| 5924 | 5894 | ||
| 5925 | return 0; | 5895 | return 0; |
| @@ -102,6 +102,15 @@ enum scheduling_pass { · 101 unmodified lines | |||
| 102 | SCHED_PASS_DONE | 102 | SCHED_PASS_DONE |
| 103 | }; | 103 | }; |
| 104 | 104 | ||
| 105 | /* Bit numbers for max3421_hcd->todo: */ | ||
| 106 | enum { | ||
| 107 | ENABLE_IRQ = 0, | ||
| 108 | RESET_HCD, | ||
| 109 | RESET_PORT, | ||
| 110 | CHECK_UNLINK, | ||
| 111 | IOPIN_UPDATE | ||
| 112 | }; | ||
| 113 | |||
| 105 | struct max3421_dma_buf { | 114 | struct max3421_dma_buf { |
| 106 | u8 data[2]; | 115 | u8 data[2]; |
| 107 | }; | 116 | }; |
| @@ -146,11 +155,7 @@ struct max3421_hcd { · 38 unmodified lines | |||
| 146 | u8 hien; | 155 | u8 hien; |
| 147 | u8 mode; | 156 | u8 mode; |
| 148 | u8 iopins[2]; | 157 | u8 iopins[2]; |
| 149 | unsigned int do_enable_irq:1; | 158 | unsigned long todo; |
| 150 | unsigned int do_reset_hcd:1; | ||
| 151 | unsigned int do_reset_port:1; | ||
| 152 | unsigned int do_check_unlink:1; | ||
| 153 | unsigned int do_iopin_update:1; | ||
| 154 | #ifdef DEBUG | 159 | #ifdef DEBUG |
| 155 | unsigned long err_stat[16]; | 160 | unsigned long err_stat[16]; |
| 156 | #endif | 161 | #endif |
| @@ -1165,10 +1170,8 @@ max3421_irq_handler(int irq, void *dev_id) · 1008 unmodified lines | |||
| 1165 | if (max3421_hcd->spi_thread && | 1170 | if (max3421_hcd->spi_thread && |
| 1166 | max3421_hcd->spi_thread->state != TASK_RUNNING) | 1171 | max3421_hcd->spi_thread->state != TASK_RUNNING) |
| 1167 | wake_up_process(max3421_hcd->spi_thread); | 1172 | wake_up_process(max3421_hcd->spi_thread); |
| 1168 | if (!max3421_hcd->do_enable_irq) { | 1173 | if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo)) |
| 1169 | max3421_hcd->do_enable_irq = 1; | ||
| 1170 | disable_irq_nosync(spi->irq); | 1174 | disable_irq_nosync(spi->irq); |
| 1171 | } | ||
| 1172 | return IRQ_HANDLED; | 1175 | return IRQ_HANDLED; |
| 1173 | } | 1176 | } |
| 1174 | 1177 | ||
| @@ -1423,10 +1426,8 @@ max3421_spi_thread(void *dev_id) · 248 unmodified lines | |||
| 1423 | spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); | 1426 | spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); |
| 1424 | 1427 | ||
| 1425 | set_current_state(TASK_INTERRUPTIBLE); | 1428 | set_current_state(TASK_INTERRUPTIBLE); |
| 1426 | if (max3421_hcd->do_enable_irq) { | 1429 | if (test_and_clear_bit(ENABLE_IRQ, &max3421_hcd->todo)) |
| 1427 | max3421_hcd->do_enable_irq = 0; | ||
| 1428 | enable_irq(spi->irq); | 1430 | enable_irq(spi->irq); |
| 1429 | } | ||
| 1430 | schedule(); | 1431 | schedule(); |
| 1431 | __set_current_state(TASK_RUNNING); | 1432 | __set_current_state(TASK_RUNNING); |
| 1432 | } | 1433 | } |
| @@ -1440,23 +1441,18 @@ max3421_spi_thread(void *dev_id) · 7 unmodified lines | |||
| 1440 | else if (!max3421_hcd->curr_urb) | 1441 | else if (!max3421_hcd->curr_urb) |
| 1441 | i_worked |= max3421_select_and_start_urb(hcd); | 1442 | i_worked |= max3421_select_and_start_urb(hcd); |
| 1442 | 1443 | ||
| 1443 | if (max3421_hcd->do_reset_hcd) { | 1444 | if (test_and_clear_bit(RESET_HCD, &max3421_hcd->todo)) |
| 1444 | /* reset the HCD: */ | 1445 | /* reset the HCD: */ |
| 1445 | max3421_hcd->do_reset_hcd = 0; | ||
| 1446 | i_worked |= max3421_reset_hcd(hcd); | 1446 | i_worked |= max3421_reset_hcd(hcd); |
| 1447 | } | 1447 | if (test_and_clear_bit(RESET_PORT, &max3421_hcd->todo)) { |
| 1448 | if (max3421_hcd->do_reset_port) { | ||
| 1449 | /* perform a USB bus reset: */ | 1448 | /* perform a USB bus reset: */ |
| 1450 | max3421_hcd->do_reset_port = 0; | ||
| 1451 | spi_wr8(hcd, MAX3421_REG_HCTL, | 1449 | spi_wr8(hcd, MAX3421_REG_HCTL, |
| 1452 | BIT(MAX3421_HCTL_BUSRST_BIT)); | 1450 | BIT(MAX3421_HCTL_BUSRST_BIT)); |
| 1453 | i_worked = 1; | 1451 | i_worked = 1; |
| 1454 | } | 1452 | } |
| 1455 | if (max3421_hcd->do_check_unlink) { | 1453 | if (test_and_clear_bit(CHECK_UNLINK, &max3421_hcd->todo)) |
| 1456 | max3421_hcd->do_check_unlink = 0; | ||
| 1457 | i_worked |= max3421_check_unlink(hcd); | 1454 | i_worked |= max3421_check_unlink(hcd); |
| 1458 | } | 1455 | if (test_and_clear_bit(IOPIN_UPDATE, &max3421_hcd->todo)) { |
| 1459 | if (max3421_hcd->do_iopin_update) { | ||
| 1460 | /* | 1456 | /* |
| 1461 | * IOPINS1/IOPINS2 do not auto-increment, so we can't | 1457 | * IOPINS1/IOPINS2 do not auto-increment, so we can't |
| 1462 | * use spi_wr_buf(). | 1458 | * use spi_wr_buf(). |
| @@ -1469,7 +1465,6 @@ max3421_spi_thread(void *dev_id) · 6 unmodified lines | |||
| 1469 | spi_wr8(hcd, MAX3421_REG_IOPINS1 + i, val); | 1465 | spi_wr8(hcd, MAX3421_REG_IOPINS1 + i, val); |
| 1470 | max3421_hcd->iopins[i] = val; | 1466 | max3421_hcd->iopins[i] = val; |
| 1471 | } | 1467 | } |
| 1472 | max3421_hcd->do_iopin_update = 0; | ||
| 1473 | i_worked = 1; | 1468 | i_worked = 1; |
| 1474 | } | 1469 | } |
| 1475 | } | 1470 | } |
| @@ -1485,7 +1480,8 @@ max3421_reset_port(struct usb_hcd *hcd) · 9 unmodified lines | |||
| 1485 | 1480 | ||
| 1486 | max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | | 1481 | max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | |
| 1487 | USB_PORT_STAT_LOW_SPEED); | 1482 | USB_PORT_STAT_LOW_SPEED); |
| 1488 | max3421_hcd->do_reset_port = 1; | 1483 | max3421_hcd->port_status |= USB_PORT_STAT_RESET; |
| 1484 | set_bit(RESET_PORT, &max3421_hcd->todo); | ||
| 1489 | wake_up_process(max3421_hcd->spi_thread); | 1485 | wake_up_process(max3421_hcd->spi_thread); |
| 1490 | return 0; | 1486 | return 0; |
| 1491 | } | 1487 | } |
| @@ -1498,7 +1494,7 @@ max3421_reset(struct usb_hcd *hcd) · 6 unmodified lines | |||
| 1498 | hcd->self.sg_tablesize = 0; | 1494 | hcd->self.sg_tablesize = 0; |
| 1499 | hcd->speed = HCD_USB2; | 1495 | hcd->speed = HCD_USB2; |
| 1500 | hcd->self.root_hub->speed = USB_SPEED_FULL; | 1496 | hcd->self.root_hub->speed = USB_SPEED_FULL; |
| 1501 | max3421_hcd->do_reset_hcd = 1; | 1497 | set_bit(RESET_HCD, &max3421_hcd->todo); |
| 1502 | wake_up_process(max3421_hcd->spi_thread); | 1498 | wake_up_process(max3421_hcd->spi_thread); |
| 1503 | return 0; | 1499 | return 0; |
| 1504 | } | 1500 | } |
| @@ -1551,7 +1547,7 @@ max3421_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) · 46 unmodified lines | |||
| 1551 | max3421_ep = urb->ep->hcpriv; | 1547 | max3421_ep = urb->ep->hcpriv; |
| 1552 | if (!max3421_ep) { | 1548 | if (!max3421_ep) { |
| 1553 | /* gets freed in max3421_endpoint_disable: */ | 1549 | /* gets freed in max3421_endpoint_disable: */ |
| 1554 | max3421_ep = kzalloc(sizeof(struct max3421_ep), mem_flags); | 1550 | max3421_ep = kzalloc(sizeof(struct max3421_ep), GFP_ATOMIC); |
| 1555 | if (!max3421_ep) { | 1551 | if (!max3421_ep) { |
| 1556 | retval = -ENOMEM; | 1552 | retval = -ENOMEM; |
| 1557 | goto out; | 1553 | goto out; |
| @@ -1590,7 +1586,7 @@ max3421_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) · 32 unmodified lines | |||
| 1590 | */ | 1586 | */ |
| 1591 | retval = usb_hcd_check_unlink_urb(hcd, urb, status); | 1587 | retval = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 1592 | if (retval == 0) { | 1588 | if (retval == 0) { |
| 1593 | max3421_hcd->do_check_unlink = 1; | 1589 | set_bit(CHECK_UNLINK, &max3421_hcd->todo); |
| 1594 | wake_up_process(max3421_hcd->spi_thread); | 1590 | wake_up_process(max3421_hcd->spi_thread); |
| 1595 | } | 1591 | } |
| 1596 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | 1592 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); |
| @@ -1690,7 +1686,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value) · 93 unmodified lines | |||
| 1690 | max3421_hcd->iopins[idx] |= mask; | 1686 | max3421_hcd->iopins[idx] |= mask; |
| 1691 | else | 1687 | else |
| 1692 | max3421_hcd->iopins[idx] &= ~mask; | 1688 | max3421_hcd->iopins[idx] &= ~mask; |
| 1693 | max3421_hcd->do_iopin_update = 1; | 1689 | set_bit(IOPIN_UPDATE, &max3421_hcd->todo); |
| 1694 | wake_up_process(max3421_hcd->spi_thread); | 1690 | wake_up_process(max3421_hcd->spi_thread); |
| 1695 | } | 1691 | } |
| 1696 | 1692 | ||
| @@ -236,7 +236,7 @@ ohci_dump_roothub ( · 235 unmodified lines | |||
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | static void ohci_dump (struct ohci_hcd *controller, int verbose) | 239 | static void ohci_dump(struct ohci_hcd *controller) |
| 240 | { | 240 | { |
| 241 | ohci_dbg (controller, "OHCI controller state\n"); | 241 | ohci_dbg (controller, "OHCI controller state\n"); |
| 242 | 242 | ||
| @@ -464,15 +464,16 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) · 221 unmodified lines | |||
| 464 | static ssize_t fill_async_buffer(struct debug_buffer *buf) | 464 | static ssize_t fill_async_buffer(struct debug_buffer *buf) |
| 465 | { | 465 | { |
| 466 | struct ohci_hcd *ohci; | 466 | struct ohci_hcd *ohci; |
| 467 | size_t temp; | 467 | size_t temp, size; |
| 468 | unsigned long flags; | 468 | unsigned long flags; |
| 469 | 469 | ||
| 470 | ohci = buf->ohci; | 470 | ohci = buf->ohci; |
| 471 | size = PAGE_SIZE; | ||
| 471 | 472 | ||
| 472 | /* display control and bulk lists together, for simplicity */ | 473 | /* display control and bulk lists together, for simplicity */ |
| 473 | spin_lock_irqsave (&ohci->lock, flags); | 474 | spin_lock_irqsave (&ohci->lock, flags); |
| 474 | temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail); | 475 | temp = show_list(ohci, buf->page, size, ohci->ed_controltail); |
| 475 | temp += show_list(ohci, buf->page + temp, buf->count - temp, | 476 | temp += show_list(ohci, buf->page + temp, size - temp, |
| 476 | ohci->ed_bulktail); | 477 | ohci->ed_bulktail); |
| 477 | spin_unlock_irqrestore (&ohci->lock, flags); | 478 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 478 | 479 | ||
| @@ -87,7 +87,7 @@ static int exynos_ohci_get_phy(struct device *dev, · 86 unmodified lines | |||
| 87 | return -EINVAL; | 87 | return -EINVAL; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | phy = devm_of_phy_get(dev, child, 0); | 90 | phy = devm_of_phy_get(dev, child, NULL); |
| 91 | of_node_put(child); | 91 | of_node_put(child); |
| 92 | if (IS_ERR(phy)) { | 92 | if (IS_ERR(phy)) { |
| 93 | ret = PTR_ERR(phy); | 93 | ret = PTR_ERR(phy); |
| @@ -72,12 +72,14 @@ · 71 unmodified lines | |||
| 72 | static const char hcd_name [] = "ohci_hcd"; | 72 | static const char hcd_name [] = "ohci_hcd"; |
| 73 | 73 | ||
| 74 | #define STATECHANGE_DELAY msecs_to_jiffies(300) | 74 | #define STATECHANGE_DELAY msecs_to_jiffies(300) |
| 75 | #define IO_WATCHDOG_DELAY msecs_to_jiffies(250) | ||
| 75 | 76 | ||
| 76 | #include "ohci.h" | 77 | #include "ohci.h" |
| 77 | #include "pci-quirks.h" | 78 | #include "pci-quirks.h" |
| 78 | 79 | ||
| 79 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); | 80 | static void ohci_dump(struct ohci_hcd *ohci); |
| 80 | static void ohci_stop (struct usb_hcd *hcd); | 81 | static void ohci_stop(struct usb_hcd *hcd); |
| 82 | static void io_watchdog_func(unsigned long _ohci); | ||
| 81 | 83 | ||
| 82 | #include "ohci-hub.c" | 84 | #include "ohci-hub.c" |
| 83 | #include "ohci-dbg.c" | 85 | #include "ohci-dbg.c" |
| @@ -109,6 +111,33 @@ MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake"); · 25 unmodified lines | |||
| 109 | 111 | ||
| 110 | /*-------------------------------------------------------------------------*/ | 112 | /*-------------------------------------------------------------------------*/ |
| 111 | 113 | ||
| 114 | static int number_of_tds(struct urb *urb) | ||
| 115 | { | ||
| 116 | int len, i, num, this_sg_len; | ||
| 117 | struct scatterlist *sg; | ||
| 118 | |||
| 119 | len = urb->transfer_buffer_length; | ||
| 120 | i = urb->num_mapped_sgs; | ||
| 121 | |||
| 122 | if (len > 0 && i > 0) { /* Scatter-gather transfer */ | ||
| 123 | num = 0; | ||
| 124 | sg = urb->sg; | ||
| 125 | for (;;) { | ||
| 126 | this_sg_len = min_t(int, sg_dma_len(sg), len); | ||
| 127 | num += DIV_ROUND_UP(this_sg_len, 4096); | ||
| 128 | len -= this_sg_len; | ||
| 129 | if (--i <= 0 || len <= 0) | ||
| 130 | break; | ||
| 131 | sg = sg_next(sg); | ||
| 132 | } | ||
| 133 | |||
| 134 | } else { /* Non-SG transfer */ | ||
| 135 | /* one TD for every 4096 Bytes (could be up to 8K) */ | ||
| 136 | num = DIV_ROUND_UP(len, 4096); | ||
| 137 | } | ||
| 138 | return num; | ||
| 139 | } | ||
| 140 | |||
| 112 | /* | 141 | /* |
| 113 | * queue up an urb for anything except the root hub | 142 | * queue up an urb for anything except the root hub |
| 114 | */ | 143 | */ |
| @@ -142,12 +171,8 @@ static int ohci_urb_enqueue ( · 27 unmodified lines | |||
| 142 | // case PIPE_INTERRUPT: | 171 | // case PIPE_INTERRUPT: |
| 143 | // case PIPE_BULK: | 172 | // case PIPE_BULK: |
| 144 | default: | 173 | default: |
| 145 | /* one TD for every 4096 Bytes (can be up to 8K) */ | 174 | size += number_of_tds(urb); |
| 146 | size += urb->transfer_buffer_length / 4096; | 175 | /* maybe a zero-length packet to wrap it up */ |
| 147 | /* ... and for any remaining bytes ... */ | ||
| 148 | if ((urb->transfer_buffer_length % 4096) != 0) | ||
| 149 | size++; | ||
| 150 | /* ... and maybe a zero length packet to wrap it up */ | ||
| 151 | if (size == 0) | 176 | if (size == 0) |
| 152 | size++; | 177 | size++; |
| 153 | else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 | 178 | else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 |
| @@ -202,6 +227,16 @@ static int ohci_urb_enqueue ( · 48 unmodified lines | |||
| 202 | usb_hcd_unlink_urb_from_ep(hcd, urb); | 227 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
| 203 | goto fail; | 228 | goto fail; |
| 204 | } | 229 | } |
| 230 | |||
| 231 | /* Start up the I/O watchdog timer, if it's not running */ | ||
| 232 | if (!timer_pending(&ohci->io_watchdog) && | ||
| 233 | list_empty(&ohci->eds_in_use)) { | ||
| 234 | ohci->prev_frame_no = ohci_frame_no(ohci); | ||
| 235 | mod_timer(&ohci->io_watchdog, | ||
| 236 | jiffies + IO_WATCHDOG_DELAY); | ||
| 237 | } | ||
| 238 | list_add(&ed->in_use_list, &ohci->eds_in_use); | ||
| 239 | |||
| 205 | if (ed->type == PIPE_ISOCHRONOUS) { | 240 | if (ed->type == PIPE_ISOCHRONOUS) { |
| 206 | u16 frame = ohci_frame_no(ohci); | 241 | u16 frame = ohci_frame_no(ohci); |
| 207 | 242 | ||
| @@ -277,30 +312,24 @@ static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) · 69 unmodified lines | |||
| 277 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 312 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 278 | unsigned long flags; | 313 | unsigned long flags; |
| 279 | int rc; | 314 | int rc; |
| 315 | urb_priv_t *urb_priv; | ||
| 280 | 316 | ||
| 281 | spin_lock_irqsave (&ohci->lock, flags); | 317 | spin_lock_irqsave (&ohci->lock, flags); |
| 282 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); | 318 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 283 | if (rc) { | 319 | if (rc == 0) { |
| 284 | ; /* Do nothing */ | ||
| 285 | } else if (ohci->rh_state == OHCI_RH_RUNNING) { | ||
| 286 | urb_priv_t *urb_priv; | ||
| 287 | 320 | ||
| 288 | /* Unless an IRQ completed the unlink while it was being | 321 | /* Unless an IRQ completed the unlink while it was being |
| 289 | * handed to us, flag it for unlink and giveback, and force | 322 | * handed to us, flag it for unlink and giveback, and force |
| 290 | * some upcoming INTR_SF to call finish_unlinks() | 323 | * some upcoming INTR_SF to call finish_unlinks() |
| 291 | */ | 324 | */ |
| 292 | urb_priv = urb->hcpriv; | 325 | urb_priv = urb->hcpriv; |
| 293 | if (urb_priv) { | 326 | if (urb_priv->ed->state == ED_OPER) |
| 294 | if (urb_priv->ed->state == ED_OPER) | 327 | start_ed_unlink(ohci, urb_priv->ed); |
| 295 | start_ed_unlink (ohci, urb_priv->ed); | 328 | |
| 329 | if (ohci->rh_state != OHCI_RH_RUNNING) { | ||
| 330 | /* With HC dead, we can clean up right away */ | ||
| 331 | ohci_work(ohci); | ||
| 296 | } | 332 | } |
| 297 | } else { | ||
| 298 | /* | ||
| 299 | * with HC dead, we won't respect hc queue pointers | ||
| 300 | * any more ... just clean up every urb's memory. | ||
| 301 | */ | ||
| 302 | if (urb->hcpriv) | ||
| 303 | finish_urb(ohci, urb, status); | ||
| 304 | } | 333 | } |
| 305 | spin_unlock_irqrestore (&ohci->lock, flags); | 334 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 306 | return rc; | 335 | return rc; |
| @@ -332,9 +361,7 @@ rescan: · 25 unmodified lines | |||
| 332 | if (ohci->rh_state != OHCI_RH_RUNNING) { | 361 | if (ohci->rh_state != OHCI_RH_RUNNING) { |
| 333 | sanitize: | 362 | sanitize: |
| 334 | ed->state = ED_IDLE; | 363 | ed->state = ED_IDLE; |
| 335 | if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) | 364 | ohci_work(ohci); |
| 336 | ohci->eds_scheduled--; | ||
| 337 | finish_unlinks (ohci, 0); | ||
| 338 | } | 365 | } |
| 339 | 366 | ||
| 340 | switch (ed->state) { | 367 | switch (ed->state) { |
| @@ -342,11 +369,6 @@ sanitize: · 1 unmodified line | |||
| 342 | /* major IRQ delivery trouble loses INTR_SF too... */ | 369 | /* major IRQ delivery trouble loses INTR_SF too... */ |
| 343 | if (limit-- == 0) { | 370 | if (limit-- == 0) { |
| 344 | ohci_warn(ohci, "ED unlink timeout\n"); | 371 | ohci_warn(ohci, "ED unlink timeout\n"); |
| 345 | if (quirk_zfmicro(ohci)) { | ||
| 346 | ohci_warn(ohci, "Attempting ZF TD recovery\n"); | ||
| 347 | ohci->ed_to_check = ed; | ||
| 348 | ohci->zf_delay = 2; | ||
| 349 | } | ||
| 350 | goto sanitize; | 372 | goto sanitize; |
| 351 | } | 373 | } |
| 352 | spin_unlock_irqrestore (&ohci->lock, flags); | 374 | spin_unlock_irqrestore (&ohci->lock, flags); |
| @@ -406,93 +428,7 @@ ohci_shutdown (struct usb_hcd *hcd) · 53 unmodified lines | |||
| 406 | udelay(10); | 428 | udelay(10); |
| 407 | 429 | ||
| 408 | ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval); | 430 | ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval); |
| 409 | } | 431 | ohci->rh_state = OHCI_RH_HALTED; |
| 410 | |||
| 411 | static int check_ed(struct ohci_hcd *ohci, struct ed *ed) | ||
| 412 | { | ||
| 413 | return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0 | ||
| 414 | && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK) | ||
| 415 | == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK) | ||
| 416 | && !list_empty(&ed->td_list); | ||
| 417 | } | ||
| 418 | |||
| 419 | /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes | ||
| 420 | * an interrupt TD but neglects to add it to the donelist. On systems with | ||
| 421 | * this chipset, we need to periodically check the state of the queues to look | ||
| 422 | * for such "lost" TDs. | ||
| 423 | */ | ||
| 424 | static void unlink_watchdog_func(unsigned long _ohci) | ||
| 425 | { | ||
| 426 | unsigned long flags; | ||
| 427 | unsigned max; | ||
| 428 | unsigned seen_count = 0; | ||
| 429 | unsigned i; | ||
| 430 | struct ed **seen = NULL; | ||
| 431 | struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci; | ||
| 432 | |||
| 433 | spin_lock_irqsave(&ohci->lock, flags); | ||
| 434 | max = ohci->eds_scheduled; | ||
| 435 | if (!max) | ||
| 436 | goto done; | ||
| 437 | |||
| 438 | if (ohci->ed_to_check) | ||
| 439 | goto out; | ||
| 440 | |||
| 441 | seen = kcalloc(max, sizeof *seen, GFP_ATOMIC); | ||
| 442 | if (!seen) | ||
| 443 | goto out; | ||
| 444 | |||
| 445 | for (i = 0; i < NUM_INTS; i++) { | ||
| 446 | struct ed *ed = ohci->periodic[i]; | ||
| 447 | |||
| 448 | while (ed) { | ||
| 449 | unsigned temp; | ||
| 450 | |||
| 451 | /* scan this branch of the periodic schedule tree */ | ||
| 452 | for (temp = 0; temp < seen_count; temp++) { | ||
| 453 | if (seen[temp] == ed) { | ||
| 454 | /* we've checked it and what's after */ | ||
| 455 | ed = NULL; | ||
| 456 | break; | ||
| 457 | } | ||
| 458 | } | ||
| 459 | if (!ed) | ||
| 460 | break; | ||
| 461 | seen[seen_count++] = ed; | ||
| 462 | if (!check_ed(ohci, ed)) { | ||
| 463 | ed = ed->ed_next; | ||
| 464 | continue; | ||
| 465 | } | ||
| 466 | |||
| 467 | /* HC's TD list is empty, but HCD sees at least one | ||
| 468 | * TD that's not been sent through the donelist. | ||
| 469 | */ | ||
| 470 | ohci->ed_to_check = ed; | ||
| 471 | ohci->zf_delay = 2; | ||
| 472 | |||
| 473 | /* The HC may wait until the next frame to report the | ||
| 474 | * TD as done through the donelist and INTR_WDH. (We | ||
| 475 | * just *assume* it's not a multi-TD interrupt URB; | ||
| 476 | * those could defer the IRQ more than one frame, using | ||
| 477 | * DI...) Check again after the next INTR_SF. | ||
| 478 | */ | ||
| 479 | ohci_writel(ohci, OHCI_INTR_SF, | ||
| 480 | &ohci->regs->intrstatus); | ||
| 481 | ohci_writel(ohci, OHCI_INTR_SF, | ||
| 482 | &ohci->regs->intrenable); | ||
| 483 | |||
| 484 | /* flush those writes */ | ||
| 485 | (void) ohci_readl(ohci, &ohci->regs->control); | ||
| 486 | |||
| 487 | goto out; | ||
| 488 | } | ||
| 489 | } | ||
| 490 | out: | ||
| 491 | kfree(seen); | ||
| 492 | if (ohci->eds_scheduled) | ||
| 493 | mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ)); | ||
| 494 | done: | ||
| 495 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
| 496 | } | 432 | } |
| 497 | 433 | ||
| 498 | /*-------------------------------------------------------------------------* | 434 | /*-------------------------------------------------------------------------* |
| @@ -506,6 +442,9 @@ static int ohci_init (struct ohci_hcd *ohci) · 7 unmodified lines | |||
| 506 | int ret; | 442 | int ret; |
| 507 | struct usb_hcd *hcd = ohci_to_hcd(ohci); | 443 | struct usb_hcd *hcd = ohci_to_hcd(ohci); |
| 508 | 444 | ||
| 445 | /* Accept arbitrarily long scatter-gather lists */ | ||
| 446 | hcd->self.sg_tablesize = ~0; | ||
| 447 | |||
| 509 | if (distrust_firmware) | 448 | if (distrust_firmware) |
| 510 | ohci->flags |= OHCI_QUIRK_HUB_POWER; | 449 | ohci->flags |= OHCI_QUIRK_HUB_POWER; |
| 511 | 450 | ||
| @@ -558,8 +497,12 @@ static int ohci_init (struct ohci_hcd *ohci) · 46 unmodified lines | |||
| 558 | if (ohci->hcca) | 497 | if (ohci->hcca) |
| 559 | return 0; | 498 | return 0; |
| 560 | 499 | ||
| 500 | setup_timer(&ohci->io_watchdog, io_watchdog_func, | ||
| 501 | (unsigned long) ohci); | ||
| 502 | set_timer_slack(&ohci->io_watchdog, msecs_to_jiffies(20)); | ||
| 503 | |||
| 561 | ohci->hcca = dma_alloc_coherent (hcd->self.controller, | 504 | ohci->hcca = dma_alloc_coherent (hcd->self.controller, |
| 562 | sizeof *ohci->hcca, &ohci->hcca_dma, 0); | 505 | sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL); |
| 563 | if (!ohci->hcca) | 506 | if (!ohci->hcca) |
| 564 | return -ENOMEM; | 507 | return -ENOMEM; |
| 565 | 508 | ||
| @@ -735,16 +678,7 @@ retry: · 169 unmodified lines | |||
| 735 | // POTPGT delay is bits 24-31, in 2 ms units. | 678 | // POTPGT delay is bits 24-31, in 2 ms units. |
| 736 | mdelay ((val >> 23) & 0x1fe); | 679 | mdelay ((val >> 23) & 0x1fe); |
| 737 | 680 | ||
| 738 | if (quirk_zfmicro(ohci)) { | 681 | ohci_dump(ohci); |
| 739 | /* Create timer to watch for bad queue state on ZF Micro */ | ||
| 740 | setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func, | ||
| 741 | (unsigned long) ohci); | ||
| 742 | |||
| 743 | ohci->eds_scheduled = 0; | ||
| 744 | ohci->ed_to_check = NULL; | ||
| 745 | } | ||
| 746 | |||
| 747 | ohci_dump (ohci, 1); | ||
| 748 | 682 | ||
| 749 | return 0; | 683 | return 0; |
| 750 | } | 684 | } |
| @@ -777,6 +711,142 @@ static int ohci_start(struct usb_hcd *hcd) · 26 unmodified lines | |||
| 777 | 711 | ||
| 778 | /*-------------------------------------------------------------------------*/ | 712 | /*-------------------------------------------------------------------------*/ |
| 779 | 713 | ||
| 714 | /* | ||
| 715 | * Some OHCI controllers are known to lose track of completed TDs. They | ||
| 716 | * don't add the TDs to the hardware done queue, which means we never see | ||
| 717 | * them as being completed. | ||
| 718 | * | ||
| 719 | * This watchdog routine checks for such problems. Without some way to | ||
| 720 | * tell when those TDs have completed, we would never take their EDs off | ||
| 721 | * the unlink list. As a result, URBs could never be dequeued and | ||
| 722 | * endpoints could never be released. | ||
| 723 | */ | ||
| 724 | static void io_watchdog_func(unsigned long _ohci) | ||
| 725 | { | ||
| 726 | struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci; | ||
| 727 | bool takeback_all_pending = false; | ||
| 728 | u32 status; | ||
| 729 | u32 head; | ||
| 730 | struct ed *ed; | ||
| 731 | struct td *td, *td_start, *td_next; | ||
| 732 | unsigned frame_no; | ||
| 733 | unsigned long flags; | ||
| 734 | |||
| 735 | spin_lock_irqsave(&ohci->lock, flags); | ||
| 736 | |||
| 737 | /* | ||
| 738 | * One way to lose track of completed TDs is if the controller | ||
| 739 | * never writes back the done queue head. If it hasn't been | ||
| 740 | * written back since the last time this function ran and if it | ||
| 741 | * was non-empty at that time, something is badly wrong with the | ||
| 742 | * hardware. | ||
| 743 | */ | ||
| 744 | status = ohci_readl(ohci, &ohci->regs->intrstatus); | ||
| 745 | if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) { | ||
| 746 | if (ohci->prev_donehead) { | ||
| 747 | ohci_err(ohci, "HcDoneHead not written back; disabled\n"); | ||
| 748 | died: | ||
| 749 | usb_hc_died(ohci_to_hcd(ohci)); | ||
| 750 | ohci_dump(ohci); | ||
| 751 | ohci_shutdown(ohci_to_hcd(ohci)); | ||
| 752 | goto done; | ||
| 753 | } else { | ||
| 754 | /* No write back because the done queue was empty */ | ||
| 755 | takeback_all_pending = true; | ||
| 756 | } | ||
| 757 | } | ||
| 758 | |||
| 759 | /* Check every ED which might have pending TDs */ | ||
| 760 | list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) { | ||
| 761 | if (ed->pending_td) { | ||
| 762 | if (takeback_all_pending || | ||
| 763 | OKAY_TO_TAKEBACK(ohci, ed)) { | ||
| 764 | unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO); | ||
| 765 | |||
| 766 | ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n", | ||
| 767 | 0x007f & tmp, | ||
| 768 | (0x000f & (tmp >> 7)) + | ||
| 769 | ((tmp & ED_IN) >> 5)); | ||
| 770 | add_to_done_list(ohci, ed->pending_td); | ||
| 771 | } | ||
| 772 | } | ||
| 773 | |||
| 774 | /* Starting from the latest pending TD, */ | ||
| 775 | td = ed->pending_td; | ||
| 776 | |||
| 777 | /* or the last TD on the done list, */ | ||
| 778 | if (!td) { | ||
| 779 | list_for_each_entry(td_next, &ed->td_list, td_list) { | ||
| 780 | if (!td_next->next_dl_td) | ||
| 781 | break; | ||
| 782 | td = td_next; | ||
| 783 | } | ||
| 784 | } | ||
| 785 | |||
| 786 | /* find the last TD processed by the controller. */ | ||
| 787 | head = hc32_to_cpu(ohci, ACCESS_ONCE(ed->hwHeadP)) & TD_MASK; | ||
| 788 | td_start = td; | ||
| 789 | td_next = list_prepare_entry(td, &ed->td_list, td_list); | ||
| 790 | list_for_each_entry_continue(td_next, &ed->td_list, td_list) { | ||
| 791 | if (head == (u32) td_next->td_dma) | ||
| 792 | break; | ||
| 793 | td = td_next; /* head pointer has passed this TD */ | ||
| 794 | } | ||
| 795 | if (td != td_start) { | ||
| 796 | /* | ||
| 797 | * In case a WDH cycle is in progress, we will wait | ||
| 798 | * for the next two cycles to complete before assuming | ||
| 799 | * this TD will never get on the done queue. | ||
| 800 | */ | ||
| 801 | ed->takeback_wdh_cnt = ohci->wdh_cnt + 2; | ||
| 802 | ed->pending_td = td; | ||
| 803 | } | ||
| 804 | } | ||
| 805 | |||
| 806 | ohci_work(ohci); | ||
| 807 | |||
| 808 | if (ohci->rh_state == OHCI_RH_RUNNING) { | ||
| 809 | |||
| 810 | /* | ||
| 811 | * Sometimes a controller just stops working. We can tell | ||
| 812 | * by checking that the frame counter has advanced since | ||
| 813 | * the last time we ran. | ||
| 814 | * | ||
| 815 | * But be careful: Some controllers violate the spec by | ||
| 816 | * stopping their frame counter when no ports are active. | ||
| 817 | */ | ||
| 818 | frame_no = ohci_frame_no(ohci); | ||
| 819 | if (frame_no == ohci->prev_frame_no) { | ||
| 820 | int active_cnt = 0; | ||
| 821 | int i; | ||
| 822 | unsigned tmp; | ||
| 823 | |||
| 824 | for (i = 0; i < ohci->num_ports; ++i) { | ||
| 825 | tmp = roothub_portstatus(ohci, i); | ||
| 826 | /* Enabled and not suspended? */ | ||
| 827 | if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS)) | ||
| 828 | ++active_cnt; | ||
| 829 | } | ||
| 830 | |||
| 831 | if (active_cnt > 0) { | ||
| 832 | ohci_err(ohci, "frame counter not updating; disabled\n"); | ||
| 833 | goto died; | ||
| 834 | } | ||
| 835 | } | ||
| 836 | if (!list_empty(&ohci->eds_in_use)) { | ||
| 837 | ohci->prev_frame_no = frame_no; | ||
| 838 | ohci->prev_wdh_cnt = ohci->wdh_cnt; | ||
| 839 | ohci->prev_donehead = ohci_readl(ohci, | ||
| 840 | &ohci->regs->donehead); | ||
| 841 | mod_timer(&ohci->io_watchdog, | ||
| 842 | jiffies + IO_WATCHDOG_DELAY); | ||
| 843 | } | ||
| 844 | } | ||
| 845 | |||
| 846 | done: | ||
| 847 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
| 848 | } | ||
| 849 | |||
| 780 | /* an interrupt happens */ | 850 | /* an interrupt happens */ |
| 781 | 851 | ||
| 782 | static irqreturn_t ohci_irq (struct usb_hcd *hcd) | 852 | static irqreturn_t ohci_irq (struct usb_hcd *hcd) |
| @@ -825,7 +895,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) · 42 unmodified lines | |||
| 825 | usb_hc_died(hcd); | 895 | usb_hc_died(hcd); |
| 826 | } | 896 | } |
| 827 | 897 | ||
| 828 | ohci_dump (ohci, 1); | 898 | ohci_dump(ohci); |
| 829 | ohci_usb_reset (ohci); | 899 | ohci_usb_reset (ohci); |
| 830 | } | 900 | } |
| 831 | 901 | ||
| @@ -863,58 +933,30 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) · 31 unmodified lines | |||
| 863 | usb_hcd_resume_root_hub(hcd); | 933 | usb_hcd_resume_root_hub(hcd); |
| 864 | } | 934 | } |
| 865 | 935 | ||
| 866 | if (ints & OHCI_INTR_WDH) { | 936 | spin_lock(&ohci->lock); |
| 867 | spin_lock (&ohci->lock); | 937 | if (ints & OHCI_INTR_WDH) |
| 868 | dl_done_list (ohci); | 938 | update_done_list(ohci); |
| 869 | spin_unlock (&ohci->lock); | ||
| 870 | } | ||
| 871 | |||
| 872 | if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) { | ||
| 873 | spin_lock(&ohci->lock); | ||
| 874 | if (ohci->ed_to_check) { | ||
| 875 | struct ed *ed = ohci->ed_to_check; | ||
| 876 | |||
| 877 | if (check_ed(ohci, ed)) { | ||
| 878 | /* HC thinks the TD list is empty; HCD knows | ||
| 879 | * at least one TD is outstanding | ||
| 880 | */ | ||
| 881 | if (--ohci->zf_delay == 0) { | ||
| 882 | struct td *td = list_entry( | ||
| 883 | ed->td_list.next, | ||
| 884 | struct td, td_list); | ||
| 885 | ohci_warn(ohci, | ||
| 886 | "Reclaiming orphan TD %p\n", | ||
| 887 | td); | ||
| 888 | takeback_td(ohci, td); | ||
| 889 | ohci->ed_to_check = NULL; | ||
| 890 | } | ||
| 891 | } else | ||
| 892 | ohci->ed_to_check = NULL; | ||
| 893 | } | ||
| 894 | spin_unlock(&ohci->lock); | ||
| 895 | } | ||
| 896 | 939 | ||
| 897 | /* could track INTR_SO to reduce available PCI/... bandwidth */ | 940 | /* could track INTR_SO to reduce available PCI/... bandwidth */ |
| 898 | 941 | ||
| 899 | /* handle any pending URB/ED unlinks, leaving INTR_SF enabled | 942 | /* handle any pending URB/ED unlinks, leaving INTR_SF enabled |
| 900 | * when there's still unlinking to be done (next frame). | 943 | * when there's still unlinking to be done (next frame). |
| 901 | */ | 944 | */ |
| 902 | spin_lock (&ohci->lock); | 945 | ohci_work(ohci); |
| 903 | if (ohci->ed_rm_list) | 946 | if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list |
| 904 | finish_unlinks (ohci, ohci_frame_no(ohci)); | ||
| 905 | if ((ints & OHCI_INTR_SF) != 0 | ||
| 906 | && !ohci->ed_rm_list | ||
| 907 | && !ohci->ed_to_check | ||
| 908 | && ohci->rh_state == OHCI_RH_RUNNING) | 947 | && ohci->rh_state == OHCI_RH_RUNNING) |
| 909 | ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable); | 948 | ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable); |
| 910 | spin_unlock (&ohci->lock); | ||
| 911 | 949 | ||
| 912 | if (ohci->rh_state == OHCI_RH_RUNNING) { | 950 | if (ohci->rh_state == OHCI_RH_RUNNING) { |
| 913 | ohci_writel (ohci, ints, ®s->intrstatus); | 951 | ohci_writel (ohci, ints, ®s->intrstatus); |
| 952 | if (ints & OHCI_INTR_WDH) | ||
| 953 | ++ohci->wdh_cnt; | ||
| 954 | |||
| 914 | ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable); | 955 | ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable); |
| 915 | // flush those writes | 956 | // flush those writes |
| 916 | (void) ohci_readl (ohci, &ohci->regs->control); | 957 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 917 | } | 958 | } |
| 959 | spin_unlock(&ohci->lock); | ||
| 918 | 960 | ||
| 919 | return IRQ_HANDLED; | 961 | return IRQ_HANDLED; |
| 920 | } | 962 | } |
| @@ -925,18 +967,17 @@ static void ohci_stop (struct usb_hcd *hcd) · 4 unmodified lines | |||
| 925 | { | 967 | { |
| 926 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 968 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 927 | 969 | ||
| 928 | ohci_dump (ohci, 1); | 970 | ohci_dump(ohci); |
| 929 | 971 | ||
| 930 | if (quirk_nec(ohci)) | 972 | if (quirk_nec(ohci)) |
| 931 | flush_work(&ohci->nec_work); | 973 | flush_work(&ohci->nec_work); |
| 974 | del_timer_sync(&ohci->io_watchdog); | ||
| 932 | 975 | ||
| 933 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); | 976 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
| 934 | ohci_usb_reset(ohci); | 977 | ohci_usb_reset(ohci); |
| 935 | free_irq(hcd->irq, hcd); | 978 | free_irq(hcd->irq, hcd); |
| 936 | hcd->irq = 0; | 979 | hcd->irq = 0; |
| 937 | 980 | ||
| 938 | if (quirk_zfmicro(ohci)) | ||
| 939 | del_timer(&ohci->unlink_watchdog); | ||
| 940 | if (quirk_amdiso(ohci)) | 981 | if (quirk_amdiso(ohci)) |
| 941 | usb_amd_dev_put(); | 982 | usb_amd_dev_put(); |
| 942 | 983 | ||
| @@ -993,7 +1034,7 @@ int ohci_restart(struct ohci_hcd *ohci) · 50 unmodified lines | |||
| 993 | if (!urb->unlinked) | 1034 | if (!urb->unlinked) |
| 994 | urb->unlinked = -ESHUTDOWN; | 1035 | urb->unlinked = -ESHUTDOWN; |
| 995 | } | 1036 | } |
| 996 | finish_unlinks (ohci, 0); | 1037 | ohci_work(ohci); |
| 997 | spin_unlock_irq(&ohci->lock); | 1038 | spin_unlock_irq(&ohci->lock); |
| 998 | 1039 | ||
| 999 | /* paranoia, in case that didn't work: */ | 1040 | /* paranoia, in case that didn't work: */ |
| @@ -39,8 +39,8 @@ · 38 unmodified lines | |||
| 39 | #define OHCI_SCHED_ENABLES \ | 39 | #define OHCI_SCHED_ENABLES \ |
| 40 | (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) | 40 | (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) |
| 41 | 41 | ||
| 42 | static void dl_done_list (struct ohci_hcd *); | 42 | static void update_done_list(struct ohci_hcd *); |
| 43 | static void finish_unlinks (struct ohci_hcd *, u16); | 43 | static void ohci_work(struct ohci_hcd *); |
| 44 | 44 | ||
| 45 | #ifdef CONFIG_PM | 45 | #ifdef CONFIG_PM |
| 46 | static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) | 46 | static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) |
| @@ -87,8 +87,8 @@ __acquires(ohci->lock) · 40 unmodified lines | |||
| 87 | msleep (8); | 87 | msleep (8); |
| 88 | spin_lock_irq (&ohci->lock); | 88 | spin_lock_irq (&ohci->lock); |
| 89 | } | 89 | } |
| 90 | dl_done_list (ohci); | 90 | update_done_list(ohci); |
| 91 | finish_unlinks (ohci, ohci_frame_no(ohci)); | 91 | ohci_work(ohci); |
| 92 | 92 | ||
| 93 | /* | 93 | /* |
| 94 | * Some controllers don't handle "global" suspend properly if | 94 | * Some controllers don't handle "global" suspend properly if |
| @@ -309,6 +309,9 @@ static int ohci_bus_suspend (struct usb_hcd *hcd) · 214 unmodified lines | |||
| 309 | else | 309 | else |
| 310 | rc = ohci_rh_suspend (ohci, 0); | 310 | rc = ohci_rh_suspend (ohci, 0); |
| 311 | spin_unlock_irq (&ohci->lock); | 311 | spin_unlock_irq (&ohci->lock); |
| 312 | |||
| 313 | if (rc == 0) | ||
| 314 | del_timer_sync(&ohci->io_watchdog); | ||
| 312 | return rc; | 315 | return rc; |
| 313 | } | 316 | } |
| 314 | 317 | ||
| @@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci) · 27 unmodified lines | |||
| 28 | ohci->next_statechange = jiffies; | 28 | ohci->next_statechange = jiffies; |
| 29 | spin_lock_init (&ohci->lock); | 29 | spin_lock_init (&ohci->lock); |
| 30 | INIT_LIST_HEAD (&ohci->pending); | 30 | INIT_LIST_HEAD (&ohci->pending); |
| 31 | INIT_LIST_HEAD(&ohci->eds_in_use); | ||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | /*-------------------------------------------------------------------------*/ | 34 | /*-------------------------------------------------------------------------*/ |
| @@ -187,10 +187,6 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed) · 186 unmodified lines | |||
| 187 | ed->ed_prev = NULL; | 187 | ed->ed_prev = NULL; |
| 188 | ed->ed_next = NULL; | 188 | ed->ed_next = NULL; |
| 189 | ed->hwNextED = 0; | 189 | ed->hwNextED = 0; |
| 190 | if (quirk_zfmicro(ohci) | ||
| 191 | && (ed->type == PIPE_INTERRUPT) | ||
| 192 | && !(ohci->eds_scheduled++)) | ||
| 193 | mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ)); | ||
| 194 | wmb (); | 190 | wmb (); |
| 195 | 191 | ||
| 196 | /* we care about rm_list when setting CLE/BLE in case the HC was at | 192 | /* we care about rm_list when setting CLE/BLE in case the HC was at |
| @@ -311,8 +307,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed) · 114 unmodified lines | |||
| 311 | * - ED_OPER: when there's any request queued, the ED gets rescheduled | 307 | * - ED_OPER: when there's any request queued, the ED gets rescheduled |
| 312 | * immediately. HC should be working on them. | 308 | * immediately. HC should be working on them. |
| 313 | * | 309 | * |
| 314 | * - ED_IDLE: when there's no TD queue. there's no reason for the HC | 310 | * - ED_IDLE: when there's no TD queue or the HC isn't running. |
| 315 | * to care about this ED; safe to disable the endpoint. | ||
| 316 | * | 311 | * |
| 317 | * When finish_unlinks() runs later, after SOF interrupt, it will often | 312 | * When finish_unlinks() runs later, after SOF interrupt, it will often |
| 318 | * complete one or more URB unlinks before making that state change. | 313 | * complete one or more URB unlinks before making that state change. |
| @@ -602,6 +597,8 @@ static void td_submit_urb ( · 283 unmodified lines | |||
| 602 | u32 info = 0; | 597 | u32 info = 0; |
| 603 | int is_out = usb_pipeout (urb->pipe); | 598 | int is_out = usb_pipeout (urb->pipe); |
| 604 | int periodic = 0; | 599 | int periodic = 0; |
| 600 | int i, this_sg_len, n; | ||
| 601 | struct scatterlist *sg; | ||
| 605 | 602 | ||
| 606 | /* OHCI handles the bulk/interrupt data toggles itself. We just | 603 | /* OHCI handles the bulk/interrupt data toggles itself. We just |
| 607 | * use the device toggle bits for resetting, and rely on the fact | 604 | * use the device toggle bits for resetting, and rely on the fact |
| @@ -615,10 +612,24 @@ static void td_submit_urb ( · 7 unmodified lines | |||
| 615 | 612 | ||
| 616 | list_add (&urb_priv->pending, &ohci->pending); | 613 | list_add (&urb_priv->pending, &ohci->pending); |
| 617 | 614 | ||
| 618 | if (data_len) | 615 | i = urb->num_mapped_sgs; |
| 619 | data = urb->transfer_dma; | 616 | if (data_len > 0 && i > 0) { |
| 620 | else | 617 | sg = urb->sg; |
| 621 | data = 0; | 618 | data = sg_dma_address(sg); |
| 619 | |||
| 620 | /* | ||
| 621 | * urb->transfer_buffer_length may be smaller than the | ||
| 622 | * size of the scatterlist (or vice versa) | ||
| 623 | */ | ||
| 624 | this_sg_len = min_t(int, sg_dma_len(sg), data_len); | ||
| 625 | } else { | ||
| 626 | sg = NULL; | ||
| 627 | if (data_len) | ||
| 628 | data = urb->transfer_dma; | ||
| 629 | else | ||
| 630 | data = 0; | ||
| 631 | this_sg_len = data_len; | ||
| 632 | } | ||
| 622 | 633 | ||
| 623 | /* NOTE: TD_CC is set so we can tell which TDs the HC processed by | 634 | /* NOTE: TD_CC is set so we can tell which TDs the HC processed by |
| 624 | * using TD_CC_GET, as well as by seeing them on the done list. | 635 | * using TD_CC_GET, as well as by seeing them on the done list. |
| @@ -639,17 +650,29 @@ static void td_submit_urb ( · 14 unmodified lines | |||
| 639 | ? TD_T_TOGGLE | TD_CC | TD_DP_OUT | 650 | ? TD_T_TOGGLE | TD_CC | TD_DP_OUT |
| 640 | : TD_T_TOGGLE | TD_CC | TD_DP_IN; | 651 | : TD_T_TOGGLE | TD_CC | TD_DP_IN; |
| 641 | /* TDs _could_ transfer up to 8K each */ | 652 | /* TDs _could_ transfer up to 8K each */ |
| 642 | while (data_len > 4096) { | 653 | for (;;) { |
| 643 | td_fill (ohci, info, data, 4096, urb, cnt); | 654 | n = min(this_sg_len, 4096); |
| 644 | data += 4096; | 655 | |
| 645 | data_len -= 4096; | 656 | /* maybe avoid ED halt on final TD short read */ |
| 657 | if (n >= data_len || (i == 1 && n >= this_sg_len)) { | ||
| 658 | if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) | ||
| 659 | info |= TD_R; | ||
| 660 | } | ||
| 661 | td_fill(ohci, info, data, n, urb, cnt); | ||
| 662 | this_sg_len -= n; | ||
| 663 | data_len -= n; | ||
| 664 | data += n; | ||
| 646 | cnt++; | 665 | cnt++; |
| 666 | |||
| 667 | if (this_sg_len <= 0) { | ||
| 668 | if (--i <= 0 || data_len <= 0) | ||
| 669 | break; | ||
| 670 | sg = sg_next(sg); | ||
| 671 | data = sg_dma_address(sg); | ||
| 672 | this_sg_len = min_t(int, sg_dma_len(sg), | ||
| 673 | data_len); | ||
| 674 | } | ||
| 647 | } | 675 | } |
| 648 | /* maybe avoid ED halt on final TD short read */ | ||
| 649 | if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) | ||
| 650 | info |= TD_R; | ||
| 651 | td_fill (ohci, info, data, data_len, urb, cnt); | ||
| 652 | cnt++; | ||
| 653 | if ((urb->transfer_flags & URB_ZERO_PACKET) | 676 | if ((urb->transfer_flags & URB_ZERO_PACKET) |
| 654 | && cnt < urb_priv->length) { | 677 | && cnt < urb_priv->length) { |
| 655 | td_fill (ohci, info, 0, 0, urb, cnt); | 678 | td_fill (ohci, info, 0, 0, urb, cnt); |
| @@ -869,13 +892,46 @@ static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc) · 213 unmodified lines | |||
| 869 | } | 892 | } |
| 870 | } | 893 | } |
| 871 | 894 | ||
| 872 | /* replies to the request have to be on a FIFO basis so | 895 | /* Add a TD to the done list */ |
| 873 | * we unreverse the hc-reversed done-list | 896 | static void add_to_done_list(struct ohci_hcd *ohci, struct td *td) |
| 874 | */ | 897 | { |
| 875 | static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) | 898 | struct td *td2, *td_prev; |
| 899 | struct ed *ed; | ||
| 900 | |||
| 901 | if (td->next_dl_td) | ||
| 902 | return; /* Already on the list */ | ||
| 903 | |||
| 904 | /* Add all the TDs going back until we reach one that's on the list */ | ||
| 905 | ed = td->ed; | ||
| 906 | td2 = td_prev = td; | ||
| 907 | list_for_each_entry_continue_reverse(td2, &ed->td_list, td_list) { | ||
| 908 | if (td2->next_dl_td) | ||
| 909 | break; | ||
| 910 | td2->next_dl_td = td_prev; | ||
| 911 | td_prev = td2; | ||
| 912 | } | ||
| 913 | |||
| 914 | if (ohci->dl_end) | ||
| 915 | ohci->dl_end->next_dl_td = td_prev; | ||
| 916 | else | ||
| 917 | ohci->dl_start = td_prev; | ||
| 918 | |||
| 919 | /* | ||
| 920 | * Make td->next_dl_td point to td itself, to mark the fact | ||
| 921 | * that td is on the done list. | ||
| 922 | */ | ||
| 923 | ohci->dl_end = td->next_dl_td = td; | ||
| 924 | |||
| 925 | /* Did we just add the latest pending TD? */ | ||
| 926 | td2 = ed->pending_td; | ||
| 927 | if (td2 && td2->next_dl_td) | ||
| 928 | ed->pending_td = NULL; | ||
| 929 | } | ||
| 930 | |||
| 931 | /* Get the entries on the hardware done queue and put them on our list */ | ||
| 932 | static void update_done_list(struct ohci_hcd *ohci) | ||
| 876 | { | 933 | { |
| 877 | u32 td_dma; | 934 | u32 td_dma; |
| 878 | struct td *td_rev = NULL; | ||
| 879 | struct td *td = NULL; | 935 | struct td *td = NULL; |
| 880 | 936 | ||
| 881 | td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head); | 937 | td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head); |
| @@ -883,7 +939,7 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) · 1 unmodified line | |||
| 883 | wmb(); | 939 | wmb(); |
| 884 | 940 | ||
| 885 | /* get TD from hc's singly linked list, and | 941 | /* get TD from hc's singly linked list, and |
| 886 | * prepend to ours. ed->td_list changes later. | 942 | * add to ours. ed->td_list changes later. |
| 887 | */ | 943 | */ |
| 888 | while (td_dma) { | 944 | while (td_dma) { |
| 889 | int cc; | 945 | int cc; |
| @@ -905,19 +961,17 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) · 15 unmodified lines | |||
| 905 | && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) | 961 | && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) |
| 906 | ed_halted(ohci, td, cc); | 962 | ed_halted(ohci, td, cc); |
| 907 | 963 | ||
| 908 | td->next_dl_td = td_rev; | ||
| 909 | td_rev = td; | ||
| 910 | td_dma = hc32_to_cpup (ohci, &td->hwNextTD); | 964 | td_dma = hc32_to_cpup (ohci, &td->hwNextTD); |
| 965 | add_to_done_list(ohci, td); | ||
| 911 | } | 966 | } |
| 912 | return td_rev; | ||
| 913 | } | 967 | } |
| 914 | 968 | ||
| 915 | /*-------------------------------------------------------------------------*/ | 969 | /*-------------------------------------------------------------------------*/ |
| 916 | 970 | ||
| 917 | /* there are some urbs/eds to unlink; called in_irq(), with HCD locked */ | 971 | /* there are some urbs/eds to unlink; called in_irq(), with HCD locked */ |
| 918 | static void | 972 | static void finish_unlinks(struct ohci_hcd *ohci) |
| 919 | finish_unlinks (struct ohci_hcd *ohci, u16 tick) | ||
| 920 | { | 973 | { |
| 974 | unsigned tick = ohci_frame_no(ohci); | ||
| 921 | struct ed *ed, **last; | 975 | struct ed *ed, **last; |
| 922 | 976 | ||
| 923 | rescan_all: | 977 | rescan_all: |
| @@ -926,41 +980,48 @@ rescan_all: · 2 unmodified lines | |||
| 926 | int completed, modified; | 980 | int completed, modified; |
| 927 | __hc32 *prev; | 981 | __hc32 *prev; |
| 928 | 982 | ||
| 983 | /* Is this ED already invisible to the hardware? */ | ||
| 984 | if (ed->state == ED_IDLE) | ||
| 985 | goto ed_idle; | ||
| 986 | |||
| 929 | /* only take off EDs that the HC isn't using, accounting for | 987 | /* only take off EDs that the HC isn't using, accounting for |
| 930 | * frame counter wraps and EDs with partially retired TDs | 988 | * frame counter wraps and EDs with partially retired TDs |
| 931 | */ | 989 | */ |
| 932 | if (likely(ohci->rh_state == OHCI_RH_RUNNING)) { | 990 | if (likely(ohci->rh_state == OHCI_RH_RUNNING) && |
| 933 | if (tick_before (tick, ed->tick)) { | 991 | tick_before(tick, ed->tick)) { |
| 934 | skip_ed: | 992 | skip_ed: |
| 935 | last = &ed->ed_next; | 993 | last = &ed->ed_next; |
| 936 | continue; | 994 | continue; |
| 937 | } | 995 | } |
| 996 | if (!list_empty(&ed->td_list)) { | ||
| 997 | struct td *td; | ||
| 998 | u32 head; | ||
| 938 | 999 | ||
| 939 | if (!list_empty (&ed->td_list)) { | 1000 | td = list_first_entry(&ed->td_list, struct td, td_list); |
| 940 | struct td *td; | 1001 | |
| 941 | u32 head; | 1002 | /* INTR_WDH may need to clean up first */ |
| 942 | 1003 | head = hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK; | |
| 943 | td = list_entry (ed->td_list.next, struct td, | 1004 | if (td->td_dma != head && |
| 944 | td_list); | 1005 | ohci->rh_state == OHCI_RH_RUNNING) |
| 945 | head = hc32_to_cpu (ohci, ed->hwHeadP) & | 1006 | goto skip_ed; |
| 946 | TD_MASK; | 1007 | |
| 947 | 1008 | /* Don't mess up anything already on the done list */ | |
| 948 | /* INTR_WDH may need to clean up first */ | 1009 | if (td->next_dl_td) |
| 949 | if (td->td_dma != head) { | 1010 | goto skip_ed; |
| 950 | if (ed == ohci->ed_to_check) | ||
| 951 | ohci->ed_to_check = NULL; | ||
| 952 | else | ||
| 953 | goto skip_ed; | ||
| 954 | } | ||
| 955 | } | ||
| 956 | } | 1011 | } |
| 957 | 1012 | ||
| 1013 | /* ED's now officially unlinked, hc doesn't see */ | ||
| 1014 | ed->state = ED_IDLE; | ||
| 1015 | ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H); | ||
| 1016 | ed->hwNextED = 0; | ||
| 1017 | wmb(); | ||
| 1018 | ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE); | ||
| 1019 | ed_idle: | ||
| 1020 | |||
| 958 | /* reentrancy: if we drop the schedule lock, someone might | 1021 | /* reentrancy: if we drop the schedule lock, someone might |
| 959 | * have modified this list. normally it's just prepending | 1022 | * have modified this list. normally it's just prepending |
| 960 | * entries (which we'd ignore), but paranoia won't hurt. | 1023 | * entries (which we'd ignore), but paranoia won't hurt. |
| 961 | */ | 1024 | */ |
| 962 | *last = ed->ed_next; | ||
| 963 | ed->ed_next = NULL; | ||
| 964 | modified = 0; | 1025 | modified = 0; |
| 965 | 1026 | ||
| 966 | /* unlink urbs as requested, but rescan the list after | 1027 | /* unlink urbs as requested, but rescan the list after |
| @@ -1018,19 +1079,21 @@ rescan_this: · 51 unmodified lines | |||
| 1018 | if (completed && !list_empty (&ed->td_list)) | 1079 | if (completed && !list_empty (&ed->td_list)) |
| 1019 | goto rescan_this; | 1080 | goto rescan_this; |
| 1020 | 1081 | ||
| 1021 | /* ED's now officially unlinked, hc doesn't see */ | 1082 | /* |
| 1022 | ed->state = ED_IDLE; | 1083 | * If no TDs are queued, take ED off the ed_rm_list. |
| 1023 | if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) | 1084 | * Otherwise, if the HC is running, reschedule. |
| 1024 | ohci->eds_scheduled--; | 1085 | * If not, leave it on the list for further dequeues. |
| 1025 | ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H); | 1086 | */ |
| 1026 | ed->hwNextED = 0; | 1087 | if (list_empty(&ed->td_list)) { |
| 1027 | wmb (); | 1088 | *last = ed->ed_next; |
| 1028 | ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE); | 1089 | ed->ed_next = NULL; |
| 1029 | 1090 | list_del(&ed->in_use_list); | |
| 1030 | /* but if there's work queued, reschedule */ | 1091 | } else if (ohci->rh_state == OHCI_RH_RUNNING) { |
| 1031 | if (!list_empty (&ed->td_list)) { | 1092 | *last = ed->ed_next; |
| 1032 | if (ohci->rh_state == OHCI_RH_RUNNING) | 1093 | ed->ed_next = NULL; |
| 1033 | ed_schedule (ohci, ed); | 1094 | ed_schedule(ohci, ed); |
| 1095 | } else { | ||
| 1096 | last = &ed->ed_next; | ||
| 1034 | } | 1097 | } |
| 1035 | 1098 | ||
| 1036 | if (modified) | 1099 | if (modified) |
| @@ -1082,12 +1145,7 @@ rescan_this: · 45 unmodified lines | |||
| 1082 | 1145 | ||
| 1083 | /*-------------------------------------------------------------------------*/ | 1146 | /*-------------------------------------------------------------------------*/ |
| 1084 | 1147 | ||
| 1085 | /* | 1148 | /* Take back a TD from the host controller */ |
| 1086 | * Used to take back a TD from the host controller. This would normally be | ||
| 1087 | * called from within dl_done_list, however it may be called directly if the | ||
| 1088 | * HC no longer sees the TD and it has not appeared on the donelist (after | ||
| 1089 | * two frames). This bug has been observed on ZF Micro systems. | ||
| 1090 | */ | ||
| 1091 | static void takeback_td(struct ohci_hcd *ohci, struct td *td) | 1149 | static void takeback_td(struct ohci_hcd *ohci, struct td *td) |
| 1092 | { | 1150 | { |
| 1093 | struct urb *urb = td->urb; | 1151 | struct urb *urb = td->urb; |
| @@ -1134,37 +1192,43 @@ static void takeback_td(struct ohci_hcd *ohci, struct td *td) · 40 unmodified lines | |||
| 1134 | * | 1192 | * |
| 1135 | * This is the main path for handing urbs back to drivers. The only other | 1193 | * This is the main path for handing urbs back to drivers. The only other |
| 1136 | * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list, | 1194 | * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list, |
| 1137 | * instead of scanning the (re-reversed) donelist as this does. There's | 1195 | * instead of scanning the (re-reversed) donelist as this does. |
| 1138 | * an abnormal path too, handling a quirk in some Compaq silicon: URBs | ||
| 1139 | * with TDs that appear to be orphaned are directly reclaimed. | ||
| 1140 | */ | 1196 | */ |
| 1141 | static void | 1197 | static void process_done_list(struct ohci_hcd *ohci) |
| 1142 | dl_done_list (struct ohci_hcd *ohci) | ||
| 1143 | { | 1198 | { |
| 1144 | struct td *td = dl_reverse_done_list (ohci); | 1199 | struct td *td; |
| 1145 | 1200 | ||
| 1146 | while (td) { | 1201 | while (ohci->dl_start) { |
| 1147 | struct td *td_next = td->next_dl_td; | 1202 | td = ohci->dl_start; |
| 1148 | struct ed *ed = td->ed; | 1203 | if (td == ohci->dl_end) |
| 1204 | ohci->dl_start = ohci->dl_end = NULL; | ||
| 1205 | else | ||
| 1206 | ohci->dl_start = td->next_dl_td; | ||
| 1149 | 1207 | ||
| 1150 | /* | 1208 | takeback_td(ohci, td); |
| 1151 | * Some OHCI controllers (NVIDIA for sure, maybe others) | 1209 | } |
| 1152 | * occasionally forget to add TDs to the done queue. Since | 1210 | } |
| 1153 | * TDs for a given endpoint are always processed in order, | ||
| 1154 | * if we find a TD on the donelist then all of its | ||
| 1155 | * predecessors must be finished as well. | ||
| 1156 | */ | ||
| 1157 | for (;;) { | ||
| 1158 | struct td *td2; | ||
| 1159 | 1211 | ||
| 1160 | td2 = list_first_entry(&ed->td_list, struct td, | 1212 | /* |
| 1161 | td_list); | 1213 | * TD takeback and URB giveback must be single-threaded. |
| 1162 | if (td2 == td) | 1214 | * This routine takes care of it all. |
| 1163 | break; | 1215 | */ |
| 1164 | takeback_td(ohci, td2); | 1216 | static void ohci_work(struct ohci_hcd *ohci) |
| 1165 | } | 1217 | { |
| 1218 | if (ohci->working) { | ||
| 1219 | ohci->restart_work = 1; | ||
| 1220 | return; | ||
| 1221 | } | ||
| 1222 | ohci->working = 1; | ||
| 1166 | 1223 | ||
| 1167 | takeback_td(ohci, td); | 1224 | restart: |
| 1168 | td = td_next; | 1225 | process_done_list(ohci); |
| 1226 | if (ohci->ed_rm_list) | ||
| 1227 | finish_unlinks(ohci); | ||
| 1228 | |||
| 1229 | if (ohci->restart_work) { | ||
| 1230 | ohci->restart_work = 0; | ||
| 1231 | goto restart; | ||
| 1169 | } | 1232 | } |
| 1233 | ohci->working = 0; | ||
| 1170 | } | 1234 | } |
| @@ -162,7 +162,7 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev) · 161 unmodified lines | |||
| 162 | } | 162 | } |
| 163 | #endif | 163 | #endif |
| 164 | 164 | ||
| 165 | static struct of_device_id spear_ohci_id_table[] = { | 165 | static const struct of_device_id spear_ohci_id_table[] = { |
| 166 | { .compatible = "st,spear600-ohci", }, | 166 | { .compatible = "st,spear600-ohci", }, |
| 167 | { }, | 167 | { }, |
| 168 | }; | 168 | }; |
| @@ -47,6 +47,7 @@ struct ed { · 46 unmodified lines | |||
| 47 | struct ed *ed_next; /* on schedule or rm_list */ | 47 | struct ed *ed_next; /* on schedule or rm_list */ |
| 48 | struct ed *ed_prev; /* for non-interrupt EDs */ | 48 | struct ed *ed_prev; /* for non-interrupt EDs */ |
| 49 | struct list_head td_list; /* "shadow list" of our TDs */ | 49 | struct list_head td_list; /* "shadow list" of our TDs */ |
| 50 | struct list_head in_use_list; | ||
| 50 | 51 | ||
| 51 | /* create --> IDLE --> OPER --> ... --> IDLE --> destroy | 52 | /* create --> IDLE --> OPER --> ... --> IDLE --> destroy |
| 52 | * usually: OPER --> UNLINK --> (IDLE | OPER) --> ... | 53 | * usually: OPER --> UNLINK --> (IDLE | OPER) --> ... |
| @@ -66,6 +67,13 @@ struct ed { · 13 unmodified lines | |||
| 66 | 67 | ||
| 67 | /* HC may see EDs on rm_list until next frame (frame_no == tick) */ | 68 | /* HC may see EDs on rm_list until next frame (frame_no == tick) */ |
| 68 | u16 tick; | 69 | u16 tick; |
| 70 | |||
| 71 | /* Detect TDs not added to the done queue */ | ||
| 72 | unsigned takeback_wdh_cnt; | ||
| 73 | struct td *pending_td; | ||
| 74 | #define OKAY_TO_TAKEBACK(ohci, ed) \ | ||
| 75 | ((int) (ohci->wdh_cnt - ed->takeback_wdh_cnt) >= 0) | ||
| 76 | |||
| 69 | } __attribute__ ((aligned(16))); | 77 | } __attribute__ ((aligned(16))); |
| 70 | 78 | ||
| 71 | #define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */ | 79 | #define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */ |
| @@ -380,7 +388,9 @@ struct ohci_hcd { · 308 unmodified lines | |||
| 380 | struct dma_pool *td_cache; | 388 | struct dma_pool *td_cache; |
| 381 | struct dma_pool *ed_cache; | 389 | struct dma_pool *ed_cache; |
| 382 | struct td *td_hash [TD_HASH_SIZE]; | 390 | struct td *td_hash [TD_HASH_SIZE]; |
| 391 | struct td *dl_start, *dl_end; /* the done list */ | ||
| 383 | struct list_head pending; | 392 | struct list_head pending; |
| 393 | struct list_head eds_in_use; /* all EDs with at least 1 TD */ | ||
| 384 | 394 | ||
| 385 | /* | 395 | /* |
| 386 | * driver state | 396 | * driver state |
| @@ -392,6 +402,8 @@ struct ohci_hcd { · 5 unmodified lines | |||
| 392 | unsigned long next_statechange; /* suspend/resume */ | 402 | unsigned long next_statechange; /* suspend/resume */ |
| 393 | u32 fminterval; /* saved register */ | 403 | u32 fminterval; /* saved register */ |
| 394 | unsigned autostop:1; /* rh auto stopping/stopped */ | 404 | unsigned autostop:1; /* rh auto stopping/stopped */ |
| 405 | unsigned working:1; | ||
| 406 | unsigned restart_work:1; | ||
| 395 | 407 | ||
| 396 | unsigned long flags; /* for HC bugs */ | 408 | unsigned long flags; /* for HC bugs */ |
| 397 | #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ | 409 | #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ |
| @@ -409,13 +421,12 @@ struct ohci_hcd { · 11 unmodified lines | |||
| 409 | 421 | ||
| 410 | // there are also chip quirks/bugs in init logic | 422 | // there are also chip quirks/bugs in init logic |
| 411 | 423 | ||
| 412 | struct work_struct nec_work; /* Worker for NEC quirk */ | 424 | unsigned prev_frame_no; |
| 425 | unsigned wdh_cnt, prev_wdh_cnt; | ||
| 426 | u32 prev_donehead; | ||
| 427 | struct timer_list io_watchdog; | ||
| 413 | 428 | ||
| 414 | /* Needed for ZF Micro quirk */ | 429 | struct work_struct nec_work; /* Worker for NEC quirk */ |
| 415 | struct timer_list unlink_watchdog; | ||
| 416 | unsigned eds_scheduled; | ||
| 417 | struct ed *ed_to_check; | ||
| 418 | unsigned zf_delay; | ||
| 419 | 430 | ||
| 420 | struct dentry *debug_dir; | 431 | struct dentry *debug_dir; |
| 421 | struct dentry *debug_async; | 432 | struct dentry *debug_async; |
| @@ -3826,49 +3826,36 @@ static int oxu_drv_probe(struct platform_device *pdev) · 3825 unmodified lines | |||
| 3826 | dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); | 3826 | dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); |
| 3827 | 3827 | ||
| 3828 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 3828 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 3829 | if (!res) { | 3829 | base = devm_ioremap_resource(&pdev->dev, res); |
| 3830 | dev_err(&pdev->dev, "no registers address! Check %s setup!\n", | 3830 | if (IS_ERR(base)) { |
| 3831 | dev_name(&pdev->dev)); | 3831 | ret = PTR_ERR(base); |
| 3832 | return -ENODEV; | 3832 | goto error; |
| 3833 | } | 3833 | } |
| 3834 | memstart = res->start; | 3834 | memstart = res->start; |
| 3835 | memlen = resource_size(res); | 3835 | memlen = resource_size(res); |
| 3836 | dev_dbg(&pdev->dev, "MEM resource %lx-%lx\n", memstart, memlen); | ||
| 3837 | if (!request_mem_region(memstart, memlen, | ||
| 3838 | oxu_hc_driver.description)) { | ||
| 3839 | dev_dbg(&pdev->dev, "memory area already in use\n"); | ||
| 3840 | return -EBUSY; | ||
| 3841 | } | ||
| 3842 | 3836 | ||
| 3843 | ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING); | 3837 | ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING); |
| 3844 | if (ret) { | 3838 | if (ret) { |
| 3845 | dev_err(&pdev->dev, "error setting irq type\n"); | 3839 | dev_err(&pdev->dev, "error setting irq type\n"); |
| 3846 | ret = -EFAULT; | 3840 | ret = -EFAULT; |
| 3847 | goto error_set_irq_type; | 3841 | goto error; |
| 3848 | } | ||
| 3849 | |||
| 3850 | base = ioremap(memstart, memlen); | ||
| 3851 | if (!base) { | ||
| 3852 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
| 3853 | ret = -EFAULT; | ||
| 3854 | goto error_ioremap; | ||
| 3855 | } | 3842 | } |
| 3856 | 3843 | ||
| 3857 | /* Allocate a driver data struct to hold useful info for both | 3844 | /* Allocate a driver data struct to hold useful info for both |
| 3858 | * SPH & OTG devices | 3845 | * SPH & OTG devices |
| 3859 | */ | 3846 | */ |
| 3860 | info = kzalloc(sizeof(struct oxu_info), GFP_KERNEL); | 3847 | info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL); |
| 3861 | if (!info) { | 3848 | if (!info) { |
| 3862 | dev_dbg(&pdev->dev, "error allocating memory\n"); | 3849 | dev_dbg(&pdev->dev, "error allocating memory\n"); |
| 3863 | ret = -EFAULT; | 3850 | ret = -EFAULT; |
| 3864 | goto error_alloc; | 3851 | goto error; |
| 3865 | } | 3852 | } |
| 3866 | platform_set_drvdata(pdev, info); | 3853 | platform_set_drvdata(pdev, info); |
| 3867 | 3854 | ||
| 3868 | ret = oxu_init(pdev, memstart, memlen, base, irq); | 3855 | ret = oxu_init(pdev, memstart, memlen, base, irq); |
| 3869 | if (ret < 0) { | 3856 | if (ret < 0) { |
| 3870 | dev_dbg(&pdev->dev, "cannot init USB devices\n"); | 3857 | dev_dbg(&pdev->dev, "cannot init USB devices\n"); |
| 3871 | goto error_init; | 3858 | goto error; |
| 3872 | } | 3859 | } |
| 3873 | 3860 | ||
| 3874 | dev_info(&pdev->dev, "devices enabled and running\n"); | 3861 | dev_info(&pdev->dev, "devices enabled and running\n"); |
| @@ -3876,16 +3863,7 @@ static int oxu_drv_probe(struct platform_device *pdev) · 1 unmodified line | |||
| 3876 | 3863 | ||
| 3877 | return 0; | 3864 | return 0; |
| 3878 | 3865 | ||
| 3879 | error_init: | 3866 | error: |
| 3880 | kfree(info); | ||
| 3881 | |||
| 3882 | error_alloc: | ||
| 3883 | iounmap(base); | ||
| 3884 | |||
| 3885 | error_set_irq_type: | ||
| 3886 | error_ioremap: | ||
| 3887 | release_mem_region(memstart, memlen); | ||
| 3888 | |||
| 3889 | dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); | 3867 | dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); |
| 3890 | return ret; | 3868 | return ret; |
| 3891 | } | 3869 | } |
| @@ -3899,18 +3877,10 @@ static void oxu_remove(struct platform_device *pdev, struct usb_hcd *hcd) · 7 unmodified lines | |||
| 3899 | static int oxu_drv_remove(struct platform_device *pdev) | 3877 | static int oxu_drv_remove(struct platform_device *pdev) |
| 3900 | { | 3878 | { |
| 3901 | struct oxu_info *info = platform_get_drvdata(pdev); | 3879 | struct oxu_info *info = platform_get_drvdata(pdev); |
| 3902 | unsigned long memstart = info->hcd[0]->rsrc_start, | ||
| 3903 | memlen = info->hcd[0]->rsrc_len; | ||
| 3904 | void *base = info->hcd[0]->regs; | ||
| 3905 | 3880 | ||
| 3906 | oxu_remove(pdev, info->hcd[0]); | 3881 | oxu_remove(pdev, info->hcd[0]); |
| 3907 | oxu_remove(pdev, info->hcd[1]); | 3882 | oxu_remove(pdev, info->hcd[1]); |
| 3908 | 3883 | ||
| 3909 | iounmap(base); | ||
| 3910 | release_mem_region(memstart, memlen); | ||
| 3911 | |||
| 3912 | kfree(info); | ||
| 3913 | |||
| 3914 | return 0; | 3884 | return 0; |
| 3915 | } | 3885 | } |
| 3916 | 3886 | ||
| @@ -17,6 +17,7 @@ · 16 unmodified lines | |||
| 17 | * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu | 17 | * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu |
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | #include <linux/device.h> | ||
| 20 | #include <linux/of_irq.h> | 21 | #include <linux/of_irq.h> |
| 21 | #include <linux/of_address.h> | 22 | #include <linux/of_address.h> |
| 22 | #include <linux/of_platform.h> | 23 | #include <linux/of_platform.h> |
| @@ -113,24 +114,17 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) · 90 unmodified lines | |||
| 113 | hcd->rsrc_start = res.start; | 114 | hcd->rsrc_start = res.start; |
| 114 | hcd->rsrc_len = resource_size(&res); | 115 | hcd->rsrc_len = resource_size(&res); |
| 115 | 116 | ||
| 116 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | ||
| 117 | printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__); | ||
| 118 | rv = -EBUSY; | ||
| 119 | goto err_rmr; | ||
| 120 | } | ||
| 121 | |||
| 122 | irq = irq_of_parse_and_map(dn, 0); | 117 | irq = irq_of_parse_and_map(dn, 0); |
| 123 | if (irq == NO_IRQ) { | 118 | if (irq == NO_IRQ) { |
| 124 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); | 119 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); |
| 125 | rv = -EBUSY; | 120 | rv = -EBUSY; |
| 126 | goto err_irq; | 121 | goto err_usb; |
| 127 | } | 122 | } |
| 128 | 123 | ||
| 129 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | 124 | hcd->regs = devm_ioremap_resource(&op->dev, &res); |
| 130 | if (!hcd->regs) { | 125 | if (IS_ERR(hcd->regs)) { |
| 131 | printk(KERN_ERR "%s: ioremap failed\n", __FILE__); | 126 | rv = PTR_ERR(hcd->regs); |
| 132 | rv = -ENOMEM; | 127 | goto err_irq; |
| 133 | goto err_ioremap; | ||
| 134 | } | 128 | } |
| 135 | 129 | ||
| 136 | uhci = hcd_to_uhci(hcd); | 130 | uhci = hcd_to_uhci(hcd); |
| @@ -139,18 +133,14 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) · 2 unmodified lines | |||
| 139 | 133 | ||
| 140 | rv = usb_add_hcd(hcd, irq, 0); | 134 | rv = usb_add_hcd(hcd, irq, 0); |
| 141 | if (rv) | 135 | if (rv) |
| 142 | goto err_uhci; | 136 | goto err_irq; |
| 143 | 137 | ||
| 144 | device_wakeup_enable(hcd->self.controller); | 138 | device_wakeup_enable(hcd->self.controller); |
| 145 | return 0; | 139 | return 0; |
| 146 | 140 | ||
| 147 | err_uhci: | ||
| 148 | iounmap(hcd->regs); | ||
| 149 | err_ioremap: | ||
| 150 | irq_dispose_mapping(irq); | ||
| 151 | err_irq: | 141 | err_irq: |
| 152 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 142 | irq_dispose_mapping(irq); |
| 153 | err_rmr: | 143 | err_usb: |
| 154 | usb_put_hcd(hcd); | 144 | usb_put_hcd(hcd); |
| 155 | 145 | ||
| 156 | return rv; | 146 | return rv; |
| @@ -164,10 +154,7 @@ static int uhci_hcd_grlib_remove(struct platform_device *op) · 7 unmodified lines | |||
| 164 | 154 | ||
| 165 | usb_remove_hcd(hcd); | 155 | usb_remove_hcd(hcd); |
| 166 | 156 | ||
| 167 | iounmap(hcd->regs); | ||
| 168 | irq_dispose_mapping(hcd->irq); | 157 | irq_dispose_mapping(hcd->irq); |
| 169 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 170 | |||
| 171 | usb_put_hcd(hcd); | 158 | usb_put_hcd(hcd); |
| 172 | 159 | ||
| 173 | return 0; | 160 | return 0; |
| @@ -591,7 +591,7 @@ static int uhci_start(struct usb_hcd *hcd) · 590 unmodified lines | |||
| 591 | 591 | ||
| 592 | uhci->frame = dma_alloc_coherent(uhci_dev(uhci), | 592 | uhci->frame = dma_alloc_coherent(uhci_dev(uhci), |
| 593 | UHCI_NUMFRAMES * sizeof(*uhci->frame), | 593 | UHCI_NUMFRAMES * sizeof(*uhci->frame), |
| 594 | &uhci->frame_dma_handle, 0); | 594 | &uhci->frame_dma_handle, GFP_KERNEL); |
| 595 | if (!uhci->frame) { | 595 | if (!uhci->frame) { |
| 596 | dev_err(uhci_dev(uhci), | 596 | dev_err(uhci_dev(uhci), |
| 597 | "unable to allocate consistent memory for frame list\n"); | 597 | "unable to allocate consistent memory for frame list\n"); |
| @@ -8,6 +8,7 @@ · 7 unmodified lines | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include <linux/of.h> | 10 | #include <linux/of.h> |
| 11 | #include <linux/device.h> | ||
| 11 | #include <linux/platform_device.h> | 12 | #include <linux/platform_device.h> |
| 12 | 13 | ||
| 13 | static int uhci_platform_init(struct usb_hcd *hcd) | 14 | static int uhci_platform_init(struct usb_hcd *hcd) |
| @@ -88,33 +89,22 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev) · 74 unmodified lines | |||
| 88 | hcd->rsrc_start = res->start; | 89 | hcd->rsrc_start = res->start; |
| 89 | hcd->rsrc_len = resource_size(res); | 90 | hcd->rsrc_len = resource_size(res); |
| 90 | 91 | ||
| 91 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 92 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 92 | pr_err("%s: request_mem_region failed\n", __func__); | 93 | if (IS_ERR(hcd->regs)) { |
| 93 | ret = -EBUSY; | 94 | ret = PTR_ERR(hcd->regs); |
| 94 | goto err_rmr; | 95 | goto err_rmr; |
| 95 | } | 96 | } |
| 96 | |||
| 97 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
| 98 | if (!hcd->regs) { | ||
| 99 | pr_err("%s: ioremap failed\n", __func__); | ||
| 100 | ret = -ENOMEM; | ||
| 101 | goto err_irq; | ||
| 102 | } | ||
| 103 | uhci = hcd_to_uhci(hcd); | 97 | uhci = hcd_to_uhci(hcd); |
| 104 | 98 | ||
| 105 | uhci->regs = hcd->regs; | 99 | uhci->regs = hcd->regs; |
| 106 | 100 | ||
| 107 | ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); | 101 | ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); |
| 108 | if (ret) | 102 | if (ret) |
| 109 | goto err_uhci; | 103 | goto err_rmr; |
| 110 | 104 | ||
| 111 | device_wakeup_enable(hcd->self.controller); | 105 | device_wakeup_enable(hcd->self.controller); |
| 112 | return 0; | 106 | return 0; |
| 113 | 107 | ||
| 114 | err_uhci: | ||
| 115 | iounmap(hcd->regs); | ||
| 116 | err_irq: | ||
| 117 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 118 | err_rmr: | 108 | err_rmr: |
| 119 | usb_put_hcd(hcd); | 109 | usb_put_hcd(hcd); |
| 120 | 110 | ||
| @@ -126,8 +116,6 @@ static int uhci_hcd_platform_remove(struct platform_device *pdev) · 5 unmodified lines | |||
| 126 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 116 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 127 | 117 | ||
| 128 | usb_remove_hcd(hcd); | 118 | usb_remove_hcd(hcd); |
| 129 | iounmap(hcd->regs); | ||
| 130 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 131 | usb_put_hcd(hcd); | 119 | usb_put_hcd(hcd); |
| 132 | 120 | ||
| 133 | return 0; | 121 | return 0; |
| @@ -33,7 +33,7 @@ · 32 unmodified lines | |||
| 33 | #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400 | 33 | #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400 |
| 34 | 34 | ||
| 35 | #define PCI_VENDOR_ID_ETRON 0x1b6f | 35 | #define PCI_VENDOR_ID_ETRON 0x1b6f |
| 36 | #define PCI_DEVICE_ID_ASROCK_P67 0x7023 | 36 | #define PCI_DEVICE_ID_EJ168 0x7023 |
| 37 | 37 | ||
| 38 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 | 38 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 |
| 39 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 | 39 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 |
| @@ -140,9 +140,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · 100 unmodified lines | |||
| 140 | xhci->quirks |= XHCI_SPURIOUS_REBOOT; | 140 | xhci->quirks |= XHCI_SPURIOUS_REBOOT; |
| 141 | } | 141 | } |
| 142 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && | 142 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && |
| 143 | pdev->device == PCI_DEVICE_ID_ASROCK_P67) { | 143 | pdev->device == PCI_DEVICE_ID_EJ168) { |
| 144 | xhci->quirks |= XHCI_RESET_ON_RESUME; | 144 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 145 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; | 145 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 146 | xhci->quirks |= XHCI_BROKEN_STREAMS; | ||
| 146 | } | 147 | } |
| 147 | if (pdev->vendor == PCI_VENDOR_ID_RENESAS && | 148 | if (pdev->vendor == PCI_VENDOR_ID_RENESAS && |
| 148 | pdev->device == 0x0015) | 149 | pdev->device == 0x0015) |
| @@ -230,7 +231,8 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) · 81 unmodified lines | |||
| 230 | goto put_usb3_hcd; | 231 | goto put_usb3_hcd; |
| 231 | /* Roothub already marked as USB 3.0 speed */ | 232 | /* Roothub already marked as USB 3.0 speed */ |
| 232 | 233 | ||
| 233 | if (HCC_MAX_PSA(xhci->hcc_params) >= 4) | 234 | if (!(xhci->quirks & XHCI_BROKEN_STREAMS) && |
| 235 | HCC_MAX_PSA(xhci->hcc_params) >= 4) | ||
| 234 | xhci->shared_hcd->can_do_streams = 1; | 236 | xhci->shared_hcd->can_do_streams = 1; |
| 235 | 237 | ||
| 236 | /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */ | 238 | /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */ |
| @@ -17,9 +17,11 @@ · 16 unmodified lines | |||
| 17 | #include <linux/of.h> | 17 | #include <linux/of.h> |
| 18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
| 20 | #include <linux/usb/xhci_pdriver.h> | ||
| 20 | 21 | ||
| 21 | #include "xhci.h" | 22 | #include "xhci.h" |
| 22 | #include "xhci-mvebu.h" | 23 | #include "xhci-mvebu.h" |
| 24 | #include "xhci-rcar.h" | ||
| 23 | 25 | ||
| 24 | static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) | 26 | static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) |
| 25 | { | 27 | { |
| @@ -34,11 +36,27 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) · 8 unmodified lines | |||
| 34 | /* called during probe() after chip reset completes */ | 36 | /* called during probe() after chip reset completes */ |
| 35 | static int xhci_plat_setup(struct usb_hcd *hcd) | 37 | static int xhci_plat_setup(struct usb_hcd *hcd) |
| 36 | { | 38 | { |
| 39 | struct device_node *of_node = hcd->self.controller->of_node; | ||
| 40 | int ret; | ||
| 41 | |||
| 42 | if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") || | ||
| 43 | of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) { | ||
| 44 | ret = xhci_rcar_init_quirk(hcd); | ||
| 45 | if (ret) | ||
| 46 | return ret; | ||
| 47 | } | ||
| 48 | |||
| 37 | return xhci_gen_setup(hcd, xhci_plat_quirks); | 49 | return xhci_gen_setup(hcd, xhci_plat_quirks); |
| 38 | } | 50 | } |
| 39 | 51 | ||
| 40 | static int xhci_plat_start(struct usb_hcd *hcd) | 52 | static int xhci_plat_start(struct usb_hcd *hcd) |
| 41 | { | 53 | { |
| 54 | struct device_node *of_node = hcd->self.controller->of_node; | ||
| 55 | |||
| 56 | if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") || | ||
| 57 | of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) | ||
| 58 | xhci_rcar_start(hcd); | ||
| 59 | |||
| 42 | return xhci_run(hcd); | 60 | return xhci_run(hcd); |
| 43 | } | 61 | } |
| 44 | 62 | ||
| @@ -90,10 +108,15 @@ static const struct hc_driver xhci_plat_xhci_driver = { · 45 unmodified lines | |||
| 90 | .hub_status_data = xhci_hub_status_data, | 108 | .hub_status_data = xhci_hub_status_data, |
| 91 | .bus_suspend = xhci_bus_suspend, | 109 | .bus_suspend = xhci_bus_suspend, |
| 92 | .bus_resume = xhci_bus_resume, | 110 | .bus_resume = xhci_bus_resume, |
| 111 | |||
| 112 | .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, | ||
| 113 | .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, | ||
| 93 | }; | 114 | }; |
| 94 | 115 | ||
| 95 | static int xhci_plat_probe(struct platform_device *pdev) | 116 | static int xhci_plat_probe(struct platform_device *pdev) |
| 96 | { | 117 | { |
| 118 | struct device_node *node = pdev->dev.of_node; | ||
| 119 | struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev); | ||
| 97 | const struct hc_driver *driver; | 120 | const struct hc_driver *driver; |
| 98 | struct xhci_hcd *xhci; | 121 | struct xhci_hcd *xhci; |
| 99 | struct resource *res; | 122 | struct resource *res; |
| @@ -140,20 +163,12 @@ static int xhci_plat_probe(struct platform_device *pdev) · 40 unmodified lines | |||
| 140 | hcd->rsrc_start = res->start; | 163 | hcd->rsrc_start = res->start; |
| 141 | hcd->rsrc_len = resource_size(res); | 164 | hcd->rsrc_len = resource_size(res); |
| 142 | 165 | ||
| 143 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | 166 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 144 | driver->description)) { | 167 | if (IS_ERR(hcd->regs)) { |
| 145 | dev_dbg(&pdev->dev, "controller already in use\n"); | 168 | ret = PTR_ERR(hcd->regs); |
| 146 | ret = -EBUSY; | ||
| 147 | goto put_hcd; | 169 | goto put_hcd; |
| 148 | } | 170 | } |
| 149 | 171 | ||
| 150 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | ||
| 151 | if (!hcd->regs) { | ||
| 152 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
| 153 | ret = -EFAULT; | ||
| 154 | goto release_mem_region; | ||
| 155 | } | ||
| 156 | |||
| 157 | /* | 172 | /* |
| 158 | * Not all platforms have a clk so it is not an error if the | 173 | * Not all platforms have a clk so it is not an error if the |
| 159 | * clock does not exists. | 174 | * clock does not exists. |
| @@ -162,7 +177,7 @@ static int xhci_plat_probe(struct platform_device *pdev) · 2 unmodified lines | |||
| 162 | if (!IS_ERR(clk)) { | 177 | if (!IS_ERR(clk)) { |
| 163 | ret = clk_prepare_enable(clk); | 178 | ret = clk_prepare_enable(clk); |
| 164 | if (ret) | 179 | if (ret) |
| 165 | goto unmap_registers; | 180 | goto put_hcd; |
| 166 | } | 181 | } |
| 167 | 182 | ||
| 168 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); | 183 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| @@ -182,6 +197,9 @@ static int xhci_plat_probe(struct platform_device *pdev) · 13 unmodified lines | |||
| 182 | goto dealloc_usb2_hcd; | 197 | goto dealloc_usb2_hcd; |
| 183 | } | 198 | } |
| 184 | 199 | ||
| 200 | if ((node && of_property_read_bool(node, "usb3-lpm-capable")) || | ||
| 201 | (pdata && pdata->usb3_lpm_capable)) | ||
| 202 | xhci->quirks |= XHCI_LPM_SUPPORT; | ||
| 185 | /* | 203 | /* |
| 186 | * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset) | 204 | * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset) |
| 187 | * is called by usb_add_hcd(). | 205 | * is called by usb_add_hcd(). |
| @@ -207,12 +225,6 @@ disable_clk: · 19 unmodified lines | |||
| 207 | if (!IS_ERR(clk)) | 225 | if (!IS_ERR(clk)) |
| 208 | clk_disable_unprepare(clk); | 226 | clk_disable_unprepare(clk); |
| 209 | 227 | ||
| 210 | unmap_registers: | ||
| 211 | iounmap(hcd->regs); | ||
| 212 | |||
| 213 | release_mem_region: | ||
| 214 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 215 | |||
| 216 | put_hcd: | 228 | put_hcd: |
| 217 | usb_put_hcd(hcd); | 229 | usb_put_hcd(hcd); |
| 218 | 230 | ||
| @@ -231,8 +243,6 @@ static int xhci_plat_remove(struct platform_device *dev) · 12 unmodified lines | |||
| 231 | usb_remove_hcd(hcd); | 243 | usb_remove_hcd(hcd); |
| 232 | if (!IS_ERR(clk)) | 244 | if (!IS_ERR(clk)) |
| 233 | clk_disable_unprepare(clk); | 245 | clk_disable_unprepare(clk); |
| 234 | iounmap(hcd->regs); | ||
| 235 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 236 | usb_put_hcd(hcd); | 246 | usb_put_hcd(hcd); |
| 237 | kfree(xhci); | 247 | kfree(xhci); |
| 238 | 248 | ||
| @@ -270,6 +280,8 @@ static const struct of_device_id usb_xhci_of_match[] = { · 31 unmodified lines | |||
| 270 | { .compatible = "xhci-platform" }, | 280 | { .compatible = "xhci-platform" }, |
| 271 | { .compatible = "marvell,armada-375-xhci"}, | 281 | { .compatible = "marvell,armada-375-xhci"}, |
| 272 | { .compatible = "marvell,armada-380-xhci"}, | 282 | { .compatible = "marvell,armada-380-xhci"}, |
| 283 | { .compatible = "renesas,xhci-r8a7790"}, | ||
| 284 | { .compatible = "renesas,xhci-r8a7791"}, | ||
| 273 | { }, | 285 | { }, |
| 274 | }; | 286 | }; |
| 275 | MODULE_DEVICE_TABLE(of, usb_xhci_of_match); | 287 | MODULE_DEVICE_TABLE(of, usb_xhci_of_match); |
| @@ -0,0 +1,148 @@ | |||
| 1 | /* | ||
| 2 | * xHCI host controller driver for R-Car SoCs | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Renesas Electronics Corporation | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU General Public License | ||
| 8 | * version 2 as published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/firmware.h> | ||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/platform_device.h> | ||
| 14 | #include <linux/usb/phy.h> | ||
| 15 | |||
| 16 | #include "xhci.h" | ||
| 17 | #include "xhci-rcar.h" | ||
| 18 | |||
| 19 | #define FIRMWARE_NAME "r8a779x_usb3_v1.dlmem" | ||
| 20 | MODULE_FIRMWARE(FIRMWARE_NAME); | ||
| 21 | |||
| 22 | /*** Register Offset ***/ | ||
| 23 | #define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */ | ||
| 24 | #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */ | ||
| 25 | #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */ | ||
| 26 | |||
| 27 | #define RCAR_USB3_LCLK 0xa44 /* LCLK Select */ | ||
| 28 | #define RCAR_USB3_CONF1 0xa48 /* USB3.0 Configuration1 */ | ||
| 29 | #define RCAR_USB3_CONF2 0xa5c /* USB3.0 Configuration2 */ | ||
| 30 | #define RCAR_USB3_CONF3 0xaa8 /* USB3.0 Configuration3 */ | ||
| 31 | #define RCAR_USB3_RX_POL 0xab0 /* USB3.0 RX Polarity */ | ||
| 32 | #define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */ | ||
| 33 | |||
| 34 | /*** Register Settings ***/ | ||
| 35 | /* Interrupt Enable */ | ||
| 36 | #define RCAR_USB3_INT_XHC_ENA 0x00000001 | ||
| 37 | #define RCAR_USB3_INT_PME_ENA 0x00000002 | ||
| 38 | #define RCAR_USB3_INT_HSE_ENA 0x00000004 | ||
| 39 | #define RCAR_USB3_INT_ENA_VAL (RCAR_USB3_INT_XHC_ENA | \ | ||
| 40 | RCAR_USB3_INT_PME_ENA | RCAR_USB3_INT_HSE_ENA) | ||
| 41 | |||
| 42 | /* FW Download Control & Status */ | ||
| 43 | #define RCAR_USB3_DL_CTRL_ENABLE 0x00000001 | ||
| 44 | #define RCAR_USB3_DL_CTRL_FW_SUCCESS 0x00000010 | ||
| 45 | #define RCAR_USB3_DL_CTRL_FW_SET_DATA0 0x00000100 | ||
| 46 | |||
| 47 | /* LCLK Select */ | ||
| 48 | #define RCAR_USB3_LCLK_ENA_VAL 0x01030001 | ||
| 49 | |||
| 50 | /* USB3.0 Configuration */ | ||
| 51 | #define RCAR_USB3_CONF1_VAL 0x00030204 | ||
| 52 | #define RCAR_USB3_CONF2_VAL 0x00030300 | ||
| 53 | #define RCAR_USB3_CONF3_VAL 0x13802007 | ||
| 54 | |||
| 55 | /* USB3.0 Polarity */ | ||
| 56 | #define RCAR_USB3_RX_POL_VAL BIT(21) | ||
| 57 | #define RCAR_USB3_TX_POL_VAL BIT(4) | ||
| 58 | |||
| 59 | void xhci_rcar_start(struct usb_hcd *hcd) | ||
| 60 | { | ||
| 61 | u32 temp; | ||
| 62 | |||
| 63 | if (hcd->regs != NULL) { | ||
| 64 | /* Interrupt Enable */ | ||
| 65 | temp = readl(hcd->regs + RCAR_USB3_INT_ENA); | ||
| 66 | temp |= RCAR_USB3_INT_ENA_VAL; | ||
| 67 | writel(temp, hcd->regs + RCAR_USB3_INT_ENA); | ||
| 68 | /* LCLK Select */ | ||
| 69 | writel(RCAR_USB3_LCLK_ENA_VAL, hcd->regs + RCAR_USB3_LCLK); | ||
| 70 | /* USB3.0 Configuration */ | ||
| 71 | writel(RCAR_USB3_CONF1_VAL, hcd->regs + RCAR_USB3_CONF1); | ||
| 72 | writel(RCAR_USB3_CONF2_VAL, hcd->regs + RCAR_USB3_CONF2); | ||
| 73 | writel(RCAR_USB3_CONF3_VAL, hcd->regs + RCAR_USB3_CONF3); | ||
| 74 | /* USB3.0 Polarity */ | ||
| 75 | writel(RCAR_USB3_RX_POL_VAL, hcd->regs + RCAR_USB3_RX_POL); | ||
| 76 | writel(RCAR_USB3_TX_POL_VAL, hcd->regs + RCAR_USB3_TX_POL); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | static int xhci_rcar_download_firmware(struct device *dev, void __iomem *regs) | ||
| 81 | { | ||
| 82 | const struct firmware *fw; | ||
| 83 | int retval, index, j, time; | ||
| 84 | int timeout = 10000; | ||
| 85 | u32 data, val, temp; | ||
| 86 | |||
| 87 | /* request R-Car USB3.0 firmware */ | ||
| 88 | retval = request_firmware(&fw, FIRMWARE_NAME, dev); | ||
| 89 | if (retval) | ||
| 90 | return retval; | ||
| 91 | |||
| 92 | /* download R-Car USB3.0 firmware */ | ||
| 93 | temp = readl(regs + RCAR_USB3_DL_CTRL); | ||
| 94 | temp |= RCAR_USB3_DL_CTRL_ENABLE; | ||
| 95 | writel(temp, regs + RCAR_USB3_DL_CTRL); | ||
| 96 | |||
| 97 | for (index = 0; index < fw->size; index += 4) { | ||
| 98 | /* to avoid reading beyond the end of the buffer */ | ||
| 99 | for (data = 0, j = 3; j >= 0; j--) { | ||
| 100 | if ((j + index) < fw->size) | ||
| 101 | data |= fw->data[index + j] << (8 * j); | ||
| 102 | } | ||
| 103 | writel(data, regs + RCAR_USB3_FW_DATA0); | ||
| 104 | temp = readl(regs + RCAR_USB3_DL_CTRL); | ||
| 105 | temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0; | ||
| 106 | writel(temp, regs + RCAR_USB3_DL_CTRL); | ||
| 107 | |||
| 108 | for (time = 0; time < timeout; time++) { | ||
| 109 | val = readl(regs + RCAR_USB3_DL_CTRL); | ||
| 110 | if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0) | ||
| 111 | break; | ||
| 112 | udelay(1); | ||
| 113 | } | ||
| 114 | if (time == timeout) { | ||
| 115 | retval = -ETIMEDOUT; | ||
| 116 | break; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | temp = readl(regs + RCAR_USB3_DL_CTRL); | ||
| 121 | temp &= ~RCAR_USB3_DL_CTRL_ENABLE; | ||
| 122 | writel(temp, regs + RCAR_USB3_DL_CTRL); | ||
| 123 | |||
| 124 | for (time = 0; time < timeout; time++) { | ||
| 125 | val = readl(regs + RCAR_USB3_DL_CTRL); | ||
| 126 | if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) { | ||
| 127 | retval = 0; | ||
| 128 | break; | ||
| 129 | } | ||
| 130 | udelay(1); | ||
| 131 | } | ||
| 132 | if (time == timeout) | ||
| 133 | retval = -ETIMEDOUT; | ||
| 134 | |||
| 135 | release_firmware(fw); | ||
| 136 | |||
| 137 | return retval; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* This function needs to initialize a "phy" of usb before */ | ||
| 141 | int xhci_rcar_init_quirk(struct usb_hcd *hcd) | ||
| 142 | { | ||
| 143 | /* If hcd->regs is NULL, we don't just call the following function */ | ||
| 144 | if (!hcd->regs) | ||
| 145 | return 0; | ||
| 146 | |||
| 147 | return xhci_rcar_download_firmware(hcd->self.controller, hcd->regs); | ||
| 148 | } | ||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* | ||
| 2 | * drivers/usb/host/xhci-rcar.h | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Renesas Electronics Corporation | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU General Public License | ||
| 8 | * version 2 as published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef _XHCI_RCAR_H | ||
| 12 | #define _XHCI_RCAR_H | ||
| 13 | |||
| 14 | #if IS_ENABLED(CONFIG_USB_XHCI_RCAR) | ||
| 15 | void xhci_rcar_start(struct usb_hcd *hcd); | ||
| 16 | int xhci_rcar_init_quirk(struct usb_hcd *hcd); | ||
| 17 | #else | ||
| 18 | static inline void xhci_rcar_start(struct usb_hcd *hcd) | ||
| 19 | { | ||
| 20 | } | ||
| 21 | |||
| 22 | static inline int xhci_rcar_init_quirk(struct usb_hcd *hcd) | ||
| 23 | { | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | #endif /* _XHCI_RCAR_H */ | ||
| @@ -1118,6 +1118,10 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, · 1117 unmodified lines | |||
| 1118 | if (xhci->quirks & XHCI_RESET_EP_QUIRK) { | 1118 | if (xhci->quirks & XHCI_RESET_EP_QUIRK) { |
| 1119 | struct xhci_command *command; | 1119 | struct xhci_command *command; |
| 1120 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | 1120 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); |
| 1121 | if (!command) { | ||
| 1122 | xhci_warn(xhci, "WARN Cannot submit cfg ep: ENOMEM\n"); | ||
| 1123 | return; | ||
| 1124 | } | ||
| 1121 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | 1125 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
| 1122 | "Queueing configure endpoint command"); | 1126 | "Queueing configure endpoint command"); |
| 1123 | xhci_queue_configure_endpoint(xhci, command, | 1127 | xhci_queue_configure_endpoint(xhci, command, |
| @@ -1553,6 +1553,10 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) · 1552 unmodified lines | |||
| 1553 | */ | 1553 | */ |
| 1554 | if (!(ep->ep_state & EP_HALT_PENDING)) { | 1554 | if (!(ep->ep_state & EP_HALT_PENDING)) { |
| 1555 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | 1555 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); |
| 1556 | if (!command) { | ||
| 1557 | ret = -ENOMEM; | ||
| 1558 | goto done; | ||
| 1559 | } | ||
| 1556 | ep->ep_state |= EP_HALT_PENDING; | 1560 | ep->ep_state |= EP_HALT_PENDING; |
| 1557 | ep->stop_cmds_pending++; | 1561 | ep->stop_cmds_pending++; |
| 1558 | ep->stop_cmd_timer.expires = jiffies + | 1562 | ep->stop_cmd_timer.expires = jiffies + |
| @@ -1586,12 +1590,10 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 27 unmodified lines | |||
| 1586 | struct xhci_hcd *xhci; | 1590 | struct xhci_hcd *xhci; |
| 1587 | struct xhci_container_ctx *in_ctx, *out_ctx; | 1591 | struct xhci_container_ctx *in_ctx, *out_ctx; |
| 1588 | struct xhci_input_control_ctx *ctrl_ctx; | 1592 | struct xhci_input_control_ctx *ctrl_ctx; |
| 1589 | struct xhci_slot_ctx *slot_ctx; | ||
| 1590 | unsigned int last_ctx; | ||
| 1591 | unsigned int ep_index; | 1593 | unsigned int ep_index; |
| 1592 | struct xhci_ep_ctx *ep_ctx; | 1594 | struct xhci_ep_ctx *ep_ctx; |
| 1593 | u32 drop_flag; | 1595 | u32 drop_flag; |
| 1594 | u32 new_add_flags, new_drop_flags, new_slot_info; | 1596 | u32 new_add_flags, new_drop_flags; |
| 1595 | int ret; | 1597 | int ret; |
| 1596 | 1598 | ||
| 1597 | ret = xhci_check_args(hcd, udev, ep, 1, true, __func__); | 1599 | ret = xhci_check_args(hcd, udev, ep, 1, true, __func__); |
| @@ -1638,24 +1640,13 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 40 unmodified lines | |||
| 1638 | ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); | 1640 | ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); |
| 1639 | new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); | 1641 | new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); |
| 1640 | 1642 | ||
| 1641 | last_ctx = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)); | ||
| 1642 | slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); | ||
| 1643 | /* Update the last valid endpoint context, if we deleted the last one */ | ||
| 1644 | if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) > | ||
| 1645 | LAST_CTX(last_ctx)) { | ||
| 1646 | slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); | ||
| 1647 | slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx)); | ||
| 1648 | } | ||
| 1649 | new_slot_info = le32_to_cpu(slot_ctx->dev_info); | ||
| 1650 | |||
| 1651 | xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); | 1643 | xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); |
| 1652 | 1644 | ||
| 1653 | xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", | 1645 | xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", |
| 1654 | (unsigned int) ep->desc.bEndpointAddress, | 1646 | (unsigned int) ep->desc.bEndpointAddress, |
| 1655 | udev->slot_id, | 1647 | udev->slot_id, |
| 1656 | (unsigned int) new_drop_flags, | 1648 | (unsigned int) new_drop_flags, |
| 1657 | (unsigned int) new_add_flags, | 1649 | (unsigned int) new_add_flags); |
| 1658 | (unsigned int) new_slot_info); | ||
| 1659 | return 0; | 1650 | return 0; |
| 1660 | } | 1651 | } |
| 1661 | 1652 | ||
| @@ -1678,11 +1669,9 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 16 unmodified lines | |||
| 1678 | struct xhci_hcd *xhci; | 1669 | struct xhci_hcd *xhci; |
| 1679 | struct xhci_container_ctx *in_ctx, *out_ctx; | 1670 | struct xhci_container_ctx *in_ctx, *out_ctx; |
| 1680 | unsigned int ep_index; | 1671 | unsigned int ep_index; |
| 1681 | struct xhci_slot_ctx *slot_ctx; | ||
| 1682 | struct xhci_input_control_ctx *ctrl_ctx; | 1672 | struct xhci_input_control_ctx *ctrl_ctx; |
| 1683 | u32 added_ctxs; | 1673 | u32 added_ctxs; |
| 1684 | unsigned int last_ctx; | 1674 | u32 new_add_flags, new_drop_flags; |
| 1685 | u32 new_add_flags, new_drop_flags, new_slot_info; | ||
| 1686 | struct xhci_virt_device *virt_dev; | 1675 | struct xhci_virt_device *virt_dev; |
| 1687 | int ret = 0; | 1676 | int ret = 0; |
| 1688 | 1677 | ||
| @@ -1697,7 +1686,6 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 8 unmodified lines | |||
| 1697 | return -ENODEV; | 1686 | return -ENODEV; |
| 1698 | 1687 | ||
| 1699 | added_ctxs = xhci_get_endpoint_flag(&ep->desc); | 1688 | added_ctxs = xhci_get_endpoint_flag(&ep->desc); |
| 1700 | last_ctx = xhci_last_valid_endpoint(added_ctxs); | ||
| 1701 | if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) { | 1689 | if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) { |
| 1702 | /* FIXME when we have to issue an evaluate endpoint command to | 1690 | /* FIXME when we have to issue an evaluate endpoint command to |
| 1703 | * deal with ep0 max packet size changing once we get the | 1691 | * deal with ep0 max packet size changing once we get the |
| @@ -1763,24 +1751,14 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 59 unmodified lines | |||
| 1763 | */ | 1751 | */ |
| 1764 | new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); | 1752 | new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); |
| 1765 | 1753 | ||
| 1766 | slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); | ||
| 1767 | /* Update the last valid endpoint context, if we just added one past */ | ||
| 1768 | if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) < | ||
| 1769 | LAST_CTX(last_ctx)) { | ||
| 1770 | slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); | ||
| 1771 | slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx)); | ||
| 1772 | } | ||
| 1773 | new_slot_info = le32_to_cpu(slot_ctx->dev_info); | ||
| 1774 | |||
| 1775 | /* Store the usb_device pointer for later use */ | 1754 | /* Store the usb_device pointer for later use */ |
| 1776 | ep->hcpriv = udev; | 1755 | ep->hcpriv = udev; |
| 1777 | 1756 | ||
| 1778 | xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", | 1757 | xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", |
| 1779 | (unsigned int) ep->desc.bEndpointAddress, | 1758 | (unsigned int) ep->desc.bEndpointAddress, |
| 1780 | udev->slot_id, | 1759 | udev->slot_id, |
| 1781 | (unsigned int) new_drop_flags, | 1760 | (unsigned int) new_drop_flags, |
| 1782 | (unsigned int) new_add_flags, | 1761 | (unsigned int) new_add_flags); |
| 1783 | (unsigned int) new_slot_info); | ||
| 1784 | return 0; | 1762 | return 0; |
| 1785 | } | 1763 | } |
| 1786 | 1764 | ||
| @@ -1830,15 +1808,15 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, · 43 unmodified lines | |||
| 1830 | ret = -ETIME; | 1808 | ret = -ETIME; |
| 1831 | break; | 1809 | break; |
| 1832 | case COMP_ENOMEM: | 1810 | case COMP_ENOMEM: |
| 1833 | dev_warn(&udev->dev, "Not enough host controller resources " | 1811 | dev_warn(&udev->dev, |
| 1834 | "for new device state.\n"); | 1812 | "Not enough host controller resources for new device state.\n"); |
| 1835 | ret = -ENOMEM; | 1813 | ret = -ENOMEM; |
| 1836 | /* FIXME: can we allocate more resources for the HC? */ | 1814 | /* FIXME: can we allocate more resources for the HC? */ |
| 1837 | break; | 1815 | break; |
| 1838 | case COMP_BW_ERR: | 1816 | case COMP_BW_ERR: |
| 1839 | case COMP_2ND_BW_ERR: | 1817 | case COMP_2ND_BW_ERR: |
| 1840 | dev_warn(&udev->dev, "Not enough bandwidth " | 1818 | dev_warn(&udev->dev, |
| 1841 | "for new device state.\n"); | 1819 | "Not enough bandwidth for new device state.\n"); |
| 1842 | ret = -ENOSPC; | 1820 | ret = -ENOSPC; |
| 1843 | /* FIXME: can we go back to the old state? */ | 1821 | /* FIXME: can we go back to the old state? */ |
| 1844 | break; | 1822 | break; |
| @@ -1850,8 +1828,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, · 5 unmodified lines | |||
| 1850 | ret = -EINVAL; | 1828 | ret = -EINVAL; |
| 1851 | break; | 1829 | break; |
| 1852 | case COMP_DEV_ERR: | 1830 | case COMP_DEV_ERR: |
| 1853 | dev_warn(&udev->dev, "ERROR: Incompatible device for endpoint " | 1831 | dev_warn(&udev->dev, |
| 1854 | "configure command.\n"); | 1832 | "ERROR: Incompatible device for endpoint configure command.\n"); |
| 1855 | ret = -ENODEV; | 1833 | ret = -ENODEV; |
| 1856 | break; | 1834 | break; |
| 1857 | case COMP_SUCCESS: | 1835 | case COMP_SUCCESS: |
| @@ -1860,8 +1838,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, · 2 unmodified lines | |||
| 1860 | ret = 0; | 1838 | ret = 0; |
| 1861 | break; | 1839 | break; |
| 1862 | default: | 1840 | default: |
| 1863 | xhci_err(xhci, "ERROR: unexpected command completion " | 1841 | xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", |
| 1864 | "code 0x%x.\n", *cmd_status); | 1842 | *cmd_status); |
| 1865 | ret = -EINVAL; | 1843 | ret = -EINVAL; |
| 1866 | break; | 1844 | break; |
| 1867 | } | 1845 | } |
| @@ -1881,24 +1859,24 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci, · 13 unmodified lines | |||
| 1881 | ret = -ETIME; | 1859 | ret = -ETIME; |
| 1882 | break; | 1860 | break; |
| 1883 | case COMP_EINVAL: | 1861 | case COMP_EINVAL: |
| 1884 | dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate " | 1862 | dev_warn(&udev->dev, |
| 1885 | "context command.\n"); | 1863 | "WARN: xHCI driver setup invalid evaluate context command.\n"); |
| 1886 | ret = -EINVAL; | 1864 | ret = -EINVAL; |
| 1887 | break; | 1865 | break; |
| 1888 | case COMP_EBADSLT: | 1866 | case COMP_EBADSLT: |
| 1889 | dev_warn(&udev->dev, "WARN: slot not enabled for" | 1867 | dev_warn(&udev->dev, |
| 1890 | "evaluate context command.\n"); | 1868 | "WARN: slot not enabled for evaluate context command.\n"); |
| 1891 | ret = -EINVAL; | 1869 | ret = -EINVAL; |
| 1892 | break; | 1870 | break; |
| 1893 | case COMP_CTX_STATE: | 1871 | case COMP_CTX_STATE: |
| 1894 | dev_warn(&udev->dev, "WARN: invalid context state for " | 1872 | dev_warn(&udev->dev, |
| 1895 | "evaluate context command.\n"); | 1873 | "WARN: invalid context state for evaluate context command.\n"); |
| 1896 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1); | 1874 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1); |
| 1897 | ret = -EINVAL; | 1875 | ret = -EINVAL; |
| 1898 | break; | 1876 | break; |
| 1899 | case COMP_DEV_ERR: | 1877 | case COMP_DEV_ERR: |
| 1900 | dev_warn(&udev->dev, "ERROR: Incompatible device for evaluate " | 1878 | dev_warn(&udev->dev, |
| 1901 | "context command.\n"); | 1879 | "ERROR: Incompatible device for evaluate context command.\n"); |
| 1902 | ret = -ENODEV; | 1880 | ret = -ENODEV; |
| 1903 | break; | 1881 | break; |
| 1904 | case COMP_MEL_ERR: | 1882 | case COMP_MEL_ERR: |
| @@ -1912,8 +1890,8 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci, · 7 unmodified lines | |||
| 1912 | ret = 0; | 1890 | ret = 0; |
| 1913 | break; | 1891 | break; |
| 1914 | default: | 1892 | default: |
| 1915 | xhci_err(xhci, "ERROR: unexpected command completion " | 1893 | xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", |
| 1916 | "code 0x%x.\n", *cmd_status); | 1894 | *cmd_status); |
| 1917 | ret = -EINVAL; | 1895 | ret = -EINVAL; |
| 1918 | break; | 1896 | break; |
| 1919 | } | 1897 | } |
| @@ -2750,8 +2728,19 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) · 830 unmodified lines | |||
| 2750 | ret = 0; | 2728 | ret = 0; |
| 2751 | goto command_cleanup; | 2729 | goto command_cleanup; |
| 2752 | } | 2730 | } |
| 2753 | xhci_dbg(xhci, "New Input Control Context:\n"); | 2731 | /* Fix up Context Entries field. Minimum value is EP0 == BIT(1). */ |
| 2754 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); | 2732 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); |
| 2733 | for (i = 31; i >= 1; i--) { | ||
| 2734 | __le32 le32 = cpu_to_le32(BIT(i)); | ||
| 2735 | |||
| 2736 | if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) | ||
| 2737 | || (ctrl_ctx->add_flags & le32) || i == 1) { | ||
| 2738 | slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); | ||
| 2739 | slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); | ||
| 2740 | break; | ||
| 2741 | } | ||
| 2742 | } | ||
| 2743 | xhci_dbg(xhci, "New Input Control Context:\n"); | ||
| 2755 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, | 2744 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, |
| 2756 | LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info))); | 2745 | LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info))); |
| 2757 | 2746 | ||
| @@ -3163,7 +3152,8 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, · 405 unmodified lines | |||
| 3163 | num_streams); | 3152 | num_streams); |
| 3164 | 3153 | ||
| 3165 | /* MaxPSASize value 0 (2 streams) means streams are not supported */ | 3154 | /* MaxPSASize value 0 (2 streams) means streams are not supported */ |
| 3166 | if (HCC_MAX_PSA(xhci->hcc_params) < 4) { | 3155 | if ((xhci->quirks & XHCI_BROKEN_STREAMS) || |
| 3156 | HCC_MAX_PSA(xhci->hcc_params) < 4) { | ||
| 3167 | xhci_dbg(xhci, "xHCI controller does not support streams.\n"); | 3157 | xhci_dbg(xhci, "xHCI controller does not support streams.\n"); |
| 3168 | return -ENOSYS; | 3158 | return -ENOSYS; |
| 3169 | } | 3159 | } |
| @@ -4303,8 +4293,7 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev, · 1133 unmodified lines | |||
| 4303 | return USB3_LPM_DISABLED; | 4293 | return USB3_LPM_DISABLED; |
| 4304 | } | 4294 | } |
| 4305 | 4295 | ||
| 4306 | /* Returns the hub-encoded U1 timeout value. | 4296 | /* The U1 timeout should be the maximum of the following values: |
| 4307 | * The U1 timeout should be the maximum of the following values: | ||
| 4308 | * - For control endpoints, U1 system exit latency (SEL) * 3 | 4297 | * - For control endpoints, U1 system exit latency (SEL) * 3 |
| 4309 | * - For bulk endpoints, U1 SEL * 5 | 4298 | * - For bulk endpoints, U1 SEL * 5 |
| 4310 | * - For interrupt endpoints: | 4299 | * - For interrupt endpoints: |
| @@ -4312,7 +4301,8 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev, · 1 unmodified line | |||
| 4312 | * - Periodic EPs, max(105% of bInterval, U1 SEL * 2) | 4301 | * - Periodic EPs, max(105% of bInterval, U1 SEL * 2) |
| 4313 | * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2) | 4302 | * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2) |
| 4314 | */ | 4303 | */ |
| 4315 | static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev, | 4304 | static unsigned long long xhci_calculate_intel_u1_timeout( |
| 4305 | struct usb_device *udev, | ||
| 4316 | struct usb_endpoint_descriptor *desc) | 4306 | struct usb_endpoint_descriptor *desc) |
| 4317 | { | 4307 | { |
| 4318 | unsigned long long timeout_ns; | 4308 | unsigned long long timeout_ns; |
| @@ -4344,11 +4334,28 @@ static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev, · 25 unmodified lines | |||
| 4344 | return 0; | 4334 | return 0; |
| 4345 | } | 4335 | } |
| 4346 | 4336 | ||
| 4347 | /* The U1 timeout is encoded in 1us intervals. */ | 4337 | return timeout_ns; |
| 4348 | timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000); | 4338 | } |
| 4349 | /* Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */ | 4339 | |
| 4340 | /* Returns the hub-encoded U1 timeout value. */ | ||
| 4341 | static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, | ||
| 4342 | struct usb_device *udev, | ||
| 4343 | struct usb_endpoint_descriptor *desc) | ||
| 4344 | { | ||
| 4345 | unsigned long long timeout_ns; | ||
| 4346 | |||
| 4347 | if (xhci->quirks & XHCI_INTEL_HOST) | ||
| 4348 | timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc); | ||
| 4349 | else | ||
| 4350 | timeout_ns = udev->u1_params.sel; | ||
| 4351 | |||
| 4352 | /* The U1 timeout is encoded in 1us intervals. | ||
| 4353 | * Don't return a timeout of zero, because that's USB3_LPM_DISABLED. | ||
| 4354 | */ | ||
| 4350 | if (timeout_ns == USB3_LPM_DISABLED) | 4355 | if (timeout_ns == USB3_LPM_DISABLED) |
| 4351 | timeout_ns++; | 4356 | timeout_ns = 1; |
| 4357 | else | ||
| 4358 | timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000); | ||
| 4352 | 4359 | ||
| 4353 | /* If the necessary timeout value is bigger than what we can set in the | 4360 | /* If the necessary timeout value is bigger than what we can set in the |
| 4354 | * USB 3.0 hub, we have to disable hub-initiated U1. | 4361 | * USB 3.0 hub, we have to disable hub-initiated U1. |
| @@ -4360,14 +4367,14 @@ static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev, · 5 unmodified lines | |||
| 4360 | return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1); | 4367 | return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1); |
| 4361 | } | 4368 | } |
| 4362 | 4369 | ||
| 4363 | /* Returns the hub-encoded U2 timeout value. | 4370 | /* The U2 timeout should be the maximum of: |
| 4364 | * The U2 timeout should be the maximum of: | ||
| 4365 | * - 10 ms (to avoid the bandwidth impact on the scheduler) | 4371 | * - 10 ms (to avoid the bandwidth impact on the scheduler) |
| 4366 | * - largest bInterval of any active periodic endpoint (to avoid going | 4372 | * - largest bInterval of any active periodic endpoint (to avoid going |
| 4367 | * into lower power link states between intervals). | 4373 | * into lower power link states between intervals). |
| 4368 | * - the U2 Exit Latency of the device | 4374 | * - the U2 Exit Latency of the device |
| 4369 | */ | 4375 | */ |
| 4370 | static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev, | 4376 | static unsigned long long xhci_calculate_intel_u2_timeout( |
| 4377 | struct usb_device *udev, | ||
| 4371 | struct usb_endpoint_descriptor *desc) | 4378 | struct usb_endpoint_descriptor *desc) |
| 4372 | { | 4379 | { |
| 4373 | unsigned long long timeout_ns; | 4380 | unsigned long long timeout_ns; |
| @@ -4383,6 +4390,21 @@ static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev, · 9 unmodified lines | |||
| 4383 | if (u2_del_ns > timeout_ns) | 4390 | if (u2_del_ns > timeout_ns) |
| 4384 | timeout_ns = u2_del_ns; | 4391 | timeout_ns = u2_del_ns; |
| 4385 | 4392 | ||
| 4393 | return timeout_ns; | ||
| 4394 | } | ||
| 4395 | |||
| 4396 | /* Returns the hub-encoded U2 timeout value. */ | ||
| 4397 | static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, | ||
| 4398 | struct usb_device *udev, | ||
| 4399 | struct usb_endpoint_descriptor *desc) | ||
| 4400 | { | ||
| 4401 | unsigned long long timeout_ns; | ||
| 4402 | |||
| 4403 | if (xhci->quirks & XHCI_INTEL_HOST) | ||
| 4404 | timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc); | ||
| 4405 | else | ||
| 4406 | timeout_ns = udev->u2_params.sel; | ||
| 4407 | |||
| 4386 | /* The U2 timeout is encoded in 256us intervals */ | 4408 | /* The U2 timeout is encoded in 256us intervals */ |
| 4387 | timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000); | 4409 | timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000); |
| 4388 | /* If the necessary timeout value is bigger than what we can set in the | 4410 | /* If the necessary timeout value is bigger than what we can set in the |
| @@ -4401,13 +4423,10 @@ static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, · 12 unmodified lines | |||
| 4401 | enum usb3_link_state state, | 4423 | enum usb3_link_state state, |
| 4402 | u16 *timeout) | 4424 | u16 *timeout) |
| 4403 | { | 4425 | { |
| 4404 | if (state == USB3_LPM_U1) { | 4426 | if (state == USB3_LPM_U1) |
| 4405 | if (xhci->quirks & XHCI_INTEL_HOST) | 4427 | return xhci_calculate_u1_timeout(xhci, udev, desc); |
| 4406 | return xhci_calculate_intel_u1_timeout(udev, desc); | 4428 | else if (state == USB3_LPM_U2) |
| 4407 | } else { | 4429 | return xhci_calculate_u2_timeout(xhci, udev, desc); |
| 4408 | if (xhci->quirks & XHCI_INTEL_HOST) | ||
| 4409 | return xhci_calculate_intel_u2_timeout(udev, desc); | ||
| 4410 | } | ||
| 4411 | 4430 | ||
| 4412 | return USB3_LPM_DISABLED; | 4431 | return USB3_LPM_DISABLED; |
| 4413 | } | 4432 | } |
| @@ -4484,7 +4503,8 @@ static int xhci_check_tier_policy(struct xhci_hcd *xhci, · 70 unmodified lines | |||
| 4484 | { | 4503 | { |
| 4485 | if (xhci->quirks & XHCI_INTEL_HOST) | 4504 | if (xhci->quirks & XHCI_INTEL_HOST) |
| 4486 | return xhci_check_intel_tier_policy(udev, state); | 4505 | return xhci_check_intel_tier_policy(udev, state); |
| 4487 | return -EINVAL; | 4506 | else |
| 4507 | return 0; | ||
| 4488 | } | 4508 | } |
| 4489 | 4509 | ||
| 4490 | /* Returns the U1 or U2 timeout that should be enabled. | 4510 | /* Returns the U1 or U2 timeout that should be enabled. |
| @@ -1558,6 +1558,8 @@ struct xhci_hcd { · 1557 unmodified lines | |||
| 1558 | #define XHCI_PLAT (1 << 16) | 1558 | #define XHCI_PLAT (1 << 16) |
| 1559 | #define XHCI_SLOW_SUSPEND (1 << 17) | 1559 | #define XHCI_SLOW_SUSPEND (1 << 17) |
| 1560 | #define XHCI_SPURIOUS_WAKEUP (1 << 18) | 1560 | #define XHCI_SPURIOUS_WAKEUP (1 << 18) |
| 1561 | /* For controllers with a broken beyond repair streams implementation */ | ||
| 1562 | #define XHCI_BROKEN_STREAMS (1 << 19) | ||
| 1561 | unsigned int num_active_eps; | 1563 | unsigned int num_active_eps; |
| 1562 | unsigned int limit_active_eps; | 1564 | unsigned int limit_active_eps; |
| 1563 | /* There are two roothubs to keep track of bus suspend info for */ | 1565 | /* There are two roothubs to keep track of bus suspend info for */ |
| @@ -248,3 +248,10 @@ config USB_HSIC_USB3503 · 247 unmodified lines | |||
| 248 | select REGMAP_I2C | 248 | select REGMAP_I2C |
| 249 | help | 249 | help |
| 250 | This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver. | 250 | This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver. |
| 251 | |||
| 252 | config USB_LINK_LAYER_TEST | ||
| 253 | tristate "USB Link Layer Test driver" | ||
| 254 | help | ||
| 255 | This driver is for generating specific traffic for Super Speed Link | ||
| 256 | Layer Test Device. Say Y only when you want to conduct USB Super Speed | ||
| 257 | Link Layer Test for host controllers. | ||
| @@ -27,3 +27,4 @@ obj-$(CONFIG_USB_YUREX) += yurex.o · 26 unmodified lines | |||
| 27 | obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o | 27 | obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o |
| 28 | 28 | ||
| 29 | obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ | 29 | obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ |
| 30 | obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o | ||
| @@ -0,0 +1,460 @@ | |||
| 1 | /* | ||
| 2 | * drivers/usb/misc/lvstest.c | ||
| 3 | * | ||
| 4 | * Test pattern generation for Link Layer Validation System Tests | ||
| 5 | * | ||
| 6 | * Copyright (C) 2014 ST Microelectronics | ||
| 7 | * Pratyush Anand <pratyush.anand@st.com> | ||
| 8 | * | ||
| 9 | * This file is licensed under the terms of the GNU General Public | ||
| 10 | * License version 2. This program is licensed "as is" without any | ||
| 11 | * warranty of any kind, whether express or implied. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/init.h> | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/platform_device.h> | ||
| 18 | #include <linux/slab.h> | ||
| 19 | #include <linux/usb.h> | ||
| 20 | #include <linux/usb/ch11.h> | ||
| 21 | #include <linux/usb/hcd.h> | ||
| 22 | #include <linux/usb/phy.h> | ||
| 23 | |||
| 24 | struct lvs_rh { | ||
| 25 | /* root hub interface */ | ||
| 26 | struct usb_interface *intf; | ||
| 27 | /* if lvs device connected */ | ||
| 28 | bool present; | ||
| 29 | /* port no at which lvs device is present */ | ||
| 30 | int portnum; | ||
| 31 | /* urb buffer */ | ||
| 32 | u8 buffer[8]; | ||
| 33 | /* class descriptor */ | ||
| 34 | struct usb_hub_descriptor descriptor; | ||
| 35 | /* urb for polling interrupt pipe */ | ||
| 36 | struct urb *urb; | ||
| 37 | /* LVS RH work queue */ | ||
| 38 | struct workqueue_struct *rh_queue; | ||
| 39 | /* LVH RH work */ | ||
| 40 | struct work_struct rh_work; | ||
| 41 | /* RH port status */ | ||
| 42 | struct usb_port_status port_status; | ||
| 43 | }; | ||
| 44 | |||
| 45 | static struct usb_device *create_lvs_device(struct usb_interface *intf) | ||
| 46 | { | ||
| 47 | struct usb_device *udev, *hdev; | ||
| 48 | struct usb_hcd *hcd; | ||
| 49 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 50 | |||
| 51 | if (!lvs->present) { | ||
| 52 | dev_err(&intf->dev, "No LVS device is present\n"); | ||
| 53 | return NULL; | ||
| 54 | } | ||
| 55 | |||
| 56 | hdev = interface_to_usbdev(intf); | ||
| 57 | hcd = bus_to_hcd(hdev->bus); | ||
| 58 | |||
| 59 | udev = usb_alloc_dev(hdev, hdev->bus, lvs->portnum); | ||
| 60 | if (!udev) { | ||
| 61 | dev_err(&intf->dev, "Could not allocate lvs udev\n"); | ||
| 62 | return NULL; | ||
| 63 | } | ||
| 64 | udev->speed = USB_SPEED_SUPER; | ||
| 65 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); | ||
| 66 | usb_set_device_state(udev, USB_STATE_DEFAULT); | ||
| 67 | |||
| 68 | if (hcd->driver->enable_device) { | ||
| 69 | if (hcd->driver->enable_device(hcd, udev) < 0) { | ||
| 70 | dev_err(&intf->dev, "Failed to enable\n"); | ||
| 71 | usb_put_dev(udev); | ||
| 72 | return NULL; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | return udev; | ||
| 77 | } | ||
| 78 | |||
| 79 | static void destroy_lvs_device(struct usb_device *udev) | ||
| 80 | { | ||
| 81 | struct usb_device *hdev = udev->parent; | ||
| 82 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | ||
| 83 | |||
| 84 | if (hcd->driver->free_dev) | ||
| 85 | hcd->driver->free_dev(hcd, udev); | ||
| 86 | |||
| 87 | usb_put_dev(udev); | ||
| 88 | } | ||
| 89 | |||
| 90 | static int lvs_rh_clear_port_feature(struct usb_device *hdev, | ||
| 91 | int port1, int feature) | ||
| 92 | { | ||
| 93 | return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), | ||
| 94 | USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port1, | ||
| 95 | NULL, 0, 1000); | ||
| 96 | } | ||
| 97 | |||
| 98 | static int lvs_rh_set_port_feature(struct usb_device *hdev, | ||
| 99 | int port1, int feature) | ||
| 100 | { | ||
| 101 | return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), | ||
| 102 | USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port1, | ||
| 103 | NULL, 0, 1000); | ||
| 104 | } | ||
| 105 | |||
| 106 | static ssize_t u3_entry_store(struct device *dev, | ||
| 107 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 108 | { | ||
| 109 | struct usb_interface *intf = to_usb_interface(dev); | ||
| 110 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
| 111 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 112 | struct usb_device *udev; | ||
| 113 | int ret; | ||
| 114 | |||
| 115 | udev = create_lvs_device(intf); | ||
| 116 | if (!udev) { | ||
| 117 | dev_err(dev, "failed to create lvs device\n"); | ||
| 118 | return -ENOMEM; | ||
| 119 | } | ||
| 120 | |||
| 121 | ret = lvs_rh_set_port_feature(hdev, lvs->portnum, | ||
| 122 | USB_PORT_FEAT_SUSPEND); | ||
| 123 | if (ret < 0) | ||
| 124 | dev_err(dev, "can't issue U3 entry %d\n", ret); | ||
| 125 | |||
| 126 | destroy_lvs_device(udev); | ||
| 127 | |||
| 128 | if (ret < 0) | ||
| 129 | return ret; | ||
| 130 | |||
| 131 | return count; | ||
| 132 | } | ||
| 133 | static DEVICE_ATTR_WO(u3_entry); | ||
| 134 | |||
| 135 | static ssize_t u3_exit_store(struct device *dev, | ||
| 136 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 137 | { | ||
| 138 | struct usb_interface *intf = to_usb_interface(dev); | ||
| 139 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
| 140 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 141 | struct usb_device *udev; | ||
| 142 | int ret; | ||
| 143 | |||
| 144 | udev = create_lvs_device(intf); | ||
| 145 | if (!udev) { | ||
| 146 | dev_err(dev, "failed to create lvs device\n"); | ||
| 147 | return -ENOMEM; | ||
| 148 | } | ||
| 149 | |||
| 150 | ret = lvs_rh_clear_port_feature(hdev, lvs->portnum, | ||
| 151 | USB_PORT_FEAT_SUSPEND); | ||
| 152 | if (ret < 0) | ||
| 153 | dev_err(dev, "can't issue U3 exit %d\n", ret); | ||
| 154 | |||
| 155 | destroy_lvs_device(udev); | ||
| 156 | |||
| 157 | if (ret < 0) | ||
| 158 | return ret; | ||
| 159 | |||
| 160 | return count; | ||
| 161 | } | ||
| 162 | static DEVICE_ATTR_WO(u3_exit); | ||
| 163 | |||
| 164 | static ssize_t hot_reset_store(struct device *dev, | ||
| 165 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 166 | { | ||
| 167 | struct usb_interface *intf = to_usb_interface(dev); | ||
| 168 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
| 169 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 170 | int ret; | ||
| 171 | |||
| 172 | ret = lvs_rh_set_port_feature(hdev, lvs->portnum, | ||
| 173 | USB_PORT_FEAT_RESET); | ||
| 174 | if (ret < 0) { | ||
| 175 | dev_err(dev, "can't issue hot reset %d\n", ret); | ||
| 176 | return ret; | ||
| 177 | } | ||
| 178 | |||
| 179 | return count; | ||
| 180 | } | ||
| 181 | static DEVICE_ATTR_WO(hot_reset); | ||
| 182 | |||
| 183 | static ssize_t u2_timeout_store(struct device *dev, | ||
| 184 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 185 | { | ||
| 186 | struct usb_interface *intf = to_usb_interface(dev); | ||
| 187 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
| 188 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 189 | unsigned long val; | ||
| 190 | int ret; | ||
| 191 | |||
| 192 | ret = kstrtoul(buf, 10, &val); | ||
| 193 | if (ret < 0) { | ||
| 194 | dev_err(dev, "couldn't parse string %d\n", ret); | ||
| 195 | return ret; | ||
| 196 | } | ||
| 197 | |||
| 198 | if (val < 0 || val > 127) | ||
| 199 | return -EINVAL; | ||
| 200 | |||
| 201 | ret = lvs_rh_set_port_feature(hdev, lvs->portnum | (val << 8), | ||
| 202 | USB_PORT_FEAT_U2_TIMEOUT); | ||
| 203 | if (ret < 0) { | ||
| 204 | dev_err(dev, "Error %d while setting U2 timeout %ld\n", ret, val); | ||
| 205 | return ret; | ||
| 206 | } | ||
| 207 | |||
| 208 | return count; | ||
| 209 | } | ||
| 210 | static DEVICE_ATTR_WO(u2_timeout); | ||
| 211 | |||
| 212 | static ssize_t u1_timeout_store(struct device *dev, | ||
| 213 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 214 | { | ||
| 215 | struct usb_interface *intf = to_usb_interface(dev); | ||
| 216 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
| 217 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 218 | unsigned long val; | ||
| 219 | int ret; | ||
| 220 | |||
| 221 | ret = kstrtoul(buf, 10, &val); | ||
| 222 | if (ret < 0) { | ||
| 223 | dev_err(dev, "couldn't parse string %d\n", ret); | ||
| 224 | return ret; | ||
| 225 | } | ||
| 226 | |||
| 227 | if (val < 0 || val > 127) | ||
| 228 | return -EINVAL; | ||
| 229 | |||
| 230 | ret = lvs_rh_set_port_feature(hdev, lvs->portnum | (val << 8), | ||
| 231 | USB_PORT_FEAT_U1_TIMEOUT); | ||
| 232 | if (ret < 0) { | ||
| 233 | dev_err(dev, "Error %d while setting U1 timeout %ld\n", ret, val); | ||
| 234 | return ret; | ||
| 235 | } | ||
| 236 | |||
| 237 | return count; | ||
| 238 | } | ||
| 239 | static DEVICE_ATTR_WO(u1_timeout); | ||
| 240 | |||
| 241 | static ssize_t get_dev_desc_store(struct device *dev, | ||
| 242 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 243 | { | ||
| 244 | struct usb_interface *intf = to_usb_interface(dev); | ||
| 245 | struct usb_device *udev; | ||
| 246 | struct usb_device_descriptor *descriptor; | ||
| 247 | int ret; | ||
| 248 | |||
| 249 | descriptor = kmalloc(sizeof(*descriptor), GFP_KERNEL); | ||
| 250 | if (!descriptor) { | ||
| 251 | dev_err(dev, "failed to allocate descriptor memory\n"); | ||
| 252 | return -ENOMEM; | ||
| 253 | } | ||
| 254 | |||
| 255 | udev = create_lvs_device(intf); | ||
| 256 | if (!udev) { | ||
| 257 | dev_err(dev, "failed to create lvs device\n"); | ||
| 258 | ret = -ENOMEM; | ||
| 259 | goto free_desc; | ||
| 260 | } | ||
| 261 | |||
| 262 | ret = usb_control_msg(udev, (PIPE_CONTROL << 30) | USB_DIR_IN, | ||
| 263 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, USB_DT_DEVICE << 8, | ||
| 264 | 0, descriptor, sizeof(*descriptor), | ||
| 265 | USB_CTRL_GET_TIMEOUT); | ||
| 266 | if (ret < 0) | ||
| 267 | dev_err(dev, "can't read device descriptor %d\n", ret); | ||
| 268 | |||
| 269 | destroy_lvs_device(udev); | ||
| 270 | |||
| 271 | free_desc: | ||
| 272 | kfree(descriptor); | ||
| 273 | |||
| 274 | if (ret < 0) | ||
| 275 | return ret; | ||
| 276 | |||
| 277 | return count; | ||
| 278 | } | ||
| 279 | static DEVICE_ATTR_WO(get_dev_desc); | ||
| 280 | |||
| 281 | static struct attribute *lvs_attributes[] = { | ||
| 282 | &dev_attr_get_dev_desc.attr, | ||
| 283 | &dev_attr_u1_timeout.attr, | ||
| 284 | &dev_attr_u2_timeout.attr, | ||
| 285 | &dev_attr_hot_reset.attr, | ||
| 286 | &dev_attr_u3_entry.attr, | ||
| 287 | &dev_attr_u3_exit.attr, | ||
| 288 | NULL | ||
| 289 | }; | ||
| 290 | |||
| 291 | static const struct attribute_group lvs_attr_group = { | ||
| 292 | .attrs = lvs_attributes, | ||
| 293 | }; | ||
| 294 | |||
| 295 | static void lvs_rh_work(struct work_struct *work) | ||
| 296 | { | ||
| 297 | struct lvs_rh *lvs = container_of(work, struct lvs_rh, rh_work); | ||
| 298 | struct usb_interface *intf = lvs->intf; | ||
| 299 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
| 300 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | ||
| 301 | struct usb_hub_descriptor *descriptor = &lvs->descriptor; | ||
| 302 | struct usb_port_status *port_status = &lvs->port_status; | ||
| 303 | int i, ret = 0; | ||
| 304 | u16 portchange; | ||
| 305 | |||
| 306 | /* Examine each root port */ | ||
| 307 | for (i = 1; i <= descriptor->bNbrPorts; i++) { | ||
| 308 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | ||
| 309 | USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, i, | ||
| 310 | port_status, sizeof(*port_status), 1000); | ||
| 311 | if (ret < 4) | ||
| 312 | continue; | ||
| 313 | |||
| 314 | portchange = le16_to_cpu(port_status->wPortChange); | ||
| 315 | |||
| 316 | if (portchange & USB_PORT_STAT_C_LINK_STATE) | ||
| 317 | lvs_rh_clear_port_feature(hdev, i, | ||
| 318 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
| 319 | if (portchange & USB_PORT_STAT_C_ENABLE) | ||
| 320 | lvs_rh_clear_port_feature(hdev, i, | ||
| 321 | USB_PORT_FEAT_C_ENABLE); | ||
| 322 | if (portchange & USB_PORT_STAT_C_RESET) | ||
| 323 | lvs_rh_clear_port_feature(hdev, i, | ||
| 324 | USB_PORT_FEAT_C_RESET); | ||
| 325 | if (portchange & USB_PORT_STAT_C_BH_RESET) | ||
| 326 | lvs_rh_clear_port_feature(hdev, i, | ||
| 327 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
| 328 | if (portchange & USB_PORT_STAT_C_CONNECTION) { | ||
| 329 | lvs_rh_clear_port_feature(hdev, i, | ||
| 330 | USB_PORT_FEAT_C_CONNECTION); | ||
| 331 | |||
| 332 | if (le16_to_cpu(port_status->wPortStatus) & | ||
| 333 | USB_PORT_STAT_CONNECTION) { | ||
| 334 | lvs->present = true; | ||
| 335 | lvs->portnum = i; | ||
| 336 | if (hcd->phy) | ||
| 337 | usb_phy_notify_connect(hcd->phy, | ||
| 338 | USB_SPEED_SUPER); | ||
| 339 | } else { | ||
| 340 | lvs->present = false; | ||
| 341 | if (hcd->phy) | ||
| 342 | usb_phy_notify_disconnect(hcd->phy, | ||
| 343 | USB_SPEED_SUPER); | ||
| 344 | } | ||
| 345 | break; | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | ret = usb_submit_urb(lvs->urb, GFP_KERNEL); | ||
| 350 | if (ret != 0 && ret != -ENODEV && ret != -EPERM) | ||
| 351 | dev_err(&intf->dev, "urb resubmit error %d\n", ret); | ||
| 352 | } | ||
| 353 | |||
| 354 | static void lvs_rh_irq(struct urb *urb) | ||
| 355 | { | ||
| 356 | struct lvs_rh *lvs = urb->context; | ||
| 357 | |||
| 358 | queue_work(lvs->rh_queue, &lvs->rh_work); | ||
| 359 | } | ||
| 360 | |||
| 361 | static int lvs_rh_probe(struct usb_interface *intf, | ||
| 362 | const struct usb_device_id *id) | ||
| 363 | { | ||
| 364 | struct usb_device *hdev; | ||
| 365 | struct usb_host_interface *desc; | ||
| 366 | struct usb_endpoint_descriptor *endpoint; | ||
| 367 | struct lvs_rh *lvs; | ||
| 368 | unsigned int pipe; | ||
| 369 | int ret, maxp; | ||
| 370 | |||
| 371 | hdev = interface_to_usbdev(intf); | ||
| 372 | desc = intf->cur_altsetting; | ||
| 373 | endpoint = &desc->endpoint[0].desc; | ||
| 374 | |||
| 375 | /* valid only for SS root hub */ | ||
| 376 | if (hdev->descriptor.bDeviceProtocol != USB_HUB_PR_SS || hdev->parent) { | ||
| 377 | dev_err(&intf->dev, "Bind LVS driver with SS root Hub only\n"); | ||
| 378 | return -EINVAL; | ||
| 379 | } | ||
| 380 | |||
| 381 | lvs = devm_kzalloc(&intf->dev, sizeof(*lvs), GFP_KERNEL); | ||
| 382 | if (!lvs) | ||
| 383 | return -ENOMEM; | ||
| 384 | |||
| 385 | lvs->intf = intf; | ||
| 386 | usb_set_intfdata(intf, lvs); | ||
| 387 | |||
| 388 | /* how many number of ports this root hub has */ | ||
| 389 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | ||
| 390 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, | ||
| 391 | USB_DT_SS_HUB << 8, 0, &lvs->descriptor, | ||
| 392 | USB_DT_SS_HUB_SIZE, USB_CTRL_GET_TIMEOUT); | ||
| 393 | if (ret < (USB_DT_HUB_NONVAR_SIZE + 2)) { | ||
| 394 | dev_err(&hdev->dev, "wrong root hub descriptor read %d\n", ret); | ||
| 395 | return ret; | ||
| 396 | } | ||
| 397 | |||
| 398 | /* submit urb to poll interrupt endpoint */ | ||
| 399 | lvs->urb = usb_alloc_urb(0, GFP_KERNEL); | ||
| 400 | if (!lvs->urb) { | ||
| 401 | dev_err(&intf->dev, "couldn't allocate lvs urb\n"); | ||
| 402 | return -ENOMEM; | ||
| 403 | } | ||
| 404 | |||
| 405 | lvs->rh_queue = create_singlethread_workqueue("lvs_rh_queue"); | ||
| 406 | if (!lvs->rh_queue) { | ||
| 407 | dev_err(&intf->dev, "couldn't create workqueue\n"); | ||
| 408 | ret = -ENOMEM; | ||
| 409 | goto free_urb; | ||
| 410 | } | ||
| 411 | |||
| 412 | INIT_WORK(&lvs->rh_work, lvs_rh_work); | ||
| 413 | |||
| 414 | ret = sysfs_create_group(&intf->dev.kobj, &lvs_attr_group); | ||
| 415 | if (ret < 0) { | ||
| 416 | dev_err(&intf->dev, "Failed to create sysfs node %d\n", ret); | ||
| 417 | goto destroy_queue; | ||
| 418 | } | ||
| 419 | |||
| 420 | pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); | ||
| 421 | maxp = usb_maxpacket(hdev, pipe, usb_pipeout(pipe)); | ||
| 422 | usb_fill_int_urb(lvs->urb, hdev, pipe, &lvs->buffer[0], maxp, | ||
| 423 | lvs_rh_irq, lvs, endpoint->bInterval); | ||
| 424 | |||
| 425 | ret = usb_submit_urb(lvs->urb, GFP_KERNEL); | ||
| 426 | if (ret < 0) { | ||
| 427 | dev_err(&intf->dev, "couldn't submit lvs urb %d\n", ret); | ||
| 428 | goto sysfs_remove; | ||
| 429 | } | ||
| 430 | |||
| 431 | return ret; | ||
| 432 | |||
| 433 | sysfs_remove: | ||
| 434 | sysfs_remove_group(&intf->dev.kobj, &lvs_attr_group); | ||
| 435 | destroy_queue: | ||
| 436 | destroy_workqueue(lvs->rh_queue); | ||
| 437 | free_urb: | ||
| 438 | usb_free_urb(lvs->urb); | ||
| 439 | return ret; | ||
| 440 | } | ||
| 441 | |||
| 442 | static void lvs_rh_disconnect(struct usb_interface *intf) | ||
| 443 | { | ||
| 444 | struct lvs_rh *lvs = usb_get_intfdata(intf); | ||
| 445 | |||
| 446 | sysfs_remove_group(&intf->dev.kobj, &lvs_attr_group); | ||
| 447 | destroy_workqueue(lvs->rh_queue); | ||
| 448 | usb_free_urb(lvs->urb); | ||
| 449 | } | ||
| 450 | |||
| 451 | static struct usb_driver lvs_driver = { | ||
| 452 | .name = "lvs", | ||
| 453 | .probe = lvs_rh_probe, | ||
| 454 | .disconnect = lvs_rh_disconnect, | ||
| 455 | }; | ||
| 456 | |||
| 457 | module_usb_driver(lvs_driver); | ||
| 458 | |||
| 459 | MODULE_DESCRIPTION("Link Layer Validation System Driver"); | ||
| 460 | MODULE_LICENSE("GPL"); | ||
| @@ -149,8 +149,6 @@ static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode) · 148 unmodified lines | |||
| 149 | 149 | ||
| 150 | case USB3503_MODE_STANDBY: | 150 | case USB3503_MODE_STANDBY: |
| 151 | usb3503_reset(hub, 0); | 151 | usb3503_reset(hub, 0); |
| 152 | |||
| 153 | hub->mode = mode; | ||
| 154 | dev_info(dev, "switched to STANDBY mode\n"); | 152 | dev_info(dev, "switched to STANDBY mode\n"); |
| 155 | break; | 153 | break; |
| 156 | 154 | ||
| @@ -192,7 +190,8 @@ static int usb3503_probe(struct usb3503 *hub) · 35 unmodified lines | |||
| 192 | 190 | ||
| 193 | clk = devm_clk_get(dev, "refclk"); | 191 | clk = devm_clk_get(dev, "refclk"); |
| 194 | if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) { | 192 | if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) { |
| 195 | dev_err(dev, "unable to request refclk (%d)\n", err); | 193 | dev_err(dev, "unable to request refclk (%ld)\n", |
| 194 | PTR_ERR(clk)); | ||
| 196 | return PTR_ERR(clk); | 195 | return PTR_ERR(clk); |
| 197 | } | 196 | } |
| 198 | 197 | ||
| @@ -346,6 +345,37 @@ static int usb3503_platform_probe(struct platform_device *pdev) · 147 unmodified lines | |||
| 346 | return usb3503_probe(hub); | 345 | return usb3503_probe(hub); |
| 347 | } | 346 | } |
| 348 | 347 | ||
| 348 | #ifdef CONFIG_PM_SLEEP | ||
| 349 | static int usb3503_i2c_suspend(struct device *dev) | ||
| 350 | { | ||
| 351 | struct i2c_client *client = to_i2c_client(dev); | ||
| 352 | struct usb3503 *hub = i2c_get_clientdata(client); | ||
| 353 | |||
| 354 | usb3503_switch_mode(hub, USB3503_MODE_STANDBY); | ||
| 355 | |||
| 356 | if (hub->clk) | ||
| 357 | clk_disable_unprepare(hub->clk); | ||
| 358 | |||
| 359 | return 0; | ||
| 360 | } | ||
| 361 | |||
| 362 | static int usb3503_i2c_resume(struct device *dev) | ||
| 363 | { | ||
| 364 | struct i2c_client *client = to_i2c_client(dev); | ||
| 365 | struct usb3503 *hub = i2c_get_clientdata(client); | ||
| 366 | |||
| 367 | if (hub->clk) | ||
| 368 | clk_prepare_enable(hub->clk); | ||
| 369 | |||
| 370 | usb3503_switch_mode(hub, hub->mode); | ||
| 371 | |||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | #endif | ||
| 375 | |||
| 376 | static SIMPLE_DEV_PM_OPS(usb3503_i2c_pm_ops, usb3503_i2c_suspend, | ||
| 377 | usb3503_i2c_resume); | ||
| 378 | |||
| 349 | static const struct i2c_device_id usb3503_id[] = { | 379 | static const struct i2c_device_id usb3503_id[] = { |
| 350 | { USB3503_I2C_NAME, 0 }, | 380 | { USB3503_I2C_NAME, 0 }, |
| 351 | { } | 381 | { } |
| @@ -364,6 +394,7 @@ MODULE_DEVICE_TABLE(of, usb3503_of_match); · 12 unmodified lines | |||
| 364 | static struct i2c_driver usb3503_i2c_driver = { | 394 | static struct i2c_driver usb3503_i2c_driver = { |
| 365 | .driver = { | 395 | .driver = { |
| 366 | .name = USB3503_I2C_NAME, | 396 | .name = USB3503_I2C_NAME, |
| 397 | .pm = &usb3503_i2c_pm_ops, | ||
| 367 | .of_match_table = of_match_ptr(usb3503_of_match), | 398 | .of_match_table = of_match_ptr(usb3503_of_match), |
| 368 | }, | 399 | }, |
| 369 | .probe = usb3503_i2c_probe, | 400 | .probe = usb3503_i2c_probe, |
| @@ -455,7 +455,7 @@ static int bfin_probe(struct platform_device *pdev) · 454 unmodified lines | |||
| 455 | 455 | ||
| 456 | int ret = -ENOMEM; | 456 | int ret = -ENOMEM; |
| 457 | 457 | ||
| 458 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 458 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
| 459 | if (!glue) { | 459 | if (!glue) { |
| 460 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | 460 | dev_err(&pdev->dev, "failed to allocate glue context\n"); |
| 461 | goto err0; | 461 | goto err0; |
| @@ -464,7 +464,7 @@ static int bfin_probe(struct platform_device *pdev) · 2 unmodified lines | |||
| 464 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | 464 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
| 465 | if (!musb) { | 465 | if (!musb) { |
| 466 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | 466 | dev_err(&pdev->dev, "failed to allocate musb device\n"); |
| 467 | goto err1; | 467 | goto err0; |
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | musb->dev.parent = &pdev->dev; | 470 | musb->dev.parent = &pdev->dev; |
| @@ -478,7 +478,7 @@ static int bfin_probe(struct platform_device *pdev) · 7 unmodified lines | |||
| 478 | 478 | ||
| 479 | glue->phy = usb_phy_generic_register(); | 479 | glue->phy = usb_phy_generic_register(); |
| 480 | if (IS_ERR(glue->phy)) | 480 | if (IS_ERR(glue->phy)) |
| 481 | goto err2; | 481 | goto err1; |
| 482 | platform_set_drvdata(pdev, glue); | 482 | platform_set_drvdata(pdev, glue); |
| 483 | 483 | ||
| 484 | memset(musb_resources, 0x00, sizeof(*musb_resources) * | 484 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
| @@ -498,31 +498,28 @@ static int bfin_probe(struct platform_device *pdev) · 13 unmodified lines | |||
| 498 | ARRAY_SIZE(musb_resources)); | 498 | ARRAY_SIZE(musb_resources)); |
| 499 | if (ret) { | 499 | if (ret) { |
| 500 | dev_err(&pdev->dev, "failed to add resources\n"); | 500 | dev_err(&pdev->dev, "failed to add resources\n"); |
| 501 | goto err3; | 501 | goto err2; |
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 504 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); |
| 505 | if (ret) { | 505 | if (ret) { |
| 506 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 506 | dev_err(&pdev->dev, "failed to add platform_data\n"); |
| 507 | goto err3; | 507 | goto err2; |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | ret = platform_device_add(musb); | 510 | ret = platform_device_add(musb); |
| 511 | if (ret) { | 511 | if (ret) { |
| 512 | dev_err(&pdev->dev, "failed to register musb device\n"); | 512 | dev_err(&pdev->dev, "failed to register musb device\n"); |
| 513 | goto err3; | 513 | goto err2; |
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | return 0; | 516 | return 0; |
| 517 | 517 | ||
| 518 | err3: | ||
| 519 | usb_phy_generic_unregister(glue->phy); | ||
| 520 | |||
| 521 | err2: | 518 | err2: |
| 522 | platform_device_put(musb); | 519 | usb_phy_generic_unregister(glue->phy); |
| 523 | 520 | ||
| 524 | err1: | 521 | err1: |
| 525 | kfree(glue); | 522 | platform_device_put(musb); |
| 526 | 523 | ||
| 527 | err0: | 524 | err0: |
| 528 | return ret; | 525 | return ret; |
| @@ -534,7 +531,6 @@ static int bfin_remove(struct platform_device *pdev) · 5 unmodified lines | |||
| 534 | 531 | ||
| 535 | platform_device_unregister(glue->musb); | 532 | platform_device_unregister(glue->musb); |
| 536 | usb_phy_generic_unregister(glue->phy); | 533 | usb_phy_generic_unregister(glue->phy); |
| 537 | kfree(glue); | ||
| 538 | 534 | ||
| 539 | return 0; | 535 | return 0; |
| 540 | } | 536 | } |
| @@ -519,23 +519,23 @@ static int davinci_probe(struct platform_device *pdev) · 518 unmodified lines | |||
| 519 | 519 | ||
| 520 | int ret = -ENOMEM; | 520 | int ret = -ENOMEM; |
| 521 | 521 | ||
| 522 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 522 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
| 523 | if (!glue) { | 523 | if (!glue) { |
| 524 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | 524 | dev_err(&pdev->dev, "failed to allocate glue context\n"); |
| 525 | goto err0; | 525 | goto err0; |
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | clk = clk_get(&pdev->dev, "usb"); | 528 | clk = devm_clk_get(&pdev->dev, "usb"); |
| 529 | if (IS_ERR(clk)) { | 529 | if (IS_ERR(clk)) { |
| 530 | dev_err(&pdev->dev, "failed to get clock\n"); | 530 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 531 | ret = PTR_ERR(clk); | 531 | ret = PTR_ERR(clk); |
| 532 | goto err3; | 532 | goto err0; |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | ret = clk_enable(clk); | 535 | ret = clk_enable(clk); |
| 536 | if (ret) { | 536 | if (ret) { |
| 537 | dev_err(&pdev->dev, "failed to enable clock\n"); | 537 | dev_err(&pdev->dev, "failed to enable clock\n"); |
| 538 | goto err4; | 538 | goto err0; |
| 539 | } | 539 | } |
| 540 | 540 | ||
| 541 | glue->dev = &pdev->dev; | 541 | glue->dev = &pdev->dev; |
| @@ -579,20 +579,14 @@ static int davinci_probe(struct platform_device *pdev) · 37 unmodified lines | |||
| 579 | if (IS_ERR(musb)) { | 579 | if (IS_ERR(musb)) { |
| 580 | ret = PTR_ERR(musb); | 580 | ret = PTR_ERR(musb); |
| 581 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); | 581 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
| 582 | goto err5; | 582 | goto err1; |
| 583 | } | 583 | } |
| 584 | 584 | ||
| 585 | return 0; | 585 | return 0; |
| 586 | 586 | ||
| 587 | err5: | 587 | err1: |
| 588 | clk_disable(clk); | 588 | clk_disable(clk); |
| 589 | 589 | ||
| 590 | err4: | ||
| 591 | clk_put(clk); | ||
| 592 | |||
| 593 | err3: | ||
| 594 | kfree(glue); | ||
| 595 | |||
| 596 | err0: | 590 | err0: |
| 597 | return ret; | 591 | return ret; |
| 598 | } | 592 | } |
| @@ -604,8 +598,6 @@ static int davinci_remove(struct platform_device *pdev) · 5 unmodified lines | |||
| 604 | platform_device_unregister(glue->musb); | 598 | platform_device_unregister(glue->musb); |
| 605 | usb_phy_generic_unregister(); | 599 | usb_phy_generic_unregister(); |
| 606 | clk_disable(glue->clk); | 600 | clk_disable(glue->clk); |
| 607 | clk_put(glue->clk); | ||
| 608 | kfree(glue); | ||
| 609 | 601 | ||
| 610 | return 0; | 602 | return 0; |
| 611 | } | 603 | } |
| @@ -19,6 +19,7 @@ · 18 unmodified lines | |||
| 19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/usb/usb_phy_generic.h> | ||
| 22 | 23 | ||
| 23 | #include "musb_core.h" | 24 | #include "musb_core.h" |
| 24 | 25 | ||
| @@ -80,6 +81,7 @@ static struct musb_hdrc_platform_data jz4740_musb_platform_data = { · 55 unmodified lines | |||
| 80 | 81 | ||
| 81 | static int jz4740_musb_init(struct musb *musb) | 82 | static int jz4740_musb_init(struct musb *musb) |
| 82 | { | 83 | { |
| 84 | usb_phy_generic_register(); | ||
| 83 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 85 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
| 84 | if (!musb->xceiv) { | 86 | if (!musb->xceiv) { |
| 85 | pr_err("HS UDC: no transceiver configured\n"); | 87 | pr_err("HS UDC: no transceiver configured\n"); |
| @@ -182,6 +184,7 @@ static int jz4740_remove(struct platform_device *pdev) · 96 unmodified lines | |||
| 182 | struct jz4740_glue *glue = platform_get_drvdata(pdev); | 184 | struct jz4740_glue *glue = platform_get_drvdata(pdev); |
| 183 | 185 | ||
| 184 | platform_device_unregister(glue->musb); | 186 | platform_device_unregister(glue->musb); |
| 187 | usb_phy_generic_unregister(pdev); | ||
| 185 | clk_disable_unprepare(glue->clk); | 188 | clk_disable_unprepare(glue->clk); |
| 186 | 189 | ||
| 187 | return 0; | 190 | return 0; |
| @@ -850,7 +850,8 @@ b_host: · 849 unmodified lines | |||
| 850 | 850 | ||
| 851 | /* handle babble condition */ | 851 | /* handle babble condition */ |
| 852 | if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb)) | 852 | if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb)) |
| 853 | schedule_work(&musb->recover_work); | 853 | schedule_delayed_work(&musb->recover_work, |
| 854 | msecs_to_jiffies(100)); | ||
| 854 | 855 | ||
| 855 | #if 0 | 856 | #if 0 |
| 856 | /* REVISIT ... this would be for multiplexing periodic endpoints, or | 857 | /* REVISIT ... this would be for multiplexing periodic endpoints, or |
| @@ -1517,7 +1518,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 660 unmodified lines | |||
| 1517 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 1518 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 1518 | 1519 | ||
| 1519 | dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n", | 1520 | dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n", |
| 1520 | (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral", | 1521 | is_host_active(musb) ? "host" : "peripheral", |
| 1521 | musb->int_usb, musb->int_tx, musb->int_rx); | 1522 | musb->int_usb, musb->int_tx, musb->int_rx); |
| 1522 | 1523 | ||
| 1523 | /* the core can interrupt us for multiple reasons; docs have | 1524 | /* the core can interrupt us for multiple reasons; docs have |
| @@ -1531,7 +1532,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 7 unmodified lines | |||
| 1531 | 1532 | ||
| 1532 | /* handle endpoint 0 first */ | 1533 | /* handle endpoint 0 first */ |
| 1533 | if (musb->int_tx & 1) { | 1534 | if (musb->int_tx & 1) { |
| 1534 | if (devctl & MUSB_DEVCTL_HM) | 1535 | if (is_host_active(musb)) |
| 1535 | retval |= musb_h_ep0_irq(musb); | 1536 | retval |= musb_h_ep0_irq(musb); |
| 1536 | else | 1537 | else |
| 1537 | retval |= musb_g_ep0_irq(musb); | 1538 | retval |= musb_g_ep0_irq(musb); |
| @@ -1545,7 +1546,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 7 unmodified lines | |||
| 1545 | /* musb_ep_select(musb->mregs, ep_num); */ | 1546 | /* musb_ep_select(musb->mregs, ep_num); */ |
| 1546 | /* REVISIT just retval = ep->rx_irq(...) */ | 1547 | /* REVISIT just retval = ep->rx_irq(...) */ |
| 1547 | retval = IRQ_HANDLED; | 1548 | retval = IRQ_HANDLED; |
| 1548 | if (devctl & MUSB_DEVCTL_HM) | 1549 | if (is_host_active(musb)) |
| 1549 | musb_host_rx(musb, ep_num); | 1550 | musb_host_rx(musb, ep_num); |
| 1550 | else | 1551 | else |
| 1551 | musb_g_rx(musb, ep_num); | 1552 | musb_g_rx(musb, ep_num); |
| @@ -1563,7 +1564,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 11 unmodified lines | |||
| 1563 | /* musb_ep_select(musb->mregs, ep_num); */ | 1564 | /* musb_ep_select(musb->mregs, ep_num); */ |
| 1564 | /* REVISIT just retval |= ep->tx_irq(...) */ | 1565 | /* REVISIT just retval |= ep->tx_irq(...) */ |
| 1565 | retval = IRQ_HANDLED; | 1566 | retval = IRQ_HANDLED; |
| 1566 | if (devctl & MUSB_DEVCTL_HM) | 1567 | if (is_host_active(musb)) |
| 1567 | musb_host_tx(musb, ep_num); | 1568 | musb_host_tx(musb, ep_num); |
| 1568 | else | 1569 | else |
| 1569 | musb_g_tx(musb, ep_num); | 1570 | musb_g_tx(musb, ep_num); |
| @@ -1585,15 +1586,13 @@ MODULE_PARM_DESC(use_dma, "enable/disable use of DMA"); · 15 unmodified lines | |||
| 1585 | 1586 | ||
| 1586 | void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit) | 1587 | void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit) |
| 1587 | { | 1588 | { |
| 1588 | u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | ||
| 1589 | |||
| 1590 | /* called with controller lock already held */ | 1589 | /* called with controller lock already held */ |
| 1591 | 1590 | ||
| 1592 | if (!epnum) { | 1591 | if (!epnum) { |
| 1593 | #ifndef CONFIG_USB_TUSB_OMAP_DMA | 1592 | #ifndef CONFIG_USB_TUSB_OMAP_DMA |
| 1594 | if (!is_cppi_enabled()) { | 1593 | if (!is_cppi_enabled()) { |
| 1595 | /* endpoint 0 */ | 1594 | /* endpoint 0 */ |
| 1596 | if (devctl & MUSB_DEVCTL_HM) | 1595 | if (is_host_active(musb)) |
| 1597 | musb_h_ep0_irq(musb); | 1596 | musb_h_ep0_irq(musb); |
| 1598 | else | 1597 | else |
| 1599 | musb_g_ep0_irq(musb); | 1598 | musb_g_ep0_irq(musb); |
| @@ -1602,13 +1601,13 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit) · 2 unmodified lines | |||
| 1602 | } else { | 1601 | } else { |
| 1603 | /* endpoints 1..15 */ | 1602 | /* endpoints 1..15 */ |
| 1604 | if (transmit) { | 1603 | if (transmit) { |
| 1605 | if (devctl & MUSB_DEVCTL_HM) | 1604 | if (is_host_active(musb)) |
| 1606 | musb_host_tx(musb, epnum); | 1605 | musb_host_tx(musb, epnum); |
| 1607 | else | 1606 | else |
| 1608 | musb_g_tx(musb, epnum); | 1607 | musb_g_tx(musb, epnum); |
| 1609 | } else { | 1608 | } else { |
| 1610 | /* receive */ | 1609 | /* receive */ |
| 1611 | if (devctl & MUSB_DEVCTL_HM) | 1610 | if (is_host_active(musb)) |
| 1612 | musb_host_rx(musb, epnum); | 1611 | musb_host_rx(musb, epnum); |
| 1613 | else | 1612 | else |
| 1614 | musb_g_rx(musb, epnum); | 1613 | musb_g_rx(musb, epnum); |
| @@ -1753,20 +1752,22 @@ static void musb_irq_work(struct work_struct *data) · 138 unmodified lines | |||
| 1753 | /* Recover from babble interrupt conditions */ | 1752 | /* Recover from babble interrupt conditions */ |
| 1754 | static void musb_recover_work(struct work_struct *data) | 1753 | static void musb_recover_work(struct work_struct *data) |
| 1755 | { | 1754 | { |
| 1756 | struct musb *musb = container_of(data, struct musb, recover_work); | 1755 | struct musb *musb = container_of(data, struct musb, recover_work.work); |
| 1757 | int status; | 1756 | int status, ret; |
| 1758 | 1757 | ||
| 1759 | musb_platform_reset(musb); | 1758 | ret = musb_platform_reset(musb); |
| 1759 | if (ret) | ||
| 1760 | return; | ||
| 1760 | 1761 | ||
| 1761 | usb_phy_vbus_off(musb->xceiv); | 1762 | usb_phy_vbus_off(musb->xceiv); |
| 1762 | udelay(100); | 1763 | usleep_range(100, 200); |
| 1763 | 1764 | ||
| 1764 | usb_phy_vbus_on(musb->xceiv); | 1765 | usb_phy_vbus_on(musb->xceiv); |
| 1765 | udelay(100); | 1766 | usleep_range(100, 200); |
| 1766 | 1767 | ||
| 1767 | /* | 1768 | /* |
| 1768 | * When a babble condition occurs, the musb controller removes the | 1769 | * When a babble condition occurs, the musb controller |
| 1769 | * session bit and the endpoint config is lost. | 1770 | * removes the session bit and the endpoint config is lost. |
| 1770 | */ | 1771 | */ |
| 1771 | if (musb->dyn_fifo) | 1772 | if (musb->dyn_fifo) |
| 1772 | status = ep_config_from_table(musb); | 1773 | status = ep_config_from_table(musb); |
| @@ -1945,7 +1946,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) · 172 unmodified lines | |||
| 1945 | 1946 | ||
| 1946 | /* Init IRQ workqueue before request_irq */ | 1947 | /* Init IRQ workqueue before request_irq */ |
| 1947 | INIT_WORK(&musb->irq_work, musb_irq_work); | 1948 | INIT_WORK(&musb->irq_work, musb_irq_work); |
| 1948 | INIT_WORK(&musb->recover_work, musb_recover_work); | 1949 | INIT_DELAYED_WORK(&musb->recover_work, musb_recover_work); |
| 1949 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); | 1950 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); |
| 1950 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); | 1951 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); |
| 1951 | 1952 | ||
| @@ -2041,7 +2042,7 @@ fail4: · 89 unmodified lines | |||
| 2041 | 2042 | ||
| 2042 | fail3: | 2043 | fail3: |
| 2043 | cancel_work_sync(&musb->irq_work); | 2044 | cancel_work_sync(&musb->irq_work); |
| 2044 | cancel_work_sync(&musb->recover_work); | 2045 | cancel_delayed_work_sync(&musb->recover_work); |
| 2045 | cancel_delayed_work_sync(&musb->finish_resume_work); | 2046 | cancel_delayed_work_sync(&musb->finish_resume_work); |
| 2046 | cancel_delayed_work_sync(&musb->deassert_reset_work); | 2047 | cancel_delayed_work_sync(&musb->deassert_reset_work); |
| 2047 | if (musb->dma_controller) | 2048 | if (musb->dma_controller) |
| @@ -2107,7 +2108,7 @@ static int musb_remove(struct platform_device *pdev) · 59 unmodified lines | |||
| 2107 | dma_controller_destroy(musb->dma_controller); | 2108 | dma_controller_destroy(musb->dma_controller); |
| 2108 | 2109 | ||
| 2109 | cancel_work_sync(&musb->irq_work); | 2110 | cancel_work_sync(&musb->irq_work); |
| 2110 | cancel_work_sync(&musb->recover_work); | 2111 | cancel_delayed_work_sync(&musb->recover_work); |
| 2111 | cancel_delayed_work_sync(&musb->finish_resume_work); | 2112 | cancel_delayed_work_sync(&musb->finish_resume_work); |
| 2112 | cancel_delayed_work_sync(&musb->deassert_reset_work); | 2113 | cancel_delayed_work_sync(&musb->deassert_reset_work); |
| 2113 | musb_free(musb); | 2114 | musb_free(musb); |
| @@ -192,7 +192,7 @@ struct musb_platform_ops { · 191 unmodified lines | |||
| 192 | 192 | ||
| 193 | int (*set_mode)(struct musb *musb, u8 mode); | 193 | int (*set_mode)(struct musb *musb, u8 mode); |
| 194 | void (*try_idle)(struct musb *musb, unsigned long timeout); | 194 | void (*try_idle)(struct musb *musb, unsigned long timeout); |
| 195 | void (*reset)(struct musb *musb); | 195 | int (*reset)(struct musb *musb); |
| 196 | 196 | ||
| 197 | int (*vbus_status)(struct musb *musb); | 197 | int (*vbus_status)(struct musb *musb); |
| 198 | void (*set_vbus)(struct musb *musb, int on); | 198 | void (*set_vbus)(struct musb *musb, int on); |
| @@ -297,7 +297,7 @@ struct musb { · 98 unmodified lines | |||
| 297 | 297 | ||
| 298 | irqreturn_t (*isr)(int, void *); | 298 | irqreturn_t (*isr)(int, void *); |
| 299 | struct work_struct irq_work; | 299 | struct work_struct irq_work; |
| 300 | struct work_struct recover_work; | 300 | struct delayed_work recover_work; |
| 301 | struct delayed_work deassert_reset_work; | 301 | struct delayed_work deassert_reset_work; |
| 302 | struct delayed_work finish_resume_work; | 302 | struct delayed_work finish_resume_work; |
| 303 | u16 hwvers; | 303 | u16 hwvers; |
| @@ -555,10 +555,12 @@ static inline void musb_platform_try_idle(struct musb *musb, · 251 unmodified lines | |||
| 555 | musb->ops->try_idle(musb, timeout); | 555 | musb->ops->try_idle(musb, timeout); |
| 556 | } | 556 | } |
| 557 | 557 | ||
| 558 | static inline void musb_platform_reset(struct musb *musb) | 558 | static inline int musb_platform_reset(struct musb *musb) |
| 559 | { | 559 | { |
| 560 | if (musb->ops->reset) | 560 | if (!musb->ops->reset) |
| 561 | musb->ops->reset(musb); | 561 | return -EINVAL; |
| 562 | |||
| 563 | return musb->ops->reset(musb); | ||
| 562 | } | 564 | } |
| 563 | 565 | ||
| 564 | static inline int musb_platform_get_vbus_status(struct musb *musb) | 566 | static inline int musb_platform_get_vbus_status(struct musb *musb) |
| @@ -39,7 +39,6 @@ struct cppi41_dma_channel { · 38 unmodified lines | |||
| 39 | u32 transferred; | 39 | u32 transferred; |
| 40 | u32 packet_sz; | 40 | u32 packet_sz; |
| 41 | struct list_head tx_check; | 41 | struct list_head tx_check; |
| 42 | struct work_struct dma_completion; | ||
| 43 | }; | 42 | }; |
| 44 | 43 | ||
| 45 | #define MUSB_DMA_NUM_CHANNELS 15 | 44 | #define MUSB_DMA_NUM_CHANNELS 15 |
| @@ -74,15 +73,18 @@ static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel) · 28 unmodified lines | |||
| 74 | 73 | ||
| 75 | static void update_rx_toggle(struct cppi41_dma_channel *cppi41_channel) | 74 | static void update_rx_toggle(struct cppi41_dma_channel *cppi41_channel) |
| 76 | { | 75 | { |
| 76 | struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; | ||
| 77 | struct musb *musb = hw_ep->musb; | ||
| 77 | u16 csr; | 78 | u16 csr; |
| 78 | u8 toggle; | 79 | u8 toggle; |
| 79 | 80 | ||
| 80 | if (cppi41_channel->is_tx) | 81 | if (cppi41_channel->is_tx) |
| 81 | return; | 82 | return; |
| 82 | if (!is_host_active(cppi41_channel->controller->musb)) | 83 | if (!is_host_active(musb)) |
| 83 | return; | 84 | return; |
| 84 | 85 | ||
| 85 | csr = musb_readw(cppi41_channel->hw_ep->regs, MUSB_RXCSR); | 86 | musb_ep_select(musb->mregs, hw_ep->epnum); |
| 87 | csr = musb_readw(hw_ep->regs, MUSB_RXCSR); | ||
| 86 | toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0; | 88 | toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0; |
| 87 | 89 | ||
| 88 | /* | 90 | /* |
| @@ -107,24 +109,13 @@ static bool musb_is_tx_fifo_empty(struct musb_hw_ep *hw_ep) · 18 unmodified lines | |||
| 107 | void __iomem *epio = musb->endpoints[epnum].regs; | 109 | void __iomem *epio = musb->endpoints[epnum].regs; |
| 108 | u16 csr; | 110 | u16 csr; |
| 109 | 111 | ||
| 112 | musb_ep_select(musb->mregs, hw_ep->epnum); | ||
| 110 | csr = musb_readw(epio, MUSB_TXCSR); | 113 | csr = musb_readw(epio, MUSB_TXCSR); |
| 111 | if (csr & MUSB_TXCSR_TXPKTRDY) | 114 | if (csr & MUSB_TXCSR_TXPKTRDY) |
| 112 | return false; | 115 | return false; |
| 113 | return true; | 116 | return true; |
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | static bool is_isoc(struct musb_hw_ep *hw_ep, bool in) | ||
| 117 | { | ||
| 118 | if (in && hw_ep->in_qh) { | ||
| 119 | if (hw_ep->in_qh->type == USB_ENDPOINT_XFER_ISOC) | ||
| 120 | return true; | ||
| 121 | } else if (hw_ep->out_qh) { | ||
| 122 | if (hw_ep->out_qh->type == USB_ENDPOINT_XFER_ISOC) | ||
| 123 | return true; | ||
| 124 | } | ||
| 125 | return false; | ||
| 126 | } | ||
| 127 | |||
| 128 | static void cppi41_dma_callback(void *private_data); | 119 | static void cppi41_dma_callback(void *private_data); |
| 129 | 120 | ||
| 130 | static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) | 121 | static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) |
| @@ -139,6 +130,7 @@ static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) · 8 unmodified lines | |||
| 139 | cppi41_channel->channel.actual_len = | 130 | cppi41_channel->channel.actual_len = |
| 140 | cppi41_channel->transferred; | 131 | cppi41_channel->transferred; |
| 141 | cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE; | 132 | cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE; |
| 133 | cppi41_channel->channel.rx_packet_done = true; | ||
| 142 | musb_dma_completion(musb, hw_ep->epnum, cppi41_channel->is_tx); | 134 | musb_dma_completion(musb, hw_ep->epnum, cppi41_channel->is_tx); |
| 143 | } else { | 135 | } else { |
| 144 | /* next iteration, reload */ | 136 | /* next iteration, reload */ |
| @@ -172,6 +164,7 @@ static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) · 27 unmodified lines | |||
| 172 | dma_async_issue_pending(dc); | 164 | dma_async_issue_pending(dc); |
| 173 | 165 | ||
| 174 | if (!cppi41_channel->is_tx) { | 166 | if (!cppi41_channel->is_tx) { |
| 167 | musb_ep_select(musb->mregs, hw_ep->epnum); | ||
| 175 | csr = musb_readw(epio, MUSB_RXCSR); | 168 | csr = musb_readw(epio, MUSB_RXCSR); |
| 176 | csr |= MUSB_RXCSR_H_REQPKT; | 169 | csr |= MUSB_RXCSR_H_REQPKT; |
| 177 | musb_writew(epio, MUSB_RXCSR, csr); | 170 | musb_writew(epio, MUSB_RXCSR, csr); |
| @@ -179,32 +172,6 @@ static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) · 1 unmodified line | |||
| 179 | } | 172 | } |
| 180 | } | 173 | } |
| 181 | 174 | ||
| 182 | static void cppi_trans_done_work(struct work_struct *work) | ||
| 183 | { | ||
| 184 | unsigned long flags; | ||
| 185 | struct cppi41_dma_channel *cppi41_channel = | ||
| 186 | container_of(work, struct cppi41_dma_channel, dma_completion); | ||
| 187 | struct cppi41_dma_controller *controller = cppi41_channel->controller; | ||
| 188 | struct musb *musb = controller->musb; | ||
| 189 | struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; | ||
| 190 | bool empty; | ||
| 191 | |||
| 192 | if (!cppi41_channel->is_tx && is_isoc(hw_ep, 1)) { | ||
| 193 | spin_lock_irqsave(&musb->lock, flags); | ||
| 194 | cppi41_trans_done(cppi41_channel); | ||
| 195 | spin_unlock_irqrestore(&musb->lock, flags); | ||
| 196 | } else { | ||
| 197 | empty = musb_is_tx_fifo_empty(hw_ep); | ||
| 198 | if (empty) { | ||
| 199 | spin_lock_irqsave(&musb->lock, flags); | ||
| 200 | cppi41_trans_done(cppi41_channel); | ||
| 201 | spin_unlock_irqrestore(&musb->lock, flags); | ||
| 202 | } else { | ||
| 203 | schedule_work(&cppi41_channel->dma_completion); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | static enum hrtimer_restart cppi41_recheck_tx_req(struct hrtimer *timer) | 175 | static enum hrtimer_restart cppi41_recheck_tx_req(struct hrtimer *timer) |
| 209 | { | 176 | { |
| 210 | struct cppi41_dma_controller *controller; | 177 | struct cppi41_dma_controller *controller; |
| @@ -233,7 +200,7 @@ static enum hrtimer_restart cppi41_recheck_tx_req(struct hrtimer *timer) · 22 unmodified lines | |||
| 233 | if (!list_empty(&controller->early_tx_list)) { | 200 | if (!list_empty(&controller->early_tx_list)) { |
| 234 | ret = HRTIMER_RESTART; | 201 | ret = HRTIMER_RESTART; |
| 235 | hrtimer_forward_now(&controller->early_tx, | 202 | hrtimer_forward_now(&controller->early_tx, |
| 236 | ktime_set(0, 150 * NSEC_PER_USEC)); | 203 | ktime_set(0, 50 * NSEC_PER_USEC)); |
| 237 | } | 204 | } |
| 238 | 205 | ||
| 239 | spin_unlock_irqrestore(&musb->lock, flags); | 206 | spin_unlock_irqrestore(&musb->lock, flags); |
| @@ -268,14 +235,6 @@ static void cppi41_dma_callback(void *private_data) · 28 unmodified lines | |||
| 268 | transferred < cppi41_channel->packet_sz) | 235 | transferred < cppi41_channel->packet_sz) |
| 269 | cppi41_channel->prog_len = 0; | 236 | cppi41_channel->prog_len = 0; |
| 270 | 237 | ||
| 271 | if (!cppi41_channel->is_tx) { | ||
| 272 | if (is_isoc(hw_ep, 1)) | ||
| 273 | schedule_work(&cppi41_channel->dma_completion); | ||
| 274 | else | ||
| 275 | cppi41_trans_done(cppi41_channel); | ||
| 276 | goto out; | ||
| 277 | } | ||
| 278 | |||
| 279 | empty = musb_is_tx_fifo_empty(hw_ep); | 238 | empty = musb_is_tx_fifo_empty(hw_ep); |
| 280 | if (empty) { | 239 | if (empty) { |
| 281 | cppi41_trans_done(cppi41_channel); | 240 | cppi41_trans_done(cppi41_channel); |
| @@ -312,15 +271,13 @@ static void cppi41_dma_callback(void *private_data) · 30 unmodified lines | |||
| 312 | goto out; | 271 | goto out; |
| 313 | } | 272 | } |
| 314 | } | 273 | } |
| 315 | if (is_isoc(hw_ep, 0)) { | ||
| 316 | schedule_work(&cppi41_channel->dma_completion); | ||
| 317 | goto out; | ||
| 318 | } | ||
| 319 | list_add_tail(&cppi41_channel->tx_check, | 274 | list_add_tail(&cppi41_channel->tx_check, |
| 320 | &controller->early_tx_list); | 275 | &controller->early_tx_list); |
| 321 | if (!hrtimer_is_queued(&controller->early_tx)) { | 276 | if (!hrtimer_is_queued(&controller->early_tx)) { |
| 277 | unsigned long usecs = cppi41_channel->total_len / 10; | ||
| 278 | |||
| 322 | hrtimer_start_range_ns(&controller->early_tx, | 279 | hrtimer_start_range_ns(&controller->early_tx, |
| 323 | ktime_set(0, 140 * NSEC_PER_USEC), | 280 | ktime_set(0, usecs * NSEC_PER_USEC), |
| 324 | 40 * NSEC_PER_USEC, | 281 | 40 * NSEC_PER_USEC, |
| 325 | HRTIMER_MODE_REL); | 282 | HRTIMER_MODE_REL); |
| 326 | } | 283 | } |
| @@ -450,6 +407,7 @@ static bool cppi41_configure_channel(struct dma_channel *channel, · 123 unmodified lines | |||
| 450 | dma_desc->callback = cppi41_dma_callback; | 407 | dma_desc->callback = cppi41_dma_callback; |
| 451 | dma_desc->callback_param = channel; | 408 | dma_desc->callback_param = channel; |
| 452 | cppi41_channel->cookie = dma_desc->tx_submit(dma_desc); | 409 | cppi41_channel->cookie = dma_desc->tx_submit(dma_desc); |
| 410 | cppi41_channel->channel.rx_packet_done = false; | ||
| 453 | 411 | ||
| 454 | save_rx_toggle(cppi41_channel); | 412 | save_rx_toggle(cppi41_channel); |
| 455 | dma_async_issue_pending(dc); | 413 | dma_async_issue_pending(dc); |
| @@ -672,8 +630,6 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) · 216 unmodified lines | |||
| 672 | cppi41_channel->port_num = port; | 630 | cppi41_channel->port_num = port; |
| 673 | cppi41_channel->is_tx = is_tx; | 631 | cppi41_channel->is_tx = is_tx; |
| 674 | INIT_LIST_HEAD(&cppi41_channel->tx_check); | 632 | INIT_LIST_HEAD(&cppi41_channel->tx_check); |
| 675 | INIT_WORK(&cppi41_channel->dma_completion, | ||
| 676 | cppi_trans_done_work); | ||
| 677 | 633 | ||
| 678 | musb_dma = &cppi41_channel->channel; | 634 | musb_dma = &cppi41_channel->channel; |
| 679 | musb_dma->private_data = cppi41_channel; | 635 | musb_dma->private_data = cppi41_channel; |
| @@ -129,6 +129,7 @@ struct dma_channel { · 128 unmodified lines | |||
| 129 | size_t actual_len; | 129 | size_t actual_len; |
| 130 | enum dma_channel_status status; | 130 | enum dma_channel_status status; |
| 131 | bool desired_mode; | 131 | bool desired_mode; |
| 132 | bool rx_packet_done; | ||
| 132 | }; | 133 | }; |
| 133 | 134 | ||
| 134 | /* | 135 | /* |
| @@ -56,16 +56,24 @@ static const struct of_device_id musb_dsps_of_match[]; · 55 unmodified lines | |||
| 56 | * dependent on musb core layer symbols. | 56 | * dependent on musb core layer symbols. |
| 57 | */ | 57 | */ |
| 58 | static inline u8 dsps_readb(const void __iomem *addr, unsigned offset) | 58 | static inline u8 dsps_readb(const void __iomem *addr, unsigned offset) |
| 59 | { return __raw_readb(addr + offset); } | 59 | { |
| 60 | return __raw_readb(addr + offset); | ||
| 61 | } | ||
| 60 | 62 | ||
| 61 | static inline u32 dsps_readl(const void __iomem *addr, unsigned offset) | 63 | static inline u32 dsps_readl(const void __iomem *addr, unsigned offset) |
| 62 | { return __raw_readl(addr + offset); } | 64 | { |
| 65 | return __raw_readl(addr + offset); | ||
| 66 | } | ||
| 63 | 67 | ||
| 64 | static inline void dsps_writeb(void __iomem *addr, unsigned offset, u8 data) | 68 | static inline void dsps_writeb(void __iomem *addr, unsigned offset, u8 data) |
| 65 | { __raw_writeb(data, addr + offset); } | 69 | { |
| 70 | __raw_writeb(data, addr + offset); | ||
| 71 | } | ||
| 66 | 72 | ||
| 67 | static inline void dsps_writel(void __iomem *addr, unsigned offset, u32 data) | 73 | static inline void dsps_writel(void __iomem *addr, unsigned offset, u32 data) |
| 68 | { __raw_writel(data, addr + offset); } | 74 | { |
| 75 | __raw_writel(data, addr + offset); | ||
| 76 | } | ||
| 69 | 77 | ||
| 70 | /** | 78 | /** |
| 71 | * DSPS musb wrapper register offset. | 79 | * DSPS musb wrapper register offset. |
| @@ -136,6 +144,7 @@ struct dsps_glue { · 64 unmodified lines | |||
| 136 | const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ | 144 | const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ |
| 137 | struct timer_list timer; /* otg_workaround timer */ | 145 | struct timer_list timer; /* otg_workaround timer */ |
| 138 | unsigned long last_timer; /* last timer data for each instance */ | 146 | unsigned long last_timer; /* last timer data for each instance */ |
| 147 | bool sw_babble_enabled; | ||
| 139 | 148 | ||
| 140 | struct dsps_context context; | 149 | struct dsps_context context; |
| 141 | struct debugfs_regset32 regset; | 150 | struct debugfs_regset32 regset; |
| @@ -469,6 +478,19 @@ static int dsps_musb_init(struct musb *musb) · 327 unmodified lines | |||
| 469 | val &= ~(1 << wrp->otg_disable); | 478 | val &= ~(1 << wrp->otg_disable); |
| 470 | dsps_writel(musb->ctrl_base, wrp->phy_utmi, val); | 479 | dsps_writel(musb->ctrl_base, wrp->phy_utmi, val); |
| 471 | 480 | ||
| 481 | /* | ||
| 482 | * Check whether the dsps version has babble control enabled. | ||
| 483 | * In latest silicon revision the babble control logic is enabled. | ||
| 484 | * If MUSB_BABBLE_CTL returns 0x4 then we have the babble control | ||
| 485 | * logic enabled. | ||
| 486 | */ | ||
| 487 | val = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); | ||
| 488 | if (val == MUSB_BABBLE_RCV_DISABLE) { | ||
| 489 | glue->sw_babble_enabled = true; | ||
| 490 | val |= MUSB_BABBLE_SW_SESSION_CTRL; | ||
| 491 | dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, val); | ||
| 492 | } | ||
| 493 | |||
| 472 | ret = dsps_musb_dbg_init(musb, glue); | 494 | ret = dsps_musb_dbg_init(musb, glue); |
| 473 | if (ret) | 495 | if (ret) |
| 474 | return ret; | 496 | return ret; |
| @@ -535,14 +557,82 @@ static int dsps_musb_set_mode(struct musb *musb, u8 mode) · 60 unmodified lines | |||
| 535 | return 0; | 557 | return 0; |
| 536 | } | 558 | } |
| 537 | 559 | ||
| 538 | static void dsps_musb_reset(struct musb *musb) | 560 | static bool sw_babble_control(struct musb *musb) |
| 561 | { | ||
| 562 | u8 babble_ctl; | ||
| 563 | bool session_restart = false; | ||
| 564 | |||
| 565 | babble_ctl = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); | ||
| 566 | dev_dbg(musb->controller, "babble: MUSB_BABBLE_CTL value %x\n", | ||
| 567 | babble_ctl); | ||
| 568 | /* | ||
| 569 | * check line monitor flag to check whether babble is | ||
| 570 | * due to noise | ||
| 571 | */ | ||
| 572 | dev_dbg(musb->controller, "STUCK_J is %s\n", | ||
| 573 | babble_ctl & MUSB_BABBLE_STUCK_J ? "set" : "reset"); | ||
| 574 | |||
| 575 | if (babble_ctl & MUSB_BABBLE_STUCK_J) { | ||
| 576 | int timeout = 10; | ||
| 577 | |||
| 578 | /* | ||
| 579 | * babble is due to noise, then set transmit idle (d7 bit) | ||
| 580 | * to resume normal operation | ||
| 581 | */ | ||
| 582 | babble_ctl = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); | ||
| 583 | babble_ctl |= MUSB_BABBLE_FORCE_TXIDLE; | ||
| 584 | dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, babble_ctl); | ||
| 585 | |||
| 586 | /* wait till line monitor flag cleared */ | ||
| 587 | dev_dbg(musb->controller, "Set TXIDLE, wait J to clear\n"); | ||
| 588 | do { | ||
| 589 | babble_ctl = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); | ||
| 590 | udelay(1); | ||
| 591 | } while ((babble_ctl & MUSB_BABBLE_STUCK_J) && timeout--); | ||
| 592 | |||
| 593 | /* check whether stuck_at_j bit cleared */ | ||
| 594 | if (babble_ctl & MUSB_BABBLE_STUCK_J) { | ||
| 595 | /* | ||
| 596 | * real babble condition has occurred | ||
| 597 | * restart the controller to start the | ||
| 598 | * session again | ||
| 599 | */ | ||
| 600 | dev_dbg(musb->controller, "J not cleared, misc (%x)\n", | ||
| 601 | babble_ctl); | ||
| 602 | session_restart = true; | ||
| 603 | } | ||
| 604 | } else { | ||
| 605 | session_restart = true; | ||
| 606 | } | ||
| 607 | |||
| 608 | return session_restart; | ||
| 609 | } | ||
| 610 | |||
| 611 | static int dsps_musb_reset(struct musb *musb) | ||
| 539 | { | 612 | { |
| 540 | struct device *dev = musb->controller; | 613 | struct device *dev = musb->controller; |
| 541 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); | 614 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); |
| 542 | const struct dsps_musb_wrapper *wrp = glue->wrp; | 615 | const struct dsps_musb_wrapper *wrp = glue->wrp; |
| 616 | int session_restart = 0; | ||
| 617 | |||
| 618 | if (glue->sw_babble_enabled) | ||
| 619 | session_restart = sw_babble_control(musb); | ||
| 620 | /* | ||
| 621 | * In case of new silicon version babble condition can be recovered | ||
| 622 | * without resetting the MUSB. But for older silicon versions, MUSB | ||
| 623 | * reset is needed | ||
| 624 | */ | ||
| 625 | if (session_restart || !glue->sw_babble_enabled) { | ||
| 626 | dev_info(musb->controller, "Restarting MUSB to recover from Babble\n"); | ||
| 627 | dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset)); | ||
| 628 | usleep_range(100, 200); | ||
| 629 | usb_phy_shutdown(musb->xceiv); | ||
| 630 | usleep_range(100, 200); | ||
| 631 | usb_phy_init(musb->xceiv); | ||
| 632 | session_restart = 1; | ||
| 633 | } | ||
| 543 | 634 | ||
| 544 | dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset)); | 635 | return !session_restart; |
| 545 | udelay(100); | ||
| 546 | } | 636 | } |
| 547 | 637 | ||
| 548 | static struct musb_platform_ops dsps_ops = { | 638 | static struct musb_platform_ops dsps_ops = { |
| @@ -120,7 +120,7 @@ static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep) · 119 unmodified lines | |||
| 120 | if (csr != lastcsr) | 120 | if (csr != lastcsr) |
| 121 | dev_dbg(musb->controller, "Host TX FIFONOTEMPTY csr: %02x\n", csr); | 121 | dev_dbg(musb->controller, "Host TX FIFONOTEMPTY csr: %02x\n", csr); |
| 122 | lastcsr = csr; | 122 | lastcsr = csr; |
| 123 | csr |= MUSB_TXCSR_FLUSHFIFO; | 123 | csr |= MUSB_TXCSR_FLUSHFIFO | MUSB_TXCSR_TXPKTRDY; |
| 124 | musb_writew(epio, MUSB_TXCSR, csr); | 124 | musb_writew(epio, MUSB_TXCSR, csr); |
| 125 | csr = musb_readw(epio, MUSB_TXCSR); | 125 | csr = musb_readw(epio, MUSB_TXCSR); |
| 126 | if (WARN(retries-- < 1, | 126 | if (WARN(retries-- < 1, |
| @@ -1295,7 +1295,7 @@ done: · 1168 unmodified lines | |||
| 1295 | if (status) { | 1295 | if (status) { |
| 1296 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { | 1296 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { |
| 1297 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; | 1297 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; |
| 1298 | (void) musb->dma_controller->channel_abort(dma); | 1298 | musb->dma_controller->channel_abort(dma); |
| 1299 | } | 1299 | } |
| 1300 | 1300 | ||
| 1301 | /* do the proper sequence to abort the transfer in the | 1301 | /* do the proper sequence to abort the transfer in the |
| @@ -1640,7 +1640,7 @@ void musb_host_rx(struct musb *musb, u8 epnum) · 338 unmodified lines | |||
| 1640 | /* clean up dma and collect transfer count */ | 1640 | /* clean up dma and collect transfer count */ |
| 1641 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { | 1641 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { |
| 1642 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; | 1642 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; |
| 1643 | (void) musb->dma_controller->channel_abort(dma); | 1643 | musb->dma_controller->channel_abort(dma); |
| 1644 | xfer_len = dma->actual_len; | 1644 | xfer_len = dma->actual_len; |
| 1645 | } | 1645 | } |
| 1646 | musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG); | 1646 | musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG); |
| @@ -1671,7 +1671,7 @@ void musb_host_rx(struct musb *musb, u8 epnum) · 24 unmodified lines | |||
| 1671 | */ | 1671 | */ |
| 1672 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { | 1672 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { |
| 1673 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; | 1673 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; |
| 1674 | (void) musb->dma_controller->channel_abort(dma); | 1674 | musb->dma_controller->channel_abort(dma); |
| 1675 | xfer_len = dma->actual_len; | 1675 | xfer_len = dma->actual_len; |
| 1676 | done = true; | 1676 | done = true; |
| 1677 | } | 1677 | } |
| @@ -1734,10 +1734,11 @@ void musb_host_rx(struct musb *musb, u8 epnum) · 56 unmodified lines | |||
| 1734 | } | 1734 | } |
| 1735 | 1735 | ||
| 1736 | } else { | 1736 | } else { |
| 1737 | /* done if urb buffer is full or short packet is recd */ | 1737 | /* done if urb buffer is full or short packet is recd */ |
| 1738 | done = (urb->actual_length + xfer_len >= | 1738 | done = (urb->actual_length + xfer_len >= |
| 1739 | urb->transfer_buffer_length | 1739 | urb->transfer_buffer_length |
| 1740 | || dma->actual_len < qh->maxpacket); | 1740 | || dma->actual_len < qh->maxpacket |
| 1741 | || dma->rx_packet_done); | ||
| 1741 | } | 1742 | } |
| 1742 | 1743 | ||
| 1743 | /* send IN token for next packet, without AUTOREQ */ | 1744 | /* send IN token for next packet, without AUTOREQ */ |
| @@ -1957,7 +1958,7 @@ static int musb_schedule( · 213 unmodified lines | |||
| 1957 | struct musb_qh *qh, | 1958 | struct musb_qh *qh, |
| 1958 | int is_in) | 1959 | int is_in) |
| 1959 | { | 1960 | { |
| 1960 | int idle; | 1961 | int idle = 0; |
| 1961 | int best_diff; | 1962 | int best_diff; |
| 1962 | int best_end, epnum; | 1963 | int best_end, epnum; |
| 1963 | struct musb_hw_ep *hw_ep = NULL; | 1964 | struct musb_hw_ep *hw_ep = NULL; |
| @@ -72,6 +72,12 @@ · 71 unmodified lines | |||
| 72 | #define MUSB_DEVCTL_HR 0x02 | 72 | #define MUSB_DEVCTL_HR 0x02 |
| 73 | #define MUSB_DEVCTL_SESSION 0x01 | 73 | #define MUSB_DEVCTL_SESSION 0x01 |
| 74 | 74 | ||
| 75 | /* BABBLE_CTL */ | ||
| 76 | #define MUSB_BABBLE_FORCE_TXIDLE 0x80 | ||
| 77 | #define MUSB_BABBLE_SW_SESSION_CTRL 0x40 | ||
| 78 | #define MUSB_BABBLE_STUCK_J 0x20 | ||
| 79 | #define MUSB_BABBLE_RCV_DISABLE 0x04 | ||
| 80 | |||
| 75 | /* MUSB ULPI VBUSCONTROL */ | 81 | /* MUSB ULPI VBUSCONTROL */ |
| 76 | #define MUSB_ULPI_USE_EXTVBUS 0x01 | 82 | #define MUSB_ULPI_USE_EXTVBUS 0x01 |
| 77 | #define MUSB_ULPI_USE_EXTVBUSIND 0x02 | 83 | #define MUSB_ULPI_USE_EXTVBUSIND 0x02 |
| @@ -246,6 +252,7 @@ · 168 unmodified lines | |||
| 246 | */ | 252 | */ |
| 247 | 253 | ||
| 248 | #define MUSB_DEVCTL 0x60 /* 8 bit */ | 254 | #define MUSB_DEVCTL 0x60 /* 8 bit */ |
| 255 | #define MUSB_BABBLE_CTL 0x61 /* 8 bit */ | ||
| 249 | 256 | ||
| 250 | /* These are always controlled through the INDEX register */ | 257 | /* These are always controlled through the INDEX register */ |
| 251 | #define MUSB_TXFIFOSZ 0x62 /* 8-bit (see masks) */ | 258 | #define MUSB_TXFIFOSZ 0x62 /* 8-bit (see masks) */ |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
| 23 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
| 24 | #include <linux/io.h> | 24 | #include <linux/io.h> |
| 25 | #include <linux/device.h> | ||
| 25 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
| 26 | #include <linux/dma-mapping.h> | 27 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/usb/usb_phy_generic.h> | 28 | #include <linux/usb/usb_phy_generic.h> |
| @@ -1160,12 +1161,12 @@ static int tusb_probe(struct platform_device *pdev) · 1132 unmodified lines | |||
| 1160 | struct platform_device *musb; | 1161 | struct platform_device *musb; |
| 1161 | struct tusb6010_glue *glue; | 1162 | struct tusb6010_glue *glue; |
| 1162 | struct platform_device_info pinfo; | 1163 | struct platform_device_info pinfo; |
| 1163 | int ret = -ENOMEM; | 1164 | int ret; |
| 1164 | 1165 | ||
| 1165 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 1166 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
| 1166 | if (!glue) { | 1167 | if (!glue) { |
| 1167 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | 1168 | dev_err(&pdev->dev, "failed to allocate glue context\n"); |
| 1168 | goto err0; | 1169 | return -ENOMEM; |
| 1169 | } | 1170 | } |
| 1170 | 1171 | ||
| 1171 | glue->dev = &pdev->dev; | 1172 | glue->dev = &pdev->dev; |
| @@ -1204,16 +1205,10 @@ static int tusb_probe(struct platform_device *pdev) · 32 unmodified lines | |||
| 1204 | if (IS_ERR(musb)) { | 1205 | if (IS_ERR(musb)) { |
| 1205 | ret = PTR_ERR(musb); | 1206 | ret = PTR_ERR(musb); |
| 1206 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); | 1207 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
| 1207 | goto err3; | 1208 | return ret; |
| 1208 | } | 1209 | } |
| 1209 | 1210 | ||
| 1210 | return 0; | 1211 | return 0; |
| 1211 | |||
| 1212 | err3: | ||
| 1213 | kfree(glue); | ||
| 1214 | |||
| 1215 | err0: | ||
| 1216 | return ret; | ||
| 1217 | } | 1212 | } |
| 1218 | 1213 | ||
| 1219 | static int tusb_remove(struct platform_device *pdev) | 1214 | static int tusb_remove(struct platform_device *pdev) |
| @@ -1222,7 +1217,6 @@ static int tusb_remove(struct platform_device *pdev) · 2 unmodified lines | |||
| 1222 | 1217 | ||
| 1223 | platform_device_unregister(glue->musb); | 1218 | platform_device_unregister(glue->musb); |
| 1224 | usb_phy_generic_unregister(glue->phy); | 1219 | usb_phy_generic_unregister(glue->phy); |
| 1225 | kfree(glue); | ||
| 1226 | 1220 | ||
| 1227 | return 0; | 1221 | return 0; |
| 1228 | } | 1222 | } |
| @@ -246,7 +246,7 @@ static int ux500_probe(struct platform_device *pdev) · 245 unmodified lines | |||
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 249 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
| 250 | if (!glue) { | 250 | if (!glue) { |
| 251 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | 251 | dev_err(&pdev->dev, "failed to allocate glue context\n"); |
| 252 | goto err0; | 252 | goto err0; |
| @@ -255,20 +255,20 @@ static int ux500_probe(struct platform_device *pdev) · 2 unmodified lines | |||
| 255 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | 255 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
| 256 | if (!musb) { | 256 | if (!musb) { |
| 257 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | 257 | dev_err(&pdev->dev, "failed to allocate musb device\n"); |
| 258 | goto err1; | 258 | goto err0; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | clk = clk_get(&pdev->dev, NULL); | 261 | clk = devm_clk_get(&pdev->dev, NULL); |
| 262 | if (IS_ERR(clk)) { | 262 | if (IS_ERR(clk)) { |
| 263 | dev_err(&pdev->dev, "failed to get clock\n"); | 263 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 264 | ret = PTR_ERR(clk); | 264 | ret = PTR_ERR(clk); |
| 265 | goto err3; | 265 | goto err1; |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | ret = clk_prepare_enable(clk); | 268 | ret = clk_prepare_enable(clk); |
| 269 | if (ret) { | 269 | if (ret) { |
| 270 | dev_err(&pdev->dev, "failed to enable clock\n"); | 270 | dev_err(&pdev->dev, "failed to enable clock\n"); |
| 271 | goto err4; | 271 | goto err1; |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | musb->dev.parent = &pdev->dev; | 274 | musb->dev.parent = &pdev->dev; |
| @@ -301,34 +301,28 @@ static int ux500_probe(struct platform_device *pdev) · 26 unmodified lines | |||
| 301 | ARRAY_SIZE(musb_resources)); | 301 | ARRAY_SIZE(musb_resources)); |
| 302 | if (ret) { | 302 | if (ret) { |
| 303 | dev_err(&pdev->dev, "failed to add resources\n"); | 303 | dev_err(&pdev->dev, "failed to add resources\n"); |
| 304 | goto err5; | 304 | goto err2; |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 307 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); |
| 308 | if (ret) { | 308 | if (ret) { |
| 309 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 309 | dev_err(&pdev->dev, "failed to add platform_data\n"); |
| 310 | goto err5; | 310 | goto err2; |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | ret = platform_device_add(musb); | 313 | ret = platform_device_add(musb); |
| 314 | if (ret) { | 314 | if (ret) { |
| 315 | dev_err(&pdev->dev, "failed to register musb device\n"); | 315 | dev_err(&pdev->dev, "failed to register musb device\n"); |
| 316 | goto err5; | 316 | goto err2; |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | return 0; | 319 | return 0; |
| 320 | 320 | ||
| 321 | err5: | 321 | err2: |
| 322 | clk_disable_unprepare(clk); | 322 | clk_disable_unprepare(clk); |
| 323 | 323 | ||
| 324 | err4: | ||
| 325 | clk_put(clk); | ||
| 326 | |||
| 327 | err3: | ||
| 328 | platform_device_put(musb); | ||
| 329 | |||
| 330 | err1: | 324 | err1: |
| 331 | kfree(glue); | 325 | platform_device_put(musb); |
| 332 | 326 | ||
| 333 | err0: | 327 | err0: |
| 334 | return ret; | 328 | return ret; |
| @@ -340,8 +334,6 @@ static int ux500_remove(struct platform_device *pdev) · 5 unmodified lines | |||
| 340 | 334 | ||
| 341 | platform_device_unregister(glue->musb); | 335 | platform_device_unregister(glue->musb); |
| 342 | clk_disable_unprepare(glue->clk); | 336 | clk_disable_unprepare(glue->clk); |
| 343 | clk_put(glue->clk); | ||
| 344 | kfree(glue); | ||
| 345 | 337 | ||
| 346 | return 0; | 338 | return 0; |
| 347 | } | 339 | } |
| @@ -122,16 +122,10 @@ static int am335x_phy_resume(struct device *dev) · 121 unmodified lines | |||
| 122 | 122 | ||
| 123 | return 0; | 123 | return 0; |
| 124 | } | 124 | } |
| 125 | |||
| 126 | static const struct dev_pm_ops am335x_pm_ops = { | ||
| 127 | SET_SYSTEM_SLEEP_PM_OPS(am335x_phy_suspend, am335x_phy_resume) | ||
| 128 | }; | ||
| 129 | |||
| 130 | #define DEV_PM_OPS (&am335x_pm_ops) | ||
| 131 | #else | ||
| 132 | #define DEV_PM_OPS NULL | ||
| 133 | #endif | 125 | #endif |
| 134 | 126 | ||
| 127 | static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume); | ||
| 128 | |||
| 135 | static const struct of_device_id am335x_phy_ids[] = { | 129 | static const struct of_device_id am335x_phy_ids[] = { |
| 136 | { .compatible = "ti,am335x-usb-phy" }, | 130 | { .compatible = "ti,am335x-usb-phy" }, |
| 137 | { } | 131 | { } |
| @@ -144,7 +138,7 @@ static struct platform_driver am335x_phy_driver = { · 6 unmodified lines | |||
| 144 | .driver = { | 138 | .driver = { |
| 145 | .name = "am335x-phy-driver", | 139 | .name = "am335x-phy-driver", |
| 146 | .owner = THIS_MODULE, | 140 | .owner = THIS_MODULE, |
| 147 | .pm = DEV_PM_OPS, | 141 | .pm = &am335x_pm_ops, |
| 148 | .of_match_table = am335x_phy_ids, | 142 | .of_match_table = am335x_phy_ids, |
| 149 | }, | 143 | }, |
| 150 | }; | 144 | }; |
| @@ -253,11 +253,13 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 252 unmodified lines | |||
| 253 | return -EINVAL; | 253 | return -EINVAL; |
| 254 | gpio = pdata->gpio_vbus; | 254 | gpio = pdata->gpio_vbus; |
| 255 | 255 | ||
| 256 | gpio_vbus = kzalloc(sizeof(struct gpio_vbus_data), GFP_KERNEL); | 256 | gpio_vbus = devm_kzalloc(&pdev->dev, sizeof(struct gpio_vbus_data), |
| 257 | GFP_KERNEL); | ||
| 257 | if (!gpio_vbus) | 258 | if (!gpio_vbus) |
| 258 | return -ENOMEM; | 259 | return -ENOMEM; |
| 259 | 260 | ||
| 260 | gpio_vbus->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); | 261 | gpio_vbus->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), |
| 262 | GFP_KERNEL); | ||
| 261 | if (!gpio_vbus->phy.otg) { | 263 | if (!gpio_vbus->phy.otg) { |
| 262 | kfree(gpio_vbus); | 264 | kfree(gpio_vbus); |
| 263 | return -ENOMEM; | 265 | return -ENOMEM; |
| @@ -274,11 +276,11 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 10 unmodified lines | |||
| 274 | gpio_vbus->phy.otg->phy = &gpio_vbus->phy; | 276 | gpio_vbus->phy.otg->phy = &gpio_vbus->phy; |
| 275 | gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; | 277 | gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; |
| 276 | 278 | ||
| 277 | err = gpio_request(gpio, "vbus_detect"); | 279 | err = devm_gpio_request(&pdev->dev, gpio, "vbus_detect"); |
| 278 | if (err) { | 280 | if (err) { |
| 279 | dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", | 281 | dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", |
| 280 | gpio, err); | 282 | gpio, err); |
| 281 | goto err_gpio; | 283 | return err; |
| 282 | } | 284 | } |
| 283 | gpio_direction_input(gpio); | 285 | gpio_direction_input(gpio); |
| 284 | 286 | ||
| @@ -296,27 +298,27 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 11 unmodified lines | |||
| 296 | /* if data line pullup is in use, initialize it to "not pulling up" */ | 298 | /* if data line pullup is in use, initialize it to "not pulling up" */ |
| 297 | gpio = pdata->gpio_pullup; | 299 | gpio = pdata->gpio_pullup; |
| 298 | if (gpio_is_valid(gpio)) { | 300 | if (gpio_is_valid(gpio)) { |
| 299 | err = gpio_request(gpio, "udc_pullup"); | 301 | err = devm_gpio_request(&pdev->dev, gpio, "udc_pullup"); |
| 300 | if (err) { | 302 | if (err) { |
| 301 | dev_err(&pdev->dev, | 303 | dev_err(&pdev->dev, |
| 302 | "can't request pullup gpio %d, err: %d\n", | 304 | "can't request pullup gpio %d, err: %d\n", |
| 303 | gpio, err); | 305 | gpio, err); |
| 304 | gpio_free(pdata->gpio_vbus); | 306 | return err; |
| 305 | goto err_gpio; | ||
| 306 | } | 307 | } |
| 307 | gpio_direction_output(gpio, pdata->gpio_pullup_inverted); | 308 | gpio_direction_output(gpio, pdata->gpio_pullup_inverted); |
| 308 | } | 309 | } |
| 309 | 310 | ||
| 310 | err = request_irq(irq, gpio_vbus_irq, irqflags, "vbus_detect", pdev); | 311 | err = devm_request_irq(&pdev->dev, irq, gpio_vbus_irq, irqflags, |
| 312 | "vbus_detect", pdev); | ||
| 311 | if (err) { | 313 | if (err) { |
| 312 | dev_err(&pdev->dev, "can't request irq %i, err: %d\n", | 314 | dev_err(&pdev->dev, "can't request irq %i, err: %d\n", |
| 313 | irq, err); | 315 | irq, err); |
| 314 | goto err_irq; | 316 | return err; |
| 315 | } | 317 | } |
| 316 | 318 | ||
| 317 | INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); | 319 | INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); |
| 318 | 320 | ||
| 319 | gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); | 321 | gpio_vbus->vbus_draw = devm_regulator_get(&pdev->dev, "vbus_draw"); |
| 320 | if (IS_ERR(gpio_vbus->vbus_draw)) { | 322 | if (IS_ERR(gpio_vbus->vbus_draw)) { |
| 321 | dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n", | 323 | dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n", |
| 322 | PTR_ERR(gpio_vbus->vbus_draw)); | 324 | PTR_ERR(gpio_vbus->vbus_draw)); |
| @@ -328,44 +330,23 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 5 unmodified lines | |||
| 328 | if (err) { | 330 | if (err) { |
| 329 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", | 331 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", |
| 330 | err); | 332 | err); |
| 331 | goto err_otg; | 333 | return err; |
| 332 | } | 334 | } |
| 333 | 335 | ||
| 334 | device_init_wakeup(&pdev->dev, pdata->wakeup); | 336 | device_init_wakeup(&pdev->dev, pdata->wakeup); |
| 335 | 337 | ||
| 336 | return 0; | 338 | return 0; |
| 337 | err_otg: | ||
| 338 | regulator_put(gpio_vbus->vbus_draw); | ||
| 339 | free_irq(irq, pdev); | ||
| 340 | err_irq: | ||
| 341 | if (gpio_is_valid(pdata->gpio_pullup)) | ||
| 342 | gpio_free(pdata->gpio_pullup); | ||
| 343 | gpio_free(pdata->gpio_vbus); | ||
| 344 | err_gpio: | ||
| 345 | kfree(gpio_vbus->phy.otg); | ||
| 346 | kfree(gpio_vbus); | ||
| 347 | return err; | ||
| 348 | } | 339 | } |
| 349 | 340 | ||
| 350 | static int gpio_vbus_remove(struct platform_device *pdev) | 341 | static int gpio_vbus_remove(struct platform_device *pdev) |
| 351 | { | 342 | { |
| 352 | struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); | 343 | struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); |
| 353 | struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev); | ||
| 354 | int gpio = pdata->gpio_vbus; | ||
| 355 | 344 | ||
| 356 | device_init_wakeup(&pdev->dev, 0); | 345 | device_init_wakeup(&pdev->dev, 0); |
| 357 | cancel_delayed_work_sync(&gpio_vbus->work); | 346 | cancel_delayed_work_sync(&gpio_vbus->work); |
| 358 | regulator_put(gpio_vbus->vbus_draw); | ||
| 359 | 347 | ||
| 360 | usb_remove_phy(&gpio_vbus->phy); | 348 | usb_remove_phy(&gpio_vbus->phy); |
| 361 | 349 | ||
| 362 | free_irq(gpio_vbus->irq, pdev); | ||
| 363 | if (gpio_is_valid(pdata->gpio_pullup)) | ||
| 364 | gpio_free(pdata->gpio_pullup); | ||
| 365 | gpio_free(gpio); | ||
| 366 | kfree(gpio_vbus->phy.otg); | ||
| 367 | kfree(gpio_vbus); | ||
| 368 | |||
| 369 | return 0; | 350 | return 0; |
| 370 | } | 351 | } |
| 371 | 352 | ||
| @@ -279,11 +279,11 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) · 278 unmodified lines | |||
| 279 | 279 | ||
| 280 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) | 280 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) |
| 281 | { | 281 | { |
| 282 | int ret; | 282 | int ret = 0; |
| 283 | 283 | ||
| 284 | if (motg->pdata->phy_clk_reset) | 284 | if (motg->pdata->phy_clk_reset && motg->phy_reset_clk) |
| 285 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); | 285 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); |
| 286 | else | 286 | else if (motg->phy_rst) |
| 287 | ret = reset_control_reset(motg->phy_rst); | 287 | ret = reset_control_reset(motg->phy_rst); |
| 288 | 288 | ||
| 289 | if (ret) | 289 | if (ret) |
| @@ -1429,7 +1429,7 @@ static void msm_otg_debugfs_cleanup(void) · 1139 unmodified lines | |||
| 1429 | debugfs_remove(msm_otg_dbg_root); | 1429 | debugfs_remove(msm_otg_dbg_root); |
| 1430 | } | 1430 | } |
| 1431 | 1431 | ||
| 1432 | static struct of_device_id msm_otg_dt_match[] = { | 1432 | static const struct of_device_id msm_otg_dt_match[] = { |
| 1433 | { | 1433 | { |
| 1434 | .compatible = "qcom,usb-otg-ci", | 1434 | .compatible = "qcom,usb-otg-ci", |
| 1435 | .data = (void *) CI_45NM_INTEGRATED_PHY | 1435 | .data = (void *) CI_45NM_INTEGRATED_PHY |
| @@ -1466,7 +1466,7 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) · 30 unmodified lines | |||
| 1466 | 1466 | ||
| 1467 | motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy"); | 1467 | motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy"); |
| 1468 | if (IS_ERR(motg->phy_rst)) | 1468 | if (IS_ERR(motg->phy_rst)) |
| 1469 | return PTR_ERR(motg->phy_rst); | 1469 | motg->phy_rst = NULL; |
| 1470 | 1470 | ||
| 1471 | pdata->mode = of_usb_get_dr_mode(node); | 1471 | pdata->mode = of_usb_get_dr_mode(node); |
| 1472 | if (pdata->mode == USB_DR_MODE_UNKNOWN) | 1472 | if (pdata->mode == USB_DR_MODE_UNKNOWN) |
| @@ -1558,7 +1558,7 @@ static int msm_otg_probe(struct platform_device *pdev) · 85 unmodified lines | |||
| 1558 | np ? "phy" : "usb_phy_clk"); | 1558 | np ? "phy" : "usb_phy_clk"); |
| 1559 | if (IS_ERR(motg->phy_reset_clk)) { | 1559 | if (IS_ERR(motg->phy_reset_clk)) { |
| 1560 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); | 1560 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); |
| 1561 | return PTR_ERR(motg->phy_reset_clk); | 1561 | motg->phy_reset_clk = NULL; |
| 1562 | } | 1562 | } |
| 1563 | 1563 | ||
| 1564 | motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); | 1564 | motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); |
| @@ -33,7 +33,6 @@ · 32 unmodified lines | |||
| 33 | #include <linux/usb/otg.h> | 33 | #include <linux/usb/otg.h> |
| 34 | #include <linux/usb/ulpi.h> | 34 | #include <linux/usb/ulpi.h> |
| 35 | #include <linux/usb/of.h> | 35 | #include <linux/usb/of.h> |
| 36 | #include <asm/mach-types.h> | ||
| 37 | #include <linux/usb/ehci_def.h> | 36 | #include <linux/usb/ehci_def.h> |
| 38 | #include <linux/usb/tegra_usb_phy.h> | 37 | #include <linux/usb/tegra_usb_phy.h> |
| 39 | #include <linux/regulator/consumer.h> | 38 | #include <linux/regulator/consumer.h> |
| @@ -686,10 +685,8 @@ static int ulpi_phy_power_off(struct tegra_usb_phy *phy) · 646 unmodified lines | |||
| 686 | return gpio_direction_output(phy->reset_gpio, 0); | 685 | return gpio_direction_output(phy->reset_gpio, 0); |
| 687 | } | 686 | } |
| 688 | 687 | ||
| 689 | static void tegra_usb_phy_close(struct usb_phy *x) | 688 | static void tegra_usb_phy_close(struct tegra_usb_phy *phy) |
| 690 | { | 689 | { |
| 691 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); | ||
| 692 | |||
| 693 | if (!IS_ERR(phy->vbus)) | 690 | if (!IS_ERR(phy->vbus)) |
| 694 | regulator_disable(phy->vbus); | 691 | regulator_disable(phy->vbus); |
| 695 | 692 | ||
| @@ -965,7 +962,7 @@ static const struct tegra_phy_soc_config tegra30_soc_config = { · 269 unmodified lines | |||
| 965 | .requires_extra_tuning_parameters = true, | 962 | .requires_extra_tuning_parameters = true, |
| 966 | }; | 963 | }; |
| 967 | 964 | ||
| 968 | static struct of_device_id tegra_usb_phy_id_table[] = { | 965 | static const struct of_device_id tegra_usb_phy_id_table[] = { |
| 969 | { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config }, | 966 | { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config }, |
| 970 | { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config }, | 967 | { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config }, |
| 971 | { }, | 968 | { }, |
| @@ -1061,14 +1058,13 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) · 89 unmodified lines | |||
| 1061 | if (err < 0) | 1058 | if (err < 0) |
| 1062 | return err; | 1059 | return err; |
| 1063 | 1060 | ||
| 1064 | tegra_phy->u_phy.shutdown = tegra_usb_phy_close; | ||
| 1065 | tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend; | 1061 | tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend; |
| 1066 | 1062 | ||
| 1067 | platform_set_drvdata(pdev, tegra_phy); | 1063 | platform_set_drvdata(pdev, tegra_phy); |
| 1068 | 1064 | ||
| 1069 | err = usb_add_phy_dev(&tegra_phy->u_phy); | 1065 | err = usb_add_phy_dev(&tegra_phy->u_phy); |
| 1070 | if (err < 0) { | 1066 | if (err < 0) { |
| 1071 | tegra_usb_phy_close(&tegra_phy->u_phy); | 1067 | tegra_usb_phy_close(tegra_phy); |
| 1072 | return err; | 1068 | return err; |
| 1073 | } | 1069 | } |
| 1074 | 1070 | ||
| @@ -1080,6 +1076,7 @@ static int tegra_usb_phy_remove(struct platform_device *pdev) · 5 unmodified lines | |||
| 1080 | struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev); | 1076 | struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev); |
| 1081 | 1077 | ||
| 1082 | usb_remove_phy(&tegra_phy->u_phy); | 1078 | usb_remove_phy(&tegra_phy->u_phy); |
| 1079 | tegra_usb_phy_close(tegra_phy); | ||
| 1083 | 1080 | ||
| 1084 | return 0; | 1081 | return 0; |
| 1085 | } | 1082 | } |
| @@ -4,7 +4,7 @@ · 3 unmodified lines | |||
| 4 | 4 | ||
| 5 | obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o | 5 | obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o |
| 6 | 6 | ||
| 7 | renesas_usbhs-y := common.o mod.o pipe.o fifo.o | 7 | renesas_usbhs-y := common.o mod.o pipe.o fifo.o rcar2.o |
| 8 | 8 | ||
| 9 | ifneq ($(CONFIG_USB_RENESAS_USBHS_HCD),) | 9 | ifneq ($(CONFIG_USB_RENESAS_USBHS_HCD),) |
| 10 | renesas_usbhs-y += mod_host.o | 10 | renesas_usbhs-y += mod_host.o |
| @@ -15,12 +15,14 @@ · 14 unmodified lines | |||
| 15 | * | 15 | * |
| 16 | */ | 16 | */ |
| 17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
| 18 | #include <linux/gpio.h> | ||
| 18 | #include <linux/io.h> | 19 | #include <linux/io.h> |
| 19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
111 more lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 32 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 78 lines aren’t shown here.
This diff is large: its 5 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 156 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
This diff is large: its 51 lines aren’t shown here.
This diff is large: its 12 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 15 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 22 lines aren’t shown here.
This diff is large: its 16 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 200 lines aren’t shown here.
This diff is large: its 28 lines aren’t shown here.
This diff is large: its 115 lines aren’t shown here.
This diff is large: its 66 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.
This diff is large: its 66 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.