phy: qualcomm: add qcom ipq806x dwc usb phy driver
PATCH v9 1/2 phy: qualcomm: add qcom ipq806x dwc usb phy driver
This has lost in the original push for the dwc3 qcom driver. This is needed for ipq806x SoC as without this the usb ports doesn't work at all.
---
v9:
* Use device_property_read_u32 and skip compatible check v8:
* Drop useless init
* Drop invalid copyright
v7:
* Add TestedBy tag
v6:
* Use GENMASK instead of hex value
v4:
* Add qcom to specific bindings
v3:
* Use reg instead of regmap phandle
v2:
* Renamed config from PHY_QCOM_DWC3 to PHY_QCOM_IPQ806X_USB
* Rename inline function to generic name to reduce length
* Fix check reported by checkpatch --strict
* Rename compatible to qcom,ipq806x-usb-phy-(hs/ss)
drivers/phy/qualcomm/Kconfig | 11 + drivers/phy/qualcomm/Makefile | 1 + drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c | 575 ++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c
drivers/phy/qualcomm/Kconfig +11 -0
@@ -91,3 +91,14 @@ config PHY_QCOM_USB_HSIC select GENERIC_PHY help Support for the USB HSIC ULPI compliant PHY on QCOM chipsets. + +config PHY_QCOM_IPQ806X_USB + tristate "Qualcomm IPQ806x DWC3 USB PHY driver" + depends on HAS_IOMEM + depends on OF && (ARCH_QCOM || COMPILE_TEST) + select GENERIC_PHY + help + This option enables support for the Synopsis PHYs present inside the + Qualcomm USB3.0 DWC3 controller on ipq806x SoC. This driver supports + both HS and SS PHY controllers. +
drivers/phy/qualcomm/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_PHY_QCOM_UFS_14NM) += phy-qcom-ufs-qmp-14nm.o obj-$(CONFIG_PHY_QCOM_UFS_20NM) += phy-qcom-ufs-qmp-20nm.o obj-$(CONFIG_PHY_QCOM_USB_HS) += phy-qcom-usb-hs.o obj-$(CONFIG_PHY_QCOM_USB_HSIC) += phy-qcom-usb-hsic.o +obj-$(CONFIG_PHY_QCOM_IPQ806X_USB) += phy-qcom-ipq806x-usb.o
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +575 -0
575 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v9 2/2 devicetree: bindings: phy: Document ipq806x dwc3 qcom phy
Document dwc3 qcom phy hs and ss phy bindings needed to correctly inizialize and use usb on ipq806x SoC.
---
v7:
* Drop useless AllOf
v6:
* Add maximum value
v5:
* Fix dt_binding_check error
v4:
* Add qcom to specific bindings
v3:
* Use explicit reg instead of regmap
.../bindings/phy/qcom,ipq806x-usb-phy-hs.yaml | 55 ++++++++++++++ .../bindings/phy/qcom,ipq806x-usb-phy-ss.yaml | 73 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom,ipq806x-usb-phy-hs.yaml create mode 100644 Documentation/devicetree/bindings/phy/qcom,ipq806x-usb-phy-ss.yaml
Documentation/devicetree/bindings/phy/qcom,ipq806x-usb-phy-hs.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/qcom,ipq806x-usb-phy-hs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm ipq806x usb DWC3 HS PHY CONTROLLER + +maintainers: + - Ansuel Smith <[email protected]> + +description: + DWC3 PHY nodes are defined to describe on-chip Synopsis Physical layer + controllers used in ipq806x. Each DWC3 PHY controller should have its + own node. + +properties: + compatible: + const: qcom,ipq806x-usb-phy-hs + + "#phy-cells": + const: 0 + + reg: + maxItems: 1 + + clocks: + minItems: 1 + maxItems: 2 + + clock-names: + minItems: 1 + maxItems: 2 + items: + - const: ref + - const: xo + +required: + - compatible + - "#phy-cells" + - reg + - clocks + - clock-names + +examples: + - | + #include <dt-bindings/clock/qcom,gcc-ipq806x.h> + + hs_phy_0: phy@110f8800 { + compatible = "qcom,ipq806x-usb-phy-hs"; + reg = <0x110f8800 0x30>; + clocks = <&gcc USB30_0_UTMI_CLK>; + clock-names = "ref"; + #phy-cells = <0>; + };
Documentation/devicetree/bindings/phy/qcom,ipq806x-usb-phy-ss.yaml new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.27.0
Vinod Koul
maintainerQuoted 60 lines · Ansuel Smith
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +60
-0+static int qcom_ipq806x_usb_ss_phy_init (struct phy *phy) +{ +struct usb_phy *phy_dwc3 =phy_get_drvdata (phy); +int ret; +u32 data; + + ret =clk_prepare_enable (phy_dwc3->xo_clk); +if (ret) +return ret; + + ret =clk_prepare_enable (phy_dwc3->ref_clk); +if (ret) { +clk_disable_unprepare (phy_dwc3->xo_clk); +return ret; + } + +/* reset phy */ + data =readl (phy_dwc3->base +SSUSB_PHY_CTRL_REG ); +writel (data |SSUSB_CTRL_SS_PHY_RESET , + phy_dwc3->base +SSUSB_PHY_CTRL_REG ); +usleep_range (2000 ,2200 ); +writel (data, phy_dwc3->base +SSUSB_PHY_CTRL_REG ); + +/* clear REF_PAD if we don't have XO clk */ +if (!phy_dwc3->xo_clk) + data &= ~SSUSB_CTRL_REF_USE_PAD ; +else + data |=SSUSB_CTRL_REF_USE_PAD ; + +writel (data, phy_dwc3->base +SSUSB_PHY_CTRL_REG ); + +/* wait for ref clk to become stable, this can take up to 30ms */ +msleep (30 ); + + data |=SSUSB_CTRL_SS_PHY_EN |SSUSB_CTRL_LANE0_PWR_PRESENT ; +writel (data, phy_dwc3->base +SSUSB_PHY_CTRL_REG ); + +/* +* WORKAROUND: There is SSPHY suspend bug due to which USB enumerates +* in HS mode instead of SS mode. Workaround it by asserting +* LANE0.TX_ALT_BLOCK.EN_ALT_BUS to enable TX to use alt bus mode +*/ + ret =usb_ss_read_phycreg (phy_dwc3,0x102D , &data); +if (ret) + goto err_phy_trans; + + data |= (1 <<7 ); + ret =usb_ss_write_phycreg (phy_dwc3,0x102D , data); +if (ret) + goto err_phy_trans; + + ret =usb_ss_read_phycreg (phy_dwc3,0x1010 , &data); +if (ret) + goto err_phy_trans; + + data &= ~0xff0 ; + data |=0x20 ; + ret =usb_ss_write_phycreg (phy_dwc3,0x1010 , data); +if (ret) + goto err_phy_trans;
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c line 374
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +10
-0+ +/* +* Fix RX Equalization setting as follows +* LANE0.RX_OVRD_IN_HI. RX_EQ_EN set to 0 +* LANE0.RX_OVRD_IN_HI.RX_EQ_EN_OVRD set to 1 +* LANE0.RX_OVRD_IN_HI.RX_EQ set based on SoC version +* LANE0.RX_OVRD_IN_HI.RX_EQ_OVRD set to 1 +*/ + ret =usb_ss_read_phycreg (phy_dwc3, +SSPHY_CTRL_RX_OVRD_IN_HI (0 ), &data);
nit: I think this would fit in single line and make a better read :)
Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +6
-0+static int qcom_ipq806x_usb_phy_probe (struct platform_device *pdev) +{ +struct resource *res; +resource_size_t size; +struct phy *generic_phy; +struct usb_phy *phy_dwc3;
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c line 501
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +10
-0+const struct phy_drvdata *data; +const struct of_device_id *match; +struct phy_provider *phy_provider; + + phy_dwc3 =devm_kzalloc (&pdev->dev,sizeof (*phy_dwc3),GFP_KERNEL ); +if (!phy_dwc3) +return -ENOMEM ; + + match =of_match_node (qcom_ipq806x_usb_phy_table, pdev->dev.of_node); + data = match->data;
you don't need the match node anymore and can use of_device_get_match_data() my original question on this :)
Quoted 32 lines
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +32
-0+ + phy_dwc3->dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + size =resource_size (res); + phy_dwc3->base =devm_ioremap (phy_dwc3->dev, res->start, size); + +if (IS_ERR (phy_dwc3->base)) { +dev_err (phy_dwc3->dev,"failed to map reg\n" ); +return PTR_ERR (phy_dwc3->base); + } + + phy_dwc3->ref_clk =devm_clk_get (phy_dwc3->dev,"ref" ); +if (IS_ERR (phy_dwc3->ref_clk)) { +dev_dbg (phy_dwc3->dev,"cannot get reference clock\n" ); +return PTR_ERR (phy_dwc3->ref_clk); + } + +clk_set_rate (phy_dwc3->ref_clk, data->clk_rate); + + phy_dwc3->xo_clk =devm_clk_get (phy_dwc3->dev,"xo" ); +if (IS_ERR (phy_dwc3->xo_clk)) { +dev_dbg (phy_dwc3->dev,"cannot get TCXO clock\n" ); + phy_dwc3->xo_clk =NULL ; + } + +/* Parse device node to probe HSIO settings */ +if (device_property_read_u32 (&pdev->dev,"qcom,rx-eq" , + &phy_dwc3->rx_eq)) + phy_dwc3->rx_eq =SSPHY_RX_EQ_VALUE ;
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c line 543
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c new file +10
-0+ +if (device_property_read_u32 (&pdev->dev,"qcom,tx-deamp_3_5db" , + &phy_dwc3->tx_deamp_3_5db)) + phy_dwc3->rx_eq =SSPHY_TX_DEEMPH_3_5DB ; + +if (device_property_read_u32 (&pdev->dev,"qcom,mpll" , &phy_dwc3->mpll)) + phy_dwc3->mpll =SSPHY_MPLL_VALUE ; + + generic_phy =devm_phy_create (phy_dwc3->dev, pdev->dev.of_node, + &data->ops);
nitpick, this could be single line as well
Signature · 1 line
~Vinod