Commit 9caef856 authored by Manivannan Sadhasivam's avatar Manivannan Sadhasivam Committed by Martin K. Petersen

scsi: ufs: qcom: Use clk_bulk APIs for managing lane clocks

Lane clock handling can be simplified by using the clk_bulk APIs. So let's
make use of them. This also get's rid of the clock validation in the driver
as kernel should just rely on the firmware (DT/ACPI) to provide the clocks
required for proper functioning.
Reviewed-by: default avatarAndrew Halaney <ahalaney@redhat.com>
Signed-off-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20231208065902.11006-2-manivannan.sadhasivam@linaro.org
Tested-by: Andrew Halaney <ahalaney@redhat.com> # sa8775p-ride
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent b85ea95d
...@@ -194,52 +194,12 @@ static inline int ufs_qcom_ice_suspend(struct ufs_qcom_host *host) ...@@ -194,52 +194,12 @@ static inline int ufs_qcom_ice_suspend(struct ufs_qcom_host *host)
} }
#endif #endif
static int ufs_qcom_host_clk_get(struct device *dev,
const char *name, struct clk **clk_out, bool optional)
{
struct clk *clk;
int err = 0;
clk = devm_clk_get(dev, name);
if (!IS_ERR(clk)) {
*clk_out = clk;
return 0;
}
err = PTR_ERR(clk);
if (optional && err == -ENOENT) {
*clk_out = NULL;
return 0;
}
if (err != -EPROBE_DEFER)
dev_err(dev, "failed to get %s err %d\n", name, err);
return err;
}
static int ufs_qcom_host_clk_enable(struct device *dev,
const char *name, struct clk *clk)
{
int err = 0;
err = clk_prepare_enable(clk);
if (err)
dev_err(dev, "%s: %s enable failed %d\n", __func__, name, err);
return err;
}
static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host) static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host)
{ {
if (!host->is_lane_clks_enabled) if (!host->is_lane_clks_enabled)
return; return;
clk_disable_unprepare(host->tx_l1_sync_clk); clk_bulk_disable_unprepare(host->num_clks, host->clks);
clk_disable_unprepare(host->tx_l0_sync_clk);
clk_disable_unprepare(host->rx_l1_sync_clk);
clk_disable_unprepare(host->rx_l0_sync_clk);
host->is_lane_clks_enabled = false; host->is_lane_clks_enabled = false;
} }
...@@ -247,43 +207,14 @@ static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host) ...@@ -247,43 +207,14 @@ static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host)
static int ufs_qcom_enable_lane_clks(struct ufs_qcom_host *host) static int ufs_qcom_enable_lane_clks(struct ufs_qcom_host *host)
{ {
int err; int err;
struct device *dev = host->hba->dev;
if (host->is_lane_clks_enabled)
return 0;
err = ufs_qcom_host_clk_enable(dev, "rx_lane0_sync_clk", err = clk_bulk_prepare_enable(host->num_clks, host->clks);
host->rx_l0_sync_clk);
if (err) if (err)
return err; return err;
err = ufs_qcom_host_clk_enable(dev, "tx_lane0_sync_clk",
host->tx_l0_sync_clk);
if (err)
goto disable_rx_l0;
err = ufs_qcom_host_clk_enable(dev, "rx_lane1_sync_clk",
host->rx_l1_sync_clk);
if (err)
goto disable_tx_l0;
err = ufs_qcom_host_clk_enable(dev, "tx_lane1_sync_clk",
host->tx_l1_sync_clk);
if (err)
goto disable_rx_l1;
host->is_lane_clks_enabled = true; host->is_lane_clks_enabled = true;
return 0; return 0;
disable_rx_l1:
clk_disable_unprepare(host->rx_l1_sync_clk);
disable_tx_l0:
clk_disable_unprepare(host->tx_l0_sync_clk);
disable_rx_l0:
clk_disable_unprepare(host->rx_l0_sync_clk);
return err;
} }
static int ufs_qcom_init_lane_clks(struct ufs_qcom_host *host) static int ufs_qcom_init_lane_clks(struct ufs_qcom_host *host)
...@@ -294,26 +225,11 @@ static int ufs_qcom_init_lane_clks(struct ufs_qcom_host *host) ...@@ -294,26 +225,11 @@ static int ufs_qcom_init_lane_clks(struct ufs_qcom_host *host)
if (has_acpi_companion(dev)) if (has_acpi_companion(dev))
return 0; return 0;
err = ufs_qcom_host_clk_get(dev, "rx_lane0_sync_clk", err = devm_clk_bulk_get_all(dev, &host->clks);
&host->rx_l0_sync_clk, false); if (err <= 0)
if (err)
return err;
err = ufs_qcom_host_clk_get(dev, "tx_lane0_sync_clk",
&host->tx_l0_sync_clk, false);
if (err)
return err; return err;
/* In case of single lane per direction, don't read lane1 clocks */ host->num_clks = err;
if (host->hba->lanes_per_direction > 1) {
err = ufs_qcom_host_clk_get(dev, "rx_lane1_sync_clk",
&host->rx_l1_sync_clk, false);
if (err)
return err;
err = ufs_qcom_host_clk_get(dev, "tx_lane1_sync_clk",
&host->tx_l1_sync_clk, true);
}
return 0; return 0;
} }
......
...@@ -213,10 +213,8 @@ struct ufs_qcom_host { ...@@ -213,10 +213,8 @@ struct ufs_qcom_host {
struct phy *generic_phy; struct phy *generic_phy;
struct ufs_hba *hba; struct ufs_hba *hba;
struct ufs_pa_layer_attr dev_req_params; struct ufs_pa_layer_attr dev_req_params;
struct clk *rx_l0_sync_clk; struct clk_bulk_data *clks;
struct clk *tx_l0_sync_clk; u32 num_clks;
struct clk *rx_l1_sync_clk;
struct clk *tx_l1_sync_clk;
bool is_lane_clks_enabled; bool is_lane_clks_enabled;
struct icc_path *icc_ddr; struct icc_path *icc_ddr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment