qcom-ufs: phy/hcd: Refactor phy initialization code
v2 cover qcom-ufs: phy/hcd: Refactor phy initialization code
Refactoring the qcom-ufs phy and host controller code to move further towards the generic phy usage. Right now the qcom-ufs exports a bunch of APIs that are used by the host controller to initialize the phy.
With this patch series, we populate the phy_init() which was a no-op earlier. The host controller then calls the phy_init() at the designated place rather than doing it invariably in ufs_hcd_init().
As part of this series, we introduce phy modes for ufs phy. The M-PHY has two data rates defined for each generations (Gears) - Rate A and Rate B. These can serve as the two modes of ufs HS phy. Host controller can direct the phy to set the respective configurations based on the phy modes.
The patch-series has been tested with necessary dt patches on db820c.
Hi Kishon,
I shall be on vacation for the next week. Can you kindly consider picking this series for 4.15. Martin was good with last version of the patches[1], and Subhash has reviewed the patches of which he has given 'Reviewed-by' for [PATCH 4/5] , and I have addressed his comments for the last patch. I hope it's not too late for 4.15. Subhash, can you please consider giving your 'Reviewed-by' for the last patch if you find it good.
[1] https://lkml.org/lkml/2017/8/10/958
Vivek Gautam (5):
dt-bindings: phy: Add PHY_TYPE_UFS definition
phy: Add UFS PHY modes
phy: qcom-ufs: Add support to set phy mode scsi/ufs: qcom: Set phy mode based on the controllers HS MODE ufs/phy: qcom: Refactor to use phy_init call
drivers/phy/qualcomm/phy-qcom-ufs-i.h | 5 ++-- drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c | 29 +++++++++++++++++-- drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c | 29 +++++++++++++++++-- drivers/phy/qualcomm/phy-qcom-ufs.c | 42 ++++++++++------------------ drivers/scsi/ufs/ufs-qcom.c | 39 +++++++++++--------------- include/dt-bindings/phy/phy.h | 1 + include/linux/phy/phy-qcom-ufs.h | 3 -- include/linux/phy/phy.h | 2 ++ 8 files changed, 91 insertions(+), 59 deletions(-)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/5 dt-bindings: phy: Add PHY_TYPE_UFS definition
Add definition for UFS phy type.
---
Changes since v1:
- none.
include/dt-bindings/phy/phy.h | 1 + 1 file changed, 1 insertion(+)
include/dt-bindings/phy/phy.h +1 -0
@@ -15,5 +15,6 @@#define PHY_TYPE_PCIE 2#define PHY_TYPE_USB2 3#define PHY_TYPE_USB3 4 +#define PHY_TYPE_UFS 5#endif /* _DT_BINDINGS_PHY */
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/5 phy: Add UFS PHY modes
In reply to Vivek GautamUFS phy has two modes for each High speed generation. These modes are identified by two rates of operations - Rate A, and Rate B.
Add these UFS phy modes to phy framework.
---
Changes since v1:
- Rebased on linux-phy/next.
include/linux/phy/phy.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/phy/phy.h +2 -0
@@ -29,6 +29,8 @@ enum phy_mode {PHY_MODE_USB_OTG ,PHY_MODE_SGMII ,PHY_MODE_10GKR , +PHY_MODE_UFS_HS_A , + PHY_MODE_UFS_HS_B, };/**
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 3/5 phy: qcom-ufs: Add support to set phy mode
In reply to Vivek GautamAdding support to set desired UFS phy mode that can be set from the host controller.
---
Changes since v1:
- none.
drivers/phy/qualcomm/phy-qcom-ufs-i.h | 2 ++ drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c | 14 ++++++++++++++ drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+)
drivers/phy/qualcomm/phy-qcom-ufs-i.h +2 -0
@@ -115,6 +115,8 @@ struct ufs_qcom_phy {int cached_regs_table_size;bool is_powered_on;struct ufs_qcom_phy_specific_ops *phy_spec_ops; + +enum phy_mode mode; };/**
drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c +14 -0
@@ -53,6 +53,19 @@ static int ufs_qcom_phy_qmp_14nm_exit(struct phy *generic_phy) }static +int ufs_qcom_phy_qmp_14nm_set_mode (struct phy *generic_phy,enum phy_mode mode) +{ +struct ufs_qcom_phy *phy_common =get_ufs_qcom_phy (generic_phy); + + phy_common->mode =PHY_MODE_INVALID ; + +if (mode >0 ) + phy_common->mode = mode; + +return 0 ; +} + +static void ufs_qcom_phy_qmp_14nm_power_control (struct ufs_qcom_phy *phy,bool val) {writel_relaxed (val ?0x1 :0x0 , phy->mmio +UFS_PHY_POWER_DOWN_CONTROL );
@@ -102,6 +115,7 @@ static int ufs_qcom_phy_qmp_14nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) .exit = ufs_qcom_phy_qmp_14nm_exit, .power_on = ufs_qcom_phy_power_on, .power_off = ufs_qcom_phy_power_off, + .set_mode = ufs_qcom_phy_qmp_14nm_set_mode, .owner = THIS_MODULE, };
drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c +14 -0
@@ -72,6 +72,19 @@ static int ufs_qcom_phy_qmp_20nm_exit(struct phy *generic_phy) }static +int ufs_qcom_phy_qmp_20nm_set_mode (struct phy *generic_phy,enum phy_mode mode) +{ +struct ufs_qcom_phy *phy_common =get_ufs_qcom_phy (generic_phy); + + phy_common->mode =PHY_MODE_INVALID ; + +if (mode >0 ) + phy_common->mode = mode; + +return 0 ; +} + +static void ufs_qcom_phy_qmp_20nm_power_control (struct ufs_qcom_phy *phy,bool val) { bool hibern8_exit_after_pwr_collapse = phy->quirks &
@@ -160,6 +173,7 @@ static int ufs_qcom_phy_qmp_20nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) .exit = ufs_qcom_phy_qmp_20nm_exit, .power_on = ufs_qcom_phy_power_on, .power_off = ufs_qcom_phy_power_off, + .set_mode = ufs_qcom_phy_qmp_20nm_set_mode, .owner = THIS_MODULE, };
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 4/5 scsi/ufs: qcom: Set phy mode based on the controllers HS MODE
In reply to Vivek GautamSet the phy mode based on the UFS HS PA mode. This lets the controller let phy know the mode in which the PHY Adapter is running and set the phy rates accordingly.
---
Changes since v1:
- none.
drivers/scsi/ufs/ufs-qcom.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/ufs/ufs-qcom.c +3 -0
@@ -273,6 +273,9 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba)bool is_rate_B = (UFS_QCOM_LIMIT_HS_RATE ==PA_HS_MODE_B ) ? true : false; +if (is_rate_B) +phy_set_mode (phy,PHY_MODE_UFS_HS_B ); +/* Assert PHY reset and apply PHY calibration values */ ufs_qcom_assert_reset (hba);/* provide 1ms delay to let the reset pulse propagate */
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 5/5 ufs/phy: qcom: Refactor to use phy_init call
In reply to Vivek GautamRefactor ufs_qcom_power_up_sequence() to get rid of ugly exported phy APIs and use the phy_init() and phy_power_on() to do the phy initialization.
---
Changes since v1:
- The UFS phy retain state in low power mode. The phy can enter the low power state and come up without starting the serdes again, unless we reprogram the phy.
So, added a check to start the serdes only once after phy initialization.
drivers/phy/qualcomm/phy-qcom-ufs-i.h | 3 +- drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c | 15 ++++++++-- drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c | 15 ++++++++-- drivers/phy/qualcomm/phy-qcom-ufs.c | 42 ++++++++++------------------ drivers/scsi/ufs/ufs-qcom.c | 36 ++++++++++-------------- include/linux/phy/phy-qcom-ufs.h | 3 -- 6 files changed, 55 insertions(+), 59 deletions(-)
drivers/phy/qualcomm/phy-qcom-ufs-i.h +1 -2
@@ -114,6 +114,7 @@ struct ufs_qcom_phy {struct ufs_qcom_phy_calibration *cached_regs;int cached_regs_table_size;bool is_powered_on; +bool is_started;struct ufs_qcom_phy_specific_ops *phy_spec_ops;enum phy_mode mode;
@@ -123,7 +124,6 @@ struct ufs_qcom_phy {* struct ufs_qcom_phy_specific_ops - set of pointers to functions which have a * specific implementation per phy. Each UFS phy, should implement * those functions according to its spec and requirements -* @calibrate_phy: pointer to a function that calibrate the phy * @start_serdes: pointer to a function that starts the serdes * @is_physical_coding_sublayer_ready: pointer to a function that * checks pcs readiness. returns 0 for success and non-zero for error.
@@ -132,7 +132,6 @@ struct ufs_qcom_phy {* and writes to QSERDES_RX_SIGDET_CNTRL attribute */ struct ufs_qcom_phy_specific_ops { -int (*calibrate_phy)(struct ufs_qcom_phy *phy,bool is_rate_B);void (*start_serdes)(struct ufs_qcom_phy *phy);int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy);void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy,u32 val);
drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c +13 -2
@@ -44,7 +44,19 @@ void ufs_qcom_phy_qmp_14nm_advertise_quirks(struct ufs_qcom_phy *phy_common)static int ufs_qcom_phy_qmp_14nm_init (struct phy *generic_phy) { -return 0 ; +struct ufs_qcom_phy *phy_common =get_ufs_qcom_phy (generic_phy); +bool is_rate_B = false; +int ret; + +if (phy_common->mode ==PHY_MODE_UFS_HS_B ) + is_rate_B = true; + + ret =ufs_qcom_phy_qmp_14nm_phy_calibrate (phy_common, is_rate_B); +if (!ret) +/* phy calibrated, but yet to be started */ + phy_common->is_started = false; + +return ret; }static int ufs_qcom_phy_qmp_14nm_exit (struct phy *generic_phy)
@@ -120,7 +132,6 @@ static int ufs_qcom_phy_qmp_14nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) };static struct ufs_qcom_phy_specific_ops phy_14nm_ops = { - .calibrate_phy = ufs_qcom_phy_qmp_14nm_phy_calibrate, .start_serdes = ufs_qcom_phy_qmp_14nm_start_serdes, .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_14nm_is_pcs_ready, .set_tx_lane_enable = ufs_qcom_phy_qmp_14nm_set_tx_lane_enable,
drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c +13 -2
@@ -63,7 +63,19 @@ void ufs_qcom_phy_qmp_20nm_advertise_quirks(struct ufs_qcom_phy *phy_common)static int ufs_qcom_phy_qmp_20nm_init (struct phy *generic_phy) { -return 0 ; +struct ufs_qcom_phy *phy_common =get_ufs_qcom_phy (generic_phy); +bool is_rate_B = false; +int ret; + +if (phy_common->mode ==PHY_MODE_UFS_HS_B ) + is_rate_B = true; + + ret =ufs_qcom_phy_qmp_20nm_phy_calibrate (phy_common, is_rate_B); +if (!ret) +/* phy calibrated, but yet to be started */ + phy_common->is_started = false; + +return ret; }static int ufs_qcom_phy_qmp_20nm_exit (struct phy *generic_phy)
@@ -178,7 +190,6 @@ static int ufs_qcom_phy_qmp_20nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) };static struct ufs_qcom_phy_specific_ops phy_20nm_ops = { - .calibrate_phy = ufs_qcom_phy_qmp_20nm_phy_calibrate, .start_serdes = ufs_qcom_phy_qmp_20nm_start_serdes, .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_20nm_is_pcs_ready, .set_tx_lane_enable = ufs_qcom_phy_qmp_20nm_set_tx_lane_enable,
drivers/phy/qualcomm/phy-qcom-ufs.c +14 -28
74 lines not on this page · raw message
drivers/scsi/ufs/ufs-qcom.c +14 -22
@@ -281,10 +281,10 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba)/* provide 1ms delay to let the reset pulse propagate */ usleep_range (1000 ,1100 ); - ret =ufs_qcom_phy_calibrate_phy (phy, is_rate_B); - +/* phy initialization - calibrate the phy */ + ret =phy_init (phy);if (ret) { -dev_err (hba->dev,"%s: ufs_qcom_phy_calibrate_phy() failed, ret = %d\n" , +dev_err (hba->dev,"%s: phy init failed, ret = %d\n" , __func__, ret); goto out; }
@@ -297,21 +297,22 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba)* voltage, current to settle down before starting serdes. */ usleep_range (1000 ,1100 ); - ret =ufs_qcom_phy_start_serdes (phy); + +/* power on phy - start serdes and phy's power and clocks */ + ret =phy_power_on (phy);if (ret) { -dev_err (hba->dev,"%s: ufs_qcom_phy_start_serdes() failed, ret = %d\n" , +dev_err (hba->dev,"%s: phy power on failed, ret = %d\n" , __func__, ret); - goto out; + goto out_disable_phy; } - ret =ufs_qcom_phy_is_pcs_ready (phy); -if (ret) -dev_err (hba->dev, -"%s: is_physical_coding_sublayer_ready() failed, ret = %d\n" , - __func__, ret); -ufs_qcom_select_unipro_mode (host); +return 0 ; + +out_disable_phy: +ufs_qcom_assert_reset (hba); +phy_exit (phy); out:return ret; }
@@ -1276,14 +1277,9 @@ static int ufs_qcom_init(struct ufs_hba *hba)ufs_qcom_phy_save_controller_version (host->generic_phy, host->hw_ver.major, host->hw_ver.minor, host->hw_ver.step); -phy_init (host->generic_phy); - err =phy_power_on (host->generic_phy); -if (err) - goto out_unregister_bus; - err =ufs_qcom_init_lane_clks (host);if (err) - goto out_disable_phy; + goto out_variant_clear;ufs_qcom_set_caps (hba);ufs_qcom_advertise_quirks (hba);
@@ -1304,10 +1300,6 @@ static int ufs_qcom_init(struct ufs_hba *hba) goto out; -out_disable_phy: -phy_power_off (host->generic_phy); -out_unregister_bus: -phy_exit (host->generic_phy); out_variant_clear:ufshcd_set_variant (hba,NULL ); out:
include/linux/phy/phy-qcom-ufs.h +0 -3
@@ -31,10 +31,7 @@*/ void ufs_qcom_phy_disable_dev_ref_clk (struct phy *phy); -int ufs_qcom_phy_start_serdes (struct phy *phy);int ufs_qcom_phy_set_tx_lane_enable (struct phy *phy,u32 tx_lanes); -int ufs_qcom_phy_calibrate_phy (struct phy *phy,bool is_rate_B); -int ufs_qcom_phy_is_pcs_ready (struct phy *phy);void ufs_qcom_phy_save_controller_version (struct phy *phy,u8 major,u16 minor,u16 step);
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH v2 5/5] ufs/phy: qcom: Refactor to use phy_init call
Quoted 308 lines · Vivek Gautam
Refactor
ufs_qcom_power_up_sequence()to get rid of ugly exported phy APIs and use thephy_init()andphy_power_on()to do the phy initialization.Signed-off-by Vivek Gautam <[email protected]>---
Changes since v1:
- The UFS phy retain state in low power mode. The phy can enter the low power state and come up without starting the serdes again, unless we reprogram the phy.
So, added a check to start the serdes only once after phy initialization.drivers/phy/qualcomm/phy-qcom-ufs-i.h | 3 +- drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c | 15 ++++++++-- drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c | 15 ++++++++-- drivers/phy/qualcomm/phy-qcom-ufs.c | 42 ++++++++++------------------ drivers/scsi/ufs/ufs-qcom.c | 36 ++++++++++-------------- include/linux/phy/phy-qcom-ufs.h | 3 -- 6 files changed, 55 insertions(+), 59 deletions(-)drivers/phy/qualcomm/phy-qcom-ufs-i.h +1
-0@@ -114,6 +114,7 @@ struct ufs_qcom_phy {struct ufs_qcom_phy_calibration *cached_regs;int cached_regs_table_size;bool is_powered_on; +bool is_started;struct ufs_qcom_phy_specific_ops *phy_spec_ops;enum phy_mode mode;@@ -123,7 +124,6 @@ struct ufs_qcom_phy {* struct ufs_qcom_phy_specific_ops - set of pointers to functions which have a
* specific implementation per phy. Each UFS phy, should implement
* those functions according to its spec and requirements
- * @calibrate_phy: pointer to a function that calibrate the phy
* @start_serdes: pointer to a function that starts the serdes
* @is_physical_coding_sublayer_ready: pointer to a function that
* checks pcs readiness. returns 0 for success and non-zero for error.drivers/phy/qualcomm/phy-qcom-ufs-i.h +0
-1@@ -132,7 +132,6 @@ struct ufs_qcom_phy {* and writes to QSERDES_RX_SIGDET_CNTRL attribute */ struct ufs_qcom_phy_specific_ops { -int (*calibrate_phy)(struct ufs_qcom_phy *phy,bool is_rate_B);void (*start_serdes)(struct ufs_qcom_phy *phy);int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy);void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy,u32 val);drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c +13
-1@@ -44,7 +44,19 @@ void ufs_qcom_phy_qmp_14nm_advertise_quirks(struct ufs_qcom_phy *phy_common)static int ufs_qcom_phy_qmp_14nm_init (struct phy *generic_phy) { -return 0 ; +struct ufs_qcom_phy *phy_common =get_ufs_qcom_phy (generic_phy); +bool is_rate_B = false; +int ret; + +if (phy_common->mode ==PHY_MODE_UFS_HS_B ) + is_rate_B = true; + + ret =ufs_qcom_phy_qmp_14nm_phy_calibrate (phy_common, is_rate_B); +if (!ret) +/* phy calibrated, but yet to be started */ + phy_common->is_started = false; + +return ret; }static int
ufs_qcom_phy_qmp_14nm_exit(struct phy *generic_phy)drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c +0
-1@@ -120,7 +132,6 @@ static int ufs_qcom_phy_qmp_14nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) };static struct ufs_qcom_phy_specific_ops phy_14nm_ops = { - .calibrate_phy = ufs_qcom_phy_qmp_14nm_phy_calibrate, .start_serdes = ufs_qcom_phy_qmp_14nm_start_serdes, .is_physical_coding_sublayer_ready =
ufs_qcom_phy_qmp_14nm_is_pcs_ready,drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c +0
-0.set_tx_lane_enable = ufs_qcom_phy_qmp_14nm_set_tx_lane_enable,drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c +13
-1@@ -63,7 +63,19 @@ void ufs_qcom_phy_qmp_20nm_advertise_quirks(struct ufs_qcom_phy *phy_common)static int ufs_qcom_phy_qmp_20nm_init (struct phy *generic_phy) { -return 0 ; +struct ufs_qcom_phy *phy_common =get_ufs_qcom_phy (generic_phy); +bool is_rate_B = false; +int ret; + +if (phy_common->mode ==PHY_MODE_UFS_HS_B ) + is_rate_B = true; + + ret =ufs_qcom_phy_qmp_20nm_phy_calibrate (phy_common, is_rate_B); +if (!ret) +/* phy calibrated, but yet to be started */ + phy_common->is_started = false; + +return ret; }static int
ufs_qcom_phy_qmp_20nm_exit(struct phy *generic_phy)drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c +0
-1@@ -178,7 +190,6 @@ static int ufs_qcom_phy_qmp_20nm_is_pcs_ready(struct ufs_qcom_phy *phy_common) };static struct ufs_qcom_phy_specific_ops phy_20nm_ops = { - .calibrate_phy = ufs_qcom_phy_qmp_20nm_phy_calibrate, .start_serdes = ufs_qcom_phy_qmp_20nm_start_serdes, .is_physical_coding_sublayer_ready =
ufs_qcom_phy_qmp_20nm_is_pcs_ready,drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c +0
-0.set_tx_lane_enable = ufs_qcom_phy_qmp_20nm_set_tx_lane_enable,drivers/phy/qualcomm/phy-qcom-ufs.c +1
-2@@ -518,9 +518,8 @@ void ufs_qcom_phy_disable_iface_clk(struct ufs_qcom_phy *phy) } } -int ufs_qcom_phy_start_serdes (struct phy *generic_phy) +static int ufs_qcom_phy_start_serdes (struct ufs_qcom_phy *ufs_qcom_phy) { -struct ufs_qcom_phy *ufs_qcom_phy =get_ufs_qcom_phy (generic_phy);int ret =0 ;drivers/phy/qualcomm/phy-qcom-ufs.c +0
-1if (!ufs_qcom_phy->phy_spec_ops->start_serdes) {@@ -533,7 +532,6 @@ int ufs_qcom_phy_start_serdes(struct phy *generic_phy)return ret; } -EXPORT_SYMBOL_GPL (ufs_qcom_phy_start_serdes); int ufs_qcom_phy_set_tx_lane_enable(struct phy *generic_phy, u32
tx_lanes)
{drivers/phy/qualcomm/phy-qcom-ufs.c +1
-24@@ -564,31 +562,8 @@ void ufs_qcom_phy_save_controller_version(structphy *generic_phy, }EXPORT_SYMBOL_GPL (ufs_qcom_phy_save_controller_version ); -int ufs_qcom_phy_calibrate_phy (struct phy *generic_phy,bool is_rate_B) -{ -struct ufs_qcom_phy *ufs_qcom_phy =get_ufs_qcom_phy (generic_phy); -int ret =0 ; - -if (!ufs_qcom_phy->phy_spec_ops->calibrate_phy) { -dev_err (ufs_qcom_phy->dev,"%s: calibrate_phy() callback is not supported\n", - __func__); - ret = -ENOTSUPP ; - }else { - ret = ufs_qcom_phy->phy_spec_ops-> -calibrate_phy (ufs_qcom_phy, is_rate_B); -if (ret) -dev_err (ufs_qcom_phy->dev,"%s: calibrate_phy() failed %d\n" , - __func__, ret); - } - -return ret; -} -EXPORT_SYMBOL_GPL (ufs_qcom_phy_calibrate_phy); - -int ufs_qcom_phy_is_pcs_ready (struct phy *generic_phy) +static int ufs_qcom_phy_is_pcs_ready(struct ufs_qcom_phy *ufs_qcom_phy) { -struct ufs_qcom_phy *ufs_qcom_phy =get_ufs_qcom_phy (generic_phy); -if (!ufs_qcom_phy->phy_spec_ops->is_physical_coding_sublayer_ready) { dev_err(ufs_qcom_phy->dev, "%s: is_physical_coding_sublayer_ready()callback is not supported\n",
drivers/phy/qualcomm/phy-qcom-ufs.c +0
-1__func__);@@ -598,7 +573,6 @@ int ufs_qcom_phy_is_pcs_ready(struct phy *generic_phy)return ufs_qcom_phy->phy_spec_ops->is_physical_coding_sublayer_ready (ufs_qcom_phy); } -EXPORT_SYMBOL_GPL (ufs_qcom_phy_is_pcs_ready);int ufs_qcom_phy_power_on (struct phy *generic_phy){
drivers/phy/qualcomm/phy-qcom-ufs.c +12
-0@@ -609,6 +583,18 @@ int ufs_qcom_phy_power_on(struct phy *generic_phy)if (phy_common->is_powered_on)return 0 ; +if (!phy_common->is_started) { + err =ufs_qcom_phy_start_serdes (phy_common); +if (err) +return err; + + err =ufs_qcom_phy_is_pcs_ready (phy_common); +if (err) +return err; + + phy_common->is_started = true; + } + err =ufs_qcom_phy_enable_vreg (dev, &phy_common->vdda_phy);if (err) { dev_err(dev, "%s enable vdda_phy failed, err=%d\n",drivers/scsi/ufs/ufs-qcom.c +3
-3@@ -281,10 +281,10 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba)/* provide 1ms delay to let the reset pulse propagate */ usleep_range(1000, 1100); - ret =ufs_qcom_phy_calibrate_phy (phy, is_rate_B); - +/* phy initialization - calibrate the phy */ + ret =phy_init (phy);if (ret) { - dev_err(hba->dev, "%s: ufs_qcom_phy_calibrate_phy() failed, ret = %d\n", + dev_err(hba->dev, "%s: phy init failed, ret = %d\n", __func__, ret);drivers/scsi/ufs/ufs-qcom.c +10
-9goto out; }@@ -297,21 +297,22 @@ static int ufs_qcom_power_up_sequence(structufs_hba *hba) * voltage, current to settle down before starting serdes. */ usleep_range (1000 ,1100 ); - ret =ufs_qcom_phy_start_serdes (phy); + +/* power on phy - start serdes and phy's power and clocks */ + ret =phy_power_on (phy);if (ret) { - dev_err(hba->dev, "%s: ufs_qcom_phy_start_serdes() failed, ret = %d\n", + dev_err(hba->dev, "%s: phy power on failed, ret = %d\n", __func__, ret); - goto out; + goto out_disable_phy; } - ret =ufs_qcom_phy_is_pcs_ready (phy); -if (ret) -dev_err (hba->dev, -"%s: is_physical_coding_sublayer_ready() failed, ret = %d\n" , - __func__, ret); -ufs_qcom_select_unipro_mode (host); +return 0 ; + +out_disable_phy: +ufs_qcom_assert_reset (hba); +phy_exit (phy); out:drivers/scsi/ufs/ufs-qcom.c +1
-10return ret; }@@ -1276,14 +1277,9 @@ static int ufs_qcom_init(struct ufs_hba *hba)ufs_qcom_phy_save_controller_version (host->generic_phy, host->hw_ver.major, host->hw_ver.minor, host->hw_ver.step); -phy_init (host->generic_phy); - err =phy_power_on (host->generic_phy); -if (err) - goto out_unregister_bus; - err =ufs_qcom_init_lane_clks (host);if (err) - goto out_disable_phy; + goto out_variant_clear;ufs_qcom_set_caps (hba);ufs_qcom_advertise_quirks (hba);@@ -1304,10 +1300,6 @@ static int ufs_qcom_init(struct ufs_hba *hba) goto out; -out_disable_phy: -phy_power_off (host->generic_phy); -out_unregister_bus: -phy_exit (host->generic_phy); out_variant_clear:ufshcd_set_variant (hba,NULL ); out:include/linux/phy/phy-qcom-ufs.h +0
-0
include/linux/phy/phy-qcom-ufs.h line 36
Quoted 9 lines
include/linux/phy/phy-qcom-ufs.h +0
-3@@ -31,10 +31,7 @@*/ void ufs_qcom_phy_disable_dev_ref_clk (struct phy *phy); -int ufs_qcom_phy_start_serdes (struct phy *phy);int ufs_qcom_phy_set_tx_lane_enable (struct phy *phy,u32 tx_lanes); -int ufs_qcom_phy_calibrate_phy (struct phy *phy,bool is_rate_B); -int ufs_qcom_phy_is_pcs_ready (struct phy *phy);void ufs_qcom_phy_save_controller_version (struct phy *phy,u8 major,u16 minor,u16 step);
Looks good to me.
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Kishon Vijay Abraham I
AppliedQuoted 19 lines · Vivek Gautam
Refactoring the qcom-ufs phy and host controller code to move further towards the generic phy usage. Right now the qcom-ufs exports a bunch of APIs that are used by the host controller to initialize the phy.
With this patch series, we populate thephy_init()which was a no-op earlier. The host controller then calls thephy_init()at the designated place rather than doing it invariably inufs_hcd_init().As part of this series, we introduce phy modes for ufs phy. The M-PHY has two data rates defined for each generations (Gears) - Rate A and Rate B. These can serve as the two modes of ufs HS phy. Host controller can direct the phy to set the respective configurations based on the phy modes.
The patch-series has been tested with necessary dt patches on db820c.
Hi Kishon,
Quoted 7 lines
I shall be on vacation for the next week. Can you kindly consider picking this series for 4.15. Martin was good with last version of the patches[1], and Subhash has reviewed the patches of which he has given 'Reviewed-by' for [PATCH 4/5] , and I have addressed his comments for the last patch. I hope it's not too late for 4.15. Subhash, can you please consider giving your 'Reviewed-by' for the last patch if you find it good.
merged to phy -next, thanks!
-Kishon
Quoted 20 lines
[1] https://lkml.org/lkml/2017/8/10/958
Vivek Gautam (5):
dt-bindings: phy: AddPHY_TYPE_UFSdefinition
phy: Add UFS PHY modes
phy: qcom-ufs: Add support to set phy mode scsi/ufs: qcom: Set phy mode based on the controllers HS MODE ufs/phy: qcom: Refactor to usephy_initcalldrivers/phy/qualcomm/phy-qcom-ufs-i.h | 5 ++-- drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c | 29 +++++++++++++++++-- drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c | 29 +++++++++++++++++-- drivers/phy/qualcomm/phy-qcom-ufs.c | 42 ++++++++++------------------ drivers/scsi/ufs/ufs-qcom.c | 39 +++++++++++--------------- include/dt-bindings/phy/phy.h | 1 + include/linux/phy/phy-qcom-ufs.h | 3 -- include/linux/phy/phy.h | 2 ++ 8 files changed, 91 insertions(+), 59 deletions(-)