Kishon writes: phy: for 5.2 *) Add a new *release* phy_ops invoked when the consumer relinquishes PHY that can be used to undo the operation performed in xlate *) Add new driver to support USB2 PHY and shared USB3 + PCIE PHY in Amlogic G12A SoC Family. *) Add new driver to support for Broadcom's Stingray USB PHY (Type 1 has one super speed PHY and one high speed PHY, Type 2 has one high speed PHY) *) Add new driver to support USB PHY in hi3660 SoC of Hisilicon *) Add new driver to support UFS M-PHY in MediaTek SoC *) Add new driver to support XUSB pad controller in Tegra186 SoCs *) Add new driver to support SERDES in TI's AM654 platform *) Add support for generation 2 USB2 PHY and gneration 3 USB2 PHY in r8a77470 to phy-rcar-gen2.c and phy-rcar-gen3-usb2.c respectively *) Add support for PCIe QMP PHY support in msm8998 to phy-qcom-qmp.c *) Add support for SERDES6G in phy-ocelot-serdes.c *) Add support to set drive impedance from device tree in phy-rockchip-emmc.c *) Add support to power up/down the VBUS voltage rail in phy-fsl-imx8mq-usb.c *) Add support to shut off regulators that power UFS during system suspend *) Re-design phy-rcar-gen3-usb2.c to create separate PHY instances for each channel which helps to enable/disable interrupts for each instance independently *) Fix PCIe power up sequence to follow the TRM in order to ensure the DPLL & PHY operates correctly over the entire temperature range. *) Use devm_clk_get_optional to get optional clocks instead of adding custom error checks Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> * tag 'phy-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy: (51 commits) dt-bindings: phy-qcom-qmp: Tweak qcom,msm8998-qmp-ufs-phy dt-bindings: phy-qcom-qmp: Add qcom,msm8998-qmp-pcie-phy phy: Add usb phy support for hi3660 Soc of Hisilicon dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY scsi: phy: mediatek: fix typo in author's email address phy: ocelot-serdes: Add support for SERDES6G muxing phy: fsl-imx8mq-usb: add support for VBUS power control dt-bindings: phy-imx8mq-usb: add optional vbus supply regulator phy: qcom-qmp: Add msm8998 PCIe QMP PHY support phy: ti: am654-serdes: Support all clksel values phy: ti: Add a new SERDES driver for TI's AM654x SoC dt-bindings: phy: ti: Add dt binding documentation for SERDES in AM654x SoC phy: core: Invoke pm_runtime_get_*/pm_runtime_put_* before invoking reset callback phy: core: Add *release* phy_ops invoked when the consumer relinquishes PHY phy: phy-meson-gxl-usb2: get optional clock by devm_clk_get_optional() phy: socionext: get optional clock by devm_clk_get_optional() phy: qcom-qusb2: get optional clock by devm_clk_get_optional() phy: phy-mtk-tphy: get optional clock by devm_clk_get_optional() phy: renesas: rcar-gen3-usb2: enable/disable independent irqs phy: renesas: rcar-gen3-usb2: Use pdev's device pointer on dev_vdbg() ...
Unified · Split
| @@ -0,0 +1,32 @@ | |||
| 1 | Broadcom Stingray USB PHY | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible : should be one of the listed compatibles | ||
| 5 | - "brcm,sr-usb-combo-phy" is combo PHY has two PHYs, one SS and one HS. | ||
| 6 | - "brcm,sr-usb-hs-phy" is a single HS PHY. | ||
| 7 | - reg: offset and length of the PHY blocks registers | ||
| 8 | - #phy-cells: | ||
| 9 | - Must be 1 for brcm,sr-usb-combo-phy as it expects one argument to indicate | ||
| 10 | the PHY number of two PHYs. 0 for HS PHY and 1 for SS PHY. | ||
| 11 | - Must be 0 for brcm,sr-usb-hs-phy. | ||
| 12 | |||
| 13 | Refer to phy/phy-bindings.txt for the generic PHY binding properties | ||
| 14 | |||
| 15 | Example: | ||
| 16 | usbphy0: usb-phy@0 { | ||
| 17 | compatible = "brcm,sr-usb-combo-phy"; | ||
| 18 | reg = <0x00000000 0x100>; | ||
| 19 | #phy-cells = <1>; | ||
| 20 | }; | ||
| 21 | |||
| 22 | usbphy1: usb-phy@10000 { | ||
| 23 | compatible = "brcm,sr-usb-combo-phy"; | ||
| 24 | reg = <0x00010000 0x100>, | ||
| 25 | #phy-cells = <1>; | ||
| 26 | }; | ||
| 27 | |||
| 28 | usbphy2: usb-phy@20000 { | ||
| 29 | compatible = "brcm,sr-usb-hs-phy"; | ||
| 30 | reg = <0x00020000 0x100>, | ||
| 31 | #phy-cells = <0>; | ||
| 32 | }; | ||
| @@ -7,6 +7,9 @@ Required properties: · 6 unmodified lines | |||
| 7 | - clocks: phandles to the clocks for each clock listed in clock-names | 7 | - clocks: phandles to the clocks for each clock listed in clock-names |
| 8 | - clock-names: must contain "phy" | 8 | - clock-names: must contain "phy" |
| 9 | 9 | ||
| 10 | Optional properties: | ||
| 11 | - vbus-supply: A phandle to the regulator for USB VBUS. | ||
| 12 | |||
| 10 | Example: | 13 | Example: |
| 11 | usb3_phy0: phy@381f0040 { | 14 | usb3_phy0: phy@381f0040 { |
| 12 | compatible = "fsl,imx8mq-usb-phy"; | 15 | compatible = "fsl,imx8mq-usb-phy"; |
| @@ -0,0 +1,22 @@ | |||
| 1 | * Amlogic G12A USB2 PHY binding | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: Should be "amlogic,meson-g12a-usb2-phy" | ||
| 5 | - reg: The base address and length of the registers | ||
| 6 | - #phys-cells: must be 0 (see phy-bindings.txt in this directory) | ||
| 7 | - clocks: a phandle to the clock of this PHY | ||
| 8 | - clock-names: must be "xtal" | ||
| 9 | - resets: a phandle to the reset line of this PHY | ||
| 10 | - reset-names: must be "phy" | ||
| 11 | - phy-supply: see phy-bindings.txt in this directory | ||
| 12 | |||
| 13 | Example: | ||
| 14 | usb2_phy0: phy@36000 { | ||
| 15 | compatible = "amlogic,g12a-usb2-phy"; | ||
| 16 | reg = <0x0 0x36000 0x0 0x2000>; | ||
| 17 | clocks = <&xtal>; | ||
| 18 | clock-names = "xtal"; | ||
| 19 | resets = <&reset RESET_USB_PHY21>; | ||
| 20 | reset-names = "phy"; | ||
| 21 | #phy-cells = <0>; | ||
| 22 | }; | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | * Amlogic G12A USB3 + PCIE Combo PHY binding | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: Should be "amlogic,meson-g12a-usb3-pcie-phy" | ||
| 5 | - #phys-cells: must be 1. The cell number is used to select the phy mode | ||
| 6 | as defined in <dt-bindings/phy/phy.h> between PHY_TYPE_USB3 and PHY_TYPE_PCIE | ||
| 7 | - reg: The base address and length of the registers | ||
| 8 | - clocks: a phandle to the 100MHz reference clock of this PHY | ||
| 9 | - clock-names: must be "ref_clk" | ||
| 10 | - resets: phandle to the reset lines for the PHY control | ||
| 11 | - reset-names: must be "phy" | ||
| 12 | |||
| 13 | Example: | ||
| 14 | usb3_pcie_phy: phy@46000 { | ||
| 15 | compatible = "amlogic,g12a-usb3-pcie-phy"; | ||
| 16 | reg = <0x0 0x46000 0x0 0x2000>; | ||
| 17 | clocks = <&clkc CLKID_PCIE_PLL>; | ||
| 18 | clock-names = "ref_clk"; | ||
| 19 | resets = <&reset RESET_PCIE_PHY>; | ||
| 20 | reset-names = "phy"; | ||
| 21 | #phy-cells = <1>; | ||
| 22 | }; | ||
| @@ -36,11 +36,20 @@ Required properties: · 35 unmodified lines | |||
| 36 | - Tegra124: "nvidia,tegra124-xusb-padctl" | 36 | - Tegra124: "nvidia,tegra124-xusb-padctl" |
| 37 | - Tegra132: "nvidia,tegra132-xusb-padctl", "nvidia,tegra124-xusb-padctl" | 37 | - Tegra132: "nvidia,tegra132-xusb-padctl", "nvidia,tegra124-xusb-padctl" |
| 38 | - Tegra210: "nvidia,tegra210-xusb-padctl" | 38 | - Tegra210: "nvidia,tegra210-xusb-padctl" |
| 39 | - Tegra186: "nvidia,tegra186-xusb-padctl" | ||
| 39 | - reg: Physical base address and length of the controller's registers. | 40 | - reg: Physical base address and length of the controller's registers. |
| 40 | - resets: Must contain an entry for each entry in reset-names. | 41 | - resets: Must contain an entry for each entry in reset-names. |
| 41 | - reset-names: Must include the following entries: | 42 | - reset-names: Must include the following entries: |
| 42 | - "padctl" | 43 | - "padctl" |
| 43 | 44 | ||
| 45 | For Tegra186: | ||
| 46 | - avdd-pll-erefeut-supply: UPHY brick and reference clock as well as UTMI PHY | ||
| 47 | power supply. Must supply 1.8 V. | ||
| 48 | - avdd-usb-supply: USB I/Os, VBUS, ID, REXT, D+/D- power supply. Must supply | ||
| 49 | 3.3 V. | ||
| 50 | - vclamp-usb-supply: Bias rail for USB pad. Must supply 1.8 V. | ||
| 51 | - vddio-hsic-supply: HSIC PHY power supply. Must supply 1.2 V. | ||
| 52 | |||
| 44 | 53 | ||
| 45 | Pad nodes: | 54 | Pad nodes: |
| 46 | ========== | 55 | ========== |
| @@ -0,0 +1,26 @@ | |||
| 1 | Hisilicon hi3660 USB PHY | ||
| 2 | ----------------------- | ||
| 3 | |||
| 4 | Required properties: | ||
| 5 | - compatible: should be "hisilicon,hi3660-usb-phy" | ||
| 6 | - #phy-cells: must be 0 | ||
| 7 | - hisilicon,pericrg-syscon: phandle of syscon used to control phy. | ||
| 8 | - hisilicon,pctrl-syscon: phandle of syscon used to control phy. | ||
| 9 | - hisilicon,eye-diagram-param: parameter set for phy | ||
| 10 | Refer to phy/phy-bindings.txt for the generic PHY binding properties | ||
| 11 | |||
| 12 | This is a subnode of usb3_otg_bc register node. | ||
| 13 | |||
| 14 | Example: | ||
| 15 | usb3_otg_bc: usb3_otg_bc@ff200000 { | ||
| 16 | compatible = "syscon", "simple-mfd"; | ||
| 17 | reg = <0x0 0xff200000 0x0 0x1000>; | ||
| 18 | |||
| 19 | usb-phy { | ||
| 20 | compatible = "hisilicon,hi3660-usb-phy"; | ||
| 21 | #phy-cells = <0>; | ||
| 22 | hisilicon,pericrg-syscon = <&crg_ctrl>; | ||
| 23 | hisilicon,pctrl-syscon = <&pctrl>; | ||
| 24 | hisilicon,eye-diagram-param = <0x22466e4>; | ||
| 25 | }; | ||
| 26 | }; | ||
| @@ -0,0 +1,38 @@ | |||
| 1 | MediaTek Universal Flash Storage (UFS) M-PHY binding | ||
| 2 | -------------------------------------------------------- | ||
| 3 | |||
| 4 | UFS M-PHY nodes are defined to describe on-chip UFS M-PHY hardware macro. | ||
| 5 | Each UFS M-PHY node should have its own node. | ||
| 6 | |||
| 7 | To bind UFS M-PHY with UFS host controller, the controller node should | ||
| 8 | contain a phandle reference to UFS M-PHY node. | ||
| 9 | |||
| 10 | Required properties for UFS M-PHY nodes: | ||
| 11 | - compatible : Compatible list, contains the following controller: | ||
| 12 | "mediatek,mt8183-ufsphy" for ufs phy | ||
| 13 | persent on MT81xx chipsets. | ||
| 14 | - reg : Address and length of the UFS M-PHY register set. | ||
| 15 | - #phy-cells : This property shall be set to 0. | ||
| 16 | - clocks : List of phandle and clock specifier pairs. | ||
| 17 | - clock-names : List of clock input name strings sorted in the same | ||
| 18 | order as the clocks property. Following clocks are | ||
| 19 | mandatory. | ||
| 20 | "unipro": Unipro core control clock. | ||
| 21 | "mp": M-PHY core control clock. | ||
| 22 | |||
| 23 | Example: | ||
| 24 | |||
| 25 | ufsphy: phy@11fa0000 { | ||
| 26 | compatible = "mediatek,mt8183-ufsphy"; | ||
| 27 | reg = <0 0x11fa0000 0 0xc000>; | ||
| 28 | #phy-cells = <0>; | ||
| 29 | |||
| 30 | clocks = <&infracfg_ao INFRACFG_AO_UNIPRO_SCK_CG>, | ||
| 31 | <&infracfg_ao INFRACFG_AO_UFS_MP_SAP_BCLK_CG>; | ||
| 32 | clock-names = "unipro", "mp"; | ||
| 33 | }; | ||
| 34 | |||
| 35 | ufshci@11270000 { | ||
| 36 | ... | ||
| 37 | phys = <&ufsphy>; | ||
| 38 | }; | ||
| @@ -11,6 +11,7 @@ Required properties: · 10 unmodified lines | |||
| 11 | "qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996, | 11 | "qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996, |
| 12 | "qcom,msm8998-qmp-usb3-phy" for USB3 QMP V3 phy on msm8998, | 12 | "qcom,msm8998-qmp-usb3-phy" for USB3 QMP V3 phy on msm8998, |
| 13 | "qcom,msm8998-qmp-ufs-phy" for UFS QMP phy on msm8998, | 13 | "qcom,msm8998-qmp-ufs-phy" for UFS QMP phy on msm8998, |
| 14 | "qcom,msm8998-qmp-pcie-phy" for PCIe QMP phy on msm8998, | ||
| 14 | "qcom,sdm845-qmp-usb3-phy" for USB3 QMP V3 phy on sdm845, | 15 | "qcom,sdm845-qmp-usb3-phy" for USB3 QMP V3 phy on sdm845, |
| 15 | "qcom,sdm845-qmp-usb3-uni-phy" for USB3 QMP V3 UNI phy on sdm845, | 16 | "qcom,sdm845-qmp-usb3-uni-phy" for USB3 QMP V3 UNI phy on sdm845, |
| 16 | "qcom,sdm845-qmp-ufs-phy" for UFS QMP phy on sdm845. | 17 | "qcom,sdm845-qmp-ufs-phy" for UFS QMP phy on sdm845. |
| @@ -48,6 +49,8 @@ Required properties: · 31 unmodified lines | |||
| 48 | "aux", "cfg_ahb", "ref". | 49 | "aux", "cfg_ahb", "ref". |
| 49 | For "qcom,msm8998-qmp-ufs-phy" must contain: | 50 | For "qcom,msm8998-qmp-ufs-phy" must contain: |
| 50 | "ref", "ref_aux". | 51 | "ref", "ref_aux". |
| 52 | For "qcom,msm8998-qmp-pcie-phy" must contain: | ||
| 53 | "aux", "cfg_ahb", "ref". | ||
| 51 | For "qcom,sdm845-qmp-usb3-phy" must contain: | 54 | For "qcom,sdm845-qmp-usb3-phy" must contain: |
| 52 | "aux", "cfg_ahb", "ref", "com_aux". | 55 | "aux", "cfg_ahb", "ref", "com_aux". |
| 53 | For "qcom,sdm845-qmp-usb3-uni-phy" must contain: | 56 | For "qcom,sdm845-qmp-usb3-uni-phy" must contain: |
| @@ -59,7 +62,8 @@ Required properties: · 5 unmodified lines | |||
| 59 | one for each entry in reset-names. | 62 | one for each entry in reset-names. |
| 60 | - reset-names: "phy" for reset of phy block, | 63 | - reset-names: "phy" for reset of phy block, |
| 61 | "common" for phy common block reset, | 64 | "common" for phy common block reset, |
| 62 | "cfg" for phy's ahb cfg block reset. | 65 | "cfg" for phy's ahb cfg block reset, |
| 66 | "ufsphy" for the PHY reset in the UFS controller. | ||
| 63 | 67 | ||
| 64 | For "qcom,ipq8074-qmp-pcie-phy" must contain: | 68 | For "qcom,ipq8074-qmp-pcie-phy" must contain: |
| 65 | "phy", "common". | 69 | "phy", "common". |
| @@ -69,12 +73,16 @@ Required properties: · 3 unmodified lines | |||
| 69 | "phy", "common". | 73 | "phy", "common". |
| 70 | For "qcom,msm8998-qmp-usb3-phy" must contain | 74 | For "qcom,msm8998-qmp-usb3-phy" must contain |
| 71 | "phy", "common". | 75 | "phy", "common". |
| 72 | For "qcom,msm8998-qmp-ufs-phy": no resets are listed. | 76 | For "qcom,msm8998-qmp-ufs-phy": must contain: |
| 77 | "ufsphy". | ||
| 78 | For "qcom,msm8998-qmp-pcie-phy" must contain: | ||
| 79 | "phy", "common". | ||
| 73 | For "qcom,sdm845-qmp-usb3-phy" must contain: | 80 | For "qcom,sdm845-qmp-usb3-phy" must contain: |
| 74 | "phy", "common". | 81 | "phy", "common". |
| 75 | For "qcom,sdm845-qmp-usb3-uni-phy" must contain: | 82 | For "qcom,sdm845-qmp-usb3-uni-phy" must contain: |
| 76 | "phy", "common". | 83 | "phy", "common". |
| 77 | For "qcom,sdm845-qmp-ufs-phy": no resets are listed. | 84 | For "qcom,sdm845-qmp-ufs-phy": must contain: |
| 85 | "ufsphy". | ||
| 78 | 86 | ||
| 79 | - vdda-phy-supply: Phandle to a regulator supply to PHY core block. | 87 | - vdda-phy-supply: Phandle to a regulator supply to PHY core block. |
| 80 | - vdda-pll-supply: Phandle to 1.8V regulator supply to PHY refclk pll block. | 88 | - vdda-pll-supply: Phandle to 1.8V regulator supply to PHY refclk pll block. |
| @@ -7,6 +7,7 @@ Required properties: · 6 unmodified lines | |||
| 7 | - compatible: "renesas,usb-phy-r8a7743" if the device is a part of R8A7743 SoC. | 7 | - compatible: "renesas,usb-phy-r8a7743" if the device is a part of R8A7743 SoC. |
| 8 | "renesas,usb-phy-r8a7744" if the device is a part of R8A7744 SoC. | 8 | "renesas,usb-phy-r8a7744" if the device is a part of R8A7744 SoC. |
| 9 | "renesas,usb-phy-r8a7745" if the device is a part of R8A7745 SoC. | 9 | "renesas,usb-phy-r8a7745" if the device is a part of R8A7745 SoC. |
| 10 | "renesas,usb-phy-r8a77470" if the device is a part of R8A77470 SoC. | ||
| 10 | "renesas,usb-phy-r8a7790" if the device is a part of R8A7790 SoC. | 11 | "renesas,usb-phy-r8a7790" if the device is a part of R8A7790 SoC. |
| 11 | "renesas,usb-phy-r8a7791" if the device is a part of R8A7791 SoC. | 12 | "renesas,usb-phy-r8a7791" if the device is a part of R8A7791 SoC. |
| 12 | "renesas,usb-phy-r8a7794" if the device is a part of R8A7794 SoC. | 13 | "renesas,usb-phy-r8a7794" if the device is a part of R8A7794 SoC. |
| @@ -30,7 +31,7 @@ channels. These subnodes must contain the following properties: · 17 unmodified lines | |||
| 30 | - #phy-cells: see phy-bindings.txt in the same directory, must be <1>. | 31 | - #phy-cells: see phy-bindings.txt in the same directory, must be <1>. |
| 31 | 32 | ||
| 32 | The phandle's argument in the PHY specifier is the USB controller selector for | 33 | The phandle's argument in the PHY specifier is the USB controller selector for |
| 33 | the USB channel; see the selector meanings below: | 34 | the USB channel other than r8a77470 SoC; see the selector meanings below: |
| 34 | 35 | ||
| 35 | +-----------+---------------+---------------+ | 36 | +-----------+---------------+---------------+ |
| 36 | |\ Selector | | | | 37 | |\ Selector | | | |
| @@ -41,6 +42,16 @@ the USB channel; see the selector meanings below: · 4 unmodified lines | |||
| 41 | | 2 | PCI EHCI/OHCI | xHCI | | 42 | | 2 | PCI EHCI/OHCI | xHCI | |
| 42 | +-----------+---------------+---------------+ | 43 | +-----------+---------------+---------------+ |
| 43 | 44 | ||
| 45 | For r8a77470 SoC;see the selector meaning below: | ||
| 46 | |||
| 47 | +-----------+---------------+---------------+ | ||
| 48 | |\ Selector | | | | ||
| 49 | + --------- + 0 | 1 | | ||
| 50 | | Channel \| | | | ||
| 51 | +-----------+---------------+---------------+ | ||
| 52 | | 0 | EHCI/OHCI | HS-USB | | ||
| 53 | +-----------+---------------+---------------+ | ||
| 54 | |||
| 44 | Example (Lager board): | 55 | Example (Lager board): |
| 45 | 56 | ||
| 46 | usb-phy@e6590100 { | 57 | usb-phy@e6590100 { |
| @@ -48,15 +59,53 @@ Example (Lager board): · 1 unmodified line | |||
| 48 | reg = <0 0xe6590100 0 0x100>; | 59 | reg = <0 0xe6590100 0 0x100>; |
| 49 | #address-cells = <1>; | 60 | #address-cells = <1>; |
| 50 | #size-cells = <0>; | 61 | #size-cells = <0>; |
| 51 | clocks = <&mstp7_clks R8A7790_CLK_HSUSB>; | 62 | clocks = <&cpg CPG_MOD 704>; |
| 52 | clock-names = "usbhs"; | 63 | clock-names = "usbhs"; |
| 64 | power-domains = <&sysc R8A7790_PD_ALWAYS_ON>; | ||
| 65 | resets = <&cpg 704>; | ||
| 53 | 66 | ||
| 54 | usb-channel@0 { | 67 | usb0: usb-channel@0 { |
| 55 | reg = <0>; | 68 | reg = <0>; |
| 56 | #phy-cells = <1>; | 69 | #phy-cells = <1>; |
| 57 | }; | 70 | }; |
| 58 | usb-channel@2 { | 71 | usb2: usb-channel@2 { |
| 59 | reg = <2>; | 72 | reg = <2>; |
| 60 | #phy-cells = <1>; | 73 | #phy-cells = <1>; |
| 61 | }; | 74 | }; |
| 62 | }; | 75 | }; |
| 76 | |||
| 77 | Example (iWave RZ/G1C sbc): | ||
| 78 | |||
| 79 | usbphy0: usb-phy0@e6590100 { | ||
| 80 | compatible = "renesas,usb-phy-r8a77470", | ||
| 81 | "renesas,rcar-gen2-usb-phy"; | ||
| 82 | reg = <0 0xe6590100 0 0x100>; | ||
| 83 | #address-cells = <1>; | ||
| 84 | #size-cells = <0>; | ||
| 85 | clocks = <&cpg CPG_MOD 704>; | ||
| 86 | clock-names = "usbhs"; | ||
| 87 | power-domains = <&sysc R8A77470_PD_ALWAYS_ON>; | ||
| 88 | resets = <&cpg 704>; | ||
| 89 | |||
| 90 | usb0: usb-channel@0 { | ||
| 91 | reg = <0>; | ||
| 92 | #phy-cells = <1>; | ||
| 93 | }; | ||
| 94 | }; | ||
| 95 | |||
| 96 | usbphy1: usb-phy@e6598100 { | ||
| 97 | compatible = "renesas,usb-phy-r8a77470", | ||
| 98 | "renesas,rcar-gen2-usb-phy"; | ||
| 99 | reg = <0 0xe6598100 0 0x100>; | ||
| 100 | #address-cells = <1>; | ||
| 101 | #size-cells = <0>; | ||
| 102 | clocks = <&cpg CPG_MOD 706>; | ||
| 103 | clock-names = "usbhs"; | ||
| 104 | power-domains = <&sysc R8A77470_PD_ALWAYS_ON>; | ||
| 105 | resets = <&cpg 706>; | ||
| 106 | |||
| 107 | usb1: usb-channel@0 { | ||
| 108 | reg = <0>; | ||
| 109 | #phy-cells = <1>; | ||
| 110 | }; | ||
| 111 | }; | ||
| @@ -1,10 +1,12 @@ | |||
| 1 | * Renesas R-Car generation 3 USB 2.0 PHY | 1 | * Renesas R-Car generation 3 USB 2.0 PHY |
| 2 | 2 | ||
| 3 | This file provides information on what the device node for the R-Car generation | 3 | This file provides information on what the device node for the R-Car generation |
| 4 | 3 and RZ/G2 USB 2.0 PHY contain. | 4 | 3, RZ/G1C and RZ/G2 USB 2.0 PHY contain. |
| 5 | 5 | ||
| 6 | Required properties: | 6 | Required properties: |
| 7 | - compatible: "renesas,usb2-phy-r8a774a1" if the device is a part of an R8A774A1 | 7 | - compatible: "renesas,usb2-phy-r8a77470" if the device is a part of an R8A77470 |
| 8 | SoC. | ||
| 9 | "renesas,usb2-phy-r8a774a1" if the device is a part of an R8A774A1 | ||
| 8 | SoC. | 10 | SoC. |
| 9 | "renesas,usb2-phy-r8a774c0" if the device is a part of an R8A774C0 | 11 | "renesas,usb2-phy-r8a774c0" if the device is a part of an R8A774C0 |
| 10 | SoC. | 12 | SoC. |
| @@ -27,7 +29,13 @@ Required properties: · 16 unmodified lines | |||
| 27 | 29 | ||
| 28 | - reg: offset and length of the partial USB 2.0 Host register block. | 30 | - reg: offset and length of the partial USB 2.0 Host register block. |
| 29 | - clocks: clock phandle and specifier pair(s). | 31 | - clocks: clock phandle and specifier pair(s). |
| 30 | - #phy-cells: see phy-bindings.txt in the same directory, must be <0>. | 32 | - #phy-cells: see phy-bindings.txt in the same directory, must be <1> (and |
| 33 | using <0> is deprecated). | ||
| 34 | |||
| 35 | The phandle's argument in the PHY specifier is the INT_STATUS bit of controller: | ||
| 36 | - 1 = USBH_INTA (OHCI) | ||
| 37 | - 2 = USBH_INTB (EHCI) | ||
| 38 | - 3 = UCOM_INT (OTG and BC) | ||
| 31 | 39 | ||
| 32 | Optional properties: | 40 | Optional properties: |
| 33 | To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are | 41 | To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are |
| @@ -7,12 +7,15 @@ Required properties: · 6 unmodified lines | |||
| 7 | - reg: PHY register address offset and length in "general | 7 | - reg: PHY register address offset and length in "general |
| 8 | register files" | 8 | register files" |
| 9 | 9 | ||
| 10 | Optional clocks using the clock bindings (see ../clock/clock-bindings.txt), | 10 | Optional properties: |
| 11 | specified by name: | ||
| 12 | - clock-names: Should contain "emmcclk". Although this is listed as optional | 11 | - clock-names: Should contain "emmcclk". Although this is listed as optional |
| 13 | (because most boards can get basic functionality without having | 12 | (because most boards can get basic functionality without having |
| 14 | access to it), it is strongly suggested. | 13 | access to it), it is strongly suggested. |
| 14 | See ../clock/clock-bindings.txt for details. | ||
| 15 | - clocks: Should have a phandle to the card clock exported by the SDHCI driver. | 15 | - clocks: Should have a phandle to the card clock exported by the SDHCI driver. |
| 16 | - drive-impedance-ohm: Specifies the drive impedance in Ohm. | ||
| 17 | Possible values are 33, 40, 50, 66 and 100. | ||
| 18 | If not set, the default value of 50 will be applied. | ||
| 16 | 19 | ||
| 17 | Example: | 20 | Example: |
| 18 | 21 | ||
| @@ -29,6 +32,7 @@ grf: syscon@ff770000 { · 10 unmodified lines | |||
| 29 | reg = <0xf780 0x20>; | 32 | reg = <0xf780 0x20>; |
| 30 | clocks = <&sdhci>; | 33 | clocks = <&sdhci>; |
| 31 | clock-names = "emmcclk"; | 34 | clock-names = "emmcclk"; |
| 35 | drive-impedance-ohm = <50>; | ||
| 32 | #phy-cells = <0>; | 36 | #phy-cells = <0>; |
| 33 | }; | 37 | }; |
| 34 | }; | 38 | }; |
| @@ -0,0 +1,82 @@ | |||
| 1 | TI AM654 SERDES | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: Should be "ti,phy-am654-serdes" | ||
| 5 | - reg : Address and length of the register set for the device. | ||
| 6 | - #phy-cells: determine the number of cells that should be given in the | ||
| 7 | phandle while referencing this phy. Should be "2". The 1st cell | ||
| 8 | corresponds to the phy type (should be one of the types specified in | ||
| 9 | include/dt-bindings/phy/phy.h) and the 2nd cell should be the serdes | ||
| 10 | lane function. | ||
| 11 | If SERDES0 is referenced 2nd cell should be: | ||
| 12 | 0 - USB3 | ||
| 13 | 1 - PCIe0 Lane0 | ||
| 14 | 2 - ICSS2 SGMII Lane0 | ||
| 15 | If SERDES1 is referenced 2nd cell should be: | ||
| 16 | 0 - PCIe1 Lane0 | ||
| 17 | 1 - PCIe0 Lane1 | ||
| 18 | 2 - ICSS2 SGMII Lane1 | ||
| 19 | - power-domains: As documented by the generic PM domain bindings in | ||
| 20 | Documentation/devicetree/bindings/power/power_domain.txt. | ||
| 21 | - clocks: List of clock-specifiers representing the input to the SERDES. | ||
| 22 | Should have 3 items representing the left input clock, external | ||
| 23 | reference clock and right input clock in that order. | ||
| 24 | - clock-output-names: List of clock names for each of the clock outputs of | ||
| 25 | SERDES. Should have 3 items for CMU reference clock, | ||
| 26 | left output clock and right output clock in that order. | ||
| 27 | - assigned-clocks: As defined in | ||
| 28 | Documentation/devicetree/bindings/clock/clock-bindings.txt | ||
| 29 | - assigned-clock-parents: As defined in | ||
| 30 | Documentation/devicetree/bindings/clock/clock-bindings.txt | ||
| 31 | - #clock-cells: Should be <1> to choose between the 3 output clocks. | ||
| 32 | Defined in Documentation/devicetree/bindings/clock/clock-bindings.txt | ||
| 33 | |||
| 34 | The following macros are defined in dt-bindings/phy/phy-am654-serdes.h | ||
| 35 | for selecting the correct reference clock. This can be used while | ||
| 36 | specifying the clocks created by SERDES. | ||
| 37 | => AM654_SERDES_CMU_REFCLK | ||
| 38 | => AM654_SERDES_LO_REFCLK | ||
| 39 | => AM654_SERDES_RO_REFCLK | ||
| 40 | |||
| 41 | - mux-controls: Phandle to the multiplexer that is used to select the lane | ||
| 42 | function. See #phy-cells above to see the multiplex values. | ||
| 43 | |||
| 44 | Example: | ||
| 45 | |||
| 46 | Example for SERDES0 is given below. It has 3 clock inputs; | ||
| 47 | left input reference clock as indicated by <&k3_clks 153 4>, external | ||
| 48 | reference clock as indicated by <&k3_clks 153 1> and right input | ||
| 49 | reference clock as indicated by <&serdes1 AM654_SERDES_LO_REFCLK>. (The | ||
| 50 | right input of SERDES0 is connected to the left output of SERDES1). | ||
| 51 | |||
| 52 | SERDES0 registers 3 clock outputs as indicated in clock-output-names. The | ||
| 53 | first refers to the CMU reference clock, second refers to the left output | ||
| 54 | reference clock and the third refers to the right output reference clock. | ||
| 55 | |||
| 56 | The assigned-clocks and assigned-clock-parents is used here to set the | ||
| 57 | parent of left input reference clock to MAINHSDIV_CLKOUT4 and parent of | ||
| 58 | CMU reference clock to left input reference clock. | ||
| 59 | |||
| 60 | serdes0: serdes@900000 { | ||
| 61 | compatible = "ti,phy-am654-serdes"; | ||
| 62 | reg = <0x0 0x900000 0x0 0x2000>; | ||
| 63 | reg-names = "serdes"; | ||
| 64 | #phy-cells = <2>; | ||
| 65 | power-domains = <&k3_pds 153>; | ||
| 66 | clocks = <&k3_clks 153 4>, <&k3_clks 153 1>, | ||
| 67 | <&serdes1 AM654_SERDES_LO_REFCLK>; | ||
| 68 | clock-output-names = "serdes0_cmu_refclk", "serdes0_lo_refclk", | ||
| 69 | "serdes0_ro_refclk"; | ||
| 70 | assigned-clocks = <&k3_clks 153 4>, <&serdes0 AM654_SERDES_CMU_REFCLK>; | ||
| 71 | assigned-clock-parents = <&k3_clks 153 8>, <&k3_clks 153 4>; | ||
| 72 | ti,serdes-clk = <&serdes0_clk>; | ||
| 73 | mux-controls = <&serdes_mux 0>; | ||
| 74 | #clock-cells = <1>; | ||
| 75 | }; | ||
| 76 | |||
| 77 | Example for PCIe consumer node using the SERDES PHY specifier is given below. | ||
| 78 | &pcie0_rc { | ||
| 79 | num-lanes = <2>; | ||
| 80 | phys = <&serdes0 PHY_TYPE_PCIE 1>, <&serdes1 PHY_TYPE_PCIE 1>; | ||
| 81 | phy-names = "pcie-phy0", "pcie-phy1"; | ||
| 82 | }; | ||
| @@ -29,6 +29,7 @@ Optional properties: · 28 unmodified lines | |||
| 29 | - vdda-pll-max-microamp : specifies max. load that can be drawn from pll supply | 29 | - vdda-pll-max-microamp : specifies max. load that can be drawn from pll supply |
| 30 | - vddp-ref-clk-supply : phandle to UFS device ref_clk pad power supply | 30 | - vddp-ref-clk-supply : phandle to UFS device ref_clk pad power supply |
| 31 | - vddp-ref-clk-max-microamp : specifies max. load that can be drawn from this supply | 31 | - vddp-ref-clk-max-microamp : specifies max. load that can be drawn from this supply |
| 32 | - resets : specifies the PHY reset in the UFS controller | ||
| 32 | 33 | ||
| 33 | Example: | 34 | Example: |
| 34 | 35 | ||
| @@ -51,9 +52,11 @@ Example: · 16 unmodified lines | |||
| 51 | <&clock_gcc clk_ufs_phy_ldo>, | 52 | <&clock_gcc clk_ufs_phy_ldo>, |
| 52 | <&clock_gcc clk_gcc_ufs_tx_cfg_clk>, | 53 | <&clock_gcc clk_gcc_ufs_tx_cfg_clk>, |
| 53 | <&clock_gcc clk_gcc_ufs_rx_cfg_clk>; | 54 | <&clock_gcc clk_gcc_ufs_rx_cfg_clk>; |
| 55 | resets = <&ufshc 0>; | ||
| 54 | }; | 56 | }; |
| 55 | 57 | ||
| 56 | ufshc@fc598000 { | 58 | ufshc: ufshc@fc598000 { |
| 59 | #reset-cells = <1>; | ||
| 57 | ... | 60 | ... |
| 58 | phys = <&ufsphy1>; | 61 | phys = <&ufsphy1>; |
| 59 | phy-names = "ufsphy"; | 62 | phy-names = "ufsphy"; |
| @@ -50,6 +50,8 @@ Optional properties: · 49 unmodified lines | |||
| 50 | -lanes-per-direction : number of lanes available per direction - either 1 or 2. | 50 | -lanes-per-direction : number of lanes available per direction - either 1 or 2. |
| 51 | Note that it is assume same number of lanes is used both | 51 | Note that it is assume same number of lanes is used both |
| 52 | directions at once. If not specified, default is 2 lanes per direction. | 52 | directions at once. If not specified, default is 2 lanes per direction. |
| 53 | - #reset-cells : Must be <1> for Qualcomm UFS controllers that expose | ||
| 54 | PHY reset from the UFS controller. | ||
| 53 | - resets : reset node register | 55 | - resets : reset node register |
| 54 | - reset-names : describe reset node register, the "rst" corresponds to reset the whole UFS IP. | 56 | - reset-names : describe reset node register, the "rst" corresponds to reset the whole UFS IP. |
| 55 | 57 | ||
| @@ -79,4 +81,5 @@ Example: · 23 unmodified lines | |||
| 79 | reset-names = "rst"; | 81 | reset-names = "rst"; |
| 80 | phys = <&ufsphy1>; | 82 | phys = <&ufsphy1>; |
| 81 | phy-names = "ufsphy"; | 83 | phy-names = "ufsphy"; |
| 84 | #reset-cells = <1>; | ||
| 82 | }; | 85 | }; |
| @@ -15313,6 +15313,11 @@ M: Laxman Dewangan <ldewangan@nvidia.com> · 15312 unmodified lines | |||
| 15313 | S: Supported | 15313 | S: Supported |
| 15314 | F: drivers/spi/spi-tegra* | 15314 | F: drivers/spi/spi-tegra* |
| 15315 | 15315 | ||
| 15316 | TEGRA XUSB PADCTL DRIVER | ||
| 15317 | M: JC Kuo <jckuo@nvidia.com> | ||
| 15318 | S: Supported | ||
| 15319 | F: drivers/phy/tegra/xusb* | ||
| 15320 | |||
| 15316 | TEHUTI ETHERNET DRIVER | 15321 | TEHUTI ETHERNET DRIVER |
| 15317 | M: Andy Gospodarek <andy@greyhouse.net> | 15322 | M: Andy Gospodarek <andy@greyhouse.net> |
| 15318 | L: netdev@vger.kernel.org | 15323 | L: netdev@vger.kernel.org |
| @@ -16083,6 +16088,14 @@ L: linux-usb@vger.kernel.org · 764 unmodified lines | |||
| 16083 | S: Maintained | 16088 | S: Maintained |
| 16084 | F: drivers/usb/roles/intel-xhci-usb-role-switch.c | 16089 | F: drivers/usb/roles/intel-xhci-usb-role-switch.c |
| 16085 | 16090 | ||
| 16091 | USB IP DRIVER FOR HISILICON KIRIN | ||
| 16092 | M: Yu Chen <chenyu56@huawei.com> | ||
| 16093 | M: Binghui Wang <wangbinghui@hisilicon.com> | ||
| 16094 | L: linux-usb@vger.kernel.org | ||
| 16095 | S: Maintained | ||
| 16096 | F: Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt | ||
| 16097 | F: drivers/phy/hisilicon/phy-hi3660-usb3.c | ||
| 16098 | |||
| 16086 | USB ISP116X DRIVER | 16099 | USB ISP116X DRIVER |
| 16087 | M: Olav Kongas <ok@artecdesign.ee> | 16100 | M: Olav Kongas <ok@artecdesign.ee> |
| 16088 | L: linux-usb@vger.kernel.org | 16101 | L: linux-usb@vger.kernel.org |
| @@ -36,3 +36,25 @@ config PHY_MESON_GXL_USB3 · 35 unmodified lines | |||
| 36 | Enable this to support the Meson USB3 PHY and OTG detection | 36 | Enable this to support the Meson USB3 PHY and OTG detection |
| 37 | IP block found in Meson GXL and GXM SoCs. | 37 | IP block found in Meson GXL and GXM SoCs. |
| 38 | If unsure, say N. | 38 | If unsure, say N. |
| 39 | |||
| 40 | config PHY_MESON_G12A_USB2 | ||
| 41 | tristate "Meson G12A USB2 PHY driver" | ||
| 42 | default ARCH_MESON | ||
| 43 | depends on OF && (ARCH_MESON || COMPILE_TEST) | ||
| 44 | select GENERIC_PHY | ||
| 45 | select REGMAP_MMIO | ||
| 46 | help | ||
| 47 | Enable this to support the Meson USB2 PHYs found in Meson | ||
| 48 | G12A SoCs. | ||
| 49 | If unsure, say N. | ||
| 50 | |||
| 51 | config PHY_MESON_G12A_USB3_PCIE | ||
| 52 | tristate "Meson G12A USB3+PCIE Combo PHY driver" | ||
| 53 | default ARCH_MESON | ||
| 54 | depends on OF && (ARCH_MESON || COMPILE_TEST) | ||
| 55 | select GENERIC_PHY | ||
| 56 | select REGMAP_MMIO | ||
| 57 | help | ||
| 58 | Enable this to support the Meson USB3 + PCIE Combo PHY found | ||
| 59 | in Meson G12A SoCs. | ||
| 60 | If unsure, say N. | ||
| @@ -1,3 +1,5 @@ | |||
| 1 | obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o | 1 | obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o |
| 2 | obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o | 2 | obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o |
| 3 | obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o | ||
| 3 | obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.o | 4 | obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.o |
| 5 | obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.o | ||
| @@ -0,0 +1,341 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Meson G12A USB2 PHY driver | ||
| 4 | * | ||
| 5 | * Copyright (C) 2017 Martin Blumenstingl <martin.blumenstingl@googlemail.com> | ||
| 6 | * Copyright (C) 2017 Amlogic, Inc. All rights reserved | ||
| 7 | * Copyright (C) 2019 BayLibre, SAS | ||
| 8 | * Author: Neil Armstrong <narmstrong@baylibre.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/bitfield.h> | ||
| 12 | #include <linux/bitops.h> | ||
| 13 | #include <linux/clk.h> | ||
| 14 | #include <linux/delay.h> | ||
| 15 | #include <linux/io.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/of_device.h> | ||
| 18 | #include <linux/regmap.h> | ||
| 19 | #include <linux/reset.h> | ||
| 20 | #include <linux/phy/phy.h> | ||
| 21 | #include <linux/platform_device.h> | ||
| 22 | |||
| 23 | #define PHY_CTRL_R0 0x0 | ||
| 24 | #define PHY_CTRL_R1 0x4 | ||
| 25 | #define PHY_CTRL_R2 0x8 | ||
| 26 | #define PHY_CTRL_R3 0xc | ||
| 27 | #define PHY_CTRL_R3_SQUELCH_REF GENMASK(1, 0) | ||
| 28 | #define PHY_CTRL_R3_HSDIC_REF GENMASK(3, 2) | ||
| 29 | #define PHY_CTRL_R3_DISC_THRESH GENMASK(7, 4) | ||
| 30 | |||
| 31 | #define PHY_CTRL_R4 0x10 | ||
| 32 | #define PHY_CTRL_R4_CALIB_CODE_7_0 GENMASK(7, 0) | ||
| 33 | #define PHY_CTRL_R4_CALIB_CODE_15_8 GENMASK(15, 8) | ||
| 34 | #define PHY_CTRL_R4_CALIB_CODE_23_16 GENMASK(23, 16) | ||
| 35 | #define PHY_CTRL_R4_I_C2L_CAL_EN BIT(24) | ||
| 36 | #define PHY_CTRL_R4_I_C2L_CAL_RESET_N BIT(25) | ||
| 37 | #define PHY_CTRL_R4_I_C2L_CAL_DONE BIT(26) | ||
| 38 | #define PHY_CTRL_R4_TEST_BYPASS_MODE_EN BIT(27) | ||
| 39 | #define PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0 GENMASK(29, 28) | ||
| 40 | #define PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2 GENMASK(31, 30) | ||
| 41 | |||
| 42 | #define PHY_CTRL_R5 0x14 | ||
| 43 | #define PHY_CTRL_R6 0x18 | ||
| 44 | #define PHY_CTRL_R7 0x1c | ||
| 45 | #define PHY_CTRL_R8 0x20 | ||
| 46 | #define PHY_CTRL_R9 0x24 | ||
| 47 | #define PHY_CTRL_R10 0x28 | ||
| 48 | #define PHY_CTRL_R11 0x2c | ||
| 49 | #define PHY_CTRL_R12 0x30 | ||
| 50 | #define PHY_CTRL_R13 0x34 | ||
| 51 | #define PHY_CTRL_R13_CUSTOM_PATTERN_19 GENMASK(7, 0) | ||
| 52 | #define PHY_CTRL_R13_LOAD_STAT BIT(14) | ||
| 53 | #define PHY_CTRL_R13_UPDATE_PMA_SIGNALS BIT(15) | ||
| 54 | #define PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET GENMASK(20, 16) | ||
| 55 | #define PHY_CTRL_R13_CLEAR_HOLD_HS_DISCONNECT BIT(21) | ||
| 56 | #define PHY_CTRL_R13_BYPASS_HOST_DISCONNECT_VAL BIT(22) | ||
| 57 | #define PHY_CTRL_R13_BYPASS_HOST_DISCONNECT_EN BIT(23) | ||
| 58 | #define PHY_CTRL_R13_I_C2L_HS_EN BIT(24) | ||
| 59 | #define PHY_CTRL_R13_I_C2L_FS_EN BIT(25) | ||
| 60 | #define PHY_CTRL_R13_I_C2L_LS_EN BIT(26) | ||
| 61 | #define PHY_CTRL_R13_I_C2L_HS_OE BIT(27) | ||
| 62 | #define PHY_CTRL_R13_I_C2L_FS_OE BIT(28) | ||
| 63 | #define PHY_CTRL_R13_I_C2L_HS_RX_EN BIT(29) | ||
| 64 | #define PHY_CTRL_R13_I_C2L_FSLS_RX_EN BIT(30) | ||
| 65 | |||
| 66 | #define PHY_CTRL_R14 0x38 | ||
| 67 | #define PHY_CTRL_R14_I_RDP_EN BIT(0) | ||
| 68 | #define PHY_CTRL_R14_I_RPU_SW1_EN BIT(1) | ||
| 69 | #define PHY_CTRL_R14_I_RPU_SW2_EN GENMASK(2, 3) | ||
| 70 | #define PHY_CTRL_R14_PG_RSTN BIT(4) | ||
| 71 | #define PHY_CTRL_R14_I_C2L_DATA_16_8 BIT(5) | ||
| 72 | #define PHY_CTRL_R14_I_C2L_ASSERT_SINGLE_EN_ZERO BIT(6) | ||
| 73 | #define PHY_CTRL_R14_BYPASS_CTRL_7_0 GENMASK(15, 8) | ||
| 74 | #define PHY_CTRL_R14_BYPASS_CTRL_15_8 GENMASK(23, 16) | ||
| 75 | |||
| 76 | #define PHY_CTRL_R15 0x3c | ||
| 77 | #define PHY_CTRL_R16 0x40 | ||
| 78 | #define PHY_CTRL_R16_MPLL_M GENMASK(8, 0) | ||
| 79 | #define PHY_CTRL_R16_MPLL_N GENMASK(14, 10) | ||
| 80 | #define PHY_CTRL_R16_MPLL_TDC_MODE BIT(20) | ||
| 81 | #define PHY_CTRL_R16_MPLL_SDM_EN BIT(21) | ||
| 82 | #define PHY_CTRL_R16_MPLL_LOAD BIT(22) | ||
| 83 | #define PHY_CTRL_R16_MPLL_DCO_SDM_EN BIT(23) | ||
| 84 | #define PHY_CTRL_R16_MPLL_LOCK_LONG GENMASK(25, 24) | ||
| 85 | #define PHY_CTRL_R16_MPLL_LOCK_F BIT(26) | ||
| 86 | #define PHY_CTRL_R16_MPLL_FAST_LOCK BIT(27) | ||
| 87 | #define PHY_CTRL_R16_MPLL_EN BIT(28) | ||
| 88 | #define PHY_CTRL_R16_MPLL_RESET BIT(29) | ||
| 89 | #define PHY_CTRL_R16_MPLL_LOCK BIT(30) | ||
| 90 | #define PHY_CTRL_R16_MPLL_LOCK_DIG BIT(31) | ||
| 91 | |||
| 92 | #define PHY_CTRL_R17 0x44 | ||
| 93 | #define PHY_CTRL_R17_MPLL_FRAC_IN GENMASK(13, 0) | ||
| 94 | #define PHY_CTRL_R17_MPLL_FIX_EN BIT(16) | ||
| 95 | #define PHY_CTRL_R17_MPLL_LAMBDA1 GENMASK(19, 17) | ||
| 96 | #define PHY_CTRL_R17_MPLL_LAMBDA0 GENMASK(22, 20) | ||
| 97 | #define PHY_CTRL_R17_MPLL_FILTER_MODE BIT(23) | ||
| 98 | #define PHY_CTRL_R17_MPLL_FILTER_PVT2 GENMASK(27, 24) | ||
| 99 | #define PHY_CTRL_R17_MPLL_FILTER_PVT1 GENMASK(31, 28) | ||
| 100 | |||
| 101 | #define PHY_CTRL_R18 0x48 | ||
| 102 | #define PHY_CTRL_R18_MPLL_LKW_SEL GENMASK(1, 0) | ||
| 103 | #define PHY_CTRL_R18_MPLL_LK_W GENMASK(5, 2) | ||
| 104 | #define PHY_CTRL_R18_MPLL_LK_S GENMASK(11, 6) | ||
| 105 | #define PHY_CTRL_R18_MPLL_DCO_M_EN BIT(12) | ||
| 106 | #define PHY_CTRL_R18_MPLL_DCO_CLK_SEL BIT(13) | ||
| 107 | #define PHY_CTRL_R18_MPLL_PFD_GAIN GENMASK(15, 14) | ||
| 108 | #define PHY_CTRL_R18_MPLL_ROU GENMASK(18, 16) | ||
| 109 | #define PHY_CTRL_R18_MPLL_DATA_SEL GENMASK(21, 19) | ||
| 110 | #define PHY_CTRL_R18_MPLL_BIAS_ADJ GENMASK(23, 22) | ||
| 111 | #define PHY_CTRL_R18_MPLL_BB_MODE GENMASK(25, 24) | ||
| 112 | #define PHY_CTRL_R18_MPLL_ALPHA GENMASK(28, 26) | ||
| 113 | #define PHY_CTRL_R18_MPLL_ADJ_LDO GENMASK(30, 29) | ||
| 114 | #define PHY_CTRL_R18_MPLL_ACG_RANGE BIT(31) | ||
| 115 | |||
| 116 | #define PHY_CTRL_R19 0x4c | ||
| 117 | #define PHY_CTRL_R20 0x50 | ||
| 118 | #define PHY_CTRL_R20_USB2_IDDET_EN BIT(0) | ||
| 119 | #define PHY_CTRL_R20_USB2_OTG_VBUS_TRIM_2_0 GENMASK(3, 1) | ||
| 120 | #define PHY_CTRL_R20_USB2_OTG_VBUSDET_EN BIT(4) | ||
| 121 | #define PHY_CTRL_R20_USB2_AMON_EN BIT(5) | ||
| 122 | #define PHY_CTRL_R20_USB2_CAL_CODE_R5 BIT(6) | ||
| 123 | #define PHY_CTRL_R20_BYPASS_OTG_DET BIT(7) | ||
| 124 | #define PHY_CTRL_R20_USB2_DMON_EN BIT(8) | ||
| 125 | #define PHY_CTRL_R20_USB2_DMON_SEL_3_0 GENMASK(12, 9) | ||
| 126 | #define PHY_CTRL_R20_USB2_EDGE_DRV_EN BIT(13) | ||
| 127 | #define PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0 GENMASK(15, 14) | ||
| 128 | #define PHY_CTRL_R20_USB2_BGR_ADJ_4_0 GENMASK(20, 16) | ||
| 129 | #define PHY_CTRL_R20_USB2_BGR_START BIT(21) | ||
| 130 | #define PHY_CTRL_R20_USB2_BGR_VREF_4_0 GENMASK(28, 24) | ||
| 131 | #define PHY_CTRL_R20_USB2_BGR_DBG_1_0 GENMASK(30, 29) | ||
| 132 | #define PHY_CTRL_R20_BYPASS_CAL_DONE_R5 BIT(31) | ||
| 133 | |||
| 134 | #define PHY_CTRL_R21 0x54 | ||
| 135 | #define PHY_CTRL_R21_USB2_BGR_FORCE BIT(0) | ||
| 136 | #define PHY_CTRL_R21_USB2_CAL_ACK_EN BIT(1) | ||
| 137 | #define PHY_CTRL_R21_USB2_OTG_ACA_EN BIT(2) | ||
| 138 | #define PHY_CTRL_R21_USB2_TX_STRG_PD BIT(3) | ||
| 139 | #define PHY_CTRL_R21_USB2_OTG_ACA_TRIM_1_0 GENMASK(5, 4) | ||
| 140 | #define PHY_CTRL_R21_BYPASS_UTMI_CNTR GENMASK(15, 6) | ||
| 141 | #define PHY_CTRL_R21_BYPASS_UTMI_REG GENMASK(25, 20) | ||
| 142 | |||
| 143 | #define PHY_CTRL_R22 0x58 | ||
| 144 | #define PHY_CTRL_R23 0x5c | ||
| 145 | |||
| 146 | #define RESET_COMPLETE_TIME 1000 | ||
| 147 | #define PLL_RESET_COMPLETE_TIME 100 | ||
| 148 | |||
| 149 | struct phy_meson_g12a_usb2_priv { | ||
| 150 | struct device *dev; | ||
| 151 | struct regmap *regmap; | ||
| 152 | struct clk *clk; | ||
| 153 | struct reset_control *reset; | ||
| 154 | }; | ||
| 155 | |||
| 156 | static const struct regmap_config phy_meson_g12a_usb2_regmap_conf = { | ||
| 157 | .reg_bits = 8, | ||
| 158 | .val_bits = 32, | ||
| 159 | .reg_stride = 4, | ||
| 160 | .max_register = PHY_CTRL_R23, | ||
| 161 | }; | ||
| 162 | |||
| 163 | static int phy_meson_g12a_usb2_init(struct phy *phy) | ||
| 164 | { | ||
| 165 | struct phy_meson_g12a_usb2_priv *priv = phy_get_drvdata(phy); | ||
| 166 | int ret; | ||
| 167 | |||
| 168 | ret = reset_control_reset(priv->reset); | ||
| 169 | if (ret) | ||
| 170 | return ret; | ||
| 171 | |||
| 172 | udelay(RESET_COMPLETE_TIME); | ||
| 173 | |||
| 174 | /* usb2_otg_aca_en == 0 */ | ||
| 175 | regmap_update_bits(priv->regmap, PHY_CTRL_R21, | ||
| 176 | PHY_CTRL_R21_USB2_OTG_ACA_EN, 0); | ||
| 177 | |||
| 178 | /* PLL Setup : 24MHz * 20 / 1 = 480MHz */ | ||
| 179 | regmap_write(priv->regmap, PHY_CTRL_R16, | ||
| 180 | FIELD_PREP(PHY_CTRL_R16_MPLL_M, 20) | | ||
| 181 | FIELD_PREP(PHY_CTRL_R16_MPLL_N, 1) | | ||
| 182 | PHY_CTRL_R16_MPLL_LOAD | | ||
| 183 | FIELD_PREP(PHY_CTRL_R16_MPLL_LOCK_LONG, 1) | | ||
| 184 | PHY_CTRL_R16_MPLL_FAST_LOCK | | ||
| 185 | PHY_CTRL_R16_MPLL_EN | | ||
| 186 | PHY_CTRL_R16_MPLL_RESET); | ||
| 187 | |||
| 188 | regmap_write(priv->regmap, PHY_CTRL_R17, | ||
| 189 | FIELD_PREP(PHY_CTRL_R17_MPLL_FRAC_IN, 0) | | ||
| 190 | FIELD_PREP(PHY_CTRL_R17_MPLL_LAMBDA1, 7) | | ||
| 191 | FIELD_PREP(PHY_CTRL_R17_MPLL_LAMBDA0, 7) | | ||
| 192 | FIELD_PREP(PHY_CTRL_R17_MPLL_FILTER_PVT2, 2) | | ||
| 193 | FIELD_PREP(PHY_CTRL_R17_MPLL_FILTER_PVT1, 9)); | ||
| 194 | |||
| 195 | regmap_write(priv->regmap, PHY_CTRL_R18, | ||
| 196 | FIELD_PREP(PHY_CTRL_R18_MPLL_LKW_SEL, 1) | | ||
| 197 | FIELD_PREP(PHY_CTRL_R18_MPLL_LK_W, 9) | | ||
| 198 | FIELD_PREP(PHY_CTRL_R18_MPLL_LK_S, 0x27) | | ||
| 199 | FIELD_PREP(PHY_CTRL_R18_MPLL_PFD_GAIN, 1) | | ||
| 200 | FIELD_PREP(PHY_CTRL_R18_MPLL_ROU, 7) | | ||
| 201 | FIELD_PREP(PHY_CTRL_R18_MPLL_DATA_SEL, 3) | | ||
| 202 | FIELD_PREP(PHY_CTRL_R18_MPLL_BIAS_ADJ, 1) | | ||
| 203 | FIELD_PREP(PHY_CTRL_R18_MPLL_BB_MODE, 0) | | ||
| 204 | FIELD_PREP(PHY_CTRL_R18_MPLL_ALPHA, 3) | | ||
| 205 | FIELD_PREP(PHY_CTRL_R18_MPLL_ADJ_LDO, 1) | | ||
| 206 | PHY_CTRL_R18_MPLL_ACG_RANGE); | ||
| 207 | |||
| 208 | udelay(PLL_RESET_COMPLETE_TIME); | ||
| 209 | |||
| 210 | /* UnReset PLL */ | ||
| 211 | regmap_write(priv->regmap, PHY_CTRL_R16, | ||
| 212 | FIELD_PREP(PHY_CTRL_R16_MPLL_M, 20) | | ||
| 213 | FIELD_PREP(PHY_CTRL_R16_MPLL_N, 1) | | ||
| 214 | PHY_CTRL_R16_MPLL_LOAD | | ||
| 215 | FIELD_PREP(PHY_CTRL_R16_MPLL_LOCK_LONG, 1) | | ||
| 216 | PHY_CTRL_R16_MPLL_FAST_LOCK | | ||
| 217 | PHY_CTRL_R16_MPLL_EN); | ||
| 218 | |||
| 219 | /* PHY Tuning */ | ||
| 220 | regmap_write(priv->regmap, PHY_CTRL_R20, | ||
| 221 | FIELD_PREP(PHY_CTRL_R20_USB2_OTG_VBUS_TRIM_2_0, 4) | | ||
| 222 | PHY_CTRL_R20_USB2_OTG_VBUSDET_EN | | ||
| 223 | FIELD_PREP(PHY_CTRL_R20_USB2_DMON_SEL_3_0, 15) | | ||
| 224 | PHY_CTRL_R20_USB2_EDGE_DRV_EN | | ||
| 225 | FIELD_PREP(PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0, 3) | | ||
| 226 | FIELD_PREP(PHY_CTRL_R20_USB2_BGR_ADJ_4_0, 0) | | ||
| 227 | FIELD_PREP(PHY_CTRL_R20_USB2_BGR_VREF_4_0, 0) | | ||
| 228 | FIELD_PREP(PHY_CTRL_R20_USB2_BGR_DBG_1_0, 0)); | ||
| 229 | |||
| 230 | regmap_write(priv->regmap, PHY_CTRL_R4, | ||
| 231 | FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_7_0, 0xf) | | ||
| 232 | FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_15_8, 0xf) | | ||
| 233 | FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_23_16, 0xf) | | ||
| 234 | PHY_CTRL_R4_TEST_BYPASS_MODE_EN | | ||
| 235 | FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0, 0) | | ||
| 236 | FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2, 0)); | ||
| 237 | |||
| 238 | /* Tuning Disconnect Threshold */ | ||
| 239 | regmap_write(priv->regmap, PHY_CTRL_R3, | ||
| 240 | FIELD_PREP(PHY_CTRL_R3_SQUELCH_REF, 0) | | ||
| 241 | FIELD_PREP(PHY_CTRL_R3_HSDIC_REF, 1) | | ||
| 242 | FIELD_PREP(PHY_CTRL_R3_DISC_THRESH, 3)); | ||
| 243 | |||
| 244 | /* Analog Settings */ | ||
| 245 | regmap_write(priv->regmap, PHY_CTRL_R14, 0); | ||
| 246 | regmap_write(priv->regmap, PHY_CTRL_R13, | ||
| 247 | PHY_CTRL_R13_UPDATE_PMA_SIGNALS | | ||
| 248 | FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7)); | ||
| 249 | |||
| 250 | return 0; | ||
| 251 | } | ||
| 252 | |||
| 253 | static int phy_meson_g12a_usb2_exit(struct phy *phy) | ||
| 254 | { | ||
| 255 | struct phy_meson_g12a_usb2_priv *priv = phy_get_drvdata(phy); | ||
| 256 | |||
| 257 | return reset_control_reset(priv->reset); | ||
| 258 | } | ||
| 259 | |||
| 260 | /* set_mode is not needed, mode setting is handled via the UTMI bus */ | ||
| 261 | static const struct phy_ops phy_meson_g12a_usb2_ops = { | ||
| 262 | .init = phy_meson_g12a_usb2_init, | ||
| 263 | .exit = phy_meson_g12a_usb2_exit, | ||
| 264 | .owner = THIS_MODULE, | ||
| 265 | }; | ||
| 266 | |||
| 267 | static int phy_meson_g12a_usb2_probe(struct platform_device *pdev) | ||
| 268 | { | ||
| 269 | struct device *dev = &pdev->dev; | ||
| 270 | struct phy_provider *phy_provider; | ||
| 271 | struct resource *res; | ||
| 272 | struct phy_meson_g12a_usb2_priv *priv; | ||
| 273 | struct phy *phy; | ||
| 274 | void __iomem *base; | ||
| 275 | int ret; | ||
| 276 | |||
| 277 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 278 | if (!priv) | ||
| 279 | return -ENOMEM; | ||
| 280 | |||
| 281 | priv->dev = dev; | ||
| 282 | platform_set_drvdata(pdev, priv); | ||
| 283 | |||
| 284 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 285 | base = devm_ioremap_resource(dev, res); | ||
| 286 | if (IS_ERR(base)) | ||
| 287 | return PTR_ERR(base); | ||
| 288 | |||
| 289 | priv->regmap = devm_regmap_init_mmio(dev, base, | ||
| 290 | &phy_meson_g12a_usb2_regmap_conf); | ||
| 291 | if (IS_ERR(priv->regmap)) | ||
| 292 | return PTR_ERR(priv->regmap); | ||
| 293 | |||
| 294 | priv->clk = devm_clk_get(dev, "xtal"); | ||
| 295 | if (IS_ERR(priv->clk)) | ||
| 296 | return PTR_ERR(priv->clk); | ||
| 297 | |||
| 298 | priv->reset = devm_reset_control_get(dev, "phy"); | ||
| 299 | if (IS_ERR(priv->reset)) | ||
| 300 | return PTR_ERR(priv->reset); | ||
| 301 | |||
| 302 | ret = reset_control_deassert(priv->reset); | ||
| 303 | if (ret) | ||
| 304 | return ret; | ||
| 305 | |||
| 306 | phy = devm_phy_create(dev, NULL, &phy_meson_g12a_usb2_ops); | ||
| 307 | if (IS_ERR(phy)) { | ||
| 308 | ret = PTR_ERR(phy); | ||
| 309 | if (ret != -EPROBE_DEFER) | ||
| 310 | dev_err(dev, "failed to create PHY\n"); | ||
| 311 | |||
| 312 | return ret; | ||
| 313 | } | ||
| 314 | |||
| 315 | phy_set_bus_width(phy, 8); | ||
| 316 | phy_set_drvdata(phy, priv); | ||
| 317 | |||
| 318 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
| 319 | |||
| 320 | return PTR_ERR_OR_ZERO(phy_provider); | ||
| 321 | } | ||
| 322 | |||
| 323 | static const struct of_device_id phy_meson_g12a_usb2_of_match[] = { | ||
| 324 | { .compatible = "amlogic,g12a-usb2-phy", }, | ||
| 325 | { }, | ||
| 326 | }; | ||
| 327 | MODULE_DEVICE_TABLE(of, phy_meson_g12a_usb2_of_match); | ||
| 328 | |||
| 329 | static struct platform_driver phy_meson_g12a_usb2_driver = { | ||
| 330 | .probe = phy_meson_g12a_usb2_probe, | ||
| 331 | .driver = { | ||
| 332 | .name = "phy-meson-g12a-usb2", | ||
| 333 | .of_match_table = phy_meson_g12a_usb2_of_match, | ||
| 334 | }, | ||
| 335 | }; | ||
| 336 | module_platform_driver(phy_meson_g12a_usb2_driver); | ||
| 337 | |||
| 338 | MODULE_AUTHOR("Martin Blumenstingl <martin.blumenstingl@googlemail.com>"); | ||
| 339 | MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>"); | ||
| 340 | MODULE_DESCRIPTION("Meson G12A USB2 PHY driver"); | ||
| 341 | MODULE_LICENSE("GPL v2"); | ||
| @@ -0,0 +1,413 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Amlogic G12A USB3 + PCIE Combo PHY driver | ||
| 4 | * | ||
| 5 | * Copyright (C) 2017 Amlogic, Inc. All rights reserved | ||
| 6 | * Copyright (C) 2019 BayLibre, SAS | ||
| 7 | * Author: Neil Armstrong <narmstrong@baylibre.com> | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <linux/bitfield.h> | ||
| 11 | #include <linux/bitops.h> | ||
| 12 | #include <linux/clk.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/of_device.h> | ||
| 15 | #include <linux/phy/phy.h> | ||
| 16 | #include <linux/regmap.h> | ||
| 17 | #include <linux/reset.h> | ||
| 18 | #include <linux/platform_device.h> | ||
| 19 | #include <dt-bindings/phy/phy.h> | ||
| 20 | |||
| 21 | #define PHY_R0 0x00 | ||
| 22 | #define PHY_R0_PCIE_POWER_STATE GENMASK(4, 0) | ||
| 23 | #define PHY_R0_PCIE_USB3_SWITCH GENMASK(6, 5) | ||
| 24 | |||
| 25 | #define PHY_R1 0x04 | ||
| 26 | #define PHY_R1_PHY_TX1_TERM_OFFSET GENMASK(4, 0) | ||
| 27 | #define PHY_R1_PHY_TX0_TERM_OFFSET GENMASK(9, 5) | ||
| 28 | #define PHY_R1_PHY_RX1_EQ GENMASK(12, 10) | ||
| 29 | #define PHY_R1_PHY_RX0_EQ GENMASK(15, 13) | ||
| 30 | #define PHY_R1_PHY_LOS_LEVEL GENMASK(20, 16) | ||
| 31 | #define PHY_R1_PHY_LOS_BIAS GENMASK(23, 21) | ||
| 32 | #define PHY_R1_PHY_REF_CLKDIV2 BIT(24) | ||
| 33 | #define PHY_R1_PHY_MPLL_MULTIPLIER GENMASK(31, 25) | ||
| 34 | |||
| 35 | #define PHY_R2 0x08 | ||
| 36 | #define PHY_R2_PCS_TX_DEEMPH_GEN2_6DB GENMASK(5, 0) | ||
| 37 | #define PHY_R2_PCS_TX_DEEMPH_GEN2_3P5DB GENMASK(11, 6) | ||
| 38 | #define PHY_R2_PCS_TX_DEEMPH_GEN1 GENMASK(17, 12) | ||
| 39 | #define PHY_R2_PHY_TX_VBOOST_LVL GENMASK(20, 18) | ||
| 40 | |||
| 41 | #define PHY_R4 0x10 | ||
| 42 | #define PHY_R4_PHY_CR_WRITE BIT(0) | ||
| 43 | #define PHY_R4_PHY_CR_READ BIT(1) | ||
| 44 | #define PHY_R4_PHY_CR_DATA_IN GENMASK(17, 2) | ||
| 45 | #define PHY_R4_PHY_CR_CAP_DATA BIT(18) | ||
| 46 | #define PHY_R4_PHY_CR_CAP_ADDR BIT(19) | ||
| 47 | |||
| 48 | #define PHY_R5 0x14 | ||
| 49 | #define PHY_R5_PHY_CR_DATA_OUT GENMASK(15, 0) | ||
| 50 | #define PHY_R5_PHY_CR_ACK BIT(16) | ||
| 51 | #define PHY_R5_PHY_BS_OUT BIT(17) | ||
| 52 | |||
| 53 | struct phy_g12a_usb3_pcie_priv { | ||
| 54 | struct regmap *regmap; | ||
| 55 | struct regmap *regmap_cr; | ||
| 56 | struct clk *clk_ref; | ||
| 57 | struct reset_control *reset; | ||
| 58 | struct phy *phy; | ||
| 59 | unsigned int mode; | ||
| 60 | }; | ||
| 61 | |||
| 62 | static const struct regmap_config phy_g12a_usb3_pcie_regmap_conf = { | ||
| 63 | .reg_bits = 8, | ||
| 64 | .val_bits = 32, | ||
| 65 | .reg_stride = 4, | ||
| 66 | .max_register = PHY_R5, | ||
| 67 | }; | ||
| 68 | |||
| 69 | static int phy_g12a_usb3_pcie_cr_bus_addr(struct phy_g12a_usb3_pcie_priv *priv, | ||
| 70 | unsigned int addr) | ||
| 71 | { | ||
| 72 | unsigned int val, reg; | ||
| 73 | int ret; | ||
| 74 | |||
| 75 | reg = FIELD_PREP(PHY_R4_PHY_CR_DATA_IN, addr); | ||
| 76 | |||
| 77 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 78 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 79 | |||
| 80 | regmap_write(priv->regmap, PHY_R4, reg | PHY_R4_PHY_CR_CAP_ADDR); | ||
| 81 | |||
| 82 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 83 | (val & PHY_R5_PHY_CR_ACK), | ||
| 84 | 5, 1000); | ||
| 85 | if (ret) | ||
| 86 | return ret; | ||
| 87 | |||
| 88 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 89 | |||
| 90 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 91 | !(val & PHY_R5_PHY_CR_ACK), | ||
| 92 | 5, 1000); | ||
| 93 | if (ret) | ||
| 94 | return ret; | ||
| 95 | |||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int phy_g12a_usb3_pcie_cr_bus_read(void *context, unsigned int addr, | ||
| 100 | unsigned int *data) | ||
| 101 | { | ||
| 102 | struct phy_g12a_usb3_pcie_priv *priv = context; | ||
| 103 | unsigned int val; | ||
| 104 | int ret; | ||
| 105 | |||
| 106 | ret = phy_g12a_usb3_pcie_cr_bus_addr(priv, addr); | ||
| 107 | if (ret) | ||
| 108 | return ret; | ||
| 109 | |||
| 110 | regmap_write(priv->regmap, PHY_R4, 0); | ||
| 111 | regmap_write(priv->regmap, PHY_R4, PHY_R4_PHY_CR_READ); | ||
| 112 | |||
| 113 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 114 | (val & PHY_R5_PHY_CR_ACK), | ||
| 115 | 5, 1000); | ||
| 116 | if (ret) | ||
| 117 | return ret; | ||
| 118 | |||
| 119 | *data = FIELD_GET(PHY_R5_PHY_CR_DATA_OUT, val); | ||
| 120 | |||
| 121 | regmap_write(priv->regmap, PHY_R4, 0); | ||
| 122 | |||
| 123 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 124 | !(val & PHY_R5_PHY_CR_ACK), | ||
| 125 | 5, 1000); | ||
| 126 | if (ret) | ||
| 127 | return ret; | ||
| 128 | |||
| 129 | return 0; | ||
| 130 | } | ||
| 131 | |||
| 132 | static int phy_g12a_usb3_pcie_cr_bus_write(void *context, unsigned int addr, | ||
| 133 | unsigned int data) | ||
| 134 | { | ||
| 135 | struct phy_g12a_usb3_pcie_priv *priv = context; | ||
| 136 | unsigned int val, reg; | ||
| 137 | int ret; | ||
| 138 | |||
| 139 | ret = phy_g12a_usb3_pcie_cr_bus_addr(priv, addr); | ||
| 140 | if (ret) | ||
| 141 | return ret; | ||
| 142 | |||
| 143 | reg = FIELD_PREP(PHY_R4_PHY_CR_DATA_IN, data); | ||
| 144 | |||
| 145 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 146 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 147 | |||
| 148 | regmap_write(priv->regmap, PHY_R4, reg | PHY_R4_PHY_CR_CAP_DATA); | ||
| 149 | |||
| 150 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 151 | (val & PHY_R5_PHY_CR_ACK), | ||
| 152 | 5, 1000); | ||
| 153 | if (ret) | ||
| 154 | return ret; | ||
| 155 | |||
| 156 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 157 | |||
| 158 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 159 | (val & PHY_R5_PHY_CR_ACK) == 0, | ||
| 160 | 5, 1000); | ||
| 161 | if (ret) | ||
| 162 | return ret; | ||
| 163 | |||
| 164 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 165 | |||
| 166 | regmap_write(priv->regmap, PHY_R4, reg | PHY_R4_PHY_CR_WRITE); | ||
| 167 | |||
| 168 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 169 | (val & PHY_R5_PHY_CR_ACK), | ||
| 170 | 5, 1000); | ||
| 171 | if (ret) | ||
| 172 | return ret; | ||
| 173 | |||
| 174 | regmap_write(priv->regmap, PHY_R4, reg); | ||
| 175 | |||
| 176 | ret = regmap_read_poll_timeout(priv->regmap, PHY_R5, val, | ||
| 177 | (val & PHY_R5_PHY_CR_ACK) == 0, | ||
| 178 | 5, 1000); | ||
| 179 | if (ret) | ||
| 180 | return ret; | ||
| 181 | |||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | |||
| 185 | static const struct regmap_config phy_g12a_usb3_pcie_cr_regmap_conf = { | ||
| 186 | .reg_bits = 16, | ||
| 187 | .val_bits = 16, | ||
| 188 | .reg_read = phy_g12a_usb3_pcie_cr_bus_read, | ||
| 189 | .reg_write = phy_g12a_usb3_pcie_cr_bus_write, | ||
| 190 | .max_register = 0xffff, | ||
| 191 | .fast_io = true, | ||
| 192 | }; | ||
| 193 | |||
| 194 | static int phy_g12a_usb3_init(struct phy *phy) | ||
| 195 | { | ||
| 196 | struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy); | ||
| 197 | int data, ret; | ||
| 198 | |||
| 199 | /* Switch PHY to USB3 */ | ||
| 200 | /* TODO figure out how to handle when PCIe was set in the bootloader */ | ||
| 201 | regmap_update_bits(priv->regmap, PHY_R0, | ||
| 202 | PHY_R0_PCIE_USB3_SWITCH, | ||
| 203 | PHY_R0_PCIE_USB3_SWITCH); | ||
| 204 | |||
| 205 | /* | ||
| 206 | * WORKAROUND: There is SSPHY suspend bug due to | ||
| 207 | * which USB enumerates | ||
| 208 | * in HS mode instead of SS mode. Workaround it by asserting | ||
| 209 | * LANE0.TX_ALT_BLOCK.EN_ALT_BUS to enable TX to use alt bus | ||
| 210 | * mode | ||
| 211 | */ | ||
| 212 | ret = regmap_update_bits(priv->regmap_cr, 0x102d, BIT(7), BIT(7)); | ||
| 213 | if (ret) | ||
| 214 | return ret; | ||
| 215 | |||
| 216 | ret = regmap_update_bits(priv->regmap_cr, 0x1010, 0xff0, 20); | ||
| 217 | if (ret) | ||
| 218 | return ret; | ||
| 219 | |||
| 220 | /* | ||
| 221 | * Fix RX Equalization setting as follows | ||
| 222 | * LANE0.RX_OVRD_IN_HI. RX_EQ_EN set to 0 | ||
| 223 | * LANE0.RX_OVRD_IN_HI.RX_EQ_EN_OVRD set to 1 | ||
| 224 | * LANE0.RX_OVRD_IN_HI.RX_EQ set to 3 | ||
| 225 | * LANE0.RX_OVRD_IN_HI.RX_EQ_OVRD set to 1 | ||
| 226 | */ | ||
| 227 | ret = regmap_read(priv->regmap_cr, 0x1006, &data); | ||
| 228 | if (ret) | ||
| 229 | return ret; | ||
| 230 | |||
| 231 | data &= ~BIT(6); | ||
| 232 | data |= BIT(7); | ||
| 233 | data &= ~(0x7 << 8); | ||
| 234 | data |= (0x3 << 8); | ||
| 235 | data |= (1 << 11); | ||
| 236 | ret = regmap_write(priv->regmap_cr, 0x1006, data); | ||
| 237 | if (ret) | ||
| 238 | return ret; | ||
| 239 | |||
| 240 | /* | ||
| 241 | * Set EQ and TX launch amplitudes as follows | ||
| 242 | * LANE0.TX_OVRD_DRV_LO.PREEMPH set to 22 | ||
| 243 | * LANE0.TX_OVRD_DRV_LO.AMPLITUDE set to 127 | ||
| 244 | * LANE0.TX_OVRD_DRV_LO.EN set to 1. | ||
| 245 | */ | ||
| 246 | ret = regmap_read(priv->regmap_cr, 0x1002, &data); | ||
| 247 | if (ret) | ||
| 248 | return ret; | ||
| 249 | |||
| 250 | data &= ~0x3f80; | ||
| 251 | data |= (0x16 << 7); | ||
| 252 | data &= ~0x7f; | ||
| 253 | data |= (0x7f | BIT(14)); | ||
| 254 | ret = regmap_write(priv->regmap_cr, 0x1002, data); | ||
| 255 | if (ret) | ||
| 256 | return ret; | ||
| 257 | |||
| 258 | /* MPLL_LOOP_CTL.PROP_CNTRL = 8 */ | ||
| 259 | ret = regmap_update_bits(priv->regmap_cr, 0x30, 0xf << 4, 8 << 4); | ||
| 260 | if (ret) | ||
| 261 | return ret; | ||
| 262 | |||
| 263 | regmap_update_bits(priv->regmap, PHY_R2, | ||
| 264 | PHY_R2_PHY_TX_VBOOST_LVL, | ||
| 265 | FIELD_PREP(PHY_R2_PHY_TX_VBOOST_LVL, 0x4)); | ||
| 266 | |||
| 267 | regmap_update_bits(priv->regmap, PHY_R1, | ||
| 268 | PHY_R1_PHY_LOS_BIAS | PHY_R1_PHY_LOS_LEVEL, | ||
| 269 | FIELD_PREP(PHY_R1_PHY_LOS_BIAS, 4) | | ||
| 270 | FIELD_PREP(PHY_R1_PHY_LOS_LEVEL, 9)); | ||
| 271 | |||
| 272 | return 0; | ||
| 273 | } | ||
| 274 | |||
| 275 | static int phy_g12a_usb3_pcie_init(struct phy *phy) | ||
| 276 | { | ||
| 277 | struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy); | ||
| 278 | int ret; | ||
| 279 | |||
| 280 | ret = reset_control_reset(priv->reset); | ||
| 281 | if (ret) | ||
| 282 | return ret; | ||
| 283 | |||
| 284 | if (priv->mode == PHY_TYPE_USB3) | ||
| 285 | return phy_g12a_usb3_init(phy); | ||
| 286 | |||
| 287 | /* Power UP PCIE */ | ||
| 288 | /* TODO figure out when the bootloader has set USB3 mode before */ | ||
| 289 | regmap_update_bits(priv->regmap, PHY_R0, | ||
| 290 | PHY_R0_PCIE_POWER_STATE, | ||
| 291 | FIELD_PREP(PHY_R0_PCIE_POWER_STATE, 0x1c)); | ||
| 292 | |||
| 293 | return 0; | ||
| 294 | } | ||
| 295 | |||
| 296 | static int phy_g12a_usb3_pcie_exit(struct phy *phy) | ||
| 297 | { | ||
| 298 | struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy); | ||
| 299 | |||
| 300 | return reset_control_reset(priv->reset); | ||
| 301 | } | ||
| 302 | |||
| 303 | static struct phy *phy_g12a_usb3_pcie_xlate(struct device *dev, | ||
| 304 | struct of_phandle_args *args) | ||
| 305 | { | ||
| 306 | struct phy_g12a_usb3_pcie_priv *priv = dev_get_drvdata(dev); | ||
| 307 | unsigned int mode; | ||
| 308 | |||
| 309 | if (args->args_count < 1) { | ||
| 310 | dev_err(dev, "invalid number of arguments\n"); | ||
| 311 | return ERR_PTR(-EINVAL); | ||
| 312 | } | ||
| 313 | |||
| 314 | mode = args->args[0]; | ||
| 315 | |||
| 316 | if (mode != PHY_TYPE_USB3 && mode != PHY_TYPE_PCIE) { | ||
| 317 | dev_err(dev, "invalid phy mode select argument\n"); | ||
| 318 | return ERR_PTR(-EINVAL); | ||
| 319 | } | ||
| 320 | |||
| 321 | priv->mode = mode; | ||
| 322 | |||
| 323 | return priv->phy; | ||
| 324 | } | ||
| 325 | |||
| 326 | static const struct phy_ops phy_g12a_usb3_pcie_ops = { | ||
| 327 | .init = phy_g12a_usb3_pcie_init, | ||
| 328 | .exit = phy_g12a_usb3_pcie_exit, | ||
| 329 | .owner = THIS_MODULE, | ||
| 330 | }; | ||
| 331 | |||
| 332 | static int phy_g12a_usb3_pcie_probe(struct platform_device *pdev) | ||
| 333 | { | ||
| 334 | struct device *dev = &pdev->dev; | ||
| 335 | struct device_node *np = dev->of_node; | ||
| 336 | struct phy_g12a_usb3_pcie_priv *priv; | ||
| 337 | struct resource *res; | ||
| 338 | struct phy_provider *phy_provider; | ||
| 339 | void __iomem *base; | ||
| 340 | int ret; | ||
| 341 | |||
| 342 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 343 | if (!priv) | ||
| 344 | return -ENOMEM; | ||
| 345 | |||
| 346 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 347 | base = devm_ioremap_resource(dev, res); | ||
| 348 | if (IS_ERR(base)) | ||
| 349 | return PTR_ERR(base); | ||
| 350 | |||
| 351 | priv->regmap = devm_regmap_init_mmio(dev, base, | ||
| 352 | &phy_g12a_usb3_pcie_regmap_conf); | ||
| 353 | if (IS_ERR(priv->regmap)) | ||
| 354 | return PTR_ERR(priv->regmap); | ||
| 355 | |||
| 356 | priv->regmap_cr = devm_regmap_init(dev, NULL, priv, | ||
| 357 | &phy_g12a_usb3_pcie_cr_regmap_conf); | ||
| 358 | if (IS_ERR(priv->regmap_cr)) | ||
| 359 | return PTR_ERR(priv->regmap_cr); | ||
| 360 | |||
| 361 | priv->clk_ref = devm_clk_get(dev, "ref_clk"); | ||
| 362 | if (IS_ERR(priv->clk_ref)) | ||
| 363 | return PTR_ERR(priv->clk_ref); | ||
| 364 | |||
| 365 | ret = clk_prepare_enable(priv->clk_ref); | ||
| 366 | if (ret) | ||
| 367 | goto err_disable_clk_ref; | ||
| 368 | |||
| 369 | priv->reset = devm_reset_control_array_get(dev, false, false); | ||
| 370 | if (IS_ERR(priv->reset)) | ||
| 371 | return PTR_ERR(priv->reset); | ||
| 372 | |||
| 373 | priv->phy = devm_phy_create(dev, np, &phy_g12a_usb3_pcie_ops); | ||
| 374 | if (IS_ERR(priv->phy)) { | ||
| 375 | ret = PTR_ERR(priv->phy); | ||
| 376 | if (ret != -EPROBE_DEFER) | ||
| 377 | dev_err(dev, "failed to create PHY\n"); | ||
| 378 | |||
| 379 | return ret; | ||
| 380 | } | ||
| 381 | |||
| 382 | phy_set_drvdata(priv->phy, priv); | ||
| 383 | dev_set_drvdata(dev, priv); | ||
| 384 | |||
| 385 | phy_provider = devm_of_phy_provider_register(dev, | ||
| 386 | phy_g12a_usb3_pcie_xlate); | ||
| 387 | |||
| 388 | return PTR_ERR_OR_ZERO(phy_provider); | ||
| 389 | |||
| 390 | err_disable_clk_ref: | ||
| 391 | clk_disable_unprepare(priv->clk_ref); | ||
| 392 | |||
| 393 | return ret; | ||
| 394 | } | ||
| 395 | |||
| 396 | static const struct of_device_id phy_g12a_usb3_pcie_of_match[] = { | ||
| 397 | { .compatible = "amlogic,g12a-usb3-pcie-phy", }, | ||
| 398 | { }, | ||
| 399 | }; | ||
| 400 | MODULE_DEVICE_TABLE(of, phy_g12a_usb3_pcie_of_match); | ||
| 401 | |||
| 402 | static struct platform_driver phy_g12a_usb3_pcie_driver = { | ||
| 403 | .probe = phy_g12a_usb3_pcie_probe, | ||
| 404 | .driver = { | ||
| 405 | .name = "phy-g12a-usb3-pcie", | ||
| 406 | .of_match_table = phy_g12a_usb3_pcie_of_match, | ||
| 407 | }, | ||
| 408 | }; | ||
| 409 | module_platform_driver(phy_g12a_usb3_pcie_driver); | ||
| 410 | |||
| 411 | MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>"); | ||
| 412 | MODULE_DESCRIPTION("Amlogic G12A USB3 + PCIE Combo PHY driver"); | ||
| 413 | MODULE_LICENSE("GPL v2"); | ||
| @@ -261,14 +261,9 @@ static int phy_meson_gxl_usb2_probe(struct platform_device *pdev) · 260 unmodified lines | |||
| 261 | if (IS_ERR(priv->regmap)) | 261 | if (IS_ERR(priv->regmap)) |
| 262 | return PTR_ERR(priv->regmap); | 262 | return PTR_ERR(priv->regmap); |
| 263 | 263 | ||
| 264 | priv->clk = devm_clk_get(dev, "phy"); | 264 | priv->clk = devm_clk_get_optional(dev, "phy"); |
| 265 | if (IS_ERR(priv->clk)) { | 265 | if (IS_ERR(priv->clk)) |
| 266 | ret = PTR_ERR(priv->clk); | 266 | return PTR_ERR(priv->clk); |
| 267 | if (ret == -ENOENT) | ||
| 268 | priv->clk = NULL; | ||
| 269 | else | ||
| 270 | return ret; | ||
| 271 | } | ||
| 272 | 267 | ||
| 273 | priv->reset = devm_reset_control_get_optional_shared(dev, "phy"); | 268 | priv->reset = devm_reset_control_get_optional_shared(dev, "phy"); |
| 274 | if (IS_ERR(priv->reset)) | 269 | if (IS_ERR(priv->reset)) |
| @@ -10,6 +10,17 @@ config PHY_CYGNUS_PCIE · 9 unmodified lines | |||
| 10 | Enable this to support the Broadcom Cygnus PCIe PHY. | 10 | Enable this to support the Broadcom Cygnus PCIe PHY. |
| 11 | If unsure, say N. | 11 | If unsure, say N. |
| 12 | 12 | ||
| 13 | config PHY_BCM_SR_USB | ||
| 14 | tristate "Broadcom Stingray USB PHY driver" | ||
| 15 | depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST) | ||
| 16 | select GENERIC_PHY | ||
| 17 | default ARCH_BCM_IPROC | ||
| 18 | help | ||
| 19 | Enable this to support the Broadcom Stingray USB PHY | ||
| 20 | driver. It supports all versions of Superspeed and | ||
| 21 | Highspeed PHYs. | ||
| 22 | If unsure, say N. | ||
| 23 | |||
| 13 | config BCM_KONA_USB2_PHY | 24 | config BCM_KONA_USB2_PHY |
| 14 | tristate "Broadcom Kona USB2 PHY Driver" | 25 | tristate "Broadcom Kona USB2 PHY Driver" |
| 15 | depends on HAS_IOMEM | 26 | depends on HAS_IOMEM |
| @@ -11,3 +11,4 @@ obj-$(CONFIG_PHY_BRCM_USB) += phy-brcm-usb-dvr.o · 10 unmodified lines | |||
| 11 | phy-brcm-usb-dvr-objs := phy-brcm-usb.o phy-brcm-usb-init.o | 11 | phy-brcm-usb-dvr-objs := phy-brcm-usb.o phy-brcm-usb-init.o |
| 12 | 12 | ||
| 13 | obj-$(CONFIG_PHY_BCM_SR_PCIE) += phy-bcm-sr-pcie.o | 13 | obj-$(CONFIG_PHY_BCM_SR_PCIE) += phy-bcm-sr-pcie.o |
| 14 | obj-$(CONFIG_PHY_BCM_SR_USB) += phy-bcm-sr-usb.o | ||
| @@ -0,0 +1,394 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2016-2018 Broadcom | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <linux/delay.h> | ||
| 7 | #include <linux/io.h> | ||
| 8 | #include <linux/module.h> | ||
| 9 | #include <linux/of.h> | ||
| 10 | #include <linux/phy/phy.h> | ||
| 11 | #include <linux/platform_device.h> | ||
| 12 | |||
| 13 | enum bcm_usb_phy_version { | ||
| 14 | BCM_SR_USB_COMBO_PHY, | ||
| 15 | BCM_SR_USB_HS_PHY, | ||
| 16 | }; | ||
| 17 | |||
| 18 | enum bcm_usb_phy_reg { | ||
| 19 | PLL_NDIV_FRAC, | ||
| 20 | PLL_NDIV_INT, | ||
| 21 | PLL_CTRL, | ||
| 22 | PHY_CTRL, | ||
| 23 | PHY_PLL_CTRL, | ||
| 24 | }; | ||
| 25 | |||
| 26 | /* USB PHY registers */ | ||
| 27 | |||
| 28 | static const u8 bcm_usb_combo_phy_ss[] = { | ||
| 29 | [PLL_CTRL] = 0x18, | ||
| 30 | [PHY_CTRL] = 0x14, | ||
| 31 | }; | ||
| 32 | |||
| 33 | static const u8 bcm_usb_combo_phy_hs[] = { | ||
| 34 | [PLL_NDIV_FRAC] = 0x04, | ||
| 35 | [PLL_NDIV_INT] = 0x08, | ||
| 36 | [PLL_CTRL] = 0x0c, | ||
| 37 | [PHY_CTRL] = 0x10, | ||
| 38 | }; | ||
| 39 | |||
| 40 | #define HSPLL_NDIV_INT_VAL 0x13 | ||
| 41 | #define HSPLL_NDIV_FRAC_VAL 0x1005 | ||
| 42 | |||
| 43 | static const u8 bcm_usb_hs_phy[] = { | ||
| 44 | [PLL_NDIV_FRAC] = 0x0, | ||
| 45 | [PLL_NDIV_INT] = 0x4, | ||
| 46 | [PLL_CTRL] = 0x8, | ||
| 47 | [PHY_CTRL] = 0xc, | ||
| 48 | }; | ||
| 49 | |||
| 50 | enum pll_ctrl_bits { | ||
| 51 | PLL_RESETB, | ||
| 52 | SSPLL_SUSPEND_EN, | ||
| 53 | PLL_SEQ_START, | ||
| 54 | PLL_LOCK, | ||
| 55 | PLL_PDIV, | ||
| 56 | }; | ||
| 57 | |||
| 58 | static const u8 u3pll_ctrl[] = { | ||
| 59 | [PLL_RESETB] = 0, | ||
| 60 | [SSPLL_SUSPEND_EN] = 1, | ||
| 61 | [PLL_SEQ_START] = 2, | ||
| 62 | [PLL_LOCK] = 3, | ||
| 63 | }; | ||
| 64 | |||
| 65 | #define HSPLL_PDIV_MASK 0xF | ||
| 66 | #define HSPLL_PDIV_VAL 0x1 | ||
| 67 | |||
| 68 | static const u8 u2pll_ctrl[] = { | ||
| 69 | [PLL_PDIV] = 1, | ||
| 70 | [PLL_RESETB] = 5, | ||
| 71 | [PLL_LOCK] = 6, | ||
| 72 | }; | ||
| 73 | |||
| 74 | enum bcm_usb_phy_ctrl_bits { | ||
| 75 | CORERDY, | ||
| 76 | AFE_LDO_PWRDWNB, | ||
| 77 | AFE_PLL_PWRDWNB, | ||
| 78 | AFE_BG_PWRDWNB, | ||
| 79 | PHY_ISO, | ||
| 80 | PHY_RESETB, | ||
| 81 | PHY_PCTL, | ||
| 82 | }; | ||
| 83 | |||
| 84 | #define PHY_PCTL_MASK 0xffff | ||
| 85 | /* | ||
| 86 | * 0x0806 of PCTL_VAL has below bits set | ||
| 87 | * BIT-8 : refclk divider 1 | ||
| 88 | * BIT-3:2: device mode; mode is not effect | ||
| 89 | * BIT-1: soft reset active low | ||
| 90 | */ | ||
| 91 | #define HSPHY_PCTL_VAL 0x0806 | ||
| 92 | #define SSPHY_PCTL_VAL 0x0006 | ||
| 93 | |||
| 94 | static const u8 u3phy_ctrl[] = { | ||
| 95 | [PHY_RESETB] = 1, | ||
| 96 | [PHY_PCTL] = 2, | ||
| 97 | }; | ||
| 98 | |||
| 99 | static const u8 u2phy_ctrl[] = { | ||
| 100 | [CORERDY] = 0, | ||
| 101 | [AFE_LDO_PWRDWNB] = 1, | ||
| 102 | [AFE_PLL_PWRDWNB] = 2, | ||
| 103 | [AFE_BG_PWRDWNB] = 3, | ||
| 104 | [PHY_ISO] = 4, | ||
| 105 | [PHY_RESETB] = 5, | ||
| 106 | [PHY_PCTL] = 6, | ||
| 107 | }; | ||
| 108 | |||
| 109 | struct bcm_usb_phy_cfg { | ||
| 110 | uint32_t type; | ||
| 111 | uint32_t version; | ||
| 112 | void __iomem *regs; | ||
| 113 | struct phy *phy; | ||
| 114 | const u8 *offset; | ||
| 115 | }; | ||
| 116 | |||
| 117 | #define PLL_LOCK_RETRY_COUNT 1000 | ||
| 118 | |||
| 119 | enum bcm_usb_phy_type { | ||
| 120 | USB_HS_PHY, | ||
| 121 | USB_SS_PHY, | ||
| 122 | }; | ||
| 123 | |||
| 124 | #define NUM_BCM_SR_USB_COMBO_PHYS 2 | ||
| 125 | |||
| 126 | static inline void bcm_usb_reg32_clrbits(void __iomem *addr, uint32_t clear) | ||
| 127 | { | ||
| 128 | writel(readl(addr) & ~clear, addr); | ||
| 129 | } | ||
| 130 | |||
| 131 | static inline void bcm_usb_reg32_setbits(void __iomem *addr, uint32_t set) | ||
| 132 | { | ||
| 133 | writel(readl(addr) | set, addr); | ||
| 134 | } | ||
| 135 | |||
| 136 | static int bcm_usb_pll_lock_check(void __iomem *addr, u32 bit) | ||
| 137 | { | ||
| 138 | int retry; | ||
| 139 | u32 rd_data; | ||
| 140 | |||
| 141 | retry = PLL_LOCK_RETRY_COUNT; | ||
| 142 | do { | ||
| 143 | rd_data = readl(addr); | ||
| 144 | if (rd_data & bit) | ||
| 145 | return 0; | ||
| 146 | udelay(1); | ||
| 147 | } while (--retry > 0); | ||
| 148 | |||
| 149 | pr_err("%s: FAIL\n", __func__); | ||
| 150 | return -ETIMEDOUT; | ||
| 151 | } | ||
| 152 | |||
| 153 | static int bcm_usb_ss_phy_init(struct bcm_usb_phy_cfg *phy_cfg) | ||
| 154 | { | ||
| 155 | int ret = 0; | ||
| 156 | void __iomem *regs = phy_cfg->regs; | ||
| 157 | const u8 *offset; | ||
| 158 | u32 rd_data; | ||
| 159 | |||
| 160 | offset = phy_cfg->offset; | ||
| 161 | |||
| 162 | /* Set pctl with mode and soft reset */ | ||
| 163 | rd_data = readl(regs + offset[PHY_CTRL]); | ||
| 164 | rd_data &= ~(PHY_PCTL_MASK << u3phy_ctrl[PHY_PCTL]); | ||
| 165 | rd_data |= (SSPHY_PCTL_VAL << u3phy_ctrl[PHY_PCTL]); | ||
| 166 | writel(rd_data, regs + offset[PHY_CTRL]); | ||
| 167 | |||
| 168 | bcm_usb_reg32_clrbits(regs + offset[PLL_CTRL], | ||
| 169 | BIT(u3pll_ctrl[SSPLL_SUSPEND_EN])); | ||
| 170 | bcm_usb_reg32_setbits(regs + offset[PLL_CTRL], | ||
| 171 | BIT(u3pll_ctrl[PLL_SEQ_START])); | ||
| 172 | bcm_usb_reg32_setbits(regs + offset[PLL_CTRL], | ||
| 173 | BIT(u3pll_ctrl[PLL_RESETB])); | ||
| 174 | |||
| 175 | /* Maximum timeout for PLL reset done */ | ||
| 176 | msleep(30); | ||
| 177 | |||
| 178 | ret = bcm_usb_pll_lock_check(regs + offset[PLL_CTRL], | ||
| 179 | BIT(u3pll_ctrl[PLL_LOCK])); | ||
| 180 | |||
| 181 | return ret; | ||
| 182 | } | ||
| 183 | |||
| 184 | static int bcm_usb_hs_phy_init(struct bcm_usb_phy_cfg *phy_cfg) | ||
| 185 | { | ||
| 186 | int ret = 0; | ||
| 187 | void __iomem *regs = phy_cfg->regs; | ||
| 188 | const u8 *offset; | ||
| 189 | u32 rd_data; | ||
| 190 | |||
| 191 | offset = phy_cfg->offset; | ||
| 192 | |||
| 193 | writel(HSPLL_NDIV_INT_VAL, regs + offset[PLL_NDIV_INT]); | ||
| 194 | writel(HSPLL_NDIV_FRAC_VAL, regs + offset[PLL_NDIV_FRAC]); | ||
| 195 | |||
| 196 | rd_data = readl(regs + offset[PLL_CTRL]); | ||
| 197 | rd_data &= ~(HSPLL_PDIV_MASK << u2pll_ctrl[PLL_PDIV]); | ||
| 198 | rd_data |= (HSPLL_PDIV_VAL << u2pll_ctrl[PLL_PDIV]); | ||
| 199 | writel(rd_data, regs + offset[PLL_CTRL]); | ||
| 200 | |||
| 201 | /* Set Core Ready high */ | ||
| 202 | bcm_usb_reg32_setbits(regs + offset[PHY_CTRL], | ||
| 203 | BIT(u2phy_ctrl[CORERDY])); | ||
| 204 | |||
| 205 | /* Maximum timeout for Core Ready done */ | ||
| 206 | msleep(30); | ||
| 207 | |||
| 208 | bcm_usb_reg32_setbits(regs + offset[PLL_CTRL], | ||
| 209 | BIT(u2pll_ctrl[PLL_RESETB])); | ||
| 210 | bcm_usb_reg32_setbits(regs + offset[PHY_CTRL], | ||
| 211 | BIT(u2phy_ctrl[PHY_RESETB])); | ||
| 212 | |||
| 213 | |||
| 214 | rd_data = readl(regs + offset[PHY_CTRL]); | ||
| 215 | rd_data &= ~(PHY_PCTL_MASK << u2phy_ctrl[PHY_PCTL]); | ||
| 216 | rd_data |= (HSPHY_PCTL_VAL << u2phy_ctrl[PHY_PCTL]); | ||
| 217 | writel(rd_data, regs + offset[PHY_CTRL]); | ||
| 218 | |||
| 219 | /* Maximum timeout for PLL reset done */ | ||
| 220 | msleep(30); | ||
| 221 | |||
| 222 | ret = bcm_usb_pll_lock_check(regs + offset[PLL_CTRL], | ||
| 223 | BIT(u2pll_ctrl[PLL_LOCK])); | ||
| 224 | |||
| 225 | return ret; | ||
| 226 | } | ||
| 227 | |||
| 228 | static int bcm_usb_phy_reset(struct phy *phy) | ||
| 229 | { | ||
| 230 | struct bcm_usb_phy_cfg *phy_cfg = phy_get_drvdata(phy); | ||
| 231 | void __iomem *regs = phy_cfg->regs; | ||
| 232 | const u8 *offset; | ||
| 233 | |||
| 234 | offset = phy_cfg->offset; | ||
| 235 | |||
| 236 | if (phy_cfg->type == USB_HS_PHY) { | ||
| 237 | bcm_usb_reg32_clrbits(regs + offset[PHY_CTRL], | ||
| 238 | BIT(u2phy_ctrl[CORERDY])); | ||
| 239 | bcm_usb_reg32_setbits(regs + offset[PHY_CTRL], | ||
| 240 | BIT(u2phy_ctrl[CORERDY])); | ||
| 241 | } | ||
| 242 | |||
| 243 | return 0; | ||
| 244 | } | ||
| 245 | |||
| 246 | static int bcm_usb_phy_init(struct phy *phy) | ||
| 247 | { | ||
| 248 | struct bcm_usb_phy_cfg *phy_cfg = phy_get_drvdata(phy); | ||
| 249 | int ret = -EINVAL; | ||
| 250 | |||
| 251 | if (phy_cfg->type == USB_SS_PHY) | ||
| 252 | ret = bcm_usb_ss_phy_init(phy_cfg); | ||
| 253 | else if (phy_cfg->type == USB_HS_PHY) | ||
| 254 | ret = bcm_usb_hs_phy_init(phy_cfg); | ||
| 255 | |||
| 256 | return ret; | ||
| 257 | } | ||
| 258 | |||
| 259 | static struct phy_ops sr_phy_ops = { | ||
| 260 | .init = bcm_usb_phy_init, | ||
| 261 | .reset = bcm_usb_phy_reset, | ||
| 262 | .owner = THIS_MODULE, | ||
| 263 | }; | ||
| 264 | |||
| 265 | static struct phy *bcm_usb_phy_xlate(struct device *dev, | ||
| 266 | struct of_phandle_args *args) | ||
| 267 | { | ||
| 268 | struct bcm_usb_phy_cfg *phy_cfg; | ||
| 269 | int phy_idx; | ||
| 270 | |||
| 271 | phy_cfg = dev_get_drvdata(dev); | ||
| 272 | if (!phy_cfg) | ||
| 273 | return ERR_PTR(-EINVAL); | ||
| 274 | |||
| 275 | if (phy_cfg->version == BCM_SR_USB_COMBO_PHY) { | ||
| 276 | phy_idx = args->args[0]; | ||
| 277 | |||
| 278 | if (WARN_ON(phy_idx > 1)) | ||
| 279 | return ERR_PTR(-ENODEV); | ||
| 280 | |||
| 281 | return phy_cfg[phy_idx].phy; | ||
| 282 | } else | ||
| 283 | return phy_cfg->phy; | ||
| 284 | } | ||
| 285 | |||
| 286 | static int bcm_usb_phy_create(struct device *dev, struct device_node *node, | ||
| 287 | void __iomem *regs, uint32_t version) | ||
| 288 | { | ||
| 289 | struct bcm_usb_phy_cfg *phy_cfg; | ||
| 290 | int idx; | ||
| 291 | |||
| 292 | if (version == BCM_SR_USB_COMBO_PHY) { | ||
| 293 | phy_cfg = devm_kzalloc(dev, NUM_BCM_SR_USB_COMBO_PHYS * | ||
| 294 | sizeof(struct bcm_usb_phy_cfg), | ||
| 295 | GFP_KERNEL); | ||
| 296 | if (!phy_cfg) | ||
| 297 | return -ENOMEM; | ||
| 298 | |||
| 299 | for (idx = 0; idx < NUM_BCM_SR_USB_COMBO_PHYS; idx++) { | ||
| 300 | phy_cfg[idx].regs = regs; | ||
| 301 | phy_cfg[idx].version = version; | ||
| 302 | if (idx == 0) { | ||
| 303 | phy_cfg[idx].offset = bcm_usb_combo_phy_hs; | ||
| 304 | phy_cfg[idx].type = USB_HS_PHY; | ||
| 305 | } else { | ||
| 306 | phy_cfg[idx].offset = bcm_usb_combo_phy_ss; | ||
| 307 | phy_cfg[idx].type = USB_SS_PHY; | ||
| 308 | } | ||
| 309 | phy_cfg[idx].phy = devm_phy_create(dev, node, | ||
| 310 | &sr_phy_ops); | ||
| 311 | if (IS_ERR(phy_cfg[idx].phy)) | ||
| 312 | return PTR_ERR(phy_cfg[idx].phy); | ||
| 313 | |||
| 314 | phy_set_drvdata(phy_cfg[idx].phy, &phy_cfg[idx]); | ||
| 315 | } | ||
| 316 | } else if (version == BCM_SR_USB_HS_PHY) { | ||
| 317 | phy_cfg = devm_kzalloc(dev, sizeof(struct bcm_usb_phy_cfg), | ||
| 318 | GFP_KERNEL); | ||
| 319 | if (!phy_cfg) | ||
| 320 | return -ENOMEM; | ||
| 321 | |||
| 322 | phy_cfg->regs = regs; | ||
| 323 | phy_cfg->version = version; | ||
| 324 | phy_cfg->offset = bcm_usb_hs_phy; | ||
| 325 | phy_cfg->type = USB_HS_PHY; | ||
| 326 | phy_cfg->phy = devm_phy_create(dev, node, &sr_phy_ops); | ||
| 327 | if (IS_ERR(phy_cfg->phy)) | ||
| 328 | return PTR_ERR(phy_cfg->phy); | ||
| 329 | |||
| 330 | phy_set_drvdata(phy_cfg->phy, phy_cfg); | ||
| 331 | } else | ||
| 332 | return -ENODEV; | ||
| 333 | |||
| 334 | dev_set_drvdata(dev, phy_cfg); | ||
| 335 | |||
| 336 | return 0; | ||
| 337 | } | ||
| 338 | |||
| 339 | static const struct of_device_id bcm_usb_phy_of_match[] = { | ||
| 340 | { | ||
| 341 | .compatible = "brcm,sr-usb-combo-phy", | ||
| 342 | .data = (void *)BCM_SR_USB_COMBO_PHY, | ||
| 343 | }, | ||
| 344 | { | ||
| 345 | .compatible = "brcm,sr-usb-hs-phy", | ||
| 346 | .data = (void *)BCM_SR_USB_HS_PHY, | ||
| 347 | }, | ||
| 348 | { /* sentinel */ }, | ||
| 349 | }; | ||
| 350 | MODULE_DEVICE_TABLE(of, bcm_usb_phy_of_match); | ||
| 351 | |||
| 352 | static int bcm_usb_phy_probe(struct platform_device *pdev) | ||
| 353 | { | ||
| 354 | struct device *dev = &pdev->dev; | ||
| 355 | struct device_node *dn = dev->of_node; | ||
| 356 | const struct of_device_id *of_id; | ||
| 357 | struct resource *res; | ||
| 358 | void __iomem *regs; | ||
| 359 | int ret; | ||
| 360 | enum bcm_usb_phy_version version; | ||
| 361 | struct phy_provider *phy_provider; | ||
| 362 | |||
| 363 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 364 | regs = devm_ioremap_resource(dev, res); | ||
| 365 | if (IS_ERR(regs)) | ||
| 366 | return PTR_ERR(regs); | ||
| 367 | |||
| 368 | of_id = of_match_node(bcm_usb_phy_of_match, dn); | ||
| 369 | if (of_id) | ||
| 370 | version = (enum bcm_usb_phy_version)of_id->data; | ||
| 371 | else | ||
| 372 | return -ENODEV; | ||
| 373 | |||
| 374 | ret = bcm_usb_phy_create(dev, dn, regs, version); | ||
| 375 | if (ret) | ||
| 376 | return ret; | ||
| 377 | |||
| 378 | phy_provider = devm_of_phy_provider_register(dev, bcm_usb_phy_xlate); | ||
| 379 | |||
| 380 | return PTR_ERR_OR_ZERO(phy_provider); | ||
| 381 | } | ||
| 382 | |||
| 383 | static struct platform_driver bcm_usb_phy_driver = { | ||
| 384 | .driver = { | ||
| 385 | .name = "phy-bcm-sr-usb", | ||
| 386 | .of_match_table = bcm_usb_phy_of_match, | ||
| 387 | }, | ||
| 388 | .probe = bcm_usb_phy_probe, | ||
| 389 | }; | ||
| 390 | module_platform_driver(bcm_usb_phy_driver); | ||
| 391 | |||
| 392 | MODULE_AUTHOR("Broadcom"); | ||
| 393 | MODULE_DESCRIPTION("Broadcom stingray USB Phy driver"); | ||
| 394 | MODULE_LICENSE("GPL v2"); | ||
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | #include <linux/module.h> | 6 | #include <linux/module.h> |
| 7 | #include <linux/phy/phy.h> | 7 | #include <linux/phy/phy.h> |
| 8 | #include <linux/platform_device.h> | 8 | #include <linux/platform_device.h> |
| 9 | #include <linux/regulator/consumer.h> | ||
| 9 | 10 | ||
| 10 | #define PHY_CTRL0 0x0 | 11 | #define PHY_CTRL0 0x0 |
| 11 | #define PHY_CTRL0_REF_SSP_EN BIT(2) | 12 | #define PHY_CTRL0_REF_SSP_EN BIT(2) |
| @@ -24,6 +25,7 @@ struct imx8mq_usb_phy { · 12 unmodified lines | |||
| 24 | struct phy *phy; | 25 | struct phy *phy; |
| 25 | struct clk *clk; | 26 | struct clk *clk; |
| 26 | void __iomem *base; | 27 | void __iomem *base; |
| 28 | struct regulator *vbus; | ||
| 27 | }; | 29 | }; |
| 28 | 30 | ||
| 29 | static int imx8mq_usb_phy_init(struct phy *phy) | 31 | static int imx8mq_usb_phy_init(struct phy *phy) |
| @@ -55,6 +57,11 @@ static int imx8mq_usb_phy_init(struct phy *phy) · 25 unmodified lines | |||
| 55 | static int imx8mq_phy_power_on(struct phy *phy) | 57 | static int imx8mq_phy_power_on(struct phy *phy) |
| 56 | { | 58 | { |
| 57 | struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy); | 59 | struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy); |
| 60 | int ret; | ||
| 61 | |||
| 62 | ret = regulator_enable(imx_phy->vbus); | ||
| 63 | if (ret) | ||
| 64 | return ret; | ||
| 58 | 65 | ||
| 59 | return clk_prepare_enable(imx_phy->clk); | 66 | return clk_prepare_enable(imx_phy->clk); |
| 60 | } | 67 | } |
| @@ -64,6 +71,7 @@ static int imx8mq_phy_power_off(struct phy *phy) · 3 unmodified lines | |||
| 64 | struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy); | 71 | struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy); |
| 65 | 72 | ||
| 66 | clk_disable_unprepare(imx_phy->clk); | 73 | clk_disable_unprepare(imx_phy->clk); |
| 74 | regulator_disable(imx_phy->vbus); | ||
| 67 | 75 | ||
| 68 | return 0; | 76 | return 0; |
| 69 | } | 77 | } |
| @@ -101,6 +109,10 @@ static int imx8mq_usb_phy_probe(struct platform_device *pdev) · 31 unmodified lines | |||
| 101 | if (IS_ERR(imx_phy->phy)) | 109 | if (IS_ERR(imx_phy->phy)) |
| 102 | return PTR_ERR(imx_phy->phy); | 110 | return PTR_ERR(imx_phy->phy); |
| 103 | 111 | ||
| 112 | imx_phy->vbus = devm_regulator_get(dev, "vbus"); | ||
| 113 | if (IS_ERR(imx_phy->vbus)) | ||
| 114 | return PTR_ERR(imx_phy->vbus); | ||
| 115 | |||
| 104 | phy_set_drvdata(imx_phy->phy, imx_phy); | 116 | phy_set_drvdata(imx_phy->phy, imx_phy); |
| 105 | 117 | ||
| 106 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | 118 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); |
| @@ -12,6 +12,16 @@ config PHY_HI6220_USB · 11 unmodified lines | |||
| 12 | 12 | ||
| 13 | To compile this driver as a module, choose M here. | 13 | To compile this driver as a module, choose M here. |
| 14 | 14 | ||
| 15 | config PHY_HI3660_USB | ||
| 16 | tristate "hi3660 USB PHY support" | ||
| 17 | depends on (ARCH_HISI && ARM64) || COMPILE_TEST | ||
| 18 | select GENERIC_PHY | ||
| 19 | select MFD_SYSCON | ||
| 20 | help | ||
| 21 | Enable this to support the HISILICON HI3660 USB PHY. | ||
| 22 | |||
| 23 | To compile this driver as a module, choose M here. | ||
| 24 | |||
| 15 | config PHY_HISTB_COMBPHY | 25 | config PHY_HISTB_COMBPHY |
| 16 | tristate "HiSilicon STB SoCs COMBPHY support" | 26 | tristate "HiSilicon STB SoCs COMBPHY support" |
| 17 | depends on (ARCH_HISI && ARM64) || COMPILE_TEST | 27 | depends on (ARCH_HISI && ARM64) || COMPILE_TEST |
| @@ -1,4 +1,5 @@ | |||
| 1 | obj-$(CONFIG_PHY_HI6220_USB) += phy-hi6220-usb.o | 1 | obj-$(CONFIG_PHY_HI6220_USB) += phy-hi6220-usb.o |
| 2 | obj-$(CONFIG_PHY_HI3660_USB) += phy-hi3660-usb3.o | ||
| 2 | obj-$(CONFIG_PHY_HISTB_COMBPHY) += phy-histb-combphy.o | 3 | obj-$(CONFIG_PHY_HISTB_COMBPHY) += phy-histb-combphy.o |
| 3 | obj-$(CONFIG_PHY_HISI_INNO_USB2) += phy-hisi-inno-usb2.o | 4 | obj-$(CONFIG_PHY_HISI_INNO_USB2) += phy-hisi-inno-usb2.o |
| 4 | obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o | 5 | obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o |
| @@ -0,0 +1,233 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Phy provider for USB 3.0 controller on HiSilicon 3660 platform | ||
| 4 | * | ||
| 5 | * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd. | ||
| 6 | * http://www.huawei.com | ||
| 7 | * | ||
| 8 | * Authors: Yu Chen <chenyu56@huawei.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/kernel.h> | ||
| 12 | #include <linux/mfd/syscon.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/phy/phy.h> | ||
| 15 | #include <linux/platform_device.h> | ||
| 16 | #include <linux/regmap.h> | ||
| 17 | |||
| 18 | #define PERI_CRG_CLK_EN4 0x40 | ||
| 19 | #define PERI_CRG_CLK_DIS4 0x44 | ||
| 20 | #define GT_CLK_USB3OTG_REF BIT(0) | ||
| 21 | #define GT_ACLK_USB3OTG BIT(1) | ||
| 22 | |||
| 23 | #define PERI_CRG_RSTEN4 0x90 | ||
| 24 | #define PERI_CRG_RSTDIS4 0x94 | ||
| 25 | #define IP_RST_USB3OTGPHY_POR BIT(3) | ||
| 26 | #define IP_RST_USB3OTG BIT(5) | ||
| 27 | |||
| 28 | #define PERI_CRG_ISODIS 0x148 | ||
| 29 | #define USB_REFCLK_ISO_EN BIT(25) | ||
| 30 | |||
| 31 | #define PCTRL_PERI_CTRL3 0x10 | ||
| 32 | #define PCTRL_PERI_CTRL3_MSK_START 16 | ||
| 33 | #define USB_TCXO_EN BIT(1) | ||
| 34 | |||
| 35 | #define PCTRL_PERI_CTRL24 0x64 | ||
| 36 | #define SC_CLK_USB3PHY_3MUX1_SEL BIT(25) | ||
| 37 | |||
| 38 | #define USBOTG3_CTRL0 0x00 | ||
| 39 | #define SC_USB3PHY_ABB_GT_EN BIT(15) | ||
| 40 | |||
| 41 | #define USBOTG3_CTRL2 0x08 | ||
| 42 | #define USBOTG3CTRL2_POWERDOWN_HSP BIT(0) | ||
| 43 | #define USBOTG3CTRL2_POWERDOWN_SSP BIT(1) | ||
| 44 | |||
| 45 | #define USBOTG3_CTRL3 0x0C | ||
| 46 | #define USBOTG3_CTRL3_VBUSVLDEXT BIT(6) | ||
| 47 | #define USBOTG3_CTRL3_VBUSVLDEXTSEL BIT(5) | ||
| 48 | |||
| 49 | #define USBOTG3_CTRL4 0x10 | ||
| 50 | |||
| 51 | #define USBOTG3_CTRL7 0x1c | ||
| 52 | #define REF_SSP_EN BIT(16) | ||
| 53 | |||
| 54 | /* This value config the default txtune parameter of the usb 2.0 phy */ | ||
| 55 | #define HI3660_USB_DEFAULT_PHY_PARAM 0x1c466e3 | ||
| 56 | |||
| 57 | struct hi3660_priv { | ||
| 58 | struct device *dev; | ||
| 59 | struct regmap *peri_crg; | ||
| 60 | struct regmap *pctrl; | ||
| 61 | struct regmap *otg_bc; | ||
| 62 | u32 eye_diagram_param; | ||
| 63 | }; | ||
| 64 | |||
| 65 | static int hi3660_phy_init(struct phy *phy) | ||
| 66 | { | ||
| 67 | struct hi3660_priv *priv = phy_get_drvdata(phy); | ||
| 68 | u32 val, mask; | ||
| 69 | int ret; | ||
| 70 | |||
| 71 | /* usb refclk iso disable */ | ||
| 72 | ret = regmap_write(priv->peri_crg, PERI_CRG_ISODIS, USB_REFCLK_ISO_EN); | ||
| 73 | if (ret) | ||
| 74 | goto out; | ||
| 75 | |||
| 76 | /* enable usb_tcxo_en */ | ||
| 77 | val = USB_TCXO_EN | (USB_TCXO_EN << PCTRL_PERI_CTRL3_MSK_START); | ||
| 78 | ret = regmap_write(priv->pctrl, PCTRL_PERI_CTRL3, val); | ||
| 79 | if (ret) | ||
| 80 | goto out; | ||
| 81 | |||
| 82 | /* assert phy */ | ||
| 83 | val = IP_RST_USB3OTGPHY_POR | IP_RST_USB3OTG; | ||
| 84 | ret = regmap_write(priv->peri_crg, PERI_CRG_RSTEN4, val); | ||
| 85 | if (ret) | ||
| 86 | goto out; | ||
| 87 | |||
| 88 | /* enable phy ref clk */ | ||
| 89 | val = SC_USB3PHY_ABB_GT_EN; | ||
| 90 | mask = val; | ||
| 91 | ret = regmap_update_bits(priv->otg_bc, USBOTG3_CTRL0, mask, val); | ||
| 92 | if (ret) | ||
| 93 | goto out; | ||
| 94 | |||
| 95 | val = REF_SSP_EN; | ||
| 96 | mask = val; | ||
| 97 | ret = regmap_update_bits(priv->otg_bc, USBOTG3_CTRL7, mask, val); | ||
| 98 | if (ret) | ||
| 99 | goto out; | ||
| 100 | |||
| 101 | /* exit from IDDQ mode */ | ||
| 102 | mask = USBOTG3CTRL2_POWERDOWN_HSP | USBOTG3CTRL2_POWERDOWN_SSP; | ||
| 103 | ret = regmap_update_bits(priv->otg_bc, USBOTG3_CTRL2, mask, 0); | ||
| 104 | if (ret) | ||
| 105 | goto out; | ||
| 106 | |||
| 107 | /* delay for exit from IDDQ mode */ | ||
| 108 | usleep_range(100, 120); | ||
| 109 | |||
| 110 | /* deassert phy */ | ||
| 111 | val = IP_RST_USB3OTGPHY_POR | IP_RST_USB3OTG; | ||
| 112 | ret = regmap_write(priv->peri_crg, PERI_CRG_RSTDIS4, val); | ||
| 113 | if (ret) | ||
| 114 | goto out; | ||
| 115 | |||
| 116 | /* delay for phy deasserted */ | ||
| 117 | usleep_range(10000, 15000); | ||
| 118 | |||
| 119 | /* fake vbus valid signal */ | ||
| 120 | val = USBOTG3_CTRL3_VBUSVLDEXT | USBOTG3_CTRL3_VBUSVLDEXTSEL; | ||
| 121 | mask = val; | ||
| 122 | ret = regmap_update_bits(priv->otg_bc, USBOTG3_CTRL3, mask, val); | ||
| 123 | if (ret) | ||
| 124 | goto out; | ||
| 125 | |||
| 126 | /* delay for vbus valid */ | ||
| 127 | usleep_range(100, 120); | ||
| 128 | |||
| 129 | ret = regmap_write(priv->otg_bc, USBOTG3_CTRL4, | ||
| 130 | priv->eye_diagram_param); | ||
| 131 | if (ret) | ||
| 132 | goto out; | ||
| 133 | |||
| 134 | return 0; | ||
| 135 | out: | ||
| 136 | dev_err(priv->dev, "failed to init phy ret: %d\n", ret); | ||
| 137 | return ret; | ||
| 138 | } | ||
| 139 | |||
| 140 | static int hi3660_phy_exit(struct phy *phy) | ||
| 141 | { | ||
| 142 | struct hi3660_priv *priv = phy_get_drvdata(phy); | ||
| 143 | u32 val; | ||
| 144 | int ret; | ||
| 145 | |||
| 146 | /* assert phy */ | ||
| 147 | val = IP_RST_USB3OTGPHY_POR; | ||
| 148 | ret = regmap_write(priv->peri_crg, PERI_CRG_RSTEN4, val); | ||
| 149 | if (ret) | ||
| 150 | goto out; | ||
| 151 | |||
| 152 | /* disable usb_tcxo_en */ | ||
| 153 | val = USB_TCXO_EN << PCTRL_PERI_CTRL3_MSK_START; | ||
| 154 | ret = regmap_write(priv->pctrl, PCTRL_PERI_CTRL3, val); | ||
| 155 | if (ret) | ||
| 156 | goto out; | ||
| 157 | |||
| 158 | return 0; | ||
| 159 | out: | ||
| 160 | dev_err(priv->dev, "failed to exit phy ret: %d\n", ret); | ||
| 161 | return ret; | ||
| 162 | } | ||
| 163 | |||
| 164 | static struct phy_ops hi3660_phy_ops = { | ||
| 165 | .init = hi3660_phy_init, | ||
| 166 | .exit = hi3660_phy_exit, | ||
| 167 | .owner = THIS_MODULE, | ||
| 168 | }; | ||
| 169 | |||
| 170 | static int hi3660_phy_probe(struct platform_device *pdev) | ||
| 171 | { | ||
| 172 | struct phy_provider *phy_provider; | ||
| 173 | struct device *dev = &pdev->dev; | ||
| 174 | struct phy *phy; | ||
| 175 | struct hi3660_priv *priv; | ||
| 176 | |||
| 177 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 178 | if (!priv) | ||
| 179 | return -ENOMEM; | ||
| 180 | |||
| 181 | priv->dev = dev; | ||
| 182 | priv->peri_crg = syscon_regmap_lookup_by_phandle(dev->of_node, | ||
| 183 | "hisilicon,pericrg-syscon"); | ||
| 184 | if (IS_ERR(priv->peri_crg)) { | ||
| 185 | dev_err(dev, "no hisilicon,pericrg-syscon\n"); | ||
| 186 | return PTR_ERR(priv->peri_crg); | ||
| 187 | } | ||
| 188 | |||
| 189 | priv->pctrl = syscon_regmap_lookup_by_phandle(dev->of_node, | ||
| 190 | "hisilicon,pctrl-syscon"); | ||
| 191 | if (IS_ERR(priv->pctrl)) { | ||
| 192 | dev_err(dev, "no hisilicon,pctrl-syscon\n"); | ||
| 193 | return PTR_ERR(priv->pctrl); | ||
| 194 | } | ||
| 195 | |||
| 196 | /* node of hi3660 phy is a sub-node of usb3_otg_bc */ | ||
| 197 | priv->otg_bc = syscon_node_to_regmap(dev->parent->of_node); | ||
| 198 | if (IS_ERR(priv->otg_bc)) { | ||
| 199 | dev_err(dev, "no hisilicon,usb3-otg-bc-syscon\n"); | ||
| 200 | return PTR_ERR(priv->otg_bc); | ||
| 201 | } | ||
| 202 | |||
| 203 | if (of_property_read_u32(dev->of_node, "hisilicon,eye-diagram-param", | ||
| 204 | &(priv->eye_diagram_param))) | ||
| 205 | priv->eye_diagram_param = HI3660_USB_DEFAULT_PHY_PARAM; | ||
| 206 | |||
| 207 | phy = devm_phy_create(dev, NULL, &hi3660_phy_ops); | ||
| 208 | if (IS_ERR(phy)) | ||
| 209 | return PTR_ERR(phy); | ||
| 210 | |||
| 211 | phy_set_drvdata(phy, priv); | ||
| 212 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
| 213 | return PTR_ERR_OR_ZERO(phy_provider); | ||
| 214 | } | ||
| 215 | |||
| 216 | static const struct of_device_id hi3660_phy_of_match[] = { | ||
| 217 | {.compatible = "hisilicon,hi3660-usb-phy",}, | ||
| 218 | { } | ||
| 219 | }; | ||
| 220 | MODULE_DEVICE_TABLE(of, hi3660_phy_of_match); | ||
| 221 | |||
| 222 | static struct platform_driver hi3660_phy_driver = { | ||
| 223 | .probe = hi3660_phy_probe, | ||
| 224 | .driver = { | ||
| 225 | .name = "hi3660-usb-phy", | ||
| 226 | .of_match_table = hi3660_phy_of_match, | ||
| 227 | } | ||
| 228 | }; | ||
| 229 | module_platform_driver(hi3660_phy_driver); | ||
| 230 | |||
| 231 | MODULE_AUTHOR("Yu Chen <chenyu56@huawei.com>"); | ||
| 232 | MODULE_LICENSE("GPL v2"); | ||
| 233 | MODULE_DESCRIPTION("Hilisicon Hi3660 USB3 PHY Driver"); | ||
| @@ -13,6 +13,16 @@ config PHY_MTK_TPHY · 12 unmodified lines | |||
| 13 | multi-ports is first version, otherwise is second veriosn, | 13 | multi-ports is first version, otherwise is second veriosn, |
| 14 | so you can easily distinguish them by banks layout. | 14 | so you can easily distinguish them by banks layout. |
| 15 | 15 | ||
| 16 | config PHY_MTK_UFS | ||
| 17 | tristate "MediaTek UFS M-PHY driver" | ||
| 18 | depends on ARCH_MEDIATEK && OF | ||
| 19 | select GENERIC_PHY | ||
| 20 | help | ||
| 21 | Support for UFS M-PHY on MediaTek chipsets. | ||
| 22 | Enable this to provide vendor-specific probing, | ||
| 23 | initialization, power on and power off flow of | ||
| 24 | specified M-PHYs. | ||
| 25 | |||
| 16 | config PHY_MTK_XSPHY | 26 | config PHY_MTK_XSPHY |
| 17 | tristate "MediaTek XS-PHY Driver" | 27 | tristate "MediaTek XS-PHY Driver" |
| 18 | depends on ARCH_MEDIATEK && OF | 28 | depends on ARCH_MEDIATEK && OF |
| @@ -4,4 +4,5 @@ · 3 unmodified lines | |||
| 4 | # | 4 | # |
| 5 | 5 | ||
| 6 | obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o | 6 | obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o |
| 7 | obj-$(CONFIG_PHY_MTK_UFS) += phy-mtk-ufs.o | ||
| 7 | obj-$(CONFIG_PHY_MTK_XSPHY) += phy-mtk-xsphy.o | 8 | obj-$(CONFIG_PHY_MTK_XSPHY) += phy-mtk-xsphy.o |
| @@ -1103,13 +1103,9 @@ static int mtk_tphy_probe(struct platform_device *pdev) · 1102 unmodified lines | |||
| 1103 | } | 1103 | } |
| 1104 | 1104 | ||
| 1105 | /* it's deprecated, make it optional for backward compatibility */ | 1105 | /* it's deprecated, make it optional for backward compatibility */ |
| 1106 | tphy->u3phya_ref = devm_clk_get(dev, "u3phya_ref"); | 1106 | tphy->u3phya_ref = devm_clk_get_optional(dev, "u3phya_ref"); |
| 1107 | if (IS_ERR(tphy->u3phya_ref)) { | 1107 | if (IS_ERR(tphy->u3phya_ref)) |
| 1108 | if (PTR_ERR(tphy->u3phya_ref) == -EPROBE_DEFER) | 1108 | return PTR_ERR(tphy->u3phya_ref); |
| 1109 | return -EPROBE_DEFER; | ||
| 1110 | |||
| 1111 | tphy->u3phya_ref = NULL; | ||
| 1112 | } | ||
| 1113 | 1109 | ||
| 1114 | tphy->src_ref_clk = U3P_REF_CLK; | 1110 | tphy->src_ref_clk = U3P_REF_CLK; |
| 1115 | tphy->src_coef = U3P_SLEW_RATE_COEF; | 1111 | tphy->src_coef = U3P_SLEW_RATE_COEF; |
| @@ -0,0 +1,245 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2019 MediaTek Inc. | ||
| 4 | * Author: Stanley Chu <stanley.chu@mediatek.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <linux/clk.h> | ||
| 8 | #include <linux/delay.h> | ||
| 9 | #include <linux/io.h> | ||
| 10 | #include <linux/module.h> | ||
| 11 | #include <linux/phy/phy.h> | ||
| 12 | #include <linux/platform_device.h> | ||
| 13 | |||
| 14 | /* mphy register and offsets */ | ||
| 15 | #define MP_GLB_DIG_8C 0x008C | ||
| 16 | #define FRC_PLL_ISO_EN BIT(8) | ||
| 17 | #define PLL_ISO_EN BIT(9) | ||
| 18 | #define FRC_FRC_PWR_ON BIT(10) | ||
| 19 | #define PLL_PWR_ON BIT(11) | ||
| 20 | |||
| 21 | #define MP_LN_DIG_RX_9C 0xA09C | ||
| 22 | #define FSM_DIFZ_FRC BIT(18) | ||
| 23 | |||
| 24 | #define MP_LN_DIG_RX_AC 0xA0AC | ||
| 25 | #define FRC_RX_SQ_EN BIT(0) | ||
| 26 | #define RX_SQ_EN BIT(1) | ||
| 27 | |||
| 28 | #define MP_LN_RX_44 0xB044 | ||
| 29 | #define FRC_CDR_PWR_ON BIT(17) | ||
| 30 | #define CDR_PWR_ON BIT(18) | ||
| 31 | #define FRC_CDR_ISO_EN BIT(19) | ||
| 32 | #define CDR_ISO_EN BIT(20) | ||
| 33 | |||
| 34 | struct ufs_mtk_phy { | ||
| 35 | struct device *dev; | ||
| 36 | void __iomem *mmio; | ||
| 37 | struct clk *mp_clk; | ||
| 38 | struct clk *unipro_clk; | ||
| 39 | }; | ||
| 40 | |||
| 41 | static inline u32 mphy_readl(struct ufs_mtk_phy *phy, u32 reg) | ||
| 42 | { | ||
| 43 | return readl(phy->mmio + reg); | ||
| 44 | } | ||
| 45 | |||
| 46 | static inline void mphy_writel(struct ufs_mtk_phy *phy, u32 val, u32 reg) | ||
| 47 | { | ||
| 48 | writel(val, phy->mmio + reg); | ||
| 49 | } | ||
| 50 | |||
| 51 | static void mphy_set_bit(struct ufs_mtk_phy *phy, u32 reg, u32 bit) | ||
| 52 | { | ||
| 53 | u32 val; | ||
| 54 | |||
| 55 | val = mphy_readl(phy, reg); | ||
| 56 | val |= bit; | ||
| 57 | mphy_writel(phy, val, reg); | ||
| 58 | } | ||
| 59 | |||
| 60 | static void mphy_clr_bit(struct ufs_mtk_phy *phy, u32 reg, u32 bit) | ||
| 61 | { | ||
| 62 | u32 val; | ||
| 63 | |||
| 64 | val = mphy_readl(phy, reg); | ||
| 65 | val &= ~bit; | ||
| 66 | mphy_writel(phy, val, reg); | ||
| 67 | } | ||
| 68 | |||
| 69 | static struct ufs_mtk_phy *get_ufs_mtk_phy(struct phy *generic_phy) | ||
| 70 | { | ||
| 71 | return (struct ufs_mtk_phy *)phy_get_drvdata(generic_phy); | ||
| 72 | } | ||
| 73 | |||
| 74 | static int ufs_mtk_phy_clk_init(struct ufs_mtk_phy *phy) | ||
| 75 | { | ||
| 76 | struct device *dev = phy->dev; | ||
| 77 | |||
| 78 | phy->unipro_clk = devm_clk_get(dev, "unipro"); | ||
| 79 | if (IS_ERR(phy->unipro_clk)) { | ||
| 80 | dev_err(dev, "failed to get clock: unipro"); | ||
| 81 | return PTR_ERR(phy->unipro_clk); | ||
| 82 | } | ||
| 83 | |||
| 84 | phy->mp_clk = devm_clk_get(dev, "mp"); | ||
| 85 | if (IS_ERR(phy->mp_clk)) { | ||
| 86 | dev_err(dev, "failed to get clock: mp"); | ||
| 87 | return PTR_ERR(phy->mp_clk); | ||
| 88 | } | ||
| 89 | |||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | static void ufs_mtk_phy_set_active(struct ufs_mtk_phy *phy) | ||
| 94 | { | ||
| 95 | /* release DA_MP_PLL_PWR_ON */ | ||
| 96 | mphy_set_bit(phy, MP_GLB_DIG_8C, PLL_PWR_ON); | ||
| 97 | mphy_clr_bit(phy, MP_GLB_DIG_8C, FRC_FRC_PWR_ON); | ||
| 98 | |||
| 99 | /* release DA_MP_PLL_ISO_EN */ | ||
| 100 | mphy_clr_bit(phy, MP_GLB_DIG_8C, PLL_ISO_EN); | ||
| 101 | mphy_clr_bit(phy, MP_GLB_DIG_8C, FRC_PLL_ISO_EN); | ||
| 102 | |||
| 103 | /* release DA_MP_CDR_PWR_ON */ | ||
| 104 | mphy_set_bit(phy, MP_LN_RX_44, CDR_PWR_ON); | ||
| 105 | mphy_clr_bit(phy, MP_LN_RX_44, FRC_CDR_PWR_ON); | ||
| 106 | |||
| 107 | /* release DA_MP_CDR_ISO_EN */ | ||
| 108 | mphy_clr_bit(phy, MP_LN_RX_44, CDR_ISO_EN); | ||
| 109 | mphy_clr_bit(phy, MP_LN_RX_44, FRC_CDR_ISO_EN); | ||
| 110 | |||
| 111 | /* release DA_MP_RX0_SQ_EN */ | ||
| 112 | mphy_set_bit(phy, MP_LN_DIG_RX_AC, RX_SQ_EN); | ||
| 113 | mphy_clr_bit(phy, MP_LN_DIG_RX_AC, FRC_RX_SQ_EN); | ||
| 114 | |||
| 115 | /* delay 1us to wait DIFZ stable */ | ||
| 116 | udelay(1); | ||
| 117 | |||
| 118 | /* release DIFZ */ | ||
| 119 | mphy_clr_bit(phy, MP_LN_DIG_RX_9C, FSM_DIFZ_FRC); | ||
| 120 | } | ||
| 121 | |||
| 122 | static void ufs_mtk_phy_set_deep_hibern(struct ufs_mtk_phy *phy) | ||
| 123 | { | ||
| 124 | /* force DIFZ */ | ||
| 125 | mphy_set_bit(phy, MP_LN_DIG_RX_9C, FSM_DIFZ_FRC); | ||
| 126 | |||
| 127 | /* force DA_MP_RX0_SQ_EN */ | ||
| 128 | mphy_set_bit(phy, MP_LN_DIG_RX_AC, FRC_RX_SQ_EN); | ||
| 129 | mphy_clr_bit(phy, MP_LN_DIG_RX_AC, RX_SQ_EN); | ||
| 130 | |||
| 131 | /* force DA_MP_CDR_ISO_EN */ | ||
| 132 | mphy_set_bit(phy, MP_LN_RX_44, FRC_CDR_ISO_EN); | ||
| 133 | mphy_set_bit(phy, MP_LN_RX_44, CDR_ISO_EN); | ||
| 134 | |||
| 135 | /* force DA_MP_CDR_PWR_ON */ | ||
| 136 | mphy_set_bit(phy, MP_LN_RX_44, FRC_CDR_PWR_ON); | ||
| 137 | mphy_clr_bit(phy, MP_LN_RX_44, CDR_PWR_ON); | ||
| 138 | |||
| 139 | /* force DA_MP_PLL_ISO_EN */ | ||
| 140 | mphy_set_bit(phy, MP_GLB_DIG_8C, FRC_PLL_ISO_EN); | ||
| 141 | mphy_set_bit(phy, MP_GLB_DIG_8C, PLL_ISO_EN); | ||
| 142 | |||
| 143 | /* force DA_MP_PLL_PWR_ON */ | ||
| 144 | mphy_set_bit(phy, MP_GLB_DIG_8C, FRC_FRC_PWR_ON); | ||
| 145 | mphy_clr_bit(phy, MP_GLB_DIG_8C, PLL_PWR_ON); | ||
| 146 | } | ||
| 147 | |||
| 148 | static int ufs_mtk_phy_power_on(struct phy *generic_phy) | ||
| 149 | { | ||
| 150 | struct ufs_mtk_phy *phy = get_ufs_mtk_phy(generic_phy); | ||
| 151 | int ret; | ||
| 152 | |||
| 153 | ret = clk_prepare_enable(phy->unipro_clk); | ||
| 154 | if (ret) { | ||
| 155 | dev_err(phy->dev, "unipro_clk enable failed %d\n", ret); | ||
| 156 | goto out; | ||
| 157 | } | ||
| 158 | |||
| 159 | ret = clk_prepare_enable(phy->mp_clk); | ||
| 160 | if (ret) { | ||
| 161 | dev_err(phy->dev, "mp_clk enable failed %d\n", ret); | ||
| 162 | goto out_unprepare_unipro_clk; | ||
| 163 | } | ||
| 164 | |||
| 165 | ufs_mtk_phy_set_active(phy); | ||
| 166 | |||
| 167 | return 0; | ||
| 168 | |||
| 169 | out_unprepare_unipro_clk: | ||
| 170 | clk_disable_unprepare(phy->unipro_clk); | ||
| 171 | out: | ||
| 172 | return ret; | ||
| 173 | } | ||
| 174 | |||
| 175 | static int ufs_mtk_phy_power_off(struct phy *generic_phy) | ||
| 176 | { | ||
| 177 | struct ufs_mtk_phy *phy = get_ufs_mtk_phy(generic_phy); | ||
| 178 | |||
| 179 | ufs_mtk_phy_set_deep_hibern(phy); | ||
| 180 | |||
| 181 | clk_disable_unprepare(phy->unipro_clk); | ||
| 182 | clk_disable_unprepare(phy->mp_clk); | ||
| 183 | |||
| 184 | return 0; | ||
| 185 | } | ||
| 186 | |||
| 187 | static const struct phy_ops ufs_mtk_phy_ops = { | ||
| 188 | .power_on = ufs_mtk_phy_power_on, | ||
| 189 | .power_off = ufs_mtk_phy_power_off, | ||
| 190 | .owner = THIS_MODULE, | ||
| 191 | }; | ||
| 192 | |||
| 193 | static int ufs_mtk_phy_probe(struct platform_device *pdev) | ||
| 194 | { | ||
| 195 | struct device *dev = &pdev->dev; | ||
| 196 | struct phy *generic_phy; | ||
| 197 | struct phy_provider *phy_provider; | ||
| 198 | struct resource *res; | ||
| 199 | struct ufs_mtk_phy *phy; | ||
| 200 | int ret; | ||
| 201 | |||
| 202 | phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); | ||
| 203 | if (!phy) | ||
| 204 | return -ENOMEM; | ||
| 205 | |||
| 206 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 207 | phy->mmio = devm_ioremap_resource(dev, res); | ||
| 208 | if (IS_ERR(phy->mmio)) | ||
| 209 | return PTR_ERR(phy->mmio); | ||
| 210 | |||
| 211 | phy->dev = dev; | ||
| 212 | |||
| 213 | ret = ufs_mtk_phy_clk_init(phy); | ||
| 214 | if (ret) | ||
| 215 | return ret; | ||
| 216 | |||
| 217 | generic_phy = devm_phy_create(dev, NULL, &ufs_mtk_phy_ops); | ||
| 218 | if (IS_ERR(generic_phy)) | ||
| 219 | return PTR_ERR(generic_phy); | ||
| 220 | |||
| 221 | phy_set_drvdata(generic_phy, phy); | ||
| 222 | |||
| 223 | phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | ||
| 224 | |||
| 225 | return PTR_ERR_OR_ZERO(phy_provider); | ||
| 226 | } | ||
| 227 | |||
| 228 | static const struct of_device_id ufs_mtk_phy_of_match[] = { | ||
| 229 | {.compatible = "mediatek,mt8183-ufsphy"}, | ||
| 230 | {}, | ||
| 231 | }; | ||
| 232 | MODULE_DEVICE_TABLE(of, ufs_mtk_phy_of_match); | ||
| 233 | |||
| 234 | static struct platform_driver ufs_mtk_phy_driver = { | ||
| 235 | .probe = ufs_mtk_phy_probe, | ||
| 236 | .driver = { | ||
| 237 | .of_match_table = ufs_mtk_phy_of_match, | ||
| 238 | .name = "ufs_mtk_phy", | ||
| 239 | }, | ||
| 240 | }; | ||
| 241 | module_platform_driver(ufs_mtk_phy_driver); | ||
| 242 | |||
| 243 | MODULE_DESCRIPTION("Universal Flash Storage (UFS) MediaTek MPHY"); | ||
| 244 | MODULE_AUTHOR("Stanley Chu <stanley.chu@mediatek.com>"); | ||
| 245 | MODULE_LICENSE("GPL v2"); | ||
| @@ -31,6 +31,238 @@ struct serdes_macro { · 30 unmodified lines | |||
| 31 | struct serdes_ctrl *ctrl; | 31 | struct serdes_ctrl *ctrl; |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | #define MCB_S6G_CFG_TIMEOUT 50 | ||
| 35 | |||
| 36 | static int __serdes_write_mcb_s6g(struct regmap *regmap, u8 macro, u32 op) | ||
| 37 | { | ||
| 38 | unsigned int regval = 0; | ||
| 39 | |||
| 40 | regmap_write(regmap, HSIO_MCB_S6G_ADDR_CFG, op | | ||
| 41 | HSIO_MCB_S6G_ADDR_CFG_SERDES6G_ADDR(BIT(macro))); | ||
| 42 | |||
| 43 | return regmap_read_poll_timeout(regmap, HSIO_MCB_S6G_ADDR_CFG, regval, | ||
| 44 | (regval & op) != op, 100, | ||
| 45 | MCB_S6G_CFG_TIMEOUT * 1000); | ||
| 46 | } | ||
| 47 | |||
| 48 | static int serdes_commit_mcb_s6g(struct regmap *regmap, u8 macro) | ||
| 49 | { | ||
| 50 | return __serdes_write_mcb_s6g(regmap, macro, | ||
| 51 | HSIO_MCB_S6G_ADDR_CFG_SERDES6G_WR_ONE_SHOT); | ||
| 52 | } | ||
| 53 | |||
| 54 | static int serdes_update_mcb_s6g(struct regmap *regmap, u8 macro) | ||
| 55 | { | ||
| 56 | return __serdes_write_mcb_s6g(regmap, macro, | ||
| 57 | HSIO_MCB_S6G_ADDR_CFG_SERDES6G_RD_ONE_SHOT); | ||
| 58 | } | ||
| 59 | |||
| 60 | static int serdes_init_s6g(struct regmap *regmap, u8 serdes, int mode) | ||
| 61 | { | ||
| 62 | u32 pll_fsm_ctrl_data; | ||
| 63 | u32 ob_ena1v_mode; | ||
| 64 | u32 des_bw_ana; | ||
| 65 | u32 ob_ena_cas; | ||
| 66 | u32 if_mode; | ||
| 67 | u32 ob_lev; | ||
| 68 | u32 qrate; | ||
| 69 | int ret; | ||
| 70 | |||
| 71 | if (mode == PHY_INTERFACE_MODE_QSGMII) { | ||
| 72 | pll_fsm_ctrl_data = 120; | ||
| 73 | ob_ena1v_mode = 0; | ||
| 74 | ob_ena_cas = 0; | ||
| 75 | des_bw_ana = 5; | ||
| 76 | ob_lev = 24; | ||
| 77 | if_mode = 3; | ||
| 78 | qrate = 0; | ||
| 79 | } else { | ||
| 80 | pll_fsm_ctrl_data = 60; | ||
| 81 | ob_ena1v_mode = 1; | ||
| 82 | ob_ena_cas = 2; | ||
| 83 | des_bw_ana = 3; | ||
| 84 | ob_lev = 48; | ||
| 85 | if_mode = 1; | ||
| 86 | qrate = 1; | ||
| 87 | } | ||
| 88 | |||
| 89 | ret = serdes_update_mcb_s6g(regmap, serdes); | ||
| 90 | if (ret) | ||
| 91 | return ret; | ||
| 92 | |||
| 93 | /* Test pattern */ | ||
| 94 | |||
| 95 | regmap_update_bits(regmap, HSIO_S6G_COMMON_CFG, | ||
| 96 | HSIO_S6G_COMMON_CFG_SYS_RST, 0); | ||
| 97 | |||
| 98 | regmap_update_bits(regmap, HSIO_S6G_PLL_CFG, | ||
| 99 | HSIO_S6G_PLL_CFG_PLL_FSM_ENA, 0); | ||
| 100 | |||
| 101 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG, | ||
| 102 | HSIO_S6G_IB_CFG_IB_SIG_DET_ENA | | ||
| 103 | HSIO_S6G_IB_CFG_IB_REG_ENA | | ||
| 104 | HSIO_S6G_IB_CFG_IB_SAM_ENA | | ||
| 105 | HSIO_S6G_IB_CFG_IB_EQZ_ENA | | ||
| 106 | HSIO_S6G_IB_CFG_IB_CONCUR | | ||
| 107 | HSIO_S6G_IB_CFG_IB_CAL_ENA, | ||
| 108 | HSIO_S6G_IB_CFG_IB_SIG_DET_ENA | | ||
| 109 | HSIO_S6G_IB_CFG_IB_REG_ENA | | ||
| 110 | HSIO_S6G_IB_CFG_IB_SAM_ENA | | ||
| 111 | HSIO_S6G_IB_CFG_IB_EQZ_ENA | | ||
| 112 | HSIO_S6G_IB_CFG_IB_CONCUR); | ||
| 113 | |||
| 114 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG1, | ||
| 115 | HSIO_S6G_IB_CFG1_IB_FRC_OFFSET | | ||
| 116 | HSIO_S6G_IB_CFG1_IB_FRC_LP | | ||
| 117 | HSIO_S6G_IB_CFG1_IB_FRC_MID | | ||
| 118 | HSIO_S6G_IB_CFG1_IB_FRC_HP | | ||
| 119 | HSIO_S6G_IB_CFG1_IB_FILT_OFFSET | | ||
| 120 | HSIO_S6G_IB_CFG1_IB_FILT_LP | | ||
| 121 | HSIO_S6G_IB_CFG1_IB_FILT_MID | | ||
| 122 | HSIO_S6G_IB_CFG1_IB_FILT_HP, | ||
| 123 | HSIO_S6G_IB_CFG1_IB_FILT_OFFSET | | ||
| 124 | HSIO_S6G_IB_CFG1_IB_FILT_HP | | ||
| 125 | HSIO_S6G_IB_CFG1_IB_FILT_LP | | ||
| 126 | HSIO_S6G_IB_CFG1_IB_FILT_MID); | ||
| 127 | |||
| 128 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG2, | ||
| 129 | HSIO_S6G_IB_CFG2_IB_UREG_M, | ||
| 130 | HSIO_S6G_IB_CFG2_IB_UREG(4)); | ||
| 131 | |||
| 132 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG3, | ||
| 133 | HSIO_S6G_IB_CFG3_IB_INI_OFFSET_M | | ||
| 134 | HSIO_S6G_IB_CFG3_IB_INI_LP_M | | ||
| 135 | HSIO_S6G_IB_CFG3_IB_INI_MID_M | | ||
| 136 | HSIO_S6G_IB_CFG3_IB_INI_HP_M, | ||
| 137 | HSIO_S6G_IB_CFG3_IB_INI_OFFSET(31) | | ||
| 138 | HSIO_S6G_IB_CFG3_IB_INI_LP(1) | | ||
| 139 | HSIO_S6G_IB_CFG3_IB_INI_MID(31) | | ||
| 140 | HSIO_S6G_IB_CFG3_IB_INI_HP(0)); | ||
| 141 | |||
| 142 | regmap_update_bits(regmap, HSIO_S6G_MISC_CFG, | ||
| 143 | HSIO_S6G_MISC_CFG_LANE_RST, | ||
| 144 | HSIO_S6G_MISC_CFG_LANE_RST); | ||
| 145 | |||
| 146 | ret = serdes_commit_mcb_s6g(regmap, serdes); | ||
| 147 | if (ret) | ||
| 148 | return ret; | ||
| 149 | |||
| 150 | /* OB + DES + IB + SER CFG */ | ||
| 151 | regmap_update_bits(regmap, HSIO_S6G_OB_CFG, | ||
| 152 | HSIO_S6G_OB_CFG_OB_IDLE | | ||
| 153 | HSIO_S6G_OB_CFG_OB_ENA1V_MODE | | ||
| 154 | HSIO_S6G_OB_CFG_OB_POST0_M | | ||
| 155 | HSIO_S6G_OB_CFG_OB_PREC_M, | ||
| 156 | (ob_ena1v_mode ? HSIO_S6G_OB_CFG_OB_ENA1V_MODE : 0) | | ||
| 157 | HSIO_S6G_OB_CFG_OB_POST0(0) | | ||
| 158 | HSIO_S6G_OB_CFG_OB_PREC(0)); | ||
| 159 | |||
| 160 | regmap_update_bits(regmap, HSIO_S6G_OB_CFG1, | ||
| 161 | HSIO_S6G_OB_CFG1_OB_ENA_CAS_M | | ||
| 162 | HSIO_S6G_OB_CFG1_OB_LEV_M, | ||
| 163 | HSIO_S6G_OB_CFG1_OB_LEV(ob_lev) | | ||
| 164 | HSIO_S6G_OB_CFG1_OB_ENA_CAS(ob_ena_cas)); | ||
| 165 | |||
| 166 | regmap_update_bits(regmap, HSIO_S6G_DES_CFG, | ||
| 167 | HSIO_S6G_DES_CFG_DES_PHS_CTRL_M | | ||
| 168 | HSIO_S6G_DES_CFG_DES_CPMD_SEL_M | | ||
| 169 | HSIO_S6G_DES_CFG_DES_BW_ANA_M, | ||
| 170 | HSIO_S6G_DES_CFG_DES_PHS_CTRL(2) | | ||
| 171 | HSIO_S6G_DES_CFG_DES_CPMD_SEL(0) | | ||
| 172 | HSIO_S6G_DES_CFG_DES_BW_ANA(des_bw_ana)); | ||
| 173 | |||
| 174 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG, | ||
| 175 | HSIO_S6G_IB_CFG_IB_SIG_DET_CLK_SEL_M | | ||
| 176 | HSIO_S6G_IB_CFG_IB_REG_PAT_SEL_OFFSET_M, | ||
| 177 | HSIO_S6G_IB_CFG_IB_REG_PAT_SEL_OFFSET(0) | | ||
| 178 | HSIO_S6G_IB_CFG_IB_SIG_DET_CLK_SEL(0)); | ||
| 179 | |||
| 180 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG1, | ||
| 181 | HSIO_S6G_IB_CFG1_IB_TSDET_M, | ||
| 182 | HSIO_S6G_IB_CFG1_IB_TSDET(16)); | ||
| 183 | |||
| 184 | regmap_update_bits(regmap, HSIO_S6G_SER_CFG, | ||
| 185 | HSIO_S6G_SER_CFG_SER_ALISEL_M | | ||
| 186 | HSIO_S6G_SER_CFG_SER_ENALI, | ||
| 187 | HSIO_S6G_SER_CFG_SER_ALISEL(0)); | ||
| 188 | |||
| 189 | regmap_update_bits(regmap, HSIO_S6G_PLL_CFG, | ||
| 190 | HSIO_S6G_PLL_CFG_PLL_DIV4 | | ||
| 191 | HSIO_S6G_PLL_CFG_PLL_ENA_ROT | | ||
| 192 | HSIO_S6G_PLL_CFG_PLL_FSM_CTRL_DATA_M | | ||
| 193 | HSIO_S6G_PLL_CFG_PLL_ROT_DIR | | ||
| 194 | HSIO_S6G_PLL_CFG_PLL_ROT_FRQ, | ||
| 195 | HSIO_S6G_PLL_CFG_PLL_FSM_CTRL_DATA | ||
| 196 | (pll_fsm_ctrl_data)); | ||
| 197 | |||
| 198 | regmap_update_bits(regmap, HSIO_S6G_COMMON_CFG, | ||
| 199 | HSIO_S6G_COMMON_CFG_SYS_RST | | ||
| 200 | HSIO_S6G_COMMON_CFG_ENA_LANE | | ||
| 201 | HSIO_S6G_COMMON_CFG_PWD_RX | | ||
| 202 | HSIO_S6G_COMMON_CFG_PWD_TX | | ||
| 203 | HSIO_S6G_COMMON_CFG_HRATE | | ||
| 204 | HSIO_S6G_COMMON_CFG_QRATE | | ||
| 205 | HSIO_S6G_COMMON_CFG_ENA_ELOOP | | ||
| 206 | HSIO_S6G_COMMON_CFG_ENA_FLOOP | | ||
| 207 | HSIO_S6G_COMMON_CFG_IF_MODE_M, | ||
| 208 | HSIO_S6G_COMMON_CFG_SYS_RST | | ||
| 209 | HSIO_S6G_COMMON_CFG_ENA_LANE | | ||
| 210 | (qrate ? HSIO_S6G_COMMON_CFG_QRATE : 0) | | ||
| 211 | HSIO_S6G_COMMON_CFG_IF_MODE(if_mode)); | ||
| 212 | |||
| 213 | regmap_update_bits(regmap, HSIO_S6G_MISC_CFG, | ||
| 214 | HSIO_S6G_MISC_CFG_LANE_RST | | ||
| 215 | HSIO_S6G_MISC_CFG_DES_100FX_CPMD_ENA | | ||
| 216 | HSIO_S6G_MISC_CFG_RX_LPI_MODE_ENA | | ||
| 217 | HSIO_S6G_MISC_CFG_TX_LPI_MODE_ENA, | ||
| 218 | HSIO_S6G_MISC_CFG_LANE_RST | | ||
| 219 | HSIO_S6G_MISC_CFG_RX_LPI_MODE_ENA); | ||
| 220 | |||
| 221 | |||
| 222 | ret = serdes_commit_mcb_s6g(regmap, serdes); | ||
| 223 | if (ret) | ||
| 224 | return ret; | ||
| 225 | |||
| 226 | regmap_update_bits(regmap, HSIO_S6G_PLL_CFG, | ||
| 227 | HSIO_S6G_PLL_CFG_PLL_FSM_ENA, | ||
| 228 | HSIO_S6G_PLL_CFG_PLL_FSM_ENA); | ||
| 229 | |||
| 230 | ret = serdes_commit_mcb_s6g(regmap, serdes); | ||
| 231 | if (ret) | ||
| 232 | return ret; | ||
| 233 | |||
| 234 | /* Wait for PLL bringup */ | ||
| 235 | msleep(20); | ||
| 236 | |||
| 237 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG, | ||
| 238 | HSIO_S6G_IB_CFG_IB_CAL_ENA, | ||
| 239 | HSIO_S6G_IB_CFG_IB_CAL_ENA); | ||
| 240 | |||
| 241 | regmap_update_bits(regmap, HSIO_S6G_MISC_CFG, | ||
| 242 | HSIO_S6G_MISC_CFG_LANE_RST, 0); | ||
| 243 | |||
| 244 | ret = serdes_commit_mcb_s6g(regmap, serdes); | ||
| 245 | if (ret) | ||
| 246 | return ret; | ||
| 247 | |||
| 248 | /* Wait for calibration */ | ||
| 249 | msleep(60); | ||
| 250 | |||
| 251 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG, | ||
| 252 | HSIO_S6G_IB_CFG_IB_REG_PAT_SEL_OFFSET_M | | ||
| 253 | HSIO_S6G_IB_CFG_IB_SIG_DET_CLK_SEL_M, | ||
| 254 | HSIO_S6G_IB_CFG_IB_REG_PAT_SEL_OFFSET(0) | | ||
| 255 | HSIO_S6G_IB_CFG_IB_SIG_DET_CLK_SEL(7)); | ||
| 256 | |||
| 257 | regmap_update_bits(regmap, HSIO_S6G_IB_CFG1, | ||
| 258 | HSIO_S6G_IB_CFG1_IB_TSDET_M, | ||
| 259 | HSIO_S6G_IB_CFG1_IB_TSDET(3)); | ||
| 260 | |||
| 261 | /* IB CFG */ | ||
| 262 | |||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | |||
| 34 | #define MCB_S1G_CFG_TIMEOUT 50 | 266 | #define MCB_S1G_CFG_TIMEOUT 50 |
| 35 | 267 | ||
| 36 | static int __serdes_write_mcb_s1g(struct regmap *regmap, u8 macro, u32 op) | 268 | static int __serdes_write_mcb_s1g(struct regmap *regmap, u8 macro, u32 op) |
| @@ -110,7 +342,7 @@ struct serdes_mux { · 73 unmodified lines | |||
| 110 | u32 mux; | 342 | u32 mux; |
| 111 | }; | 343 | }; |
| 112 | 344 | ||
| 113 | #define SERDES_MUX(_idx, _port, _mode, _submode, _mask, _mux) { \ | 345 | #define SERDES_MUX(_idx, _port, _mode, _submode, _mask, _mux) { \ |
| 114 | .idx = _idx, \ | 346 | .idx = _idx, \ |
| 115 | .port = _port, \ | 347 | .port = _port, \ |
| 116 | .mode = _mode, \ | 348 | .mode = _mode, \ |
| @@ -191,8 +423,12 @@ static int serdes_set_mode(struct phy *phy, enum phy_mode mode, int submode) · 74 unmodified lines | |||
| 191 | 423 | ||
| 192 | if (macro->idx <= SERDES1G_MAX) | 424 | if (macro->idx <= SERDES1G_MAX) |
| 193 | return serdes_init_s1g(macro->ctrl->regs, macro->idx); | 425 | return serdes_init_s1g(macro->ctrl->regs, macro->idx); |
| 426 | else if (macro->idx <= SERDES6G_MAX) | ||
| 427 | return serdes_init_s6g(macro->ctrl->regs, | ||
| 428 | macro->idx - (SERDES1G_MAX + 1), | ||
| 429 | ocelot_serdes_muxes[i].submode); | ||
| 194 | 430 | ||
| 195 | /* SERDES6G and PCIe not supported yet */ | 431 | /* PCIe not supported yet */ |
| 196 | return -EOPNOTSUPP; | 432 | return -EOPNOTSUPP; |
| 197 | } | 433 | } |
| 198 | 434 | ||
| @@ -384,10 +384,16 @@ int phy_reset(struct phy *phy) · 383 unmodified lines | |||
| 384 | if (!phy || !phy->ops->reset) | 384 | if (!phy || !phy->ops->reset) |
| 385 | return 0; | 385 | return 0; |
| 386 | 386 | ||
| 387 | ret = phy_pm_runtime_get_sync(phy); | ||
| 388 | if (ret < 0 && ret != -ENOTSUPP) | ||
| 389 | return ret; | ||
| 390 | |||
| 387 | mutex_lock(&phy->mutex); | 391 | mutex_lock(&phy->mutex); |
| 388 | ret = phy->ops->reset(phy); | 392 | ret = phy->ops->reset(phy); |
| 389 | mutex_unlock(&phy->mutex); | 393 | mutex_unlock(&phy->mutex); |
| 390 | 394 | ||
| 395 | phy_pm_runtime_put(phy); | ||
| 396 | |||
| 391 | return ret; | 397 | return ret; |
| 392 | } | 398 | } |
| 393 | EXPORT_SYMBOL_GPL(phy_reset); | 399 | EXPORT_SYMBOL_GPL(phy_reset); |
| @@ -564,6 +570,11 @@ void phy_put(struct phy *phy) · 170 unmodified lines | |||
| 564 | if (!phy || IS_ERR(phy)) | 570 | if (!phy || IS_ERR(phy)) |
| 565 | return; | 571 | return; |
| 566 | 572 | ||
| 573 | mutex_lock(&phy->mutex); | ||
| 574 | if (phy->ops->release) | ||
| 575 | phy->ops->release(phy); | ||
| 576 | mutex_unlock(&phy->mutex); | ||
| 577 | |||
| 567 | module_put(phy->ops->owner); | 578 | module_put(phy->ops->owner); |
| 568 | put_device(&phy->dev); | 579 | put_device(&phy->dev); |
| 569 | } | 580 | } |
| @@ -242,6 +242,88 @@ static const struct qmp_phy_init_tbl msm8996_pcie_pcs_tbl[] = { · 241 unmodified lines | |||
| 242 | QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0x0e), | 242 | QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0x0e), |
| 243 | }; | 243 | }; |
| 244 | 244 | ||
| 245 | static const struct qmp_phy_init_tbl msm8998_pcie_serdes_tbl[] = { | ||
| 246 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x14), | ||
| 247 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30), | ||
| 248 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x0f), | ||
| 249 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06), | ||
| 250 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x01), | ||
| 251 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL, 0x20), | ||
| 252 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00), | ||
| 253 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01), | ||
| 254 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9), | ||
| 255 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_TIMER1, 0xff), | ||
| 256 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_TIMER2, 0x3f), | ||
| 257 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01), | ||
| 258 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00), | ||
| 259 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a), | ||
| 260 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_EP_DIV, 0x19), | ||
| 261 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_ENABLE1, 0x90), | ||
| 262 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82), | ||
| 263 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x03), | ||
| 264 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0x55), | ||
| 265 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0x55), | ||
| 266 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00), | ||
| 267 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x0d), | ||
| 268 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x04), | ||
| 269 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x00), | ||
| 270 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x08), | ||
| 271 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16), | ||
| 272 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x34), | ||
| 273 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06), | ||
| 274 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x33), | ||
| 275 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02), | ||
| 276 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x07), | ||
| 277 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x04), | ||
| 278 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00), | ||
| 279 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f), | ||
| 280 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_BG_TIMER, 0x09), | ||
| 281 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01), | ||
| 282 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x40), | ||
| 283 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01), | ||
| 284 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x02), | ||
| 285 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00), | ||
| 286 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x7e), | ||
| 287 | QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x15), | ||
| 288 | }; | ||
| 289 | |||
| 290 | static const struct qmp_phy_init_tbl msm8998_pcie_tx_tbl[] = { | ||
| 291 | QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x02), | ||
| 292 | QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12), | ||
| 293 | QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10), | ||
| 294 | QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x06), | ||
| 295 | }; | ||
| 296 | |||
| 297 | static const struct qmp_phy_init_tbl msm8998_pcie_rx_tbl[] = { | ||
| 298 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03), | ||
| 299 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_ENABLES, 0x1c), | ||
| 300 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x14), | ||
| 301 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0a), | ||
| 302 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04), | ||
| 303 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1a), | ||
| 304 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b), | ||
| 305 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_GAIN, 0x04), | ||
| 306 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_GAIN_HALF, 0x04), | ||
| 307 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x00), | ||
| 308 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80), | ||
| 309 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40), | ||
| 310 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x71), | ||
| 311 | QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x40), | ||
| 312 | }; | ||
| 313 | |||
| 314 | static const struct qmp_phy_init_tbl msm8998_pcie_pcs_tbl[] = { | ||
| 315 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_ENDPOINT_REFCLK_DRIVE, 0x04), | ||
| 316 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_OSC_DTCT_ACTIONS, 0x00), | ||
| 317 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x01), | ||
| 318 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB, 0x00), | ||
| 319 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB, 0x20), | ||
| 320 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_LP_WAKEUP_DLY_TIME_AUXCLK_MSB, 0x00), | ||
| 321 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_LP_WAKEUP_DLY_TIME_AUXCLK, 0x01), | ||
| 322 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_PLL_LOCK_CHK_DLY_TIME, 0x73), | ||
| 323 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0x99), | ||
| 324 | QMP_PHY_INIT_CFG(QPHY_V3_PCS_SIGDET_CNTRL, 0x03), | ||
| 325 | }; | ||
| 326 | |||
| 245 | static const struct qmp_phy_init_tbl msm8996_usb3_serdes_tbl[] = { | 327 | static const struct qmp_phy_init_tbl msm8996_usb3_serdes_tbl[] = { |
| 246 | QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14), | 328 | QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14), |
| 247 | QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08), | 329 | QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08), |
| @@ -897,6 +979,7 @@ struct qmp_phy { · 649 unmodified lines | |||
| 897 | * @init_count: phy common block initialization count | 979 | * @init_count: phy common block initialization count |
| 898 | * @phy_initialized: indicate if PHY has been initialized | 980 | * @phy_initialized: indicate if PHY has been initialized |
| 899 | * @mode: current PHY mode | 981 | * @mode: current PHY mode |
| 982 | * @ufs_reset: optional UFS PHY reset handle | ||
| 900 | */ | 983 | */ |
| 901 | struct qcom_qmp { | 984 | struct qcom_qmp { |
| 902 | struct device *dev; | 985 | struct device *dev; |
| @@ -914,6 +997,8 @@ struct qcom_qmp { · 11 unmodified lines | |||
| 914 | int init_count; | 997 | int init_count; |
| 915 | bool phy_initialized; | 998 | bool phy_initialized; |
| 916 | enum phy_mode mode; | 999 | enum phy_mode mode; |
| 1000 | |||
| 1001 | struct reset_control *ufs_reset; | ||
| 917 | }; | 1002 | }; |
| 918 | 1003 | ||
| 919 | static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val) | 1004 | static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val) |
| @@ -1146,6 +1231,31 @@ static const struct qmp_phy_cfg sdm845_ufsphy_cfg = { · 226 unmodified lines | |||
| 1146 | .no_pcs_sw_reset = true, | 1231 | .no_pcs_sw_reset = true, |
| 1147 | }; | 1232 | }; |
| 1148 | 1233 | ||
| 1234 | static const struct qmp_phy_cfg msm8998_pciephy_cfg = { | ||
| 1235 | .type = PHY_TYPE_PCIE, | ||
| 1236 | .nlanes = 1, | ||
| 1237 | |||
| 1238 | .serdes_tbl = msm8998_pcie_serdes_tbl, | ||
| 1239 | .serdes_tbl_num = ARRAY_SIZE(msm8998_pcie_serdes_tbl), | ||
| 1240 | .tx_tbl = msm8998_pcie_tx_tbl, | ||
| 1241 | .tx_tbl_num = ARRAY_SIZE(msm8998_pcie_tx_tbl), | ||
| 1242 | .rx_tbl = msm8998_pcie_rx_tbl, | ||
| 1243 | .rx_tbl_num = ARRAY_SIZE(msm8998_pcie_rx_tbl), | ||
| 1244 | .pcs_tbl = msm8998_pcie_pcs_tbl, | ||
| 1245 | .pcs_tbl_num = ARRAY_SIZE(msm8998_pcie_pcs_tbl), | ||
| 1246 | .clk_list = msm8996_phy_clk_l, | ||
| 1247 | .num_clks = ARRAY_SIZE(msm8996_phy_clk_l), | ||
| 1248 | .reset_list = ipq8074_pciephy_reset_l, | ||
| 1249 | .num_resets = ARRAY_SIZE(ipq8074_pciephy_reset_l), | ||
| 1250 | .vreg_list = qmp_phy_vreg_l, | ||
| 1251 | .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l), | ||
| 1252 | .regs = pciephy_regs_layout, | ||
| 1253 | |||
| 1254 | .start_ctrl = SERDES_START | PCS_START, | ||
| 1255 | .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL, | ||
| 1256 | .mask_com_pcs_ready = PCS_READY, | ||
| 1257 | }; | ||
| 1258 | |||
| 1149 | static const struct qmp_phy_cfg msm8998_usb3phy_cfg = { | 1259 | static const struct qmp_phy_cfg msm8998_usb3phy_cfg = { |
| 1150 | .type = PHY_TYPE_USB3, | 1260 | .type = PHY_TYPE_USB3, |
| 1151 | .nlanes = 1, | 1261 | .nlanes = 1, |
| @@ -1314,6 +1424,7 @@ static int qcom_qmp_phy_com_exit(struct qcom_qmp *qmp) · 162 unmodified lines | |||
| 1314 | return 0; | 1424 | return 0; |
| 1315 | } | 1425 | } |
| 1316 | 1426 | ||
| 1427 | reset_control_assert(qmp->ufs_reset); | ||
| 1317 | if (cfg->has_phy_com_ctrl) { | 1428 | if (cfg->has_phy_com_ctrl) { |
| 1318 | qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL], | 1429 | qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL], |
| 1319 | SERDES_START | PCS_START); | 1430 | SERDES_START | PCS_START); |
| @@ -1335,8 +1446,7 @@ static int qcom_qmp_phy_com_exit(struct qcom_qmp *qmp) · 15 unmodified lines | |||
| 1335 | return 0; | 1446 | return 0; |
| 1336 | } | 1447 | } |
| 1337 | 1448 | ||
| 1338 | /* PHY Initialization */ | 1449 | static int qcom_qmp_phy_enable(struct phy *phy) |
| 1339 | static int qcom_qmp_phy_init(struct phy *phy) | ||
| 1340 | { | 1450 | { |
| 1341 | struct qmp_phy *qphy = phy_get_drvdata(phy); | 1451 | struct qmp_phy *qphy = phy_get_drvdata(phy); |
| 1342 | struct qcom_qmp *qmp = qphy->qmp; | 1452 | struct qcom_qmp *qmp = qphy->qmp; |
| @@ -1351,6 +1461,33 @@ static int qcom_qmp_phy_init(struct phy *phy) · 8 unmodified lines | |||
| 1351 | 1461 | ||
| 1352 | dev_vdbg(qmp->dev, "Initializing QMP phy\n"); | 1462 | dev_vdbg(qmp->dev, "Initializing QMP phy\n"); |
| 1353 | 1463 | ||
| 1464 | if (cfg->no_pcs_sw_reset) { | ||
| 1465 | /* | ||
| 1466 | * Get UFS reset, which is delayed until now to avoid a | ||
| 1467 | * circular dependency where UFS needs its PHY, but the PHY | ||
| 1468 | * needs this UFS reset. | ||
| 1469 | */ | ||
| 1470 | if (!qmp->ufs_reset) { | ||
| 1471 | qmp->ufs_reset = | ||
| 1472 | devm_reset_control_get_exclusive(qmp->dev, | ||
| 1473 | "ufsphy"); | ||
| 1474 | |||
| 1475 | if (IS_ERR(qmp->ufs_reset)) { | ||
| 1476 | ret = PTR_ERR(qmp->ufs_reset); | ||
| 1477 | dev_err(qmp->dev, | ||
| 1478 | "failed to get UFS reset: %d\n", | ||
| 1479 | ret); | ||
| 1480 | |||
| 1481 | qmp->ufs_reset = NULL; | ||
| 1482 | return ret; | ||
| 1483 | } | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | ret = reset_control_assert(qmp->ufs_reset); | ||
| 1487 | if (ret) | ||
| 1488 | goto err_lane_rst; | ||
| 1489 | } | ||
| 1490 | |||
| 1354 | ret = qcom_qmp_phy_com_init(qphy); | 1491 | ret = qcom_qmp_phy_com_init(qphy); |
| 1355 | if (ret) | 1492 | if (ret) |
| 1356 | return ret; | 1493 | return ret; |
| @@ -1383,14 +1520,9 @@ static int qcom_qmp_phy_init(struct phy *phy) · 26 unmodified lines | |||
| 1383 | cfg->rx_tbl, cfg->rx_tbl_num); | 1520 | cfg->rx_tbl, cfg->rx_tbl_num); |
| 1384 | 1521 | ||
| 1385 | qcom_qmp_phy_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num); | 1522 | qcom_qmp_phy_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num); |
| 1386 | 1523 | ret = reset_control_deassert(qmp->ufs_reset); | |
| 1387 | /* | 1524 | if (ret) |
| 1388 | * UFS PHY requires the deassert of software reset before serdes start. | 1525 | goto err_lane_rst; |
| 1389 | * For UFS PHYs that do not have software reset control bits, defer | ||
| 1390 | * starting serdes until the power on callback. | ||
| 1391 | */ | ||
| 1392 | if ((cfg->type == PHY_TYPE_UFS) && cfg->no_pcs_sw_reset) | ||
| 1393 | goto out; | ||
| 1394 | 1526 | ||
| 1395 | /* | 1527 | /* |
| 1396 | * Pull out PHY from POWER DOWN state. | 1528 | * Pull out PHY from POWER DOWN state. |
| @@ -1403,7 +1535,9 @@ static int qcom_qmp_phy_init(struct phy *phy) · 6 unmodified lines | |||
| 1403 | usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max); | 1535 | usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max); |
| 1404 | 1536 | ||
| 1405 | /* Pull PHY out of reset state */ | 1537 | /* Pull PHY out of reset state */ |
| 1406 | qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); | 1538 | if (!cfg->no_pcs_sw_reset) |
| 1539 | qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); | ||
| 1540 | |||
| 1407 | if (cfg->has_phy_dp_com_ctrl) | 1541 | if (cfg->has_phy_dp_com_ctrl) |
| 1408 | qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET); | 1542 | qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET); |
| 1409 | 1543 | ||
| @@ -1420,11 +1554,10 @@ static int qcom_qmp_phy_init(struct phy *phy) · 10 unmodified lines | |||
| 1420 | goto err_pcs_ready; | 1554 | goto err_pcs_ready; |
| 1421 | } | 1555 | } |
| 1422 | qmp->phy_initialized = true; | 1556 | qmp->phy_initialized = true; |
| 1423 | 1557 | return 0; | |
| 1424 | out: | ||
| 1425 | return ret; | ||
| 1426 | 1558 | ||
| 1427 | err_pcs_ready: | 1559 | err_pcs_ready: |
| 1560 | reset_control_assert(qmp->ufs_reset); | ||
| 1428 | clk_disable_unprepare(qphy->pipe_clk); | 1561 | clk_disable_unprepare(qphy->pipe_clk); |
| 1429 | err_clk_enable: | 1562 | err_clk_enable: |
| 1430 | if (cfg->has_lane_rst) | 1563 | if (cfg->has_lane_rst) |
| @@ -1435,7 +1568,7 @@ err_lane_rst: · 4 unmodified lines | |||
| 1435 | return ret; | 1568 | return ret; |
| 1436 | } | 1569 | } |
| 1437 | 1570 | ||
| 1438 | static int qcom_qmp_phy_exit(struct phy *phy) | 1571 | static int qcom_qmp_phy_disable(struct phy *phy) |
| 1439 | { | 1572 | { |
| 1440 | struct qmp_phy *qphy = phy_get_drvdata(phy); | 1573 | struct qmp_phy *qphy = phy_get_drvdata(phy); |
| 1441 | struct qcom_qmp *qmp = qphy->qmp; | 1574 | struct qcom_qmp *qmp = qphy->qmp; |
| @@ -1463,44 +1596,6 @@ static int qcom_qmp_phy_exit(struct phy *phy) · 21 unmodified lines | |||
| 1463 | return 0; | 1596 | return 0; |
| 1464 | } | 1597 | } |
| 1465 | 1598 | ||
| 1466 | static int qcom_qmp_phy_poweron(struct phy *phy) | ||
| 1467 | { | ||
| 1468 | struct qmp_phy *qphy = phy_get_drvdata(phy); | ||
| 1469 | struct qcom_qmp *qmp = qphy->qmp; | ||
| 1470 | const struct qmp_phy_cfg *cfg = qmp->cfg; | ||
| 1471 | void __iomem *pcs = qphy->pcs; | ||
| 1472 | void __iomem *status; | ||
| 1473 | unsigned int mask, val; | ||
| 1474 | int ret = 0; | ||
| 1475 | |||
| 1476 | if (cfg->type != PHY_TYPE_UFS) | ||
| 1477 | return 0; | ||
| 1478 | |||
| 1479 | /* | ||
| 1480 | * For UFS PHY that has not software reset control, serdes start | ||
| 1481 | * should only happen when UFS driver explicitly calls phy_power_on | ||
| 1482 | * after it deasserts software reset. | ||
| 1483 | */ | ||
| 1484 | if (cfg->no_pcs_sw_reset && !qmp->phy_initialized && | ||
| 1485 | (qmp->init_count != 0)) { | ||
| 1486 | /* start SerDes and Phy-Coding-Sublayer */ | ||
| 1487 | qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl); | ||
| 1488 | |||
| 1489 | status = pcs + cfg->regs[QPHY_PCS_READY_STATUS]; | ||
| 1490 | mask = cfg->mask_pcs_ready; | ||
| 1491 | |||
| 1492 | ret = readl_poll_timeout(status, val, !(val & mask), 1, | ||
| 1493 | PHY_INIT_COMPLETE_TIMEOUT); | ||
| 1494 | if (ret) { | ||
| 1495 | dev_err(qmp->dev, "phy initialization timed-out\n"); | ||
| 1496 | return ret; | ||
| 1497 | } | ||
| 1498 | qmp->phy_initialized = true; | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | return ret; | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | static int qcom_qmp_phy_set_mode(struct phy *phy, | 1599 | static int qcom_qmp_phy_set_mode(struct phy *phy, |
| 1505 | enum phy_mode mode, int submode) | 1600 | enum phy_mode mode, int submode) |
| 1506 | { | 1601 | { |
| @@ -1750,9 +1845,15 @@ static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np) · 243 unmodified lines | |||
| 1750 | } | 1845 | } |
| 1751 | 1846 | ||
| 1752 | static const struct phy_ops qcom_qmp_phy_gen_ops = { | 1847 | static const struct phy_ops qcom_qmp_phy_gen_ops = { |
| 1753 | .init = qcom_qmp_phy_init, | 1848 | .init = qcom_qmp_phy_enable, |
| 1754 | .exit = qcom_qmp_phy_exit, | 1849 | .exit = qcom_qmp_phy_disable, |
| 1755 | .power_on = qcom_qmp_phy_poweron, | 1850 | .set_mode = qcom_qmp_phy_set_mode, |
| 1851 | .owner = THIS_MODULE, | ||
| 1852 | }; | ||
| 1853 | |||
| 1854 | static const struct phy_ops qcom_qmp_ufs_ops = { | ||
| 1855 | .power_on = qcom_qmp_phy_enable, | ||
| 1856 | .power_off = qcom_qmp_phy_disable, | ||
| 1756 | .set_mode = qcom_qmp_phy_set_mode, | 1857 | .set_mode = qcom_qmp_phy_set_mode, |
| 1757 | .owner = THIS_MODULE, | 1858 | .owner = THIS_MODULE, |
| 1758 | }; | 1859 | }; |
| @@ -1763,6 +1864,7 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id) · 4 unmodified lines | |||
| 1763 | struct qcom_qmp *qmp = dev_get_drvdata(dev); | 1864 | struct qcom_qmp *qmp = dev_get_drvdata(dev); |
| 1764 | struct phy *generic_phy; | 1865 | struct phy *generic_phy; |
| 1765 | struct qmp_phy *qphy; | 1866 | struct qmp_phy *qphy; |
| 1867 | const struct phy_ops *ops = &qcom_qmp_phy_gen_ops; | ||
| 1766 | char prop_name[MAX_PROP_NAME]; | 1868 | char prop_name[MAX_PROP_NAME]; |
| 1767 | int ret; | 1869 | int ret; |
| 1768 | 1870 | ||
| @@ -1849,7 +1951,10 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id) · 80 unmodified lines | |||
| 1849 | } | 1951 | } |
| 1850 | } | 1952 | } |
| 1851 | 1953 | ||
| 1852 | generic_phy = devm_phy_create(dev, np, &qcom_qmp_phy_gen_ops); | 1954 | if (qmp->cfg->type == PHY_TYPE_UFS) |
| 1955 | ops = &qcom_qmp_ufs_ops; | ||
| 1956 | |||
| 1957 | generic_phy = devm_phy_create(dev, np, ops); | ||
| 1853 | if (IS_ERR(generic_phy)) { | 1958 | if (IS_ERR(generic_phy)) { |
| 1854 | ret = PTR_ERR(generic_phy); | 1959 | ret = PTR_ERR(generic_phy); |
| 1855 | dev_err(dev, "failed to create qphy %d\n", ret); | 1960 | dev_err(dev, "failed to create qphy %d\n", ret); |
| @@ -1872,6 +1977,9 @@ static const struct of_device_id qcom_qmp_phy_of_match_table[] = { · 16 unmodified lines | |||
| 1872 | }, { | 1977 | }, { |
| 1873 | .compatible = "qcom,msm8996-qmp-usb3-phy", | 1978 | .compatible = "qcom,msm8996-qmp-usb3-phy", |
| 1874 | .data = &msm8996_usb3phy_cfg, | 1979 | .data = &msm8996_usb3phy_cfg, |
| 1980 | }, { | ||
| 1981 | .compatible = "qcom,msm8998-qmp-pcie-phy", | ||
| 1982 | .data = &msm8998_pciephy_cfg, | ||
| 1875 | }, { | 1983 | }, { |
| 1876 | .compatible = "qcom,msm8998-qmp-ufs-phy", | 1984 | .compatible = "qcom,msm8998-qmp-ufs-phy", |
| 1877 | .data = &sdm845_ufsphy_cfg, | 1985 | .data = &sdm845_ufsphy_cfg, |
| @@ -241,6 +241,7 @@ · 240 unmodified lines | |||
| 241 | #define QSERDES_V3_RX_RX_BAND 0x110 | 241 | #define QSERDES_V3_RX_RX_BAND 0x110 |
| 242 | #define QSERDES_V3_RX_RX_INTERFACE_MODE 0x11c | 242 | #define QSERDES_V3_RX_RX_INTERFACE_MODE 0x11c |
| 243 | #define QSERDES_V3_RX_RX_MODE_00 0x164 | 243 | #define QSERDES_V3_RX_RX_MODE_00 0x164 |
| 244 | #define QSERDES_V3_RX_RX_MODE_01 0x168 | ||
| 244 | 245 | ||
| 245 | /* Only for QMP V3 PHY - PCS registers */ | 246 | /* Only for QMP V3 PHY - PCS registers */ |
| 246 | #define QPHY_V3_PCS_POWER_DOWN_CONTROL 0x004 | 247 | #define QPHY_V3_PCS_POWER_DOWN_CONTROL 0x004 |
| @@ -280,6 +281,7 @@ · 33 unmodified lines | |||
| 280 | #define QPHY_V3_PCS_TSYNC_RSYNC_TIME 0x08c | 281 | #define QPHY_V3_PCS_TSYNC_RSYNC_TIME 0x08c |
| 281 | #define QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK 0x0a0 | 282 | #define QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK 0x0a0 |
| 282 | #define QPHY_V3_PCS_LP_WAKEUP_DLY_TIME_AUXCLK 0x0a4 | 283 | #define QPHY_V3_PCS_LP_WAKEUP_DLY_TIME_AUXCLK 0x0a4 |
| 284 | #define QPHY_V3_PCS_PLL_LOCK_CHK_DLY_TIME 0x0a8 | ||
| 283 | #define QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK 0x0b0 | 285 | #define QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK 0x0b0 |
| 284 | #define QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME 0x0b8 | 286 | #define QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME 0x0b8 |
| 285 | #define QPHY_V3_PCS_RXEQTRAINING_RUN_TIME 0x0bc | 287 | #define QPHY_V3_PCS_RXEQTRAINING_RUN_TIME 0x0bc |
| @@ -292,13 +294,23 @@ · 6 unmodified lines | |||
| 292 | #define QPHY_V3_PCS_RX_MIN_HIBERN8_TIME 0x138 | 294 | #define QPHY_V3_PCS_RX_MIN_HIBERN8_TIME 0x138 |
| 293 | #define QPHY_V3_PCS_RX_SIGDET_CTRL1 0x13c | 295 | #define QPHY_V3_PCS_RX_SIGDET_CTRL1 0x13c |
| 294 | #define QPHY_V3_PCS_RX_SIGDET_CTRL2 0x140 | 296 | #define QPHY_V3_PCS_RX_SIGDET_CTRL2 0x140 |
| 297 | #define QPHY_V3_PCS_LP_WAKEUP_DLY_TIME_AUXCLK_MSB 0x1a8 | ||
| 298 | #define QPHY_V3_PCS_OSC_DTCT_ACTIONS 0x1ac | ||
| 299 | #define QPHY_V3_PCS_SIGDET_CNTRL 0x1b0 | ||
| 295 | #define QPHY_V3_PCS_TX_MID_TERM_CTRL1 0x1bc | 300 | #define QPHY_V3_PCS_TX_MID_TERM_CTRL1 0x1bc |
| 296 | #define QPHY_V3_PCS_MULTI_LANE_CTRL1 0x1c4 | 301 | #define QPHY_V3_PCS_MULTI_LANE_CTRL1 0x1c4 |
| 297 | #define QPHY_V3_PCS_RX_SIGDET_LVL 0x1d8 | 302 | #define QPHY_V3_PCS_RX_SIGDET_LVL 0x1d8 |
| 303 | #define QPHY_V3_PCS_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB 0x1dc | ||
| 304 | #define QPHY_V3_PCS_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB 0x1e0 | ||
| 298 | #define QPHY_V3_PCS_REFGEN_REQ_CONFIG1 0x20c | 305 | #define QPHY_V3_PCS_REFGEN_REQ_CONFIG1 0x20c |
| 299 | #define QPHY_V3_PCS_REFGEN_REQ_CONFIG2 0x210 | 306 | #define QPHY_V3_PCS_REFGEN_REQ_CONFIG2 0x210 |
| 300 | 307 | ||
| 301 | /* Only for QMP V3 PHY - PCS_MISC registers */ | 308 | /* Only for QMP V3 PHY - PCS_MISC registers */ |
| 302 | #define QPHY_V3_PCS_MISC_CLAMP_ENABLE 0x0c | 309 | #define QPHY_V3_PCS_MISC_CLAMP_ENABLE 0x0c |
| 310 | #define QPHY_V3_PCS_MISC_OSC_DTCT_CONFIG2 0x2c | ||
| 311 | #define QPHY_V3_PCS_MISC_PCIE_INT_AUX_CLK_CONFIG1 0x44 | ||
| 312 | #define QPHY_V3_PCS_MISC_OSC_DTCT_MODE2_CONFIG2 0x54 | ||
| 313 | #define QPHY_V3_PCS_MISC_OSC_DTCT_MODE2_CONFIG4 0x5c | ||
| 314 | #define QPHY_V3_PCS_MISC_OSC_DTCT_MODE2_CONFIG5 0x60 | ||
| 303 | 315 | ||
| 304 | #endif | 316 | #endif |
| @@ -822,14 +822,9 @@ static int qusb2_phy_probe(struct platform_device *pdev) · 821 unmodified lines | |||
| 822 | return ret; | 822 | return ret; |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 825 | qphy->iface_clk = devm_clk_get(dev, "iface"); | 825 | qphy->iface_clk = devm_clk_get_optional(dev, "iface"); |
| 826 | if (IS_ERR(qphy->iface_clk)) { | 826 | if (IS_ERR(qphy->iface_clk)) |
| 827 | ret = PTR_ERR(qphy->iface_clk); | 827 | return PTR_ERR(qphy->iface_clk); |
| 828 | if (ret == -EPROBE_DEFER) | ||
| 829 | return ret; | ||
| 830 | qphy->iface_clk = NULL; | ||
| 831 | dev_dbg(dev, "failed to get iface clk, %d\n", ret); | ||
| 832 | } | ||
| 833 | 828 | ||
| 834 | qphy->phy_reset = devm_reset_control_get_by_index(&pdev->dev, 0); | 829 | qphy->phy_reset = devm_reset_control_get_by_index(&pdev->dev, 0); |
| 835 | if (IS_ERR(qphy->phy_reset)) { | 830 | if (IS_ERR(qphy->phy_reset)) { |
| @@ -19,6 +19,7 @@ · 18 unmodified lines | |||
| 19 | #include <linux/clk.h> | 19 | #include <linux/clk.h> |
| 20 | #include <linux/phy/phy.h> | 20 | #include <linux/phy/phy.h> |
| 21 | #include <linux/regulator/consumer.h> | 21 | #include <linux/regulator/consumer.h> |
| 22 | #include <linux/reset.h> | ||
| 22 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
| 23 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
| 24 | #include <linux/io.h> | 25 | #include <linux/io.h> |
| @@ -96,11 +97,10 @@ struct ufs_qcom_phy { · 71 unmodified lines | |||
| 96 | char name[UFS_QCOM_PHY_NAME_LEN]; | 97 | char name[UFS_QCOM_PHY_NAME_LEN]; |
| 97 | struct ufs_qcom_phy_calibration *cached_regs; | 98 | struct ufs_qcom_phy_calibration *cached_regs; |
| 98 | int cached_regs_table_size; | 99 | int cached_regs_table_size; |
| 99 | bool is_powered_on; | ||
| 100 | bool is_started; | ||
| 101 | struct ufs_qcom_phy_specific_ops *phy_spec_ops; | 100 | struct ufs_qcom_phy_specific_ops *phy_spec_ops; |
| 102 | 101 | ||
| 103 | enum phy_mode mode; | 102 | enum phy_mode mode; |
| 103 | struct reset_control *ufs_reset; | ||
| 104 | }; | 104 | }; |
| 105 | 105 | ||
| 106 | /** | 106 | /** |
| @@ -115,6 +115,7 @@ struct ufs_qcom_phy { · 8 unmodified lines | |||
| 115 | * and writes to QSERDES_RX_SIGDET_CNTRL attribute | 115 | * and writes to QSERDES_RX_SIGDET_CNTRL attribute |
| 116 | */ | 116 | */ |
| 117 | struct ufs_qcom_phy_specific_ops { | 117 | struct ufs_qcom_phy_specific_ops { |
| 118 | int (*calibrate)(struct ufs_qcom_phy *ufs_qcom_phy, bool is_rate_B); | ||
| 118 | void (*start_serdes)(struct ufs_qcom_phy *phy); | 119 | void (*start_serdes)(struct ufs_qcom_phy *phy); |
| 119 | int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy); | 120 | int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy); |
| 120 | void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy, u32 val); | 121 | void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy, u32 val); |
| @@ -42,28 +42,6 @@ void ufs_qcom_phy_qmp_14nm_advertise_quirks(struct ufs_qcom_phy *phy_common) · 41 unmodified lines | |||
| 42 | UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE; | 42 | UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static int ufs_qcom_phy_qmp_14nm_init(struct phy *generic_phy) | ||
| 46 | { | ||
| 47 | struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy); | ||
| 48 | bool is_rate_B = false; | ||
| 49 | int ret; | ||
| 50 | |||
| 51 | if (phy_common->mode == PHY_MODE_UFS_HS_B) | ||
| 52 | is_rate_B = true; | ||
| 53 | |||
| 54 | ret = ufs_qcom_phy_qmp_14nm_phy_calibrate(phy_common, is_rate_B); | ||
| 55 | if (!ret) | ||
| 56 | /* phy calibrated, but yet to be started */ | ||
| 57 | phy_common->is_started = false; | ||
| 58 | |||
| 59 | return ret; | ||
| 60 | } | ||
| 61 | |||
| 62 | static int ufs_qcom_phy_qmp_14nm_exit(struct phy *generic_phy) | ||
| 63 | { | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | static | 45 | static |
| 68 | int ufs_qcom_phy_qmp_14nm_set_mode(struct phy *generic_phy, | 46 | int ufs_qcom_phy_qmp_14nm_set_mode(struct phy *generic_phy, |
| 69 | enum phy_mode mode, int submode) | 47 | enum phy_mode mode, int submode) |
| @@ -124,8 +102,6 @@ static int ufs_qcom_phy_qmp_14nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) · 54 unmodified lines | |||
| 124 | } | 102 | } |
| 125 | 103 | ||
| 126 | static const struct phy_ops ufs_qcom_phy_qmp_14nm_phy_ops = { | 104 | static const struct phy_ops ufs_qcom_phy_qmp_14nm_phy_ops = { |
| 127 | .init = ufs_qcom_phy_qmp_14nm_init, | ||
| 128 | .exit = ufs_qcom_phy_qmp_14nm_exit, | ||
| 129 | .power_on = ufs_qcom_phy_power_on, | 105 | .power_on = ufs_qcom_phy_power_on, |
| 130 | .power_off = ufs_qcom_phy_power_off, | 106 | .power_off = ufs_qcom_phy_power_off, |
| 131 | .set_mode = ufs_qcom_phy_qmp_14nm_set_mode, | 107 | .set_mode = ufs_qcom_phy_qmp_14nm_set_mode, |
| @@ -133,6 +109,7 @@ static const struct phy_ops ufs_qcom_phy_qmp_14nm_phy_ops = { · 1 unmodified line | |||
| 133 | }; | 109 | }; |
| 134 | 110 | ||
| 135 | static struct ufs_qcom_phy_specific_ops phy_14nm_ops = { | 111 | static struct ufs_qcom_phy_specific_ops phy_14nm_ops = { |
| 112 | .calibrate = ufs_qcom_phy_qmp_14nm_phy_calibrate, | ||
| 136 | .start_serdes = ufs_qcom_phy_qmp_14nm_start_serdes, | 113 | .start_serdes = ufs_qcom_phy_qmp_14nm_start_serdes, |
| 137 | .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_14nm_is_pcs_ready, | 114 | .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_14nm_is_pcs_ready, |
| 138 | .set_tx_lane_enable = ufs_qcom_phy_qmp_14nm_set_tx_lane_enable, | 115 | .set_tx_lane_enable = ufs_qcom_phy_qmp_14nm_set_tx_lane_enable, |
| @@ -61,28 +61,6 @@ void ufs_qcom_phy_qmp_20nm_advertise_quirks(struct ufs_qcom_phy *phy_common) · 60 unmodified lines | |||
| 61 | UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE; | 61 | UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | static int ufs_qcom_phy_qmp_20nm_init(struct phy *generic_phy) | ||
| 65 | { | ||
| 66 | struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy); | ||
| 67 | bool is_rate_B = false; | ||
| 68 | int ret; | ||
| 69 | |||
| 70 | if (phy_common->mode == PHY_MODE_UFS_HS_B) | ||
| 71 | is_rate_B = true; | ||
| 72 | |||
| 73 | ret = ufs_qcom_phy_qmp_20nm_phy_calibrate(phy_common, is_rate_B); | ||
| 74 | if (!ret) | ||
| 75 | /* phy calibrated, but yet to be started */ | ||
| 76 | phy_common->is_started = false; | ||
| 77 | |||
| 78 | return ret; | ||
| 79 | } | ||
| 80 | |||
| 81 | static int ufs_qcom_phy_qmp_20nm_exit(struct phy *generic_phy) | ||
| 82 | { | ||
| 83 | return 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | static | 64 | static |
| 87 | int ufs_qcom_phy_qmp_20nm_set_mode(struct phy *generic_phy, | 65 | int ufs_qcom_phy_qmp_20nm_set_mode(struct phy *generic_phy, |
| 88 | enum phy_mode mode, int submode) | 66 | enum phy_mode mode, int submode) |
| @@ -182,8 +160,6 @@ static int ufs_qcom_phy_qmp_20nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) · 93 unmodified lines | |||
| 182 | } | 160 | } |
| 183 | 161 | ||
| 184 | static const struct phy_ops ufs_qcom_phy_qmp_20nm_phy_ops = { | 162 | static const struct phy_ops ufs_qcom_phy_qmp_20nm_phy_ops = { |
| 185 | .init = ufs_qcom_phy_qmp_20nm_init, | ||
| 186 | .exit = ufs_qcom_phy_qmp_20nm_exit, | ||
| 187 | .power_on = ufs_qcom_phy_power_on, | 163 | .power_on = ufs_qcom_phy_power_on, |
| 188 | .power_off = ufs_qcom_phy_power_off, | 164 | .power_off = ufs_qcom_phy_power_off, |
| 189 | .set_mode = ufs_qcom_phy_qmp_20nm_set_mode, | 165 | .set_mode = ufs_qcom_phy_qmp_20nm_set_mode, |
| @@ -191,6 +167,7 @@ static const struct phy_ops ufs_qcom_phy_qmp_20nm_phy_ops = { · 1 unmodified line | |||
| 191 | }; | 167 | }; |
| 192 | 168 | ||
| 193 | static struct ufs_qcom_phy_specific_ops phy_20nm_ops = { | 169 | static struct ufs_qcom_phy_specific_ops phy_20nm_ops = { |
| 170 | .calibrate = ufs_qcom_phy_qmp_20nm_phy_calibrate, | ||
| 194 | .start_serdes = ufs_qcom_phy_qmp_20nm_start_serdes, | 171 | .start_serdes = ufs_qcom_phy_qmp_20nm_start_serdes, |
| 195 | .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_20nm_is_pcs_ready, | 172 | .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_20nm_is_pcs_ready, |
| 196 | .set_tx_lane_enable = ufs_qcom_phy_qmp_20nm_set_tx_lane_enable, | 173 | .set_tx_lane_enable = ufs_qcom_phy_qmp_20nm_set_tx_lane_enable, |
| @@ -147,6 +147,21 @@ out: · 146 unmodified lines | |||
| 147 | } | 147 | } |
| 148 | EXPORT_SYMBOL_GPL(ufs_qcom_phy_generic_probe); | 148 | EXPORT_SYMBOL_GPL(ufs_qcom_phy_generic_probe); |
| 149 | 149 | ||
| 150 | static int ufs_qcom_phy_get_reset(struct ufs_qcom_phy *phy_common) | ||
| 151 | { | ||
| 152 | struct reset_control *reset; | ||
| 153 | |||
| 154 | if (phy_common->ufs_reset) | ||
| 155 | return 0; | ||
| 156 | |||
| 157 | reset = devm_reset_control_get_exclusive_by_index(phy_common->dev, 0); | ||
| 158 | if (IS_ERR(reset)) | ||
| 159 | return PTR_ERR(reset); | ||
| 160 | |||
| 161 | phy_common->ufs_reset = reset; | ||
| 162 | return 0; | ||
| 163 | } | ||
| 164 | |||
| 150 | static int __ufs_qcom_phy_clk_get(struct device *dev, | 165 | static int __ufs_qcom_phy_clk_get(struct device *dev, |
| 151 | const char *name, struct clk **clk_out, bool err_print) | 166 | const char *name, struct clk **clk_out, bool err_print) |
| 152 | { | 167 | { |
| @@ -528,23 +543,38 @@ int ufs_qcom_phy_power_on(struct phy *generic_phy) · 375 unmodified lines | |||
| 528 | { | 543 | { |
| 529 | struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy); | 544 | struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy); |
| 530 | struct device *dev = phy_common->dev; | 545 | struct device *dev = phy_common->dev; |
| 546 | bool is_rate_B = false; | ||
| 531 | int err; | 547 | int err; |
| 532 | 548 | ||
| 533 | if (phy_common->is_powered_on) | 549 | err = ufs_qcom_phy_get_reset(phy_common); |
| 534 | return 0; | 550 | if (err) |
| 551 | return err; | ||
| 535 | 552 | ||
| 536 | if (!phy_common->is_started) { | 553 | err = reset_control_assert(phy_common->ufs_reset); |
| 537 | err = ufs_qcom_phy_start_serdes(phy_common); | 554 | if (err) |
| 538 | if (err) | 555 | return err; |
| 539 | return err; | ||
| 540 | 556 | ||
| 541 | err = ufs_qcom_phy_is_pcs_ready(phy_common); | 557 | if (phy_common->mode == PHY_MODE_UFS_HS_B) |
| 542 | if (err) | 558 | is_rate_B = true; |
| 543 | return err; | ||
| 544 | 559 | ||
| 545 | phy_common->is_started = true; | 560 | err = phy_common->phy_spec_ops->calibrate(phy_common, is_rate_B); |
| 561 | if (err) | ||
| 562 | return err; | ||
| 563 | |||
| 564 | err = reset_control_deassert(phy_common->ufs_reset); | ||
| 565 | if (err) { | ||
| 566 | dev_err(dev, "Failed to assert UFS PHY reset"); | ||
| 567 | return err; | ||
| 546 | } | 568 | } |
| 547 | 569 | ||
| 570 | err = ufs_qcom_phy_start_serdes(phy_common); | ||
| 571 | if (err) | ||
| 572 | return err; | ||
| 573 | |||
| 574 | err = ufs_qcom_phy_is_pcs_ready(phy_common); | ||
| 575 | if (err) | ||
| 576 | return err; | ||
| 577 | |||
| 548 | err = ufs_qcom_phy_enable_vreg(dev, &phy_common->vdda_phy); | 578 | err = ufs_qcom_phy_enable_vreg(dev, &phy_common->vdda_phy); |
| 549 | if (err) { | 579 | if (err) { |
| 550 | dev_err(dev, "%s enable vdda_phy failed, err=%d\n", | 580 | dev_err(dev, "%s enable vdda_phy failed, err=%d\n", |
| @@ -587,7 +617,6 @@ int ufs_qcom_phy_power_on(struct phy *generic_phy) · 36 unmodified lines | |||
| 587 | } | 617 | } |
| 588 | } | 618 | } |
| 589 | 619 | ||
| 590 | phy_common->is_powered_on = true; | ||
| 591 | goto out; | 620 | goto out; |
| 592 | 621 | ||
| 593 | out_disable_ref_clk: | 622 | out_disable_ref_clk: |
| @@ -607,9 +636,6 @@ int ufs_qcom_phy_power_off(struct phy *generic_phy) · 13 unmodified lines | |||
| 607 | { | 636 | { |
| 608 | struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy); | 637 | struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy); |
| 609 | 638 | ||
| 610 | if (!phy_common->is_powered_on) | ||
| 611 | return 0; | ||
| 612 | |||
| 613 | phy_common->phy_spec_ops->power_control(phy_common, false); | 639 | phy_common->phy_spec_ops->power_control(phy_common, false); |
| 614 | 640 | ||
| 615 | if (phy_common->vddp_ref_clk.reg) | 641 | if (phy_common->vddp_ref_clk.reg) |
| @@ -620,8 +646,7 @@ int ufs_qcom_phy_power_off(struct phy *generic_phy) · 4 unmodified lines | |||
| 620 | 646 | ||
| 621 | ufs_qcom_phy_disable_vreg(phy_common->dev, &phy_common->vdda_pll); | 647 | ufs_qcom_phy_disable_vreg(phy_common->dev, &phy_common->vdda_pll); |
| 622 | ufs_qcom_phy_disable_vreg(phy_common->dev, &phy_common->vdda_phy); | 648 | ufs_qcom_phy_disable_vreg(phy_common->dev, &phy_common->vdda_phy); |
| 623 | phy_common->is_powered_on = false; | 649 | reset_control_assert(phy_common->ufs_reset); |
| 624 | |||
| 625 | return 0; | 650 | return 0; |
| 626 | } | 651 | } |
| 627 | EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_off); | 652 | EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_off); |
| @@ -19,7 +19,7 @@ config PHY_RCAR_GEN3_PCIE · 18 unmodified lines | |||
| 19 | config PHY_RCAR_GEN3_USB2 | 19 | config PHY_RCAR_GEN3_USB2 |
| 20 | tristate "Renesas R-Car generation 3 USB 2.0 PHY driver" | 20 | tristate "Renesas R-Car generation 3 USB 2.0 PHY driver" |
| 21 | depends on ARCH_RENESAS | 21 | depends on ARCH_RENESAS |
| 22 | depends on EXTCON | 22 | depends on EXTCON || !EXTCON # if EXTCON=m, this cannot be built-in |
| 23 | depends on USB_SUPPORT | 23 | depends on USB_SUPPORT |
| 24 | select GENERIC_PHY | 24 | select GENERIC_PHY |
| 25 | select USB_COMMON | 25 | select USB_COMMON |
| @@ -4,6 +4,7 @@ · 3 unmodified lines | |||
| 4 | * | 4 | * |
| 5 | * Copyright (C) 2014 Renesas Solutions Corp. | 5 | * Copyright (C) 2014 Renesas Solutions Corp. |
| 6 | * Copyright (C) 2014 Cogent Embedded, Inc. | 6 | * Copyright (C) 2014 Cogent Embedded, Inc. |
| 7 | * Copyright (C) 2019 Renesas Electronics Corp. | ||
| 7 | */ | 8 | */ |
| 8 | 9 | ||
| 9 | #include <linux/clk.h> | 10 | #include <linux/clk.h> |
| @@ -15,6 +16,7 @@ · 5 unmodified lines | |||
| 15 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| 16 | #include <linux/spinlock.h> | 17 | #include <linux/spinlock.h> |
| 17 | #include <linux/atomic.h> | 18 | #include <linux/atomic.h> |
| 19 | #include <linux/of_device.h> | ||
| 18 | 20 | ||
| 19 | #define USBHS_LPSTS 0x02 | 21 | #define USBHS_LPSTS 0x02 |
| 20 | #define USBHS_UGCTRL 0x80 | 22 | #define USBHS_UGCTRL 0x80 |
| @@ -35,6 +37,8 @@ · 14 unmodified lines | |||
| 35 | #define USBHS_UGCTRL2_USB0SEL 0x00000030 | 37 | #define USBHS_UGCTRL2_USB0SEL 0x00000030 |
| 36 | #define USBHS_UGCTRL2_USB0SEL_PCI 0x00000010 | 38 | #define USBHS_UGCTRL2_USB0SEL_PCI 0x00000010 |
| 37 | #define USBHS_UGCTRL2_USB0SEL_HS_USB 0x00000030 | 39 | #define USBHS_UGCTRL2_USB0SEL_HS_USB 0x00000030 |
| 40 | #define USBHS_UGCTRL2_USB0SEL_USB20 0x00000010 | ||
| 41 | #define USBHS_UGCTRL2_USB0SEL_HS_USB20 0x00000020 | ||
| 38 | 42 | ||
| 39 | /* USB General status register (UGSTS) */ | 43 | /* USB General status register (UGSTS) */ |
| 40 | #define USBHS_UGSTS_LOCK 0x00000100 /* From technical update */ | 44 | #define USBHS_UGSTS_LOCK 0x00000100 /* From technical update */ |
| @@ -64,6 +68,11 @@ struct rcar_gen2_phy_driver { · 23 unmodified lines | |||
| 64 | struct rcar_gen2_channel *channels; | 68 | struct rcar_gen2_channel *channels; |
| 65 | }; | 69 | }; |
| 66 | 70 | ||
| 71 | struct rcar_gen2_phy_data { | ||
| 72 | const struct phy_ops *gen2_phy_ops; | ||
| 73 | const u32 (*select_value)[PHYS_PER_CHANNEL]; | ||
| 74 | }; | ||
| 75 | |||
| 67 | static int rcar_gen2_phy_init(struct phy *p) | 76 | static int rcar_gen2_phy_init(struct phy *p) |
| 68 | { | 77 | { |
| 69 | struct rcar_gen2_phy *phy = phy_get_drvdata(p); | 78 | struct rcar_gen2_phy *phy = phy_get_drvdata(p); |
| @@ -180,6 +189,60 @@ static int rcar_gen2_phy_power_off(struct phy *p) · 110 unmodified lines | |||
| 180 | return 0; | 189 | return 0; |
| 181 | } | 190 | } |
| 182 | 191 | ||
| 192 | static int rz_g1c_phy_power_on(struct phy *p) | ||
| 193 | { | ||
| 194 | struct rcar_gen2_phy *phy = phy_get_drvdata(p); | ||
| 195 | struct rcar_gen2_phy_driver *drv = phy->channel->drv; | ||
| 196 | void __iomem *base = drv->base; | ||
| 197 | unsigned long flags; | ||
| 198 | u32 value; | ||
| 199 | |||
| 200 | spin_lock_irqsave(&drv->lock, flags); | ||
| 201 | |||
| 202 | /* Power on USBHS PHY */ | ||
| 203 | value = readl(base + USBHS_UGCTRL); | ||
| 204 | value &= ~USBHS_UGCTRL_PLLRESET; | ||
| 205 | writel(value, base + USBHS_UGCTRL); | ||
| 206 | |||
| 207 | /* As per the data sheet wait 340 micro sec for power stable */ | ||
| 208 | udelay(340); | ||
| 209 | |||
| 210 | if (phy->select_value == USBHS_UGCTRL2_USB0SEL_HS_USB20) { | ||
| 211 | value = readw(base + USBHS_LPSTS); | ||
| 212 | value |= USBHS_LPSTS_SUSPM; | ||
| 213 | writew(value, base + USBHS_LPSTS); | ||
| 214 | } | ||
| 215 | |||
| 216 | spin_unlock_irqrestore(&drv->lock, flags); | ||
| 217 | |||
| 218 | return 0; | ||
| 219 | } | ||
| 220 | |||
| 221 | static int rz_g1c_phy_power_off(struct phy *p) | ||
| 222 | { | ||
| 223 | struct rcar_gen2_phy *phy = phy_get_drvdata(p); | ||
| 224 | struct rcar_gen2_phy_driver *drv = phy->channel->drv; | ||
| 225 | void __iomem *base = drv->base; | ||
| 226 | unsigned long flags; | ||
| 227 | u32 value; | ||
| 228 | |||
| 229 | spin_lock_irqsave(&drv->lock, flags); | ||
| 230 | /* Power off USBHS PHY */ | ||
| 231 | if (phy->select_value == USBHS_UGCTRL2_USB0SEL_HS_USB20) { | ||
| 232 | value = readw(base + USBHS_LPSTS); | ||
| 233 | value &= ~USBHS_LPSTS_SUSPM; | ||
| 234 | writew(value, base + USBHS_LPSTS); | ||
| 235 | } | ||
| 236 | |||
| 237 | value = readl(base + USBHS_UGCTRL); | ||
| 238 | value |= USBHS_UGCTRL_PLLRESET; | ||
| 239 | writel(value, base + USBHS_UGCTRL); | ||
| 240 | |||
| 241 | spin_unlock_irqrestore(&drv->lock, flags); | ||
| 242 | |||
| 243 | return 0; | ||
| 244 | } | ||
| 245 | |||
| 183 | static const struct phy_ops rcar_gen2_phy_ops = { | 246 | static const struct phy_ops rcar_gen2_phy_ops = { |
| 184 | .init = rcar_gen2_phy_init, | 247 | .init = rcar_gen2_phy_init, |
| 185 | .exit = rcar_gen2_phy_exit, | 248 | .exit = rcar_gen2_phy_exit, |
| @@ -188,12 +251,55 @@ static const struct phy_ops rcar_gen2_phy_ops = { · 2 unmodified lines | |||
| 188 | .owner = THIS_MODULE, | 251 | .owner = THIS_MODULE, |
| 189 | }; | 252 | }; |
| 190 | 253 | ||
| 254 | static const struct phy_ops rz_g1c_phy_ops = { | ||
| 255 | .init = rcar_gen2_phy_init, | ||
| 256 | .exit = rcar_gen2_phy_exit, | ||
| 257 | .power_on = rz_g1c_phy_power_on, | ||
| 258 | .power_off = rz_g1c_phy_power_off, | ||
| 259 | .owner = THIS_MODULE, | ||
| 260 | }; | ||
| 261 | |||
| 262 | static const u32 pci_select_value[][PHYS_PER_CHANNEL] = { | ||
| 263 | [0] = { USBHS_UGCTRL2_USB0SEL_PCI, USBHS_UGCTRL2_USB0SEL_HS_USB }, | ||
| 264 | [2] = { USBHS_UGCTRL2_USB2SEL_PCI, USBHS_UGCTRL2_USB2SEL_USB30 }, | ||
| 265 | }; | ||
| 266 | |||
| 267 | static const u32 usb20_select_value[][PHYS_PER_CHANNEL] = { | ||
| 268 | { USBHS_UGCTRL2_USB0SEL_USB20, USBHS_UGCTRL2_USB0SEL_HS_USB20 }, | ||
| 269 | }; | ||
| 270 | |||
| 271 | static const struct rcar_gen2_phy_data rcar_gen2_usb_phy_data = { | ||
| 272 | .gen2_phy_ops = &rcar_gen2_phy_ops, | ||
| 273 | .select_value = pci_select_value, | ||
| 274 | }; | ||
| 275 | |||
| 276 | static const struct rcar_gen2_phy_data rz_g1c_usb_phy_data = { | ||
| 277 | .gen2_phy_ops = &rz_g1c_phy_ops, | ||
| 278 | .select_value = usb20_select_value, | ||
| 279 | }; | ||
| 280 | |||
| 191 | static const struct of_device_id rcar_gen2_phy_match_table[] = { | 281 | static const struct of_device_id rcar_gen2_phy_match_table[] = { |
| 192 | { .compatible = "renesas,usb-phy-r8a7790" }, | 282 | { |
| 193 | { .compatible = "renesas,usb-phy-r8a7791" }, | 283 | .compatible = "renesas,usb-phy-r8a77470", |
| 194 | { .compatible = "renesas,usb-phy-r8a7794" }, | 284 | .data = &rz_g1c_usb_phy_data, |
| 195 | { .compatible = "renesas,rcar-gen2-usb-phy" }, | 285 | }, |
| 196 | { } | 286 | { |
| 287 | .compatible = "renesas,usb-phy-r8a7790", | ||
| 288 | .data = &rcar_gen2_usb_phy_data, | ||
| 289 | }, | ||
| 290 | { | ||
| 291 | .compatible = "renesas,usb-phy-r8a7791", | ||
| 292 | .data = &rcar_gen2_usb_phy_data, | ||
| 293 | }, | ||
| 294 | { | ||
| 295 | .compatible = "renesas,usb-phy-r8a7794", | ||
| 296 | .data = &rcar_gen2_usb_phy_data, | ||
| 297 | }, | ||
| 298 | { | ||
| 299 | .compatible = "renesas,rcar-gen2-usb-phy", | ||
| 300 | .data = &rcar_gen2_usb_phy_data, | ||
| 301 | }, | ||
| 302 | { /* sentinel */ }, | ||
| 197 | }; | 303 | }; |
| 198 | MODULE_DEVICE_TABLE(of, rcar_gen2_phy_match_table); | 304 | MODULE_DEVICE_TABLE(of, rcar_gen2_phy_match_table); |
| 199 | 305 | ||
| @@ -224,11 +330,6 @@ static const u32 select_mask[] = { · 24 unmodified lines | |||
| 224 | [2] = USBHS_UGCTRL2_USB2SEL, | 330 | [2] = USBHS_UGCTRL2_USB2SEL, |
| 225 | }; | 331 | }; |
| 226 | 332 | ||
| 227 | static const u32 select_value[][PHYS_PER_CHANNEL] = { | ||
| 228 | [0] = { USBHS_UGCTRL2_USB0SEL_PCI, USBHS_UGCTRL2_USB0SEL_HS_USB }, | ||
| 229 | [2] = { USBHS_UGCTRL2_USB2SEL_PCI, USBHS_UGCTRL2_USB2SEL_USB30 }, | ||
| 230 | }; | ||
| 231 | |||
| 232 | static int rcar_gen2_phy_probe(struct platform_device *pdev) | 333 | static int rcar_gen2_phy_probe(struct platform_device *pdev) |
| 233 | { | 334 | { |
| 234 | struct device *dev = &pdev->dev; | 335 | struct device *dev = &pdev->dev; |
| @@ -238,6 +339,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) · 3 unmodified lines | |||
| 238 | struct resource *res; | 339 | struct resource *res; |
| 239 | void __iomem *base; | 340 | void __iomem *base; |
| 240 | struct clk *clk; | 341 | struct clk *clk; |
| 342 | const struct rcar_gen2_phy_data *data; | ||
| 241 | int i = 0; | 343 | int i = 0; |
| 242 | 344 | ||
| 243 | if (!dev->of_node) { | 345 | if (!dev->of_node) { |
| @@ -266,6 +368,10 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) · 22 unmodified lines | |||
| 266 | drv->clk = clk; | 368 | drv->clk = clk; |
| 267 | drv->base = base; | 369 | drv->base = base; |
| 268 | 370 | ||
| 371 | data = of_device_get_match_data(dev); | ||
| 372 | if (!data) | ||
| 373 | return -EINVAL; | ||
| 374 | |||
| 269 | drv->num_channels = of_get_child_count(dev->of_node); | 375 | drv->num_channels = of_get_child_count(dev->of_node); |
| 270 | drv->channels = devm_kcalloc(dev, drv->num_channels, | 376 | drv->channels = devm_kcalloc(dev, drv->num_channels, |
| 271 | sizeof(struct rcar_gen2_channel), | 377 | sizeof(struct rcar_gen2_channel), |
| @@ -294,10 +400,10 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) · 22 unmodified lines | |||
| 294 | 400 | ||
| 295 | phy->channel = channel; | 401 | phy->channel = channel; |
| 296 | phy->number = n; | 402 | phy->number = n; |
| 297 | phy->select_value = select_value[channel_num][n]; | 403 | phy->select_value = data->select_value[channel_num][n]; |
| 298 | 404 | ||
| 299 | phy->phy = devm_phy_create(dev, NULL, | 405 | phy->phy = devm_phy_create(dev, NULL, |
| 300 | &rcar_gen2_phy_ops); | 406 | data->gen2_phy_ops); |
| 301 | if (IS_ERR(phy->phy)) { | 407 | if (IS_ERR(phy->phy)) { |
| 302 | dev_err(dev, "Failed to create PHY\n"); | 408 | dev_err(dev, "Failed to create PHY\n"); |
| 303 | return PTR_ERR(phy->phy); | 409 | return PTR_ERR(phy->phy); |
| @@ -37,11 +37,8 @@ · 36 unmodified lines | |||
| 37 | 37 | ||
| 38 | /* INT_ENABLE */ | 38 | /* INT_ENABLE */ |
| 39 | #define USB2_INT_ENABLE_UCOM_INTEN BIT(3) | 39 | #define USB2_INT_ENABLE_UCOM_INTEN BIT(3) |
| 40 | #define USB2_INT_ENABLE_USBH_INTB_EN BIT(2) | 40 | #define USB2_INT_ENABLE_USBH_INTB_EN BIT(2) /* For EHCI */ |
| 41 | #define USB2_INT_ENABLE_USBH_INTA_EN BIT(1) | 41 | #define USB2_INT_ENABLE_USBH_INTA_EN BIT(1) /* For OHCI */ |
| 42 | #define USB2_INT_ENABLE_INIT (USB2_INT_ENABLE_UCOM_INTEN | \ | ||
| 43 | USB2_INT_ENABLE_USBH_INTB_EN | \ | ||
| 44 | USB2_INT_ENABLE_USBH_INTA_EN) | ||
| 45 | 42 | ||
| 46 | /* USBCTR */ | 43 | /* USBCTR */ |
| 47 | #define USB2_USBCTR_DIRPD BIT(2) | 44 | #define USB2_USBCTR_DIRPD BIT(2) |
| @@ -78,10 +75,35 @@ · 30 unmodified lines | |||
| 78 | #define USB2_ADPCTRL_IDPULLUP BIT(5) /* 1 = ID sampling is enabled */ | 75 | #define USB2_ADPCTRL_IDPULLUP BIT(5) /* 1 = ID sampling is enabled */ |
| 79 | #define USB2_ADPCTRL_DRVVBUS BIT(4) | 76 | #define USB2_ADPCTRL_DRVVBUS BIT(4) |
| 80 | 77 | ||
| 78 | #define NUM_OF_PHYS 4 | ||
| 79 | enum rcar_gen3_phy_index { | ||
| 80 | PHY_INDEX_BOTH_HC, | ||
| 81 | PHY_INDEX_OHCI, | ||
| 82 | PHY_INDEX_EHCI, | ||
| 83 | PHY_INDEX_HSUSB | ||
| 84 | }; | ||
| 85 | |||
| 86 | static const u32 rcar_gen3_int_enable[NUM_OF_PHYS] = { | ||
| 87 | USB2_INT_ENABLE_USBH_INTB_EN | USB2_INT_ENABLE_USBH_INTA_EN, | ||
| 88 | USB2_INT_ENABLE_USBH_INTA_EN, | ||
| 89 | USB2_INT_ENABLE_USBH_INTB_EN, | ||
| 90 | 0 | ||
| 91 | }; | ||
| 92 | |||
| 93 | struct rcar_gen3_phy { | ||
| 94 | struct phy *phy; | ||
| 95 | struct rcar_gen3_chan *ch; | ||
| 96 | u32 int_enable_bits; | ||
| 97 | bool initialized; | ||
| 98 | bool otg_initialized; | ||
| 99 | bool powered; | ||
| 100 | }; | ||
| 101 | |||
| 81 | struct rcar_gen3_chan { | 102 | struct rcar_gen3_chan { |
| 82 | void __iomem *base; | 103 | void __iomem *base; |
| 104 | struct device *dev; /* platform_device's device */ | ||
| 83 | struct extcon_dev *extcon; | 105 | struct extcon_dev *extcon; |
| 84 | struct phy *phy; | 106 | struct rcar_gen3_phy rphys[NUM_OF_PHYS]; |
| 85 | struct regulator *vbus; | 107 | struct regulator *vbus; |
| 86 | struct work_struct work; | 108 | struct work_struct work; |
| 87 | enum usb_dr_mode dr_mode; | 109 | enum usb_dr_mode dr_mode; |
| @@ -120,7 +142,7 @@ static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host) · 32 unmodified lines | |||
| 120 | void __iomem *usb2_base = ch->base; | 142 | void __iomem *usb2_base = ch->base; |
| 121 | u32 val = readl(usb2_base + USB2_COMMCTRL); | 143 | u32 val = readl(usb2_base + USB2_COMMCTRL); |
| 122 | 144 | ||
| 123 | dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, host); | 145 | dev_vdbg(ch->dev, "%s: %08x, %d\n", __func__, val, host); |
| 124 | if (host) | 146 | if (host) |
| 125 | val &= ~USB2_COMMCTRL_OTG_PERI; | 147 | val &= ~USB2_COMMCTRL_OTG_PERI; |
| 126 | else | 148 | else |
| @@ -133,7 +155,7 @@ static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm) · 6 unmodified lines | |||
| 133 | void __iomem *usb2_base = ch->base; | 155 | void __iomem *usb2_base = ch->base; |
| 134 | u32 val = readl(usb2_base + USB2_LINECTRL1); | 156 | u32 val = readl(usb2_base + USB2_LINECTRL1); |
| 135 | 157 | ||
| 136 | dev_vdbg(&ch->phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm); | 158 | dev_vdbg(ch->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm); |
| 137 | val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD); | 159 | val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD); |
| 138 | if (dp) | 160 | if (dp) |
| 139 | val |= USB2_LINECTRL1_DP_RPD; | 161 | val |= USB2_LINECTRL1_DP_RPD; |
| @@ -147,7 +169,7 @@ static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus) · 7 unmodified lines | |||
| 147 | void __iomem *usb2_base = ch->base; | 169 | void __iomem *usb2_base = ch->base; |
| 148 | u32 val = readl(usb2_base + USB2_ADPCTRL); | 170 | u32 val = readl(usb2_base + USB2_ADPCTRL); |
| 149 | 171 | ||
| 150 | dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, vbus); | 172 | dev_vdbg(ch->dev, "%s: %08x, %d\n", __func__, val, vbus); |
| 151 | if (vbus) | 173 | if (vbus) |
| 152 | val |= USB2_ADPCTRL_DRVVBUS; | 174 | val |= USB2_ADPCTRL_DRVVBUS; |
| 153 | else | 175 | else |
| @@ -249,6 +271,42 @@ static enum phy_mode rcar_gen3_get_phy_mode(struct rcar_gen3_chan *ch) · 95 unmodified lines | |||
| 249 | return PHY_MODE_USB_DEVICE; | 271 | return PHY_MODE_USB_DEVICE; |
| 250 | } | 272 | } |
| 251 | 273 | ||
| 274 | static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch) | ||
| 275 | { | ||
| 276 | int i; | ||
| 277 | |||
| 278 | for (i = 0; i < NUM_OF_PHYS; i++) { | ||
| 279 | if (ch->rphys[i].initialized) | ||
| 280 | return true; | ||
| 281 | } | ||
| 282 | |||
| 283 | return false; | ||
| 284 | } | ||
| 285 | |||
| 286 | static bool rcar_gen3_needs_init_otg(struct rcar_gen3_chan *ch) | ||
| 287 | { | ||
| 288 | int i; | ||
| 289 | |||
| 290 | for (i = 0; i < NUM_OF_PHYS; i++) { | ||
| 291 | if (ch->rphys[i].otg_initialized) | ||
| 292 | return false; | ||
| 293 | } | ||
| 294 | |||
| 295 | return true; | ||
| 296 | } | ||
| 297 | |||
| 298 | static bool rcar_gen3_are_all_rphys_power_off(struct rcar_gen3_chan *ch) | ||
| 299 | { | ||
| 300 | int i; | ||
| 301 | |||
| 302 | for (i = 0; i < NUM_OF_PHYS; i++) { | ||
| 303 | if (ch->rphys[i].powered) | ||
| 304 | return false; | ||
| 305 | } | ||
| 306 | |||
| 307 | return true; | ||
| 308 | } | ||
| 309 | |||
| 252 | static ssize_t role_store(struct device *dev, struct device_attribute *attr, | 310 | static ssize_t role_store(struct device *dev, struct device_attribute *attr, |
| 253 | const char *buf, size_t count) | 311 | const char *buf, size_t count) |
| 254 | { | 312 | { |
| @@ -256,7 +314,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, · 1 unmodified line | |||
| 256 | bool is_b_device; | 314 | bool is_b_device; |
| 257 | enum phy_mode cur_mode, new_mode; | 315 | enum phy_mode cur_mode, new_mode; |
| 258 | 316 | ||
| 259 | if (!ch->is_otg_channel || !ch->phy->init_count) | 317 | if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) |
| 260 | return -EIO; | 318 | return -EIO; |
| 261 | 319 | ||
| 262 | if (!strncmp(buf, "host", strlen("host"))) | 320 | if (!strncmp(buf, "host", strlen("host"))) |
| @@ -294,7 +352,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, · 31 unmodified lines | |||
| 294 | { | 352 | { |
| 295 | struct rcar_gen3_chan *ch = dev_get_drvdata(dev); | 353 | struct rcar_gen3_chan *ch = dev_get_drvdata(dev); |
| 296 | 354 | ||
| 297 | if (!ch->is_otg_channel || !ch->phy->init_count) | 355 | if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) |
| 298 | return -EIO; | 356 | return -EIO; |
| 299 | 357 | ||
| 300 | return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" : | 358 | return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" : |
| @@ -328,37 +386,62 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) · 27 unmodified lines | |||
| 328 | 386 | ||
| 329 | static int rcar_gen3_phy_usb2_init(struct phy *p) | 387 | static int rcar_gen3_phy_usb2_init(struct phy *p) |
| 330 | { | 388 | { |
| 331 | struct rcar_gen3_chan *channel = phy_get_drvdata(p); | 389 | struct rcar_gen3_phy *rphy = phy_get_drvdata(p); |
| 390 | struct rcar_gen3_chan *channel = rphy->ch; | ||
| 332 | void __iomem *usb2_base = channel->base; | 391 | void __iomem *usb2_base = channel->base; |
| 392 | u32 val; | ||
| 333 | 393 | ||
| 334 | /* Initialize USB2 part */ | 394 | /* Initialize USB2 part */ |
| 335 | writel(USB2_INT_ENABLE_INIT, usb2_base + USB2_INT_ENABLE); | 395 | val = readl(usb2_base + USB2_INT_ENABLE); |
| 396 | val |= USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits; | ||
| 397 | writel(val, usb2_base + USB2_INT_ENABLE); | ||
| 336 | writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); | 398 | writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); |
| 337 | writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); | 399 | writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); |
| 338 | 400 | ||
| 339 | /* Initialize otg part */ | 401 | /* Initialize otg part */ |
| 340 | if (channel->is_otg_channel) | 402 | if (channel->is_otg_channel) { |
| 341 | rcar_gen3_init_otg(channel); | 403 | if (rcar_gen3_needs_init_otg(channel)) |
| 404 | rcar_gen3_init_otg(channel); | ||
| 405 | rphy->otg_initialized = true; | ||
| 406 | } | ||
| 407 | |||
| 408 | rphy->initialized = true; | ||
| 342 | 409 | ||
| 343 | return 0; | 410 | return 0; |
| 344 | } | 411 | } |
| 345 | 412 | ||
| 346 | static int rcar_gen3_phy_usb2_exit(struct phy *p) | 413 | static int rcar_gen3_phy_usb2_exit(struct phy *p) |
| 347 | { | 414 | { |
| 348 | struct rcar_gen3_chan *channel = phy_get_drvdata(p); | 415 | struct rcar_gen3_phy *rphy = phy_get_drvdata(p); |
| 416 | struct rcar_gen3_chan *channel = rphy->ch; | ||
| 417 | void __iomem *usb2_base = channel->base; | ||
| 418 | u32 val; | ||
| 419 | |||
| 420 | rphy->initialized = false; | ||
| 421 | |||
| 422 | if (channel->is_otg_channel) | ||
| 423 | rphy->otg_initialized = false; | ||
| 349 | 424 | ||
| 350 | writel(0, channel->base + USB2_INT_ENABLE); | 425 | val = readl(usb2_base + USB2_INT_ENABLE); |
| 426 | val &= ~rphy->int_enable_bits; | ||
| 427 | if (!rcar_gen3_is_any_rphy_initialized(channel)) | ||
| 428 | val &= ~USB2_INT_ENABLE_UCOM_INTEN; | ||
| 429 | writel(val, usb2_base + USB2_INT_ENABLE); | ||
| 351 | 430 | ||
| 352 | return 0; | 431 | return 0; |
| 353 | } | 432 | } |
| 354 | 433 | ||
| 355 | static int rcar_gen3_phy_usb2_power_on(struct phy *p) | 434 | static int rcar_gen3_phy_usb2_power_on(struct phy *p) |
| 356 | { | 435 | { |
| 357 | struct rcar_gen3_chan *channel = phy_get_drvdata(p); | 436 | struct rcar_gen3_phy *rphy = phy_get_drvdata(p); |
| 437 | struct rcar_gen3_chan *channel = rphy->ch; | ||
| 358 | void __iomem *usb2_base = channel->base; | 438 | void __iomem *usb2_base = channel->base; |
| 359 | u32 val; | 439 | u32 val; |
| 360 | int ret; | 440 | int ret; |
| 361 | 441 | ||
| 442 | if (!rcar_gen3_are_all_rphys_power_off(channel)) | ||
| 443 | return 0; | ||
| 444 | |||
| 362 | if (channel->vbus) { | 445 | if (channel->vbus) { |
| 363 | ret = regulator_enable(channel->vbus); | 446 | ret = regulator_enable(channel->vbus); |
| 364 | if (ret) | 447 | if (ret) |
| @@ -371,14 +454,22 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) · 6 unmodified lines | |||
| 371 | val &= ~USB2_USBCTR_PLL_RST; | 454 | val &= ~USB2_USBCTR_PLL_RST; |
| 372 | writel(val, usb2_base + USB2_USBCTR); | 455 | writel(val, usb2_base + USB2_USBCTR); |
| 373 | 456 | ||
| 457 | rphy->powered = true; | ||
| 458 | |||
| 374 | return 0; | 459 | return 0; |
| 375 | } | 460 | } |
| 376 | 461 | ||
| 377 | static int rcar_gen3_phy_usb2_power_off(struct phy *p) | 462 | static int rcar_gen3_phy_usb2_power_off(struct phy *p) |
| 378 | { | 463 | { |
| 379 | struct rcar_gen3_chan *channel = phy_get_drvdata(p); | 464 | struct rcar_gen3_phy *rphy = phy_get_drvdata(p); |
| 465 | struct rcar_gen3_chan *channel = rphy->ch; | ||
| 380 | int ret = 0; | 466 | int ret = 0; |
| 381 | 467 | ||
| 468 | rphy->powered = false; | ||
| 469 | |||
| 470 | if (!rcar_gen3_are_all_rphys_power_off(channel)) | ||
| 471 | return 0; | ||
| 472 | |||
| 382 | if (channel->vbus) | 473 | if (channel->vbus) |
| 383 | ret = regulator_disable(channel->vbus); | 474 | ret = regulator_disable(channel->vbus); |
| 384 | 475 | ||
| @@ -393,6 +484,12 @@ static const struct phy_ops rcar_gen3_phy_usb2_ops = { · 8 unmodified lines | |||
| 393 | .owner = THIS_MODULE, | 484 | .owner = THIS_MODULE, |
| 394 | }; | 485 | }; |
| 395 | 486 | ||
| 487 | static const struct phy_ops rz_g1c_phy_usb2_ops = { | ||
| 488 | .init = rcar_gen3_phy_usb2_init, | ||
| 489 | .exit = rcar_gen3_phy_usb2_exit, | ||
| 490 | .owner = THIS_MODULE, | ||
| 491 | }; | ||
| 492 | |||
| 396 | static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) | 493 | static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) |
| 397 | { | 494 | { |
| 398 | struct rcar_gen3_chan *ch = _ch; | 495 | struct rcar_gen3_chan *ch = _ch; |
| @@ -401,7 +498,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) · 2 unmodified lines | |||
| 401 | irqreturn_t ret = IRQ_NONE; | 498 | irqreturn_t ret = IRQ_NONE; |
| 402 | 499 | ||
| 403 | if (status & USB2_OBINT_BITS) { | 500 | if (status & USB2_OBINT_BITS) { |
| 404 | dev_vdbg(&ch->phy->dev, "%s: %08x\n", __func__, status); | 501 | dev_vdbg(ch->dev, "%s: %08x\n", __func__, status); |
| 405 | writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); | 502 | writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); |
| 406 | rcar_gen3_device_recognition(ch); | 503 | rcar_gen3_device_recognition(ch); |
| 407 | ret = IRQ_HANDLED; | 504 | ret = IRQ_HANDLED; |
| @@ -411,11 +508,27 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) · 3 unmodified lines | |||
| 411 | } | 508 | } |
| 412 | 509 | ||
| 413 | static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = { | 510 | static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = { |
| 414 | { .compatible = "renesas,usb2-phy-r8a7795" }, | 511 | { |
| 415 | { .compatible = "renesas,usb2-phy-r8a7796" }, | 512 | .compatible = "renesas,usb2-phy-r8a77470", |
| 416 | { .compatible = "renesas,usb2-phy-r8a77965" }, | 513 | .data = &rz_g1c_phy_usb2_ops, |
| 417 | { .compatible = "renesas,rcar-gen3-usb2-phy" }, | 514 | }, |
| 418 | { } | 515 | { |
| 516 | .compatible = "renesas,usb2-phy-r8a7795", | ||
| 517 | .data = &rcar_gen3_phy_usb2_ops, | ||
| 518 | }, | ||
| 519 | { | ||
| 520 | .compatible = "renesas,usb2-phy-r8a7796", | ||
| 521 | .data = &rcar_gen3_phy_usb2_ops, | ||
| 522 | }, | ||
| 523 | { | ||
| 524 | .compatible = "renesas,usb2-phy-r8a77965", | ||
| 525 | .data = &rcar_gen3_phy_usb2_ops, | ||
| 526 | }, | ||
| 527 | { | ||
| 528 | .compatible = "renesas,rcar-gen3-usb2-phy", | ||
| 529 | .data = &rcar_gen3_phy_usb2_ops, | ||
| 530 | }, | ||
| 531 | { /* sentinel */ }, | ||
| 419 | }; | 532 | }; |
| 420 | MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table); | 533 | MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table); |
| 421 | 534 | ||
| @@ -425,13 +538,54 @@ static const unsigned int rcar_gen3_phy_cable[] = { · 3 unmodified lines | |||
| 425 | EXTCON_NONE, | 538 | EXTCON_NONE, |
| 426 | }; | 539 | }; |
| 427 | 540 | ||
| 541 | static struct phy *rcar_gen3_phy_usb2_xlate(struct device *dev, | ||
| 542 | struct of_phandle_args *args) | ||
| 543 | { | ||
| 544 | struct rcar_gen3_chan *ch = dev_get_drvdata(dev); | ||
| 545 | |||
| 546 | if (args->args_count == 0) /* For old version dts */ | ||
| 547 | return ch->rphys[PHY_INDEX_BOTH_HC].phy; | ||
| 548 | else if (args->args_count > 1) /* Prevent invalid args count */ | ||
| 549 | return ERR_PTR(-ENODEV); | ||
| 550 | |||
| 551 | if (args->args[0] >= NUM_OF_PHYS) | ||
| 552 | return ERR_PTR(-ENODEV); | ||
| 553 | |||
| 554 | return ch->rphys[args->args[0]].phy; | ||
| 555 | } | ||
| 556 | |||
| 557 | static enum usb_dr_mode rcar_gen3_get_dr_mode(struct device_node *np) | ||
| 558 | { | ||
| 559 | enum usb_dr_mode candidate = USB_DR_MODE_UNKNOWN; | ||
| 560 | int i; | ||
| 561 | |||
| 562 | /* | ||
| 563 | * If one of device nodes has other dr_mode except UNKNOWN, | ||
| 564 | * this function returns UNKNOWN. To achieve backward compatibility, | ||
| 565 | * this loop starts the index as 0. | ||
| 566 | */ | ||
| 567 | for (i = 0; i < NUM_OF_PHYS; i++) { | ||
| 568 | enum usb_dr_mode mode = of_usb_get_dr_mode_by_phy(np, i); | ||
| 569 | |||
| 570 | if (mode != USB_DR_MODE_UNKNOWN) { | ||
| 571 | if (candidate == USB_DR_MODE_UNKNOWN) | ||
| 572 | candidate = mode; | ||
| 573 | else if (candidate != mode) | ||
| 574 | return USB_DR_MODE_UNKNOWN; | ||
| 575 | } | ||
| 576 | } | ||
| 577 | |||
| 578 | return candidate; | ||
| 579 | } | ||
| 580 | |||
| 428 | static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) | 581 | static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) |
| 429 | { | 582 | { |
| 430 | struct device *dev = &pdev->dev; | 583 | struct device *dev = &pdev->dev; |
| 431 | struct rcar_gen3_chan *channel; | 584 | struct rcar_gen3_chan *channel; |
| 432 | struct phy_provider *provider; | 585 | struct phy_provider *provider; |
| 433 | struct resource *res; | 586 | struct resource *res; |
| 434 | int irq, ret = 0; | 587 | const struct phy_ops *phy_usb2_ops; |
| 588 | int irq, ret = 0, i; | ||
| 435 | 589 | ||
| 436 | if (!dev->of_node) { | 590 | if (!dev->of_node) { |
| 437 | dev_err(dev, "This driver needs device tree\n"); | 591 | dev_err(dev, "This driver needs device tree\n"); |
| @@ -457,7 +611,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) · 19 unmodified lines | |||
| 457 | dev_err(dev, "No irq handler (%d)\n", irq); | 611 | dev_err(dev, "No irq handler (%d)\n", irq); |
| 458 | } | 612 | } |
| 459 | 613 | ||
| 460 | channel->dr_mode = of_usb_get_dr_mode_by_phy(dev->of_node, 0); | 614 | channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node); |
| 461 | if (channel->dr_mode != USB_DR_MODE_UNKNOWN) { | 615 | if (channel->dr_mode != USB_DR_MODE_UNKNOWN) { |
| 462 | int ret; | 616 | int ret; |
| 463 | 617 | ||
| @@ -481,11 +635,21 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) · 17 unmodified lines | |||
| 481 | * And then, phy-core will manage runtime pm for this device. | 635 | * And then, phy-core will manage runtime pm for this device. |
| 482 | */ | 636 | */ |
| 483 | pm_runtime_enable(dev); | 637 | pm_runtime_enable(dev); |
| 484 | channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops); | 638 | phy_usb2_ops = of_device_get_match_data(dev); |
| 485 | if (IS_ERR(channel->phy)) { | 639 | if (!phy_usb2_ops) |
| 486 | dev_err(dev, "Failed to create USB2 PHY\n"); | 640 | return -EINVAL; |
| 487 | ret = PTR_ERR(channel->phy); | 641 | |
| 488 | goto error; | 642 | for (i = 0; i < NUM_OF_PHYS; i++) { |
| 643 | channel->rphys[i].phy = devm_phy_create(dev, NULL, | ||
| 644 | phy_usb2_ops); | ||
| 645 | if (IS_ERR(channel->rphys[i].phy)) { | ||
| 646 | dev_err(dev, "Failed to create USB2 PHY\n"); | ||
| 647 | ret = PTR_ERR(channel->rphys[i].phy); | ||
| 648 | goto error; | ||
| 649 | } | ||
| 650 | channel->rphys[i].ch = channel; | ||
| 651 | channel->rphys[i].int_enable_bits = rcar_gen3_int_enable[i]; | ||
| 652 | phy_set_drvdata(channel->rphys[i].phy, &channel->rphys[i]); | ||
| 489 | } | 653 | } |
| 490 | 654 | ||
| 491 | channel->vbus = devm_regulator_get_optional(dev, "vbus"); | 655 | channel->vbus = devm_regulator_get_optional(dev, "vbus"); |
| @@ -498,9 +662,9 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) · 6 unmodified lines | |||
| 498 | } | 662 | } |
| 499 | 663 | ||
| 500 | platform_set_drvdata(pdev, channel); | 664 | platform_set_drvdata(pdev, channel); |
| 501 | phy_set_drvdata(channel->phy, channel); | 665 | channel->dev = dev; |
| 502 | 666 | ||
| 503 | provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); | 667 | provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); |
| 504 | if (IS_ERR(provider)) { | 668 | if (IS_ERR(provider)) { |
| 505 | dev_err(dev, "Failed to register PHY provider\n"); | 669 | dev_err(dev, "Failed to register PHY provider\n"); |
| 506 | ret = PTR_ERR(provider); | 670 | ret = PTR_ERR(provider); |
| @@ -87,6 +87,7 @@ struct rockchip_emmc_phy { · 86 unmodified lines | |||
| 87 | unsigned int reg_offset; | 87 | unsigned int reg_offset; |
| 88 | struct regmap *reg_base; | 88 | struct regmap *reg_base; |
| 89 | struct clk *emmcclk; | 89 | struct clk *emmcclk; |
| 90 | unsigned int drive_impedance; | ||
| 90 | }; | 91 | }; |
| 91 | 92 | ||
| 92 | static int rockchip_emmc_phy_power(struct phy *phy, bool on_off) | 93 | static int rockchip_emmc_phy_power(struct phy *phy, bool on_off) |
| @@ -281,10 +282,10 @@ static int rockchip_emmc_phy_power_on(struct phy *phy) · 188 unmodified lines | |||
| 281 | { | 282 | { |
| 282 | struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); | 283 | struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); |
| 283 | 284 | ||
| 284 | /* Drive impedance: 50 Ohm */ | 285 | /* Drive impedance: from DTS */ |
| 285 | regmap_write(rk_phy->reg_base, | 286 | regmap_write(rk_phy->reg_base, |
| 286 | rk_phy->reg_offset + GRF_EMMCPHY_CON6, | 287 | rk_phy->reg_offset + GRF_EMMCPHY_CON6, |
| 287 | HIWORD_UPDATE(PHYCTRL_DR_50OHM, | 288 | HIWORD_UPDATE(rk_phy->drive_impedance, |
| 288 | PHYCTRL_DR_MASK, | 289 | PHYCTRL_DR_MASK, |
| 289 | PHYCTRL_DR_SHIFT)); | 290 | PHYCTRL_DR_SHIFT)); |
| 290 | 291 | ||
| @@ -314,6 +315,26 @@ static const struct phy_ops ops = { · 23 unmodified lines | |||
| 314 | .owner = THIS_MODULE, | 315 | .owner = THIS_MODULE, |
| 315 | }; | 316 | }; |
| 316 | 317 | ||
| 318 | static u32 convert_drive_impedance_ohm(struct platform_device *pdev, u32 dr_ohm) | ||
| 319 | { | ||
| 320 | switch (dr_ohm) { | ||
| 321 | case 100: | ||
| 322 | return PHYCTRL_DR_100OHM; | ||
| 323 | case 66: | ||
| 324 | return PHYCTRL_DR_66OHM; | ||
| 325 | case 50: | ||
| 326 | return PHYCTRL_DR_50OHM; | ||
| 327 | case 40: | ||
| 328 | return PHYCTRL_DR_40OHM; | ||
| 329 | case 33: | ||
| 330 | return PHYCTRL_DR_33OHM; | ||
| 331 | } | ||
| 332 | |||
| 333 | dev_warn(&pdev->dev, "Invalid value %u for drive-impedance-ohm.\n", | ||
| 334 | dr_ohm); | ||
| 335 | return PHYCTRL_DR_50OHM; | ||
| 336 | } | ||
| 337 | |||
| 317 | static int rockchip_emmc_phy_probe(struct platform_device *pdev) | 338 | static int rockchip_emmc_phy_probe(struct platform_device *pdev) |
| 318 | { | 339 | { |
| 319 | struct device *dev = &pdev->dev; | 340 | struct device *dev = &pdev->dev; |
| @@ -322,6 +343,7 @@ static int rockchip_emmc_phy_probe(struct platform_device *pdev) · 2 unmodified lines | |||
| 322 | struct phy_provider *phy_provider; | 343 | struct phy_provider *phy_provider; |
| 323 | struct regmap *grf; | 344 | struct regmap *grf; |
| 324 | unsigned int reg_offset; | 345 | unsigned int reg_offset; |
| 346 | u32 val; | ||
| 325 | 347 | ||
| 326 | if (!dev->parent || !dev->parent->of_node) | 348 | if (!dev->parent || !dev->parent->of_node) |
| 327 | return -ENODEV; | 349 | return -ENODEV; |
| @@ -344,6 +366,10 @@ static int rockchip_emmc_phy_probe(struct platform_device *pdev) · 16 unmodified lines | |||
| 344 | 366 | ||
| 345 | rk_phy->reg_offset = reg_offset; | 367 | rk_phy->reg_offset = reg_offset; |
| 346 | rk_phy->reg_base = grf; | 368 | rk_phy->reg_base = grf; |
| 369 | rk_phy->drive_impedance = PHYCTRL_DR_50OHM; | ||
| 370 | |||
| 371 | if (!of_property_read_u32(dev->of_node, "drive-impedance-ohm", &val)) | ||
| 372 | rk_phy->drive_impedance = convert_drive_impedance_ohm(pdev, val); | ||
| 347 | 373 | ||
| 348 | generic_phy = devm_phy_create(dev, dev->of_node, &ops); | 374 | generic_phy = devm_phy_create(dev, dev->of_node, &ops); |
| 349 | if (IS_ERR(generic_phy)) { | 375 | if (IS_ERR(generic_phy)) { |
| @@ -335,13 +335,9 @@ static int uniphier_u3hsphy_probe(struct platform_device *pdev) · 334 unmodified lines | |||
| 335 | if (IS_ERR(priv->clk_parent)) | 335 | if (IS_ERR(priv->clk_parent)) |
| 336 | return PTR_ERR(priv->clk_parent); | 336 | return PTR_ERR(priv->clk_parent); |
| 337 | 337 | ||
| 338 | priv->clk_ext = devm_clk_get(dev, "phy-ext"); | 338 | priv->clk_ext = devm_clk_get_optional(dev, "phy-ext"); |
| 339 | if (IS_ERR(priv->clk_ext)) { | 339 | if (IS_ERR(priv->clk_ext)) |
| 340 | if (PTR_ERR(priv->clk_ext) == -ENOENT) | 340 | return PTR_ERR(priv->clk_ext); |
| 341 | priv->clk_ext = NULL; | ||
| 342 | else | ||
| 343 | return PTR_ERR(priv->clk_ext); | ||
| 344 | } | ||
| 345 | 341 | ||
| 346 | priv->rst = devm_reset_control_get_shared(dev, "phy"); | 342 | priv->rst = devm_reset_control_get_shared(dev, "phy"); |
| 347 | if (IS_ERR(priv->rst)) | 343 | if (IS_ERR(priv->rst)) |
| @@ -238,13 +238,9 @@ static int uniphier_u3ssphy_probe(struct platform_device *pdev) · 237 unmodified lines | |||
| 238 | if (IS_ERR(priv->clk)) | 238 | if (IS_ERR(priv->clk)) |
| 239 | return PTR_ERR(priv->clk); | 239 | return PTR_ERR(priv->clk); |
| 240 | 240 | ||
| 241 | priv->clk_ext = devm_clk_get(dev, "phy-ext"); | 241 | priv->clk_ext = devm_clk_get_optional(dev, "phy-ext"); |
| 242 | if (IS_ERR(priv->clk_ext)) { | 242 | if (IS_ERR(priv->clk_ext)) |
| 243 | if (PTR_ERR(priv->clk_ext) == -ENOENT) | 243 | return PTR_ERR(priv->clk_ext); |
| 244 | priv->clk_ext = NULL; | ||
| 245 | else | ||
| 246 | return PTR_ERR(priv->clk_ext); | ||
| 247 | } | ||
| 248 | 244 | ||
| 249 | priv->rst = devm_reset_control_get_shared(dev, "phy"); | 245 | priv->rst = devm_reset_control_get_shared(dev, "phy"); |
| 250 | if (IS_ERR(priv->rst)) | 246 | if (IS_ERR(priv->rst)) |
| @@ -4,3 +4,4 @@ phy-tegra-xusb-y += xusb.o · 3 unmodified lines | |||
| 4 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_124_SOC) += xusb-tegra124.o | 4 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_124_SOC) += xusb-tegra124.o |
| 5 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_132_SOC) += xusb-tegra124.o | 5 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_132_SOC) += xusb-tegra124.o |
| 6 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_210_SOC) += xusb-tegra210.o | 6 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_210_SOC) += xusb-tegra210.o |
| 7 | phy-tegra-xusb-$(CONFIG_ARCH_TEGRA_186_SOC) += xusb-tegra186.o | ||
| @@ -0,0 +1,899 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <linux/delay.h> | ||
| 7 | #include <linux/io.h> | ||
| 8 | #include <linux/module.h> | ||
| 9 | #include <linux/of.h> | ||
| 10 | #include <linux/phy/phy.h> | ||
| 11 | #include <linux/regulator/consumer.h> | ||
| 12 | #include <linux/platform_device.h> | ||
| 13 | #include <linux/clk.h> | ||
| 14 | #include <linux/slab.h> | ||
| 15 | |||
| 16 | #include <soc/tegra/fuse.h> | ||
| 17 | |||
| 18 | #include "xusb.h" | ||
| 19 | |||
| 20 | /* FUSE USB_CALIB registers */ | ||
| 21 | #define HS_CURR_LEVEL_PADX_SHIFT(x) ((x) ? (11 + (x - 1) * 6) : 0) | ||
| 22 | #define HS_CURR_LEVEL_PAD_MASK 0x3f | ||
| 23 | #define HS_TERM_RANGE_ADJ_SHIFT 7 | ||
| 24 | #define HS_TERM_RANGE_ADJ_MASK 0xf | ||
| 25 | #define HS_SQUELCH_SHIFT 29 | ||
| 26 | #define HS_SQUELCH_MASK 0x7 | ||
| 27 | |||
| 28 | #define RPD_CTRL_SHIFT 0 | ||
| 29 | #define RPD_CTRL_MASK 0x1f | ||
| 30 | |||
| 31 | /* XUSB PADCTL registers */ | ||
| 32 | #define XUSB_PADCTL_USB2_PAD_MUX 0x4 | ||
| 33 | #define USB2_PORT_SHIFT(x) ((x) * 2) | ||
| 34 | #define USB2_PORT_MASK 0x3 | ||
| 35 | #define PORT_XUSB 1 | ||
| 36 | #define HSIC_PORT_SHIFT(x) ((x) + 20) | ||
| 37 | #define HSIC_PORT_MASK 0x1 | ||
| 38 | #define PORT_HSIC 0 | ||
| 39 | |||
| 40 | #define XUSB_PADCTL_USB2_PORT_CAP 0x8 | ||
| 41 | #define XUSB_PADCTL_SS_PORT_CAP 0xc | ||
| 42 | #define PORTX_CAP_SHIFT(x) ((x) * 4) | ||
| 43 | #define PORT_CAP_MASK 0x3 | ||
| 44 | #define PORT_CAP_DISABLED 0x0 | ||
| 45 | #define PORT_CAP_HOST 0x1 | ||
| 46 | #define PORT_CAP_DEVICE 0x2 | ||
| 47 | #define PORT_CAP_OTG 0x3 | ||
| 48 | |||
| 49 | #define XUSB_PADCTL_ELPG_PROGRAM 0x20 | ||
| 50 | #define USB2_PORT_WAKE_INTERRUPT_ENABLE(x) BIT(x) | ||
| 51 | #define USB2_PORT_WAKEUP_EVENT(x) BIT((x) + 7) | ||
| 52 | #define SS_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x) + 14) | ||
| 53 | #define SS_PORT_WAKEUP_EVENT(x) BIT((x) + 21) | ||
| 54 | #define USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x) + 28) | ||
| 55 | #define USB2_HSIC_PORT_WAKEUP_EVENT(x) BIT((x) + 30) | ||
| 56 | #define ALL_WAKE_EVENTS \ | ||
| 57 | (USB2_PORT_WAKEUP_EVENT(0) | USB2_PORT_WAKEUP_EVENT(1) | \ | ||
| 58 | USB2_PORT_WAKEUP_EVENT(2) | SS_PORT_WAKEUP_EVENT(0) | \ | ||
| 59 | SS_PORT_WAKEUP_EVENT(1) | SS_PORT_WAKEUP_EVENT(2) | \ | ||
| 60 | USB2_HSIC_PORT_WAKEUP_EVENT(0)) | ||
| 61 | |||
| 62 | #define XUSB_PADCTL_ELPG_PROGRAM_1 0x24 | ||
| 63 | #define SSPX_ELPG_CLAMP_EN(x) BIT(0 + (x) * 3) | ||
| 64 | #define SSPX_ELPG_CLAMP_EN_EARLY(x) BIT(1 + (x) * 3) | ||
| 65 | #define SSPX_ELPG_VCORE_DOWN(x) BIT(2 + (x) * 3) | ||
| 66 | |||
| 67 | #define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x) (0x88 + (x) * 0x40) | ||
| 68 | #define HS_CURR_LEVEL(x) ((x) & 0x3f) | ||
| 69 | #define TERM_SEL BIT(25) | ||
| 70 | #define USB2_OTG_PD BIT(26) | ||
| 71 | #define USB2_OTG_PD2 BIT(27) | ||
| 72 | #define USB2_OTG_PD2_OVRD_EN BIT(28) | ||
| 73 | #define USB2_OTG_PD_ZI BIT(29) | ||
| 74 | |||
| 75 | #define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x) (0x8c + (x) * 0x40) | ||
| 76 | #define USB2_OTG_PD_DR BIT(2) | ||
| 77 | #define TERM_RANGE_ADJ(x) (((x) & 0xf) << 3) | ||
| 78 | #define RPD_CTRL(x) (((x) & 0x1f) << 26) | ||
| 79 | |||
| 80 | #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0 0x284 | ||
| 81 | #define BIAS_PAD_PD BIT(11) | ||
| 82 | #define HS_SQUELCH_LEVEL(x) (((x) & 0x7) << 0) | ||
| 83 | |||
| 84 | #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1 0x288 | ||
| 85 | #define USB2_TRK_START_TIMER(x) (((x) & 0x7f) << 12) | ||
| 86 | #define USB2_TRK_DONE_RESET_TIMER(x) (((x) & 0x7f) << 19) | ||
| 87 | #define USB2_PD_TRK BIT(26) | ||
| 88 | |||
| 89 | #define XUSB_PADCTL_HSIC_PADX_CTL0(x) (0x300 + (x) * 0x20) | ||
| 90 | #define HSIC_PD_TX_DATA0 BIT(1) | ||
| 91 | #define HSIC_PD_TX_STROBE BIT(3) | ||
| 92 | #define HSIC_PD_RX_DATA0 BIT(4) | ||
| 93 | #define HSIC_PD_RX_STROBE BIT(6) | ||
| 94 | #define HSIC_PD_ZI_DATA0 BIT(7) | ||
| 95 | #define HSIC_PD_ZI_STROBE BIT(9) | ||
| 96 | #define HSIC_RPD_DATA0 BIT(13) | ||
| 97 | #define HSIC_RPD_STROBE BIT(15) | ||
| 98 | #define HSIC_RPU_DATA0 BIT(16) | ||
| 99 | #define HSIC_RPU_STROBE BIT(18) | ||
| 100 | |||
| 101 | #define XUSB_PADCTL_HSIC_PAD_TRK_CTL0 0x340 | ||
| 102 | #define HSIC_TRK_START_TIMER(x) (((x) & 0x7f) << 5) | ||
| 103 | #define HSIC_TRK_DONE_RESET_TIMER(x) (((x) & 0x7f) << 12) | ||
| 104 | #define HSIC_PD_TRK BIT(19) | ||
| 105 | |||
| 106 | #define USB2_VBUS_ID 0x360 | ||
| 107 | #define VBUS_OVERRIDE BIT(14) | ||
| 108 | #define ID_OVERRIDE(x) (((x) & 0xf) << 18) | ||
| 109 | #define ID_OVERRIDE_FLOATING ID_OVERRIDE(8) | ||
| 110 | #define ID_OVERRIDE_GROUNDED ID_OVERRIDE(0) | ||
| 111 | |||
| 112 | #define TEGRA186_LANE(_name, _offset, _shift, _mask, _type) \ | ||
| 113 | { \ | ||
| 114 | .name = _name, \ | ||
| 115 | .offset = _offset, \ | ||
| 116 | .shift = _shift, \ | ||
| 117 | .mask = _mask, \ | ||
| 118 | .num_funcs = ARRAY_SIZE(tegra186_##_type##_functions), \ | ||
| 119 | .funcs = tegra186_##_type##_functions, \ | ||
| 120 | } | ||
| 121 | |||
| 122 | struct tegra_xusb_fuse_calibration { | ||
| 123 | u32 *hs_curr_level; | ||
| 124 | u32 hs_squelch; | ||
| 125 | u32 hs_term_range_adj; | ||
| 126 | u32 rpd_ctrl; | ||
| 127 | }; | ||
| 128 | |||
| 129 | struct tegra186_xusb_padctl { | ||
| 130 | struct tegra_xusb_padctl base; | ||
| 131 | |||
| 132 | struct tegra_xusb_fuse_calibration calib; | ||
| 133 | |||
| 134 | /* UTMI bias and tracking */ | ||
| 135 | struct clk *usb2_trk_clk; | ||
| 136 | unsigned int bias_pad_enable; | ||
| 137 | }; | ||
| 138 | |||
| 139 | static inline struct tegra186_xusb_padctl * | ||
| 140 | to_tegra186_xusb_padctl(struct tegra_xusb_padctl *padctl) | ||
| 141 | { | ||
| 142 | return container_of(padctl, struct tegra186_xusb_padctl, base); | ||
| 143 | } | ||
| 144 | |||
| 145 | /* USB 2.0 UTMI PHY support */ | ||
| 146 | static struct tegra_xusb_lane * | ||
| 147 | tegra186_usb2_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np, | ||
| 148 | unsigned int index) | ||
| 149 | { | ||
| 150 | struct tegra_xusb_usb2_lane *usb2; | ||
| 151 | int err; | ||
| 152 | |||
| 153 | usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); | ||
| 154 | if (!usb2) | ||
| 155 | return ERR_PTR(-ENOMEM); | ||
| 156 | |||
| 157 | INIT_LIST_HEAD(&usb2->base.list); | ||
| 158 | usb2->base.soc = &pad->soc->lanes[index]; | ||
| 159 | usb2->base.index = index; | ||
| 160 | usb2->base.pad = pad; | ||
| 161 | usb2->base.np = np; | ||
| 162 | |||
| 163 | err = tegra_xusb_lane_parse_dt(&usb2->base, np); | ||
| 164 | if (err < 0) { | ||
| 165 | kfree(usb2); | ||
| 166 | return ERR_PTR(err); | ||
| 167 | } | ||
| 168 | |||
| 169 | return &usb2->base; | ||
| 170 | } | ||
| 171 | |||
| 172 | static void tegra186_usb2_lane_remove(struct tegra_xusb_lane *lane) | ||
| 173 | { | ||
| 174 | struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane); | ||
| 175 | |||
| 176 | kfree(usb2); | ||
| 177 | } | ||
| 178 | |||
| 179 | static const struct tegra_xusb_lane_ops tegra186_usb2_lane_ops = { | ||
| 180 | .probe = tegra186_usb2_lane_probe, | ||
| 181 | .remove = tegra186_usb2_lane_remove, | ||
| 182 | }; | ||
| 183 | |||
| 184 | static void tegra186_utmi_bias_pad_power_on(struct tegra_xusb_padctl *padctl) | ||
| 185 | { | ||
| 186 | struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl); | ||
| 187 | struct device *dev = padctl->dev; | ||
| 188 | u32 value; | ||
| 189 | int err; | ||
| 190 | |||
| 191 | mutex_lock(&padctl->lock); | ||
| 192 | |||
| 193 | if (priv->bias_pad_enable++ > 0) { | ||
| 194 | mutex_unlock(&padctl->lock); | ||
| 195 | return; | ||
| 196 | } | ||
| 197 | |||
| 198 | err = clk_prepare_enable(priv->usb2_trk_clk); | ||
| 199 | if (err < 0) | ||
| 200 | dev_warn(dev, "failed to enable USB2 trk clock: %d\n", err); | ||
| 201 | |||
| 202 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); | ||
| 203 | value &= ~USB2_TRK_START_TIMER(~0); | ||
| 204 | value |= USB2_TRK_START_TIMER(0x1e); | ||
| 205 | value &= ~USB2_TRK_DONE_RESET_TIMER(~0); | ||
| 206 | value |= USB2_TRK_DONE_RESET_TIMER(0xa); | ||
| 207 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); | ||
| 208 | |||
| 209 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); | ||
| 210 | value &= ~BIAS_PAD_PD; | ||
| 211 | value &= ~HS_SQUELCH_LEVEL(~0); | ||
| 212 | value |= HS_SQUELCH_LEVEL(priv->calib.hs_squelch); | ||
| 213 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); | ||
| 214 | |||
| 215 | udelay(1); | ||
| 216 | |||
| 217 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); | ||
| 218 | value &= ~USB2_PD_TRK; | ||
| 219 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); | ||
| 220 | |||
| 221 | mutex_unlock(&padctl->lock); | ||
| 222 | } | ||
| 223 | |||
| 224 | static void tegra186_utmi_bias_pad_power_off(struct tegra_xusb_padctl *padctl) | ||
| 225 | { | ||
| 226 | struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl); | ||
| 227 | u32 value; | ||
| 228 | |||
| 229 | mutex_lock(&padctl->lock); | ||
| 230 | |||
| 231 | if (WARN_ON(priv->bias_pad_enable == 0)) { | ||
| 232 | mutex_unlock(&padctl->lock); | ||
| 233 | return; | ||
| 234 | } | ||
| 235 | |||
| 236 | if (--priv->bias_pad_enable > 0) { | ||
| 237 | mutex_unlock(&padctl->lock); | ||
| 238 | return; | ||
| 239 | } | ||
| 240 | |||
| 241 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); | ||
| 242 | value |= USB2_PD_TRK; | ||
| 243 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); | ||
| 244 | |||
| 245 | clk_disable_unprepare(priv->usb2_trk_clk); | ||
| 246 | |||
| 247 | mutex_unlock(&padctl->lock); | ||
| 248 | } | ||
| 249 | |||
| 250 | static void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy) | ||
| 251 | { | ||
| 252 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 253 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 254 | struct tegra_xusb_usb2_port *port; | ||
| 255 | struct device *dev = padctl->dev; | ||
| 256 | unsigned int index = lane->index; | ||
| 257 | u32 value; | ||
| 258 | |||
| 259 | if (!phy) | ||
| 260 | return; | ||
| 261 | |||
| 262 | port = tegra_xusb_find_usb2_port(padctl, index); | ||
| 263 | if (!port) { | ||
| 264 | dev_err(dev, "no port found for USB2 lane %u\n", index); | ||
| 265 | return; | ||
| 266 | } | ||
| 267 | |||
| 268 | tegra186_utmi_bias_pad_power_on(padctl); | ||
| 269 | |||
| 270 | udelay(2); | ||
| 271 | |||
| 272 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); | ||
| 273 | value &= ~USB2_OTG_PD; | ||
| 274 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); | ||
| 275 | |||
| 276 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); | ||
| 277 | value &= ~USB2_OTG_PD_DR; | ||
| 278 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); | ||
| 279 | } | ||
| 280 | |||
| 281 | static void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy) | ||
| 282 | { | ||
| 283 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 284 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 285 | unsigned int index = lane->index; | ||
| 286 | u32 value; | ||
| 287 | |||
| 288 | if (!phy) | ||
| 289 | return; | ||
| 290 | |||
| 291 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); | ||
| 292 | value |= USB2_OTG_PD; | ||
| 293 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); | ||
| 294 | |||
| 295 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); | ||
| 296 | value |= USB2_OTG_PD_DR; | ||
| 297 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); | ||
| 298 | |||
| 299 | udelay(2); | ||
| 300 | |||
| 301 | tegra186_utmi_bias_pad_power_off(padctl); | ||
| 302 | } | ||
| 303 | |||
| 304 | static int tegra186_utmi_phy_power_on(struct phy *phy) | ||
| 305 | { | ||
| 306 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 307 | struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane); | ||
| 308 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 309 | struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl); | ||
| 310 | struct tegra_xusb_usb2_port *port; | ||
| 311 | unsigned int index = lane->index; | ||
| 312 | struct device *dev = padctl->dev; | ||
| 313 | u32 value; | ||
| 314 | |||
| 315 | port = tegra_xusb_find_usb2_port(padctl, index); | ||
| 316 | if (!port) { | ||
| 317 | dev_err(dev, "no port found for USB2 lane %u\n", index); | ||
| 318 | return -ENODEV; | ||
| 319 | } | ||
| 320 | |||
| 321 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX); | ||
| 322 | value &= ~(USB2_PORT_MASK << USB2_PORT_SHIFT(index)); | ||
| 323 | value |= (PORT_XUSB << USB2_PORT_SHIFT(index)); | ||
| 324 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX); | ||
| 325 | |||
| 326 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP); | ||
| 327 | value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(index)); | ||
| 328 | |||
| 329 | if (port->mode == USB_DR_MODE_UNKNOWN) | ||
| 330 | value |= (PORT_CAP_DISABLED << PORTX_CAP_SHIFT(index)); | ||
| 331 | else if (port->mode == USB_DR_MODE_PERIPHERAL) | ||
| 332 | value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(index)); | ||
| 333 | else if (port->mode == USB_DR_MODE_HOST) | ||
| 334 | value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(index)); | ||
| 335 | else if (port->mode == USB_DR_MODE_OTG) | ||
| 336 | value |= (PORT_CAP_OTG << PORTX_CAP_SHIFT(index)); | ||
| 337 | |||
| 338 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_PORT_CAP); | ||
| 339 | |||
| 340 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); | ||
| 341 | value &= ~USB2_OTG_PD_ZI; | ||
| 342 | value |= TERM_SEL; | ||
| 343 | value &= ~HS_CURR_LEVEL(~0); | ||
| 344 | |||
| 345 | if (usb2->hs_curr_level_offset) { | ||
| 346 | int hs_current_level; | ||
| 347 | |||
| 348 | hs_current_level = (int)priv->calib.hs_curr_level[index] + | ||
| 349 | usb2->hs_curr_level_offset; | ||
| 350 | |||
| 351 | if (hs_current_level < 0) | ||
| 352 | hs_current_level = 0; | ||
| 353 | if (hs_current_level > 0x3f) | ||
| 354 | hs_current_level = 0x3f; | ||
| 355 | |||
| 356 | value |= HS_CURR_LEVEL(hs_current_level); | ||
| 357 | } else { | ||
| 358 | value |= HS_CURR_LEVEL(priv->calib.hs_curr_level[index]); | ||
| 359 | } | ||
| 360 | |||
| 361 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); | ||
| 362 | |||
| 363 | value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); | ||
| 364 | value &= ~TERM_RANGE_ADJ(~0); | ||
| 365 | value |= TERM_RANGE_ADJ(priv->calib.hs_term_range_adj); | ||
| 366 | value &= ~RPD_CTRL(~0); | ||
| 367 | value |= RPD_CTRL(priv->calib.rpd_ctrl); | ||
| 368 | padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); | ||
| 369 | |||
| 370 | /* TODO: pad power saving */ | ||
| 371 | tegra_phy_xusb_utmi_pad_power_on(phy); | ||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | |||
| 375 | static int tegra186_utmi_phy_power_off(struct phy *phy) | ||
| 376 | { | ||
| 377 | /* TODO: pad power saving */ | ||
| 378 | tegra_phy_xusb_utmi_pad_power_down(phy); | ||
| 379 | |||
| 380 | return 0; | ||
| 381 | } | ||
| 382 | |||
| 383 | static int tegra186_utmi_phy_init(struct phy *phy) | ||
| 384 | { | ||
| 385 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 386 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 387 | struct tegra_xusb_usb2_port *port; | ||
| 388 | unsigned int index = lane->index; | ||
| 389 | struct device *dev = padctl->dev; | ||
| 390 | int err; | ||
| 391 | |||
| 392 | port = tegra_xusb_find_usb2_port(padctl, index); | ||
| 393 | if (!port) { | ||
| 394 | dev_err(dev, "no port found for USB2 lane %u\n", index); | ||
| 395 | return -ENODEV; | ||
| 396 | } | ||
| 397 | |||
| 398 | if (port->supply && port->mode == USB_DR_MODE_HOST) { | ||
| 399 | err = regulator_enable(port->supply); | ||
| 400 | if (err) { | ||
| 401 | dev_err(dev, "failed to enable port %u VBUS: %d\n", | ||
| 402 | index, err); | ||
| 403 | return err; | ||
| 404 | } | ||
| 405 | } | ||
| 406 | |||
| 407 | return 0; | ||
| 408 | } | ||
| 409 | |||
| 410 | static int tegra186_utmi_phy_exit(struct phy *phy) | ||
| 411 | { | ||
| 412 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 413 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 414 | struct tegra_xusb_usb2_port *port; | ||
| 415 | unsigned int index = lane->index; | ||
| 416 | struct device *dev = padctl->dev; | ||
| 417 | int err; | ||
| 418 | |||
| 419 | port = tegra_xusb_find_usb2_port(padctl, index); | ||
| 420 | if (!port) { | ||
| 421 | dev_err(dev, "no port found for USB2 lane %u\n", index); | ||
| 422 | return -ENODEV; | ||
| 423 | } | ||
| 424 | |||
| 425 | if (port->supply && port->mode == USB_DR_MODE_HOST) { | ||
| 426 | err = regulator_disable(port->supply); | ||
| 427 | if (err) { | ||
| 428 | dev_err(dev, "failed to disable port %u VBUS: %d\n", | ||
| 429 | index, err); | ||
| 430 | return err; | ||
| 431 | } | ||
| 432 | } | ||
| 433 | |||
| 434 | return 0; | ||
| 435 | } | ||
| 436 | |||
| 437 | static const struct phy_ops utmi_phy_ops = { | ||
| 438 | .init = tegra186_utmi_phy_init, | ||
| 439 | .exit = tegra186_utmi_phy_exit, | ||
| 440 | .power_on = tegra186_utmi_phy_power_on, | ||
| 441 | .power_off = tegra186_utmi_phy_power_off, | ||
| 442 | .owner = THIS_MODULE, | ||
| 443 | }; | ||
| 444 | |||
| 445 | static struct tegra_xusb_pad * | ||
| 446 | tegra186_usb2_pad_probe(struct tegra_xusb_padctl *padctl, | ||
| 447 | const struct tegra_xusb_pad_soc *soc, | ||
| 448 | struct device_node *np) | ||
| 449 | { | ||
| 450 | struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl); | ||
| 451 | struct tegra_xusb_usb2_pad *usb2; | ||
| 452 | struct tegra_xusb_pad *pad; | ||
| 453 | int err; | ||
| 454 | |||
| 455 | usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); | ||
| 456 | if (!usb2) | ||
| 457 | return ERR_PTR(-ENOMEM); | ||
| 458 | |||
| 459 | pad = &usb2->base; | ||
| 460 | pad->ops = &tegra186_usb2_lane_ops; | ||
| 461 | pad->soc = soc; | ||
| 462 | |||
| 463 | err = tegra_xusb_pad_init(pad, padctl, np); | ||
| 464 | if (err < 0) { | ||
| 465 | kfree(usb2); | ||
| 466 | goto out; | ||
| 467 | } | ||
| 468 | |||
| 469 | priv->usb2_trk_clk = devm_clk_get(&pad->dev, "trk"); | ||
| 470 | if (IS_ERR(priv->usb2_trk_clk)) { | ||
| 471 | err = PTR_ERR(priv->usb2_trk_clk); | ||
| 472 | dev_dbg(&pad->dev, "failed to get usb2 trk clock: %d\n", err); | ||
| 473 | goto unregister; | ||
| 474 | } | ||
| 475 | |||
| 476 | err = tegra_xusb_pad_register(pad, &utmi_phy_ops); | ||
| 477 | if (err < 0) | ||
| 478 | goto unregister; | ||
| 479 | |||
| 480 | dev_set_drvdata(&pad->dev, pad); | ||
| 481 | |||
| 482 | return pad; | ||
| 483 | |||
| 484 | unregister: | ||
| 485 | device_unregister(&pad->dev); | ||
| 486 | out: | ||
| 487 | return ERR_PTR(err); | ||
| 488 | } | ||
| 489 | |||
| 490 | static void tegra186_usb2_pad_remove(struct tegra_xusb_pad *pad) | ||
| 491 | { | ||
| 492 | struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad); | ||
| 493 | |||
| 494 | kfree(usb2); | ||
| 495 | } | ||
| 496 | |||
| 497 | static const struct tegra_xusb_pad_ops tegra186_usb2_pad_ops = { | ||
| 498 | .probe = tegra186_usb2_pad_probe, | ||
| 499 | .remove = tegra186_usb2_pad_remove, | ||
| 500 | }; | ||
| 501 | |||
| 502 | static const char * const tegra186_usb2_functions[] = { | ||
| 503 | "xusb", | ||
| 504 | }; | ||
| 505 | |||
| 506 | static const struct tegra_xusb_lane_soc tegra186_usb2_lanes[] = { | ||
| 507 | TEGRA186_LANE("usb2-0", 0, 0, 0, usb2), | ||
| 508 | TEGRA186_LANE("usb2-1", 0, 0, 0, usb2), | ||
| 509 | TEGRA186_LANE("usb2-2", 0, 0, 0, usb2), | ||
| 510 | }; | ||
| 511 | |||
| 512 | static const struct tegra_xusb_pad_soc tegra186_usb2_pad = { | ||
| 513 | .name = "usb2", | ||
| 514 | .num_lanes = ARRAY_SIZE(tegra186_usb2_lanes), | ||
| 515 | .lanes = tegra186_usb2_lanes, | ||
| 516 | .ops = &tegra186_usb2_pad_ops, | ||
| 517 | }; | ||
| 518 | |||
| 519 | static int tegra186_usb2_port_enable(struct tegra_xusb_port *port) | ||
| 520 | { | ||
| 521 | return 0; | ||
| 522 | } | ||
| 523 | |||
| 524 | static void tegra186_usb2_port_disable(struct tegra_xusb_port *port) | ||
| 525 | { | ||
| 526 | } | ||
| 527 | |||
| 528 | static struct tegra_xusb_lane * | ||
| 529 | tegra186_usb2_port_map(struct tegra_xusb_port *port) | ||
| 530 | { | ||
| 531 | return tegra_xusb_find_lane(port->padctl, "usb2", port->index); | ||
| 532 | } | ||
| 533 | |||
| 534 | static const struct tegra_xusb_port_ops tegra186_usb2_port_ops = { | ||
| 535 | .enable = tegra186_usb2_port_enable, | ||
| 536 | .disable = tegra186_usb2_port_disable, | ||
| 537 | .map = tegra186_usb2_port_map, | ||
| 538 | }; | ||
| 539 | |||
| 540 | /* SuperSpeed PHY support */ | ||
| 541 | static struct tegra_xusb_lane * | ||
| 542 | tegra186_usb3_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np, | ||
| 543 | unsigned int index) | ||
| 544 | { | ||
| 545 | struct tegra_xusb_usb3_lane *usb3; | ||
| 546 | int err; | ||
| 547 | |||
| 548 | usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL); | ||
| 549 | if (!usb3) | ||
| 550 | return ERR_PTR(-ENOMEM); | ||
| 551 | |||
| 552 | INIT_LIST_HEAD(&usb3->base.list); | ||
| 553 | usb3->base.soc = &pad->soc->lanes[index]; | ||
| 554 | usb3->base.index = index; | ||
| 555 | usb3->base.pad = pad; | ||
| 556 | usb3->base.np = np; | ||
| 557 | |||
| 558 | err = tegra_xusb_lane_parse_dt(&usb3->base, np); | ||
| 559 | if (err < 0) { | ||
| 560 | kfree(usb3); | ||
| 561 | return ERR_PTR(err); | ||
| 562 | } | ||
| 563 | |||
| 564 | return &usb3->base; | ||
| 565 | } | ||
| 566 | |||
| 567 | static void tegra186_usb3_lane_remove(struct tegra_xusb_lane *lane) | ||
| 568 | { | ||
| 569 | struct tegra_xusb_usb3_lane *usb3 = to_usb3_lane(lane); | ||
| 570 | |||
| 571 | kfree(usb3); | ||
| 572 | } | ||
| 573 | |||
| 574 | static const struct tegra_xusb_lane_ops tegra186_usb3_lane_ops = { | ||
| 575 | .probe = tegra186_usb3_lane_probe, | ||
| 576 | .remove = tegra186_usb3_lane_remove, | ||
| 577 | }; | ||
| 578 | static int tegra186_usb3_port_enable(struct tegra_xusb_port *port) | ||
| 579 | { | ||
| 580 | return 0; | ||
| 581 | } | ||
| 582 | |||
| 583 | static void tegra186_usb3_port_disable(struct tegra_xusb_port *port) | ||
| 584 | { | ||
| 585 | } | ||
| 586 | |||
| 587 | static struct tegra_xusb_lane * | ||
| 588 | tegra186_usb3_port_map(struct tegra_xusb_port *port) | ||
| 589 | { | ||
| 590 | return tegra_xusb_find_lane(port->padctl, "usb3", port->index); | ||
| 591 | } | ||
| 592 | |||
| 593 | static const struct tegra_xusb_port_ops tegra186_usb3_port_ops = { | ||
| 594 | .enable = tegra186_usb3_port_enable, | ||
| 595 | .disable = tegra186_usb3_port_disable, | ||
| 596 | .map = tegra186_usb3_port_map, | ||
| 597 | }; | ||
| 598 | |||
| 599 | static int tegra186_usb3_phy_power_on(struct phy *phy) | ||
| 600 | { | ||
| 601 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 602 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 603 | struct tegra_xusb_usb3_port *port; | ||
| 604 | struct tegra_xusb_usb2_port *usb2; | ||
| 605 | unsigned int index = lane->index; | ||
| 606 | struct device *dev = padctl->dev; | ||
| 607 | u32 value; | ||
| 608 | |||
| 609 | port = tegra_xusb_find_usb3_port(padctl, index); | ||
| 610 | if (!port) { | ||
| 611 | dev_err(dev, "no port found for USB3 lane %u\n", index); | ||
| 612 | return -ENODEV; | ||
| 613 | } | ||
| 614 | |||
| 615 | usb2 = tegra_xusb_find_usb2_port(padctl, port->port); | ||
| 616 | if (!usb2) { | ||
| 617 | dev_err(dev, "no companion port found for USB3 lane %u\n", | ||
| 618 | index); | ||
| 619 | return -ENODEV; | ||
| 620 | } | ||
| 621 | |||
| 622 | mutex_lock(&padctl->lock); | ||
| 623 | |||
| 624 | value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CAP); | ||
| 625 | value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(index)); | ||
| 626 | |||
| 627 | if (usb2->mode == USB_DR_MODE_UNKNOWN) | ||
| 628 | value |= (PORT_CAP_DISABLED << PORTX_CAP_SHIFT(index)); | ||
| 629 | else if (usb2->mode == USB_DR_MODE_PERIPHERAL) | ||
| 630 | value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(index)); | ||
| 631 | else if (usb2->mode == USB_DR_MODE_HOST) | ||
| 632 | value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(index)); | ||
| 633 | else if (usb2->mode == USB_DR_MODE_OTG) | ||
| 634 | value |= (PORT_CAP_OTG << PORTX_CAP_SHIFT(index)); | ||
| 635 | |||
| 636 | padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_CAP); | ||
| 637 | |||
| 638 | value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 639 | value &= ~SSPX_ELPG_VCORE_DOWN(index); | ||
| 640 | padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 641 | |||
| 642 | usleep_range(100, 200); | ||
| 643 | |||
| 644 | value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 645 | value &= ~SSPX_ELPG_CLAMP_EN_EARLY(index); | ||
| 646 | padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 647 | |||
| 648 | usleep_range(100, 200); | ||
| 649 | |||
| 650 | value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 651 | value &= ~SSPX_ELPG_CLAMP_EN(index); | ||
| 652 | padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 653 | |||
| 654 | mutex_unlock(&padctl->lock); | ||
| 655 | |||
| 656 | return 0; | ||
| 657 | } | ||
| 658 | |||
| 659 | static int tegra186_usb3_phy_power_off(struct phy *phy) | ||
| 660 | { | ||
| 661 | struct tegra_xusb_lane *lane = phy_get_drvdata(phy); | ||
| 662 | struct tegra_xusb_padctl *padctl = lane->pad->padctl; | ||
| 663 | struct tegra_xusb_usb3_port *port; | ||
| 664 | unsigned int index = lane->index; | ||
| 665 | struct device *dev = padctl->dev; | ||
| 666 | u32 value; | ||
| 667 | |||
| 668 | port = tegra_xusb_find_usb3_port(padctl, index); | ||
| 669 | if (!port) { | ||
| 670 | dev_err(dev, "no port found for USB3 lane %u\n", index); | ||
| 671 | return -ENODEV; | ||
| 672 | } | ||
| 673 | |||
| 674 | mutex_lock(&padctl->lock); | ||
| 675 | |||
| 676 | value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 677 | value |= SSPX_ELPG_CLAMP_EN_EARLY(index); | ||
| 678 | padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 679 | |||
| 680 | usleep_range(100, 200); | ||
| 681 | |||
| 682 | value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 683 | value |= SSPX_ELPG_CLAMP_EN(index); | ||
| 684 | padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 685 | |||
| 686 | usleep_range(250, 350); | ||
| 687 | |||
| 688 | value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 689 | value |= SSPX_ELPG_VCORE_DOWN(index); | ||
| 690 | padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1); | ||
| 691 | |||
| 692 | mutex_unlock(&padctl->lock); | ||
| 693 | |||
| 694 | return 0; | ||
| 695 | } | ||
| 696 | |||
| 697 | static int tegra186_usb3_phy_init(struct phy *phy) | ||
| 698 | { | ||
| 699 | return 0; | ||
| 700 | } | ||
| 701 | |||
| 702 | static int tegra186_usb3_phy_exit(struct phy *phy) | ||
| 703 | { | ||
| 704 | return 0; | ||
| 705 | } | ||
| 706 | |||
| 707 | static const struct phy_ops usb3_phy_ops = { | ||
| 708 | .init = tegra186_usb3_phy_init, | ||
| 709 | .exit = tegra186_usb3_phy_exit, | ||
| 710 | .power_on = tegra186_usb3_phy_power_on, | ||
| 711 | .power_off = tegra186_usb3_phy_power_off, | ||
| 712 | .owner = THIS_MODULE, | ||
| 713 | }; | ||
| 714 | |||
| 715 | static struct tegra_xusb_pad * | ||
| 716 | tegra186_usb3_pad_probe(struct tegra_xusb_padctl *padctl, | ||
| 717 | const struct tegra_xusb_pad_soc *soc, | ||
| 718 | struct device_node *np) | ||
| 719 | { | ||
| 720 | struct tegra_xusb_usb3_pad *usb3; | ||
| 721 | struct tegra_xusb_pad *pad; | ||
| 722 | int err; | ||
| 723 | |||
| 724 | usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL); | ||
| 725 | if (!usb3) | ||
| 726 | return ERR_PTR(-ENOMEM); | ||
| 727 | |||
| 728 | pad = &usb3->base; | ||
| 729 | pad->ops = &tegra186_usb3_lane_ops; | ||
| 730 | pad->soc = soc; | ||
| 731 | |||
| 732 | err = tegra_xusb_pad_init(pad, padctl, np); | ||
| 733 | if (err < 0) { | ||
| 734 | kfree(usb3); | ||
| 735 | goto out; | ||
| 736 | } | ||
| 737 | |||
| 738 | err = tegra_xusb_pad_register(pad, &usb3_phy_ops); | ||
| 739 | if (err < 0) | ||
| 740 | goto unregister; | ||
| 741 | |||
| 742 | dev_set_drvdata(&pad->dev, pad); | ||
| 743 | |||
| 744 | return pad; | ||
| 745 | |||
| 746 | unregister: | ||
| 747 | device_unregister(&pad->dev); | ||
| 748 | out: | ||
| 749 | return ERR_PTR(err); | ||
| 750 | } | ||
| 751 | |||
| 752 | static void tegra186_usb3_pad_remove(struct tegra_xusb_pad *pad) | ||
| 753 | { | ||
| 754 | struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad); | ||
| 755 | |||
| 756 | kfree(usb2); | ||
| 757 | } | ||
| 758 | |||
| 759 | static const struct tegra_xusb_pad_ops tegra186_usb3_pad_ops = { | ||
| 760 | .probe = tegra186_usb3_pad_probe, | ||
| 761 | .remove = tegra186_usb3_pad_remove, | ||
| 762 | }; | ||
| 763 | |||
| 764 | static const char * const tegra186_usb3_functions[] = { | ||
| 765 | "xusb", | ||
| 766 | }; | ||
| 767 | |||
| 768 | static const struct tegra_xusb_lane_soc tegra186_usb3_lanes[] = { | ||
| 769 | TEGRA186_LANE("usb3-0", 0, 0, 0, usb3), | ||
| 770 | TEGRA186_LANE("usb3-1", 0, 0, 0, usb3), | ||
| 771 | TEGRA186_LANE("usb3-2", 0, 0, 0, usb3), | ||
| 772 | }; | ||
| 773 | |||
| 774 | static const struct tegra_xusb_pad_soc tegra186_usb3_pad = { | ||
| 775 | .name = "usb3", | ||
| 776 | .num_lanes = ARRAY_SIZE(tegra186_usb3_lanes), | ||
| 777 | .lanes = tegra186_usb3_lanes, | ||
| 778 | .ops = &tegra186_usb3_pad_ops, | ||
| 779 | }; | ||
| 780 | |||
| 781 | static const struct tegra_xusb_pad_soc * const tegra186_pads[] = { | ||
| 782 | &tegra186_usb2_pad, | ||
| 783 | &tegra186_usb3_pad, | ||
| 784 | #if 0 /* TODO implement */ | ||
| 785 | &tegra186_hsic_pad, | ||
| 786 | #endif | ||
| 787 | }; | ||
| 788 | |||
| 789 | static int | ||
| 790 | tegra186_xusb_read_fuse_calibration(struct tegra186_xusb_padctl *padctl) | ||
| 791 | { | ||
| 792 | struct device *dev = padctl->base.dev; | ||
| 793 | unsigned int i, count; | ||
| 794 | u32 value, *level; | ||
| 795 | int err; | ||
| 796 | |||
| 797 | count = padctl->base.soc->ports.usb2.count; | ||
| 798 | |||
| 799 | level = devm_kcalloc(dev, count, sizeof(u32), GFP_KERNEL); | ||
| 800 | if (!level) | ||
| 801 | return -ENOMEM; | ||
| 802 | |||
| 803 | err = tegra_fuse_readl(TEGRA_FUSE_SKU_CALIB_0, &value); | ||
| 804 | if (err) { | ||
| 805 | dev_err(dev, "failed to read calibration fuse: %d\n", err); | ||
| 806 | return err; | ||
| 807 | } | ||
| 808 | |||
| 809 | dev_dbg(dev, "FUSE_USB_CALIB_0 %#x\n", value); | ||
| 810 | |||
| 811 | for (i = 0; i < count; i++) | ||
| 812 | level[i] = (value >> HS_CURR_LEVEL_PADX_SHIFT(i)) & | ||
| 813 | HS_CURR_LEVEL_PAD_MASK; | ||
| 814 | |||
| 815 | padctl->calib.hs_curr_level = level; | ||
| 816 | |||
| 817 | padctl->calib.hs_squelch = (value >> HS_SQUELCH_SHIFT) & | ||
| 818 | HS_SQUELCH_MASK; | ||
| 819 | padctl->calib.hs_term_range_adj = (value >> HS_TERM_RANGE_ADJ_SHIFT) & | ||
| 820 | HS_TERM_RANGE_ADJ_MASK; | ||
| 821 | |||
| 822 | err = tegra_fuse_readl(TEGRA_FUSE_USB_CALIB_EXT_0, &value); | ||
| 823 | if (err) { | ||
| 824 | dev_err(dev, "failed to read calibration fuse: %d\n", err); | ||
| 825 | return err; | ||
| 826 | } | ||
| 827 | |||
| 828 | dev_dbg(dev, "FUSE_USB_CALIB_EXT_0 %#x\n", value); | ||
| 829 | |||
| 830 | padctl->calib.rpd_ctrl = (value >> RPD_CTRL_SHIFT) & RPD_CTRL_MASK; | ||
| 831 | |||
| 832 | return 0; | ||
| 833 | } | ||
| 834 | |||
| 835 | static struct tegra_xusb_padctl * | ||
| 836 | tegra186_xusb_padctl_probe(struct device *dev, | ||
| 837 | const struct tegra_xusb_padctl_soc *soc) | ||
| 838 | { | ||
| 839 | struct tegra186_xusb_padctl *priv; | ||
| 840 | int err; | ||
| 841 | |||
| 842 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 843 | if (!priv) | ||
| 844 | return ERR_PTR(-ENOMEM); | ||
| 845 | |||
| 846 | priv->base.dev = dev; | ||
| 847 | priv->base.soc = soc; | ||
| 848 | |||
| 849 | err = tegra186_xusb_read_fuse_calibration(priv); | ||
| 850 | if (err < 0) | ||
| 851 | return ERR_PTR(err); | ||
| 852 | |||
| 853 | return &priv->base; | ||
| 854 | } | ||
| 855 | |||
| 856 | static void tegra186_xusb_padctl_remove(struct tegra_xusb_padctl *padctl) | ||
| 857 | { | ||
| 858 | } | ||
| 859 | |||
| 860 | static const struct tegra_xusb_padctl_ops tegra186_xusb_padctl_ops = { | ||
| 861 | .probe = tegra186_xusb_padctl_probe, | ||
| 862 | .remove = tegra186_xusb_padctl_remove, | ||
| 863 | }; | ||
| 864 | |||
| 865 | static const char * const tegra186_xusb_padctl_supply_names[] = { | ||
| 866 | "avdd-pll-erefeut", | ||
| 867 | "avdd-usb", | ||
| 868 | "vclamp-usb", | ||
| 869 | "vddio-hsic", | ||
| 870 | }; | ||
| 871 | |||
| 872 | const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc = { | ||
| 873 | .num_pads = ARRAY_SIZE(tegra186_pads), | ||
| 874 | .pads = tegra186_pads, | ||
| 875 | .ports = { | ||
| 876 | .usb2 = { | ||
| 877 | .ops = &tegra186_usb2_port_ops, | ||
| 878 | .count = 3, | ||
| 879 | }, | ||
| 880 | #if 0 /* TODO implement */ | ||
| 881 | .hsic = { | ||
| 882 | .ops = &tegra186_hsic_port_ops, | ||
| 883 | .count = 1, | ||
| 884 | }, | ||
| 885 | #endif | ||
| 886 | .usb3 = { | ||
| 887 | .ops = &tegra186_usb3_port_ops, | ||
| 888 | .count = 3, | ||
| 889 | }, | ||
| 890 | }, | ||
| 891 | .ops = &tegra186_xusb_padctl_ops, | ||
| 892 | .supply_names = tegra186_xusb_padctl_supply_names, | ||
| 893 | .num_supplies = ARRAY_SIZE(tegra186_xusb_padctl_supply_names), | ||
| 894 | }; | ||
| 895 | EXPORT_SYMBOL_GPL(tegra186_xusb_padctl_soc); | ||
| 896 | |||
| 897 | MODULE_AUTHOR("JC Kuo <jckuo@nvidia.com>"); | ||
| 898 | MODULE_DESCRIPTION("NVIDIA Tegra186 XUSB Pad Controller driver"); | ||
| 899 | MODULE_LICENSE("GPL v2"); | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved. | 2 | * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. |
| 3 | * | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, | 5 | * under the terms and conditions of the GNU General Public License, |
| @@ -67,6 +67,12 @@ static const struct of_device_id tegra_xusb_padctl_of_match[] = { · 61 unmodified lines | |||
| 67 | .compatible = "nvidia,tegra210-xusb-padctl", | 67 | .compatible = "nvidia,tegra210-xusb-padctl", |
| 68 | .data = &tegra210_xusb_padctl_soc, | 68 | .data = &tegra210_xusb_padctl_soc, |
| 69 | }, | 69 | }, |
| 70 | #endif | ||
| 71 | #if defined(CONFIG_ARCH_TEGRA_186_SOC) | ||
| 72 | { | ||
| 73 | .compatible = "nvidia,tegra186-xusb-padctl", | ||
| 74 | .data = &tegra186_xusb_padctl_soc, | ||
| 75 | }, | ||
| 70 | #endif | 76 | #endif |
| 71 | { } | 77 | { } |
| 72 | }; | 78 | }; |
| @@ -313,6 +319,10 @@ static void tegra_xusb_lane_program(struct tegra_xusb_lane *lane) · 240 unmodified lines | |||
| 313 | const struct tegra_xusb_lane_soc *soc = lane->soc; | 319 | const struct tegra_xusb_lane_soc *soc = lane->soc; |
| 314 | u32 value; | 320 | u32 value; |
| 315 | 321 | ||
| 322 | /* skip single function lanes */ | ||
| 323 | if (soc->num_funcs < 2) | ||
| 324 | return; | ||
| 325 | |||
| 316 | /* choose function */ | 326 | /* choose function */ |
| 317 | value = padctl_readl(padctl, soc->offset); | 327 | value = padctl_readl(padctl, soc->offset); |
| 318 | value &= ~(soc->mask << soc->shift); | 328 | value &= ~(soc->mask << soc->shift); |
| @@ -542,13 +552,34 @@ static void tegra_xusb_port_unregister(struct tegra_xusb_port *port) · 223 unmodified lines | |||
| 542 | device_unregister(&port->dev); | 552 | device_unregister(&port->dev); |
| 543 | } | 553 | } |
| 544 | 554 | ||
| 555 | static const char *const modes[] = { | ||
| 556 | [USB_DR_MODE_UNKNOWN] = "", | ||
| 557 | [USB_DR_MODE_HOST] = "host", | ||
| 558 | [USB_DR_MODE_PERIPHERAL] = "peripheral", | ||
| 559 | [USB_DR_MODE_OTG] = "otg", | ||
| 560 | }; | ||
| 561 | |||
| 545 | static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) | 562 | static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) |
| 546 | { | 563 | { |
| 547 | struct tegra_xusb_port *port = &usb2->base; | 564 | struct tegra_xusb_port *port = &usb2->base; |
| 548 | struct device_node *np = port->dev.of_node; | 565 | struct device_node *np = port->dev.of_node; |
| 566 | const char *mode; | ||
| 549 | 567 | ||
| 550 | usb2->internal = of_property_read_bool(np, "nvidia,internal"); | 568 | usb2->internal = of_property_read_bool(np, "nvidia,internal"); |
| 551 | 569 | ||
| 570 | if (!of_property_read_string(np, "mode", &mode)) { | ||
| 571 | int err = match_string(modes, ARRAY_SIZE(modes), mode); | ||
| 572 | if (err < 0) { | ||
| 573 | dev_err(&port->dev, "invalid value %s for \"mode\"\n", | ||
| 574 | mode); | ||
| 575 | usb2->mode = USB_DR_MODE_UNKNOWN; | ||
| 576 | } else { | ||
| 577 | usb2->mode = err; | ||
| 578 | } | ||
| 579 | } else { | ||
| 580 | usb2->mode = USB_DR_MODE_HOST; | ||
| 581 | } | ||
| 582 | |||
| 552 | usb2->supply = devm_regulator_get(&port->dev, "vbus"); | 583 | usb2->supply = devm_regulator_get(&port->dev, "vbus"); |
| 553 | return PTR_ERR_OR_ZERO(usb2->supply); | 584 | return PTR_ERR_OR_ZERO(usb2->supply); |
| 554 | } | 585 | } |
| @@ -839,6 +870,7 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev) · 284 unmodified lines | |||
| 839 | struct tegra_xusb_padctl *padctl; | 870 | struct tegra_xusb_padctl *padctl; |
| 840 | const struct of_device_id *match; | 871 | const struct of_device_id *match; |
| 841 | struct resource *res; | 872 | struct resource *res; |
| 873 | unsigned int i; | ||
| 842 | int err; | 874 | int err; |
| 843 | 875 | ||
| 844 | /* for backwards compatibility with old device trees */ | 876 | /* for backwards compatibility with old device trees */ |
| @@ -876,14 +908,38 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev) · 31 unmodified lines | |||
| 876 | goto remove; | 908 | goto remove; |
| 877 | } | 909 | } |
| 878 | 910 | ||
| 911 | padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies, | ||
| 912 | sizeof(*padctl->supplies), GFP_KERNEL); | ||
| 913 | if (!padctl->supplies) { | ||
| 914 | err = -ENOMEM; | ||
| 915 | goto remove; | ||
| 916 | } | ||
| 917 | |||
| 918 | for (i = 0; i < padctl->soc->num_supplies; i++) | ||
| 919 | padctl->supplies[i].supply = padctl->soc->supply_names[i]; | ||
| 920 | |||
| 921 | err = devm_regulator_bulk_get(&pdev->dev, padctl->soc->num_supplies, | ||
| 922 | padctl->supplies); | ||
| 923 | if (err < 0) { | ||
| 924 | dev_err(&pdev->dev, "failed to get regulators: %d\n", err); | ||
| 925 | goto remove; | ||
| 926 | } | ||
| 927 | |||
| 879 | err = reset_control_deassert(padctl->rst); | 928 | err = reset_control_deassert(padctl->rst); |
| 880 | if (err < 0) | 929 | if (err < 0) |
| 881 | goto remove; | 930 | goto remove; |
| 882 | 931 | ||
| 932 | err = regulator_bulk_enable(padctl->soc->num_supplies, | ||
| 933 | padctl->supplies); | ||
| 934 | if (err < 0) { | ||
| 935 | dev_err(&pdev->dev, "failed to enable supplies: %d\n", err); | ||
| 936 | goto reset; | ||
| 937 | } | ||
| 938 | |||
| 883 | err = tegra_xusb_setup_pads(padctl); | 939 | err = tegra_xusb_setup_pads(padctl); |
| 884 | if (err < 0) { | 940 | if (err < 0) { |
| 885 | dev_err(&pdev->dev, "failed to setup pads: %d\n", err); | 941 | dev_err(&pdev->dev, "failed to setup pads: %d\n", err); |
| 886 | goto reset; | 942 | goto power_down; |
| 887 | } | 943 | } |
| 888 | 944 | ||
| 889 | err = tegra_xusb_setup_ports(padctl); | 945 | err = tegra_xusb_setup_ports(padctl); |
| @@ -896,6 +952,8 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev) · 6 unmodified lines | |||
| 896 | 952 | ||
| 897 | remove_pads: | 953 | remove_pads: |
| 898 | tegra_xusb_remove_pads(padctl); | 954 | tegra_xusb_remove_pads(padctl); |
| 955 | power_down: | ||
| 956 | regulator_bulk_disable(padctl->soc->num_supplies, padctl->supplies); | ||
| 899 | reset: | 957 | reset: |
| 900 | reset_control_assert(padctl->rst); | 958 | reset_control_assert(padctl->rst); |
| 901 | remove: | 959 | remove: |
| @@ -911,6 +969,11 @@ static int tegra_xusb_padctl_remove(struct platform_device *pdev) · 9 unmodified lines | |||
| 911 | tegra_xusb_remove_ports(padctl); | 969 | tegra_xusb_remove_ports(padctl); |
| 912 | tegra_xusb_remove_pads(padctl); | 970 | tegra_xusb_remove_pads(padctl); |
| 913 | 971 | ||
| 972 | err = regulator_bulk_disable(padctl->soc->num_supplies, | ||
| 973 | padctl->supplies); | ||
| 974 | if (err < 0) | ||
| 975 | dev_err(&pdev->dev, "failed to disable supplies: %d\n", err); | ||
| 976 | |||
| 914 | err = reset_control_assert(padctl->rst); | 977 | err = reset_control_assert(padctl->rst); |
| 915 | if (err < 0) | 978 | if (err < 0) |
| 916 | dev_err(&pdev->dev, "failed to assert reset: %d\n", err); | 979 | dev_err(&pdev->dev, "failed to assert reset: %d\n", err); |
| @@ -19,6 +19,8 @@ · 18 unmodified lines | |||
| 19 | #include <linux/mutex.h> | 19 | #include <linux/mutex.h> |
| 20 | #include <linux/workqueue.h> | 20 | #include <linux/workqueue.h> |
| 21 | 21 | ||
| 22 | #include <linux/usb/otg.h> | ||
| 23 | |||
| 22 | /* legacy entry points for backwards-compatibility */ | 24 | /* legacy entry points for backwards-compatibility */ |
| 23 | int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev); | 25 | int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev); |
| 24 | int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev); | 26 | int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev); |
| @@ -54,10 +56,21 @@ struct tegra_xusb_lane { · 29 unmodified lines | |||
| 54 | int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane, | 56 | int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane, |
| 55 | struct device_node *np); | 57 | struct device_node *np); |
| 56 | 58 | ||
| 59 | struct tegra_xusb_usb3_lane { | ||
| 60 | struct tegra_xusb_lane base; | ||
| 61 | }; | ||
| 62 | |||
| 63 | static inline struct tegra_xusb_usb3_lane * | ||
| 64 | to_usb3_lane(struct tegra_xusb_lane *lane) | ||
| 65 | { | ||
| 66 | return container_of(lane, struct tegra_xusb_usb3_lane, base); | ||
| 67 | } | ||
| 68 | |||
| 57 | struct tegra_xusb_usb2_lane { | 69 | struct tegra_xusb_usb2_lane { |
| 58 | struct tegra_xusb_lane base; | 70 | struct tegra_xusb_lane base; |
| 59 | 71 | ||
| 60 | u32 hs_curr_level_offset; | 72 | u32 hs_curr_level_offset; |
| 73 | bool powered_on; | ||
| 61 | }; | 74 | }; |
| 62 | 75 | ||
| 63 | static inline struct tegra_xusb_usb2_lane * | 76 | static inline struct tegra_xusb_usb2_lane * |
| @@ -168,6 +181,19 @@ int tegra_xusb_pad_register(struct tegra_xusb_pad *pad, · 104 unmodified lines | |||
| 168 | const struct phy_ops *ops); | 181 | const struct phy_ops *ops); |
| 169 | void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad); | 182 | void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad); |
| 170 | 183 | ||
| 184 | struct tegra_xusb_usb3_pad { | ||
| 185 | struct tegra_xusb_pad base; | ||
| 186 | |||
| 187 | unsigned int enable; | ||
| 188 | struct mutex lock; | ||
| 189 | }; | ||
| 190 | |||
| 191 | static inline struct tegra_xusb_usb3_pad * | ||
| 192 | to_usb3_pad(struct tegra_xusb_pad *pad) | ||
| 193 | { | ||
| 194 | return container_of(pad, struct tegra_xusb_usb3_pad, base); | ||
| 195 | } | ||
| 196 | |||
| 171 | struct tegra_xusb_usb2_pad { | 197 | struct tegra_xusb_usb2_pad { |
| 172 | struct tegra_xusb_pad base; | 198 | struct tegra_xusb_pad base; |
| 173 | 199 | ||
| @@ -271,6 +297,7 @@ struct tegra_xusb_usb2_port { · 97 unmodified lines | |||
| 271 | struct tegra_xusb_port base; | 297 | struct tegra_xusb_port base; |
| 272 | 298 | ||
| 273 | struct regulator *supply; | 299 | struct regulator *supply; |
| 300 | enum usb_dr_mode mode; | ||
| 274 | bool internal; | 301 | bool internal; |
| 275 | }; | 302 | }; |
| 276 | 303 | ||
| @@ -367,6 +394,9 @@ struct tegra_xusb_padctl_soc { · 90 unmodified lines | |||
| 367 | } ports; | 394 | } ports; |
| 368 | 395 | ||
| 369 | const struct tegra_xusb_padctl_ops *ops; | 396 | const struct tegra_xusb_padctl_ops *ops; |
| 397 | |||
| 398 | const char * const *supply_names; | ||
| 399 | unsigned int num_supplies; | ||
| 370 | }; | 400 | }; |
| 371 | 401 | ||
| 372 | struct tegra_xusb_padctl { | 402 | struct tegra_xusb_padctl { |
| @@ -390,6 +420,8 @@ struct tegra_xusb_padctl { · 17 unmodified lines | |||
| 390 | unsigned int enable; | 420 | unsigned int enable; |
| 391 | 421 | ||
| 392 | struct clk *clk; | 422 | struct clk *clk; |
| 423 | |||
| 424 | struct regulator_bulk_data *supplies; | ||
| 393 | }; | 425 | }; |
| 394 | 426 | ||
| 395 | static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value, | 427 | static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value, |
| @@ -417,5 +449,8 @@ extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc; · 21 unmodified lines | |||
| 417 | #if defined(CONFIG_ARCH_TEGRA_210_SOC) | 449 | #if defined(CONFIG_ARCH_TEGRA_210_SOC) |
| 418 | extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc; | 450 | extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc; |
| 419 | #endif | 451 | #endif |
| 452 | #if defined(CONFIG_ARCH_TEGRA_186_SOC) | ||
| 453 | extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc; | ||
| 454 | #endif | ||
| 420 | 455 | ||
| 421 | #endif /* __PHY_TEGRA_XUSB_H */ | 456 | #endif /* __PHY_TEGRA_XUSB_H */ |
| @@ -20,6 +20,18 @@ config PHY_DM816X_USB · 19 unmodified lines | |||
| 20 | help | 20 | help |
| 21 | Enable this for dm816x USB to work. | 21 | Enable this for dm816x USB to work. |
| 22 | 22 | ||
| 23 | config PHY_AM654_SERDES | ||
| 24 | tristate "TI AM654 SERDES support" | ||
| 25 | depends on OF && ARCH_K3 || COMPILE_TEST | ||
| 26 | depends on COMMON_CLK | ||
| 27 | select GENERIC_PHY | ||
| 28 | select MULTIPLEXER | ||
| 29 | select REGMAP_MMIO | ||
| 30 | select MUX_MMIO | ||
| 31 | help | ||
| 32 | This option enables support for TI AM654 SerDes PHY used for | ||
| 33 | PCIe. | ||
| 34 | |||
| 23 | config OMAP_CONTROL_PHY | 35 | config OMAP_CONTROL_PHY |
| 24 | tristate "OMAP CONTROL PHY Driver" | 36 | tristate "OMAP CONTROL PHY Driver" |
| 25 | depends on ARCH_OMAP2PLUS || COMPILE_TEST | 37 | depends on ARCH_OMAP2PLUS || COMPILE_TEST |
| @@ -6,4 +6,5 @@ obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o · 5 unmodified lines | |||
| 6 | obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o | 6 | obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o |
| 7 | obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o | 7 | obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o |
| 8 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o | 8 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o |
| 9 | obj-$(CONFIG_PHY_AM654_SERDES) += phy-am654-serdes.o | ||
| 9 | obj-$(CONFIG_PHY_TI_GMII_SEL) += phy-gmii-sel.o | 10 | obj-$(CONFIG_PHY_TI_GMII_SEL) += phy-gmii-sel.o |
| @@ -0,0 +1,658 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /** | ||
| 3 | * PCIe SERDES driver for AM654x SoC | ||
| 4 | * | ||
| 5 | * Copyright (C) 2018 - 2019 Texas Instruments Incorporated - http://www.ti.com/ | ||
| 6 | * Author: Kishon Vijay Abraham I <kishon@ti.com> | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <dt-bindings/phy/phy.h> | ||
| 10 | #include <linux/clk.h> | ||
| 11 | #include <linux/clk-provider.h> | ||
| 12 | #include <linux/delay.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/mfd/syscon.h> | ||
| 15 | #include <linux/mux/consumer.h> | ||
| 16 | #include <linux/of_address.h> | ||
| 17 | #include <linux/phy/phy.h> | ||
| 18 | #include <linux/platform_device.h> | ||
| 19 | #include <linux/pm_runtime.h> | ||
| 20 | #include <linux/regmap.h> | ||
| 21 | |||
| 22 | #define CMU_R07C 0x7c | ||
| 23 | |||
| 24 | #define COMLANE_R138 0xb38 | ||
| 25 | #define VERSION 0x70 | ||
| 26 | |||
| 27 | #define COMLANE_R190 0xb90 | ||
| 28 | |||
| 29 | #define COMLANE_R194 0xb94 | ||
| 30 | |||
| 31 | #define SERDES_CTRL 0x1fd0 | ||
| 32 | |||
| 33 | #define WIZ_LANEXCTL_STS 0x1fe0 | ||
| 34 | #define TX0_DISABLE_STATE 0x4 | ||
| 35 | #define TX0_SLEEP_STATE 0x5 | ||
| 36 | #define TX0_SNOOZE_STATE 0x6 | ||
| 37 | #define TX0_ENABLE_STATE 0x7 | ||
| 38 | |||
| 39 | #define RX0_DISABLE_STATE 0x4 | ||
| 40 | #define RX0_SLEEP_STATE 0x5 | ||
| 41 | #define RX0_SNOOZE_STATE 0x6 | ||
| 42 | #define RX0_ENABLE_STATE 0x7 | ||
| 43 | |||
| 44 | #define WIZ_PLL_CTRL 0x1ff4 | ||
| 45 | #define PLL_DISABLE_STATE 0x4 | ||
| 46 | #define PLL_SLEEP_STATE 0x5 | ||
| 47 | #define PLL_SNOOZE_STATE 0x6 | ||
| 48 | #define PLL_ENABLE_STATE 0x7 | ||
| 49 | |||
| 50 | #define PLL_LOCK_TIME 100000 /* in microseconds */ | ||
| 51 | #define SLEEP_TIME 100 /* in microseconds */ | ||
| 52 | |||
| 53 | #define LANE_USB3 0x0 | ||
| 54 | #define LANE_PCIE0_LANE0 0x1 | ||
| 55 | |||
| 56 | #define LANE_PCIE1_LANE0 0x0 | ||
| 57 | #define LANE_PCIE0_LANE1 0x1 | ||
| 58 | |||
| 59 | #define SERDES_NUM_CLOCKS 3 | ||
| 60 | |||
| 61 | #define AM654_SERDES_CTRL_CLKSEL_MASK GENMASK(7, 4) | ||
| 62 | #define AM654_SERDES_CTRL_CLKSEL_SHIFT 4 | ||
| 63 | |||
| 64 | struct serdes_am654_clk_mux { | ||
| 65 | struct clk_hw hw; | ||
| 66 | struct regmap *regmap; | ||
| 67 | unsigned int reg; | ||
| 68 | int clk_id; | ||
| 69 | struct clk_init_data clk_data; | ||
| 70 | }; | ||
| 71 | |||
| 72 | #define to_serdes_am654_clk_mux(_hw) \ | ||
| 73 | container_of(_hw, struct serdes_am654_clk_mux, hw) | ||
| 74 | |||
| 75 | static struct regmap_config serdes_am654_regmap_config = { | ||
| 76 | .reg_bits = 32, | ||
| 77 | .val_bits = 32, | ||
| 78 | .reg_stride = 4, | ||
| 79 | .fast_io = true, | ||
| 80 | }; | ||
| 81 | |||
| 82 | static const struct reg_field cmu_master_cdn_o = REG_FIELD(CMU_R07C, 24, 24); | ||
| 83 | static const struct reg_field config_version = REG_FIELD(COMLANE_R138, 16, 23); | ||
| 84 | static const struct reg_field l1_master_cdn_o = REG_FIELD(COMLANE_R190, 9, 9); | ||
| 85 | static const struct reg_field cmu_ok_i_0 = REG_FIELD(COMLANE_R194, 19, 19); | ||
| 86 | static const struct reg_field por_en = REG_FIELD(SERDES_CTRL, 29, 29); | ||
| 87 | static const struct reg_field tx0_enable = REG_FIELD(WIZ_LANEXCTL_STS, 29, 31); | ||
| 88 | static const struct reg_field rx0_enable = REG_FIELD(WIZ_LANEXCTL_STS, 13, 15); | ||
| 89 | static const struct reg_field pll_enable = REG_FIELD(WIZ_PLL_CTRL, 29, 31); | ||
| 90 | static const struct reg_field pll_ok = REG_FIELD(WIZ_PLL_CTRL, 28, 28); | ||
| 91 | |||
| 92 | struct serdes_am654 { | ||
| 93 | struct regmap *regmap; | ||
| 94 | struct regmap_field *cmu_master_cdn_o; | ||
| 95 | struct regmap_field *config_version; | ||
| 96 | struct regmap_field *l1_master_cdn_o; | ||
| 97 | struct regmap_field *cmu_ok_i_0; | ||
| 98 | struct regmap_field *por_en; | ||
| 99 | struct regmap_field *tx0_enable; | ||
| 100 | struct regmap_field *rx0_enable; | ||
| 101 | struct regmap_field *pll_enable; | ||
| 102 | struct regmap_field *pll_ok; | ||
| 103 | |||
| 104 | struct device *dev; | ||
| 105 | struct mux_control *control; | ||
| 106 | bool busy; | ||
| 107 | u32 type; | ||
| 108 | struct device_node *of_node; | ||
| 109 | struct clk_onecell_data clk_data; | ||
| 110 | struct clk *clks[SERDES_NUM_CLOCKS]; | ||
| 111 | }; | ||
| 112 | |||
| 113 | static int serdes_am654_enable_pll(struct serdes_am654 *phy) | ||
| 114 | { | ||
| 115 | int ret; | ||
| 116 | u32 val; | ||
| 117 | |||
| 118 | ret = regmap_field_write(phy->pll_enable, PLL_ENABLE_STATE); | ||
| 119 | if (ret) | ||
| 120 | return ret; | ||
| 121 | |||
| 122 | return regmap_field_read_poll_timeout(phy->pll_ok, val, val, 1000, | ||
| 123 | PLL_LOCK_TIME); | ||
| 124 | } | ||
| 125 | |||
| 126 | static void serdes_am654_disable_pll(struct serdes_am654 *phy) | ||
| 127 | { | ||
| 128 | struct device *dev = phy->dev; | ||
| 129 | int ret; | ||
| 130 | |||
| 131 | ret = regmap_field_write(phy->pll_enable, PLL_DISABLE_STATE); | ||
| 132 | if (ret) | ||
| 133 | dev_err(dev, "Failed to disable PLL\n"); | ||
| 134 | } | ||
| 135 | |||
| 136 | static int serdes_am654_enable_txrx(struct serdes_am654 *phy) | ||
| 137 | { | ||
| 138 | int ret; | ||
| 139 | |||
| 140 | /* Enable TX */ | ||
| 141 | ret = regmap_field_write(phy->tx0_enable, TX0_ENABLE_STATE); | ||
| 142 | if (ret) | ||
| 143 | return ret; | ||
| 144 | |||
| 145 | /* Enable RX */ | ||
| 146 | ret = regmap_field_write(phy->rx0_enable, RX0_ENABLE_STATE); | ||
| 147 | if (ret) | ||
| 148 | return ret; | ||
| 149 | |||
| 150 | return 0; | ||
| 151 | } | ||
| 152 | |||
| 153 | static int serdes_am654_disable_txrx(struct serdes_am654 *phy) | ||
| 154 | { | ||
| 155 | int ret; | ||
| 156 | |||
| 157 | /* Disable TX */ | ||
| 158 | ret = regmap_field_write(phy->tx0_enable, TX0_DISABLE_STATE); | ||
| 159 | if (ret) | ||
| 160 | return ret; | ||
| 161 | |||
| 162 | /* Disable RX */ | ||
| 163 | ret = regmap_field_write(phy->rx0_enable, RX0_DISABLE_STATE); | ||
| 164 | if (ret) | ||
| 165 | return ret; | ||
| 166 | |||
| 167 | return 0; | ||
| 168 | } | ||
| 169 | |||
| 170 | static int serdes_am654_power_on(struct phy *x) | ||
| 171 | { | ||
| 172 | struct serdes_am654 *phy = phy_get_drvdata(x); | ||
| 173 | struct device *dev = phy->dev; | ||
| 174 | int ret; | ||
| 175 | u32 val; | ||
| 176 | |||
| 177 | ret = serdes_am654_enable_pll(phy); | ||
| 178 | if (ret) { | ||
| 179 | dev_err(dev, "Failed to enable PLL\n"); | ||
| 180 | return ret; | ||
| 181 | } | ||
| 182 | |||
| 183 | ret = serdes_am654_enable_txrx(phy); | ||
| 184 | if (ret) { | ||
| 185 | dev_err(dev, "Failed to enable TX RX\n"); | ||
| 186 | return ret; | ||
| 187 | } | ||
| 188 | |||
| 189 | return regmap_field_read_poll_timeout(phy->cmu_ok_i_0, val, val, | ||
| 190 | SLEEP_TIME, PLL_LOCK_TIME); | ||
| 191 | } | ||
| 192 | |||
| 193 | static int serdes_am654_power_off(struct phy *x) | ||
| 194 | { | ||
| 195 | struct serdes_am654 *phy = phy_get_drvdata(x); | ||
| 196 | |||
| 197 | serdes_am654_disable_txrx(phy); | ||
| 198 | serdes_am654_disable_pll(phy); | ||
| 199 | |||
| 200 | return 0; | ||
| 201 | } | ||
| 202 | |||
| 203 | static int serdes_am654_init(struct phy *x) | ||
| 204 | { | ||
| 205 | struct serdes_am654 *phy = phy_get_drvdata(x); | ||
| 206 | int ret; | ||
| 207 | |||
| 208 | ret = regmap_field_write(phy->config_version, VERSION); | ||
| 209 | if (ret) | ||
| 210 | return ret; | ||
| 211 | |||
| 212 | ret = regmap_field_write(phy->cmu_master_cdn_o, 0x1); | ||
| 213 | if (ret) | ||
| 214 | return ret; | ||
| 215 | |||
| 216 | ret = regmap_field_write(phy->l1_master_cdn_o, 0x1); | ||
| 217 | if (ret) | ||
| 218 | return ret; | ||
| 219 | |||
| 220 | return 0; | ||
| 221 | } | ||
| 222 | |||
| 223 | static int serdes_am654_reset(struct phy *x) | ||
| 224 | { | ||
| 225 | struct serdes_am654 *phy = phy_get_drvdata(x); | ||
| 226 | int ret; | ||
| 227 | |||
| 228 | ret = regmap_field_write(phy->por_en, 0x1); | ||
| 229 | if (ret) | ||
| 230 | return ret; | ||
| 231 | |||
| 232 | mdelay(1); | ||
| 233 | |||
| 234 | ret = regmap_field_write(phy->por_en, 0x0); | ||
| 235 | if (ret) | ||
| 236 | return ret; | ||
| 237 | |||
| 238 | return 0; | ||
| 239 | } | ||
| 240 | |||
| 241 | static void serdes_am654_release(struct phy *x) | ||
| 242 | { | ||
| 243 | struct serdes_am654 *phy = phy_get_drvdata(x); | ||
| 244 | |||
| 245 | phy->type = PHY_NONE; | ||
| 246 | phy->busy = false; | ||
| 247 | mux_control_deselect(phy->control); | ||
| 248 | } | ||
| 249 | |||
| 250 | struct phy *serdes_am654_xlate(struct device *dev, struct of_phandle_args | ||
| 251 | *args) | ||
| 252 | { | ||
| 253 | struct serdes_am654 *am654_phy; | ||
| 254 | struct phy *phy; | ||
| 255 | int ret; | ||
| 256 | |||
| 257 | phy = of_phy_simple_xlate(dev, args); | ||
| 258 | if (IS_ERR(phy)) | ||
| 259 | return phy; | ||
| 260 | |||
| 261 | am654_phy = phy_get_drvdata(phy); | ||
| 262 | if (am654_phy->busy) | ||
| 263 | return ERR_PTR(-EBUSY); | ||
| 264 | |||
| 265 | ret = mux_control_select(am654_phy->control, args->args[1]); | ||
| 266 | if (ret) { | ||
| 267 | dev_err(dev, "Failed to select SERDES Lane Function\n"); | ||
| 268 | return ERR_PTR(ret); | ||
| 269 | } | ||
| 270 | |||
| 271 | am654_phy->busy = true; | ||
| 272 | am654_phy->type = args->args[0]; | ||
| 273 | |||
| 274 | return phy; | ||
| 275 | } | ||
| 276 | |||
| 277 | static const struct phy_ops ops = { | ||
| 278 | .reset = serdes_am654_reset, | ||
| 279 | .init = serdes_am654_init, | ||
| 280 | .power_on = serdes_am654_power_on, | ||
| 281 | .power_off = serdes_am654_power_off, | ||
| 282 | .release = serdes_am654_release, | ||
| 283 | .owner = THIS_MODULE, | ||
| 284 | }; | ||
| 285 | |||
| 286 | #define SERDES_NUM_MUX_COMBINATIONS 16 | ||
| 287 | |||
| 288 | #define LICLK 0 | ||
| 289 | #define EXT_REFCLK 1 | ||
| 290 | #define RICLK 2 | ||
| 291 | |||
| 292 | static const int | ||
| 293 | serdes_am654_mux_table[SERDES_NUM_MUX_COMBINATIONS][SERDES_NUM_CLOCKS] = { | ||
| 294 | /* | ||
| 295 | * Each combination maps to one of | ||
| 296 | * "Figure 12-1986. SerDes Reference Clock Distribution" | ||
| 297 | * in TRM. | ||
| 298 | */ | ||
| 299 | /* Parent of CMU refclk, Left output, Right output | ||
| 300 | * either of EXT_REFCLK, LICLK, RICLK | ||
| 301 | */ | ||
| 302 | { EXT_REFCLK, EXT_REFCLK, EXT_REFCLK }, /* 0000 */ | ||
| 303 | { RICLK, EXT_REFCLK, EXT_REFCLK }, /* 0001 */ | ||
| 304 | { EXT_REFCLK, RICLK, LICLK }, /* 0010 */ | ||
| 305 | { RICLK, RICLK, EXT_REFCLK }, /* 0011 */ | ||
| 306 | { LICLK, EXT_REFCLK, EXT_REFCLK }, /* 0100 */ | ||
| 307 | { EXT_REFCLK, EXT_REFCLK, EXT_REFCLK }, /* 0101 */ | ||
| 308 | { LICLK, RICLK, LICLK }, /* 0110 */ | ||
| 309 | { EXT_REFCLK, RICLK, LICLK }, /* 0111 */ | ||
| 310 | { EXT_REFCLK, EXT_REFCLK, LICLK }, /* 1000 */ | ||
| 311 | { RICLK, EXT_REFCLK, LICLK }, /* 1001 */ | ||
| 312 | { EXT_REFCLK, RICLK, EXT_REFCLK }, /* 1010 */ | ||
| 313 | { RICLK, RICLK, EXT_REFCLK }, /* 1011 */ | ||
| 314 | { LICLK, EXT_REFCLK, LICLK }, /* 1100 */ | ||
| 315 | { EXT_REFCLK, EXT_REFCLK, LICLK }, /* 1101 */ | ||
| 316 | { LICLK, RICLK, EXT_REFCLK }, /* 1110 */ | ||
| 317 | { EXT_REFCLK, RICLK, EXT_REFCLK }, /* 1111 */ | ||
| 318 | }; | ||
| 319 | |||
| 320 | static u8 serdes_am654_clk_mux_get_parent(struct clk_hw *hw) | ||
| 321 | { | ||
| 322 | struct serdes_am654_clk_mux *mux = to_serdes_am654_clk_mux(hw); | ||
| 323 | struct regmap *regmap = mux->regmap; | ||
| 324 | unsigned int reg = mux->reg; | ||
| 325 | unsigned int val; | ||
| 326 | |||
| 327 | regmap_read(regmap, reg, &val); | ||
| 328 | val &= AM654_SERDES_CTRL_CLKSEL_MASK; | ||
| 329 | val >>= AM654_SERDES_CTRL_CLKSEL_SHIFT; | ||
| 330 | |||
| 331 | return serdes_am654_mux_table[val][mux->clk_id]; | ||
| 332 | } | ||
| 333 | |||
| 334 | static int serdes_am654_clk_mux_set_parent(struct clk_hw *hw, u8 index) | ||
| 335 | { | ||
| 336 | struct serdes_am654_clk_mux *mux = to_serdes_am654_clk_mux(hw); | ||
| 337 | struct regmap *regmap = mux->regmap; | ||
| 338 | unsigned int reg = mux->reg; | ||
| 339 | int clk_id = mux->clk_id; | ||
| 340 | int parents[SERDES_NUM_CLOCKS]; | ||
| 341 | const int *p; | ||
| 342 | u32 val; | ||
| 343 | int found, i; | ||
| 344 | int ret; | ||
| 345 | |||
| 346 | /* get existing setting */ | ||
| 347 | regmap_read(regmap, reg, &val); | ||
| 348 | val &= AM654_SERDES_CTRL_CLKSEL_MASK; | ||
| 349 | val >>= AM654_SERDES_CTRL_CLKSEL_SHIFT; | ||
| 350 | |||
| 351 | for (i = 0; i < SERDES_NUM_CLOCKS; i++) | ||
| 352 | parents[i] = serdes_am654_mux_table[val][i]; | ||
| 353 | |||
| 354 | /* change parent of this clock. others left intact */ | ||
| 355 | parents[clk_id] = index; | ||
| 356 | |||
| 357 | /* Find the match */ | ||
| 358 | for (val = 0; val < SERDES_NUM_MUX_COMBINATIONS; val++) { | ||
| 359 | p = serdes_am654_mux_table[val]; | ||
| 360 | found = 1; | ||
| 361 | for (i = 0; i < SERDES_NUM_CLOCKS; i++) { | ||
| 362 | if (parents[i] != p[i]) { | ||
| 363 | found = 0; | ||
| 364 | break; | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 368 | if (found) | ||
| 369 | break; | ||
| 370 | } | ||
| 371 | |||
| 372 | if (!found) { | ||
| 373 | /* | ||
| 374 | * This can never happen, unless we missed | ||
| 375 | * a valid combination in serdes_am654_mux_table. | ||
| 376 | */ | ||
| 377 | WARN(1, "Failed to find the parent of %s clock\n", | ||
| 378 | hw->init->name); | ||
| 379 | return -EINVAL; | ||
| 380 | } | ||
| 381 | |||
| 382 | val <<= AM654_SERDES_CTRL_CLKSEL_SHIFT; | ||
| 383 | ret = regmap_update_bits(regmap, reg, AM654_SERDES_CTRL_CLKSEL_MASK, | ||
| 384 | val); | ||
| 385 | |||
| 386 | return ret; | ||
| 387 | } | ||
| 388 | |||
| 389 | static const struct clk_ops serdes_am654_clk_mux_ops = { | ||
| 390 | .set_parent = serdes_am654_clk_mux_set_parent, | ||
| 391 | .get_parent = serdes_am654_clk_mux_get_parent, | ||
| 392 | }; | ||
| 393 | |||
| 394 | static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, | ||
| 395 | const char *clock_name, int clock_num) | ||
| 396 | { | ||
| 397 | struct device_node *node = am654_phy->of_node; | ||
| 398 | struct device *dev = am654_phy->dev; | ||
| 399 | struct serdes_am654_clk_mux *mux; | ||
| 400 | struct device_node *regmap_node; | ||
| 401 | const char **parent_names; | ||
| 402 | struct clk_init_data *init; | ||
| 403 | unsigned int num_parents; | ||
| 404 | struct regmap *regmap; | ||
| 405 | const __be32 *addr; | ||
| 406 | unsigned int reg; | ||
| 407 | struct clk *clk; | ||
| 408 | |||
| 409 | mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); | ||
| 410 | if (!mux) | ||
| 411 | return -ENOMEM; | ||
| 412 | |||
| 413 | init = &mux->clk_data; | ||
| 414 | |||
| 415 | regmap_node = of_parse_phandle(node, "ti,serdes-clk", 0); | ||
| 416 | of_node_put(regmap_node); | ||
| 417 | if (!regmap_node) { | ||
| 418 | dev_err(dev, "Fail to get serdes-clk node\n"); | ||
| 419 | return -ENODEV; | ||
| 420 | } | ||
| 421 | |||
| 422 | regmap = syscon_node_to_regmap(regmap_node->parent); | ||
| 423 | if (IS_ERR(regmap)) { | ||
| 424 | dev_err(dev, "Fail to get Syscon regmap\n"); | ||
| 425 | return PTR_ERR(regmap); | ||
| 426 | } | ||
| 427 | |||
| 428 | num_parents = of_clk_get_parent_count(node); | ||
| 429 | if (num_parents < 2) { | ||
| 430 | dev_err(dev, "SERDES clock must have parents\n"); | ||
| 431 | return -EINVAL; | ||
| 432 | } | ||
| 433 | |||
| 434 | parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), | ||
| 435 | GFP_KERNEL); | ||
| 436 | if (!parent_names) | ||
| 437 | return -ENOMEM; | ||
| 438 | |||
| 439 | of_clk_parent_fill(node, parent_names, num_parents); | ||
| 440 | |||
| 441 | addr = of_get_address(regmap_node, 0, NULL, NULL); | ||
| 442 | if (!addr) | ||
| 443 | return -EINVAL; | ||
| 444 | |||
| 445 | reg = be32_to_cpu(*addr); | ||
| 446 | |||
| 447 | init->ops = &serdes_am654_clk_mux_ops; | ||
| 448 | init->flags = CLK_SET_RATE_NO_REPARENT; | ||
| 449 | init->parent_names = parent_names; | ||
| 450 | init->num_parents = num_parents; | ||
| 451 | init->name = clock_name; | ||
| 452 | |||
| 453 | mux->regmap = regmap; | ||
| 454 | mux->reg = reg; | ||
| 455 | mux->clk_id = clock_num; | ||
| 456 | mux->hw.init = init; | ||
| 457 | |||
| 458 | clk = devm_clk_register(dev, &mux->hw); | ||
| 459 | if (IS_ERR(clk)) | ||
| 460 | return PTR_ERR(clk); | ||
| 461 | |||
| 462 | am654_phy->clks[clock_num] = clk; | ||
| 463 | |||
| 464 | return 0; | ||
| 465 | } | ||
| 466 | |||
| 467 | static const struct of_device_id serdes_am654_id_table[] = { | ||
| 468 | { | ||
| 469 | .compatible = "ti,phy-am654-serdes", | ||
| 470 | }, | ||
| 471 | {} | ||
| 472 | }; | ||
| 473 | MODULE_DEVICE_TABLE(of, serdes_am654_id_table); | ||
| 474 | |||
| 475 | static int serdes_am654_regfield_init(struct serdes_am654 *am654_phy) | ||
| 476 | { | ||
| 477 | struct regmap *regmap = am654_phy->regmap; | ||
| 478 | struct device *dev = am654_phy->dev; | ||
| 479 | |||
| 480 | am654_phy->cmu_master_cdn_o = devm_regmap_field_alloc(dev, regmap, | ||
| 481 | cmu_master_cdn_o); | ||
| 482 | if (IS_ERR(am654_phy->cmu_master_cdn_o)) { | ||
| 483 | dev_err(dev, "CMU_MASTER_CDN_O reg field init failed\n"); | ||
| 484 | return PTR_ERR(am654_phy->cmu_master_cdn_o); | ||
| 485 | } | ||
| 486 | |||
| 487 | am654_phy->config_version = devm_regmap_field_alloc(dev, regmap, | ||
| 488 | config_version); | ||
| 489 | if (IS_ERR(am654_phy->config_version)) { | ||
| 490 | dev_err(dev, "CONFIG_VERSION reg field init failed\n"); | ||
| 491 | return PTR_ERR(am654_phy->config_version); | ||
| 492 | } | ||
| 493 | |||
| 494 | am654_phy->l1_master_cdn_o = devm_regmap_field_alloc(dev, regmap, | ||
| 495 | l1_master_cdn_o); | ||
| 496 | if (IS_ERR(am654_phy->l1_master_cdn_o)) { | ||
| 497 | dev_err(dev, "L1_MASTER_CDN_O reg field init failed\n"); | ||
| 498 | return PTR_ERR(am654_phy->l1_master_cdn_o); | ||
| 499 | } | ||
| 500 | |||
| 501 | am654_phy->cmu_ok_i_0 = devm_regmap_field_alloc(dev, regmap, | ||
| 502 | cmu_ok_i_0); | ||
| 503 | if (IS_ERR(am654_phy->cmu_ok_i_0)) { | ||
| 504 | dev_err(dev, "CMU_OK_I_0 reg field init failed\n"); | ||
| 505 | return PTR_ERR(am654_phy->cmu_ok_i_0); | ||
| 506 | } | ||
| 507 | |||
| 508 | am654_phy->por_en = devm_regmap_field_alloc(dev, regmap, por_en); | ||
| 509 | if (IS_ERR(am654_phy->por_en)) { | ||
| 510 | dev_err(dev, "POR_EN reg field init failed\n"); | ||
| 511 | return PTR_ERR(am654_phy->por_en); | ||
| 512 | } | ||
| 513 | |||
| 514 | am654_phy->tx0_enable = devm_regmap_field_alloc(dev, regmap, | ||
| 515 | tx0_enable); | ||
| 516 | if (IS_ERR(am654_phy->tx0_enable)) { | ||
| 517 | dev_err(dev, "TX0_ENABLE reg field init failed\n"); | ||
| 518 | return PTR_ERR(am654_phy->tx0_enable); | ||
| 519 | } | ||
| 520 | |||
| 521 | am654_phy->rx0_enable = devm_regmap_field_alloc(dev, regmap, | ||
| 522 | rx0_enable); | ||
| 523 | if (IS_ERR(am654_phy->rx0_enable)) { | ||
| 524 | dev_err(dev, "RX0_ENABLE reg field init failed\n"); | ||
| 525 | return PTR_ERR(am654_phy->rx0_enable); | ||
| 526 | } | ||
| 527 | |||
| 528 | am654_phy->pll_enable = devm_regmap_field_alloc(dev, regmap, | ||
| 529 | pll_enable); | ||
| 530 | if (IS_ERR(am654_phy->pll_enable)) { | ||
| 531 | dev_err(dev, "PLL_ENABLE reg field init failed\n"); | ||
| 532 | return PTR_ERR(am654_phy->pll_enable); | ||
| 533 | } | ||
| 534 | |||
| 535 | am654_phy->pll_ok = devm_regmap_field_alloc(dev, regmap, pll_ok); | ||
| 536 | if (IS_ERR(am654_phy->pll_ok)) { | ||
| 537 | dev_err(dev, "PLL_OK reg field init failed\n"); | ||
| 538 | return PTR_ERR(am654_phy->pll_ok); | ||
| 539 | } | ||
| 540 | |||
| 541 | return 0; | ||
| 542 | } | ||
| 543 | |||
| 544 | static int serdes_am654_probe(struct platform_device *pdev) | ||
| 545 | { | ||
| 546 | struct phy_provider *phy_provider; | ||
| 547 | struct device *dev = &pdev->dev; | ||
| 548 | struct device_node *node = dev->of_node; | ||
| 549 | struct clk_onecell_data *clk_data; | ||
| 550 | struct serdes_am654 *am654_phy; | ||
| 551 | struct mux_control *control; | ||
| 552 | const char *clock_name; | ||
| 553 | struct regmap *regmap; | ||
| 554 | void __iomem *base; | ||
| 555 | struct phy *phy; | ||
| 556 | int ret; | ||
| 557 | int i; | ||
| 558 | |||
| 559 | am654_phy = devm_kzalloc(dev, sizeof(*am654_phy), GFP_KERNEL); | ||
| 560 | if (!am654_phy) | ||
| 561 | return -ENOMEM; | ||
| 562 | |||
| 563 | base = devm_platform_ioremap_resource(pdev, 0); | ||
| 564 | if (IS_ERR(base)) | ||
| 565 | return PTR_ERR(base); | ||
| 566 | |||
| 567 | regmap = devm_regmap_init_mmio(dev, base, &serdes_am654_regmap_config); | ||
| 568 | if (IS_ERR(regmap)) { | ||
| 569 | dev_err(dev, "Failed to initialize regmap\n"); | ||
| 570 | return PTR_ERR(regmap); | ||
| 571 | } | ||
| 572 | |||
| 573 | control = devm_mux_control_get(dev, NULL); | ||
| 574 | if (IS_ERR(control)) | ||
| 575 | return PTR_ERR(control); | ||
| 576 | |||
| 577 | am654_phy->dev = dev; | ||
| 578 | am654_phy->of_node = node; | ||
| 579 | am654_phy->regmap = regmap; | ||
| 580 | am654_phy->control = control; | ||
| 581 | am654_phy->type = PHY_NONE; | ||
| 582 | |||
| 583 | ret = serdes_am654_regfield_init(am654_phy); | ||
| 584 | if (ret) { | ||
| 585 | dev_err(dev, "Failed to initialize regfields\n"); | ||
| 586 | return ret; | ||
| 587 | } | ||
| 588 | |||
| 589 | platform_set_drvdata(pdev, am654_phy); | ||
| 590 | |||
| 591 | for (i = 0; i < SERDES_NUM_CLOCKS; i++) { | ||
| 592 | ret = of_property_read_string_index(node, "clock-output-names", | ||
| 593 | i, &clock_name); | ||
| 594 | if (ret) { | ||
| 595 | dev_err(dev, "Failed to get clock name\n"); | ||
| 596 | return ret; | ||
| 597 | } | ||
| 598 | |||
| 599 | ret = serdes_am654_clk_register(am654_phy, clock_name, i); | ||
| 600 | if (ret) { | ||
| 601 | dev_err(dev, "Failed to initialize clock %s\n", | ||
| 602 | clock_name); | ||
| 603 | return ret; | ||
| 604 | } | ||
| 605 | } | ||
| 606 | |||
| 607 | clk_data = &am654_phy->clk_data; | ||
| 608 | clk_data->clks = am654_phy->clks; | ||
| 609 | clk_data->clk_num = SERDES_NUM_CLOCKS; | ||
| 610 | ret = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); | ||
| 611 | if (ret) | ||
| 612 | return ret; | ||
| 613 | |||
| 614 | pm_runtime_enable(dev); | ||
| 615 | |||
| 616 | phy = devm_phy_create(dev, NULL, &ops); | ||
| 617 | if (IS_ERR(phy)) | ||
| 618 | return PTR_ERR(phy); | ||
| 619 | |||
| 620 | phy_set_drvdata(phy, am654_phy); | ||
| 621 | phy_provider = devm_of_phy_provider_register(dev, serdes_am654_xlate); | ||
| 622 | if (IS_ERR(phy_provider)) { | ||
| 623 | ret = PTR_ERR(phy_provider); | ||
| 624 | goto clk_err; | ||
| 625 | } | ||
| 626 | |||
| 627 | return 0; | ||
| 628 | |||
| 629 | clk_err: | ||
| 630 | of_clk_del_provider(node); | ||
| 631 | |||
| 632 | return ret; | ||
| 633 | } | ||
| 634 | |||
| 635 | static int serdes_am654_remove(struct platform_device *pdev) | ||
| 636 | { | ||
| 637 | struct serdes_am654 *am654_phy = platform_get_drvdata(pdev); | ||
| 638 | struct device_node *node = am654_phy->of_node; | ||
| 639 | |||
| 640 | pm_runtime_disable(&pdev->dev); | ||
| 641 | of_clk_del_provider(node); | ||
| 642 | |||
| 643 | return 0; | ||
| 644 | } | ||
| 645 | |||
| 646 | static struct platform_driver serdes_am654_driver = { | ||
| 647 | .probe = serdes_am654_probe, | ||
| 648 | .remove = serdes_am654_remove, | ||
| 649 | .driver = { | ||
| 650 | .name = "phy-am654", | ||
| 651 | .of_match_table = serdes_am654_id_table, | ||
| 652 | }, | ||
| 653 | }; | ||
| 654 | module_platform_driver(serdes_am654_driver); | ||
| 655 | |||
| 656 | MODULE_AUTHOR("Texas Instruments Inc."); | ||
| 657 | MODULE_DESCRIPTION("TI AM654x SERDES driver"); | ||
| 658 | MODULE_LICENSE("GPL v2"); | ||
| @@ -56,51 +56,73 @@ · 55 unmodified lines | |||
| 56 | 56 | ||
| 57 | #define SATA_PLL_SOFT_RESET BIT(18) | 57 | #define SATA_PLL_SOFT_RESET BIT(18) |
| 58 | 58 | ||
| 59 | #define PIPE3_PHY_PWRCTL_CLK_CMD_MASK 0x003FC000 | 59 | #define PIPE3_PHY_PWRCTL_CLK_CMD_MASK GENMASK(21, 14) |
| 60 | #define PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT 14 | 60 | #define PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT 14 |
| 61 | 61 | ||
| 62 | #define PIPE3_PHY_PWRCTL_CLK_FREQ_MASK 0xFFC00000 | 62 | #define PIPE3_PHY_PWRCTL_CLK_FREQ_MASK GENMASK(31, 22) |
| 63 | #define PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT 22 | 63 | #define PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT 22 |
| 64 | 64 | ||
| 65 | #define PIPE3_PHY_TX_RX_POWERON 0x3 | 65 | #define PIPE3_PHY_RX_POWERON (0x1 << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT) |
| 66 | #define PIPE3_PHY_TX_RX_POWEROFF 0x0 | 66 | #define PIPE3_PHY_TX_POWERON (0x2 << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT) |
| 67 | 67 | ||
| 68 | #define PCIE_PCS_MASK 0xFF0000 | 68 | #define PCIE_PCS_MASK 0xFF0000 |
| 69 | #define PCIE_PCS_DELAY_COUNT_SHIFT 0x10 | 69 | #define PCIE_PCS_DELAY_COUNT_SHIFT 0x10 |
| 70 | 70 | ||
| 71 | #define PCIEPHYRX_ANA_PROGRAMMABILITY 0x0000000C | 71 | #define PIPE3_PHY_RX_ANA_PROGRAMMABILITY 0x0000000C |
| 72 | #define INTERFACE_MASK GENMASK(31, 27) | 72 | #define INTERFACE_MASK GENMASK(31, 27) |
| 73 | #define INTERFACE_SHIFT 27 | 73 | #define INTERFACE_SHIFT 27 |
| 74 | #define INTERFACE_MODE_USBSS BIT(4) | ||
| 75 | #define INTERFACE_MODE_SATA_1P5 BIT(3) | ||
| 76 | #define INTERFACE_MODE_SATA_3P0 BIT(2) | ||
| 77 | #define INTERFACE_MODE_PCIE BIT(0) | ||
| 78 | |||
| 74 | #define LOSD_MASK GENMASK(17, 14) | 79 | #define LOSD_MASK GENMASK(17, 14) |
| 75 | #define LOSD_SHIFT 14 | 80 | #define LOSD_SHIFT 14 |
| 76 | #define MEM_PLLDIV GENMASK(6, 5) | 81 | #define MEM_PLLDIV GENMASK(6, 5) |
| 77 | 82 | ||
| 78 | #define PCIEPHYRX_TRIM 0x0000001C | 83 | #define PIPE3_PHY_RX_TRIM 0x0000001C |
| 79 | #define MEM_DLL_TRIM_SEL GENMASK(31, 30) | 84 | #define MEM_DLL_TRIM_SEL_MASK GENMASK(31, 30) |
| 80 | #define MEM_DLL_TRIM_SHIFT 30 | 85 | #define MEM_DLL_TRIM_SHIFT 30 |
| 81 | 86 | ||
| 82 | #define PCIEPHYRX_DLL 0x00000024 | 87 | #define PIPE3_PHY_RX_DLL 0x00000024 |
| 83 | #define MEM_DLL_PHINT_RATE GENMASK(31, 30) | 88 | #define MEM_DLL_PHINT_RATE_MASK GENMASK(31, 30) |
| 89 | #define MEM_DLL_PHINT_RATE_SHIFT 30 | ||
| 84 | 90 | ||
| 85 | #define PCIEPHYRX_DIGITAL_MODES 0x00000028 | 91 | #define PIPE3_PHY_RX_DIGITAL_MODES 0x00000028 |
| 92 | #define MEM_HS_RATE_MASK GENMASK(28, 27) | ||
| 93 | #define MEM_HS_RATE_SHIFT 27 | ||
| 94 | #define MEM_OVRD_HS_RATE BIT(26) | ||
| 95 | #define MEM_OVRD_HS_RATE_SHIFT 26 | ||
| 86 | #define MEM_CDR_FASTLOCK BIT(23) | 96 | #define MEM_CDR_FASTLOCK BIT(23) |
| 87 | #define MEM_CDR_LBW GENMASK(22, 21) | 97 | #define MEM_CDR_FASTLOCK_SHIFT 23 |
| 88 | #define MEM_CDR_STEPCNT GENMASK(20, 19) | 98 | #define MEM_CDR_LBW_MASK GENMASK(22, 21) |
| 99 | #define MEM_CDR_LBW_SHIFT 21 | ||
| 100 | #define MEM_CDR_STEPCNT_MASK GENMASK(20, 19) | ||
| 101 | #define MEM_CDR_STEPCNT_SHIFT 19 | ||
| 89 | #define MEM_CDR_STL_MASK GENMASK(18, 16) | 102 | #define MEM_CDR_STL_MASK GENMASK(18, 16) |
| 90 | #define MEM_CDR_STL_SHIFT 16 | 103 | #define MEM_CDR_STL_SHIFT 16 |
| 91 | #define MEM_CDR_THR_MASK GENMASK(15, 13) | 104 | #define MEM_CDR_THR_MASK GENMASK(15, 13) |
| 92 | #define MEM_CDR_THR_SHIFT 13 | 105 | #define MEM_CDR_THR_SHIFT 13 |
| 93 | #define MEM_CDR_THR_MODE BIT(12) | 106 | #define MEM_CDR_THR_MODE BIT(12) |
| 94 | #define MEM_CDR_CDR_2NDO_SDM_MODE BIT(11) | 107 | #define MEM_CDR_THR_MODE_SHIFT 12 |
| 95 | #define MEM_OVRD_HS_RATE BIT(26) | 108 | #define MEM_CDR_2NDO_SDM_MODE BIT(11) |
| 96 | 109 | #define MEM_CDR_2NDO_SDM_MODE_SHIFT 11 | |
| 97 | #define PCIEPHYRX_EQUALIZER 0x00000038 | 110 | |
| 98 | #define MEM_EQLEV GENMASK(31, 16) | 111 | #define PIPE3_PHY_RX_EQUALIZER 0x00000038 |
| 99 | #define MEM_EQFTC GENMASK(15, 11) | 112 | #define MEM_EQLEV_MASK GENMASK(31, 16) |
| 100 | #define MEM_EQCTL GENMASK(10, 7) | 113 | #define MEM_EQLEV_SHIFT 16 |
| 114 | #define MEM_EQFTC_MASK GENMASK(15, 11) | ||
| 115 | #define MEM_EQFTC_SHIFT 11 | ||
| 116 | #define MEM_EQCTL_MASK GENMASK(10, 7) | ||
| 101 | #define MEM_EQCTL_SHIFT 7 | 117 | #define MEM_EQCTL_SHIFT 7 |
| 102 | #define MEM_OVRD_EQLEV BIT(2) | 118 | #define MEM_OVRD_EQLEV BIT(2) |
| 119 | #define MEM_OVRD_EQLEV_SHIFT 2 | ||
| 103 | #define MEM_OVRD_EQFTC BIT(1) | 120 | #define MEM_OVRD_EQFTC BIT(1) |
| 121 | #define MEM_OVRD_EQFTC_SHIFT 1 | ||
| 122 | |||
| 123 | #define SATA_PHY_RX_IO_AND_A2D_OVERRIDES 0x44 | ||
| 124 | #define MEM_CDR_LOS_SOURCE_MASK GENMASK(10, 9) | ||
| 125 | #define MEM_CDR_LOS_SOURCE_SHIFT 9 | ||
| 104 | 126 | ||
| 105 | /* | 127 | /* |
| 106 | * This is an Empirical value that works, need to confirm the actual | 128 | * This is an Empirical value that works, need to confirm the actual |
| @@ -110,6 +132,10 @@ · 3 unmodified lines | |||
| 110 | #define PLL_IDLE_TIME 100 /* in milliseconds */ | 132 | #define PLL_IDLE_TIME 100 /* in milliseconds */ |
| 111 | #define PLL_LOCK_TIME 100 /* in milliseconds */ | 133 | #define PLL_LOCK_TIME 100 /* in milliseconds */ |
| 112 | 134 | ||
| 135 | enum pipe3_mode { PIPE3_MODE_PCIE = 1, | ||
| 136 | PIPE3_MODE_SATA, | ||
| 137 | PIPE3_MODE_USBSS }; | ||
| 138 | |||
| 113 | struct pipe3_dpll_params { | 139 | struct pipe3_dpll_params { |
| 114 | u16 m; | 140 | u16 m; |
| 115 | u8 n; | 141 | u8 n; |
| @@ -123,6 +149,27 @@ struct pipe3_dpll_map { · 7 unmodified lines | |||
| 123 | struct pipe3_dpll_params params; | 149 | struct pipe3_dpll_params params; |
| 124 | }; | 150 | }; |
| 125 | 151 | ||
| 152 | struct pipe3_settings { | ||
| 153 | u8 ana_interface; | ||
| 154 | u8 ana_losd; | ||
| 155 | u8 dig_fastlock; | ||
| 156 | u8 dig_lbw; | ||
| 157 | u8 dig_stepcnt; | ||
| 158 | u8 dig_stl; | ||
| 159 | u8 dig_thr; | ||
| 160 | u8 dig_thr_mode; | ||
| 161 | u8 dig_2ndo_sdm_mode; | ||
| 162 | u8 dig_hs_rate; | ||
| 163 | u8 dig_ovrd_hs_rate; | ||
| 164 | u8 dll_trim_sel; | ||
| 165 | u8 dll_phint_rate; | ||
| 166 | u8 eq_lev; | ||
| 167 | u8 eq_ftc; | ||
| 168 | u8 eq_ctl; | ||
| 169 | u8 eq_ovrd_lev; | ||
| 170 | u8 eq_ovrd_ftc; | ||
| 171 | }; | ||
| 172 | |||
| 126 | struct ti_pipe3 { | 173 | struct ti_pipe3 { |
| 127 | void __iomem *pll_ctrl_base; | 174 | void __iomem *pll_ctrl_base; |
| 128 | void __iomem *phy_rx; | 175 | void __iomem *phy_rx; |
| @@ -141,6 +188,8 @@ struct ti_pipe3 { · 12 unmodified lines | |||
| 141 | unsigned int power_reg; /* power reg. index within syscon */ | 188 | unsigned int power_reg; /* power reg. index within syscon */ |
| 142 | unsigned int pcie_pcs_reg; /* pcs reg. index in syscon */ | 189 | unsigned int pcie_pcs_reg; /* pcs reg. index in syscon */ |
| 143 | bool sata_refclk_enabled; | 190 | bool sata_refclk_enabled; |
| 191 | enum pipe3_mode mode; | ||
| 192 | struct pipe3_settings settings; | ||
| 144 | }; | 193 | }; |
| 145 | 194 | ||
| 146 | static struct pipe3_dpll_map dpll_map_usb[] = { | 195 | static struct pipe3_dpll_map dpll_map_usb[] = { |
| @@ -163,6 +212,89 @@ static struct pipe3_dpll_map dpll_map_sata[] = { · 16 unmodified lines | |||
| 163 | { }, /* Terminator */ | 212 | { }, /* Terminator */ |
| 164 | }; | 213 | }; |
| 165 | 214 | ||
| 215 | struct pipe3_data { | ||
| 216 | enum pipe3_mode mode; | ||
| 217 | struct pipe3_dpll_map *dpll_map; | ||
| 218 | struct pipe3_settings settings; | ||
| 219 | }; | ||
| 220 | |||
| 221 | static struct pipe3_data data_usb = { | ||
| 222 | .mode = PIPE3_MODE_USBSS, | ||
| 223 | .dpll_map = dpll_map_usb, | ||
| 224 | .settings = { | ||
| 225 | /* DRA75x TRM Table 26-17 Preferred USB3_PHY_RX SCP Register Settings */ | ||
| 226 | .ana_interface = INTERFACE_MODE_USBSS, | ||
| 227 | .ana_losd = 0xa, | ||
| 228 | .dig_fastlock = 1, | ||
| 229 | .dig_lbw = 3, | ||
| 230 | .dig_stepcnt = 0, | ||
| 231 | .dig_stl = 0x3, | ||
| 232 | .dig_thr = 1, | ||
| 233 | .dig_thr_mode = 1, | ||
| 234 | .dig_2ndo_sdm_mode = 0, | ||
| 235 | .dig_hs_rate = 0, | ||
| 236 | .dig_ovrd_hs_rate = 1, | ||
| 237 | .dll_trim_sel = 0x2, | ||
| 238 | .dll_phint_rate = 0x3, | ||
| 239 | .eq_lev = 0, | ||
| 240 | .eq_ftc = 0, | ||
| 241 | .eq_ctl = 0x9, | ||
| 242 | .eq_ovrd_lev = 0, | ||
| 243 | .eq_ovrd_ftc = 0, | ||
| 244 | }, | ||
| 245 | }; | ||
| 246 | |||
| 247 | static struct pipe3_data data_sata = { | ||
| 248 | .mode = PIPE3_MODE_SATA, | ||
| 249 | .dpll_map = dpll_map_sata, | ||
| 250 | .settings = { | ||
| 251 | /* DRA75x TRM Table 26-9 Preferred SATA_PHY_RX SCP Register Settings */ | ||
| 252 | .ana_interface = INTERFACE_MODE_SATA_3P0, | ||
| 253 | .ana_losd = 0x5, | ||
| 254 | .dig_fastlock = 1, | ||
| 255 | .dig_lbw = 3, | ||
| 256 | .dig_stepcnt = 0, | ||
| 257 | .dig_stl = 0x3, | ||
| 258 | .dig_thr = 1, | ||
| 259 | .dig_thr_mode = 1, | ||
| 260 | .dig_2ndo_sdm_mode = 0, | ||
| 261 | .dig_hs_rate = 0, /* Not in TRM preferred settings */ | ||
| 262 | .dig_ovrd_hs_rate = 0, /* Not in TRM preferred settings */ | ||
| 263 | .dll_trim_sel = 0x1, | ||
| 264 | .dll_phint_rate = 0x2, /* for 1.5 GHz DPLL clock */ | ||
| 265 | .eq_lev = 0, | ||
| 266 | .eq_ftc = 0x1f, | ||
| 267 | .eq_ctl = 0, | ||
| 268 | .eq_ovrd_lev = 1, | ||
| 269 | .eq_ovrd_ftc = 1, | ||
| 270 | }, | ||
| 271 | }; | ||
| 272 | |||
| 273 | static struct pipe3_data data_pcie = { | ||
| 274 | .mode = PIPE3_MODE_PCIE, | ||
| 275 | .settings = { | ||
| 276 | /* DRA75x TRM Table 26-62 Preferred PCIe_PHY_RX SCP Register Settings */ | ||
| 277 | .ana_interface = INTERFACE_MODE_PCIE, | ||
| 278 | .ana_losd = 0xa, | ||
| 279 | .dig_fastlock = 1, | ||
| 280 | .dig_lbw = 3, | ||
| 281 | .dig_stepcnt = 0, | ||
| 282 | .dig_stl = 0x3, | ||
| 283 | .dig_thr = 1, | ||
| 284 | .dig_thr_mode = 1, | ||
| 285 | .dig_2ndo_sdm_mode = 0, | ||
| 286 | .dig_hs_rate = 0, | ||
| 287 | .dig_ovrd_hs_rate = 0, | ||
| 288 | .dll_trim_sel = 0x2, | ||
| 289 | .dll_phint_rate = 0x3, | ||
| 290 | .eq_lev = 0, | ||
| 291 | .eq_ftc = 0x1f, | ||
| 292 | .eq_ctl = 1, | ||
| 293 | .eq_ovrd_lev = 0, | ||
| 294 | .eq_ovrd_ftc = 0, | ||
| 295 | }, | ||
| 296 | }; | ||
| 297 | |||
| 166 | static inline u32 ti_pipe3_readl(void __iomem *addr, unsigned offset) | 298 | static inline u32 ti_pipe3_readl(void __iomem *addr, unsigned offset) |
| 167 | { | 299 | { |
| 168 | return __raw_readl(addr + offset); | 300 | return __raw_readl(addr + offset); |
| @@ -196,7 +328,6 @@ static void ti_pipe3_disable_clocks(struct ti_pipe3 *phy); · 27 unmodified lines | |||
| 196 | 328 | ||
| 197 | static int ti_pipe3_power_off(struct phy *x) | 329 | static int ti_pipe3_power_off(struct phy *x) |
| 198 | { | 330 | { |
| 199 | u32 val; | ||
| 200 | int ret; | 331 | int ret; |
| 201 | struct ti_pipe3 *phy = phy_get_drvdata(x); | 332 | struct ti_pipe3 *phy = phy_get_drvdata(x); |
| 202 | 333 | ||
| @@ -205,13 +336,13 @@ static int ti_pipe3_power_off(struct phy *x) · 2 unmodified lines | |||
| 205 | return 0; | 336 | return 0; |
| 206 | } | 337 | } |
| 207 | 338 | ||
| 208 | val = PIPE3_PHY_TX_RX_POWEROFF << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT; | ||
| 209 | |||
| 210 | ret = regmap_update_bits(phy->phy_power_syscon, phy->power_reg, | 339 | ret = regmap_update_bits(phy->phy_power_syscon, phy->power_reg, |
| 211 | PIPE3_PHY_PWRCTL_CLK_CMD_MASK, val); | 340 | PIPE3_PHY_PWRCTL_CLK_CMD_MASK, 0); |
| 212 | return ret; | 341 | return ret; |
| 213 | } | 342 | } |
| 214 | 343 | ||
| 344 | static void ti_pipe3_calibrate(struct ti_pipe3 *phy); | ||
| 345 | |||
| 215 | static int ti_pipe3_power_on(struct phy *x) | 346 | static int ti_pipe3_power_on(struct phy *x) |
| 216 | { | 347 | { |
| 217 | u32 val; | 348 | u32 val; |
| @@ -219,6 +350,7 @@ static int ti_pipe3_power_on(struct phy *x) · 1 unmodified line | |||
| 219 | int ret; | 350 | int ret; |
| 220 | unsigned long rate; | 351 | unsigned long rate; |
| 221 | struct ti_pipe3 *phy = phy_get_drvdata(x); | 352 | struct ti_pipe3 *phy = phy_get_drvdata(x); |
| 353 | bool rx_pending = false; | ||
| 222 | 354 | ||
| 223 | if (!phy->phy_power_syscon) { | 355 | if (!phy->phy_power_syscon) { |
| 224 | omap_control_phy_power(phy->control_dev, 1); | 356 | omap_control_phy_power(phy->control_dev, 1); |
| @@ -231,14 +363,35 @@ static int ti_pipe3_power_on(struct phy *x) · 6 unmodified lines | |||
| 231 | return -EINVAL; | 363 | return -EINVAL; |
| 232 | } | 364 | } |
| 233 | rate = rate / 1000000; | 365 | rate = rate / 1000000; |
| 234 | mask = OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_CMD_MASK | | 366 | mask = OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_MASK; |
| 235 | OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_MASK; | 367 | val = rate << OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT; |
| 236 | val = PIPE3_PHY_TX_RX_POWERON << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT; | ||
| 237 | val |= rate << OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT; | ||
| 238 | |||
| 239 | ret = regmap_update_bits(phy->phy_power_syscon, phy->power_reg, | 368 | ret = regmap_update_bits(phy->phy_power_syscon, phy->power_reg, |
| 240 | mask, val); | 369 | mask, val); |
| 241 | return ret; | 370 | /* |
| 371 | * For PCIe, TX and RX must be powered on simultaneously. | ||
| 372 | * For USB and SATA, TX must be powered on before RX | ||
| 373 | */ | ||
| 374 | mask = OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_CMD_MASK; | ||
| 375 | if (phy->mode == PIPE3_MODE_SATA || phy->mode == PIPE3_MODE_USBSS) { | ||
| 376 | val = PIPE3_PHY_TX_POWERON; | ||
| 377 | rx_pending = true; | ||
| 378 | } else { | ||
| 379 | val = PIPE3_PHY_TX_POWERON | PIPE3_PHY_RX_POWERON; | ||
| 380 | } | ||
| 381 | |||
| 382 | regmap_update_bits(phy->phy_power_syscon, phy->power_reg, | ||
| 383 | mask, val); | ||
| 384 | |||
| 385 | if (rx_pending) { | ||
| 386 | val = PIPE3_PHY_TX_POWERON | PIPE3_PHY_RX_POWERON; | ||
| 387 | regmap_update_bits(phy->phy_power_syscon, phy->power_reg, | ||
| 388 | mask, val); | ||
| 389 | } | ||
| 390 | |||
| 391 | if (phy->mode == PIPE3_MODE_PCIE) | ||
| 392 | ti_pipe3_calibrate(phy); | ||
| 393 | |||
| 394 | return 0; | ||
| 242 | } | 395 | } |
| 243 | 396 | ||
| 244 | static int ti_pipe3_dpll_wait_lock(struct ti_pipe3 *phy) | 397 | static int ti_pipe3_dpll_wait_lock(struct ti_pipe3 *phy) |
| @@ -300,32 +453,55 @@ static int ti_pipe3_dpll_program(struct ti_pipe3 *phy) · 55 unmodified lines | |||
| 300 | static void ti_pipe3_calibrate(struct ti_pipe3 *phy) | 453 | static void ti_pipe3_calibrate(struct ti_pipe3 *phy) |
| 301 | { | 454 | { |
| 302 | u32 val; | 455 | u32 val; |
| 456 | struct pipe3_settings *s = &phy->settings; | ||
| 303 | 457 | ||
| 304 | val = ti_pipe3_readl(phy->phy_rx, PCIEPHYRX_ANA_PROGRAMMABILITY); | 458 | val = ti_pipe3_readl(phy->phy_rx, PIPE3_PHY_RX_ANA_PROGRAMMABILITY); |
| 305 | val &= ~(INTERFACE_MASK | LOSD_MASK | MEM_PLLDIV); | 459 | val &= ~(INTERFACE_MASK | LOSD_MASK | MEM_PLLDIV); |
| 306 | val = (0x1 << INTERFACE_SHIFT | 0xA << LOSD_SHIFT); | 460 | val |= (s->ana_interface << INTERFACE_SHIFT | s->ana_losd << LOSD_SHIFT); |
| 307 | ti_pipe3_writel(phy->phy_rx, PCIEPHYRX_ANA_PROGRAMMABILITY, val); | 461 | ti_pipe3_writel(phy->phy_rx, PIPE3_PHY_RX_ANA_PROGRAMMABILITY, val); |
| 308 | 462 | ||
| 309 | val = ti_pipe3_readl(phy->phy_rx, PCIEPHYRX_DIGITAL_MODES); | 463 | val = ti_pipe3_readl(phy->phy_rx, PIPE3_PHY_RX_DIGITAL_MODES); |
| 310 | val &= ~(MEM_CDR_STEPCNT | MEM_CDR_STL_MASK | MEM_CDR_THR_MASK | | 464 | val &= ~(MEM_HS_RATE_MASK | MEM_OVRD_HS_RATE | MEM_CDR_FASTLOCK | |
| 311 | MEM_CDR_CDR_2NDO_SDM_MODE | MEM_OVRD_HS_RATE); | 465 | MEM_CDR_LBW_MASK | MEM_CDR_STEPCNT_MASK | MEM_CDR_STL_MASK | |
| 312 | val |= (MEM_CDR_FASTLOCK | MEM_CDR_LBW | 0x3 << MEM_CDR_STL_SHIFT | | 466 | MEM_CDR_THR_MASK | MEM_CDR_THR_MODE | MEM_CDR_2NDO_SDM_MODE); |
| 313 | 0x1 << MEM_CDR_THR_SHIFT | MEM_CDR_THR_MODE); | 467 | val |= s->dig_hs_rate << MEM_HS_RATE_SHIFT | |
| 314 | ti_pipe3_writel(phy->phy_rx, PCIEPHYRX_DIGITAL_MODES, val); | 468 | s->dig_ovrd_hs_rate << MEM_OVRD_HS_RATE_SHIFT | |
| 315 | 469 | s->dig_fastlock << MEM_CDR_FASTLOCK_SHIFT | | |
| 316 | val = ti_pipe3_readl(phy->phy_rx, PCIEPHYRX_TRIM); | 470 | s->dig_lbw << MEM_CDR_LBW_SHIFT | |
| 317 | val &= ~MEM_DLL_TRIM_SEL; | 471 | s->dig_stepcnt << MEM_CDR_STEPCNT_SHIFT | |
| 318 | val |= 0x2 << MEM_DLL_TRIM_SHIFT; | 472 | s->dig_stl << MEM_CDR_STL_SHIFT | |
| 319 | ti_pipe3_writel(phy->phy_rx, PCIEPHYRX_TRIM, val); | 473 | s->dig_thr << MEM_CDR_THR_SHIFT | |
| 320 | 474 | s->dig_thr_mode << MEM_CDR_THR_MODE_SHIFT | | |
| 321 | val = ti_pipe3_readl(phy->phy_rx, PCIEPHYRX_DLL); | 475 | s->dig_2ndo_sdm_mode << MEM_CDR_2NDO_SDM_MODE_SHIFT; |
| 322 | val |= MEM_DLL_PHINT_RATE; | 476 | ti_pipe3_writel(phy->phy_rx, PIPE3_PHY_RX_DIGITAL_MODES, val); |
| 323 | ti_pipe3_writel(phy->phy_rx, PCIEPHYRX_DLL, val); | 477 | |
| 324 | 478 | val = ti_pipe3_readl(phy->phy_rx, PIPE3_PHY_RX_TRIM); | |
| 325 | val = ti_pipe3_readl(phy->phy_rx, PCIEPHYRX_EQUALIZER); | 479 | val &= ~MEM_DLL_TRIM_SEL_MASK; |
| 326 | val &= ~(MEM_EQLEV | MEM_EQCTL | MEM_OVRD_EQLEV | MEM_OVRD_EQFTC); | 480 | val |= s->dll_trim_sel << MEM_DLL_TRIM_SHIFT; |
| 327 | val |= MEM_EQFTC | 0x1 << MEM_EQCTL_SHIFT; | 481 | ti_pipe3_writel(phy->phy_rx, PIPE3_PHY_RX_TRIM, val); |
| 328 | ti_pipe3_writel(phy->phy_rx, PCIEPHYRX_EQUALIZER, val); | 482 | |
| 483 | val = ti_pipe3_readl(phy->phy_rx, PIPE3_PHY_RX_DLL); | ||
| 484 | val &= ~MEM_DLL_PHINT_RATE_MASK; | ||
| 485 | val |= s->dll_phint_rate << MEM_DLL_PHINT_RATE_SHIFT; | ||
| 486 | ti_pipe3_writel(phy->phy_rx, PIPE3_PHY_RX_DLL, val); | ||
| 487 | |||
| 488 | val = ti_pipe3_readl(phy->phy_rx, PIPE3_PHY_RX_EQUALIZER); | ||
| 489 | val &= ~(MEM_EQLEV_MASK | MEM_EQFTC_MASK | MEM_EQCTL_MASK | | ||
| 490 | MEM_OVRD_EQLEV | MEM_OVRD_EQFTC); | ||
| 491 | val |= s->eq_lev << MEM_EQLEV_SHIFT | | ||
| 492 | s->eq_ftc << MEM_EQFTC_SHIFT | | ||
| 493 | s->eq_ctl << MEM_EQCTL_SHIFT | | ||
| 494 | s->eq_ovrd_lev << MEM_OVRD_EQLEV_SHIFT | | ||
| 495 | s->eq_ovrd_ftc << MEM_OVRD_EQFTC_SHIFT; | ||
| 496 | ti_pipe3_writel(phy->phy_rx, PIPE3_PHY_RX_EQUALIZER, val); | ||
| 497 | |||
| 498 | if (phy->mode == PIPE3_MODE_SATA) { | ||
| 499 | val = ti_pipe3_readl(phy->phy_rx, | ||
| 500 | SATA_PHY_RX_IO_AND_A2D_OVERRIDES); | ||
| 501 | val &= ~MEM_CDR_LOS_SOURCE_MASK; | ||
| 502 | ti_pipe3_writel(phy->phy_rx, SATA_PHY_RX_IO_AND_A2D_OVERRIDES, | ||
| 503 | val); | ||
| 504 | } | ||
| 329 | } | 505 | } |
| 330 | 506 | ||
| 331 | static int ti_pipe3_init(struct phy *x) | 507 | static int ti_pipe3_init(struct phy *x) |
| @@ -340,7 +516,7 @@ static int ti_pipe3_init(struct phy *x) · 8 unmodified lines | |||
| 340 | * as recommended in AM572x TRM SPRUHZ6, section 18.5.2.2, table | 516 | * as recommended in AM572x TRM SPRUHZ6, section 18.5.2.2, table |
| 341 | * 18-1804. | 517 | * 18-1804. |
| 342 | */ | 518 | */ |
| 343 | if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie")) { | 519 | if (phy->mode == PIPE3_MODE_PCIE) { |
| 344 | if (!phy->pcs_syscon) { | 520 | if (!phy->pcs_syscon) { |
| 345 | omap_control_pcie_pcs(phy->control_dev, 0x96); | 521 | omap_control_pcie_pcs(phy->control_dev, 0x96); |
| 346 | return 0; | 522 | return 0; |
| @@ -349,12 +525,7 @@ static int ti_pipe3_init(struct phy *x) · 2 unmodified lines | |||
| 349 | val = 0x96 << OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT; | 525 | val = 0x96 << OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT; |
| 350 | ret = regmap_update_bits(phy->pcs_syscon, phy->pcie_pcs_reg, | 526 | ret = regmap_update_bits(phy->pcs_syscon, phy->pcie_pcs_reg, |
| 351 | PCIE_PCS_MASK, val); | 527 | PCIE_PCS_MASK, val); |
| 352 | if (ret) | 528 | return ret; |
| 353 | return ret; | ||
| 354 | |||
| 355 | ti_pipe3_calibrate(phy); | ||
| 356 | |||
| 357 | return 0; | ||
| 358 | } | 529 | } |
| 359 | 530 | ||
| 360 | /* Bring it out of IDLE if it is IDLE */ | 531 | /* Bring it out of IDLE if it is IDLE */ |
| @@ -367,8 +538,7 @@ static int ti_pipe3_init(struct phy *x) · 6 unmodified lines | |||
| 367 | 538 | ||
| 368 | /* SATA has issues if re-programmed when locked */ | 539 | /* SATA has issues if re-programmed when locked */ |
| 369 | val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS); | 540 | val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS); |
| 370 | if ((val & PLL_LOCK) && of_device_is_compatible(phy->dev->of_node, | 541 | if ((val & PLL_LOCK) && phy->mode == PIPE3_MODE_SATA) |
| 371 | "ti,phy-pipe3-sata")) | ||
| 372 | return ret; | 542 | return ret; |
| 373 | 543 | ||
| 374 | /* Program the DPLL */ | 544 | /* Program the DPLL */ |
| @@ -378,6 +548,8 @@ static int ti_pipe3_init(struct phy *x) · 3 unmodified lines | |||
| 378 | return -EINVAL; | 548 | return -EINVAL; |
| 379 | } | 549 | } |
| 380 | 550 | ||
| 551 | ti_pipe3_calibrate(phy); | ||
| 552 | |||
| 381 | return ret; | 553 | return ret; |
| 382 | } | 554 | } |
| 383 | 555 | ||
| @@ -390,12 +562,11 @@ static int ti_pipe3_exit(struct phy *x) · 6 unmodified lines | |||
| 390 | /* If dpll_reset_syscon is not present we wont power down SATA DPLL | 562 | /* If dpll_reset_syscon is not present we wont power down SATA DPLL |
| 391 | * due to Errata i783 | 563 | * due to Errata i783 |
| 392 | */ | 564 | */ |
| 393 | if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-sata") && | 565 | if (phy->mode == PIPE3_MODE_SATA && !phy->dpll_reset_syscon) |
| 394 | !phy->dpll_reset_syscon) | ||
| 395 | return 0; | 566 | return 0; |
| 396 | 567 | ||
| 397 | /* PCIe doesn't have internal DPLL */ | 568 | /* PCIe doesn't have internal DPLL */ |
| 398 | if (!of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie")) { | 569 | if (phy->mode != PIPE3_MODE_PCIE) { |
| 399 | /* Put DPLL in IDLE mode */ | 570 | /* Put DPLL in IDLE mode */ |
| 400 | val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); | 571 | val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); |
| 401 | val |= PLL_IDLE; | 572 | val |= PLL_IDLE; |
| @@ -418,7 +589,7 @@ static int ti_pipe3_exit(struct phy *x) · 16 unmodified lines | |||
| 418 | } | 589 | } |
| 419 | 590 | ||
| 420 | /* i783: SATA needs control bit toggle after PLL unlock */ | 591 | /* i783: SATA needs control bit toggle after PLL unlock */ |
| 421 | if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-sata")) { | 592 | if (phy->mode == PIPE3_MODE_SATA) { |
| 422 | regmap_update_bits(phy->dpll_reset_syscon, phy->dpll_reset_reg, | 593 | regmap_update_bits(phy->dpll_reset_syscon, phy->dpll_reset_reg, |
| 423 | SATA_PLL_SOFT_RESET, SATA_PLL_SOFT_RESET); | 594 | SATA_PLL_SOFT_RESET, SATA_PLL_SOFT_RESET); |
| 424 | regmap_update_bits(phy->dpll_reset_syscon, phy->dpll_reset_reg, | 595 | regmap_update_bits(phy->dpll_reset_syscon, phy->dpll_reset_reg, |
| @@ -443,7 +614,6 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy) · 18 unmodified lines | |||
| 443 | { | 614 | { |
| 444 | struct clk *clk; | 615 | struct clk *clk; |
| 445 | struct device *dev = phy->dev; | 616 | struct device *dev = phy->dev; |
| 446 | struct device_node *node = dev->of_node; | ||
| 447 | 617 | ||
| 448 | phy->refclk = devm_clk_get(dev, "refclk"); | 618 | phy->refclk = devm_clk_get(dev, "refclk"); |
| 449 | if (IS_ERR(phy->refclk)) { | 619 | if (IS_ERR(phy->refclk)) { |
| @@ -451,11 +621,11 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy) · 1 unmodified line | |||
| 451 | /* older DTBs have missing refclk in SATA PHY | 621 | /* older DTBs have missing refclk in SATA PHY |
| 452 | * so don't bail out in case of SATA PHY. | 622 | * so don't bail out in case of SATA PHY. |
| 453 | */ | 623 | */ |
| 454 | if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) | 624 | if (phy->mode != PIPE3_MODE_SATA) |
| 455 | return PTR_ERR(phy->refclk); | 625 | return PTR_ERR(phy->refclk); |
| 456 | } | 626 | } |
| 457 | 627 | ||
| 458 | if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) { | 628 | if (phy->mode != PIPE3_MODE_SATA) { |
| 459 | phy->wkupclk = devm_clk_get(dev, "wkupclk"); | 629 | phy->wkupclk = devm_clk_get(dev, "wkupclk"); |
| 460 | if (IS_ERR(phy->wkupclk)) { | 630 | if (IS_ERR(phy->wkupclk)) { |
| 461 | dev_err(dev, "unable to get wkupclk\n"); | 631 | dev_err(dev, "unable to get wkupclk\n"); |
| @@ -465,8 +635,7 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy) · 3 unmodified lines | |||
| 465 | phy->wkupclk = ERR_PTR(-ENODEV); | 635 | phy->wkupclk = ERR_PTR(-ENODEV); |
| 466 | } | 636 | } |
| 467 | 637 | ||
| 468 | if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie") || | 638 | if (phy->mode != PIPE3_MODE_PCIE || phy->phy_power_syscon) { |
| 469 | phy->phy_power_syscon) { | ||
| 470 | phy->sys_clk = devm_clk_get(dev, "sysclk"); | 639 | phy->sys_clk = devm_clk_get(dev, "sysclk"); |
| 471 | if (IS_ERR(phy->sys_clk)) { | 640 | if (IS_ERR(phy->sys_clk)) { |
| 472 | dev_err(dev, "unable to get sysclk\n"); | 641 | dev_err(dev, "unable to get sysclk\n"); |
| @@ -474,7 +643,7 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy) · 1 unmodified line | |||
| 474 | } | 643 | } |
| 475 | } | 644 | } |
| 476 | 645 | ||
| 477 | if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { | 646 | if (phy->mode == PIPE3_MODE_PCIE) { |
| 478 | clk = devm_clk_get(dev, "dpll_ref"); | 647 | clk = devm_clk_get(dev, "dpll_ref"); |
| 479 | if (IS_ERR(clk)) { | 648 | if (IS_ERR(clk)) { |
| 480 | dev_err(dev, "unable to get dpll ref clk\n"); | 649 | dev_err(dev, "unable to get dpll ref clk\n"); |
| @@ -546,7 +715,7 @@ static int ti_pipe3_get_sysctrl(struct ti_pipe3 *phy) · 65 unmodified lines | |||
| 546 | phy->control_dev = &control_pdev->dev; | 715 | phy->control_dev = &control_pdev->dev; |
| 547 | } | 716 | } |
| 548 | 717 | ||
| 549 | if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { | 718 | if (phy->mode == PIPE3_MODE_PCIE) { |
| 550 | phy->pcs_syscon = syscon_regmap_lookup_by_phandle(node, | 719 | phy->pcs_syscon = syscon_regmap_lookup_by_phandle(node, |
| 551 | "syscon-pcs"); | 720 | "syscon-pcs"); |
| 552 | if (IS_ERR(phy->pcs_syscon)) { | 721 | if (IS_ERR(phy->pcs_syscon)) { |
| @@ -564,7 +733,7 @@ static int ti_pipe3_get_sysctrl(struct ti_pipe3 *phy) · 11 unmodified lines | |||
| 564 | } | 733 | } |
| 565 | } | 734 | } |
| 566 | 735 | ||
| 567 | if (of_device_is_compatible(node, "ti,phy-pipe3-sata")) { | 736 | if (phy->mode == PIPE3_MODE_SATA) { |
| 568 | phy->dpll_reset_syscon = syscon_regmap_lookup_by_phandle(node, | 737 | phy->dpll_reset_syscon = syscon_regmap_lookup_by_phandle(node, |
| 569 | "syscon-pllreset"); | 738 | "syscon-pllreset"); |
| 570 | if (IS_ERR(phy->dpll_reset_syscon)) { | 739 | if (IS_ERR(phy->dpll_reset_syscon)) { |
| @@ -589,12 +758,8 @@ static int ti_pipe3_get_tx_rx_base(struct ti_pipe3 *phy) · 18 unmodified lines | |||
| 589 | { | 758 | { |
| 590 | struct resource *res; | 759 | struct resource *res; |
| 591 | struct device *dev = phy->dev; | 760 | struct device *dev = phy->dev; |
| 592 | struct device_node *node = dev->of_node; | ||
| 593 | struct platform_device *pdev = to_platform_device(dev); | 761 | struct platform_device *pdev = to_platform_device(dev); |
| 594 | 762 | ||
| 595 | if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie")) | ||
| 596 | return 0; | ||
| 597 | |||
| 598 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 763 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 599 | "phy_rx"); | 764 | "phy_rx"); |
| 600 | phy->phy_rx = devm_ioremap_resource(dev, res); | 765 | phy->phy_rx = devm_ioremap_resource(dev, res); |
| @@ -611,24 +776,12 @@ static int ti_pipe3_get_tx_rx_base(struct ti_pipe3 *phy) · 10 unmodified lines | |||
| 611 | static int ti_pipe3_get_pll_base(struct ti_pipe3 *phy) | 776 | static int ti_pipe3_get_pll_base(struct ti_pipe3 *phy) |
| 612 | { | 777 | { |
| 613 | struct resource *res; | 778 | struct resource *res; |
| 614 | const struct of_device_id *match; | ||
| 615 | struct device *dev = phy->dev; | 779 | struct device *dev = phy->dev; |
| 616 | struct device_node *node = dev->of_node; | ||
| 617 | struct platform_device *pdev = to_platform_device(dev); | 780 | struct platform_device *pdev = to_platform_device(dev); |
| 618 | 781 | ||
| 619 | if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) | 782 | if (phy->mode == PIPE3_MODE_PCIE) |
| 620 | return 0; | 783 | return 0; |
| 621 | 784 | ||
| 622 | match = of_match_device(ti_pipe3_id_table, dev); | ||
| 623 | if (!match) | ||
| 624 | return -EINVAL; | ||
| 625 | |||
| 626 | phy->dpll_map = (struct pipe3_dpll_map *)match->data; | ||
| 627 | if (!phy->dpll_map) { | ||
| 628 | dev_err(dev, "no DPLL data\n"); | ||
| 629 | return -EINVAL; | ||
| 630 | } | ||
| 631 | |||
| 632 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 785 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 633 | "pll_ctrl"); | 786 | "pll_ctrl"); |
| 634 | phy->pll_ctrl_base = devm_ioremap_resource(dev, res); | 787 | phy->pll_ctrl_base = devm_ioremap_resource(dev, res); |
| @@ -640,15 +793,29 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 5 unmodified lines | |||
| 640 | struct ti_pipe3 *phy; | 793 | struct ti_pipe3 *phy; |
| 641 | struct phy *generic_phy; | 794 | struct phy *generic_phy; |
| 642 | struct phy_provider *phy_provider; | 795 | struct phy_provider *phy_provider; |
| 643 | struct device_node *node = pdev->dev.of_node; | ||
| 644 | struct device *dev = &pdev->dev; | 796 | struct device *dev = &pdev->dev; |
| 645 | int ret; | 797 | int ret; |
| 798 | const struct of_device_id *match; | ||
| 799 | struct pipe3_data *data; | ||
| 646 | 800 | ||
| 647 | phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); | 801 | phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); |
| 648 | if (!phy) | 802 | if (!phy) |
| 649 | return -ENOMEM; | 803 | return -ENOMEM; |
| 650 | 804 | ||
| 651 | phy->dev = dev; | 805 | match = of_match_device(ti_pipe3_id_table, dev); |
| 806 | if (!match) | ||
| 807 | return -EINVAL; | ||
| 808 | |||
| 809 | data = (struct pipe3_data *)match->data; | ||
| 810 | if (!data) { | ||
| 811 | dev_err(dev, "no driver data\n"); | ||
| 812 | return -EINVAL; | ||
| 813 | } | ||
| 814 | |||
| 815 | phy->dev = dev; | ||
| 816 | phy->mode = data->mode; | ||
| 817 | phy->dpll_map = data->dpll_map; | ||
| 818 | phy->settings = data->settings; | ||
| 652 | 819 | ||
| 653 | ret = ti_pipe3_get_pll_base(phy); | 820 | ret = ti_pipe3_get_pll_base(phy); |
| 654 | if (ret) | 821 | if (ret) |
| @@ -672,7 +839,7 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 17 unmodified lines | |||
| 672 | /* | 839 | /* |
| 673 | * Prevent auto-disable of refclk for SATA PHY due to Errata i783 | 840 | * Prevent auto-disable of refclk for SATA PHY due to Errata i783 |
| 674 | */ | 841 | */ |
| 675 | if (of_device_is_compatible(node, "ti,phy-pipe3-sata")) { | 842 | if (phy->mode == PIPE3_MODE_SATA) { |
| 676 | if (!IS_ERR(phy->refclk)) { | 843 | if (!IS_ERR(phy->refclk)) { |
| 677 | clk_prepare_enable(phy->refclk); | 844 | clk_prepare_enable(phy->refclk); |
| 678 | phy->sata_refclk_enabled = true; | 845 | phy->sata_refclk_enabled = true; |
| @@ -762,18 +929,19 @@ static void ti_pipe3_disable_clocks(struct ti_pipe3 *phy) · 83 unmodified lines | |||
| 762 | static const struct of_device_id ti_pipe3_id_table[] = { | 929 | static const struct of_device_id ti_pipe3_id_table[] = { |
| 763 | { | 930 | { |
| 764 | .compatible = "ti,phy-usb3", | 931 | .compatible = "ti,phy-usb3", |
| 765 | .data = dpll_map_usb, | 932 | .data = &data_usb, |
| 766 | }, | 933 | }, |
| 767 | { | 934 | { |
| 768 | .compatible = "ti,omap-usb3", | 935 | .compatible = "ti,omap-usb3", |
| 769 | .data = dpll_map_usb, | 936 | .data = &data_usb, |
| 770 | }, | 937 | }, |
| 771 | { | 938 | { |
| 772 | .compatible = "ti,phy-pipe3-sata", | 939 | .compatible = "ti,phy-pipe3-sata", |
| 773 | .data = dpll_map_sata, | 940 | .data = &data_sata, |
| 774 | }, | 941 | }, |
| 775 | { | 942 | { |
| 776 | .compatible = "ti,phy-pipe3-pcie", | 943 | .compatible = "ti,phy-pipe3-pcie", |
| 944 | .data = &data_pcie, | ||
| 777 | }, | 945 | }, |
| 778 | {} | 946 | {} |
| 779 | }; | 947 | }; |
| @@ -99,6 +99,7 @@ config SCSI_UFS_DWC_TC_PLATFORM · 98 unmodified lines | |||
| 99 | config SCSI_UFS_QCOM | 99 | config SCSI_UFS_QCOM |
| 100 | tristate "QCOM specific hooks to UFS controller platform driver" | 100 | tristate "QCOM specific hooks to UFS controller platform driver" |
| 101 | depends on SCSI_UFSHCD_PLATFORM && ARCH_QCOM | 101 | depends on SCSI_UFSHCD_PLATFORM && ARCH_QCOM |
| 102 | select RESET_CONTROLLER | ||
| 102 | help | 103 | help |
| 103 | This selects the QCOM specific additions to UFSHCD platform driver. | 104 | This selects the QCOM specific additions to UFSHCD platform driver. |
| 104 | UFS host on QCOM needs some vendor specific configuration before | 105 | UFS host on QCOM needs some vendor specific configuration before |
| @@ -16,6 +16,7 @@ · 15 unmodified lines | |||
| 16 | #include <linux/of.h> | 16 | #include <linux/of.h> |
| 17 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/phy/phy.h> | 18 | #include <linux/phy/phy.h> |
| 19 | #include <linux/reset-controller.h> | ||
| 19 | 20 | ||
| 20 | #include "ufshcd.h" | 21 | #include "ufshcd.h" |
| 21 | #include "ufshcd-pltfrm.h" | 22 | #include "ufshcd-pltfrm.h" |
| @@ -49,6 +50,11 @@ static void ufs_qcom_get_default_testbus_cfg(struct ufs_qcom_host *host); · 27 unmodified lines | |||
| 49 | static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba, | 50 | static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba, |
| 50 | u32 clk_cycles); | 51 | u32 clk_cycles); |
| 51 | 52 | ||
| 53 | static struct ufs_qcom_host *rcdev_to_ufs_host(struct reset_controller_dev *rcd) | ||
| 54 | { | ||
| 55 | return container_of(rcd, struct ufs_qcom_host, rcdev); | ||
| 56 | } | ||
| 57 | |||
| 52 | static void ufs_qcom_dump_regs_wrapper(struct ufs_hba *hba, int offset, int len, | 58 | static void ufs_qcom_dump_regs_wrapper(struct ufs_hba *hba, int offset, int len, |
| 53 | const char *prefix, void *priv) | 59 | const char *prefix, void *priv) |
| 54 | { | 60 | { |
| @@ -255,11 +261,6 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) · 200 unmodified lines | |||
| 255 | if (is_rate_B) | 261 | if (is_rate_B) |
| 256 | phy_set_mode(phy, PHY_MODE_UFS_HS_B); | 262 | phy_set_mode(phy, PHY_MODE_UFS_HS_B); |
| 257 | 263 | ||
| 258 | /* Assert PHY reset and apply PHY calibration values */ | ||
| 259 | ufs_qcom_assert_reset(hba); | ||
| 260 | /* provide 1ms delay to let the reset pulse propagate */ | ||
| 261 | usleep_range(1000, 1100); | ||
| 262 | |||
| 263 | /* phy initialization - calibrate the phy */ | 264 | /* phy initialization - calibrate the phy */ |
| 264 | ret = phy_init(phy); | 265 | ret = phy_init(phy); |
| 265 | if (ret) { | 266 | if (ret) { |
| @@ -268,15 +269,6 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) · 2 unmodified lines | |||
| 268 | goto out; | 269 | goto out; |
| 269 | } | 270 | } |
| 270 | 271 | ||
| 271 | /* De-assert PHY reset and start serdes */ | ||
| 272 | ufs_qcom_deassert_reset(hba); | ||
| 273 | |||
| 274 | /* | ||
| 275 | * after reset deassertion, phy will need all ref clocks, | ||
| 276 | * voltage, current to settle down before starting serdes. | ||
| 277 | */ | ||
| 278 | usleep_range(1000, 1100); | ||
| 279 | |||
| 280 | /* power on phy - start serdes and phy's power and clocks */ | 272 | /* power on phy - start serdes and phy's power and clocks */ |
| 281 | ret = phy_power_on(phy); | 273 | ret = phy_power_on(phy); |
| 282 | if (ret) { | 274 | if (ret) { |
| @@ -290,7 +282,6 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) · 7 unmodified lines | |||
| 290 | return 0; | 282 | return 0; |
| 291 | 283 | ||
| 292 | out_disable_phy: | 284 | out_disable_phy: |
| 293 | ufs_qcom_assert_reset(hba); | ||
| 294 | phy_exit(phy); | 285 | phy_exit(phy); |
| 295 | out: | 286 | out: |
| 296 | return ret; | 287 | return ret; |
| @@ -554,21 +545,10 @@ static int ufs_qcom_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) · 257 unmodified lines | |||
| 554 | ufs_qcom_disable_lane_clks(host); | 545 | ufs_qcom_disable_lane_clks(host); |
| 555 | phy_power_off(phy); | 546 | phy_power_off(phy); |
| 556 | 547 | ||
| 557 | /* Assert PHY soft reset */ | 548 | } else if (!ufs_qcom_is_link_active(hba)) { |
| 558 | ufs_qcom_assert_reset(hba); | ||
| 559 | goto out; | ||
| 560 | } | ||
| 561 | |||
| 562 | /* | ||
| 563 | * If UniPro link is not active, PHY ref_clk, main PHY analog power | ||
| 564 | * rail and low noise analog power rail for PLL can be switched off. | ||
| 565 | */ | ||
| 566 | if (!ufs_qcom_is_link_active(hba)) { | ||
| 567 | ufs_qcom_disable_lane_clks(host); | 549 | ufs_qcom_disable_lane_clks(host); |
| 568 | phy_power_off(phy); | ||
| 569 | } | 550 | } |
| 570 | 551 | ||
| 571 | out: | ||
| 572 | return ret; | 552 | return ret; |
| 573 | } | 553 | } |
| 574 | 554 | ||
| @@ -578,21 +558,26 @@ static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) · 3 unmodified lines | |||
| 578 | struct phy *phy = host->generic_phy; | 558 | struct phy *phy = host->generic_phy; |
| 579 | int err; | 559 | int err; |
| 580 | 560 | ||
| 581 | err = phy_power_on(phy); | 561 | if (ufs_qcom_is_link_off(hba)) { |
| 582 | if (err) { | 562 | err = phy_power_on(phy); |
| 583 | dev_err(hba->dev, "%s: failed enabling regs, err = %d\n", | 563 | if (err) { |
| 584 | __func__, err); | 564 | dev_err(hba->dev, "%s: failed PHY power on: %d\n", |
| 585 | goto out; | 565 | __func__, err); |
| 586 | } | 566 | return err; |
| 567 | } | ||
| 587 | 568 | ||
| 588 | err = ufs_qcom_enable_lane_clks(host); | 569 | err = ufs_qcom_enable_lane_clks(host); |
| 589 | if (err) | 570 | if (err) |
| 590 | goto out; | 571 | return err; |
| 591 | 572 | ||
| 592 | hba->is_sys_suspended = false; | 573 | } else if (!ufs_qcom_is_link_active(hba)) { |
| 574 | err = ufs_qcom_enable_lane_clks(host); | ||
| 575 | if (err) | ||
| 576 | return err; | ||
| 577 | } | ||
| 593 | 578 | ||
| 594 | out: | 579 | hba->is_sys_suspended = false; |
| 595 | return err; | 580 | return 0; |
| 596 | } | 581 | } |
| 597 | 582 | ||
| 598 | struct ufs_qcom_dev_params { | 583 | struct ufs_qcom_dev_params { |
| @@ -1118,8 +1103,6 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, · 519 unmodified lines | |||
| 1118 | return 0; | 1103 | return 0; |
| 1119 | 1104 | ||
| 1120 | if (on && (status == POST_CHANGE)) { | 1105 | if (on && (status == POST_CHANGE)) { |
| 1121 | phy_power_on(host->generic_phy); | ||
| 1122 | |||
| 1123 | /* enable the device ref clock for HS mode*/ | 1106 | /* enable the device ref clock for HS mode*/ |
| 1124 | if (ufshcd_is_hs_mode(&hba->pwr_info)) | 1107 | if (ufshcd_is_hs_mode(&hba->pwr_info)) |
| 1125 | ufs_qcom_dev_ref_clk_ctrl(host, true); | 1108 | ufs_qcom_dev_ref_clk_ctrl(host, true); |
| @@ -1131,9 +1114,6 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, · 5 unmodified lines | |||
| 1131 | if (!ufs_qcom_is_link_active(hba)) { | 1114 | if (!ufs_qcom_is_link_active(hba)) { |
| 1132 | /* disable device ref_clk */ | 1115 | /* disable device ref_clk */ |
| 1133 | ufs_qcom_dev_ref_clk_ctrl(host, false); | 1116 | ufs_qcom_dev_ref_clk_ctrl(host, false); |
| 1134 | |||
| 1135 | /* powering off PHY during aggressive clk gating */ | ||
| 1136 | phy_power_off(host->generic_phy); | ||
| 1137 | } | 1117 | } |
| 1138 | 1118 | ||
| 1139 | vote = host->bus_vote.min_bw_vote; | 1119 | vote = host->bus_vote.min_bw_vote; |
| @@ -1147,6 +1127,41 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, · 7 unmodified lines | |||
| 1147 | return err; | 1127 | return err; |
| 1148 | } | 1128 | } |
| 1149 | 1129 | ||
| 1130 | static int | ||
| 1131 | ufs_qcom_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) | ||
| 1132 | { | ||
| 1133 | struct ufs_qcom_host *host = rcdev_to_ufs_host(rcdev); | ||
| 1134 | |||
| 1135 | /* Currently this code only knows about a single reset. */ | ||
| 1136 | WARN_ON(id); | ||
| 1137 | ufs_qcom_assert_reset(host->hba); | ||
| 1138 | /* provide 1ms delay to let the reset pulse propagate. */ | ||
| 1139 | usleep_range(1000, 1100); | ||
| 1140 | return 0; | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | static int | ||
| 1144 | ufs_qcom_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) | ||
| 1145 | { | ||
| 1146 | struct ufs_qcom_host *host = rcdev_to_ufs_host(rcdev); | ||
| 1147 | |||
| 1148 | /* Currently this code only knows about a single reset. */ | ||
| 1149 | WARN_ON(id); | ||
| 1150 | ufs_qcom_deassert_reset(host->hba); | ||
| 1151 | |||
| 1152 | /* | ||
| 1153 | * after reset deassertion, phy will need all ref clocks, | ||
| 1154 | * voltage, current to settle down before starting serdes. | ||
| 1155 | */ | ||
| 1156 | usleep_range(1000, 1100); | ||
| 1157 | return 0; | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | static const struct reset_control_ops ufs_qcom_reset_ops = { | ||
| 1161 | .assert = ufs_qcom_reset_assert, | ||
| 1162 | .deassert = ufs_qcom_reset_deassert, | ||
| 1163 | }; | ||
| 1164 | |||
| 1150 | #define ANDROID_BOOT_DEV_MAX 30 | 1165 | #define ANDROID_BOOT_DEV_MAX 30 |
| 1151 | static char android_boot_dev[ANDROID_BOOT_DEV_MAX]; | 1166 | static char android_boot_dev[ANDROID_BOOT_DEV_MAX]; |
| 1152 | 1167 | ||
| @@ -1191,6 +1206,17 @@ static int ufs_qcom_init(struct ufs_hba *hba) · 38 unmodified lines | |||
| 1191 | host->hba = hba; | 1206 | host->hba = hba; |
| 1192 | ufshcd_set_variant(hba, host); | 1207 | ufshcd_set_variant(hba, host); |
| 1193 | 1208 | ||
| 1209 | /* Fire up the reset controller. Failure here is non-fatal. */ | ||
| 1210 | host->rcdev.of_node = dev->of_node; | ||
| 1211 | host->rcdev.ops = &ufs_qcom_reset_ops; | ||
| 1212 | host->rcdev.owner = dev->driver->owner; | ||
| 1213 | host->rcdev.nr_resets = 1; | ||
| 1214 | err = devm_reset_controller_register(dev, &host->rcdev); | ||
| 1215 | if (err) { | ||
| 1216 | dev_warn(dev, "Failed to register reset controller\n"); | ||
| 1217 | err = 0; | ||
| 1218 | } | ||
| 1219 | |||
| 1194 | /* | 1220 | /* |
| 1195 | * voting/devoting device ref_clk source is time consuming hence | 1221 | * voting/devoting device ref_clk source is time consuming hence |
| 1196 | * skip devoting it during aggressive clock gating. This clock | 1222 | * skip devoting it during aggressive clock gating. This clock |
| @@ -14,6 +14,8 @@ · 13 unmodified lines | |||
| 14 | #ifndef UFS_QCOM_H_ | 14 | #ifndef UFS_QCOM_H_ |
| 15 | #define UFS_QCOM_H_ | 15 | #define UFS_QCOM_H_ |
| 16 | 16 | ||
| 17 | #include <linux/reset-controller.h> | ||
| 18 | |||
| 17 | #define MAX_UFS_QCOM_HOSTS 1 | 19 | #define MAX_UFS_QCOM_HOSTS 1 |
| 18 | #define MAX_U32 (~(u32)0) | 20 | #define MAX_U32 (~(u32)0) |
| 19 | #define MPHY_TX_FSM_STATE 0x41 | 21 | #define MPHY_TX_FSM_STATE 0x41 |
| @@ -237,6 +239,8 @@ struct ufs_qcom_host { · 217 unmodified lines | |||
| 237 | /* Bitmask for enabling debug prints */ | 239 | /* Bitmask for enabling debug prints */ |
| 238 | u32 dbg_print_en; | 240 | u32 dbg_print_en; |
| 239 | struct ufs_qcom_testbus testbus; | 241 | struct ufs_qcom_testbus testbus; |
| 242 | |||
| 243 | struct reset_controller_dev rcdev; | ||
| 240 | }; | 244 | }; |
| 241 | 245 | ||
| 242 | static inline u32 | 246 | static inline u32 |
| @@ -0,0 +1,13 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * This header provides constants for AM654 SERDES. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _DT_BINDINGS_AM654_SERDES | ||
| 7 | #define _DT_BINDINGS_AM654_SERDES | ||
| 8 | |||
| 9 | #define AM654_SERDES_CMU_REFCLK 0 | ||
| 10 | #define AM654_SERDES_LO_REFCLK 1 | ||
| 11 | #define AM654_SERDES_RO_REFCLK 2 | ||
| 12 | |||
| 13 | #endif /* _DT_BINDINGS_AM654_SERDES */ | ||
| @@ -64,6 +64,7 @@ union phy_configure_opts { · 63 unmodified lines | |||
| 64 | * @set_mode: set the mode of the phy | 64 | * @set_mode: set the mode of the phy |
| 65 | * @reset: resetting the phy | 65 | * @reset: resetting the phy |
| 66 | * @calibrate: calibrate the phy | 66 | * @calibrate: calibrate the phy |
| 67 | * @release: ops to be performed while the consumer relinquishes the PHY | ||
| 67 | * @owner: the module owner containing the ops | 68 | * @owner: the module owner containing the ops |
| 68 | */ | 69 | */ |
| 69 | struct phy_ops { | 70 | struct phy_ops { |
| @@ -105,6 +106,7 @@ struct phy_ops { · 35 unmodified lines | |||
| 105 | union phy_configure_opts *opts); | 106 | union phy_configure_opts *opts); |
| 106 | int (*reset)(struct phy *phy); | 107 | int (*reset)(struct phy *phy); |
| 107 | int (*calibrate)(struct phy *phy); | 108 | int (*calibrate)(struct phy *phy); |
| 109 | void (*release)(struct phy *phy); | ||
| 108 | struct module *owner; | 110 | struct module *owner; |
| 109 | }; | 111 | }; |
| 110 | 112 | ||