18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2020, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/clk.h>
78c2ecf20Sopenharmony_ci#include <linux/delay.h>
88c2ecf20Sopenharmony_ci#include <linux/err.h>
98c2ecf20Sopenharmony_ci#include <linux/io.h>
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/of.h>
138c2ecf20Sopenharmony_ci#include <linux/of_device.h>
148c2ecf20Sopenharmony_ci#include <linux/phy/phy.h>
158c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
168c2ecf20Sopenharmony_ci#include <linux/regmap.h>
178c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
188c2ecf20Sopenharmony_ci#include <linux/reset.h>
198c2ecf20Sopenharmony_ci#include <linux/slab.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_UTMI_CTRL0		(0x3c)
228c2ecf20Sopenharmony_ci#define SLEEPM					BIT(0)
238c2ecf20Sopenharmony_ci#define OPMODE_MASK				GENMASK(4, 3)
248c2ecf20Sopenharmony_ci#define OPMODE_NORMAL				(0x00)
258c2ecf20Sopenharmony_ci#define OPMODE_NONDRIVING			BIT(3)
268c2ecf20Sopenharmony_ci#define TERMSEL					BIT(5)
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_UTMI_CTRL1		(0x40)
298c2ecf20Sopenharmony_ci#define XCVRSEL					BIT(0)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_UTMI_CTRL5		(0x50)
328c2ecf20Sopenharmony_ci#define POR					BIT(1)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON0	(0x54)
358c2ecf20Sopenharmony_ci#define RETENABLEN				BIT(3)
368c2ecf20Sopenharmony_ci#define FSEL_MASK				GENMASK(6, 4)
378c2ecf20Sopenharmony_ci#define FSEL_DEFAULT				(0x3 << 4)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON1	(0x58)
408c2ecf20Sopenharmony_ci#define VBUSVLDEXTSEL0				BIT(4)
418c2ecf20Sopenharmony_ci#define PLLBTUNE				BIT(5)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON2	(0x5c)
448c2ecf20Sopenharmony_ci#define VREGBYPASS				BIT(0)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_HS_PHY_CTRL1		(0x60)
478c2ecf20Sopenharmony_ci#define VBUSVLDEXT0				BIT(0)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_HS_PHY_CTRL2		(0x64)
508c2ecf20Sopenharmony_ci#define USB2_AUTO_RESUME			BIT(0)
518c2ecf20Sopenharmony_ci#define USB2_SUSPEND_N				BIT(2)
528c2ecf20Sopenharmony_ci#define USB2_SUSPEND_N_SEL			BIT(3)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_CFG0			(0x94)
558c2ecf20Sopenharmony_ci#define UTMI_PHY_DATAPATH_CTRL_OVERRIDE_EN	BIT(0)
568c2ecf20Sopenharmony_ci#define UTMI_PHY_CMN_CTRL_OVERRIDE_EN		BIT(1)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define USB2_PHY_USB_PHY_REFCLK_CTRL		(0xa0)
598c2ecf20Sopenharmony_ci#define REFCLK_SEL_MASK				GENMASK(1, 0)
608c2ecf20Sopenharmony_ci#define REFCLK_SEL_DEFAULT			(0x2 << 0)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic const char * const qcom_snps_hsphy_vreg_names[] = {
638c2ecf20Sopenharmony_ci	"vdda-pll", "vdda33", "vdda18",
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define SNPS_HS_NUM_VREGS		ARRAY_SIZE(qcom_snps_hsphy_vreg_names)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/**
698c2ecf20Sopenharmony_ci * struct qcom_snps_hsphy - snps hs phy attributes
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * @dev: device structure
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci * @phy: generic phy
748c2ecf20Sopenharmony_ci * @base: iomapped memory space for snps hs phy
758c2ecf20Sopenharmony_ci *
768c2ecf20Sopenharmony_ci * @num_clks: number of clocks
778c2ecf20Sopenharmony_ci * @clks: array of clocks
788c2ecf20Sopenharmony_ci * @phy_reset: phy reset control
798c2ecf20Sopenharmony_ci * @vregs: regulator supplies bulk data
808c2ecf20Sopenharmony_ci * @phy_initialized: if PHY has been initialized correctly
818c2ecf20Sopenharmony_ci * @mode: contains the current mode the PHY is in
828c2ecf20Sopenharmony_ci * @update_seq_cfg: tuning parameters for phy init
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_cistruct qcom_snps_hsphy {
858c2ecf20Sopenharmony_ci	struct device *dev;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	struct phy *phy;
888c2ecf20Sopenharmony_ci	void __iomem *base;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	int num_clks;
918c2ecf20Sopenharmony_ci	struct clk_bulk_data *clks;
928c2ecf20Sopenharmony_ci	struct reset_control *phy_reset;
938c2ecf20Sopenharmony_ci	struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS];
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	bool phy_initialized;
968c2ecf20Sopenharmony_ci	enum phy_mode mode;
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_clk_init(struct qcom_snps_hsphy *hsphy)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	struct device *dev = hsphy->dev;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	hsphy->num_clks = 2;
1048c2ecf20Sopenharmony_ci	hsphy->clks = devm_kcalloc(dev, hsphy->num_clks, sizeof(*hsphy->clks), GFP_KERNEL);
1058c2ecf20Sopenharmony_ci	if (!hsphy->clks)
1068c2ecf20Sopenharmony_ci		return -ENOMEM;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	/*
1098c2ecf20Sopenharmony_ci	 * TODO: Currently no device tree instantiation of the PHY is using the clock.
1108c2ecf20Sopenharmony_ci	 * This needs to be fixed in order for this code to be able to use devm_clk_bulk_get().
1118c2ecf20Sopenharmony_ci	 */
1128c2ecf20Sopenharmony_ci	hsphy->clks[0].id = "cfg_ahb";
1138c2ecf20Sopenharmony_ci	hsphy->clks[0].clk = devm_clk_get_optional(dev, "cfg_ahb");
1148c2ecf20Sopenharmony_ci	if (IS_ERR(hsphy->clks[0].clk))
1158c2ecf20Sopenharmony_ci		return dev_err_probe(dev, PTR_ERR(hsphy->clks[0].clk),
1168c2ecf20Sopenharmony_ci				     "failed to get cfg_ahb clk\n");
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	hsphy->clks[1].id = "ref";
1198c2ecf20Sopenharmony_ci	hsphy->clks[1].clk = devm_clk_get(dev, "ref");
1208c2ecf20Sopenharmony_ci	if (IS_ERR(hsphy->clks[1].clk))
1218c2ecf20Sopenharmony_ci		return dev_err_probe(dev, PTR_ERR(hsphy->clks[1].clk),
1228c2ecf20Sopenharmony_ci				     "failed to get ref clk\n");
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	return 0;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic inline void qcom_snps_hsphy_write_mask(void __iomem *base, u32 offset,
1288c2ecf20Sopenharmony_ci						u32 mask, u32 val)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	u32 reg;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	reg = readl_relaxed(base + offset);
1338c2ecf20Sopenharmony_ci	reg &= ~mask;
1348c2ecf20Sopenharmony_ci	reg |= val & mask;
1358c2ecf20Sopenharmony_ci	writel_relaxed(reg, base + offset);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	/* Ensure above write is completed */
1388c2ecf20Sopenharmony_ci	readl_relaxed(base + offset);
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	dev_dbg(&hsphy->phy->dev, "Suspend QCOM SNPS PHY\n");
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	if (hsphy->mode == PHY_MODE_USB_HOST) {
1468c2ecf20Sopenharmony_ci		/* Enable auto-resume to meet remote wakeup timing */
1478c2ecf20Sopenharmony_ci		qcom_snps_hsphy_write_mask(hsphy->base,
1488c2ecf20Sopenharmony_ci					   USB2_PHY_USB_PHY_HS_PHY_CTRL2,
1498c2ecf20Sopenharmony_ci					   USB2_AUTO_RESUME,
1508c2ecf20Sopenharmony_ci					   USB2_AUTO_RESUME);
1518c2ecf20Sopenharmony_ci		usleep_range(500, 1000);
1528c2ecf20Sopenharmony_ci		qcom_snps_hsphy_write_mask(hsphy->base,
1538c2ecf20Sopenharmony_ci					   USB2_PHY_USB_PHY_HS_PHY_CTRL2,
1548c2ecf20Sopenharmony_ci					   0, USB2_AUTO_RESUME);
1558c2ecf20Sopenharmony_ci	}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	return 0;
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	dev_dbg(&hsphy->phy->dev, "Resume QCOM SNPS PHY, mode\n");
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	return 0;
1658c2ecf20Sopenharmony_ci}
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic int __maybe_unused qcom_snps_hsphy_runtime_suspend(struct device *dev)
1688c2ecf20Sopenharmony_ci{
1698c2ecf20Sopenharmony_ci	struct qcom_snps_hsphy *hsphy = dev_get_drvdata(dev);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	if (!hsphy->phy_initialized)
1728c2ecf20Sopenharmony_ci		return 0;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	return qcom_snps_hsphy_suspend(hsphy);
1758c2ecf20Sopenharmony_ci}
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_cistatic int __maybe_unused qcom_snps_hsphy_runtime_resume(struct device *dev)
1788c2ecf20Sopenharmony_ci{
1798c2ecf20Sopenharmony_ci	struct qcom_snps_hsphy *hsphy = dev_get_drvdata(dev);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	if (!hsphy->phy_initialized)
1828c2ecf20Sopenharmony_ci		return 0;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	return qcom_snps_hsphy_resume(hsphy);
1858c2ecf20Sopenharmony_ci}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_set_mode(struct phy *phy, enum phy_mode mode,
1888c2ecf20Sopenharmony_ci				    int submode)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	hsphy->mode = mode;
1938c2ecf20Sopenharmony_ci	return 0;
1948c2ecf20Sopenharmony_ci}
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_init(struct phy *phy)
1978c2ecf20Sopenharmony_ci{
1988c2ecf20Sopenharmony_ci	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
1998c2ecf20Sopenharmony_ci	int ret;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	dev_vdbg(&phy->dev, "%s(): Initializing SNPS HS phy\n", __func__);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	ret = regulator_bulk_enable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
2048c2ecf20Sopenharmony_ci	if (ret)
2058c2ecf20Sopenharmony_ci		return ret;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	ret = clk_bulk_prepare_enable(hsphy->num_clks, hsphy->clks);
2088c2ecf20Sopenharmony_ci	if (ret) {
2098c2ecf20Sopenharmony_ci		dev_err(&phy->dev, "failed to enable clocks, %d\n", ret);
2108c2ecf20Sopenharmony_ci		goto poweroff_phy;
2118c2ecf20Sopenharmony_ci	}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	ret = reset_control_assert(hsphy->phy_reset);
2148c2ecf20Sopenharmony_ci	if (ret) {
2158c2ecf20Sopenharmony_ci		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
2168c2ecf20Sopenharmony_ci		goto disable_clks;
2178c2ecf20Sopenharmony_ci	}
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	usleep_range(100, 150);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	ret = reset_control_deassert(hsphy->phy_reset);
2228c2ecf20Sopenharmony_ci	if (ret) {
2238c2ecf20Sopenharmony_ci		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
2248c2ecf20Sopenharmony_ci		goto disable_clks;
2258c2ecf20Sopenharmony_ci	}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
2288c2ecf20Sopenharmony_ci					UTMI_PHY_CMN_CTRL_OVERRIDE_EN,
2298c2ecf20Sopenharmony_ci					UTMI_PHY_CMN_CTRL_OVERRIDE_EN);
2308c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_UTMI_CTRL5,
2318c2ecf20Sopenharmony_ci							POR, POR);
2328c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base,
2338c2ecf20Sopenharmony_ci					USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON0,
2348c2ecf20Sopenharmony_ci					FSEL_MASK, 0);
2358c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base,
2368c2ecf20Sopenharmony_ci					USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON1,
2378c2ecf20Sopenharmony_ci					PLLBTUNE, PLLBTUNE);
2388c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_REFCLK_CTRL,
2398c2ecf20Sopenharmony_ci					REFCLK_SEL_DEFAULT, REFCLK_SEL_MASK);
2408c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base,
2418c2ecf20Sopenharmony_ci					USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON1,
2428c2ecf20Sopenharmony_ci					VBUSVLDEXTSEL0, VBUSVLDEXTSEL0);
2438c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_HS_PHY_CTRL1,
2448c2ecf20Sopenharmony_ci					VBUSVLDEXT0, VBUSVLDEXT0);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base,
2478c2ecf20Sopenharmony_ci					USB2_PHY_USB_PHY_HS_PHY_CTRL_COMMON2,
2488c2ecf20Sopenharmony_ci					VREGBYPASS, VREGBYPASS);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_HS_PHY_CTRL2,
2518c2ecf20Sopenharmony_ci					USB2_SUSPEND_N_SEL | USB2_SUSPEND_N,
2528c2ecf20Sopenharmony_ci					USB2_SUSPEND_N_SEL | USB2_SUSPEND_N);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_UTMI_CTRL0,
2558c2ecf20Sopenharmony_ci					SLEEPM, SLEEPM);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_UTMI_CTRL5,
2588c2ecf20Sopenharmony_ci					POR, 0);
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_HS_PHY_CTRL2,
2618c2ecf20Sopenharmony_ci					USB2_SUSPEND_N_SEL, 0);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
2648c2ecf20Sopenharmony_ci					UTMI_PHY_CMN_CTRL_OVERRIDE_EN, 0);
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	hsphy->phy_initialized = true;
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	return 0;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cidisable_clks:
2718c2ecf20Sopenharmony_ci	clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
2728c2ecf20Sopenharmony_cipoweroff_phy:
2738c2ecf20Sopenharmony_ci	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	return ret;
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_exit(struct phy *phy)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	reset_control_assert(hsphy->phy_reset);
2838c2ecf20Sopenharmony_ci	clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
2848c2ecf20Sopenharmony_ci	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
2858c2ecf20Sopenharmony_ci	hsphy->phy_initialized = false;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	return 0;
2888c2ecf20Sopenharmony_ci}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_cistatic const struct phy_ops qcom_snps_hsphy_gen_ops = {
2918c2ecf20Sopenharmony_ci	.init		= qcom_snps_hsphy_init,
2928c2ecf20Sopenharmony_ci	.exit		= qcom_snps_hsphy_exit,
2938c2ecf20Sopenharmony_ci	.set_mode	= qcom_snps_hsphy_set_mode,
2948c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,
2958c2ecf20Sopenharmony_ci};
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistatic const struct of_device_id qcom_snps_hsphy_of_match_table[] = {
2988c2ecf20Sopenharmony_ci	{ .compatible	= "qcom,sm8150-usb-hs-phy", },
2998c2ecf20Sopenharmony_ci	{ .compatible	= "qcom,usb-snps-hs-7nm-phy", },
3008c2ecf20Sopenharmony_ci	{ .compatible	= "qcom,usb-snps-femto-v2-phy",	},
3018c2ecf20Sopenharmony_ci	{ }
3028c2ecf20Sopenharmony_ci};
3038c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, qcom_snps_hsphy_of_match_table);
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistatic const struct dev_pm_ops qcom_snps_hsphy_pm_ops = {
3068c2ecf20Sopenharmony_ci	SET_RUNTIME_PM_OPS(qcom_snps_hsphy_runtime_suspend,
3078c2ecf20Sopenharmony_ci			   qcom_snps_hsphy_runtime_resume, NULL)
3088c2ecf20Sopenharmony_ci};
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_cistatic int qcom_snps_hsphy_probe(struct platform_device *pdev)
3118c2ecf20Sopenharmony_ci{
3128c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
3138c2ecf20Sopenharmony_ci	struct qcom_snps_hsphy *hsphy;
3148c2ecf20Sopenharmony_ci	struct phy_provider *phy_provider;
3158c2ecf20Sopenharmony_ci	struct phy *generic_phy;
3168c2ecf20Sopenharmony_ci	int ret, i;
3178c2ecf20Sopenharmony_ci	int num;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	hsphy = devm_kzalloc(dev, sizeof(*hsphy), GFP_KERNEL);
3208c2ecf20Sopenharmony_ci	if (!hsphy)
3218c2ecf20Sopenharmony_ci		return -ENOMEM;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	hsphy->dev = dev;
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	hsphy->base = devm_platform_ioremap_resource(pdev, 0);
3268c2ecf20Sopenharmony_ci	if (IS_ERR(hsphy->base))
3278c2ecf20Sopenharmony_ci		return PTR_ERR(hsphy->base);
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	ret = qcom_snps_hsphy_clk_init(hsphy);
3308c2ecf20Sopenharmony_ci	if (ret)
3318c2ecf20Sopenharmony_ci		return dev_err_probe(dev, ret, "failed to initialize clocks\n");
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	hsphy->phy_reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
3348c2ecf20Sopenharmony_ci	if (IS_ERR(hsphy->phy_reset)) {
3358c2ecf20Sopenharmony_ci		dev_err(dev, "failed to get phy core reset\n");
3368c2ecf20Sopenharmony_ci		return PTR_ERR(hsphy->phy_reset);
3378c2ecf20Sopenharmony_ci	}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	num = ARRAY_SIZE(hsphy->vregs);
3408c2ecf20Sopenharmony_ci	for (i = 0; i < num; i++)
3418c2ecf20Sopenharmony_ci		hsphy->vregs[i].supply = qcom_snps_hsphy_vreg_names[i];
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	ret = devm_regulator_bulk_get(dev, num, hsphy->vregs);
3448c2ecf20Sopenharmony_ci	if (ret)
3458c2ecf20Sopenharmony_ci		return dev_err_probe(dev, ret,
3468c2ecf20Sopenharmony_ci				     "failed to get regulator supplies\n");
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	pm_runtime_set_active(dev);
3498c2ecf20Sopenharmony_ci	pm_runtime_enable(dev);
3508c2ecf20Sopenharmony_ci	/*
3518c2ecf20Sopenharmony_ci	 * Prevent runtime pm from being ON by default. Users can enable
3528c2ecf20Sopenharmony_ci	 * it using power/control in sysfs.
3538c2ecf20Sopenharmony_ci	 */
3548c2ecf20Sopenharmony_ci	pm_runtime_forbid(dev);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_hsphy_gen_ops);
3578c2ecf20Sopenharmony_ci	if (IS_ERR(generic_phy)) {
3588c2ecf20Sopenharmony_ci		ret = PTR_ERR(generic_phy);
3598c2ecf20Sopenharmony_ci		dev_err(dev, "failed to create phy, %d\n", ret);
3608c2ecf20Sopenharmony_ci		return ret;
3618c2ecf20Sopenharmony_ci	}
3628c2ecf20Sopenharmony_ci	hsphy->phy = generic_phy;
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	dev_set_drvdata(dev, hsphy);
3658c2ecf20Sopenharmony_ci	phy_set_drvdata(generic_phy, hsphy);
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
3688c2ecf20Sopenharmony_ci	if (!IS_ERR(phy_provider))
3698c2ecf20Sopenharmony_ci		dev_dbg(dev, "Registered Qcom-SNPS HS phy\n");
3708c2ecf20Sopenharmony_ci	else
3718c2ecf20Sopenharmony_ci		pm_runtime_disable(dev);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	return PTR_ERR_OR_ZERO(phy_provider);
3748c2ecf20Sopenharmony_ci}
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistatic struct platform_driver qcom_snps_hsphy_driver = {
3778c2ecf20Sopenharmony_ci	.probe		= qcom_snps_hsphy_probe,
3788c2ecf20Sopenharmony_ci	.driver = {
3798c2ecf20Sopenharmony_ci		.name	= "qcom-snps-hs-femto-v2-phy",
3808c2ecf20Sopenharmony_ci		.pm = &qcom_snps_hsphy_pm_ops,
3818c2ecf20Sopenharmony_ci		.of_match_table = qcom_snps_hsphy_of_match_table,
3828c2ecf20Sopenharmony_ci	},
3838c2ecf20Sopenharmony_ci};
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cimodule_platform_driver(qcom_snps_hsphy_driver);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Qualcomm SNPS FEMTO USB HS PHY V2 driver");
3888c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
389