Skip to content

Commit

Permalink
ufs: use PM OPP when scaling gears
Browse files Browse the repository at this point in the history
Scaling gears requires not only scaling clocks, but also voltage levels,
e.g. via performance states.

Use the provided OPP table, to set proper OPP frequency which through
required-opps will trigger performance state change.  This deprecates
the old freq-table-hz Devicetree property and old clock scaling method
in favor of PM core code.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

---

Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
  • Loading branch information
krzk committed May 13, 2022
1 parent d7df0de commit 00fbe56
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 34 deletions.
73 changes: 73 additions & 0 deletions drivers/scsi/ufs/ufshcd-pltfrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_opp.h>
#include <linux/pm_runtime.h>
#include <linux/of.h>

Expand Down Expand Up @@ -108,6 +109,72 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
return ret;
}

static int ufshcd_parse_operating_points(struct ufs_hba *hba)
{
struct device *dev = hba->dev;
struct device_node *np = dev->of_node;
struct ufs_clk_info *clki;
const char *names[16];
int cnt, i, ret;

if (!of_find_property(dev->of_node, "operating-points-v2", NULL))
return 0;

cnt = of_property_count_strings(np, "clock-names");
if (cnt <= 0) {
dev_warn(dev, "%s: Missing clock-names\n",
__func__);
return -EINVAL;
}

if (cnt > ARRAY_SIZE(names)) {
dev_info(dev, "%s: Too many clock-names\n", __func__);
return -EINVAL;
}

if (of_find_property(np, "freq-table-hz", NULL)) {
dev_info(dev, "%s: operating-points and freq-table-hz are incompatible\n",
__func__);
return -EINVAL;
}

for (i = 0; i < cnt; i++) {
ret = of_property_read_string_index(np, "clock-names", i,
&names[i]);
if (ret)
return ret;

clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
if (!clki)
return -ENOMEM;

clki->name = devm_kstrdup(dev, names[i], GFP_KERNEL);
if (!clki->name)
return -ENOMEM;

if (!strcmp(names[i], "ref_clk"))
clki->keep_link_active = true;

list_add_tail(&clki->list, &hba->clk_list_head);
}

ret = devm_pm_opp_set_clknames(dev, names, i);
if (ret)
return ret;

ret = devm_pm_opp_register_set_opp_helper(dev, ufshcd_set_opp);
if (ret)
return ret;

ret = devm_pm_opp_of_add_table(dev);
if (ret)
return ret;

hba->use_pm_opp = true;

return 0;
}

#define MAX_PROP_SIZE 32
static int ufshcd_populate_vreg(struct device *dev, const char *name,
struct ufs_vreg **out_vreg)
Expand Down Expand Up @@ -363,6 +430,12 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
goto dealloc_host;
}

err = ufshcd_parse_operating_points(hba);
if (err) {
dev_err(dev, "%s: OPP parse failed %d\n", __func__, err);
goto dealloc_host;
}

ufshcd_init_lanes_per_dir(hba);

err = ufshcd_init(hba, mmio_base, irq);
Expand Down

0 comments on commit 00fbe56

Please sign in to comment.