[PATCH 10/16] clk: qcom: krait-cc: drop hardcoded safe_sel

Ansuel Smith
2022-03-13T19:05:30Z

Drop hardcoded safe_sel definition and use helper to correctly calculate
it. We assume qsb clk is always present as it should be declared in DTS
per Documentation and in the absence of that, it's declared as a fixed
clk.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
drivers/clk/qcom/krait-cc.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/drivers/clk/qcom/krait-cc.c b/drivers/clk/qcom/krait-cc.c
index 50352ff0ac67..6530f10a546f 100644
--- a/drivers/clk/qcom/krait-cc.c
+++ b/drivers/clk/qcom/krait-cc.c
@@ -26,6 +26,13 @@ static unsigned int pri_mux_map[] = {
0,
};

+static u8 krait_get_mux_sel(struct krait_mux_clk *mux, struct clk *safe_clk)
+{
+ struct clk_hw *safe_hw = __clk_get_hw(safe_clk);
+
+ return clk_hw_get_parent_index(&mux->hw, safe_hw);
+}
+
/*
* Notifier function for switching the muxes to safe parent
* while the hfpll is getting reprogrammed.
@@ -117,8 +124,8 @@ krait_add_div(struct device *dev, int id, const char *s, unsigned int offset)
}

static struct clk *
-krait_add_sec_mux(struct device *dev, int id, const char *s,
- unsigned int offset, bool unique_aux)
+krait_add_sec_mux(struct device *dev, struct clk *qsb, int id,
+ const char *s, unsigned int offset, bool unique_aux)
{
static struct clk_parent_data sec_mux_list[2] = {
{ .name = "qsb", .fw_name = "qsb" },
@@ -145,7 +152,6 @@ krait_add_sec_mux(struct device *dev, int id, const char *s,
mux->shift = 2;
mux->parent_map = sec_mux_map;
mux->hw.init = &init;
- mux->safe_sel = 0;

init.name = kasprintf(GFP_KERNEL, "krait%s_sec_mux", s);
if (!init.name)
@@ -167,6 +173,7 @@ krait_add_sec_mux(struct device *dev, int id, const char *s,
if (IS_ERR(clk))
goto err_clk;

+ mux->safe_sel = krait_get_mux_sel(mux, qsb);
ret = krait_notifier_register(dev, clk, mux);
if (ret)
clk = ERR_PTR(ret);
@@ -205,7 +212,6 @@ krait_add_pri_mux(struct device *dev, struct clk *hfpll_div, struct clk *sec_mux
mux->lpl = id >= 0;
mux->parent_map = pri_mux_map;
mux->hw.init = &init;
- mux->safe_sel = 2;

init.name = kasprintf(GFP_KERNEL, "krait%s_pri_mux", s);
if (!init.name)
@@ -227,6 +233,7 @@ krait_add_pri_mux(struct device *dev, struct clk *hfpll_div, struct clk *sec_mux
if (IS_ERR(clk))
goto err_clk;

+ mux->safe_sel = krait_get_mux_sel(mux, sec_mux);
ret = krait_notifier_register(dev, clk, mux);
if (ret)
clk = ERR_PTR(ret);
@@ -239,7 +246,9 @@ krait_add_pri_mux(struct device *dev, struct clk *hfpll_div, struct clk *sec_mux
}

/* id < 0 for L2, otherwise id == physical CPU number */
-static struct clk *krait_add_clks(struct device *dev, int id, bool unique_aux)
+static struct clk *
+krait_add_clks(struct device *dev, struct clk *qsb, int id,
+ bool unique_aux)
{
struct clk *hfpll_div, *sec_mux, *clk;
unsigned int offset;
@@ -262,7 +271,7 @@ static struct clk *krait_add_clks(struct device *dev, int id, bool unique_aux)
goto err;
}

- sec_mux = krait_add_sec_mux(dev, id, s, offset, unique_aux);
+ sec_mux = krait_add_sec_mux(dev, qsb, id, s, offset, unique_aux);
if (IS_ERR(sec_mux)) {
clk = sec_mux;
goto err;
@@ -296,8 +305,8 @@ MODULE_DEVICE_TABLE(of, krait_cc_match_table);

static int krait_cc_probe(struct platform_device *pdev)
{
+ struct clk *l2_pri_mux_clk, *qsb, *clk;
unsigned long cur_rate, aux_rate;
- struct clk *l2_pri_mux_clk, *clk;
struct device *dev = &pdev->dev;
const struct of_device_id *id;
struct clk **clks;
@@ -308,11 +317,12 @@ static int krait_cc_probe(struct platform_device *pdev)
return -ENODEV;

/* Rate is 1 because 0 causes problems for __clk_mux_determine_rate */
- if (IS_ERR(clk_get(dev, "qsb")))
- clk = clk_register_fixed_rate(dev, "qsb", NULL, 0, 1);
+ qsb = clk_get(dev, "qsb");
+ if (IS_ERR(qsb))
+ qsb = clk_register_fixed_rate(dev, "qsb", NULL, 0, 1);

- if (IS_ERR(clk))
- return PTR_ERR(clk);
+ if (IS_ERR(qsb))
+ return PTR_ERR(qsb);

if (!id->data) {
clk = clk_register_fixed_factor(dev, "acpu_aux",
@@ -327,13 +337,13 @@ static int krait_cc_probe(struct platform_device *pdev)
return -ENOMEM;

for_each_possible_cpu(cpu) {
- clk = krait_add_clks(dev, cpu, id->data);
+ clk = krait_add_clks(dev, qsb, cpu, id->data);
if (IS_ERR(clk))
return PTR_ERR(clk);
clks[cpu] = clk;
}

- l2_pri_mux_clk = krait_add_clks(dev, -1, id->data);
+ l2_pri_mux_clk = krait_add_clks(dev, qsb, -1, id->data);
if (IS_ERR(l2_pri_mux_clk))
return PTR_ERR(l2_pri_mux_clk);
clks[4] = l2_pri_mux_clk;
--
2.34.1