phy: USB and PCIe phy drivers for Qcom chipsets
v5 cover phy: USB and PCIe phy drivers for Qcom chipsets
This patch series adds couple of PHY drivers for Qualcomm chipsets.
a) qcom-qusb2 phy driver: that provides High Speed USB functionality.
b) qcom-qmp phy driver: that is a combo phy providing support for USB3, PCIe, UFS and few other controllers.
The patches are based on next branch of linux-phy tree.
These patches have been tested on Dragon board db820c hardware with required set of dt patches and the patches to get rpm up on msm8996. Couple of other patches [1, 2] fixing DMA config for XHCI are also pulled in for testing.
The complete branch is available in github [3].
Changes since v4:
- Addressed comment to add child nodes for qmp phy driver. Each phy lane now has a separate child node under the main qmp node.
- Modified the clock and reset initialization and enable methods. Different phys - pcie, usb and later ufs, have varying number of clocks and resets that are mandatory. So adding provision for clocks and reset lists helps in requesting all mandatory resources for individual phys and handle their failure cases accordingly.
Changes since v3:
- Addressed review comments given by Rob and Stephen for qusb2 phy and qmp phy bindings respectively.
- Addressed review comments given by Stephen and Bjorn for qmp phy driver.
Changes since v2:
- Addressed review comments given by Rob and Stephen for bindings.
- Addressed the review comments given by Stephen for the qusb2 and qmp phy drivers.
Changes since v1:
- Moved device tree binding documentation to separate patches, as suggested by Rob.
- Addressed review comment regarding qfprom accesses by qusb2 phy driver, given by Rob.
- Addressed review comments from Kishon.
- Addressed review comments from Srinivas for QMP phy driver.
- Addressed kbuild warning.
Please see individual patches for detailed changelogs.
[1] https://patchwork.kernel.org/patch/9567767/
[2] https://patchwork.kernel.org/patch/9567779/
[3] https://github.com/vivekgautam1/linux/tree/linux-v4.11-rc1-qmp-phy-db820c
Vivek Gautam (4):
dt-bindings: phy: Add support for QUSB2 phy
phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips
dt-bindings: phy: Add support for QMP phy
phy: qcom-qmp: new qmp phy driver for qcom-chipsets
.../devicetree/bindings/phy/qcom-qmp-phy.txt | 106 ++ .../devicetree/bindings/phy/qcom-qusb2-phy.txt | 45 + drivers/phy/Kconfig | 18 + drivers/phy/Makefile | 2 + drivers/phy/phy-qcom-qmp.c | 1191 ++++++++++++++++++++ drivers/phy/phy-qcom-qusb2.c | 539 +++++++++ 6 files changed, 1901 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt create mode 100644 Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt create mode 100644 drivers/phy/phy-qcom-qmp.c create mode 100644 drivers/phy/phy-qcom-qusb2.c
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 1/4 dt-bindings: phy: Add support for QUSB2 phy
Qualcomm chipsets have QUSB2 phy controller that provides HighSpeed functionality for DWC3 controller. Adding dt binding information for the same.
---
Changes since v4:
- None.
Changes since v3:
- Added 'Acked-by' from Rob.
- Removed 'reset-names' and 'nvmem-cell-names' from the bindings since we use only one cell.
Changes since v2:
- Removed binding for "ref_clk_src" since we don't request this clock in the driver.
- Addressed s/vdda-phy-dpdm/vdda-phy-dpdm-supply.
- Addressed s/ref_clk/ref. Don't need to add '_clk' suffix to clock names.
- Addressed s/tune2_hstx_trim_efuse/tune2_hstx_trim. Don't need to add 'efuse' suffix to nvmem cell.
- Addressed s/qusb2phy/phy for the node name.
Changes since v1:
- New patch, forked out of the original driver patch:
"phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips"
- Updated dt bindings to remove 'hstx-trim-bit-offset' and 'hstx-trim-bit-len' bindings.
.../devicetree/bindings/phy/qcom-qusb2-phy.txt | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt
Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt new file +45 -0
@@ -0,0 +1,45 @@ +Qualcomm QUSB2 phy controller +============================= + +QUSB2 controller supports LS/FS/HS usb connectivity on Qualcomm chipsets. + +Required properties: + - compatible: compatible list, contains "qcom,msm8996-qusb2-phy". + - reg: offset and length of the PHY register set. + - #phy-cells: must be 0. + + - clocks: a list of phandles and clock-specifier pairs, + one for each entry in clock-names. + - clock-names: must be "cfg_ahb" for phy config clock, + "ref" for 19.2 MHz ref clk, + "iface" for phy interface clock (Optional). + + - vdd-phy-supply: Phandle to a regulator supply to PHY core block. + - vdda-pll-supply: Phandle to 1.8V regulator supply to PHY refclk pll block. + - vdda-phy-dpdm-supply: Phandle to 3.1V regulator supply to Dp/Dm port signals. + + - resets: Phandle to reset to phy block. + +Optional properties: + - nvmem-cells: Phandle to nvmem cell that contains 'HS Tx trim' + tuning parameter value for qusb2 phy. + + - qcom,tcsr-syscon: Phandle to TCSR syscon register region. + +Example: + hsusb_phy: phy@7411000 { + compatible = "qcom,msm8996-qusb2-phy"; + reg = <0x07411000 0x180>; + #phy-cells = <0>; + + clocks = <&gcc GCC_USB_PHY_CFG_AHB2PHY_CLK>, + <&gcc GCC_RX1_USB2_CLKREF_CLK>, + clock-names = "cfg_ahb", "ref"; + + vdd-phy-supply = <&pm8994_s2>; + vdda-pll-supply = <&pm8994_l12>; + vdda-phy-dpdm-supply = <&pm8994_l24>; + + resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>; + nvmem-cells = <&qusb2p_hstx_trim>; + };
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 2/4 phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips
In reply to Vivek GautamPHY transceiver driver for QUSB2 phy controller that provides HighSpeed functionality for DWC3 controller present on Qualcomm chipsets.
---
Changes since v4:
- Updated the copyright year to 2017.
- Removed unnecessary of_match_ptr() cast for the match table, since the driver is compiled for CONFIG_OF.
Changes since v3:
- Added 'Reviewed-by' from Stephen.
- Fixed debug message for qusb2_phy_set_tune2_param().
- Replaced devm_reset_control_get() with devm_reset_control_get_by_index() since we are requesting only one reset.
- Updated devm_nvmem_cell_get() with a NULL cell id.
- Made error labels more idiomatic.
- Refactored qusb2_setbits() and qusb2_clrbits() a little bit to accept base address and register offset as two separate arguments.
Changes since v2:
- Removed selecting 'RESET_CONTROLLER' config.
- Added error handling for clk_prepare_enable paths.
- Removed explicitly setting ref_clk rate to 19.2 MHz. Don't need to do that since 'xo' is modeled as parent to this clock.
- Removed 'ref_clk_src' handling. Driver doesn't need to request and handle this clock.
- Moved nvmem_cell_get() to probe function.
- Simplified phy pll status handling.
- Using of_device_get_match_data() to get match data.
- Uniformly using lowercase for hex numbers.
- Fixed sparse warnings.
- Using shorter variable names in structure and in functions.
- Handling various comment style shortcomings.
Changes since v1:
- removed reference to clk_enabled/pwr_enabled.
- moved clock and regulator enable code to phy_power_on/off() callbacks.
- fixed return on EPROBE_DEFER in qusb2_phy_probe().
- fixed phy create and phy register ordering.
- removed references to non-lkml links from commit message.
- took care of other minor nits.
- Fixed coccinelle warnings -
'PTR_ERR applied after initialization to constant'
- Addressed review comment, regarding qfprom access for tune2 param value. This driver is now based on qfprom patch[1] that allows byte access now.
drivers/phy/Kconfig | 10 + drivers/phy/Makefile | 1 + drivers/phy/phy-qcom-qusb2.c | 539 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 550 insertions(+) create mode 100644 drivers/phy/phy-qcom-qusb2.c
drivers/phy/Kconfig +10 -0
@@ -439,6 +439,16 @@ config PHY_STIH407_USB Enable this support to enable the picoPHY device used by USB2 and USB3 controllers on STMicroelectronics STiH407 SoC families. +config PHY_QCOM_QUSB2 + tristate "Qualcomm QUSB2 PHY Driver" + depends on OF && (ARCH_QCOM || COMPILE_TEST) + select GENERIC_PHY + help + Enable this to support the HighSpeed QUSB2 PHY transceiver for USB + controllers on Qualcomm chips. This driver supports the high-speed + PHY which is usually paired with either the ChipIdea or Synopsys DWC3 + USB IPs on MSM SOCs. + config PHY_QCOM_UFS tristate "Qualcomm UFS PHY driver" depends on OF && ARCH_QCOM
drivers/phy/Makefile +1 -0
@@ -50,6 +50,7 @@ obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o obj-$(CONFIG_PHY_XGENE) += phy-xgene.o obj-$(CONFIG_PHY_STIH407_USB) += phy-stih407-usb.o +obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-20nm.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-14nm.o
drivers/phy/phy-qcom-qusb2.c new file +539 -0
539 lines not on this page · raw message
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 2/4] phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips
On Thu 09 Mar 10:07 CET 2017, Vivek Gautam wrote:
[..]
drivers/phy/phy-qcom-qusb2.c line 146
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+static inline void qusb2_setbits (void __iomem *base,u32 offset,u32 val) +{ +u32 reg; + + reg =readl_relaxed (base + offset); + reg |= val; +writel_relaxed (reg, base + offset); + +/* Ensure above write is completed */ +mb ();
mb() does not ensure that the operation is completed, it only ensures ordering between this write and subsequent memory accesses.
Unless you have specific reasons to you should not use the _relaxed() versions of read and write operations. Using the non-relaxed versions will ensure that your memory operations are not reordered.
drivers/phy/phy-qcom-qusb2.c line 158
Quoted 12 lines
drivers/phy/phy-qcom-qusb2.c new file +12
-0+} + +static inline void qusb2_clrbits (void __iomem *base,u32 offset,u32 val) +{ +u32 reg; + + reg =readl_relaxed (base + offset); + reg &= ~val; +writel_relaxed (reg, base + offset); + +/* Ensure above write is completed */ +mb ();
Dito.
drivers/phy/phy-qcom-qusb2.c line 171
Quoted 13 lines
drivers/phy/phy-qcom-qusb2.c new file +13
-0+} + +static inline void qcom_qusb2_phy_configure (void __iomem *base, +const struct qusb2_phy_init_tbl tbl[], +int num) +{ +int i; + +for (i =0 ; i < num; i++) +writel_relaxed (tbl[i].val, base + tbl[i].offset); + +/* flush buffered writes */ +mb ();
Dito.
drivers/phy/phy-qcom-qusb2.c line 182
Quoted 11 lines
drivers/phy/phy-qcom-qusb2.c new file +11
-0+} + +static int qusb2_phy_toggle_power (struct qusb2_phy *qphy,bool on) +{ +struct device *dev = &qphy->phy->dev; +int ret; + +if (!on) { + ret =0 ; + goto disable_vdda_phy_dpdm; + }
This is an ugly hack.
Quoted 23 lines
drivers/phy/phy-qcom-qusb2.c new file +23
-0+ + ret =regulator_enable (qphy->vdd_phy); +if (ret) { +dev_err (dev,"failed to enable vdd-phy, %d\n" , ret); + goto err_vdd_phy; + } + + ret =regulator_enable (qphy->vdda_pll); +if (ret) { +dev_err (dev,"failed to enable vdda-pll, %d\n" , ret); + goto disable_vdd_phy; + } + + ret =regulator_enable (qphy->vdda_phy_dpdm); +if (ret) { +dev_err (dev,"failed to enable vdda-phy-dpdm, %d\n" , ret); + goto disable_vdda_pll; + } + +dev_vdbg (dev,"%s(): regulators are turned on\n" , __func__); + +return ret; +
drivers/phy/phy-qcom-qusb2.c line 215
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+disable_vdda_phy_dpdm: +regulator_disable (qphy->vdda_phy_dpdm); +disable_vdda_pll: +regulator_disable (qphy->vdda_pll); +disable_vdd_phy: +regulator_disable (qphy->vdd_phy); +err_vdd_phy: +dev_vdbg (dev,"%s(): regulators are turned off\n" , __func__); +return ret; +}
If you use the regulator_bulk interface for your regulators you can replace this entire function with a call to regulator_bulk_enable() and regulator_bulk_disable().
Quoted 27 lines
drivers/phy/phy-qcom-qusb2.c new file +27
-0+ +/* +* Fetches HS Tx tuning value from nvmem and sets the +* QUSB2PHY_PORT_TUNE2 register. +* For error case, skip setting the value and use the default value. +*/ +static void qusb2_phy_set_tune2_param (struct qusb2_phy *qphy) +{ +struct device *dev = &qphy->phy->dev; +u8 *val; + +/* +* Read efuse register having TUNE2 parameter's high nibble. +* If efuse register shows value as 0x0, or if we fail to find +* a valid efuse register settings, then use default value +* as 0xB for high nibble that we have already set while +* configuring phy. +*/ + val =nvmem_cell_read (qphy->cell,NULL ); +if (IS_ERR (val) || !val[0 ]) { +dev_dbg (dev,"failed to read a valid hs-tx trim value\n" ); +return ; + } + +/* Fused TUNE2 value is the higher nibble only */ +qusb2_setbits (qphy->base,QUSB2PHY_PORT_TUNE2 , val[0 ] <<0x4 ); +}
drivers/phy/phy-qcom-qusb2.c line 252
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+ +static int qusb2_phy_poweron (struct phy *phy) +{ +struct qusb2_phy *qphy =phy_get_drvdata (phy); +int ret; + +dev_vdbg (&phy->dev,"%s(): Powering-on QUSB2 phy\n" , __func__); + +/* turn on regulator supplies */ + ret =qusb2_phy_toggle_power (qphy, true);
Call regulator_bulk_enable()
Quoted 7 lines
drivers/phy/phy-qcom-qusb2.c new file +7
-0+if (ret) +return ret; + + ret =clk_prepare_enable (qphy->iface_clk); +if (ret) +dev_err (&phy->dev,"failed to enable iface_clk, %d\n" , ret); +
drivers/phy/phy-qcom-qusb2.c line 269
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+return ret; +} + +static int qusb2_phy_poweroff (struct phy *phy) +{ +struct qusb2_phy *qphy =phy_get_drvdata (phy); + +clk_disable_unprepare (qphy->iface_clk); + +qusb2_phy_toggle_power (qphy, false);
Call regulator_bulk_disable()
Quoted 42 lines
drivers/phy/phy-qcom-qusb2.c new file +42
-0+ +return 0 ; +} + +static int qusb2_phy_init (struct phy *phy) +{ +struct qusb2_phy *qphy =phy_get_drvdata (phy); +unsigned int val; +unsigned int clk_scheme; +int ret; + +dev_vdbg (&phy->dev,"%s(): Initializing QUSB2 phy\n" , __func__); + +/* enable ahb interface clock to program phy */ + ret =clk_prepare_enable (qphy->cfg_ahb_clk); +if (ret) { +dev_err (&phy->dev,"failed to enable cfg ahb clock, %d\n" , ret); +return ret; + } + +/* Perform phy reset */ + ret =reset_control_assert (qphy->phy_reset); +if (ret) { +dev_err (&phy->dev,"failed to assert phy_reset, %d\n" , ret); + goto disable_ahb_clk; + } + +/* 100 us delay to keep PHY in reset mode */ +usleep_range (100 ,150 ); + + ret =reset_control_deassert (qphy->phy_reset); +if (ret) { +dev_err (&phy->dev,"failed to de-assert phy_reset, %d\n" , ret); + goto disable_ahb_clk; + } + +/* Disable the PHY */ +qusb2_setbits (qphy->base,QUSB2PHY_PORT_POWERDOWN , +CLAMP_N_EN |FREEZIO_N |POWER_DOWN ); + +/* save reset value to override reference clock scheme later */ + val =readl_relaxed (qphy->base +QUSB2PHY_PLL_TEST );
drivers/phy/phy-qcom-qusb2.c line 321
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+ +qcom_qusb2_phy_configure (qphy->base, qphy->cfg->tbl, + qphy->cfg->tbl_num); + +/* Set efuse value for tuning the PHY */ +qusb2_phy_set_tune2_param (qphy); + +/* Enable the PHY */ +qusb2_clrbits (qphy->base,QUSB2PHY_PORT_POWERDOWN ,POWER_DOWN ); +
The mb() in clrbits will not ensure that the write is finished before the sleep, it will only ensure that above write is done before any later memory operations. If you want to ensure that the value has hit the hardware before the sleep you should simply read back the value from the register.
Quoted 37 lines
drivers/phy/phy-qcom-qusb2.c new file +37
-0+/* Required to get phy pll lock successfully */ +usleep_range (150 ,160 ); + +/* Default is single-ended clock on msm8996 */ + qphy->has_se_clk_scheme = true; +/* +* read TCSR_PHY_CLK_SCHEME register to check if single-ended +* clock scheme is selected. If yes, then disable differential +* ref_clk and use single-ended clock, otherwise use differential +* ref_clk only. +*/ +if (qphy->tcsr) { + ret =regmap_read (qphy->tcsr, qphy->cfg->clk_scheme_offset, + &clk_scheme); +if (ret) { +dev_err (&phy->dev,"failed to read clk scheme reg\n" ); + goto assert_phy_reset; + } + +/* is it a differential clock scheme ? */ +if (!(clk_scheme &PHY_CLK_SCHEME_SEL )) { +dev_vdbg (&phy->dev,"%s(): select differential clk\n" , + __func__); + qphy->has_se_clk_scheme = false; + }else { +dev_vdbg (&phy->dev,"%s(): select single-ended clk\n" , + __func__); + } + } + +if (!qphy->has_se_clk_scheme) { + val &= ~CLK_REF_SEL ; + ret =clk_prepare_enable (qphy->ref_clk); +if (ret) { +dev_err (&phy->dev,"failed to enable ref clk, %d\n" , + ret); + goto assert_phy_reset;
drivers/phy/phy-qcom-qusb2.c line 368
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+ } + }else { + val |=CLK_REF_SEL ; + } + +writel_relaxed (val, qphy->base +QUSB2PHY_PLL_TEST ); + +/* Make sure that above write is completed to get PLL source clock */ +wmb (); +
As above.
drivers/phy/phy-qcom-qusb2.c line 371
Quoted 3 lines
drivers/phy/phy-qcom-qusb2.c new file +3
-0+/* Required to get phy pll lock successfully */ +usleep_range (100 ,110 ); +
Regards,
Bjorn
Re: [PATCH v5 2/4] phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips
Hi,
Quoted 16 lines · Bjorn Andersson
On Thu 09 Mar 10:07 CET 2017, Vivek Gautam wrote:
[..]
drivers/phy/phy-qcom-qusb2.c line 146
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+static inline void qusb2_setbits (void __iomem *base,u32 offset,u32 val) +{ +u32 reg; + + reg =readl_relaxed (base + offset); + reg |= val; +writel_relaxed (reg, base + offset); + +/* Ensure above write is completed */ +mb ();
mb()does not ensure that the operation is completed, it only ensures ordering between this write and subsequent memory accesses.
Quoted 3 lines
Unless you have specific reasons to you should not use the
_relaxed()versions of read and write operations. Using the non-relaxed versions will ensure that your memory operations are not reordered.
Right, I think this is something i took from downstream and didn't change. I should rather be using readl()/writel() and then readl() again to ensure writes are through.
Thanks for pointing out.
Quoted 14 lines
drivers/phy/phy-qcom-qusb2.c line 158
Quoted 13 lines
drivers/phy/phy-qcom-qusb2.c new file +12
-0+} + +static inline void qusb2_clrbits (void __iomem *base,u32 offset,u32 val) +{ +u32 reg; + + reg =readl_relaxed (base + offset); + reg &= ~val; +writel_relaxed (reg, base + offset); + +/* Ensure above write is completed */ +mb ();Dito.
Sure, will change it.
Quoted 15 lines
Quoted 4 lines
drivers/phy/phy-qcom-qusb2.c new file +3
-0+} + +static inline void qcom_qusb2_phy_configure(void __iomem *base,drivers/phy/phy-qcom-qusb2.c line 171
Quoted 10 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+const struct qusb2_phy_init_tbl tbl[], + int num) +{ + int i; + +for (i =0 ; i < num; i++) +writel_relaxed (tbl[i].val, base + tbl[i].offset); + +/* flush buffered writes */ +mb ();Dito.
will correct it.
Quoted 13 lines
drivers/phy/phy-qcom-qusb2.c line 182
Quoted 12 lines
drivers/phy/phy-qcom-qusb2.c new file +11
-0+} + +static int qusb2_phy_toggle_power (struct qusb2_phy *qphy,bool on) +{ +struct device *dev = &qphy->phy->dev; +int ret; + +if (!on) { + ret =0 ; + goto disable_vdda_phy_dpdm; + }This is an ugly hack.
Right, it sort of minimized the code. :)
It just jumps to disable code for an 'off' call.
But, will amend it to use regulator_bulk_*() apis.
Quoted 29 lines
Quoted 29 lines
drivers/phy/phy-qcom-qusb2.c new file +28
-0+ + ret =regulator_enable (qphy->vdd_phy); +if (ret) { +dev_err (dev,"failed to enable vdd-phy, %d\n" , ret); + goto err_vdd_phy; + } + + ret =regulator_enable (qphy->vdda_pll); +if (ret) { +dev_err (dev,"failed to enable vdda-pll, %d\n" , ret); + goto disable_vdd_phy; + } + + ret =regulator_enable (qphy->vdda_phy_dpdm); +if (ret) { +dev_err (dev,"failed to enable vdda-phy-dpdm, %d\n" , ret); + goto disable_vdda_pll; + } + +dev_vdbg (dev,"%s(): regulators are turned on\n" , __func__); + +return ret; + +disable_vdda_phy_dpdm: +regulator_disable (qphy->vdda_phy_dpdm); +disable_vdda_pll: +regulator_disable (qphy->vdda_pll); +disable_vdd_phy:
Quoted 8 lines
drivers/phy/phy-qcom-qusb2.c line 215
Quoted 5 lines
drivers/phy/phy-qcom-qusb2.c new file +5
-0+regulator_disable (qphy->vdd_phy); +err_vdd_phy: +dev_vdbg (dev,"%s(): regulators are turned off\n" , __func__); +return ret; +}If you use the
regulator_bulkinterface for your regulators you can replace this entire function with a call toregulator_bulk_enable()andregulator_bulk_disable().
Sure, will change this as suggested.
Quoted 31 lines
Quoted 31 lines
drivers/phy/phy-qcom-qusb2.c new file +30
-0+ +/* +* Fetches HS Tx tuning value from nvmem and sets the +* QUSB2PHY_PORT_TUNE2 register. +* For error case, skip setting the value and use the default value. +*/ +static void qusb2_phy_set_tune2_param (struct qusb2_phy *qphy) +{ +struct device *dev = &qphy->phy->dev; +u8 *val; + +/* +* Read efuse register having TUNE2 parameter's high nibble. +* If efuse register shows value as 0x0, or if we fail to find +* a valid efuse register settings, then use default value +* as 0xB for high nibble that we have already set while +* configuring phy. +*/ + val =nvmem_cell_read (qphy->cell,NULL ); +if (IS_ERR (val) || !val[0 ]) { +dev_dbg (dev,"failed to read a valid hs-tx trim value\n" ); +return ; + } + +/* Fused TUNE2 value is the higher nibble only */ +qusb2_setbits (qphy->base,QUSB2PHY_PORT_TUNE2 , val[0 ] <<0x4 ); +} + +static int qusb2_phy_poweron (struct phy *phy) +{
Quoted 8 lines
drivers/phy/phy-qcom-qusb2.c line 252
Quoted 7 lines
drivers/phy/phy-qcom-qusb2.c new file +7
-0+struct qusb2_phy *qphy =phy_get_drvdata (phy); +int ret; + +dev_vdbg (&phy->dev,"%s(): Powering-on QUSB2 phy\n" , __func__); + +/* turn on regulator supplies */ + ret =qusb2_phy_toggle_power (qphy, true);Call
regulator_bulk_enable()
Sure.
Quoted 11 lines
Quoted 11 lines
drivers/phy/phy-qcom-qusb2.c new file +10
-0+if (ret) +return ret; + + ret =clk_prepare_enable (qphy->iface_clk); +if (ret) +dev_err (&phy->dev,"failed to enable iface_clk, %d\n" , ret); + +return ret; +} +
Quoted 8 lines
drivers/phy/phy-qcom-qusb2.c line 269
Quoted 7 lines
drivers/phy/phy-qcom-qusb2.c new file +7
-0+static int qusb2_phy_poweroff (struct phy *phy) +{ +struct qusb2_phy *qphy =phy_get_drvdata (phy); + +clk_disable_unprepare (qphy->iface_clk); + +qusb2_phy_toggle_power (qphy, false);Call
regulator_bulk_disable()
Right, will do that.
Quoted 50 lines
Quoted 50 lines
drivers/phy/phy-qcom-qusb2.c new file +49
-0+ +return 0 ; +} + +static int qusb2_phy_init (struct phy *phy) +{ +struct qusb2_phy *qphy =phy_get_drvdata (phy); +unsigned int val; +unsigned int clk_scheme; +int ret; + +dev_vdbg (&phy->dev,"%s(): Initializing QUSB2 phy\n" , __func__); + +/* enable ahb interface clock to program phy */ + ret =clk_prepare_enable (qphy->cfg_ahb_clk); +if (ret) { +dev_err (&phy->dev,"failed to enable cfg ahb clock, %d\n" , ret); +return ret; + } + +/* Perform phy reset */ + ret =reset_control_assert (qphy->phy_reset); +if (ret) { +dev_err (&phy->dev,"failed to assert phy_reset, %d\n" , ret); + goto disable_ahb_clk; + } + +/* 100 us delay to keep PHY in reset mode */ +usleep_range (100 ,150 ); + + ret =reset_control_deassert (qphy->phy_reset); +if (ret) { +dev_err (&phy->dev,"failed to de-assert phy_reset, %d\n" , ret); + goto disable_ahb_clk; + } + +/* Disable the PHY */ +qusb2_setbits (qphy->base,QUSB2PHY_PORT_POWERDOWN , +CLAMP_N_EN |FREEZIO_N |POWER_DOWN ); + +/* save reset value to override reference clock scheme later */ + val =readl_relaxed (qphy->base +QUSB2PHY_PLL_TEST ); + +qcom_qusb2_phy_configure (qphy->base, qphy->cfg->tbl, + qphy->cfg->tbl_num); + +/* Set efuse value for tuning the PHY */ +qusb2_phy_set_tune2_param (qphy); +
Quoted 8 lines
drivers/phy/phy-qcom-qusb2.c line 321
Quoted 3 lines
drivers/phy/phy-qcom-qusb2.c new file +3
-0+/* Enable the PHY */ +qusb2_clrbits (qphy->base,QUSB2PHY_PORT_POWERDOWN ,POWER_DOWN ); +The
mb()in clrbits will not ensure that the write is finished before the sleep, it will only ensure that above write is done before any later memory operations. If you want to ensure that the value has hit the hardware before the sleep you should simply read back the value from the register.
Right. Will add a read back in qusb2_clrbits() and qusb2_setbits().
Quoted 41 lines
Quoted 41 lines
drivers/phy/phy-qcom-qusb2.c new file +40
-0+/* Required to get phy pll lock successfully */ +usleep_range (150 ,160 ); + +/* Default is single-ended clock on msm8996 */ + qphy->has_se_clk_scheme = true; +/* +* read TCSR_PHY_CLK_SCHEME register to check if single-ended +* clock scheme is selected. If yes, then disable differential +* ref_clk and use single-ended clock, otherwise use differential +* ref_clk only. +*/ +if (qphy->tcsr) { + ret =regmap_read (qphy->tcsr, qphy->cfg->clk_scheme_offset, + &clk_scheme); +if (ret) { +dev_err (&phy->dev,"failed to read clk scheme reg\n" ); + goto assert_phy_reset; + } + +/* is it a differential clock scheme ? */ +if (!(clk_scheme &PHY_CLK_SCHEME_SEL )) { +dev_vdbg (&phy->dev,"%s(): select differential clk\n" , + __func__); + qphy->has_se_clk_scheme = false; + }else { +dev_vdbg (&phy->dev,"%s(): select single-ended clk\n" , + __func__); + } + } + +if (!qphy->has_se_clk_scheme) { + val &= ~CLK_REF_SEL ; + ret =clk_prepare_enable (qphy->ref_clk); +if (ret) { +dev_err (&phy->dev,"failed to enable ref clk, %d\n" , + ret); + goto assert_phy_reset; + } + }else { + val |=CLK_REF_SEL ;
Quoted 8 lines
drivers/phy/phy-qcom-qusb2.c line 368
Quoted 7 lines
drivers/phy/phy-qcom-qusb2.c new file +7
-0+ } + +writel_relaxed (val, qphy->base +QUSB2PHY_PLL_TEST ); + +/* Make sure that above write is completed to get PLL source clock */ +wmb (); +As above.
Sure, will change this.
Quoted 5 lines
drivers/phy/phy-qcom-qusb2.c line 371
Quoted 3 lines
drivers/phy/phy-qcom-qusb2.c new file +3
-0+/* Required to get phy pll lock successfully */ +usleep_range (100 ,110 ); +Regards,
Bjorn
Regards
Vivek
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 3/4 dt-bindings: phy: Add support for QMP phy
In reply to Vivek GautamQualcomm chipsets have QMP phy controller that provides support to a number of controller, viz. PCIe, UFS, and USB. Adding dt binding information for the same.
---
Hi Rob,
I have removed your Acked-by tag because of the change in bindings. Please consider adding your Ack again if you are fine with these updated bindings.
Changes since v4:
- Added bindings for child nodes. Each phy lane is represented by child node with its own register space (for tx, rx and pcs blocks), and clocks and resets for power control facility.
- Removed register space and lane offsets for tx, rx and pcs blocks from qmp phy node.
- #phy-cells is now part of each child node and thus must be 0.
- Added information on list of mandatory clocks and resets for each phy.
Changes since v3:
- Added #clock-cells = <1>, indicating that phy is a clock provider.
Changes since v2:
- Removed binding for "ref_clk_src" since we don't request this clock in the driver.
- Addressed s/ref_clk/ref. Don't need to add '_clk' suffix to clock names.
- Using 'phy' for the node name.
Changes since v1:
- New patch, forked out of the original driver patch:
"phy: qcom-qmp: new qmp phy driver for qcom-chipsets"
- Added 'Acked-by' from Rob.
- Updated bindings to include mem resource as a list of offset - length pair for serdes block and for each lane.
- Added a new binding for 'lane-offsets' that contains offsets to tx, rx and pcs blocks from each lane base address.
.../devicetree/bindings/phy/qcom-qmp-phy.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +106 -0
@@ -0,0 +1,106 @@ +Qualcomm QMP PHY controller +=========================== + +QMP phy controller supports physical layer functionality for a number of +controllers on Qualcomm chipsets, such as, PCIe, UFS, and USB. + +Required properties: + - compatible: compatible list, contains: + "qcom,msm8996-qmp-pcie-phy" for 14nm PCIe phy on msm8996, + "qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996. + + - reg: offset and length of register set for PHY's common serdes block. + + - #clock-cells: must be 1 + - Phy pll outputs a bunch of clocks for Tx, Rx and Pipe + interface (for pipe based PHYs). These clock are then gate-controlled + by gcc. + - #address-cells: must be 1 + - #size-cells: must be 1 + - ranges: must be present + + - clocks: a list of phandles and clock-specifier pairs, + one for each entry in clock-names. + - clock-names: "cfg_ahb" for phy config clock, + "aux" for phy aux clock, + "ref" for 19.2 MHz ref clk, + For "qcom,msm8996-qmp-pcie-phy" must contain: + "aux", "cfg_ahb", "ref". + For "qcom,msm8996-qmp-usb3-phy" must contain: + "aux", "cfg_ahb", "ref". + + - resets: a list of phandles and reset controller specifier pairs, + one for each entry in reset-names. + - reset-names: "phy" for reset of phy block, + "common" for phy common block reset, + "cfg" for phy's ahb cfg block reset (Optional). + For "qcom,msm8996-qmp-pcie-phy" must contain: + "phy", "common", "cfg". + For "qcom,msm8996-qmp-usb3-phy" must contain + "phy", "common". + + - vdda-phy-supply: Phandle to a regulator supply to PHY core block. + - vdda-pll-supply: Phandle to 1.8V regulator supply to PHY refclk pll block. + +Optional properties: + - vddp-ref-clk-supply: Phandle to a regulator supply to any specific refclk + pll block. + +Required nodes: + - Each device node of QMP phy is required to have as many child nodes as + the number of lanes the PHY has. + +Required properties for child node: + - reg: list of offset and length pairs of register sets for PHY blocks - + tx, rx and pcs. + + - #phy-cells: must be 0 + + - clocks: a list of phandles and clock-specifier pairs, + one for each entry in clock-names. + - clock-names: Must contain following for pcie and usb qmp phys: + "pipe<lane-number>" for pipe clock specific to each lane. + + - resets: a list of phandles and reset controller specifier pairs, + one for each entry in reset-names. + - reset-names: Must contain following for pcie qmp phys: + "lane<lane-number>" for reset specific to each lane. + +Example: + phy@34000 { + compatible = "qcom,msm8996-qmp-pcie-phy"; + reg = <0x034000 0x488>; + #clock-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + clocks = <&gcc GCC_PCIE_PHY_AUX_CLK>, + <&gcc GCC_PCIE_PHY_CFG_AHB_CLK>, + <&gcc GCC_PCIE_CLKREF_CLK>; + clock-names = "aux", "cfg_ahb", "ref"; + + vdda-phy-supply = <&pm8994_l28>; + vdda-pll-supply = <&pm8994_l12>; + + resets = <&gcc GCC_PCIE_PHY_BCR>, + <&gcc GCC_PCIE_PHY_COM_BCR>, + <&gcc GCC_PCIE_PHY_COM_NOCSR_BCR>; + reset-names = "phy", "common", "cfg"; + + pciephy_0: lane@0 { + reg = <0x035000 0x130>, + <0x035200 0x200>, + <0x035400 0x1dc>; + #phy-cells = <0>; + + clocks = <&gcc GCC_PCIE_0_PIPE_CLK>; + clock-names = "pipe0"; + resets = <&gcc GCC_PCIE_0_PHY_BCR>; + reset-names = "lane0"; + }; + + pciephy_1: lane@1 { + ... + ... + };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v5 3/4] dt-bindings: phy: Add support for QMP phy
On Thu 09 Mar 10:07 CET 2017, Vivek Gautam wrote:
[..]
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt line 72
Quoted 3 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +3
-0+ phy@34000 { + compatible = "qcom,msm8996-qmp-pcie-phy"; + reg = <0x034000 0x488>;
Drop the leading 0 from the address.
Quoted 9 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +9
-0+ #clock-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + clocks = <&gcc GCC_PCIE_PHY_AUX_CLK>, + <&gcc GCC_PCIE_PHY_CFG_AHB_CLK>, + <&gcc GCC_PCIE_CLKREF_CLK>; + clock-names = "aux", "cfg_ahb", "ref";
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt line 91
Quoted 10 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +10
-0+ + vdda-phy-supply = <&pm8994_l28>; + vdda-pll-supply = <&pm8994_l12>; + + resets = <&gcc GCC_PCIE_PHY_BCR>, + <&gcc GCC_PCIE_PHY_COM_BCR>, + <&gcc GCC_PCIE_PHY_COM_NOCSR_BCR>; + reset-names = "phy", "common", "cfg"; + + pciephy_0: lane@0 {
The "@xyz" part should match the first value in "reg", i.e. 35000 here.
Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +5
-0+ reg = <0x035000 0x130>, + <0x035200 0x200>, + <0x035400 0x1dc>; + #phy-cells = <0>; +
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt line 106
Quoted 10 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +10
-0+ clocks = <&gcc GCC_PCIE_0_PIPE_CLK>; + clock-names = "pipe0"; + resets = <&gcc GCC_PCIE_0_PHY_BCR>; + reset-names = "lane0"; + }; + + pciephy_1: lane@1 { + ... + ... + };
Regards,
Bjorn
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 3/4] dt-bindings: phy: Add support for QMP phy
Quoted 7 lines · Bjorn Andersson
On Thu 09 Mar 10:07 CET 2017, Vivek Gautam wrote:
[..]
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt line 72
Quoted 3 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +3
-0+ phy@34000 { + compatible = "qcom,msm8996-qmp-pcie-phy"; + reg = <0x034000 0x488>;Drop the leading 0 from the address.
Okay, will drop it.
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +12
-0+ #clock-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + clocks = <&gcc GCC_PCIE_PHY_AUX_CLK>, + <&gcc GCC_PCIE_PHY_CFG_AHB_CLK>, + <&gcc GCC_PCIE_CLKREF_CLK>; + clock-names = "aux", "cfg_ahb", "ref"; + + vdda-phy-supply = <&pm8994_l28>; + vdda-pll-supply = <&pm8994_l12>;
Quoted 8 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt line 91
Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +7
-0+ + resets = <&gcc GCC_PCIE_PHY_BCR>, + <&gcc GCC_PCIE_PHY_COM_BCR>, + <&gcc GCC_PCIE_PHY_COM_NOCSR_BCR>; + reset-names = "phy", "common", "cfg"; + + pciephy_0: lane@0 {The "@xyz" part should match the first value in "reg", i.e. 35000 here.
Right, i think this came from my older version of patches. Will correct it.
Regards
Vivek
Quoted 18 lines
Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +5
-0+ reg = <0x035000 0x130>, + <0x035200 0x200>, + <0x035400 0x1dc>; + #phy-cells = <0>; +Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt line 106
Quoted 10 lines
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt new file +10
-0+ clocks = <&gcc GCC_PCIE_0_PIPE_CLK>; + clock-names = "pipe0"; + resets = <&gcc GCC_PCIE_0_PHY_BCR>; + reset-names = "lane0"; + }; + + pciephy_1: lane@1 { + ... + ... + };Regards,
Bjorn
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 3/4] dt-bindings: phy: Add support for QMP phy
In reply to Vivek GautamQuoted 22 lines · Vivek Gautam
Qualcomm chipsets have QMP phy controller that provides support to a number of controller, viz. PCIe, UFS, and USB. Adding dt binding information for the same.
Signed-off-by Vivek Gautam <[email protected]>Cc Rob Herring <[email protected]>---
Hi Rob,
I have removed your Acked-by tag because of the change in bindings. Please consider adding your Ack again if you are fine with these updated bindings.Changes since v4:
- Added bindings for child nodes. Each phy lane is represented by child node with its own register space (for tx, rx and pcs blocks), and clocks and resets for power control facility.
- Removed register space and lane offsets for tx, rx and pcs blocks from qmp phy node.
- #phy-cells is now part of each child node and thus must be 0.
- Added information on list of mandatory clocks and resets for each phy.
Quoted 6 lines
Changes since v3:
- Added #clock-cells = <1>, indicating that phy is a clock provider.Changes since v2:
- Removed binding for "ref_clk_src" since we don't request this clock in the driver.
Humm, sounds suspicious. You should describe clocks connected to the h/w block, not what the driver uses (currently).
Quoted 12 lines
- Addressed s/ref_clk/ref. Don't need to add '
_clk' suffix to clock names.
- Using 'phy' for the node name.Changes since v1:
- New patch, forked out of the original driver patch:
"phy: qcom-qmp: new qmp phy driver for qcom-chipsets"
- Added 'Acked-by' from Rob.
- Updated bindings to include mem resource as a list of offset - length pair for serdes block and for each lane.
- Added a new binding for 'lane-offsets' that contains offsets to tx, rx and pcs blocks from each lane base address.
Quoted 3 lines
.../devicetree/bindings/phy/qcom-qmp-phy.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 3/4] dt-bindings: phy: Add support for QMP phy
Hi Rob,
Quoted 26 lines · Rob Herring
Quoted 25 lines · Vivek Gautam
Qualcomm chipsets have QMP phy controller that provides support to a number of controller, viz. PCIe, UFS, and USB. Adding dt binding information for the same.
Signed-off-by Vivek Gautam <[email protected]>Cc Rob Herring <[email protected]>---
Hi Rob,
I have removed your Acked-by tag because of the change in bindings. Please consider adding your Ack again if you are fine with these updated bindings.Changes since v4:
- Added bindings for child nodes. Each phy lane is represented by child node with its own register space (for tx, rx and pcs blocks), and clocks and resets for power control facility.
- Removed register space and lane offsets for tx, rx and pcs blocks from qmp phy node.
- #phy-cells is now part of each child node and thus must be 0.
- Added information on list of mandatory clocks and resets for each phy.Changes since v3:
- Added #clock-cells = <1>, indicating that phy is a clock provider.
Quoted 6 lines
Quoted 3 lines
Changes since v2:
- Removed binding for "ref_clk_src" since we don't request this clock in the driver.Humm, sounds suspicious. You should describe clocks connected to the h/w block, not what the driver uses (currently).
The "ref_clk_src" clock is not really going to the phy block. After cross-checking
the hardware documents, we decided to remove this.
On the SoC, this is an external clock (outside of the clock controller) that comes
to a clock pad that feeds few clock tx blocks. These blocks supply the reference clock to each IP blocks.
Output of these tx blocks is what we refer to as "ref" clock in our bindings.
Quoted 13 lines
Quoted 13 lines
- Addressed s/ref_clk/ref. Don't need to add '
_clk' suffix to clock names.
- Using 'phy' for the node name.Changes since v1:
- New patch, forked out of the original driver patch:
"phy: qcom-qmp: new qmp phy driver for qcom-chipsets"
- Added 'Acked-by' from Rob.
- Updated bindings to include mem resource as a list of offset - length pair for serdes block and for each lane.
- Added a new binding for 'lane-offsets' that contains offsets to tx, rx and pcs blocks from each lane base address.
Quoted 5 lines
Quoted 3 lines
.../devicetree/bindings/phy/qcom-qmp-phy.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom-qmp-phy.txtAcked-by Rob Herring <[email protected]>
Thanks for reviewing.
Best Regards
Vivek
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 4/4 phy: qcom-qmp: new qmp phy driver for qcom-chipsets
In reply to Vivek GautamQualcomm SOCs have QMP phy controller that provides support to a number of controller, viz. PCIe, UFS, and USB. Add a new driver, based on generic phy framework, for this phy controller.
---
Changes since v4:
- Added provision for child nodes representing each phy lane. Each of these nodes have their own register space for tx, rx and pcs blocks. Added provision in qcom_qmp_phy_create() to iomap these address spaces.
- Added list of clocks and resets that are mandatory for each phy. qcom_qmp_phy_clk_init(), and qcom_qmp_phy_reset_init() methods request this list and maintains it with qmp.
The clocks and resets are then enabled/de-asserted based on this list. This list is also updated in the binding documentation.
- Removed qcom_qmp_phy_xlate() method as we don't need it with #phy-cells 0.
- Removed unnecessary of_match_ptr() cast for the match table, since the driver is compiled for CONFIG_OF.
- Updated copyright year to 2017.
Changes since v3:
- Renamed 'struct qcom_qmp_phy' to 'struct qcom_qmp' and 'struct qmp_phy_desc' to 'struct qmp_phy' to avoid any confusion in distinguishing between QMP phy block and per-lane phy which is the actual phy in Linux eyes (suggested by Bjorn Andersson).
- Made error labels more idiomatic.
- Modified status checking for phy pcs.
- Fixed power_down_delay check.
- Refactored phy_pipe_clk_register() to register the pipe clock source using devm_clk_hw_register() (suggested by Stephen).
- qcom_qmp_phy_xlate() function:
- Removed unnecessary 'for loop'.
- Added additional check for '0' or -ve args_count.
- Fixed the mixed tabs and spaces in pipe_clk_src diagram.
- Removed instances of memset() since we use snprintf() for the buffers.
- Refactored qphy_setbits() and qphy_clrbits() a little bit to accept base address and register offset as two separate arguments.
Changes since v2:
- Removed selecting 'RESET_CONTROLLER' config.
- Added error handling for clk_prepare_enable paths.
- Removed 'ref_clk_src' handling. Driver doesn't need to request and handle this clock.
- Using readl_poll_timeout() to simplify pcs ready status polling. Also fixed the polling condition for pcs block ready status:
'Common block ready status bit is set on phy init completion, while PCS block ready status bit (PHYSTATUS) is reset on phy init completion.'
- Moved out the per-lane phy creation from probe() to separate function.
- Registering pipe clock source as a fixed rate clock that comes out of the PLL block of QMP phy. These source clocks serve as parent to 'pipe_clks' that are requested by pcie or usb3 phys.
- Using of_device_get_match_data() to get match data.
- Fixed sparse warnings for 'static' and 'const'.
- Using shorter variable names in structure and in functions.
- Handling various comment style shortcomings.
Changes since v1:
- Fixed missing mutex_unlock() calls in error cases, reported by Julia Lawall.
- Selecting CONFIG_RESET_CONTROLLER when this driver is enabled.
- Added a boolean property to check if the phy has individual lane reset available.
- Took care or EPROBE_DEFER, dev_vdbg() and other minor nits.
- Removed references to non-lkml links from commit message.
- Moved to use separate iomem resources for each lanes. Tx, Rx and PCS offsets per lane can now come from dt bindings.
drivers/phy/Kconfig | 8 + drivers/phy/Makefile | 1 + drivers/phy/phy-qcom-qmp.c | 1191 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1200 insertions(+) create mode 100644 drivers/phy/phy-qcom-qmp.c
drivers/phy/Kconfig +8 -0
@@ -439,6 +439,14 @@ config PHY_STIH407_USB Enable this support to enable the picoPHY device used by USB2 and USB3 controllers on STMicroelectronics STiH407 SoC families. +config PHY_QCOM_QMP + tristate "Qualcomm QMP PHY Driver" + depends on OF && (ARCH_QCOM || COMPILE_TEST) + select GENERIC_PHY + help + Enable this to support the QMP PHY transceiver that is used + with controllers such as PCIe, UFS, and USB on Qualcomm chips. + config PHY_QCOM_QUSB2 tristate "Qualcomm QUSB2 PHY Driver" depends on OF && (ARCH_QCOM || COMPILE_TEST)
drivers/phy/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o obj-$(CONFIG_PHY_XGENE) += phy-xgene.o obj-$(CONFIG_PHY_STIH407_USB) += phy-stih407-usb.o obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o +obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-20nm.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-14nm.o
drivers/phy/phy-qcom-qmp.c new file +1191 -0
1,191 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v5 4/4] phy: qcom-qmp: new qmp phy driver for qcom-chipsets
On Thu 09 Mar 10:07 CET 2017, Vivek Gautam wrote:
[..]
drivers/phy/phy-qcom-qmp.c line 492
Quoted 10 lines
drivers/phy/phy-qcom-qmp.c new file +10
-0+static inline void qphy_setbits (void __iomem *base,u32 offset,u32 val) +{ +u32 reg; + + reg =readl_relaxed (base + offset); + reg |= val; +writel_relaxed (reg, base + offset); + +/* Make sure that above writes are completed */ +mb ();
Same comments as on patch 2 wrt the use of _relaxed operations and barriers (i.e. please don't).
Quoted 2 lines
(quoted diff) +2
-0+} +
[..]
Quoted 19 lines
drivers/phy/phy-qcom-qmp.c new file +19
-0+static int qcom_qmp_phy_poweron (struct phy *phy) +{ +struct qmp_phy *qphy =phy_get_drvdata (phy); +struct qcom_qmp *qmp = qphy->qmp; +int ret; + +dev_vdbg (&phy->dev,"Powering on QMP phy\n" ); + + ret =regulator_enable (qmp->vdda_phy); +if (ret) { +dev_err (qmp->dev,"%s: vdda-phy enable failed, err=%d\n" , + __func__, ret); +return ret; + } + + ret =regulator_enable (qmp->vdda_pll); +if (ret) { +dev_err (qmp->dev,"%s: vdda-pll enable failed, err=%d\n" , + __func__, ret);
drivers/phy/phy-qcom-qmp.c line 623
Quoted 10 lines
drivers/phy/phy-qcom-qmp.c new file +10
-0+ goto disable_vdda_phy; + } + + ret =regulator_enable (qmp->vddp_ref_clk); +if (ret) { +dev_err (qmp->dev, +"%s: vdda-ref-clk enable failed, err=%d\n" , + __func__, ret); + goto disable_vdda_pll; + }
Please use the regulator_bulk interface here as well.
Quoted 19 lines
drivers/phy/phy-qcom-qmp.c new file +19
-0+ + ret =clk_prepare_enable (qphy->pipe_clk); +if (ret) { +dev_err (qmp->dev,"%s: pipe_clk enable failed, err=%d\n" , + __func__, ret); + goto disable_vddp_ref_clk; + } + +return 0 ; + +disable_vddp_ref_clk: +regulator_disable (qmp->vddp_ref_clk); +disable_vdda_pll: +regulator_disable (qmp->vdda_pll); +disable_vdda_phy: +regulator_disable (qmp->vdda_phy); +return ret; +} +
[..]
Quoted 21 lines
drivers/phy/phy-qcom-qmp.c new file +21
-0+static int phy_pipe_clk_register (struct qcom_qmp *qmp,int id) +{ +char name[24 ]; +struct clk_fixed_rate *fixed; +struct clk_init_data init = { }; +int ret; + +switch (qmp->cfg->type) { +case PHY_TYPE_USB3 : +snprintf (name,sizeof (name),"usb3_phy_pipe_clk_src" ); +break ; +case PHY_TYPE_PCIE : +snprintf (name,sizeof (name),"pcie_%d_pipe_clk_src" , id); +break ; +default : +/* not all phys register pipe clocks, so return success */ +return 0 ; + } + + fixed =devm_kzalloc (qmp->dev,sizeof (*fixed),GFP_KERNEL ); +if (!fixed)
drivers/phy/phy-qcom-qmp.c line 993
Quoted 10 lines
drivers/phy/phy-qcom-qmp.c new file +10
-0+return -ENOMEM ; + + init.name = name; + init.ops = &clk_fixed_rate_ops; + +/* controllers using QMP phys use 125MHz pipe clock interface */ + fixed->fixed_rate =125000000 ; + fixed->hw.init = &init; + + ret =devm_clk_hw_register (qmp->dev, &fixed->hw);
Drop "ret" and just return devm_clk_hw_register()
Quoted 77 lines
drivers/phy/phy-qcom-qmp.c new file +77
-0+ +return ret; +} + +static const struct phy_ops qcom_qmp_phy_gen_ops = { + .init = qcom_qmp_phy_init, + .exit = qcom_qmp_phy_exit, + .power_on = qcom_qmp_phy_poweron, + .power_off = qcom_qmp_phy_poweroff, + .owner =THIS_MODULE , +}; + +static +int qcom_qmp_phy_create (struct device *dev,struct device_node *np,int id) +{ +struct qcom_qmp *qmp =dev_get_drvdata (dev); +struct phy *generic_phy; +struct qmp_phy *qphy; +char prop_name[MAX_PROP_NAME ]; +int ret; + + qphy =devm_kzalloc (dev,sizeof (*qphy),GFP_KERNEL ); +if (!qphy) +return -ENOMEM ; + +/* +* Get memory resources for each phy lane: +* Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2. +*/ + qphy->tx =of_iomap (np,0 ); +if (IS_ERR (qphy->tx)) +return PTR_ERR (qphy->tx); + + qphy->rx =of_iomap (np,1 ); +if (IS_ERR (qphy->rx)) +return PTR_ERR (qphy->rx); + + qphy->pcs =of_iomap (np,2 ); +if (IS_ERR (qphy->pcs)) +return PTR_ERR (qphy->pcs); + +/* +* Get PHY's Pipe clock, if any. USB3 and PCIe are PIPE3 +* based phys, so they essentially have pipe clock. So, +* we return error in case phy is USB3 or PIPE type. +* Otherwise, we initialize pipe clock to NULL for +* all phys that don't need this. +*/ +snprintf (prop_name,sizeof (prop_name),"pipe%d" , id); + qphy->pipe_clk =of_clk_get_by_name (np, prop_name); +if (IS_ERR (qphy->pipe_clk)) { +if (qmp->cfg->type ==PHY_TYPE_PCIE || + qmp->cfg->type ==PHY_TYPE_USB3 ) { + ret =PTR_ERR (qphy->pipe_clk); +if (ret != -EPROBE_DEFER ) +dev_err (dev, +"failed to get lane%d pipe_clk, %d\n" , + id, ret); +return ret; + } + qphy->pipe_clk =NULL ; + } + +/* Get lane reset, if any */ +if (qmp->cfg->has_lane_rst) { +snprintf (prop_name,sizeof (prop_name),"lane%d" , id); + qphy->lane_rst =of_reset_control_get (np, prop_name); +if (IS_ERR (qphy->lane_rst)) { +dev_err (dev,"failed to get lane%d reset\n" , id); +return PTR_ERR (qphy->lane_rst); + } + } + + generic_phy =devm_phy_create (dev, np, &qcom_qmp_phy_gen_ops); +if (IS_ERR (generic_phy)) { + ret =PTR_ERR (generic_phy); +dev_err (dev,"failed to create qphy %d\n" , ret);
drivers/phy/phy-qcom-qmp.c line 1080
Quoted 10 lines
drivers/phy/phy-qcom-qmp.c new file +10
-0+return ret; + } + + qphy->phy = generic_phy; + qphy->index = id; + qphy->qmp = qmp; + qmp->phys[id] = qphy; +phy_set_drvdata (generic_phy, qphy); + +return ret;
Afaict "ret" might not be initialized here, just return 0;
Quoted 86 lines
drivers/phy/phy-qcom-qmp.c new file +86
-0+} + +static const struct of_device_id qcom_qmp_phy_of_match_table[] = { + { + .compatible ="qcom,msm8996-qmp-pcie-phy" , + .data = &msm8996_pciephy_cfg, + }, { + .compatible ="qcom,msm8996-qmp-usb3-phy" , + .data = &msm8996_usb3phy_cfg, + }, + { }, +}; +MODULE_DEVICE_TABLE (of, qcom_qmp_phy_of_match_table); + +static int qcom_qmp_phy_probe (struct platform_device *pdev) +{ +struct qcom_qmp *qmp; +struct device *dev = &pdev->dev; +struct resource *res; +struct device_node *child; +struct phy_provider *phy_provider; +void __iomem *base; +int num, id; +int ret; + + qmp =devm_kzalloc (dev,sizeof (*qmp),GFP_KERNEL ); +if (!qmp) +return -ENOMEM ; + + qmp->dev = dev; +dev_set_drvdata (dev, qmp); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + +/* per PHY serdes; usually located at base address */ + qmp->serdes = base; + +mutex_init (&qmp->phy_mutex); + +/* Get the specific init parameters of QMP phy */ + qmp->cfg =of_device_get_match_data (dev); + + ret =qcom_qmp_phy_clk_init (dev); +if (ret) +return ret; + + ret =qcom_qmp_phy_regulator_init (dev); +if (ret) +return ret; + + ret =qcom_qmp_phy_reset_init (dev); +if (ret) +return ret; + + num =of_get_available_child_count (dev->of_node); +/* do we have a rogue child node ? */ +if (num > qmp->cfg->nlanes) +return -EINVAL ; + + qmp->phys =devm_kcalloc (dev, num,sizeof (*qmp->phys),GFP_KERNEL ); +if (!qmp->phys) +return -ENOMEM ; + + id =0 ; +for_each_available_child_of_node (dev->of_node, child) { +/* Create per-lane phy */ + ret =qcom_qmp_phy_create (dev, child, id); +if (ret) { +dev_err (dev,"failed to create lane%d phy, %d\n" , + id, ret); +return ret; + } + +/* +* Register the pipe clock provided by phy. +* See function description to see details of this pipe clock. +*/ + ret =phy_pipe_clk_register (qmp, id); +if (ret) { +dev_err (qmp->dev, +"failed to register pipe clock source\n" ); +return ret; + }
drivers/phy/phy-qcom-qmp.c line 1176
Quoted 10 lines
drivers/phy/phy-qcom-qmp.c new file +10
-0+ id++; + } + + phy_provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); +if (IS_ERR (phy_provider)) { + ret =PTR_ERR (phy_provider); +dev_err (dev,"failed to register qphy, %d\n" , ret); + } + +return ret;
Replace this as well with return 0, to not just rely on the fact that you 45 lines up will leave ret 0.
Quoted 1 line
+}
Regards,
Bjorn