18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Samsung Exynos5 SoC series USB DRD PHY driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2014 Samsung Electronics Co., Ltd.
88c2ecf20Sopenharmony_ci * Author: Vivek Gautam <gautam.vivek@samsung.com>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/clk.h>
128c2ecf20Sopenharmony_ci#include <linux/delay.h>
138c2ecf20Sopenharmony_ci#include <linux/io.h>
148c2ecf20Sopenharmony_ci#include <linux/kernel.h>
158c2ecf20Sopenharmony_ci#include <linux/module.h>
168c2ecf20Sopenharmony_ci#include <linux/of.h>
178c2ecf20Sopenharmony_ci#include <linux/of_address.h>
188c2ecf20Sopenharmony_ci#include <linux/of_device.h>
198c2ecf20Sopenharmony_ci#include <linux/iopoll.h>
208c2ecf20Sopenharmony_ci#include <linux/phy/phy.h>
218c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
228c2ecf20Sopenharmony_ci#include <linux/mutex.h>
238c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
248c2ecf20Sopenharmony_ci#include <linux/regmap.h>
258c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
268c2ecf20Sopenharmony_ci#include <linux/soc/samsung/exynos-regs-pmu.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* Exynos USB PHY registers */
298c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_9MHZ6		0x0
308c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_10MHZ		0x1
318c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_12MHZ		0x2
328c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_19MHZ2		0x3
338c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_20MHZ		0x4
348c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_24MHZ		0x5
358c2ecf20Sopenharmony_ci#define EXYNOS5_FSEL_50MHZ		0x7
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* Exynos5: USB 3.0 DRD PHY registers */
388c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_LINKSYSTEM			0x04
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define LINKSYSTEM_FLADJ_MASK			(0x3f << 1)
418c2ecf20Sopenharmony_ci#define LINKSYSTEM_FLADJ(_x)			((_x) << 1)
428c2ecf20Sopenharmony_ci#define LINKSYSTEM_XHCI_VERSION_CONTROL		BIT(27)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYUTMI			0x08
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define PHYUTMI_OTGDISABLE			BIT(6)
478c2ecf20Sopenharmony_ci#define PHYUTMI_FORCESUSPEND			BIT(1)
488c2ecf20Sopenharmony_ci#define PHYUTMI_FORCESLEEP			BIT(0)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYPIPE			0x0c
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYCLKRST			0x10
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define PHYCLKRST_EN_UTMISUSPEND		BIT(31)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define PHYCLKRST_SSC_REFCLKSEL_MASK		(0xff << 23)
578c2ecf20Sopenharmony_ci#define PHYCLKRST_SSC_REFCLKSEL(_x)		((_x) << 23)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define PHYCLKRST_SSC_RANGE_MASK		(0x03 << 21)
608c2ecf20Sopenharmony_ci#define PHYCLKRST_SSC_RANGE(_x)			((_x) << 21)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define PHYCLKRST_SSC_EN			BIT(20)
638c2ecf20Sopenharmony_ci#define PHYCLKRST_REF_SSP_EN			BIT(19)
648c2ecf20Sopenharmony_ci#define PHYCLKRST_REF_CLKDIV2			BIT(18)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define PHYCLKRST_MPLL_MULTIPLIER_MASK		(0x7f << 11)
678c2ecf20Sopenharmony_ci#define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF	(0x19 << 11)
688c2ecf20Sopenharmony_ci#define PHYCLKRST_MPLL_MULTIPLIER_50M_REF	(0x32 << 11)
698c2ecf20Sopenharmony_ci#define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF	(0x68 << 11)
708c2ecf20Sopenharmony_ci#define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF	(0x7d << 11)
718c2ecf20Sopenharmony_ci#define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF	(0x02 << 11)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL_UTMI_MASK		(0x7 << 5)
748c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL_PIPE_MASK		(0x7 << 8)
758c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL(_x)			((_x) << 5)
768c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL_PAD_100MHZ		(0x27 << 5)
778c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL_PAD_24MHZ		(0x2a << 5)
788c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL_PAD_20MHZ		(0x31 << 5)
798c2ecf20Sopenharmony_ci#define PHYCLKRST_FSEL_PAD_19_2MHZ		(0x38 << 5)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define PHYCLKRST_RETENABLEN			BIT(4)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define PHYCLKRST_REFCLKSEL_MASK		(0x03 << 2)
848c2ecf20Sopenharmony_ci#define PHYCLKRST_REFCLKSEL_PAD_REFCLK		(0x2 << 2)
858c2ecf20Sopenharmony_ci#define PHYCLKRST_REFCLKSEL_EXT_REFCLK		(0x3 << 2)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define PHYCLKRST_PORTRESET			BIT(1)
888c2ecf20Sopenharmony_ci#define PHYCLKRST_COMMONONN			BIT(0)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYREG0			0x14
918c2ecf20Sopenharmony_ci#define PHYREG0_SSC_REF_CLK_SEL			BIT(21)
928c2ecf20Sopenharmony_ci#define PHYREG0_SSC_RANGE			BIT(20)
938c2ecf20Sopenharmony_ci#define PHYREG0_CR_WRITE			BIT(19)
948c2ecf20Sopenharmony_ci#define PHYREG0_CR_READ				BIT(18)
958c2ecf20Sopenharmony_ci#define PHYREG0_CR_DATA_IN(_x)			((_x) << 2)
968c2ecf20Sopenharmony_ci#define PHYREG0_CR_CAP_DATA			BIT(1)
978c2ecf20Sopenharmony_ci#define PHYREG0_CR_CAP_ADDR			BIT(0)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYREG1			0x18
1008c2ecf20Sopenharmony_ci#define PHYREG1_CR_DATA_OUT(_x)			((_x) << 1)
1018c2ecf20Sopenharmony_ci#define PHYREG1_CR_ACK				BIT(0)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYPARAM0			0x1c
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define PHYPARAM0_REF_USE_PAD			BIT(31)
1068c2ecf20Sopenharmony_ci#define PHYPARAM0_REF_LOSLEVEL_MASK		(0x1f << 26)
1078c2ecf20Sopenharmony_ci#define PHYPARAM0_REF_LOSLEVEL			(0x9 << 26)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYPARAM1			0x20
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define PHYPARAM1_PCS_TXDEEMPH_MASK		(0x1f << 0)
1128c2ecf20Sopenharmony_ci#define PHYPARAM1_PCS_TXDEEMPH			(0x1c)
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYTERM			0x24
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYTEST			0x28
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define PHYTEST_POWERDOWN_SSP			BIT(3)
1198c2ecf20Sopenharmony_ci#define PHYTEST_POWERDOWN_HSP			BIT(2)
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYADP			0x2c
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYUTMICLKSEL		0x30
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define PHYUTMICLKSEL_UTMI_CLKSEL		BIT(2)
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYRESUME			0x34
1288c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_LINKPORT			0x44
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/* USB 3.0 DRD PHY SS Function Control Reg; accessed by CR_PORT */
1318c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYSS_LOSLEVEL_OVRD_IN		(0x15)
1328c2ecf20Sopenharmony_ci#define LOSLEVEL_OVRD_IN_LOS_BIAS_5420			(0x5 << 13)
1338c2ecf20Sopenharmony_ci#define LOSLEVEL_OVRD_IN_LOS_BIAS_DEFAULT		(0x0 << 13)
1348c2ecf20Sopenharmony_ci#define LOSLEVEL_OVRD_IN_EN				(0x1 << 10)
1358c2ecf20Sopenharmony_ci#define LOSLEVEL_OVRD_IN_LOS_LEVEL_DEFAULT		(0x9 << 0)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYSS_TX_VBOOSTLEVEL_OVRD_IN	(0x12)
1388c2ecf20Sopenharmony_ci#define TX_VBOOSTLEVEL_OVRD_IN_VBOOST_5420		(0x5 << 13)
1398c2ecf20Sopenharmony_ci#define TX_VBOOSTLEVEL_OVRD_IN_VBOOST_DEFAULT		(0x4 << 13)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define EXYNOS5_DRD_PHYSS_LANE0_TX_DEBUG		(0x1010)
1428c2ecf20Sopenharmony_ci#define LANE0_TX_DEBUG_RXDET_MEAS_TIME_19M2_20M		(0x4 << 4)
1438c2ecf20Sopenharmony_ci#define LANE0_TX_DEBUG_RXDET_MEAS_TIME_24M		(0x8 << 4)
1448c2ecf20Sopenharmony_ci#define LANE0_TX_DEBUG_RXDET_MEAS_TIME_25M_26M		(0x8 << 4)
1458c2ecf20Sopenharmony_ci#define LANE0_TX_DEBUG_RXDET_MEAS_TIME_48M_50M_52M	(0x20 << 4)
1468c2ecf20Sopenharmony_ci#define LANE0_TX_DEBUG_RXDET_MEAS_TIME_62M5		(0x20 << 4)
1478c2ecf20Sopenharmony_ci#define LANE0_TX_DEBUG_RXDET_MEAS_TIME_96M_100M		(0x40 << 4)
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define KHZ	1000
1508c2ecf20Sopenharmony_ci#define MHZ	(KHZ * KHZ)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cienum exynos5_usbdrd_phy_id {
1538c2ecf20Sopenharmony_ci	EXYNOS5_DRDPHY_UTMI,
1548c2ecf20Sopenharmony_ci	EXYNOS5_DRDPHY_PIPE3,
1558c2ecf20Sopenharmony_ci	EXYNOS5_DRDPHYS_NUM,
1568c2ecf20Sopenharmony_ci};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistruct phy_usb_instance;
1598c2ecf20Sopenharmony_cistruct exynos5_usbdrd_phy;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistruct exynos5_usbdrd_phy_config {
1628c2ecf20Sopenharmony_ci	u32 id;
1638c2ecf20Sopenharmony_ci	void (*phy_isol)(struct phy_usb_instance *inst, u32 on);
1648c2ecf20Sopenharmony_ci	void (*phy_init)(struct exynos5_usbdrd_phy *phy_drd);
1658c2ecf20Sopenharmony_ci	unsigned int (*set_refclk)(struct phy_usb_instance *inst);
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistruct exynos5_usbdrd_phy_drvdata {
1698c2ecf20Sopenharmony_ci	const struct exynos5_usbdrd_phy_config *phy_cfg;
1708c2ecf20Sopenharmony_ci	u32 pmu_offset_usbdrd0_phy;
1718c2ecf20Sopenharmony_ci	u32 pmu_offset_usbdrd1_phy;
1728c2ecf20Sopenharmony_ci	bool has_common_clk_gate;
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci/**
1768c2ecf20Sopenharmony_ci * struct exynos5_usbdrd_phy - driver data for USB 3.0 PHY
1778c2ecf20Sopenharmony_ci * @dev: pointer to device instance of this platform device
1788c2ecf20Sopenharmony_ci * @reg_phy: usb phy controller register memory base
1798c2ecf20Sopenharmony_ci * @clk: phy clock for register access
1808c2ecf20Sopenharmony_ci * @pipeclk: clock for pipe3 phy
1818c2ecf20Sopenharmony_ci * @utmiclk: clock for utmi+ phy
1828c2ecf20Sopenharmony_ci * @itpclk: clock for ITP generation
1838c2ecf20Sopenharmony_ci * @drv_data: pointer to SoC level driver data structure
1848c2ecf20Sopenharmony_ci * @phys: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY
1858c2ecf20Sopenharmony_ci *	    instances each with its 'phy' and 'phy_cfg'.
1868c2ecf20Sopenharmony_ci * @extrefclk: frequency select settings when using 'separate
1878c2ecf20Sopenharmony_ci *	       reference clocks' for SS and HS operations
1888c2ecf20Sopenharmony_ci * @ref_clk: reference clock to PHY block from which PHY's
1898c2ecf20Sopenharmony_ci *	     operational clocks are derived
1908c2ecf20Sopenharmony_ci * @vbus: VBUS regulator for phy
1918c2ecf20Sopenharmony_ci * @vbus_boost: Boost regulator for VBUS present on few Exynos boards
1928c2ecf20Sopenharmony_ci */
1938c2ecf20Sopenharmony_cistruct exynos5_usbdrd_phy {
1948c2ecf20Sopenharmony_ci	struct device *dev;
1958c2ecf20Sopenharmony_ci	void __iomem *reg_phy;
1968c2ecf20Sopenharmony_ci	struct clk *clk;
1978c2ecf20Sopenharmony_ci	struct clk *pipeclk;
1988c2ecf20Sopenharmony_ci	struct clk *utmiclk;
1998c2ecf20Sopenharmony_ci	struct clk *itpclk;
2008c2ecf20Sopenharmony_ci	const struct exynos5_usbdrd_phy_drvdata *drv_data;
2018c2ecf20Sopenharmony_ci	struct phy_usb_instance {
2028c2ecf20Sopenharmony_ci		struct phy *phy;
2038c2ecf20Sopenharmony_ci		u32 index;
2048c2ecf20Sopenharmony_ci		struct regmap *reg_pmu;
2058c2ecf20Sopenharmony_ci		u32 pmu_offset;
2068c2ecf20Sopenharmony_ci		const struct exynos5_usbdrd_phy_config *phy_cfg;
2078c2ecf20Sopenharmony_ci	} phys[EXYNOS5_DRDPHYS_NUM];
2088c2ecf20Sopenharmony_ci	u32 extrefclk;
2098c2ecf20Sopenharmony_ci	struct clk *ref_clk;
2108c2ecf20Sopenharmony_ci	struct regulator *vbus;
2118c2ecf20Sopenharmony_ci	struct regulator *vbus_boost;
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic inline
2158c2ecf20Sopenharmony_cistruct exynos5_usbdrd_phy *to_usbdrd_phy(struct phy_usb_instance *inst)
2168c2ecf20Sopenharmony_ci{
2178c2ecf20Sopenharmony_ci	return container_of((inst), struct exynos5_usbdrd_phy,
2188c2ecf20Sopenharmony_ci			    phys[(inst)->index]);
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/*
2228c2ecf20Sopenharmony_ci * exynos5_rate_to_clk() converts the supplied clock rate to the value that
2238c2ecf20Sopenharmony_ci * can be written to the phy register.
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_cistatic unsigned int exynos5_rate_to_clk(unsigned long rate, u32 *reg)
2268c2ecf20Sopenharmony_ci{
2278c2ecf20Sopenharmony_ci	/* EXYNOS5_FSEL_MASK */
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	switch (rate) {
2308c2ecf20Sopenharmony_ci	case 9600 * KHZ:
2318c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_9MHZ6;
2328c2ecf20Sopenharmony_ci		break;
2338c2ecf20Sopenharmony_ci	case 10 * MHZ:
2348c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_10MHZ;
2358c2ecf20Sopenharmony_ci		break;
2368c2ecf20Sopenharmony_ci	case 12 * MHZ:
2378c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_12MHZ;
2388c2ecf20Sopenharmony_ci		break;
2398c2ecf20Sopenharmony_ci	case 19200 * KHZ:
2408c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_19MHZ2;
2418c2ecf20Sopenharmony_ci		break;
2428c2ecf20Sopenharmony_ci	case 20 * MHZ:
2438c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_20MHZ;
2448c2ecf20Sopenharmony_ci		break;
2458c2ecf20Sopenharmony_ci	case 24 * MHZ:
2468c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_24MHZ;
2478c2ecf20Sopenharmony_ci		break;
2488c2ecf20Sopenharmony_ci	case 50 * MHZ:
2498c2ecf20Sopenharmony_ci		*reg = EXYNOS5_FSEL_50MHZ;
2508c2ecf20Sopenharmony_ci		break;
2518c2ecf20Sopenharmony_ci	default:
2528c2ecf20Sopenharmony_ci		return -EINVAL;
2538c2ecf20Sopenharmony_ci	}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	return 0;
2568c2ecf20Sopenharmony_ci}
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_cistatic void exynos5_usbdrd_phy_isol(struct phy_usb_instance *inst,
2598c2ecf20Sopenharmony_ci						unsigned int on)
2608c2ecf20Sopenharmony_ci{
2618c2ecf20Sopenharmony_ci	unsigned int val;
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	if (!inst->reg_pmu)
2648c2ecf20Sopenharmony_ci		return;
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	val = on ? 0 : EXYNOS4_PHY_ENABLE;
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	regmap_update_bits(inst->reg_pmu, inst->pmu_offset,
2698c2ecf20Sopenharmony_ci			   EXYNOS4_PHY_ENABLE, val);
2708c2ecf20Sopenharmony_ci}
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci/*
2738c2ecf20Sopenharmony_ci * Sets the pipe3 phy's clk as EXTREFCLK (XXTI) which is internal clock
2748c2ecf20Sopenharmony_ci * from clock core. Further sets multiplier values and spread spectrum
2758c2ecf20Sopenharmony_ci * clock settings for SuperSpeed operations.
2768c2ecf20Sopenharmony_ci */
2778c2ecf20Sopenharmony_cistatic unsigned int
2788c2ecf20Sopenharmony_ciexynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	u32 reg;
2818c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	/* restore any previous reference clock settings */
2848c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	/* Use EXTREFCLK as ref clock */
2878c2ecf20Sopenharmony_ci	reg &= ~PHYCLKRST_REFCLKSEL_MASK;
2888c2ecf20Sopenharmony_ci	reg |=	PHYCLKRST_REFCLKSEL_EXT_REFCLK;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	/* FSEL settings corresponding to reference clock */
2918c2ecf20Sopenharmony_ci	reg &= ~PHYCLKRST_FSEL_PIPE_MASK |
2928c2ecf20Sopenharmony_ci		PHYCLKRST_MPLL_MULTIPLIER_MASK |
2938c2ecf20Sopenharmony_ci		PHYCLKRST_SSC_REFCLKSEL_MASK;
2948c2ecf20Sopenharmony_ci	switch (phy_drd->extrefclk) {
2958c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_50MHZ:
2968c2ecf20Sopenharmony_ci		reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF |
2978c2ecf20Sopenharmony_ci			PHYCLKRST_SSC_REFCLKSEL(0x00));
2988c2ecf20Sopenharmony_ci		break;
2998c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_24MHZ:
3008c2ecf20Sopenharmony_ci		reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF |
3018c2ecf20Sopenharmony_ci			PHYCLKRST_SSC_REFCLKSEL(0x88));
3028c2ecf20Sopenharmony_ci		break;
3038c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_20MHZ:
3048c2ecf20Sopenharmony_ci		reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF |
3058c2ecf20Sopenharmony_ci			PHYCLKRST_SSC_REFCLKSEL(0x00));
3068c2ecf20Sopenharmony_ci		break;
3078c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_19MHZ2:
3088c2ecf20Sopenharmony_ci		reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF |
3098c2ecf20Sopenharmony_ci			PHYCLKRST_SSC_REFCLKSEL(0x88));
3108c2ecf20Sopenharmony_ci		break;
3118c2ecf20Sopenharmony_ci	default:
3128c2ecf20Sopenharmony_ci		dev_dbg(phy_drd->dev, "unsupported ref clk\n");
3138c2ecf20Sopenharmony_ci		break;
3148c2ecf20Sopenharmony_ci	}
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	return reg;
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci/*
3208c2ecf20Sopenharmony_ci * Sets the utmi phy's clk as EXTREFCLK (XXTI) which is internal clock
3218c2ecf20Sopenharmony_ci * from clock core. Further sets the FSEL values for HighSpeed operations.
3228c2ecf20Sopenharmony_ci */
3238c2ecf20Sopenharmony_cistatic unsigned int
3248c2ecf20Sopenharmony_ciexynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance *inst)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	u32 reg;
3278c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	/* restore any previous reference clock settings */
3308c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	reg &= ~PHYCLKRST_REFCLKSEL_MASK;
3338c2ecf20Sopenharmony_ci	reg |=	PHYCLKRST_REFCLKSEL_EXT_REFCLK;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	reg &= ~PHYCLKRST_FSEL_UTMI_MASK |
3368c2ecf20Sopenharmony_ci		PHYCLKRST_MPLL_MULTIPLIER_MASK |
3378c2ecf20Sopenharmony_ci		PHYCLKRST_SSC_REFCLKSEL_MASK;
3388c2ecf20Sopenharmony_ci	reg |= PHYCLKRST_FSEL(phy_drd->extrefclk);
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	return reg;
3418c2ecf20Sopenharmony_ci}
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic void exynos5_usbdrd_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
3448c2ecf20Sopenharmony_ci{
3458c2ecf20Sopenharmony_ci	u32 reg;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
3488c2ecf20Sopenharmony_ci	/* Set Tx De-Emphasis level */
3498c2ecf20Sopenharmony_ci	reg &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
3508c2ecf20Sopenharmony_ci	reg |=	PHYPARAM1_PCS_TXDEEMPH;
3518c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
3548c2ecf20Sopenharmony_ci	reg &= ~PHYTEST_POWERDOWN_SSP;
3558c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
3568c2ecf20Sopenharmony_ci}
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_cistatic void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	u32 reg;
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
3638c2ecf20Sopenharmony_ci	/* Set Loss-of-Signal Detector sensitivity */
3648c2ecf20Sopenharmony_ci	reg &= ~PHYPARAM0_REF_LOSLEVEL_MASK;
3658c2ecf20Sopenharmony_ci	reg |=	PHYPARAM0_REF_LOSLEVEL;
3668c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
3698c2ecf20Sopenharmony_ci	/* Set Tx De-Emphasis level */
3708c2ecf20Sopenharmony_ci	reg &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
3718c2ecf20Sopenharmony_ci	reg |=	PHYPARAM1_PCS_TXDEEMPH;
3728c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	/* UTMI Power Control */
3758c2ecf20Sopenharmony_ci	writel(PHYUTMI_OTGDISABLE, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
3788c2ecf20Sopenharmony_ci	reg &= ~PHYTEST_POWERDOWN_HSP;
3798c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_init(struct phy *phy)
3838c2ecf20Sopenharmony_ci{
3848c2ecf20Sopenharmony_ci	int ret;
3858c2ecf20Sopenharmony_ci	u32 reg;
3868c2ecf20Sopenharmony_ci	struct phy_usb_instance *inst = phy_get_drvdata(phy);
3878c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	ret = clk_prepare_enable(phy_drd->clk);
3908c2ecf20Sopenharmony_ci	if (ret)
3918c2ecf20Sopenharmony_ci		return ret;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	/* Reset USB 3.0 PHY */
3948c2ecf20Sopenharmony_ci	writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
3958c2ecf20Sopenharmony_ci	writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYRESUME);
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	/*
3988c2ecf20Sopenharmony_ci	 * Setting the Frame length Adj value[6:1] to default 0x20
3998c2ecf20Sopenharmony_ci	 * See xHCI 1.0 spec, 5.2.4
4008c2ecf20Sopenharmony_ci	 */
4018c2ecf20Sopenharmony_ci	reg =	LINKSYSTEM_XHCI_VERSION_CONTROL |
4028c2ecf20Sopenharmony_ci		LINKSYSTEM_FLADJ(0x20);
4038c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
4068c2ecf20Sopenharmony_ci	/* Select PHY CLK source */
4078c2ecf20Sopenharmony_ci	reg &= ~PHYPARAM0_REF_USE_PAD;
4088c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	/* This bit must be set for both HS and SS operations */
4118c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
4128c2ecf20Sopenharmony_ci	reg |= PHYUTMICLKSEL_UTMI_CLKSEL;
4138c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	/* UTMI or PIPE3 specific init */
4168c2ecf20Sopenharmony_ci	inst->phy_cfg->phy_init(phy_drd);
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	/* reference clock settings */
4198c2ecf20Sopenharmony_ci	reg = inst->phy_cfg->set_refclk(inst);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci		/* Digital power supply in normal operating mode */
4228c2ecf20Sopenharmony_ci	reg |=	PHYCLKRST_RETENABLEN |
4238c2ecf20Sopenharmony_ci		/* Enable ref clock for SS function */
4248c2ecf20Sopenharmony_ci		PHYCLKRST_REF_SSP_EN |
4258c2ecf20Sopenharmony_ci		/* Enable spread spectrum */
4268c2ecf20Sopenharmony_ci		PHYCLKRST_SSC_EN |
4278c2ecf20Sopenharmony_ci		/* Power down HS Bias and PLL blocks in suspend mode */
4288c2ecf20Sopenharmony_ci		PHYCLKRST_COMMONONN |
4298c2ecf20Sopenharmony_ci		/* Reset the port */
4308c2ecf20Sopenharmony_ci		PHYCLKRST_PORTRESET;
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	udelay(10);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	reg &= ~PHYCLKRST_PORTRESET;
4378c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	clk_disable_unprepare(phy_drd->clk);
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	return 0;
4428c2ecf20Sopenharmony_ci}
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_exit(struct phy *phy)
4458c2ecf20Sopenharmony_ci{
4468c2ecf20Sopenharmony_ci	int ret;
4478c2ecf20Sopenharmony_ci	u32 reg;
4488c2ecf20Sopenharmony_ci	struct phy_usb_instance *inst = phy_get_drvdata(phy);
4498c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	ret = clk_prepare_enable(phy_drd->clk);
4528c2ecf20Sopenharmony_ci	if (ret)
4538c2ecf20Sopenharmony_ci		return ret;
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci	reg =	PHYUTMI_OTGDISABLE |
4568c2ecf20Sopenharmony_ci		PHYUTMI_FORCESUSPEND |
4578c2ecf20Sopenharmony_ci		PHYUTMI_FORCESLEEP;
4588c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	/* Resetting the PHYCLKRST enable bits to reduce leakage current */
4618c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
4628c2ecf20Sopenharmony_ci	reg &= ~(PHYCLKRST_REF_SSP_EN |
4638c2ecf20Sopenharmony_ci		 PHYCLKRST_SSC_EN |
4648c2ecf20Sopenharmony_ci		 PHYCLKRST_COMMONONN);
4658c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	/* Control PHYTEST to remove leakage current */
4688c2ecf20Sopenharmony_ci	reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
4698c2ecf20Sopenharmony_ci	reg |=	PHYTEST_POWERDOWN_SSP |
4708c2ecf20Sopenharmony_ci		PHYTEST_POWERDOWN_HSP;
4718c2ecf20Sopenharmony_ci	writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	clk_disable_unprepare(phy_drd->clk);
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	return 0;
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_power_on(struct phy *phy)
4798c2ecf20Sopenharmony_ci{
4808c2ecf20Sopenharmony_ci	int ret;
4818c2ecf20Sopenharmony_ci	struct phy_usb_instance *inst = phy_get_drvdata(phy);
4828c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci	dev_dbg(phy_drd->dev, "Request to power_on usbdrd_phy phy\n");
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci	clk_prepare_enable(phy_drd->ref_clk);
4878c2ecf20Sopenharmony_ci	if (!phy_drd->drv_data->has_common_clk_gate) {
4888c2ecf20Sopenharmony_ci		clk_prepare_enable(phy_drd->pipeclk);
4898c2ecf20Sopenharmony_ci		clk_prepare_enable(phy_drd->utmiclk);
4908c2ecf20Sopenharmony_ci		clk_prepare_enable(phy_drd->itpclk);
4918c2ecf20Sopenharmony_ci	}
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	/* Enable VBUS supply */
4948c2ecf20Sopenharmony_ci	if (phy_drd->vbus_boost) {
4958c2ecf20Sopenharmony_ci		ret = regulator_enable(phy_drd->vbus_boost);
4968c2ecf20Sopenharmony_ci		if (ret) {
4978c2ecf20Sopenharmony_ci			dev_err(phy_drd->dev,
4988c2ecf20Sopenharmony_ci				"Failed to enable VBUS boost supply\n");
4998c2ecf20Sopenharmony_ci			goto fail_vbus;
5008c2ecf20Sopenharmony_ci		}
5018c2ecf20Sopenharmony_ci	}
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci	if (phy_drd->vbus) {
5048c2ecf20Sopenharmony_ci		ret = regulator_enable(phy_drd->vbus);
5058c2ecf20Sopenharmony_ci		if (ret) {
5068c2ecf20Sopenharmony_ci			dev_err(phy_drd->dev, "Failed to enable VBUS supply\n");
5078c2ecf20Sopenharmony_ci			goto fail_vbus_boost;
5088c2ecf20Sopenharmony_ci		}
5098c2ecf20Sopenharmony_ci	}
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci	/* Power-on PHY*/
5128c2ecf20Sopenharmony_ci	inst->phy_cfg->phy_isol(inst, 0);
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	return 0;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_cifail_vbus_boost:
5178c2ecf20Sopenharmony_ci	if (phy_drd->vbus_boost)
5188c2ecf20Sopenharmony_ci		regulator_disable(phy_drd->vbus_boost);
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_cifail_vbus:
5218c2ecf20Sopenharmony_ci	clk_disable_unprepare(phy_drd->ref_clk);
5228c2ecf20Sopenharmony_ci	if (!phy_drd->drv_data->has_common_clk_gate) {
5238c2ecf20Sopenharmony_ci		clk_disable_unprepare(phy_drd->itpclk);
5248c2ecf20Sopenharmony_ci		clk_disable_unprepare(phy_drd->utmiclk);
5258c2ecf20Sopenharmony_ci		clk_disable_unprepare(phy_drd->pipeclk);
5268c2ecf20Sopenharmony_ci	}
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	return ret;
5298c2ecf20Sopenharmony_ci}
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_power_off(struct phy *phy)
5328c2ecf20Sopenharmony_ci{
5338c2ecf20Sopenharmony_ci	struct phy_usb_instance *inst = phy_get_drvdata(phy);
5348c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	dev_dbg(phy_drd->dev, "Request to power_off usbdrd_phy phy\n");
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci	/* Power-off the PHY */
5398c2ecf20Sopenharmony_ci	inst->phy_cfg->phy_isol(inst, 1);
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	/* Disable VBUS supply */
5428c2ecf20Sopenharmony_ci	if (phy_drd->vbus)
5438c2ecf20Sopenharmony_ci		regulator_disable(phy_drd->vbus);
5448c2ecf20Sopenharmony_ci	if (phy_drd->vbus_boost)
5458c2ecf20Sopenharmony_ci		regulator_disable(phy_drd->vbus_boost);
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci	clk_disable_unprepare(phy_drd->ref_clk);
5488c2ecf20Sopenharmony_ci	if (!phy_drd->drv_data->has_common_clk_gate) {
5498c2ecf20Sopenharmony_ci		clk_disable_unprepare(phy_drd->itpclk);
5508c2ecf20Sopenharmony_ci		clk_disable_unprepare(phy_drd->pipeclk);
5518c2ecf20Sopenharmony_ci		clk_disable_unprepare(phy_drd->utmiclk);
5528c2ecf20Sopenharmony_ci	}
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	return 0;
5558c2ecf20Sopenharmony_ci}
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_cistatic int crport_handshake(struct exynos5_usbdrd_phy *phy_drd,
5588c2ecf20Sopenharmony_ci			    u32 val, u32 cmd)
5598c2ecf20Sopenharmony_ci{
5608c2ecf20Sopenharmony_ci	unsigned int result;
5618c2ecf20Sopenharmony_ci	int err;
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	writel(val | cmd, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1,
5668c2ecf20Sopenharmony_ci				 result, (result & PHYREG1_CR_ACK), 1, 100);
5678c2ecf20Sopenharmony_ci	if (err == -ETIMEDOUT) {
5688c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev, "CRPORT handshake timeout1 (0x%08x)\n", val);
5698c2ecf20Sopenharmony_ci		return err;
5708c2ecf20Sopenharmony_ci	}
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	writel(val, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1,
5758c2ecf20Sopenharmony_ci				 result, !(result & PHYREG1_CR_ACK), 1, 100);
5768c2ecf20Sopenharmony_ci	if (err == -ETIMEDOUT) {
5778c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev, "CRPORT handshake timeout2 (0x%08x)\n", val);
5788c2ecf20Sopenharmony_ci		return err;
5798c2ecf20Sopenharmony_ci	}
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	return 0;
5828c2ecf20Sopenharmony_ci}
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_cistatic int crport_ctrl_write(struct exynos5_usbdrd_phy *phy_drd,
5858c2ecf20Sopenharmony_ci			     u32 addr, u32 data)
5868c2ecf20Sopenharmony_ci{
5878c2ecf20Sopenharmony_ci	int ret;
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	/* Write Address */
5908c2ecf20Sopenharmony_ci	writel(PHYREG0_CR_DATA_IN(addr),
5918c2ecf20Sopenharmony_ci	       phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
5928c2ecf20Sopenharmony_ci	ret = crport_handshake(phy_drd, PHYREG0_CR_DATA_IN(addr),
5938c2ecf20Sopenharmony_ci			       PHYREG0_CR_CAP_ADDR);
5948c2ecf20Sopenharmony_ci	if (ret)
5958c2ecf20Sopenharmony_ci		return ret;
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	/* Write Data */
5988c2ecf20Sopenharmony_ci	writel(PHYREG0_CR_DATA_IN(data),
5998c2ecf20Sopenharmony_ci	       phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
6008c2ecf20Sopenharmony_ci	ret = crport_handshake(phy_drd, PHYREG0_CR_DATA_IN(data),
6018c2ecf20Sopenharmony_ci			       PHYREG0_CR_CAP_DATA);
6028c2ecf20Sopenharmony_ci	if (ret)
6038c2ecf20Sopenharmony_ci		return ret;
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci	ret = crport_handshake(phy_drd, PHYREG0_CR_DATA_IN(data),
6068c2ecf20Sopenharmony_ci			       PHYREG0_CR_WRITE);
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci	return ret;
6098c2ecf20Sopenharmony_ci}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci/*
6128c2ecf20Sopenharmony_ci * Calibrate few PHY parameters using CR_PORT register to meet
6138c2ecf20Sopenharmony_ci * SuperSpeed requirements on Exynos5420 and Exynos5800 systems,
6148c2ecf20Sopenharmony_ci * which have 28nm USB 3.0 DRD PHY.
6158c2ecf20Sopenharmony_ci */
6168c2ecf20Sopenharmony_cistatic int exynos5420_usbdrd_phy_calibrate(struct exynos5_usbdrd_phy *phy_drd)
6178c2ecf20Sopenharmony_ci{
6188c2ecf20Sopenharmony_ci	unsigned int temp;
6198c2ecf20Sopenharmony_ci	int ret = 0;
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	/*
6228c2ecf20Sopenharmony_ci	 * Change los_bias to (0x5) for 28nm PHY from a
6238c2ecf20Sopenharmony_ci	 * default value (0x0); los_level is set as default
6248c2ecf20Sopenharmony_ci	 * (0x9) as also reflected in los_level[30:26] bits
6258c2ecf20Sopenharmony_ci	 * of PHYPARAM0 register.
6268c2ecf20Sopenharmony_ci	 */
6278c2ecf20Sopenharmony_ci	temp = LOSLEVEL_OVRD_IN_LOS_BIAS_5420 |
6288c2ecf20Sopenharmony_ci		LOSLEVEL_OVRD_IN_EN |
6298c2ecf20Sopenharmony_ci		LOSLEVEL_OVRD_IN_LOS_LEVEL_DEFAULT;
6308c2ecf20Sopenharmony_ci	ret = crport_ctrl_write(phy_drd,
6318c2ecf20Sopenharmony_ci				EXYNOS5_DRD_PHYSS_LOSLEVEL_OVRD_IN,
6328c2ecf20Sopenharmony_ci				temp);
6338c2ecf20Sopenharmony_ci	if (ret) {
6348c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev,
6358c2ecf20Sopenharmony_ci			"Failed setting Loss-of-Signal level for SuperSpeed\n");
6368c2ecf20Sopenharmony_ci		return ret;
6378c2ecf20Sopenharmony_ci	}
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci	/*
6408c2ecf20Sopenharmony_ci	 * Set tx_vboost_lvl to (0x5) for 28nm PHY Tuning,
6418c2ecf20Sopenharmony_ci	 * to raise Tx signal level from its default value of (0x4)
6428c2ecf20Sopenharmony_ci	 */
6438c2ecf20Sopenharmony_ci	temp = TX_VBOOSTLEVEL_OVRD_IN_VBOOST_5420;
6448c2ecf20Sopenharmony_ci	ret = crport_ctrl_write(phy_drd,
6458c2ecf20Sopenharmony_ci				EXYNOS5_DRD_PHYSS_TX_VBOOSTLEVEL_OVRD_IN,
6468c2ecf20Sopenharmony_ci				temp);
6478c2ecf20Sopenharmony_ci	if (ret) {
6488c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev,
6498c2ecf20Sopenharmony_ci			"Failed setting Tx-Vboost-Level for SuperSpeed\n");
6508c2ecf20Sopenharmony_ci		return ret;
6518c2ecf20Sopenharmony_ci	}
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	/*
6548c2ecf20Sopenharmony_ci	 * Set proper time to wait for RxDetect measurement, for
6558c2ecf20Sopenharmony_ci	 * desired reference clock of PHY, by tuning the CR_PORT
6568c2ecf20Sopenharmony_ci	 * register LANE0.TX_DEBUG which is internal to PHY.
6578c2ecf20Sopenharmony_ci	 * This fixes issue with few USB 3.0 devices, which are
6588c2ecf20Sopenharmony_ci	 * not detected (not even generate interrupts on the bus
6598c2ecf20Sopenharmony_ci	 * on insertion) without this change.
6608c2ecf20Sopenharmony_ci	 * e.g. Samsung SUM-TSB16S 3.0 USB drive.
6618c2ecf20Sopenharmony_ci	 */
6628c2ecf20Sopenharmony_ci	switch (phy_drd->extrefclk) {
6638c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_50MHZ:
6648c2ecf20Sopenharmony_ci		temp = LANE0_TX_DEBUG_RXDET_MEAS_TIME_48M_50M_52M;
6658c2ecf20Sopenharmony_ci		break;
6668c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_20MHZ:
6678c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_19MHZ2:
6688c2ecf20Sopenharmony_ci		temp = LANE0_TX_DEBUG_RXDET_MEAS_TIME_19M2_20M;
6698c2ecf20Sopenharmony_ci		break;
6708c2ecf20Sopenharmony_ci	case EXYNOS5_FSEL_24MHZ:
6718c2ecf20Sopenharmony_ci	default:
6728c2ecf20Sopenharmony_ci		temp = LANE0_TX_DEBUG_RXDET_MEAS_TIME_24M;
6738c2ecf20Sopenharmony_ci		break;
6748c2ecf20Sopenharmony_ci	}
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	ret = crport_ctrl_write(phy_drd,
6778c2ecf20Sopenharmony_ci				EXYNOS5_DRD_PHYSS_LANE0_TX_DEBUG,
6788c2ecf20Sopenharmony_ci				temp);
6798c2ecf20Sopenharmony_ci	if (ret)
6808c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev,
6818c2ecf20Sopenharmony_ci			"Fail to set RxDet measurement time for SuperSpeed\n");
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	return ret;
6848c2ecf20Sopenharmony_ci}
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_cistatic struct phy *exynos5_usbdrd_phy_xlate(struct device *dev,
6878c2ecf20Sopenharmony_ci					struct of_phandle_args *args)
6888c2ecf20Sopenharmony_ci{
6898c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = dev_get_drvdata(dev);
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	if (WARN_ON(args->args[0] >= EXYNOS5_DRDPHYS_NUM))
6928c2ecf20Sopenharmony_ci		return ERR_PTR(-ENODEV);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	return phy_drd->phys[args->args[0]].phy;
6958c2ecf20Sopenharmony_ci}
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_calibrate(struct phy *phy)
6988c2ecf20Sopenharmony_ci{
6998c2ecf20Sopenharmony_ci	struct phy_usb_instance *inst = phy_get_drvdata(phy);
7008c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci	if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI)
7038c2ecf20Sopenharmony_ci		return exynos5420_usbdrd_phy_calibrate(phy_drd);
7048c2ecf20Sopenharmony_ci	return 0;
7058c2ecf20Sopenharmony_ci}
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_cistatic const struct phy_ops exynos5_usbdrd_phy_ops = {
7088c2ecf20Sopenharmony_ci	.init		= exynos5_usbdrd_phy_init,
7098c2ecf20Sopenharmony_ci	.exit		= exynos5_usbdrd_phy_exit,
7108c2ecf20Sopenharmony_ci	.power_on	= exynos5_usbdrd_phy_power_on,
7118c2ecf20Sopenharmony_ci	.power_off	= exynos5_usbdrd_phy_power_off,
7128c2ecf20Sopenharmony_ci	.calibrate	= exynos5_usbdrd_phy_calibrate,
7138c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,
7148c2ecf20Sopenharmony_ci};
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy *phy_drd)
7178c2ecf20Sopenharmony_ci{
7188c2ecf20Sopenharmony_ci	unsigned long ref_rate;
7198c2ecf20Sopenharmony_ci	int ret;
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	phy_drd->clk = devm_clk_get(phy_drd->dev, "phy");
7228c2ecf20Sopenharmony_ci	if (IS_ERR(phy_drd->clk)) {
7238c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev, "Failed to get phy clock\n");
7248c2ecf20Sopenharmony_ci		return PTR_ERR(phy_drd->clk);
7258c2ecf20Sopenharmony_ci	}
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	phy_drd->ref_clk = devm_clk_get(phy_drd->dev, "ref");
7288c2ecf20Sopenharmony_ci	if (IS_ERR(phy_drd->ref_clk)) {
7298c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev, "Failed to get phy reference clock\n");
7308c2ecf20Sopenharmony_ci		return PTR_ERR(phy_drd->ref_clk);
7318c2ecf20Sopenharmony_ci	}
7328c2ecf20Sopenharmony_ci	ref_rate = clk_get_rate(phy_drd->ref_clk);
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	ret = exynos5_rate_to_clk(ref_rate, &phy_drd->extrefclk);
7358c2ecf20Sopenharmony_ci	if (ret) {
7368c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev, "Clock rate (%ld) not supported\n",
7378c2ecf20Sopenharmony_ci			ref_rate);
7388c2ecf20Sopenharmony_ci		return ret;
7398c2ecf20Sopenharmony_ci	}
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	if (!phy_drd->drv_data->has_common_clk_gate) {
7428c2ecf20Sopenharmony_ci		phy_drd->pipeclk = devm_clk_get(phy_drd->dev, "phy_pipe");
7438c2ecf20Sopenharmony_ci		if (IS_ERR(phy_drd->pipeclk)) {
7448c2ecf20Sopenharmony_ci			dev_info(phy_drd->dev,
7458c2ecf20Sopenharmony_ci				 "PIPE3 phy operational clock not specified\n");
7468c2ecf20Sopenharmony_ci			phy_drd->pipeclk = NULL;
7478c2ecf20Sopenharmony_ci		}
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci		phy_drd->utmiclk = devm_clk_get(phy_drd->dev, "phy_utmi");
7508c2ecf20Sopenharmony_ci		if (IS_ERR(phy_drd->utmiclk)) {
7518c2ecf20Sopenharmony_ci			dev_info(phy_drd->dev,
7528c2ecf20Sopenharmony_ci				 "UTMI phy operational clock not specified\n");
7538c2ecf20Sopenharmony_ci			phy_drd->utmiclk = NULL;
7548c2ecf20Sopenharmony_ci		}
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci		phy_drd->itpclk = devm_clk_get(phy_drd->dev, "itp");
7578c2ecf20Sopenharmony_ci		if (IS_ERR(phy_drd->itpclk)) {
7588c2ecf20Sopenharmony_ci			dev_info(phy_drd->dev,
7598c2ecf20Sopenharmony_ci				 "ITP clock from main OSC not specified\n");
7608c2ecf20Sopenharmony_ci			phy_drd->itpclk = NULL;
7618c2ecf20Sopenharmony_ci		}
7628c2ecf20Sopenharmony_ci	}
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci	return 0;
7658c2ecf20Sopenharmony_ci}
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_cistatic const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = {
7688c2ecf20Sopenharmony_ci	{
7698c2ecf20Sopenharmony_ci		.id		= EXYNOS5_DRDPHY_UTMI,
7708c2ecf20Sopenharmony_ci		.phy_isol	= exynos5_usbdrd_phy_isol,
7718c2ecf20Sopenharmony_ci		.phy_init	= exynos5_usbdrd_utmi_init,
7728c2ecf20Sopenharmony_ci		.set_refclk	= exynos5_usbdrd_utmi_set_refclk,
7738c2ecf20Sopenharmony_ci	},
7748c2ecf20Sopenharmony_ci	{
7758c2ecf20Sopenharmony_ci		.id		= EXYNOS5_DRDPHY_PIPE3,
7768c2ecf20Sopenharmony_ci		.phy_isol	= exynos5_usbdrd_phy_isol,
7778c2ecf20Sopenharmony_ci		.phy_init	= exynos5_usbdrd_pipe3_init,
7788c2ecf20Sopenharmony_ci		.set_refclk	= exynos5_usbdrd_pipe3_set_refclk,
7798c2ecf20Sopenharmony_ci	},
7808c2ecf20Sopenharmony_ci};
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_cistatic const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
7838c2ecf20Sopenharmony_ci	.phy_cfg		= phy_cfg_exynos5,
7848c2ecf20Sopenharmony_ci	.pmu_offset_usbdrd0_phy	= EXYNOS5_USBDRD_PHY_CONTROL,
7858c2ecf20Sopenharmony_ci	.pmu_offset_usbdrd1_phy	= EXYNOS5420_USBDRD1_PHY_CONTROL,
7868c2ecf20Sopenharmony_ci	.has_common_clk_gate	= true,
7878c2ecf20Sopenharmony_ci};
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_cistatic const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
7908c2ecf20Sopenharmony_ci	.phy_cfg		= phy_cfg_exynos5,
7918c2ecf20Sopenharmony_ci	.pmu_offset_usbdrd0_phy	= EXYNOS5_USBDRD_PHY_CONTROL,
7928c2ecf20Sopenharmony_ci	.has_common_clk_gate	= true,
7938c2ecf20Sopenharmony_ci};
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_cistatic const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = {
7968c2ecf20Sopenharmony_ci	.phy_cfg		= phy_cfg_exynos5,
7978c2ecf20Sopenharmony_ci	.pmu_offset_usbdrd0_phy	= EXYNOS5_USBDRD_PHY_CONTROL,
7988c2ecf20Sopenharmony_ci	.pmu_offset_usbdrd1_phy	= EXYNOS5433_USBHOST30_PHY_CONTROL,
7998c2ecf20Sopenharmony_ci	.has_common_clk_gate	= false,
8008c2ecf20Sopenharmony_ci};
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_cistatic const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = {
8038c2ecf20Sopenharmony_ci	.phy_cfg		= phy_cfg_exynos5,
8048c2ecf20Sopenharmony_ci	.pmu_offset_usbdrd0_phy	= EXYNOS5_USBDRD_PHY_CONTROL,
8058c2ecf20Sopenharmony_ci	.has_common_clk_gate	= false,
8068c2ecf20Sopenharmony_ci};
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_cistatic const struct of_device_id exynos5_usbdrd_phy_of_match[] = {
8098c2ecf20Sopenharmony_ci	{
8108c2ecf20Sopenharmony_ci		.compatible = "samsung,exynos5250-usbdrd-phy",
8118c2ecf20Sopenharmony_ci		.data = &exynos5250_usbdrd_phy
8128c2ecf20Sopenharmony_ci	}, {
8138c2ecf20Sopenharmony_ci		.compatible = "samsung,exynos5420-usbdrd-phy",
8148c2ecf20Sopenharmony_ci		.data = &exynos5420_usbdrd_phy
8158c2ecf20Sopenharmony_ci	}, {
8168c2ecf20Sopenharmony_ci		.compatible = "samsung,exynos5433-usbdrd-phy",
8178c2ecf20Sopenharmony_ci		.data = &exynos5433_usbdrd_phy
8188c2ecf20Sopenharmony_ci	}, {
8198c2ecf20Sopenharmony_ci		.compatible = "samsung,exynos7-usbdrd-phy",
8208c2ecf20Sopenharmony_ci		.data = &exynos7_usbdrd_phy
8218c2ecf20Sopenharmony_ci	},
8228c2ecf20Sopenharmony_ci	{ },
8238c2ecf20Sopenharmony_ci};
8248c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, exynos5_usbdrd_phy_of_match);
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_cistatic int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
8278c2ecf20Sopenharmony_ci{
8288c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
8298c2ecf20Sopenharmony_ci	struct device_node *node = dev->of_node;
8308c2ecf20Sopenharmony_ci	struct exynos5_usbdrd_phy *phy_drd;
8318c2ecf20Sopenharmony_ci	struct phy_provider *phy_provider;
8328c2ecf20Sopenharmony_ci	struct resource *res;
8338c2ecf20Sopenharmony_ci	const struct exynos5_usbdrd_phy_drvdata *drv_data;
8348c2ecf20Sopenharmony_ci	struct regmap *reg_pmu;
8358c2ecf20Sopenharmony_ci	u32 pmu_offset;
8368c2ecf20Sopenharmony_ci	int i, ret;
8378c2ecf20Sopenharmony_ci	int channel;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	phy_drd = devm_kzalloc(dev, sizeof(*phy_drd), GFP_KERNEL);
8408c2ecf20Sopenharmony_ci	if (!phy_drd)
8418c2ecf20Sopenharmony_ci		return -ENOMEM;
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	dev_set_drvdata(dev, phy_drd);
8448c2ecf20Sopenharmony_ci	phy_drd->dev = dev;
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8478c2ecf20Sopenharmony_ci	phy_drd->reg_phy = devm_ioremap_resource(dev, res);
8488c2ecf20Sopenharmony_ci	if (IS_ERR(phy_drd->reg_phy))
8498c2ecf20Sopenharmony_ci		return PTR_ERR(phy_drd->reg_phy);
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci	drv_data = of_device_get_match_data(dev);
8528c2ecf20Sopenharmony_ci	if (!drv_data)
8538c2ecf20Sopenharmony_ci		return -EINVAL;
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	phy_drd->drv_data = drv_data;
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ci	ret = exynos5_usbdrd_phy_clk_handle(phy_drd);
8588c2ecf20Sopenharmony_ci	if (ret) {
8598c2ecf20Sopenharmony_ci		dev_err(dev, "Failed to initialize clocks\n");
8608c2ecf20Sopenharmony_ci		return ret;
8618c2ecf20Sopenharmony_ci	}
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	reg_pmu = syscon_regmap_lookup_by_phandle(dev->of_node,
8648c2ecf20Sopenharmony_ci						   "samsung,pmu-syscon");
8658c2ecf20Sopenharmony_ci	if (IS_ERR(reg_pmu)) {
8668c2ecf20Sopenharmony_ci		dev_err(dev, "Failed to lookup PMU regmap\n");
8678c2ecf20Sopenharmony_ci		return PTR_ERR(reg_pmu);
8688c2ecf20Sopenharmony_ci	}
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci	/*
8718c2ecf20Sopenharmony_ci	 * Exynos5420 SoC has multiple channels for USB 3.0 PHY, with
8728c2ecf20Sopenharmony_ci	 * each having separate power control registers.
8738c2ecf20Sopenharmony_ci	 * 'channel' facilitates to set such registers.
8748c2ecf20Sopenharmony_ci	 */
8758c2ecf20Sopenharmony_ci	channel = of_alias_get_id(node, "usbdrdphy");
8768c2ecf20Sopenharmony_ci	if (channel < 0)
8778c2ecf20Sopenharmony_ci		dev_dbg(dev, "Not a multi-controller usbdrd phy\n");
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci	switch (channel) {
8808c2ecf20Sopenharmony_ci	case 1:
8818c2ecf20Sopenharmony_ci		pmu_offset = phy_drd->drv_data->pmu_offset_usbdrd1_phy;
8828c2ecf20Sopenharmony_ci		break;
8838c2ecf20Sopenharmony_ci	case 0:
8848c2ecf20Sopenharmony_ci	default:
8858c2ecf20Sopenharmony_ci		pmu_offset = phy_drd->drv_data->pmu_offset_usbdrd0_phy;
8868c2ecf20Sopenharmony_ci		break;
8878c2ecf20Sopenharmony_ci	}
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci	/* Get Vbus regulators */
8908c2ecf20Sopenharmony_ci	phy_drd->vbus = devm_regulator_get(dev, "vbus");
8918c2ecf20Sopenharmony_ci	if (IS_ERR(phy_drd->vbus)) {
8928c2ecf20Sopenharmony_ci		ret = PTR_ERR(phy_drd->vbus);
8938c2ecf20Sopenharmony_ci		if (ret == -EPROBE_DEFER)
8948c2ecf20Sopenharmony_ci			return ret;
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_ci		dev_warn(dev, "Failed to get VBUS supply regulator\n");
8978c2ecf20Sopenharmony_ci		phy_drd->vbus = NULL;
8988c2ecf20Sopenharmony_ci	}
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	phy_drd->vbus_boost = devm_regulator_get(dev, "vbus-boost");
9018c2ecf20Sopenharmony_ci	if (IS_ERR(phy_drd->vbus_boost)) {
9028c2ecf20Sopenharmony_ci		ret = PTR_ERR(phy_drd->vbus_boost);
9038c2ecf20Sopenharmony_ci		if (ret == -EPROBE_DEFER)
9048c2ecf20Sopenharmony_ci			return ret;
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci		dev_warn(dev, "Failed to get VBUS boost supply regulator\n");
9078c2ecf20Sopenharmony_ci		phy_drd->vbus_boost = NULL;
9088c2ecf20Sopenharmony_ci	}
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	dev_vdbg(dev, "Creating usbdrd_phy phy\n");
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci	for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) {
9138c2ecf20Sopenharmony_ci		struct phy *phy = devm_phy_create(dev, NULL,
9148c2ecf20Sopenharmony_ci						  &exynos5_usbdrd_phy_ops);
9158c2ecf20Sopenharmony_ci		if (IS_ERR(phy)) {
9168c2ecf20Sopenharmony_ci			dev_err(dev, "Failed to create usbdrd_phy phy\n");
9178c2ecf20Sopenharmony_ci			return PTR_ERR(phy);
9188c2ecf20Sopenharmony_ci		}
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci		phy_drd->phys[i].phy = phy;
9218c2ecf20Sopenharmony_ci		phy_drd->phys[i].index = i;
9228c2ecf20Sopenharmony_ci		phy_drd->phys[i].reg_pmu = reg_pmu;
9238c2ecf20Sopenharmony_ci		phy_drd->phys[i].pmu_offset = pmu_offset;
9248c2ecf20Sopenharmony_ci		phy_drd->phys[i].phy_cfg = &drv_data->phy_cfg[i];
9258c2ecf20Sopenharmony_ci		phy_set_drvdata(phy, &phy_drd->phys[i]);
9268c2ecf20Sopenharmony_ci	}
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci	phy_provider = devm_of_phy_provider_register(dev,
9298c2ecf20Sopenharmony_ci						     exynos5_usbdrd_phy_xlate);
9308c2ecf20Sopenharmony_ci	if (IS_ERR(phy_provider)) {
9318c2ecf20Sopenharmony_ci		dev_err(phy_drd->dev, "Failed to register phy provider\n");
9328c2ecf20Sopenharmony_ci		return PTR_ERR(phy_provider);
9338c2ecf20Sopenharmony_ci	}
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_ci	return 0;
9368c2ecf20Sopenharmony_ci}
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_cistatic struct platform_driver exynos5_usb3drd_phy = {
9398c2ecf20Sopenharmony_ci	.probe	= exynos5_usbdrd_phy_probe,
9408c2ecf20Sopenharmony_ci	.driver = {
9418c2ecf20Sopenharmony_ci		.of_match_table	= exynos5_usbdrd_phy_of_match,
9428c2ecf20Sopenharmony_ci		.name		= "exynos5_usb3drd_phy",
9438c2ecf20Sopenharmony_ci		.suppress_bind_attrs = true,
9448c2ecf20Sopenharmony_ci	}
9458c2ecf20Sopenharmony_ci};
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_cimodule_platform_driver(exynos5_usb3drd_phy);
9488c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Samsung Exynos5 SoCs USB 3.0 DRD controller PHY driver");
9498c2ecf20Sopenharmony_ciMODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
9508c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
9518c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:exynos5_usb3drd_phy");
952