Skip to content

Commit 77a6725

Browse files
Nitin Rawatmartinkpetersen
authored andcommitted
scsi: ufs: core: Store min and max clk freq from OPP table
OPP support added by commit 72208eb ("scsi: ufs: core: Add support for parsing OPP") doesn't update the min_freq and max_freq of each clock in 'struct ufs_clk_info'. But these values are used by the host drivers internally for controller configuration. When the OPP support is enabled in devicetree, these values will be 0, causing boot issues on the respective platforms. So add support to parse the min_freq and max_freq of all clocks while parsing the OPP table. Fixes: 72208eb ("scsi: ufs: core: Add support for parsing OPP") Co-developed-by: Manish Pandey <quic_mapa@quicinc.com> Signed-off-by: Manish Pandey <quic_mapa@quicinc.com> Signed-off-by: Nitin Rawat <quic_nitirawa@quicinc.com> Link: https://lore.kernel.org/r/20231208131331.12596-1-quic_nitirawa@quicinc.com Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent c5becf5 commit 77a6725

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

drivers/ufs/host/ufshcd-pltfrm.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Vinayak Holikatti <h.vinayak@samsung.com>
99
*/
1010

11+
#include <linux/clk.h>
1112
#include <linux/module.h>
1213
#include <linux/platform_device.h>
1314
#include <linux/pm_opp.h>
@@ -213,6 +214,55 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba)
213214
}
214215
}
215216

217+
/**
218+
* ufshcd_parse_clock_min_max_freq - Parse MIN and MAX clocks freq
219+
* @hba: per adapter instance
220+
*
221+
* This function parses MIN and MAX frequencies of all clocks required
222+
* by the host drivers.
223+
*
224+
* Returns 0 for success and non-zero for failure
225+
*/
226+
static int ufshcd_parse_clock_min_max_freq(struct ufs_hba *hba)
227+
{
228+
struct list_head *head = &hba->clk_list_head;
229+
struct ufs_clk_info *clki;
230+
struct dev_pm_opp *opp;
231+
unsigned long freq;
232+
u8 idx = 0;
233+
234+
list_for_each_entry(clki, head, list) {
235+
if (!clki->name)
236+
continue;
237+
238+
clki->clk = devm_clk_get(hba->dev, clki->name);
239+
if (IS_ERR(clki->clk))
240+
continue;
241+
242+
/* Find Max Freq */
243+
freq = ULONG_MAX;
244+
opp = dev_pm_opp_find_freq_floor_indexed(hba->dev, &freq, idx);
245+
if (IS_ERR(opp)) {
246+
dev_err(hba->dev, "Failed to find OPP for MAX frequency\n");
247+
return PTR_ERR(opp);
248+
}
249+
clki->max_freq = dev_pm_opp_get_freq_indexed(opp, idx);
250+
dev_pm_opp_put(opp);
251+
252+
/* Find Min Freq */
253+
freq = 0;
254+
opp = dev_pm_opp_find_freq_ceil_indexed(hba->dev, &freq, idx);
255+
if (IS_ERR(opp)) {
256+
dev_err(hba->dev, "Failed to find OPP for MIN frequency\n");
257+
return PTR_ERR(opp);
258+
}
259+
clki->min_freq = dev_pm_opp_get_freq_indexed(opp, idx++);
260+
dev_pm_opp_put(opp);
261+
}
262+
263+
return 0;
264+
}
265+
216266
static int ufshcd_parse_operating_points(struct ufs_hba *hba)
217267
{
218268
struct device *dev = hba->dev;
@@ -279,6 +329,10 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba)
279329
return ret;
280330
}
281331

332+
ret = ufshcd_parse_clock_min_max_freq(hba);
333+
if (ret)
334+
return ret;
335+
282336
hba->use_pm_opp = true;
283337

284338
return 0;

0 commit comments

Comments
 (0)