Lines Matching +full:tx +full:- +full:pcs
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/clk-provider.h>
22 #include "phy-qcom-qmp.h"
23 #include "phy-qcom-qmp-pcs-misc-v3.h"
24 #include "phy-qcom-qmp-pcs-usb-v4.h"
25 #include "phy-qcom-qmp-pcs-usb-v5.h"
88 /* set of registers with offsets different per-PHY */
90 /* PCS registers */
1153 u16 pcs;
1156 u16 tx;
1163 /* struct qmp_phy_cfg - per-PHY initialization config */
1169 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
1197 /* Offset from PCS to PCS_USB region */
1207 void __iomem *pcs;
1210 void __iomem *tx;
1288 "vdda-phy", "vdda-pll",
1293 .pcs = 0x800,
1295 .tx = 0x200,
1301 .pcs = 0xc00,
1303 .tx = 0x200,
1311 .pcs = 0x0200,
1313 .tx = 0x0e00,
1628 if (!(t->lane_mask & lane_mask))
1631 writel(t->val, base + t->offset);
1644 const struct qmp_phy_cfg *cfg = qmp->cfg;
1645 void __iomem *serdes = qmp->serdes;
1646 const struct qmp_phy_init_tbl *serdes_tbl = cfg->serdes_tbl;
1647 int serdes_tbl_num = cfg->serdes_tbl_num;
1657 const struct qmp_phy_cfg *cfg = qmp->cfg;
1658 void __iomem *pcs = qmp->pcs;
1661 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
1663 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
1667 ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets);
1669 dev_err(qmp->dev, "reset assert failed\n");
1673 ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets);
1675 dev_err(qmp->dev, "reset deassert failed\n");
1679 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
1683 qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
1688 reset_control_bulk_assert(cfg->num_resets, qmp->resets);
1690 regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
1698 const struct qmp_phy_cfg *cfg = qmp->cfg;
1700 reset_control_bulk_assert(cfg->num_resets, qmp->resets);
1702 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1704 regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
1712 const struct qmp_phy_cfg *cfg = qmp->cfg;
1713 void __iomem *tx = qmp->tx;
1714 void __iomem *rx = qmp->rx;
1715 void __iomem *pcs = qmp->pcs;
1716 void __iomem *pcs_usb = qmp->pcs_usb;
1723 ret = clk_prepare_enable(qmp->pipe_clk);
1725 dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
1729 /* Tx, Rx, and PCS configurations */
1730 qmp_usb_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1);
1731 qmp_usb_configure_lane(rx, cfg->rx_tbl, cfg->rx_tbl_num, 1);
1733 if (cfg->lanes >= 2) {
1734 qmp_usb_configure_lane(qmp->tx2, cfg->tx_tbl, cfg->tx_tbl_num, 2);
1735 qmp_usb_configure_lane(qmp->rx2, cfg->rx_tbl, cfg->rx_tbl_num, 2);
1738 qmp_usb_configure(pcs, cfg->pcs_tbl, cfg->pcs_tbl_num);
1741 qmp_usb_configure(pcs_usb, cfg->pcs_usb_tbl, cfg->pcs_usb_tbl_num);
1743 if (cfg->has_pwrdn_delay)
1747 qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1749 /* start SerDes and Phy-Coding-Sublayer */
1750 qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], SERDES_START | PCS_START);
1752 status = pcs + cfg->regs[QPHY_PCS_STATUS];
1756 dev_err(qmp->dev, "phy initialization timed-out\n");
1763 clk_disable_unprepare(qmp->pipe_clk);
1771 const struct qmp_phy_cfg *cfg = qmp->cfg;
1773 clk_disable_unprepare(qmp->pipe_clk);
1776 qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1778 /* stop SerDes and Phy-Coding-Sublayer */
1779 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL],
1783 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
1818 qmp->mode = mode;
1832 const struct qmp_phy_cfg *cfg = qmp->cfg;
1833 void __iomem *pcs_usb = qmp->pcs_usb ?: qmp->pcs;
1834 void __iomem *pcs_misc = qmp->pcs_misc;
1837 if (qmp->mode == PHY_MODE_USB_HOST_SS ||
1838 qmp->mode == PHY_MODE_USB_DEVICE_SS)
1844 qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1846 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1848 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
1852 qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask);
1861 const struct qmp_phy_cfg *cfg = qmp->cfg;
1862 void __iomem *pcs_usb = qmp->pcs_usb ?: qmp->pcs;
1863 void __iomem *pcs_misc = qmp->pcs_misc;
1869 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
1872 qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1874 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1880 const struct qmp_phy_cfg *cfg = qmp->cfg;
1882 dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode);
1884 if (!qmp->phy->init_count) {
1891 clk_disable_unprepare(qmp->pipe_clk);
1892 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1900 const struct qmp_phy_cfg *cfg = qmp->cfg;
1903 dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
1905 if (!qmp->phy->init_count) {
1910 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
1914 ret = clk_prepare_enable(qmp->pipe_clk);
1917 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1933 const struct qmp_phy_cfg *cfg = qmp->cfg;
1934 struct device *dev = qmp->dev;
1935 int num = cfg->num_vregs;
1938 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
1939 if (!qmp->vregs)
1940 return -ENOMEM;
1943 qmp->vregs[i].supply = cfg->vreg_list[i];
1945 return devm_regulator_bulk_get(dev, num, qmp->vregs);
1950 const struct qmp_phy_cfg *cfg = qmp->cfg;
1951 struct device *dev = qmp->dev;
1955 qmp->resets = devm_kcalloc(dev, cfg->num_resets,
1956 sizeof(*qmp->resets), GFP_KERNEL);
1957 if (!qmp->resets)
1958 return -ENOMEM;
1960 for (i = 0; i < cfg->num_resets; i++)
1961 qmp->resets[i].id = cfg->reset_list[i];
1963 ret = devm_reset_control_bulk_get_exclusive(dev, cfg->num_resets, qmp->resets);
1972 const struct qmp_phy_cfg *cfg = qmp->cfg;
1973 struct device *dev = qmp->dev;
1974 int num = cfg->num_clks;
1977 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
1978 if (!qmp->clks)
1979 return -ENOMEM;
1982 qmp->clks[i].id = cfg->clk_list[i];
1984 return devm_clk_bulk_get(dev, num, qmp->clks);
2002 * +---------------+
2003 * | PHY block |<<---------------------------------------+
2005 * | +-------+ | +-----+ |
2006 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
2007 * clk | +-------+ | +-----+
2008 * +---------------+
2012 struct clk_fixed_rate *fixed = &qmp->pipe_clk_fixed;
2016 ret = of_property_read_string(np, "clock-output-names", &init.name);
2018 dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np);
2025 fixed->fixed_rate = 125000000;
2026 fixed->hw.init = &init;
2028 ret = devm_clk_hw_register(qmp->dev, &fixed->hw);
2032 ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw);
2040 return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np);
2050 return IOMEM_ERR_PTR(-EINVAL);
2060 struct platform_device *pdev = to_platform_device(qmp->dev);
2061 const struct qmp_phy_cfg *cfg = qmp->cfg;
2062 struct device *dev = qmp->dev;
2065 qmp->serdes = devm_platform_ioremap_resource(pdev, 0);
2066 if (IS_ERR(qmp->serdes))
2067 return PTR_ERR(qmp->serdes);
2071 * mappings for PCS.
2073 if (of_device_is_compatible(dev->of_node, "qcom,sdx65-qmp-usb3-uni-phy"))
2075 if (of_device_is_compatible(dev->of_node, "qcom,sm8350-qmp-usb3-uni-phy"))
2080 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
2081 * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5
2082 * For single lane PHYs: pcs_misc (optional) -> 3.
2084 qmp->tx = devm_of_iomap(dev, np, 0, NULL);
2085 if (IS_ERR(qmp->tx))
2086 return PTR_ERR(qmp->tx);
2088 qmp->rx = devm_of_iomap(dev, np, 1, NULL);
2089 if (IS_ERR(qmp->rx))
2090 return PTR_ERR(qmp->rx);
2092 qmp->pcs = qmp_usb_iomap(dev, np, 2, exclusive);
2093 if (IS_ERR(qmp->pcs))
2094 return PTR_ERR(qmp->pcs);
2096 if (cfg->pcs_usb_offset)
2097 qmp->pcs_usb = qmp->pcs + cfg->pcs_usb_offset;
2099 if (cfg->lanes >= 2) {
2100 qmp->tx2 = devm_of_iomap(dev, np, 3, NULL);
2101 if (IS_ERR(qmp->tx2))
2102 return PTR_ERR(qmp->tx2);
2104 qmp->rx2 = devm_of_iomap(dev, np, 4, NULL);
2105 if (IS_ERR(qmp->rx2))
2106 return PTR_ERR(qmp->rx2);
2108 qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL);
2110 qmp->pcs_misc = devm_of_iomap(dev, np, 3, NULL);
2113 if (IS_ERR(qmp->pcs_misc)) {
2114 dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
2115 qmp->pcs_misc = NULL;
2118 qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
2119 if (IS_ERR(qmp->pipe_clk)) {
2120 return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
2129 struct platform_device *pdev = to_platform_device(qmp->dev);
2130 const struct qmp_phy_cfg *cfg = qmp->cfg;
2131 const struct qmp_usb_offsets *offs = cfg->offsets;
2132 struct device *dev = qmp->dev;
2136 return -EINVAL;
2142 qmp->serdes = base + offs->serdes;
2143 qmp->pcs = base + offs->pcs;
2144 qmp->pcs_misc = base + offs->pcs_misc;
2145 qmp->pcs_usb = base + offs->pcs_usb;
2146 qmp->tx = base + offs->tx;
2147 qmp->rx = base + offs->rx;
2149 if (cfg->lanes >= 2) {
2150 qmp->tx2 = base + offs->tx2;
2151 qmp->rx2 = base + offs->rx2;
2154 qmp->pipe_clk = devm_clk_get(dev, "pipe");
2155 if (IS_ERR(qmp->pipe_clk)) {
2156 return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
2165 struct device *dev = &pdev->dev;
2173 return -ENOMEM;
2175 qmp->dev = dev;
2178 qmp->cfg = of_device_get_match_data(dev);
2179 if (!qmp->cfg)
2180 return -EINVAL;
2195 np = of_get_next_available_child(dev->of_node, NULL);
2199 np = of_node_get(dev->of_node);
2219 qmp->phy = devm_phy_create(dev, np, &qmp_usb_phy_ops);
2220 if (IS_ERR(qmp->phy)) {
2221 ret = PTR_ERR(qmp->phy);
2226 phy_set_drvdata(qmp->phy, qmp);
2241 .compatible = "qcom,ipq6018-qmp-usb3-phy",
2244 .compatible = "qcom,ipq8074-qmp-usb3-phy",
2247 .compatible = "qcom,ipq9574-qmp-usb3-phy",
2250 .compatible = "qcom,msm8996-qmp-usb3-phy",
2253 .compatible = "qcom,msm8998-qmp-usb3-phy",
2256 .compatible = "qcom,qcm2290-qmp-usb3-phy",
2259 .compatible = "qcom,sa8775p-qmp-usb3-uni-phy",
2262 .compatible = "qcom,sc8280xp-qmp-usb3-uni-phy",
2265 .compatible = "qcom,sdm845-qmp-usb3-uni-phy",
2268 .compatible = "qcom,sdx55-qmp-usb3-uni-phy",
2271 .compatible = "qcom,sdx65-qmp-usb3-uni-phy",
2274 .compatible = "qcom,sm6115-qmp-usb3-phy",
2277 .compatible = "qcom,sm8150-qmp-usb3-uni-phy",
2280 .compatible = "qcom,sm8250-qmp-usb3-uni-phy",
2283 .compatible = "qcom,sm8350-qmp-usb3-uni-phy",
2293 .name = "qcom-qmp-usb-phy",