Skip to content

Commit 9caef85

Browse files
Mani-Sadhasivammartinkpetersen
authored andcommitted
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: Andrew Halaney <ahalaney@redhat.com> Signed-off-by: Manivannan 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: Martin K. Petersen <martin.petersen@oracle.com>
1 parent b85ea95 commit 9caef85

2 files changed

Lines changed: 7 additions & 93 deletions

File tree

drivers/ufs/host/ufs-qcom.c

Lines changed: 5 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -194,96 +194,27 @@ static inline int ufs_qcom_ice_suspend(struct ufs_qcom_host *host)
194194
}
195195
#endif
196196

197-
static int ufs_qcom_host_clk_get(struct device *dev,
198-
const char *name, struct clk **clk_out, bool optional)
199-
{
200-
struct clk *clk;
201-
int err = 0;
202-
203-
clk = devm_clk_get(dev, name);
204-
if (!IS_ERR(clk)) {
205-
*clk_out = clk;
206-
return 0;
207-
}
208-
209-
err = PTR_ERR(clk);
210-
211-
if (optional && err == -ENOENT) {
212-
*clk_out = NULL;
213-
return 0;
214-
}
215-
216-
if (err != -EPROBE_DEFER)
217-
dev_err(dev, "failed to get %s err %d\n", name, err);
218-
219-
return err;
220-
}
221-
222-
static int ufs_qcom_host_clk_enable(struct device *dev,
223-
const char *name, struct clk *clk)
224-
{
225-
int err = 0;
226-
227-
err = clk_prepare_enable(clk);
228-
if (err)
229-
dev_err(dev, "%s: %s enable failed %d\n", __func__, name, err);
230-
231-
return err;
232-
}
233-
234197
static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host)
235198
{
236199
if (!host->is_lane_clks_enabled)
237200
return;
238201

239-
clk_disable_unprepare(host->tx_l1_sync_clk);
240-
clk_disable_unprepare(host->tx_l0_sync_clk);
241-
clk_disable_unprepare(host->rx_l1_sync_clk);
242-
clk_disable_unprepare(host->rx_l0_sync_clk);
202+
clk_bulk_disable_unprepare(host->num_clks, host->clks);
243203

244204
host->is_lane_clks_enabled = false;
245205
}
246206

247207
static int ufs_qcom_enable_lane_clks(struct ufs_qcom_host *host)
248208
{
249209
int err;
250-
struct device *dev = host->hba->dev;
251-
252-
if (host->is_lane_clks_enabled)
253-
return 0;
254210

255-
err = ufs_qcom_host_clk_enable(dev, "rx_lane0_sync_clk",
256-
host->rx_l0_sync_clk);
211+
err = clk_bulk_prepare_enable(host->num_clks, host->clks);
257212
if (err)
258213
return err;
259214

260-
err = ufs_qcom_host_clk_enable(dev, "tx_lane0_sync_clk",
261-
host->tx_l0_sync_clk);
262-
if (err)
263-
goto disable_rx_l0;
264-
265-
err = ufs_qcom_host_clk_enable(dev, "rx_lane1_sync_clk",
266-
host->rx_l1_sync_clk);
267-
if (err)
268-
goto disable_tx_l0;
269-
270-
err = ufs_qcom_host_clk_enable(dev, "tx_lane1_sync_clk",
271-
host->tx_l1_sync_clk);
272-
if (err)
273-
goto disable_rx_l1;
274-
275215
host->is_lane_clks_enabled = true;
276216

277217
return 0;
278-
279-
disable_rx_l1:
280-
clk_disable_unprepare(host->rx_l1_sync_clk);
281-
disable_tx_l0:
282-
clk_disable_unprepare(host->tx_l0_sync_clk);
283-
disable_rx_l0:
284-
clk_disable_unprepare(host->rx_l0_sync_clk);
285-
286-
return err;
287218
}
288219

289220
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)
294225
if (has_acpi_companion(dev))
295226
return 0;
296227

297-
err = ufs_qcom_host_clk_get(dev, "rx_lane0_sync_clk",
298-
&host->rx_l0_sync_clk, false);
299-
if (err)
300-
return err;
301-
302-
err = ufs_qcom_host_clk_get(dev, "tx_lane0_sync_clk",
303-
&host->tx_l0_sync_clk, false);
304-
if (err)
228+
err = devm_clk_bulk_get_all(dev, &host->clks);
229+
if (err <= 0)
305230
return err;
306231

307-
/* In case of single lane per direction, don't read lane1 clocks */
308-
if (host->hba->lanes_per_direction > 1) {
309-
err = ufs_qcom_host_clk_get(dev, "rx_lane1_sync_clk",
310-
&host->rx_l1_sync_clk, false);
311-
if (err)
312-
return err;
313-
314-
err = ufs_qcom_host_clk_get(dev, "tx_lane1_sync_clk",
315-
&host->tx_l1_sync_clk, true);
316-
}
232+
host->num_clks = err;
317233

318234
return 0;
319235
}

drivers/ufs/host/ufs-qcom.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,8 @@ struct ufs_qcom_host {
213213
struct phy *generic_phy;
214214
struct ufs_hba *hba;
215215
struct ufs_pa_layer_attr dev_req_params;
216-
struct clk *rx_l0_sync_clk;
217-
struct clk *tx_l0_sync_clk;
218-
struct clk *rx_l1_sync_clk;
219-
struct clk *tx_l1_sync_clk;
216+
struct clk_bulk_data *clks;
217+
u32 num_clks;
220218
bool is_lane_clks_enabled;
221219

222220
struct icc_path *icc_ddr;

0 commit comments

Comments
 (0)