xref: /openbmc/linux/drivers/phy/qualcomm/phy-qcom-qmp-ufs.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
194a407ccSDmitry Baryshkov // SPDX-License-Identifier: GPL-2.0
294a407ccSDmitry Baryshkov /*
394a407ccSDmitry Baryshkov  * Copyright (c) 2017, The Linux Foundation. All rights reserved.
494a407ccSDmitry Baryshkov  */
594a407ccSDmitry Baryshkov 
694a407ccSDmitry Baryshkov #include <linux/clk.h>
794a407ccSDmitry Baryshkov #include <linux/clk-provider.h>
894a407ccSDmitry Baryshkov #include <linux/delay.h>
994a407ccSDmitry Baryshkov #include <linux/err.h>
1094a407ccSDmitry Baryshkov #include <linux/io.h>
1194a407ccSDmitry Baryshkov #include <linux/iopoll.h>
1294a407ccSDmitry Baryshkov #include <linux/kernel.h>
1394a407ccSDmitry Baryshkov #include <linux/module.h>
1494a407ccSDmitry Baryshkov #include <linux/of.h>
1594a407ccSDmitry Baryshkov #include <linux/of_address.h>
1694a407ccSDmitry Baryshkov #include <linux/phy/phy.h>
1794a407ccSDmitry Baryshkov #include <linux/platform_device.h>
1894a407ccSDmitry Baryshkov #include <linux/regulator/consumer.h>
1994a407ccSDmitry Baryshkov #include <linux/reset.h>
2094a407ccSDmitry Baryshkov #include <linux/slab.h>
2194a407ccSDmitry Baryshkov 
22baf8d17eSManivannan Sadhasivam #include <ufs/unipro.h>
2394a407ccSDmitry Baryshkov #include "phy-qcom-qmp.h"
24eb5793fbSDmitry Baryshkov #include "phy-qcom-qmp-pcs-ufs-v2.h"
25eb5793fbSDmitry Baryshkov #include "phy-qcom-qmp-pcs-ufs-v3.h"
26eb5793fbSDmitry Baryshkov #include "phy-qcom-qmp-pcs-ufs-v4.h"
27eb5793fbSDmitry Baryshkov #include "phy-qcom-qmp-pcs-ufs-v5.h"
285b8154ceSAbel Vesa #include "phy-qcom-qmp-pcs-ufs-v6.h"
2994a407ccSDmitry Baryshkov 
30c9736600SAbel Vesa #include "phy-qcom-qmp-qserdes-txrx-ufs-v6.h"
31c9736600SAbel Vesa 
3294a407ccSDmitry Baryshkov /* QPHY_SW_RESET bit */
3394a407ccSDmitry Baryshkov #define SW_RESET				BIT(0)
3494a407ccSDmitry Baryshkov /* QPHY_POWER_DOWN_CONTROL */
3594a407ccSDmitry Baryshkov #define SW_PWRDN				BIT(0)
3694a407ccSDmitry Baryshkov /* QPHY_START_CONTROL bits */
3794a407ccSDmitry Baryshkov #define SERDES_START				BIT(0)
3894a407ccSDmitry Baryshkov #define PCS_START				BIT(1)
396d07bd6fSJohan Hovold /* QPHY_PCS_READY_STATUS bit */
4094a407ccSDmitry Baryshkov #define PCS_READY				BIT(0)
4194a407ccSDmitry Baryshkov 
4294a407ccSDmitry Baryshkov #define PHY_INIT_COMPLETE_TIMEOUT		10000
4394a407ccSDmitry Baryshkov 
4494a407ccSDmitry Baryshkov struct qmp_phy_init_tbl {
4594a407ccSDmitry Baryshkov 	unsigned int offset;
4694a407ccSDmitry Baryshkov 	unsigned int val;
4794a407ccSDmitry Baryshkov 	/*
4894a407ccSDmitry Baryshkov 	 * mask of lanes for which this register is written
4994a407ccSDmitry Baryshkov 	 * for cases when second lane needs different values
5094a407ccSDmitry Baryshkov 	 */
5194a407ccSDmitry Baryshkov 	u8 lane_mask;
5294a407ccSDmitry Baryshkov };
5394a407ccSDmitry Baryshkov 
5494a407ccSDmitry Baryshkov #define QMP_PHY_INIT_CFG(o, v)		\
5594a407ccSDmitry Baryshkov 	{				\
5694a407ccSDmitry Baryshkov 		.offset = o,		\
5794a407ccSDmitry Baryshkov 		.val = v,		\
5894a407ccSDmitry Baryshkov 		.lane_mask = 0xff,	\
5994a407ccSDmitry Baryshkov 	}
6094a407ccSDmitry Baryshkov 
6194a407ccSDmitry Baryshkov #define QMP_PHY_INIT_CFG_LANE(o, v, l)	\
6294a407ccSDmitry Baryshkov 	{				\
6394a407ccSDmitry Baryshkov 		.offset = o,		\
6494a407ccSDmitry Baryshkov 		.val = v,		\
6594a407ccSDmitry Baryshkov 		.lane_mask = l,		\
6694a407ccSDmitry Baryshkov 	}
6794a407ccSDmitry Baryshkov 
6894a407ccSDmitry Baryshkov /* set of registers with offsets different per-PHY */
6994a407ccSDmitry Baryshkov enum qphy_reg_layout {
7094a407ccSDmitry Baryshkov 	/* PCS registers */
7194a407ccSDmitry Baryshkov 	QPHY_SW_RESET,
7294a407ccSDmitry Baryshkov 	QPHY_START_CTRL,
7394a407ccSDmitry Baryshkov 	QPHY_PCS_READY_STATUS,
7494a407ccSDmitry Baryshkov 	QPHY_PCS_POWER_DOWN_CONTROL,
7594a407ccSDmitry Baryshkov 	/* Keep last to ensure regs_layout arrays are properly initialized */
7694a407ccSDmitry Baryshkov 	QPHY_LAYOUT_SIZE
7794a407ccSDmitry Baryshkov };
7894a407ccSDmitry Baryshkov 
795db22640SDmitry Baryshkov static const unsigned int ufsphy_v2_regs_layout[QPHY_LAYOUT_SIZE] = {
803b4bf465SDmitry Baryshkov 	[QPHY_START_CTRL]		= QPHY_V2_PCS_UFS_PHY_START,
813b4bf465SDmitry Baryshkov 	[QPHY_PCS_READY_STATUS]		= QPHY_V2_PCS_UFS_READY_STATUS,
823b4bf465SDmitry Baryshkov 	[QPHY_PCS_POWER_DOWN_CONTROL]	= QPHY_V2_PCS_UFS_POWER_DOWN_CONTROL,
8394a407ccSDmitry Baryshkov };
8494a407ccSDmitry Baryshkov 
855db22640SDmitry Baryshkov static const unsigned int ufsphy_v3_regs_layout[QPHY_LAYOUT_SIZE] = {
863b4bf465SDmitry Baryshkov 	[QPHY_START_CTRL]		= QPHY_V3_PCS_UFS_PHY_START,
873b4bf465SDmitry Baryshkov 	[QPHY_PCS_READY_STATUS]		= QPHY_V3_PCS_UFS_READY_STATUS,
883b4bf465SDmitry Baryshkov 	[QPHY_PCS_POWER_DOWN_CONTROL]	= QPHY_V3_PCS_UFS_POWER_DOWN_CONTROL,
8994a407ccSDmitry Baryshkov };
9094a407ccSDmitry Baryshkov 
915db22640SDmitry Baryshkov static const unsigned int ufsphy_v4_regs_layout[QPHY_LAYOUT_SIZE] = {
9294a407ccSDmitry Baryshkov 	[QPHY_START_CTRL]		= QPHY_V4_PCS_UFS_PHY_START,
9394a407ccSDmitry Baryshkov 	[QPHY_PCS_READY_STATUS]		= QPHY_V4_PCS_UFS_READY_STATUS,
9494a407ccSDmitry Baryshkov 	[QPHY_SW_RESET]			= QPHY_V4_PCS_UFS_SW_RESET,
952d3068cfSJohan Hovold 	[QPHY_PCS_POWER_DOWN_CONTROL]	= QPHY_V4_PCS_UFS_POWER_DOWN_CONTROL,
9694a407ccSDmitry Baryshkov };
9794a407ccSDmitry Baryshkov 
985db22640SDmitry Baryshkov static const unsigned int ufsphy_v5_regs_layout[QPHY_LAYOUT_SIZE] = {
995db22640SDmitry Baryshkov 	[QPHY_START_CTRL]		= QPHY_V5_PCS_UFS_PHY_START,
1005db22640SDmitry Baryshkov 	[QPHY_PCS_READY_STATUS]		= QPHY_V5_PCS_UFS_READY_STATUS,
1015db22640SDmitry Baryshkov 	[QPHY_SW_RESET]			= QPHY_V5_PCS_UFS_SW_RESET,
1025db22640SDmitry Baryshkov 	[QPHY_PCS_POWER_DOWN_CONTROL]	= QPHY_V5_PCS_UFS_POWER_DOWN_CONTROL,
1035db22640SDmitry Baryshkov };
1045db22640SDmitry Baryshkov 
1051679bfefSAbel Vesa static const unsigned int ufsphy_v6_regs_layout[QPHY_LAYOUT_SIZE] = {
1061679bfefSAbel Vesa 	[QPHY_START_CTRL]		= QPHY_V6_PCS_UFS_PHY_START,
1071679bfefSAbel Vesa 	[QPHY_PCS_READY_STATUS]		= QPHY_V6_PCS_UFS_READY_STATUS,
1081679bfefSAbel Vesa 	[QPHY_SW_RESET]			= QPHY_V6_PCS_UFS_SW_RESET,
1091679bfefSAbel Vesa 	[QPHY_PCS_POWER_DOWN_CONTROL]	= QPHY_V6_PCS_UFS_POWER_DOWN_CONTROL,
1101679bfefSAbel Vesa };
1111679bfefSAbel Vesa 
112fcfcae3bSManivannan Sadhasivam static const struct qmp_phy_init_tbl msm8996_ufsphy_serdes[] = {
11394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x0e),
11494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0xd7),
11594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
11694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x06),
11794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
11894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
11994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x05),
12094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
12194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV_MODE1, 0x0a),
12294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x01),
12394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x10),
12494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
12594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
12694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
12794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
12894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
12994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x54),
13094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x05),
13194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
13294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x00),
13394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x00),
13494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x00),
13594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
13694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
13794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
13894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
13994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
14094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE0, 0x28),
14194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE0, 0x02),
14294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xff),
14394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x0c),
14494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
14594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE1, 0x98),
14694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE1, 0x00),
14794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE1, 0x00),
14894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE1, 0x00),
14994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE1, 0x0b),
15094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE1, 0x16),
15194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE1, 0x28),
15294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE1, 0x80),
15394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
15494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE1, 0xd6),
15594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE1, 0x00),
15694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE1, 0x32),
15794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE1, 0x0f),
15894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE1, 0x00),
15994a407ccSDmitry Baryshkov };
16094a407ccSDmitry Baryshkov 
161fcfcae3bSManivannan Sadhasivam static const struct qmp_phy_init_tbl msm8996_ufsphy_tx[] = {
16294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
16394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x02),
16494a407ccSDmitry Baryshkov };
16594a407ccSDmitry Baryshkov 
166fcfcae3bSManivannan Sadhasivam static const struct qmp_phy_init_tbl msm8996_ufsphy_rx[] = {
16794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x24),
16894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x02),
16994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_INTERFACE_MODE, 0x00),
17094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x18),
17194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0B),
17294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_TERM_BW, 0x5b),
17394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_LSB, 0xff),
17494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_MSB, 0x3f),
17594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_LSB, 0xff),
17694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_MSB, 0x0f),
17794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0E),
17894a407ccSDmitry Baryshkov };
17994a407ccSDmitry Baryshkov 
180342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm6115_ufsphy_serdes[] = {
18194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x0e),
18294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14),
18394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
18494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x02),
18594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
18694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
18794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
18894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
18994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV_MODE1, 0x0a),
19094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x01),
19194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x00),
19294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
19394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
19494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
19594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
19694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
19794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x04),
19894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x05),
19994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
20094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x00),
20194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x00),
20294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x00),
20394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
20494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
20594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
20694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
20794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
20894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE0, 0x28),
20994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE0, 0x02),
21094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xff),
21194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x0c),
21294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
21394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE1, 0x98),
21494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE1, 0x00),
21594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE1, 0x00),
21694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE1, 0x00),
21794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE1, 0x0b),
21894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE1, 0x16),
21994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE1, 0x28),
22094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE1, 0x80),
22194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
22294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE1, 0xd6),
22394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE1, 0x00),
22494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE1, 0x32),
22594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE1, 0x0f),
22694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE1, 0x00),
22794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
22894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
22994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_INITVAL1, 0xff),
23094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_INITVAL2, 0x00),
2310cf7620eSManivannan Sadhasivam };
23294a407ccSDmitry Baryshkov 
2330cf7620eSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm6115_ufsphy_hs_b_serdes[] = {
23494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x44),
23594a407ccSDmitry Baryshkov };
23694a407ccSDmitry Baryshkov 
237342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm6115_ufsphy_tx[] = {
23894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
23994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
24094a407ccSDmitry Baryshkov };
24194a407ccSDmitry Baryshkov 
242342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm6115_ufsphy_rx[] = {
24394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x24),
24494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x0F),
24594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_INTERFACE_MODE, 0x40),
24694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x1E),
24794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0B),
24894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_TERM_BW, 0x5B),
24994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_LSB, 0xFF),
25094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_MSB, 0x3F),
25194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_LSB, 0xFF),
25294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_MSB, 0x3F),
25394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0D),
25494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
25594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
25694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN, 0x04),
25794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5B),
25894a407ccSDmitry Baryshkov };
25994a407ccSDmitry Baryshkov 
260342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm6115_ufsphy_pcs[] = {
261cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_PWM_GEAR_BAND, 0x15),
262cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
263cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
264cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
265cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_MIN_STALL_NOCONFIG_TIME_CAP, 0x28),
266cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
267cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_LARGE_AMP_POST_EMP_LVL, 0x12),
268cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_SMALL_AMP_POST_EMP_LVL, 0x0f),
269cbd06cdeSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_MIN_HIBERN8_TIME, 0x9a), /* 8 us */
27094a407ccSDmitry Baryshkov };
27194a407ccSDmitry Baryshkov 
272342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sdm845_ufsphy_serdes[] = {
27394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
27494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x04),
27594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_BG_TIMER, 0x0a),
27694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
27794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06),
27894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0xd5),
27994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL, 0x20),
28094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
28194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x00),
28294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x01),
28394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_CTRL, 0x00),
28494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
28594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x04),
28694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x05),
28794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_INITVAL1, 0xff),
28894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_INITVAL2, 0x00),
28994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
29094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
29194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
29294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
29394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
29494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
29594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xda),
29694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
29794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0xff),
29894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x0c),
29994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE1, 0x98),
30094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE1, 0x06),
30194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE1, 0x16),
30294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE1, 0x36),
30394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE1, 0x3f),
30494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
30594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE1, 0xc1),
30694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE1, 0x00),
30794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE1, 0x32),
30894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE1, 0x0f),
3090cf7620eSManivannan Sadhasivam };
31094a407ccSDmitry Baryshkov 
3110cf7620eSManivannan Sadhasivam static const struct qmp_phy_init_tbl sdm845_ufsphy_hs_b_serdes[] = {
31294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x44),
31394a407ccSDmitry Baryshkov };
31494a407ccSDmitry Baryshkov 
315342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sdm845_ufsphy_tx[] = {
31694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x06),
31794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x04),
31894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x07),
31994a407ccSDmitry Baryshkov };
32094a407ccSDmitry Baryshkov 
321342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sdm845_ufsphy_rx[] = {
32294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_LVL, 0x24),
32394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x0f),
32494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
32594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40),
32694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
32794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_TERM_BW, 0x5b),
32894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
32994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
33094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1b),
33194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
33294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
33394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN, 0x04),
33494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
33594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x81),
33694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
33794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x59),
33894a407ccSDmitry Baryshkov };
33994a407ccSDmitry Baryshkov 
340342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sdm845_ufsphy_pcs[] = {
341fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL2, 0x6e),
342fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
343fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
344fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
345fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
346fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL1, 0x0f),
347fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_MIN_HIBERN8_TIME, 0x9a),
348fc270d13SDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
34994a407ccSDmitry Baryshkov };
35094a407ccSDmitry Baryshkov 
351868c2a6cSDavid Wronek static const struct qmp_phy_init_tbl sm7150_ufsphy_rx[] = {
352868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_LVL, 0x24),
353868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x0f),
354868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
355868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40),
356868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
357868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_TERM_BW, 0x5b),
358868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
359868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
360868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1b),
361868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
362868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
363868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN, 0x04),
364868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5b),
365868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x81),
366868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
367868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x59),
368868c2a6cSDavid Wronek };
369868c2a6cSDavid Wronek 
370868c2a6cSDavid Wronek static const struct qmp_phy_init_tbl sm7150_ufsphy_pcs[] = {
371868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL2, 0x6f),
372868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
373868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
374868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
375868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
376868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL1, 0x0f),
377868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
378868c2a6cSDavid Wronek 	QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
379868c2a6cSDavid Wronek };
380868c2a6cSDavid Wronek 
381342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_serdes[] = {
38294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0xd9),
38394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x11),
38494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_HS_SWITCH_SEL, 0x00),
38594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x01),
38694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
38794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_IVCO, 0x0f),
38894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_INITVAL2, 0x00),
38994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
39094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x82),
39194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
39294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
39394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
39494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0xff),
39594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x0c),
39694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xac),
39794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
39894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE1, 0x98),
39994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
40094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
40194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
40294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE1, 0x32),
40394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE1, 0x0f),
40494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xdd),
40594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x23),
4060cf7620eSManivannan Sadhasivam };
40794a407ccSDmitry Baryshkov 
4080cf7620eSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_b_serdes[] = {
40994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x06),
41094a407ccSDmitry Baryshkov };
41194a407ccSDmitry Baryshkov 
412342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_tx[] = {
41394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
41494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
41594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
41694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
41794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x05),
41894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_TRAN_DRVR_EMP_EN, 0x0c),
41994a407ccSDmitry Baryshkov };
42094a407ccSDmitry Baryshkov 
421f89dcb24SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_tx[] = {
422f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x75),
423f89dcb24SManivannan Sadhasivam };
424f89dcb24SManivannan Sadhasivam 
425342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_rx[] = {
42694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
42794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
42894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
42994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
43094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
43194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
43294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
43394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
43494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x80),
43594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0c),
43694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
43794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x1b),
43894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
43994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
44094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1d),
44194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
44294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x10),
44394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
44494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
44594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x36),
44694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x36),
44794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xf6),
44894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x3b),
44994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x3d),
45094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xe0),
45194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xc8),
45294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xc8),
45394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
45494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb1),
45594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
45694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
45794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
45894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
45994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
46094a407ccSDmitry Baryshkov };
46194a407ccSDmitry Baryshkov 
462f89dcb24SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_rx[] = {
463f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
464f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
465f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
466f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
467f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
468f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
469f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
470f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
471f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
472f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
473f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
474f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x6c),
475f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
476f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
477f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
478f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
479f89dcb24SManivannan Sadhasivam };
480f89dcb24SManivannan Sadhasivam 
481342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_pcs[] = {
48294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
48394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
48494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
48594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
48694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
48794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
48894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
48994a407ccSDmitry Baryshkov };
49094a407ccSDmitry Baryshkov 
491f89dcb24SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_pcs[] = {
492f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x10),
493f89dcb24SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_BIST_FIXED_PAT_CTRL, 0x0a),
494f89dcb24SManivannan Sadhasivam };
495f89dcb24SManivannan Sadhasivam 
496692b6551SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8250_ufsphy_hs_g4_tx[] = {
497692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xe5),
498692b6551SManivannan Sadhasivam };
499692b6551SManivannan Sadhasivam 
500692b6551SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8250_ufsphy_hs_g4_rx[] = {
501692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
502692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
503692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
504692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
505692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
506692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
507692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x09),
508692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x07),
509692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
510692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
511692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
512692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
513692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
514692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
515692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
516692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
517692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x2c),
518692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
519692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
520692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
521692b6551SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
522692b6551SManivannan Sadhasivam };
523692b6551SManivannan Sadhasivam 
524342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_serdes[] = {
52594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_SYSCLK_EN_SEL, 0xd9),
52694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_SEL, 0x11),
52794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_HS_SWITCH_SEL, 0x00),
52894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP_EN, 0x42),
52994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x02),
53094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_IVCO, 0x0f),
53194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_INITVAL2, 0x00),
53294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
53394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE0, 0x82),
53494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE0, 0x14),
53594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE0, 0x18),
53694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE0, 0x18),
53794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE0, 0xff),
53894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE0, 0x19),
53994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xac),
54094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
54194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE1, 0x98),
54294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE1, 0x14),
54394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE1, 0x18),
54494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE1, 0x18),
54594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE1, 0x65),
54694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE1, 0x1e),
54794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xdd),
54894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x23),
5490cf7620eSManivannan Sadhasivam };
55094a407ccSDmitry Baryshkov 
5510cf7620eSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_hs_b_serdes[] = {
55294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x06),
55394a407ccSDmitry Baryshkov };
55494a407ccSDmitry Baryshkov 
555342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_tx[] = {
55694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
55794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
55894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
55994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
56094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0xf5),
56194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_3, 0x3f),
56294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_TX, 0x09),
56394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
56494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_TRAN_DRVR_EMP_EN, 0x0c),
56594a407ccSDmitry Baryshkov };
56694a407ccSDmitry Baryshkov 
567342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_rx[] = {
56894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_LVL, 0x24),
56994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_CNTRL, 0x0f),
57094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
57194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_BAND, 0x18),
57294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
57394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
57494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CONTROLS, 0xf1),
57594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
57694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CTRL2, 0x80),
57794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FO_GAIN, 0x0e),
57894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_GAIN, 0x04),
57994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_TERM_BW, 0x1b),
58094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
58194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
58294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
58394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1a),
58494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
58594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
58694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_MEASURE_TIME, 0x10),
58794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
58894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
58994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0x6d),
59094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0x6d),
59194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0xed),
59294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x3b),
59394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0x3c),
59494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0xe0),
59594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0xc8),
59694a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xc8),
59794a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH3, 0x3b),
59894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0xb7),
59994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_LOW, 0xe0),
60094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH, 0xc8),
60194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH2, 0xc8),
60294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH3, 0x3b),
60394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH4, 0xb7),
60494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_DCC_CTRL1, 0x0c),
60594a407ccSDmitry Baryshkov };
60694a407ccSDmitry Baryshkov 
607342ab21dSManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_pcs[] = {
60894a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
60994a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
61094a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
61194a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
61294a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
61394a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
61494a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_SIGDET_CTRL1, 0x0e),
61594a407ccSDmitry Baryshkov 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
61694a407ccSDmitry Baryshkov };
61794a407ccSDmitry Baryshkov 
61890c64cc0SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_tx[] = {
61990c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0xe5),
62090c64cc0SManivannan Sadhasivam };
62190c64cc0SManivannan Sadhasivam 
62290c64cc0SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_rx[] = {
62390c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CTRL2, 0x81),
62490c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_TERM_BW, 0x6f),
62590c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
62690c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
62790c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
62890c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_MEASURE_TIME, 0x20),
62990c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0x80),
63090c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
63190c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0xbf),
63290c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0xbf),
63390c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0x7f),
63490c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x7f),
63590c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0x2d),
63690c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0x6d),
63790c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0x6d),
63890c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xed),
63990c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0x3c),
64090c64cc0SManivannan Sadhasivam };
64190c64cc0SManivannan Sadhasivam 
64290c64cc0SManivannan Sadhasivam static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_pcs[] = {
64390c64cc0SManivannan Sadhasivam 	QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_BIST_FIXED_PAT_CTRL, 0x0a),
64490c64cc0SManivannan Sadhasivam };
64590c64cc0SManivannan Sadhasivam 
6461679bfefSAbel Vesa static const struct qmp_phy_init_tbl sm8550_ufsphy_serdes[] = {
6471679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_SYSCLK_EN_SEL, 0xd9),
6481679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_CONFIG_1, 0x16),
6491679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_SEL_1, 0x11),
6501679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_HS_SWITCH_SEL_1, 0x00),
6511679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP_EN, 0x01),
6521679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_MAP, 0x04),
6531679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO, 0x0f),
6541679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_INITVAL2, 0x00),
6551679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x41),
6561679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x0a),
6571679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
6581679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x14),
6591679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0x7f),
6601679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x06),
6611679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x4c),
6621679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x0a),
6631679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
6641679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x14),
6651679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0x99),
6661679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x07),
6671679bfefSAbel Vesa };
6681679bfefSAbel Vesa 
6691679bfefSAbel Vesa static const struct qmp_phy_init_tbl sm8550_ufsphy_tx[] = {
6701679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_V6_TX_LANE_MODE_1, 0x05),
6711679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_RES_CODE_LANE_OFFSET_TX, 0x07),
6721679bfefSAbel Vesa };
6731679bfefSAbel Vesa 
6741679bfefSAbel Vesa static const struct qmp_phy_init_tbl sm8550_ufsphy_rx[] = {
6751679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_FO_GAIN_RATE2, 0x0c),
6761679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_FO_GAIN_RATE4, 0x0f),
6771679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_VGA_CAL_MAN_VAL, 0x0e),
6781679bfefSAbel Vesa 
6791679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B0, 0xc2),
6801679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B1, 0xc2),
6811679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B3, 0x1a),
6821679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B6, 0x60),
6831679bfefSAbel Vesa 
6841679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B3, 0x9e),
6851679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B6, 0x60),
6861679bfefSAbel Vesa 
6871679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B3, 0x9e),
6881679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B4, 0x0e),
6891679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B5, 0x36),
6901679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B8, 0x02),
6911679bfefSAbel Vesa };
6921679bfefSAbel Vesa 
6931679bfefSAbel Vesa static const struct qmp_phy_init_tbl sm8550_ufsphy_pcs[] = {
6941679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_SIGDET_CTRL2, 0x69),
6951679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
6961679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
6971679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x2b),
6981679bfefSAbel Vesa 	QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
6991679bfefSAbel Vesa };
7001679bfefSAbel Vesa 
7010e089bb8SJohan Hovold struct qmp_ufs_offsets {
7020e089bb8SJohan Hovold 	u16 serdes;
7030e089bb8SJohan Hovold 	u16 pcs;
7040e089bb8SJohan Hovold 	u16 tx;
7050e089bb8SJohan Hovold 	u16 rx;
7060e089bb8SJohan Hovold 	u16 tx2;
7070e089bb8SJohan Hovold 	u16 rx2;
7080e089bb8SJohan Hovold };
7090e089bb8SJohan Hovold 
710c9a7b0ddSManivannan Sadhasivam struct qmp_phy_cfg_tbls {
711c9a7b0ddSManivannan Sadhasivam 	/* Init sequence for PHY blocks - serdes, tx, rx, pcs */
712c9a7b0ddSManivannan Sadhasivam 	const struct qmp_phy_init_tbl *serdes;
713c9a7b0ddSManivannan Sadhasivam 	int serdes_num;
714c9a7b0ddSManivannan Sadhasivam 	const struct qmp_phy_init_tbl *tx;
715c9a7b0ddSManivannan Sadhasivam 	int tx_num;
716c9a7b0ddSManivannan Sadhasivam 	const struct qmp_phy_init_tbl *rx;
717c9a7b0ddSManivannan Sadhasivam 	int rx_num;
718c9a7b0ddSManivannan Sadhasivam 	const struct qmp_phy_init_tbl *pcs;
719c9a7b0ddSManivannan Sadhasivam 	int pcs_num;
720c9a7b0ddSManivannan Sadhasivam };
721c9a7b0ddSManivannan Sadhasivam 
72294a407ccSDmitry Baryshkov /* struct qmp_phy_cfg - per-PHY initialization config */
72394a407ccSDmitry Baryshkov struct qmp_phy_cfg {
72407d386bfSJohan Hovold 	int lanes;
72594a407ccSDmitry Baryshkov 
7260e089bb8SJohan Hovold 	const struct qmp_ufs_offsets *offsets;
7270e089bb8SJohan Hovold 
728c9a7b0ddSManivannan Sadhasivam 	/* Main init sequence for PHY blocks - serdes, tx, rx, pcs */
729c9a7b0ddSManivannan Sadhasivam 	const struct qmp_phy_cfg_tbls tbls;
73069d2f980SManivannan Sadhasivam 	/* Additional sequence for HS Series B */
73169d2f980SManivannan Sadhasivam 	const struct qmp_phy_cfg_tbls tbls_hs_b;
732baf8d17eSManivannan Sadhasivam 	/* Additional sequence for HS G4 */
733baf8d17eSManivannan Sadhasivam 	const struct qmp_phy_cfg_tbls tbls_hs_g4;
73494a407ccSDmitry Baryshkov 
73594a407ccSDmitry Baryshkov 	/* clock ids to be requested */
73694a407ccSDmitry Baryshkov 	const char * const *clk_list;
73794a407ccSDmitry Baryshkov 	int num_clks;
73894a407ccSDmitry Baryshkov 	/* regulators to be requested */
73994a407ccSDmitry Baryshkov 	const char * const *vreg_list;
74094a407ccSDmitry Baryshkov 	int num_vregs;
74194a407ccSDmitry Baryshkov 
74294a407ccSDmitry Baryshkov 	/* array of registers with different offsets */
74394a407ccSDmitry Baryshkov 	const unsigned int *regs;
74494a407ccSDmitry Baryshkov 
74594a407ccSDmitry Baryshkov 	/* true, if PCS block has no separate SW_RESET register */
74694a407ccSDmitry Baryshkov 	bool no_pcs_sw_reset;
74794a407ccSDmitry Baryshkov };
74894a407ccSDmitry Baryshkov 
749a36032dbSJohan Hovold struct qmp_ufs {
750a36032dbSJohan Hovold 	struct device *dev;
751a36032dbSJohan Hovold 
75294a407ccSDmitry Baryshkov 	const struct qmp_phy_cfg *cfg;
753a36032dbSJohan Hovold 
75494a407ccSDmitry Baryshkov 	void __iomem *serdes;
755a36032dbSJohan Hovold 	void __iomem *pcs;
756a36032dbSJohan Hovold 	void __iomem *pcs_misc;
75794a407ccSDmitry Baryshkov 	void __iomem *tx;
75894a407ccSDmitry Baryshkov 	void __iomem *rx;
75994a407ccSDmitry Baryshkov 	void __iomem *tx2;
76094a407ccSDmitry Baryshkov 	void __iomem *rx2;
76194a407ccSDmitry Baryshkov 
76294a407ccSDmitry Baryshkov 	struct clk_bulk_data *clks;
76394a407ccSDmitry Baryshkov 	struct regulator_bulk_data *vregs;
76494a407ccSDmitry Baryshkov 	struct reset_control *ufs_reset;
765a36032dbSJohan Hovold 
766a36032dbSJohan Hovold 	struct phy *phy;
76769d2f980SManivannan Sadhasivam 	u32 mode;
768baf8d17eSManivannan Sadhasivam 	u32 submode;
76994a407ccSDmitry Baryshkov };
77094a407ccSDmitry Baryshkov 
qphy_setbits(void __iomem * base,u32 offset,u32 val)77194a407ccSDmitry Baryshkov static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
77294a407ccSDmitry Baryshkov {
77394a407ccSDmitry Baryshkov 	u32 reg;
77494a407ccSDmitry Baryshkov 
77594a407ccSDmitry Baryshkov 	reg = readl(base + offset);
77694a407ccSDmitry Baryshkov 	reg |= val;
77794a407ccSDmitry Baryshkov 	writel(reg, base + offset);
77894a407ccSDmitry Baryshkov 
77994a407ccSDmitry Baryshkov 	/* ensure that above write is through */
78094a407ccSDmitry Baryshkov 	readl(base + offset);
78194a407ccSDmitry Baryshkov }
78294a407ccSDmitry Baryshkov 
qphy_clrbits(void __iomem * base,u32 offset,u32 val)78394a407ccSDmitry Baryshkov static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
78494a407ccSDmitry Baryshkov {
78594a407ccSDmitry Baryshkov 	u32 reg;
78694a407ccSDmitry Baryshkov 
78794a407ccSDmitry Baryshkov 	reg = readl(base + offset);
78894a407ccSDmitry Baryshkov 	reg &= ~val;
78994a407ccSDmitry Baryshkov 	writel(reg, base + offset);
79094a407ccSDmitry Baryshkov 
79194a407ccSDmitry Baryshkov 	/* ensure that above write is through */
79294a407ccSDmitry Baryshkov 	readl(base + offset);
79394a407ccSDmitry Baryshkov }
79494a407ccSDmitry Baryshkov 
79594a407ccSDmitry Baryshkov /* list of clocks required by phy */
79694a407ccSDmitry Baryshkov static const char * const msm8996_ufs_phy_clk_l[] = {
79794a407ccSDmitry Baryshkov 	"ref",
79894a407ccSDmitry Baryshkov };
79994a407ccSDmitry Baryshkov 
80094a407ccSDmitry Baryshkov /* the primary usb3 phy on sm8250 doesn't have a ref clock */
80194a407ccSDmitry Baryshkov static const char * const sm8450_ufs_phy_clk_l[] = {
80294a407ccSDmitry Baryshkov 	"qref", "ref", "ref_aux",
80394a407ccSDmitry Baryshkov };
80494a407ccSDmitry Baryshkov 
80594a407ccSDmitry Baryshkov static const char * const sdm845_ufs_phy_clk_l[] = {
80694a407ccSDmitry Baryshkov 	"ref", "ref_aux",
80794a407ccSDmitry Baryshkov };
80894a407ccSDmitry Baryshkov 
80994a407ccSDmitry Baryshkov /* list of regulators */
81094a407ccSDmitry Baryshkov static const char * const qmp_phy_vreg_l[] = {
81194a407ccSDmitry Baryshkov 	"vdda-phy", "vdda-pll",
81294a407ccSDmitry Baryshkov };
81394a407ccSDmitry Baryshkov 
8146900fdf4SDmitry Baryshkov static const struct qmp_ufs_offsets qmp_ufs_offsets = {
8150e089bb8SJohan Hovold 	.serdes		= 0,
8160e089bb8SJohan Hovold 	.pcs		= 0xc00,
8170e089bb8SJohan Hovold 	.tx		= 0x400,
8180e089bb8SJohan Hovold 	.rx		= 0x600,
8190e089bb8SJohan Hovold 	.tx2		= 0x800,
8200e089bb8SJohan Hovold 	.rx2		= 0xa00,
8210e089bb8SJohan Hovold };
8220e089bb8SJohan Hovold 
8231679bfefSAbel Vesa static const struct qmp_ufs_offsets qmp_ufs_offsets_v6 = {
8241679bfefSAbel Vesa 	.serdes		= 0,
8251679bfefSAbel Vesa 	.pcs		= 0x0400,
8261679bfefSAbel Vesa 	.tx		= 0x1000,
8271679bfefSAbel Vesa 	.rx		= 0x1200,
8281679bfefSAbel Vesa 	.tx2		= 0x1800,
8291679bfefSAbel Vesa 	.rx2		= 0x1a00,
8301679bfefSAbel Vesa };
8311679bfefSAbel Vesa 
832fcfcae3bSManivannan Sadhasivam static const struct qmp_phy_cfg msm8996_ufsphy_cfg = {
83307d386bfSJohan Hovold 	.lanes			= 1,
83494a407ccSDmitry Baryshkov 
83520b5c6aeSDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
83620b5c6aeSDmitry Baryshkov 
837c9a7b0ddSManivannan Sadhasivam 	.tbls = {
838c9a7b0ddSManivannan Sadhasivam 		.serdes		= msm8996_ufsphy_serdes,
839c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(msm8996_ufsphy_serdes),
840c9a7b0ddSManivannan Sadhasivam 		.tx		= msm8996_ufsphy_tx,
841c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(msm8996_ufsphy_tx),
842c9a7b0ddSManivannan Sadhasivam 		.rx		= msm8996_ufsphy_rx,
843c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(msm8996_ufsphy_rx),
844c9a7b0ddSManivannan Sadhasivam 	},
84594a407ccSDmitry Baryshkov 
84694a407ccSDmitry Baryshkov 	.clk_list		= msm8996_ufs_phy_clk_l,
84794a407ccSDmitry Baryshkov 	.num_clks		= ARRAY_SIZE(msm8996_ufs_phy_clk_l),
84894a407ccSDmitry Baryshkov 
84994a407ccSDmitry Baryshkov 	.vreg_list		= qmp_phy_vreg_l,
85094a407ccSDmitry Baryshkov 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
85194a407ccSDmitry Baryshkov 
8525db22640SDmitry Baryshkov 	.regs			= ufsphy_v2_regs_layout,
85394a407ccSDmitry Baryshkov 
85494a407ccSDmitry Baryshkov 	.no_pcs_sw_reset	= true,
85594a407ccSDmitry Baryshkov };
85694a407ccSDmitry Baryshkov 
857607c101fSBartosz Golaszewski static const struct qmp_phy_cfg sa8775p_ufsphy_cfg = {
858607c101fSBartosz Golaszewski 	.lanes			= 2,
859607c101fSBartosz Golaszewski 
860607c101fSBartosz Golaszewski 	.offsets		= &qmp_ufs_offsets,
861607c101fSBartosz Golaszewski 
862607c101fSBartosz Golaszewski 	.tbls = {
863607c101fSBartosz Golaszewski 		.serdes		= sm8350_ufsphy_serdes,
864607c101fSBartosz Golaszewski 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_serdes),
865607c101fSBartosz Golaszewski 		.tx		= sm8350_ufsphy_tx,
866607c101fSBartosz Golaszewski 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_tx),
867607c101fSBartosz Golaszewski 		.rx		= sm8350_ufsphy_rx,
868607c101fSBartosz Golaszewski 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_rx),
869607c101fSBartosz Golaszewski 		.pcs		= sm8350_ufsphy_pcs,
870607c101fSBartosz Golaszewski 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_pcs),
871607c101fSBartosz Golaszewski 	},
872607c101fSBartosz Golaszewski 	.tbls_hs_b = {
873607c101fSBartosz Golaszewski 		.serdes		= sm8350_ufsphy_hs_b_serdes,
874607c101fSBartosz Golaszewski 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
875607c101fSBartosz Golaszewski 	},
876607c101fSBartosz Golaszewski 	.tbls_hs_g4 = {
877607c101fSBartosz Golaszewski 		.tx		= sm8350_ufsphy_g4_tx,
878607c101fSBartosz Golaszewski 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_tx),
879607c101fSBartosz Golaszewski 		.rx		= sm8350_ufsphy_g4_rx,
880607c101fSBartosz Golaszewski 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_rx),
881607c101fSBartosz Golaszewski 		.pcs		= sm8350_ufsphy_g4_pcs,
882607c101fSBartosz Golaszewski 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
883607c101fSBartosz Golaszewski 	},
884607c101fSBartosz Golaszewski 	.clk_list		= sm8450_ufs_phy_clk_l,
885607c101fSBartosz Golaszewski 	.num_clks		= ARRAY_SIZE(sm8450_ufs_phy_clk_l),
886607c101fSBartosz Golaszewski 	.vreg_list		= qmp_phy_vreg_l,
887607c101fSBartosz Golaszewski 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
888607c101fSBartosz Golaszewski 	.regs			= ufsphy_v5_regs_layout,
889607c101fSBartosz Golaszewski };
890607c101fSBartosz Golaszewski 
8910e089bb8SJohan Hovold static const struct qmp_phy_cfg sc8280xp_ufsphy_cfg = {
8920e089bb8SJohan Hovold 	.lanes			= 2,
8930e089bb8SJohan Hovold 
8946900fdf4SDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
8950e089bb8SJohan Hovold 
896c9a7b0ddSManivannan Sadhasivam 	.tbls = {
897c9a7b0ddSManivannan Sadhasivam 		.serdes		= sm8350_ufsphy_serdes,
898c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_serdes),
899c9a7b0ddSManivannan Sadhasivam 		.tx		= sm8350_ufsphy_tx,
900c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_tx),
901c9a7b0ddSManivannan Sadhasivam 		.rx		= sm8350_ufsphy_rx,
902c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_rx),
903c9a7b0ddSManivannan Sadhasivam 		.pcs		= sm8350_ufsphy_pcs,
904c9a7b0ddSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_pcs),
905c9a7b0ddSManivannan Sadhasivam 	},
9060cf7620eSManivannan Sadhasivam 	.tbls_hs_b = {
9070cf7620eSManivannan Sadhasivam 		.serdes		= sm8350_ufsphy_hs_b_serdes,
9080cf7620eSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
9090cf7620eSManivannan Sadhasivam 	},
9102a397a23SManivannan Sadhasivam 	.tbls_hs_g4 = {
9112a397a23SManivannan Sadhasivam 		.tx		= sm8350_ufsphy_g4_tx,
9122a397a23SManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_tx),
9132a397a23SManivannan Sadhasivam 		.rx		= sm8350_ufsphy_g4_rx,
9142a397a23SManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_rx),
9152a397a23SManivannan Sadhasivam 		.pcs		= sm8350_ufsphy_g4_pcs,
9162a397a23SManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
9172a397a23SManivannan Sadhasivam 	},
9180e089bb8SJohan Hovold 	.clk_list		= sdm845_ufs_phy_clk_l,
9190e089bb8SJohan Hovold 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
9200e089bb8SJohan Hovold 	.vreg_list		= qmp_phy_vreg_l,
9210e089bb8SJohan Hovold 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
9225db22640SDmitry Baryshkov 	.regs			= ufsphy_v5_regs_layout,
9230e089bb8SJohan Hovold };
9240e089bb8SJohan Hovold 
92594a407ccSDmitry Baryshkov static const struct qmp_phy_cfg sdm845_ufsphy_cfg = {
92607d386bfSJohan Hovold 	.lanes			= 2,
92794a407ccSDmitry Baryshkov 
92820b5c6aeSDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
92920b5c6aeSDmitry Baryshkov 
930c9a7b0ddSManivannan Sadhasivam 	.tbls = {
931c9a7b0ddSManivannan Sadhasivam 		.serdes		= sdm845_ufsphy_serdes,
932c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sdm845_ufsphy_serdes),
933c9a7b0ddSManivannan Sadhasivam 		.tx		= sdm845_ufsphy_tx,
934c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sdm845_ufsphy_tx),
935c9a7b0ddSManivannan Sadhasivam 		.rx		= sdm845_ufsphy_rx,
936c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sdm845_ufsphy_rx),
937c9a7b0ddSManivannan Sadhasivam 		.pcs		= sdm845_ufsphy_pcs,
938c9a7b0ddSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sdm845_ufsphy_pcs),
939c9a7b0ddSManivannan Sadhasivam 	},
9400cf7620eSManivannan Sadhasivam 	.tbls_hs_b = {
9410cf7620eSManivannan Sadhasivam 		.serdes		= sdm845_ufsphy_hs_b_serdes,
9420cf7620eSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sdm845_ufsphy_hs_b_serdes),
9430cf7620eSManivannan Sadhasivam 	},
94494a407ccSDmitry Baryshkov 	.clk_list		= sdm845_ufs_phy_clk_l,
94594a407ccSDmitry Baryshkov 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
94694a407ccSDmitry Baryshkov 	.vreg_list		= qmp_phy_vreg_l,
94794a407ccSDmitry Baryshkov 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
9485db22640SDmitry Baryshkov 	.regs			= ufsphy_v3_regs_layout,
94994a407ccSDmitry Baryshkov 
95094a407ccSDmitry Baryshkov 	.no_pcs_sw_reset	= true,
95194a407ccSDmitry Baryshkov };
95294a407ccSDmitry Baryshkov 
95394a407ccSDmitry Baryshkov static const struct qmp_phy_cfg sm6115_ufsphy_cfg = {
95407d386bfSJohan Hovold 	.lanes			= 1,
95594a407ccSDmitry Baryshkov 
9566900fdf4SDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
9579b9e29afSLux Aliaga 
958c9a7b0ddSManivannan Sadhasivam 	.tbls = {
959c9a7b0ddSManivannan Sadhasivam 		.serdes		= sm6115_ufsphy_serdes,
960c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm6115_ufsphy_serdes),
961c9a7b0ddSManivannan Sadhasivam 		.tx		= sm6115_ufsphy_tx,
962c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm6115_ufsphy_tx),
963c9a7b0ddSManivannan Sadhasivam 		.rx		= sm6115_ufsphy_rx,
964c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm6115_ufsphy_rx),
965c9a7b0ddSManivannan Sadhasivam 		.pcs		= sm6115_ufsphy_pcs,
966c9a7b0ddSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm6115_ufsphy_pcs),
967c9a7b0ddSManivannan Sadhasivam 	},
9680cf7620eSManivannan Sadhasivam 	.tbls_hs_b = {
9690cf7620eSManivannan Sadhasivam 		.serdes		= sm6115_ufsphy_hs_b_serdes,
9700cf7620eSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm6115_ufsphy_hs_b_serdes),
9710cf7620eSManivannan Sadhasivam 	},
97294a407ccSDmitry Baryshkov 	.clk_list		= sdm845_ufs_phy_clk_l,
97394a407ccSDmitry Baryshkov 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
97494a407ccSDmitry Baryshkov 	.vreg_list		= qmp_phy_vreg_l,
97594a407ccSDmitry Baryshkov 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
9765db22640SDmitry Baryshkov 	.regs			= ufsphy_v2_regs_layout,
97794a407ccSDmitry Baryshkov 
97894a407ccSDmitry Baryshkov 	.no_pcs_sw_reset	= true,
97994a407ccSDmitry Baryshkov };
98094a407ccSDmitry Baryshkov 
981868c2a6cSDavid Wronek static const struct qmp_phy_cfg sm7150_ufsphy_cfg = {
982868c2a6cSDavid Wronek 	.lanes			= 1,
983868c2a6cSDavid Wronek 
984868c2a6cSDavid Wronek 	.offsets		= &qmp_ufs_offsets,
985868c2a6cSDavid Wronek 
986868c2a6cSDavid Wronek 	.tbls = {
987868c2a6cSDavid Wronek 		.serdes		= sdm845_ufsphy_serdes,
988868c2a6cSDavid Wronek 		.serdes_num	= ARRAY_SIZE(sdm845_ufsphy_serdes),
989868c2a6cSDavid Wronek 		.tx		= sdm845_ufsphy_tx,
990868c2a6cSDavid Wronek 		.tx_num		= ARRAY_SIZE(sdm845_ufsphy_tx),
991868c2a6cSDavid Wronek 		.rx		= sm7150_ufsphy_rx,
992868c2a6cSDavid Wronek 		.rx_num		= ARRAY_SIZE(sm7150_ufsphy_rx),
993868c2a6cSDavid Wronek 		.pcs		= sm7150_ufsphy_pcs,
994868c2a6cSDavid Wronek 		.pcs_num	= ARRAY_SIZE(sm7150_ufsphy_pcs),
995868c2a6cSDavid Wronek 	},
996868c2a6cSDavid Wronek 	.tbls_hs_b = {
997868c2a6cSDavid Wronek 		.serdes		= sdm845_ufsphy_hs_b_serdes,
998868c2a6cSDavid Wronek 		.serdes_num	= ARRAY_SIZE(sdm845_ufsphy_hs_b_serdes),
999868c2a6cSDavid Wronek 	},
1000868c2a6cSDavid Wronek 	.clk_list		= sdm845_ufs_phy_clk_l,
1001868c2a6cSDavid Wronek 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1002868c2a6cSDavid Wronek 	.vreg_list		= qmp_phy_vreg_l,
1003868c2a6cSDavid Wronek 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
1004868c2a6cSDavid Wronek 	.regs			= ufsphy_v3_regs_layout,
1005868c2a6cSDavid Wronek 
1006868c2a6cSDavid Wronek 	.no_pcs_sw_reset	= true,
1007868c2a6cSDavid Wronek };
1008868c2a6cSDavid Wronek 
100994a407ccSDmitry Baryshkov static const struct qmp_phy_cfg sm8150_ufsphy_cfg = {
101007d386bfSJohan Hovold 	.lanes			= 2,
101194a407ccSDmitry Baryshkov 
1012*b102ce6dSDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
1013*b102ce6dSDmitry Baryshkov 
1014c9a7b0ddSManivannan Sadhasivam 	.tbls = {
1015c9a7b0ddSManivannan Sadhasivam 		.serdes		= sm8150_ufsphy_serdes,
1016c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8150_ufsphy_serdes),
1017c9a7b0ddSManivannan Sadhasivam 		.tx		= sm8150_ufsphy_tx,
1018c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8150_ufsphy_tx),
1019c9a7b0ddSManivannan Sadhasivam 		.rx		= sm8150_ufsphy_rx,
1020c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8150_ufsphy_rx),
1021c9a7b0ddSManivannan Sadhasivam 		.pcs		= sm8150_ufsphy_pcs,
1022c9a7b0ddSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8150_ufsphy_pcs),
1023c9a7b0ddSManivannan Sadhasivam 	},
10240cf7620eSManivannan Sadhasivam 	.tbls_hs_b = {
10250cf7620eSManivannan Sadhasivam 		.serdes		= sm8150_ufsphy_hs_b_serdes,
10260cf7620eSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
10270cf7620eSManivannan Sadhasivam 	},
1028f89dcb24SManivannan Sadhasivam 	.tbls_hs_g4 = {
1029f89dcb24SManivannan Sadhasivam 		.tx		= sm8150_ufsphy_hs_g4_tx,
1030f89dcb24SManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8150_ufsphy_hs_g4_tx),
1031f89dcb24SManivannan Sadhasivam 		.rx		= sm8150_ufsphy_hs_g4_rx,
1032f89dcb24SManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8150_ufsphy_hs_g4_rx),
1033f89dcb24SManivannan Sadhasivam 		.pcs		= sm8150_ufsphy_hs_g4_pcs,
1034f89dcb24SManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
1035f89dcb24SManivannan Sadhasivam 	},
103694a407ccSDmitry Baryshkov 	.clk_list		= sdm845_ufs_phy_clk_l,
103794a407ccSDmitry Baryshkov 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
103894a407ccSDmitry Baryshkov 	.vreg_list		= qmp_phy_vreg_l,
103994a407ccSDmitry Baryshkov 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
10405db22640SDmitry Baryshkov 	.regs			= ufsphy_v4_regs_layout,
104194a407ccSDmitry Baryshkov };
104294a407ccSDmitry Baryshkov 
1043692b6551SManivannan Sadhasivam static const struct qmp_phy_cfg sm8250_ufsphy_cfg = {
1044692b6551SManivannan Sadhasivam 	.lanes			= 2,
1045692b6551SManivannan Sadhasivam 
104620b5c6aeSDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
104720b5c6aeSDmitry Baryshkov 
1048692b6551SManivannan Sadhasivam 	.tbls = {
1049692b6551SManivannan Sadhasivam 		.serdes		= sm8150_ufsphy_serdes,
1050692b6551SManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8150_ufsphy_serdes),
1051692b6551SManivannan Sadhasivam 		.tx		= sm8150_ufsphy_tx,
1052692b6551SManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8150_ufsphy_tx),
1053692b6551SManivannan Sadhasivam 		.rx		= sm8150_ufsphy_rx,
1054692b6551SManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8150_ufsphy_rx),
1055692b6551SManivannan Sadhasivam 		.pcs		= sm8150_ufsphy_pcs,
1056692b6551SManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8150_ufsphy_pcs),
1057692b6551SManivannan Sadhasivam 	},
1058692b6551SManivannan Sadhasivam 	.tbls_hs_b = {
1059692b6551SManivannan Sadhasivam 		.serdes		= sm8150_ufsphy_hs_b_serdes,
1060692b6551SManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
1061692b6551SManivannan Sadhasivam 	},
1062692b6551SManivannan Sadhasivam 	.tbls_hs_g4 = {
1063692b6551SManivannan Sadhasivam 		.tx		= sm8250_ufsphy_hs_g4_tx,
1064692b6551SManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8250_ufsphy_hs_g4_tx),
1065692b6551SManivannan Sadhasivam 		.rx		= sm8250_ufsphy_hs_g4_rx,
1066692b6551SManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8250_ufsphy_hs_g4_rx),
1067692b6551SManivannan Sadhasivam 		.pcs		= sm8150_ufsphy_hs_g4_pcs,
1068692b6551SManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
1069692b6551SManivannan Sadhasivam 	},
1070692b6551SManivannan Sadhasivam 	.clk_list		= sdm845_ufs_phy_clk_l,
1071692b6551SManivannan Sadhasivam 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1072692b6551SManivannan Sadhasivam 	.vreg_list		= qmp_phy_vreg_l,
1073692b6551SManivannan Sadhasivam 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
1074692b6551SManivannan Sadhasivam 	.regs			= ufsphy_v4_regs_layout,
1075692b6551SManivannan Sadhasivam };
1076692b6551SManivannan Sadhasivam 
107794a407ccSDmitry Baryshkov static const struct qmp_phy_cfg sm8350_ufsphy_cfg = {
107807d386bfSJohan Hovold 	.lanes			= 2,
107994a407ccSDmitry Baryshkov 
108020b5c6aeSDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
108120b5c6aeSDmitry Baryshkov 
1082c9a7b0ddSManivannan Sadhasivam 	.tbls = {
1083c9a7b0ddSManivannan Sadhasivam 		.serdes		= sm8350_ufsphy_serdes,
1084c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_serdes),
1085c9a7b0ddSManivannan Sadhasivam 		.tx		= sm8350_ufsphy_tx,
1086c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_tx),
1087c9a7b0ddSManivannan Sadhasivam 		.rx		= sm8350_ufsphy_rx,
1088c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_rx),
1089c9a7b0ddSManivannan Sadhasivam 		.pcs		= sm8350_ufsphy_pcs,
1090c9a7b0ddSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_pcs),
1091c9a7b0ddSManivannan Sadhasivam 	},
10920cf7620eSManivannan Sadhasivam 	.tbls_hs_b = {
10930cf7620eSManivannan Sadhasivam 		.serdes		= sm8350_ufsphy_hs_b_serdes,
10940cf7620eSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
10950cf7620eSManivannan Sadhasivam 	},
109690c64cc0SManivannan Sadhasivam 	.tbls_hs_g4 = {
109790c64cc0SManivannan Sadhasivam 		.tx		= sm8350_ufsphy_g4_tx,
109890c64cc0SManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_tx),
109990c64cc0SManivannan Sadhasivam 		.rx		= sm8350_ufsphy_g4_rx,
110090c64cc0SManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_rx),
110190c64cc0SManivannan Sadhasivam 		.pcs		= sm8350_ufsphy_g4_pcs,
110290c64cc0SManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
110390c64cc0SManivannan Sadhasivam 	},
110494a407ccSDmitry Baryshkov 	.clk_list		= sdm845_ufs_phy_clk_l,
110594a407ccSDmitry Baryshkov 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
110694a407ccSDmitry Baryshkov 	.vreg_list		= qmp_phy_vreg_l,
110794a407ccSDmitry Baryshkov 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
11085db22640SDmitry Baryshkov 	.regs			= ufsphy_v5_regs_layout,
110994a407ccSDmitry Baryshkov };
111094a407ccSDmitry Baryshkov 
111194a407ccSDmitry Baryshkov static const struct qmp_phy_cfg sm8450_ufsphy_cfg = {
111207d386bfSJohan Hovold 	.lanes			= 2,
111394a407ccSDmitry Baryshkov 
111420b5c6aeSDmitry Baryshkov 	.offsets		= &qmp_ufs_offsets,
111520b5c6aeSDmitry Baryshkov 
1116c9a7b0ddSManivannan Sadhasivam 	.tbls = {
1117c9a7b0ddSManivannan Sadhasivam 		.serdes		= sm8350_ufsphy_serdes,
1118c9a7b0ddSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_serdes),
1119c9a7b0ddSManivannan Sadhasivam 		.tx		= sm8350_ufsphy_tx,
1120c9a7b0ddSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_tx),
1121c9a7b0ddSManivannan Sadhasivam 		.rx		= sm8350_ufsphy_rx,
1122c9a7b0ddSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_rx),
1123c9a7b0ddSManivannan Sadhasivam 		.pcs		= sm8350_ufsphy_pcs,
1124c9a7b0ddSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_pcs),
1125c9a7b0ddSManivannan Sadhasivam 	},
11260cf7620eSManivannan Sadhasivam 	.tbls_hs_b = {
11270cf7620eSManivannan Sadhasivam 		.serdes		= sm8350_ufsphy_hs_b_serdes,
11280cf7620eSManivannan Sadhasivam 		.serdes_num	= ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
11290cf7620eSManivannan Sadhasivam 	},
11308d0fb02cSManivannan Sadhasivam 	.tbls_hs_g4 = {
11318d0fb02cSManivannan Sadhasivam 		.tx		= sm8350_ufsphy_g4_tx,
11328d0fb02cSManivannan Sadhasivam 		.tx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_tx),
11338d0fb02cSManivannan Sadhasivam 		.rx		= sm8350_ufsphy_g4_rx,
11348d0fb02cSManivannan Sadhasivam 		.rx_num		= ARRAY_SIZE(sm8350_ufsphy_g4_rx),
11358d0fb02cSManivannan Sadhasivam 		.pcs		= sm8350_ufsphy_g4_pcs,
11368d0fb02cSManivannan Sadhasivam 		.pcs_num	= ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
11378d0fb02cSManivannan Sadhasivam 	},
113894a407ccSDmitry Baryshkov 	.clk_list		= sm8450_ufs_phy_clk_l,
113994a407ccSDmitry Baryshkov 	.num_clks		= ARRAY_SIZE(sm8450_ufs_phy_clk_l),
114094a407ccSDmitry Baryshkov 	.vreg_list		= qmp_phy_vreg_l,
114194a407ccSDmitry Baryshkov 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
11425db22640SDmitry Baryshkov 	.regs			= ufsphy_v5_regs_layout,
114394a407ccSDmitry Baryshkov };
114494a407ccSDmitry Baryshkov 
11451679bfefSAbel Vesa static const struct qmp_phy_cfg sm8550_ufsphy_cfg = {
11461679bfefSAbel Vesa 	.lanes			= 2,
11471679bfefSAbel Vesa 
11481679bfefSAbel Vesa 	.offsets		= &qmp_ufs_offsets_v6,
11491679bfefSAbel Vesa 
11501679bfefSAbel Vesa 	.tbls = {
11511679bfefSAbel Vesa 		.serdes		= sm8550_ufsphy_serdes,
11521679bfefSAbel Vesa 		.serdes_num	= ARRAY_SIZE(sm8550_ufsphy_serdes),
11531679bfefSAbel Vesa 		.tx		= sm8550_ufsphy_tx,
11541679bfefSAbel Vesa 		.tx_num		= ARRAY_SIZE(sm8550_ufsphy_tx),
11551679bfefSAbel Vesa 		.rx		= sm8550_ufsphy_rx,
11561679bfefSAbel Vesa 		.rx_num		= ARRAY_SIZE(sm8550_ufsphy_rx),
11571679bfefSAbel Vesa 		.pcs		= sm8550_ufsphy_pcs,
11581679bfefSAbel Vesa 		.pcs_num	= ARRAY_SIZE(sm8550_ufsphy_pcs),
11591679bfefSAbel Vesa 	},
11601679bfefSAbel Vesa 	.clk_list		= sdm845_ufs_phy_clk_l,
11611679bfefSAbel Vesa 	.num_clks		= ARRAY_SIZE(sdm845_ufs_phy_clk_l),
11621679bfefSAbel Vesa 	.vreg_list		= qmp_phy_vreg_l,
11631679bfefSAbel Vesa 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
11641679bfefSAbel Vesa 	.regs			= ufsphy_v6_regs_layout,
11651679bfefSAbel Vesa };
11661679bfefSAbel Vesa 
qmp_ufs_configure_lane(void __iomem * base,const struct qmp_phy_init_tbl tbl[],int num,u8 lane_mask)11674412817bSJohan Hovold static void qmp_ufs_configure_lane(void __iomem *base,
116894a407ccSDmitry Baryshkov 					const struct qmp_phy_init_tbl tbl[],
116994a407ccSDmitry Baryshkov 					int num,
117094a407ccSDmitry Baryshkov 					u8 lane_mask)
117194a407ccSDmitry Baryshkov {
117294a407ccSDmitry Baryshkov 	int i;
117394a407ccSDmitry Baryshkov 	const struct qmp_phy_init_tbl *t = tbl;
117494a407ccSDmitry Baryshkov 
117594a407ccSDmitry Baryshkov 	if (!t)
117694a407ccSDmitry Baryshkov 		return;
117794a407ccSDmitry Baryshkov 
117894a407ccSDmitry Baryshkov 	for (i = 0; i < num; i++, t++) {
117994a407ccSDmitry Baryshkov 		if (!(t->lane_mask & lane_mask))
118094a407ccSDmitry Baryshkov 			continue;
118194a407ccSDmitry Baryshkov 
118294a407ccSDmitry Baryshkov 		writel(t->val, base + t->offset);
118394a407ccSDmitry Baryshkov 	}
118494a407ccSDmitry Baryshkov }
118594a407ccSDmitry Baryshkov 
qmp_ufs_configure(void __iomem * base,const struct qmp_phy_init_tbl tbl[],int num)11864412817bSJohan Hovold static void qmp_ufs_configure(void __iomem *base,
118794a407ccSDmitry Baryshkov 				   const struct qmp_phy_init_tbl tbl[],
118894a407ccSDmitry Baryshkov 				   int num)
118994a407ccSDmitry Baryshkov {
119091496846SJohan Hovold 	qmp_ufs_configure_lane(base, tbl, num, 0xff);
119194a407ccSDmitry Baryshkov }
119294a407ccSDmitry Baryshkov 
qmp_ufs_serdes_init(struct qmp_ufs * qmp,const struct qmp_phy_cfg_tbls * tbls)1193c9a7b0ddSManivannan Sadhasivam static void qmp_ufs_serdes_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
1194c9a7b0ddSManivannan Sadhasivam {
1195c9a7b0ddSManivannan Sadhasivam 	void __iomem *serdes = qmp->serdes;
1196c9a7b0ddSManivannan Sadhasivam 
1197c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_configure(serdes, tbls->serdes, tbls->serdes_num);
1198c9a7b0ddSManivannan Sadhasivam }
1199c9a7b0ddSManivannan Sadhasivam 
qmp_ufs_lanes_init(struct qmp_ufs * qmp,const struct qmp_phy_cfg_tbls * tbls)1200c9a7b0ddSManivannan Sadhasivam static void qmp_ufs_lanes_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
120194a407ccSDmitry Baryshkov {
1202a36032dbSJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
1203c9a7b0ddSManivannan Sadhasivam 	void __iomem *tx = qmp->tx;
1204c9a7b0ddSManivannan Sadhasivam 	void __iomem *rx = qmp->rx;
120594a407ccSDmitry Baryshkov 
1206c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_configure_lane(tx, tbls->tx, tbls->tx_num, 1);
1207c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_configure_lane(rx, tbls->rx, tbls->rx_num, 1);
120894a407ccSDmitry Baryshkov 
1209c9a7b0ddSManivannan Sadhasivam 	if (cfg->lanes >= 2) {
1210c9a7b0ddSManivannan Sadhasivam 		qmp_ufs_configure_lane(qmp->tx2, tbls->tx, tbls->tx_num, 2);
1211c9a7b0ddSManivannan Sadhasivam 		qmp_ufs_configure_lane(qmp->rx2, tbls->rx, tbls->rx_num, 2);
1212c9a7b0ddSManivannan Sadhasivam 	}
1213c9a7b0ddSManivannan Sadhasivam }
1214c9a7b0ddSManivannan Sadhasivam 
qmp_ufs_pcs_init(struct qmp_ufs * qmp,const struct qmp_phy_cfg_tbls * tbls)1215c9a7b0ddSManivannan Sadhasivam static void qmp_ufs_pcs_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
1216c9a7b0ddSManivannan Sadhasivam {
1217c9a7b0ddSManivannan Sadhasivam 	void __iomem *pcs = qmp->pcs;
1218c9a7b0ddSManivannan Sadhasivam 
1219c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_configure(pcs, tbls->pcs, tbls->pcs_num);
1220c9a7b0ddSManivannan Sadhasivam }
1221c9a7b0ddSManivannan Sadhasivam 
qmp_ufs_init_registers(struct qmp_ufs * qmp,const struct qmp_phy_cfg * cfg)1222c9a7b0ddSManivannan Sadhasivam static void qmp_ufs_init_registers(struct qmp_ufs *qmp, const struct qmp_phy_cfg *cfg)
1223c9a7b0ddSManivannan Sadhasivam {
1224c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_serdes_init(qmp, &cfg->tbls);
122569d2f980SManivannan Sadhasivam 	if (qmp->mode == PHY_MODE_UFS_HS_B)
122669d2f980SManivannan Sadhasivam 		qmp_ufs_serdes_init(qmp, &cfg->tbls_hs_b);
1227c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_lanes_init(qmp, &cfg->tbls);
1228baf8d17eSManivannan Sadhasivam 	if (qmp->submode == UFS_HS_G4)
1229baf8d17eSManivannan Sadhasivam 		qmp_ufs_lanes_init(qmp, &cfg->tbls_hs_g4);
1230c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_pcs_init(qmp, &cfg->tbls);
1231baf8d17eSManivannan Sadhasivam 	if (qmp->submode == UFS_HS_G4)
1232baf8d17eSManivannan Sadhasivam 		qmp_ufs_pcs_init(qmp, &cfg->tbls_hs_g4);
123394a407ccSDmitry Baryshkov }
123494a407ccSDmitry Baryshkov 
qmp_ufs_com_init(struct qmp_ufs * qmp)1235a36032dbSJohan Hovold static int qmp_ufs_com_init(struct qmp_ufs *qmp)
123694a407ccSDmitry Baryshkov {
1237a36032dbSJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
1238a36032dbSJohan Hovold 	void __iomem *pcs = qmp->pcs;
12393e1865baSDmitry Baryshkov 	int ret;
124094a407ccSDmitry Baryshkov 
124194a407ccSDmitry Baryshkov 	ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
124294a407ccSDmitry Baryshkov 	if (ret) {
124394a407ccSDmitry Baryshkov 		dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
12441da7115eSDmitry Baryshkov 		return ret;
124594a407ccSDmitry Baryshkov 	}
124694a407ccSDmitry Baryshkov 
124794a407ccSDmitry Baryshkov 	ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
124894a407ccSDmitry Baryshkov 	if (ret)
12493e1865baSDmitry Baryshkov 		goto err_disable_regulators;
125094a407ccSDmitry Baryshkov 
1251cb4a982fSJohan Hovold 	qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
125294a407ccSDmitry Baryshkov 
125394a407ccSDmitry Baryshkov 	return 0;
125494a407ccSDmitry Baryshkov 
125594a407ccSDmitry Baryshkov err_disable_regulators:
125694a407ccSDmitry Baryshkov 	regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
125794a407ccSDmitry Baryshkov 
125894a407ccSDmitry Baryshkov 	return ret;
125994a407ccSDmitry Baryshkov }
126094a407ccSDmitry Baryshkov 
qmp_ufs_com_exit(struct qmp_ufs * qmp)1261a36032dbSJohan Hovold static int qmp_ufs_com_exit(struct qmp_ufs *qmp)
126294a407ccSDmitry Baryshkov {
1263a36032dbSJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
126494a407ccSDmitry Baryshkov 
126594a407ccSDmitry Baryshkov 	reset_control_assert(qmp->ufs_reset);
126694a407ccSDmitry Baryshkov 
126794a407ccSDmitry Baryshkov 	clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
126894a407ccSDmitry Baryshkov 
126994a407ccSDmitry Baryshkov 	regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
127094a407ccSDmitry Baryshkov 
127194a407ccSDmitry Baryshkov 	return 0;
127294a407ccSDmitry Baryshkov }
127394a407ccSDmitry Baryshkov 
qmp_ufs_init(struct phy * phy)12744412817bSJohan Hovold static int qmp_ufs_init(struct phy *phy)
127594a407ccSDmitry Baryshkov {
1276a36032dbSJohan Hovold 	struct qmp_ufs *qmp = phy_get_drvdata(phy);
1277a36032dbSJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
127894a407ccSDmitry Baryshkov 	int ret;
127994a407ccSDmitry Baryshkov 	dev_vdbg(qmp->dev, "Initializing QMP phy\n");
128094a407ccSDmitry Baryshkov 
128194a407ccSDmitry Baryshkov 	if (cfg->no_pcs_sw_reset) {
128294a407ccSDmitry Baryshkov 		/*
128394a407ccSDmitry Baryshkov 		 * Get UFS reset, which is delayed until now to avoid a
128494a407ccSDmitry Baryshkov 		 * circular dependency where UFS needs its PHY, but the PHY
128594a407ccSDmitry Baryshkov 		 * needs this UFS reset.
128694a407ccSDmitry Baryshkov 		 */
128794a407ccSDmitry Baryshkov 		if (!qmp->ufs_reset) {
128894a407ccSDmitry Baryshkov 			qmp->ufs_reset =
128994a407ccSDmitry Baryshkov 				devm_reset_control_get_exclusive(qmp->dev,
129094a407ccSDmitry Baryshkov 								 "ufsphy");
129194a407ccSDmitry Baryshkov 
129294a407ccSDmitry Baryshkov 			if (IS_ERR(qmp->ufs_reset)) {
129394a407ccSDmitry Baryshkov 				ret = PTR_ERR(qmp->ufs_reset);
129494a407ccSDmitry Baryshkov 				dev_err(qmp->dev,
129594a407ccSDmitry Baryshkov 					"failed to get UFS reset: %d\n",
129694a407ccSDmitry Baryshkov 					ret);
129794a407ccSDmitry Baryshkov 
129894a407ccSDmitry Baryshkov 				qmp->ufs_reset = NULL;
129994a407ccSDmitry Baryshkov 				return ret;
130094a407ccSDmitry Baryshkov 			}
130194a407ccSDmitry Baryshkov 		}
130294a407ccSDmitry Baryshkov 
130394a407ccSDmitry Baryshkov 		ret = reset_control_assert(qmp->ufs_reset);
130494a407ccSDmitry Baryshkov 		if (ret)
130594a407ccSDmitry Baryshkov 			return ret;
130694a407ccSDmitry Baryshkov 	}
130794a407ccSDmitry Baryshkov 
1308a36032dbSJohan Hovold 	ret = qmp_ufs_com_init(qmp);
130994a407ccSDmitry Baryshkov 	if (ret)
131094a407ccSDmitry Baryshkov 		return ret;
131194a407ccSDmitry Baryshkov 
131294a407ccSDmitry Baryshkov 	return 0;
131394a407ccSDmitry Baryshkov }
131494a407ccSDmitry Baryshkov 
qmp_ufs_power_on(struct phy * phy)13154412817bSJohan Hovold static int qmp_ufs_power_on(struct phy *phy)
131694a407ccSDmitry Baryshkov {
1317a36032dbSJohan Hovold 	struct qmp_ufs *qmp = phy_get_drvdata(phy);
1318a36032dbSJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
1319a36032dbSJohan Hovold 	void __iomem *pcs = qmp->pcs;
132094a407ccSDmitry Baryshkov 	void __iomem *status;
13212f561b68SJohan Hovold 	unsigned int val;
132294a407ccSDmitry Baryshkov 	int ret;
132394a407ccSDmitry Baryshkov 
1324c9a7b0ddSManivannan Sadhasivam 	qmp_ufs_init_registers(qmp, cfg);
132594a407ccSDmitry Baryshkov 
132694a407ccSDmitry Baryshkov 	ret = reset_control_deassert(qmp->ufs_reset);
132794a407ccSDmitry Baryshkov 	if (ret)
13283e1865baSDmitry Baryshkov 		return ret;
132994a407ccSDmitry Baryshkov 
133094a407ccSDmitry Baryshkov 	/* Pull PHY out of reset state */
133194a407ccSDmitry Baryshkov 	if (!cfg->no_pcs_sw_reset)
133294a407ccSDmitry Baryshkov 		qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1333cb4a982fSJohan Hovold 
1334cb4a982fSJohan Hovold 	/* start SerDes */
1335cb4a982fSJohan Hovold 	qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], SERDES_START);
133694a407ccSDmitry Baryshkov 
133794a407ccSDmitry Baryshkov 	status = pcs + cfg->regs[QPHY_PCS_READY_STATUS];
13387516edbfSJohan Hovold 	ret = readl_poll_timeout(status, val, (val & PCS_READY), 200,
133994a407ccSDmitry Baryshkov 				 PHY_INIT_COMPLETE_TIMEOUT);
134094a407ccSDmitry Baryshkov 	if (ret) {
134194a407ccSDmitry Baryshkov 		dev_err(qmp->dev, "phy initialization timed-out\n");
134294a407ccSDmitry Baryshkov 		return ret;
134394a407ccSDmitry Baryshkov 	}
134494a407ccSDmitry Baryshkov 
13453e1865baSDmitry Baryshkov 	return 0;
13463e1865baSDmitry Baryshkov }
13473e1865baSDmitry Baryshkov 
qmp_ufs_power_off(struct phy * phy)13484412817bSJohan Hovold static int qmp_ufs_power_off(struct phy *phy)
134994a407ccSDmitry Baryshkov {
1350a36032dbSJohan Hovold 	struct qmp_ufs *qmp = phy_get_drvdata(phy);
1351a36032dbSJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
135294a407ccSDmitry Baryshkov 
135394a407ccSDmitry Baryshkov 	/* PHY reset */
135494a407ccSDmitry Baryshkov 	if (!cfg->no_pcs_sw_reset)
1355a36032dbSJohan Hovold 		qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
135694a407ccSDmitry Baryshkov 
1357cb4a982fSJohan Hovold 	/* stop SerDes */
1358a36032dbSJohan Hovold 	qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL], SERDES_START);
135994a407ccSDmitry Baryshkov 
136094a407ccSDmitry Baryshkov 	/* Put PHY into POWER DOWN state: active low */
1361a36032dbSJohan Hovold 	qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
1362cb4a982fSJohan Hovold 			SW_PWRDN);
136394a407ccSDmitry Baryshkov 
136494a407ccSDmitry Baryshkov 	return 0;
136594a407ccSDmitry Baryshkov }
136694a407ccSDmitry Baryshkov 
qmp_ufs_exit(struct phy * phy)13674412817bSJohan Hovold static int qmp_ufs_exit(struct phy *phy)
136894a407ccSDmitry Baryshkov {
1369a36032dbSJohan Hovold 	struct qmp_ufs *qmp = phy_get_drvdata(phy);
137094a407ccSDmitry Baryshkov 
1371a36032dbSJohan Hovold 	qmp_ufs_com_exit(qmp);
137294a407ccSDmitry Baryshkov 
137394a407ccSDmitry Baryshkov 	return 0;
137494a407ccSDmitry Baryshkov }
137594a407ccSDmitry Baryshkov 
qmp_ufs_enable(struct phy * phy)13764412817bSJohan Hovold static int qmp_ufs_enable(struct phy *phy)
137794a407ccSDmitry Baryshkov {
137894a407ccSDmitry Baryshkov 	int ret;
137994a407ccSDmitry Baryshkov 
13804412817bSJohan Hovold 	ret = qmp_ufs_init(phy);
138194a407ccSDmitry Baryshkov 	if (ret)
138294a407ccSDmitry Baryshkov 		return ret;
138394a407ccSDmitry Baryshkov 
13844412817bSJohan Hovold 	ret = qmp_ufs_power_on(phy);
138594a407ccSDmitry Baryshkov 	if (ret)
13864412817bSJohan Hovold 		qmp_ufs_exit(phy);
138794a407ccSDmitry Baryshkov 
138894a407ccSDmitry Baryshkov 	return ret;
138994a407ccSDmitry Baryshkov }
139094a407ccSDmitry Baryshkov 
qmp_ufs_disable(struct phy * phy)13914412817bSJohan Hovold static int qmp_ufs_disable(struct phy *phy)
139294a407ccSDmitry Baryshkov {
139394a407ccSDmitry Baryshkov 	int ret;
139494a407ccSDmitry Baryshkov 
13954412817bSJohan Hovold 	ret = qmp_ufs_power_off(phy);
139694a407ccSDmitry Baryshkov 	if (ret)
139794a407ccSDmitry Baryshkov 		return ret;
13984412817bSJohan Hovold 	return qmp_ufs_exit(phy);
139994a407ccSDmitry Baryshkov }
140094a407ccSDmitry Baryshkov 
qmp_ufs_set_mode(struct phy * phy,enum phy_mode mode,int submode)140169d2f980SManivannan Sadhasivam static int qmp_ufs_set_mode(struct phy *phy, enum phy_mode mode, int submode)
140269d2f980SManivannan Sadhasivam {
140369d2f980SManivannan Sadhasivam 	struct qmp_ufs *qmp = phy_get_drvdata(phy);
140469d2f980SManivannan Sadhasivam 
140569d2f980SManivannan Sadhasivam 	qmp->mode = mode;
1406baf8d17eSManivannan Sadhasivam 	qmp->submode = submode;
140769d2f980SManivannan Sadhasivam 
140869d2f980SManivannan Sadhasivam 	return 0;
140969d2f980SManivannan Sadhasivam }
141069d2f980SManivannan Sadhasivam 
1411b98e44e6SJohan Hovold static const struct phy_ops qcom_qmp_ufs_phy_ops = {
1412b98e44e6SJohan Hovold 	.power_on	= qmp_ufs_enable,
1413b98e44e6SJohan Hovold 	.power_off	= qmp_ufs_disable,
141469d2f980SManivannan Sadhasivam 	.set_mode	= qmp_ufs_set_mode,
1415b98e44e6SJohan Hovold 	.owner		= THIS_MODULE,
1416b98e44e6SJohan Hovold };
1417b98e44e6SJohan Hovold 
qmp_ufs_vreg_init(struct qmp_ufs * qmp)1418018dfc99SJohan Hovold static int qmp_ufs_vreg_init(struct qmp_ufs *qmp)
141994a407ccSDmitry Baryshkov {
1420018dfc99SJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
1421018dfc99SJohan Hovold 	struct device *dev = qmp->dev;
142294a407ccSDmitry Baryshkov 	int num = cfg->num_vregs;
142394a407ccSDmitry Baryshkov 	int i;
142494a407ccSDmitry Baryshkov 
142594a407ccSDmitry Baryshkov 	qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
142694a407ccSDmitry Baryshkov 	if (!qmp->vregs)
142794a407ccSDmitry Baryshkov 		return -ENOMEM;
142894a407ccSDmitry Baryshkov 
142994a407ccSDmitry Baryshkov 	for (i = 0; i < num; i++)
143094a407ccSDmitry Baryshkov 		qmp->vregs[i].supply = cfg->vreg_list[i];
143194a407ccSDmitry Baryshkov 
143294a407ccSDmitry Baryshkov 	return devm_regulator_bulk_get(dev, num, qmp->vregs);
143394a407ccSDmitry Baryshkov }
143494a407ccSDmitry Baryshkov 
qmp_ufs_clk_init(struct qmp_ufs * qmp)1435018dfc99SJohan Hovold static int qmp_ufs_clk_init(struct qmp_ufs *qmp)
143694a407ccSDmitry Baryshkov {
1437018dfc99SJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
1438018dfc99SJohan Hovold 	struct device *dev = qmp->dev;
143994a407ccSDmitry Baryshkov 	int num = cfg->num_clks;
144094a407ccSDmitry Baryshkov 	int i;
144194a407ccSDmitry Baryshkov 
144294a407ccSDmitry Baryshkov 	qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
144394a407ccSDmitry Baryshkov 	if (!qmp->clks)
144494a407ccSDmitry Baryshkov 		return -ENOMEM;
144594a407ccSDmitry Baryshkov 
144694a407ccSDmitry Baryshkov 	for (i = 0; i < num; i++)
144794a407ccSDmitry Baryshkov 		qmp->clks[i].id = cfg->clk_list[i];
144894a407ccSDmitry Baryshkov 
144994a407ccSDmitry Baryshkov 	return devm_clk_bulk_get(dev, num, qmp->clks);
145094a407ccSDmitry Baryshkov }
145194a407ccSDmitry Baryshkov 
qmp_ufs_clk_release_provider(void * res)14527bd7044fSDmitry Baryshkov static void qmp_ufs_clk_release_provider(void *res)
14537bd7044fSDmitry Baryshkov {
14547bd7044fSDmitry Baryshkov 	of_clk_del_provider(res);
14557bd7044fSDmitry Baryshkov }
14567bd7044fSDmitry Baryshkov 
14577bd7044fSDmitry Baryshkov #define UFS_SYMBOL_CLOCKS 3
14587bd7044fSDmitry Baryshkov 
qmp_ufs_register_clocks(struct qmp_ufs * qmp,struct device_node * np)14597bd7044fSDmitry Baryshkov static int qmp_ufs_register_clocks(struct qmp_ufs *qmp, struct device_node *np)
14607bd7044fSDmitry Baryshkov {
14617bd7044fSDmitry Baryshkov 	struct clk_hw_onecell_data *clk_data;
14627bd7044fSDmitry Baryshkov 	struct clk_hw *hw;
14637bd7044fSDmitry Baryshkov 	char name[64];
14647bd7044fSDmitry Baryshkov 	int ret;
14657bd7044fSDmitry Baryshkov 
14667bd7044fSDmitry Baryshkov 	clk_data = devm_kzalloc(qmp->dev,
14677bd7044fSDmitry Baryshkov 				struct_size(clk_data, hws, UFS_SYMBOL_CLOCKS),
14687bd7044fSDmitry Baryshkov 				GFP_KERNEL);
14697bd7044fSDmitry Baryshkov 	if (!clk_data)
14707bd7044fSDmitry Baryshkov 		return -ENOMEM;
14717bd7044fSDmitry Baryshkov 
14727bd7044fSDmitry Baryshkov 	clk_data->num = UFS_SYMBOL_CLOCKS;
14737bd7044fSDmitry Baryshkov 
14747bd7044fSDmitry Baryshkov 	snprintf(name, sizeof(name), "%s::rx_symbol_0", dev_name(qmp->dev));
14757bd7044fSDmitry Baryshkov 	hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
14767bd7044fSDmitry Baryshkov 	if (IS_ERR(hw))
14777bd7044fSDmitry Baryshkov 		return PTR_ERR(hw);
14787bd7044fSDmitry Baryshkov 
14797bd7044fSDmitry Baryshkov 	clk_data->hws[0] = hw;
14807bd7044fSDmitry Baryshkov 
14817bd7044fSDmitry Baryshkov 	snprintf(name, sizeof(name), "%s::rx_symbol_1", dev_name(qmp->dev));
14827bd7044fSDmitry Baryshkov 	hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
14837bd7044fSDmitry Baryshkov 	if (IS_ERR(hw))
14847bd7044fSDmitry Baryshkov 		return PTR_ERR(hw);
14857bd7044fSDmitry Baryshkov 
14867bd7044fSDmitry Baryshkov 	clk_data->hws[1] = hw;
14877bd7044fSDmitry Baryshkov 
14887bd7044fSDmitry Baryshkov 	snprintf(name, sizeof(name), "%s::tx_symbol_0", dev_name(qmp->dev));
14897bd7044fSDmitry Baryshkov 	hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
14907bd7044fSDmitry Baryshkov 	if (IS_ERR(hw))
14917bd7044fSDmitry Baryshkov 		return PTR_ERR(hw);
14927bd7044fSDmitry Baryshkov 
14937bd7044fSDmitry Baryshkov 	clk_data->hws[2] = hw;
14947bd7044fSDmitry Baryshkov 
14957bd7044fSDmitry Baryshkov 	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
14967bd7044fSDmitry Baryshkov 	if (ret)
14977bd7044fSDmitry Baryshkov 		return ret;
14987bd7044fSDmitry Baryshkov 
14997bd7044fSDmitry Baryshkov 	/*
15007bd7044fSDmitry Baryshkov 	 * Roll a devm action because the clock provider can be a child node.
15017bd7044fSDmitry Baryshkov 	 */
15027bd7044fSDmitry Baryshkov 	return devm_add_action_or_reset(qmp->dev, qmp_ufs_clk_release_provider, np);
15037bd7044fSDmitry Baryshkov }
15047bd7044fSDmitry Baryshkov 
qmp_ufs_parse_dt_legacy(struct qmp_ufs * qmp,struct device_node * np)1505c64d39b4SJohan Hovold static int qmp_ufs_parse_dt_legacy(struct qmp_ufs *qmp, struct device_node *np)
150694a407ccSDmitry Baryshkov {
1507c64d39b4SJohan Hovold 	struct platform_device *pdev = to_platform_device(qmp->dev);
1508018dfc99SJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
1509018dfc99SJohan Hovold 	struct device *dev = qmp->dev;
1510c64d39b4SJohan Hovold 
1511c64d39b4SJohan Hovold 	qmp->serdes = devm_platform_ioremap_resource(pdev, 0);
1512c64d39b4SJohan Hovold 	if (IS_ERR(qmp->serdes))
1513c64d39b4SJohan Hovold 		return PTR_ERR(qmp->serdes);
151494a407ccSDmitry Baryshkov 
151594a407ccSDmitry Baryshkov 	/*
15168d3bf724SJohan Hovold 	 * Get memory resources for the PHY:
151794a407ccSDmitry Baryshkov 	 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
151894a407ccSDmitry Baryshkov 	 * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5
151994a407ccSDmitry Baryshkov 	 * For single lane PHYs: pcs_misc (optional) -> 3.
152094a407ccSDmitry Baryshkov 	 */
1521a36032dbSJohan Hovold 	qmp->tx = devm_of_iomap(dev, np, 0, NULL);
1522a36032dbSJohan Hovold 	if (IS_ERR(qmp->tx))
1523a36032dbSJohan Hovold 		return PTR_ERR(qmp->tx);
152494a407ccSDmitry Baryshkov 
1525a36032dbSJohan Hovold 	qmp->rx = devm_of_iomap(dev, np, 1, NULL);
1526a36032dbSJohan Hovold 	if (IS_ERR(qmp->rx))
1527a36032dbSJohan Hovold 		return PTR_ERR(qmp->rx);
152894a407ccSDmitry Baryshkov 
1529a36032dbSJohan Hovold 	qmp->pcs = devm_of_iomap(dev, np, 2, NULL);
1530a36032dbSJohan Hovold 	if (IS_ERR(qmp->pcs))
1531a36032dbSJohan Hovold 		return PTR_ERR(qmp->pcs);
153294a407ccSDmitry Baryshkov 
153307d386bfSJohan Hovold 	if (cfg->lanes >= 2) {
1534a36032dbSJohan Hovold 		qmp->tx2 = devm_of_iomap(dev, np, 3, NULL);
1535a36032dbSJohan Hovold 		if (IS_ERR(qmp->tx2))
1536a36032dbSJohan Hovold 			return PTR_ERR(qmp->tx2);
153763825558SJohan Hovold 
1538a36032dbSJohan Hovold 		qmp->rx2 = devm_of_iomap(dev, np, 4, NULL);
1539a36032dbSJohan Hovold 		if (IS_ERR(qmp->rx2))
1540a36032dbSJohan Hovold 			return PTR_ERR(qmp->rx2);
154194a407ccSDmitry Baryshkov 
1542a36032dbSJohan Hovold 		qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL);
154394a407ccSDmitry Baryshkov 	} else {
1544a36032dbSJohan Hovold 		qmp->pcs_misc = devm_of_iomap(dev, np, 3, NULL);
154594a407ccSDmitry Baryshkov 	}
154694a407ccSDmitry Baryshkov 
1547a36032dbSJohan Hovold 	if (IS_ERR(qmp->pcs_misc))
154894a407ccSDmitry Baryshkov 		dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
154994a407ccSDmitry Baryshkov 
155094a407ccSDmitry Baryshkov 	return 0;
155194a407ccSDmitry Baryshkov }
155294a407ccSDmitry Baryshkov 
qmp_ufs_parse_dt(struct qmp_ufs * qmp)15530e089bb8SJohan Hovold static int qmp_ufs_parse_dt(struct qmp_ufs *qmp)
15540e089bb8SJohan Hovold {
15550e089bb8SJohan Hovold 	struct platform_device *pdev = to_platform_device(qmp->dev);
15560e089bb8SJohan Hovold 	const struct qmp_phy_cfg *cfg = qmp->cfg;
15570e089bb8SJohan Hovold 	const struct qmp_ufs_offsets *offs = cfg->offsets;
15580e089bb8SJohan Hovold 	void __iomem *base;
15590e089bb8SJohan Hovold 
15600e089bb8SJohan Hovold 	if (!offs)
15610e089bb8SJohan Hovold 		return -EINVAL;
15620e089bb8SJohan Hovold 
15630e089bb8SJohan Hovold 	base = devm_platform_ioremap_resource(pdev, 0);
15640e089bb8SJohan Hovold 	if (IS_ERR(base))
15650e089bb8SJohan Hovold 		return PTR_ERR(base);
15660e089bb8SJohan Hovold 
15670e089bb8SJohan Hovold 	qmp->serdes = base + offs->serdes;
15680e089bb8SJohan Hovold 	qmp->pcs = base + offs->pcs;
15690e089bb8SJohan Hovold 	qmp->tx = base + offs->tx;
15700e089bb8SJohan Hovold 	qmp->rx = base + offs->rx;
15710e089bb8SJohan Hovold 
15720e089bb8SJohan Hovold 	if (cfg->lanes >= 2) {
15730e089bb8SJohan Hovold 		qmp->tx2 = base + offs->tx2;
15740e089bb8SJohan Hovold 		qmp->rx2 = base + offs->rx2;
15750e089bb8SJohan Hovold 	}
15760e089bb8SJohan Hovold 
15770e089bb8SJohan Hovold 	return 0;
15780e089bb8SJohan Hovold }
15790e089bb8SJohan Hovold 
qmp_ufs_probe(struct platform_device * pdev)15804412817bSJohan Hovold static int qmp_ufs_probe(struct platform_device *pdev)
158194a407ccSDmitry Baryshkov {
158294a407ccSDmitry Baryshkov 	struct device *dev = &pdev->dev;
158394a407ccSDmitry Baryshkov 	struct phy_provider *phy_provider;
15840e089bb8SJohan Hovold 	struct device_node *np;
1585a36032dbSJohan Hovold 	struct qmp_ufs *qmp;
158694a407ccSDmitry Baryshkov 	int ret;
158794a407ccSDmitry Baryshkov 
158894a407ccSDmitry Baryshkov 	qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
158994a407ccSDmitry Baryshkov 	if (!qmp)
159094a407ccSDmitry Baryshkov 		return -ENOMEM;
159194a407ccSDmitry Baryshkov 
159294a407ccSDmitry Baryshkov 	qmp->dev = dev;
159394a407ccSDmitry Baryshkov 
1594018dfc99SJohan Hovold 	qmp->cfg = of_device_get_match_data(dev);
1595018dfc99SJohan Hovold 	if (!qmp->cfg)
159694a407ccSDmitry Baryshkov 		return -EINVAL;
159794a407ccSDmitry Baryshkov 
1598018dfc99SJohan Hovold 	ret = qmp_ufs_clk_init(qmp);
159994a407ccSDmitry Baryshkov 	if (ret)
160094a407ccSDmitry Baryshkov 		return ret;
160194a407ccSDmitry Baryshkov 
1602018dfc99SJohan Hovold 	ret = qmp_ufs_vreg_init(qmp);
16036d9b32fbSYuan Can 	if (ret)
160428d74fc3SJohan Hovold 		return ret;
160594a407ccSDmitry Baryshkov 
16060e089bb8SJohan Hovold 	/* Check for legacy binding with child node. */
16070e089bb8SJohan Hovold 	np = of_get_next_available_child(dev->of_node, NULL);
16080e089bb8SJohan Hovold 	if (np) {
16090e089bb8SJohan Hovold 		ret = qmp_ufs_parse_dt_legacy(qmp, np);
16100e089bb8SJohan Hovold 	} else {
16110e089bb8SJohan Hovold 		np = of_node_get(dev->of_node);
16120e089bb8SJohan Hovold 		ret = qmp_ufs_parse_dt(qmp);
16130e089bb8SJohan Hovold 	}
1614cb2c3d2eSJohan Hovold 	if (ret)
161594a407ccSDmitry Baryshkov 		goto err_node_put;
161694a407ccSDmitry Baryshkov 
16177bd7044fSDmitry Baryshkov 	ret = qmp_ufs_register_clocks(qmp, np);
16187bd7044fSDmitry Baryshkov 	if (ret)
16197bd7044fSDmitry Baryshkov 		goto err_node_put;
16207bd7044fSDmitry Baryshkov 
16210e089bb8SJohan Hovold 	qmp->phy = devm_phy_create(dev, np, &qcom_qmp_ufs_phy_ops);
1622c64d39b4SJohan Hovold 	if (IS_ERR(qmp->phy)) {
1623c64d39b4SJohan Hovold 		ret = PTR_ERR(qmp->phy);
1624c64d39b4SJohan Hovold 		dev_err(dev, "failed to create PHY: %d\n", ret);
1625c64d39b4SJohan Hovold 		goto err_node_put;
1626c64d39b4SJohan Hovold 	}
1627c64d39b4SJohan Hovold 
1628c64d39b4SJohan Hovold 	phy_set_drvdata(qmp->phy, qmp);
1629c64d39b4SJohan Hovold 
16300e089bb8SJohan Hovold 	of_node_put(np);
163194a407ccSDmitry Baryshkov 
163294a407ccSDmitry Baryshkov 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
163394a407ccSDmitry Baryshkov 
163494a407ccSDmitry Baryshkov 	return PTR_ERR_OR_ZERO(phy_provider);
163594a407ccSDmitry Baryshkov 
163694a407ccSDmitry Baryshkov err_node_put:
16370e089bb8SJohan Hovold 	of_node_put(np);
163894a407ccSDmitry Baryshkov 	return ret;
163994a407ccSDmitry Baryshkov }
164094a407ccSDmitry Baryshkov 
1641d907774eSJohan Hovold static const struct of_device_id qmp_ufs_of_match_table[] = {
1642d907774eSJohan Hovold 	{
1643d907774eSJohan Hovold 		.compatible = "qcom,msm8996-qmp-ufs-phy",
1644fcfcae3bSManivannan Sadhasivam 		.data = &msm8996_ufsphy_cfg,
1645d907774eSJohan Hovold 	}, {
1646d907774eSJohan Hovold 		.compatible = "qcom,msm8998-qmp-ufs-phy",
1647d907774eSJohan Hovold 		.data = &sdm845_ufsphy_cfg,
1648d907774eSJohan Hovold 	}, {
1649607c101fSBartosz Golaszewski 		.compatible = "qcom,sa8775p-qmp-ufs-phy",
1650607c101fSBartosz Golaszewski 		.data = &sa8775p_ufsphy_cfg,
1651607c101fSBartosz Golaszewski 	}, {
1652d907774eSJohan Hovold 		.compatible = "qcom,sc8180x-qmp-ufs-phy",
1653d907774eSJohan Hovold 		.data = &sm8150_ufsphy_cfg,
1654d907774eSJohan Hovold 	}, {
1655d907774eSJohan Hovold 		.compatible = "qcom,sc8280xp-qmp-ufs-phy",
16560e089bb8SJohan Hovold 		.data = &sc8280xp_ufsphy_cfg,
1657d907774eSJohan Hovold 	}, {
1658d907774eSJohan Hovold 		.compatible = "qcom,sdm845-qmp-ufs-phy",
1659d907774eSJohan Hovold 		.data = &sdm845_ufsphy_cfg,
1660d907774eSJohan Hovold 	}, {
1661d907774eSJohan Hovold 		.compatible = "qcom,sm6115-qmp-ufs-phy",
1662d907774eSJohan Hovold 		.data = &sm6115_ufsphy_cfg,
1663d907774eSJohan Hovold 	}, {
16649b9e29afSLux Aliaga 		.compatible = "qcom,sm6125-qmp-ufs-phy",
16659b9e29afSLux Aliaga 		.data = &sm6115_ufsphy_cfg,
16669b9e29afSLux Aliaga 	}, {
1667d907774eSJohan Hovold 		.compatible = "qcom,sm6350-qmp-ufs-phy",
1668d907774eSJohan Hovold 		.data = &sdm845_ufsphy_cfg,
1669d907774eSJohan Hovold 	}, {
1670868c2a6cSDavid Wronek 		.compatible = "qcom,sm7150-qmp-ufs-phy",
1671868c2a6cSDavid Wronek 		.data = &sm7150_ufsphy_cfg,
1672868c2a6cSDavid Wronek 	}, {
1673d907774eSJohan Hovold 		.compatible = "qcom,sm8150-qmp-ufs-phy",
1674d907774eSJohan Hovold 		.data = &sm8150_ufsphy_cfg,
1675d907774eSJohan Hovold 	}, {
1676d907774eSJohan Hovold 		.compatible = "qcom,sm8250-qmp-ufs-phy",
1677692b6551SManivannan Sadhasivam 		.data = &sm8250_ufsphy_cfg,
1678d907774eSJohan Hovold 	}, {
1679d907774eSJohan Hovold 		.compatible = "qcom,sm8350-qmp-ufs-phy",
1680d907774eSJohan Hovold 		.data = &sm8350_ufsphy_cfg,
1681d907774eSJohan Hovold 	}, {
1682d907774eSJohan Hovold 		.compatible = "qcom,sm8450-qmp-ufs-phy",
1683d907774eSJohan Hovold 		.data = &sm8450_ufsphy_cfg,
16841679bfefSAbel Vesa 	}, {
16851679bfefSAbel Vesa 		.compatible = "qcom,sm8550-qmp-ufs-phy",
16861679bfefSAbel Vesa 		.data = &sm8550_ufsphy_cfg,
1687d907774eSJohan Hovold 	},
1688d907774eSJohan Hovold 	{ },
1689d907774eSJohan Hovold };
1690d907774eSJohan Hovold MODULE_DEVICE_TABLE(of, qmp_ufs_of_match_table);
1691d907774eSJohan Hovold 
16924412817bSJohan Hovold static struct platform_driver qmp_ufs_driver = {
16934412817bSJohan Hovold 	.probe		= qmp_ufs_probe,
169494a407ccSDmitry Baryshkov 	.driver = {
16954846a79aSDmitry Baryshkov 		.name	= "qcom-qmp-ufs-phy",
16964412817bSJohan Hovold 		.of_match_table = qmp_ufs_of_match_table,
169794a407ccSDmitry Baryshkov 	},
169894a407ccSDmitry Baryshkov };
169994a407ccSDmitry Baryshkov 
17004412817bSJohan Hovold module_platform_driver(qmp_ufs_driver);
170194a407ccSDmitry Baryshkov 
170294a407ccSDmitry Baryshkov MODULE_AUTHOR("Vivek Gautam <vivek.gautam@codeaurora.org>");
17034846a79aSDmitry Baryshkov MODULE_DESCRIPTION("Qualcomm QMP UFS PHY driver");
170494a407ccSDmitry Baryshkov MODULE_LICENSE("GPL v2");
1705