2 * Copyright (c) 2013-2015, Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include "phy-qcom-ufs-qmp-14nm.h"
17 #define UFS_PHY_NAME "ufs_phy_qmp_14nm"
18 #define UFS_PHY_VDDA_PHY_UV (925000)
21 int ufs_qcom_phy_qmp_14nm_phy_calibrate(struct ufs_qcom_phy
*ufs_qcom_phy
,
24 int tbl_size_A
= ARRAY_SIZE(phy_cal_table_rate_A
);
25 int tbl_size_B
= ARRAY_SIZE(phy_cal_table_rate_B
);
28 err
= ufs_qcom_phy_calibrate(ufs_qcom_phy
, phy_cal_table_rate_A
,
29 tbl_size_A
, phy_cal_table_rate_B
, tbl_size_B
, is_rate_B
);
32 dev_err(ufs_qcom_phy
->dev
,
33 "%s: ufs_qcom_phy_calibrate() failed %d\n",
39 void ufs_qcom_phy_qmp_14nm_advertise_quirks(struct ufs_qcom_phy
*phy_common
)
42 UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE
;
46 int ufs_qcom_phy_qmp_14nm_set_mode(struct phy
*generic_phy
,
47 enum phy_mode mode
, int submode
)
49 struct ufs_qcom_phy
*phy_common
= get_ufs_qcom_phy(generic_phy
);
51 phy_common
->mode
= PHY_MODE_INVALID
;
54 phy_common
->mode
= mode
;
60 void ufs_qcom_phy_qmp_14nm_power_control(struct ufs_qcom_phy
*phy
, bool val
)
62 writel_relaxed(val
? 0x1 : 0x0, phy
->mmio
+ UFS_PHY_POWER_DOWN_CONTROL
);
64 * Before any transactions involving PHY, ensure PHY knows
65 * that it's analog rail is powered ON (or OFF).
71 void ufs_qcom_phy_qmp_14nm_set_tx_lane_enable(struct ufs_qcom_phy
*phy
, u32 val
)
74 * 14nm PHY does not have TX_LANE_ENABLE register.
75 * Implement this function so as not to propagate error to caller.
79 static inline void ufs_qcom_phy_qmp_14nm_start_serdes(struct ufs_qcom_phy
*phy
)
83 tmp
= readl_relaxed(phy
->mmio
+ UFS_PHY_PHY_START
);
84 tmp
&= ~MASK_SERDES_START
;
85 tmp
|= (1 << OFFSET_SERDES_START
);
86 writel_relaxed(tmp
, phy
->mmio
+ UFS_PHY_PHY_START
);
87 /* Ensure register value is committed */
91 static int ufs_qcom_phy_qmp_14nm_is_pcs_ready(struct ufs_qcom_phy
*phy_common
)
96 err
= readl_poll_timeout(phy_common
->mmio
+ UFS_PHY_PCS_READY_STATUS
,
97 val
, (val
& MASK_PCS_READY
), 10, 1000000);
99 dev_err(phy_common
->dev
, "%s: poll for pcs failed err = %d\n",
104 static const struct phy_ops ufs_qcom_phy_qmp_14nm_phy_ops
= {
105 .power_on
= ufs_qcom_phy_power_on
,
106 .power_off
= ufs_qcom_phy_power_off
,
107 .set_mode
= ufs_qcom_phy_qmp_14nm_set_mode
,
108 .owner
= THIS_MODULE
,
111 static struct ufs_qcom_phy_specific_ops phy_14nm_ops
= {
112 .calibrate
= ufs_qcom_phy_qmp_14nm_phy_calibrate
,
113 .start_serdes
= ufs_qcom_phy_qmp_14nm_start_serdes
,
114 .is_physical_coding_sublayer_ready
= ufs_qcom_phy_qmp_14nm_is_pcs_ready
,
115 .set_tx_lane_enable
= ufs_qcom_phy_qmp_14nm_set_tx_lane_enable
,
116 .power_control
= ufs_qcom_phy_qmp_14nm_power_control
,
119 static int ufs_qcom_phy_qmp_14nm_probe(struct platform_device
*pdev
)
121 struct device
*dev
= &pdev
->dev
;
122 struct phy
*generic_phy
;
123 struct ufs_qcom_phy_qmp_14nm
*phy
;
124 struct ufs_qcom_phy
*phy_common
;
127 phy
= devm_kzalloc(dev
, sizeof(*phy
), GFP_KERNEL
);
132 phy_common
= &phy
->common_cfg
;
134 generic_phy
= ufs_qcom_phy_generic_probe(pdev
, phy_common
,
135 &ufs_qcom_phy_qmp_14nm_phy_ops
, &phy_14nm_ops
);
142 err
= ufs_qcom_phy_init_clks(phy_common
);
146 err
= ufs_qcom_phy_init_vregulators(phy_common
);
150 phy_common
->vdda_phy
.max_uV
= UFS_PHY_VDDA_PHY_UV
;
151 phy_common
->vdda_phy
.min_uV
= UFS_PHY_VDDA_PHY_UV
;
153 ufs_qcom_phy_qmp_14nm_advertise_quirks(phy_common
);
155 phy_set_drvdata(generic_phy
, phy
);
157 strlcpy(phy_common
->name
, UFS_PHY_NAME
, sizeof(phy_common
->name
));
163 static const struct of_device_id ufs_qcom_phy_qmp_14nm_of_match
[] = {
164 {.compatible
= "qcom,ufs-phy-qmp-14nm"},
165 {.compatible
= "qcom,msm8996-ufs-phy-qmp-14nm"},
168 MODULE_DEVICE_TABLE(of
, ufs_qcom_phy_qmp_14nm_of_match
);
170 static struct platform_driver ufs_qcom_phy_qmp_14nm_driver
= {
171 .probe
= ufs_qcom_phy_qmp_14nm_probe
,
173 .of_match_table
= ufs_qcom_phy_qmp_14nm_of_match
,
174 .name
= "ufs_qcom_phy_qmp_14nm",
178 module_platform_driver(ufs_qcom_phy_qmp_14nm_driver
);
180 MODULE_DESCRIPTION("Universal Flash Storage (UFS) QCOM PHY QMP 14nm");
181 MODULE_LICENSE("GPL v2");