2018-07-16 11:24:32 +05:30
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-03-21 17:59:37 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/export.h>
|
2015-07-24 11:55:42 -07:00
|
|
|
#include <linux/module.h>
|
2014-03-21 17:59:37 -07:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/clk-provider.h>
|
2024-04-30 12:12:12 +05:30
|
|
|
#include <linux/interconnect-clk.h>
|
2025-05-30 18:50:50 +05:30
|
|
|
#include <linux/pm_runtime.h>
|
2014-03-21 17:59:37 -07:00
|
|
|
#include <linux/reset-controller.h>
|
2015-10-26 17:11:32 -07:00
|
|
|
#include <linux/of.h>
|
2014-03-21 17:59:37 -07:00
|
|
|
|
|
|
|
#include "common.h"
|
2025-05-30 18:50:51 +05:30
|
|
|
#include "clk-alpha-pll.h"
|
|
|
|
#include "clk-branch.h"
|
2014-09-04 13:21:50 -07:00
|
|
|
#include "clk-rcg.h"
|
2014-03-21 17:59:37 -07:00
|
|
|
#include "clk-regmap.h"
|
|
|
|
#include "reset.h"
|
2015-08-06 16:07:43 +05:30
|
|
|
#include "gdsc.h"
|
2014-03-21 17:59:37 -07:00
|
|
|
|
|
|
|
struct qcom_cc {
|
|
|
|
struct qcom_reset_controller reset;
|
2016-08-16 15:38:27 -07:00
|
|
|
struct clk_regmap **rclks;
|
|
|
|
size_t num_rclks;
|
2025-01-17 13:54:09 +00:00
|
|
|
struct dev_pm_domain_list *pd_list;
|
2014-03-21 17:59:37 -07:00
|
|
|
};
|
|
|
|
|
2014-09-04 13:21:50 -07:00
|
|
|
const
|
|
|
|
struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, unsigned long rate)
|
|
|
|
{
|
|
|
|
if (!f)
|
|
|
|
return NULL;
|
|
|
|
|
2019-10-31 11:57:15 -07:00
|
|
|
if (!f->freq)
|
|
|
|
return f;
|
|
|
|
|
2014-09-04 13:21:50 -07:00
|
|
|
for (; f->freq; f++)
|
|
|
|
if (rate <= f->freq)
|
|
|
|
return f;
|
|
|
|
|
|
|
|
/* Default to our fastest rate */
|
|
|
|
return f - 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_find_freq);
|
|
|
|
|
2023-12-20 23:17:23 +01:00
|
|
|
const struct freq_multi_tbl *qcom_find_freq_multi(const struct freq_multi_tbl *f,
|
|
|
|
unsigned long rate)
|
|
|
|
{
|
|
|
|
if (!f)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!f->freq)
|
|
|
|
return f;
|
|
|
|
|
|
|
|
for (; f->freq; f++)
|
|
|
|
if (rate <= f->freq)
|
|
|
|
return f;
|
|
|
|
|
|
|
|
/* Default to our fastest rate */
|
|
|
|
return f - 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_find_freq_multi);
|
|
|
|
|
2016-11-21 12:07:11 +05:30
|
|
|
const struct freq_tbl *qcom_find_freq_floor(const struct freq_tbl *f,
|
|
|
|
unsigned long rate)
|
|
|
|
{
|
|
|
|
const struct freq_tbl *best = NULL;
|
|
|
|
|
|
|
|
for ( ; f->freq; f++) {
|
|
|
|
if (rate >= f->freq)
|
|
|
|
best = f;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_find_freq_floor);
|
|
|
|
|
2015-03-20 18:30:26 +02:00
|
|
|
int qcom_find_src_index(struct clk_hw *hw, const struct parent_map *map, u8 src)
|
|
|
|
{
|
2015-06-25 16:53:23 -07:00
|
|
|
int i, num_parents = clk_hw_get_num_parents(hw);
|
2015-03-20 18:30:26 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_parents; i++)
|
|
|
|
if (src == map[i].src)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_find_src_index);
|
|
|
|
|
2021-11-16 02:34:07 +03:00
|
|
|
int qcom_find_cfg_index(struct clk_hw *hw, const struct parent_map *map, u8 cfg)
|
|
|
|
{
|
|
|
|
int i, num_parents = clk_hw_get_num_parents(hw);
|
|
|
|
|
|
|
|
for (i = 0; i < num_parents; i++)
|
|
|
|
if (cfg == map[i].cfg)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_find_cfg_index);
|
|
|
|
|
2014-07-15 14:59:21 -07:00
|
|
|
struct regmap *
|
|
|
|
qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc)
|
2014-03-21 17:59:37 -07:00
|
|
|
{
|
|
|
|
void __iomem *base;
|
2014-07-15 14:59:21 -07:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
|
2021-09-07 16:48:50 +08:00
|
|
|
base = devm_platform_ioremap_resource(pdev, 0);
|
2014-07-15 14:59:21 -07:00
|
|
|
if (IS_ERR(base))
|
|
|
|
return ERR_CAST(base);
|
|
|
|
|
|
|
|
return devm_regmap_init_mmio(dev, base, desc->config);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_map);
|
|
|
|
|
2016-09-29 14:05:45 +05:30
|
|
|
void
|
|
|
|
qcom_pll_set_fsm_mode(struct regmap *map, u32 reg, u8 bias_count, u8 lock_count)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
u32 mask;
|
|
|
|
|
|
|
|
/* De-assert reset to FSM */
|
|
|
|
regmap_update_bits(map, reg, PLL_VOTE_FSM_RESET, 0);
|
|
|
|
|
|
|
|
/* Program bias count and lock count */
|
|
|
|
val = bias_count << PLL_BIAS_COUNT_SHIFT |
|
|
|
|
lock_count << PLL_LOCK_COUNT_SHIFT;
|
|
|
|
mask = PLL_BIAS_COUNT_MASK << PLL_BIAS_COUNT_SHIFT;
|
|
|
|
mask |= PLL_LOCK_COUNT_MASK << PLL_LOCK_COUNT_SHIFT;
|
|
|
|
regmap_update_bits(map, reg, mask, val);
|
|
|
|
|
|
|
|
/* Enable PLL FSM voting */
|
|
|
|
regmap_update_bits(map, reg, PLL_VOTE_FSM_ENA, PLL_VOTE_FSM_ENA);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_pll_set_fsm_mode);
|
|
|
|
|
2015-10-07 23:59:57 -07:00
|
|
|
static void qcom_cc_gdsc_unregister(void *data)
|
|
|
|
{
|
|
|
|
gdsc_unregister(data);
|
|
|
|
}
|
|
|
|
|
2015-10-26 17:11:32 -07:00
|
|
|
/*
|
|
|
|
* Backwards compatibility with old DTs. Register a pass-through factor 1/1
|
2017-05-08 15:57:50 -07:00
|
|
|
* clock to translate 'path' clk into 'name' clk and register the 'path'
|
2015-10-26 17:11:32 -07:00
|
|
|
* clk as a fixed rate clock if it isn't present.
|
|
|
|
*/
|
|
|
|
static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
|
|
|
|
const char *name, unsigned long rate,
|
|
|
|
bool add_factor)
|
|
|
|
{
|
|
|
|
struct device_node *node = NULL;
|
|
|
|
struct device_node *clocks_node;
|
|
|
|
struct clk_fixed_factor *factor;
|
|
|
|
struct clk_fixed_rate *fixed;
|
|
|
|
struct clk_init_data init_data = { };
|
2016-08-16 15:38:27 -07:00
|
|
|
int ret;
|
2015-10-26 17:11:32 -07:00
|
|
|
|
|
|
|
clocks_node = of_find_node_by_path("/clocks");
|
2017-11-11 17:29:28 +01:00
|
|
|
if (clocks_node) {
|
|
|
|
node = of_get_child_by_name(clocks_node, path);
|
|
|
|
of_node_put(clocks_node);
|
|
|
|
}
|
2015-10-26 17:11:32 -07:00
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
fixed = devm_kzalloc(dev, sizeof(*fixed), GFP_KERNEL);
|
|
|
|
if (!fixed)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
fixed->fixed_rate = rate;
|
|
|
|
fixed->hw.init = &init_data;
|
|
|
|
|
|
|
|
init_data.name = path;
|
|
|
|
init_data.ops = &clk_fixed_rate_ops;
|
|
|
|
|
2016-08-16 15:38:27 -07:00
|
|
|
ret = devm_clk_hw_register(dev, &fixed->hw);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-10-26 17:11:32 -07:00
|
|
|
}
|
|
|
|
of_node_put(node);
|
|
|
|
|
|
|
|
if (add_factor) {
|
|
|
|
factor = devm_kzalloc(dev, sizeof(*factor), GFP_KERNEL);
|
|
|
|
if (!factor)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
factor->mult = factor->div = 1;
|
|
|
|
factor->hw.init = &init_data;
|
|
|
|
|
|
|
|
init_data.name = name;
|
|
|
|
init_data.parent_names = &path;
|
|
|
|
init_data.num_parents = 1;
|
|
|
|
init_data.flags = 0;
|
|
|
|
init_data.ops = &clk_fixed_factor_ops;
|
|
|
|
|
2016-08-16 15:38:27 -07:00
|
|
|
ret = devm_clk_hw_register(dev, &factor->hw);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-10-26 17:11:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qcom_cc_register_board_clk(struct device *dev, const char *path,
|
|
|
|
const char *name, unsigned long rate)
|
|
|
|
{
|
|
|
|
bool add_factor = true;
|
2016-11-02 17:56:58 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: The RPM clock driver currently does not support the xo clock.
|
|
|
|
* When xo is added to the RPM clock driver, we should change this
|
|
|
|
* function to skip registration of xo factor clocks.
|
|
|
|
*/
|
2015-10-26 17:11:32 -07:00
|
|
|
|
|
|
|
return _qcom_cc_register_board_clk(dev, path, name, rate, add_factor);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_register_board_clk);
|
|
|
|
|
|
|
|
int qcom_cc_register_sleep_clk(struct device *dev)
|
|
|
|
{
|
|
|
|
return _qcom_cc_register_board_clk(dev, "sleep_clk", "sleep_clk_src",
|
|
|
|
32768, true);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_register_sleep_clk);
|
|
|
|
|
2018-11-05 11:40:11 -08:00
|
|
|
/* Drop 'protected-clocks' from the list of clocks to register */
|
|
|
|
static void qcom_cc_drop_protected(struct device *dev, struct qcom_cc *cc)
|
|
|
|
{
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
u32 i;
|
|
|
|
|
of: remove internal arguments from of_property_for_each_u32()
The of_property_for_each_u32() macro needs five parameters, two of which
are primarily meant as internal variables for the macro itself (in the
for() clause). Yet these two parameters are used by a few drivers, and this
can be considered misuse or at least bad practice.
Now that the kernel uses C11 to build, these two parameters can be avoided
by declaring them internally, thus changing this pattern:
struct property *prop;
const __be32 *p;
u32 val;
of_property_for_each_u32(np, "xyz", prop, p, val) { ... }
to this:
u32 val;
of_property_for_each_u32(np, "xyz", val) { ... }
However two variables cannot be declared in the for clause even with C11,
so declare one struct that contain the two variables we actually need. As
the variables inside this struct are not meant to be used by users of this
macro, give the struct instance the noticeable name "_it" so it is visible
during code reviews, helping to avoid new code to use it directly.
Most usages are trivially converted as they do not use those two
parameters, as expected. The non-trivial cases are:
- drivers/clk/clk.c, of_clk_get_parent_name(): easily doable anyway
- drivers/clk/clk-si5351.c, si5351_dt_parse(): this is more complex as the
checks had to be replicated in a different way, making code more verbose
and somewhat uglier, but I refrained from a full rework to keep as much
of the original code untouched having no hardware to test my changes
All the changes have been build tested. The few for which I have the
hardware have been runtime-tested too.
Reviewed-by: Andre Przywara <andre.przywara@arm.com> # drivers/clk/sunxi/clk-simple-gates.c, drivers/clk/sunxi/clk-sun8i-bus-gates.c
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> # drivers/gpio/gpio-brcmstb.c
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com> # drivers/irqchip/irq-atmel-aic-common.c
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> # drivers/iio/adc/ti_am335x_adc.c
Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> # drivers/pwm/pwm-samsung.c
Acked-by: Richard Leitner <richard.leitner@linux.dev> # drivers/usb/misc/usb251xb.c
Acked-by: Mark Brown <broonie@kernel.org> # sound/soc/codecs/arizona.c
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com> # sound/soc/codecs/arizona.c
Acked-by: Michael Ellerman <mpe@ellerman.id.au> # arch/powerpc/sysdev/xive/spapr.c
Acked-by: Stephen Boyd <sboyd@kernel.org> # clk
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Acked-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/20240724-of_property_for_each_u32-v3-1-bea82ce429e2@bootlin.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2024-07-24 18:33:06 +02:00
|
|
|
of_property_for_each_u32(np, "protected-clocks", i) {
|
2018-11-05 11:40:11 -08:00
|
|
|
if (i >= cc->num_rclks)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cc->rclks[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 15:38:27 -07:00
|
|
|
static struct clk_hw *qcom_cc_clk_hw_get(struct of_phandle_args *clkspec,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct qcom_cc *cc = data;
|
|
|
|
unsigned int idx = clkspec->args[0];
|
|
|
|
|
|
|
|
if (idx >= cc->num_rclks) {
|
|
|
|
pr_err("%s: invalid index %u\n", __func__, idx);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:53:05 +05:30
|
|
|
return cc->rclks[idx] ? &cc->rclks[idx]->hw : NULL;
|
2016-08-16 15:38:27 -07:00
|
|
|
}
|
|
|
|
|
2024-04-30 12:12:12 +05:30
|
|
|
static int qcom_cc_icc_register(struct device *dev,
|
|
|
|
const struct qcom_cc_desc *desc)
|
|
|
|
{
|
|
|
|
struct icc_clk_data *icd;
|
|
|
|
struct clk_hw *hws;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_INTERCONNECT_CLK))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!desc->icc_hws)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
icd = devm_kcalloc(dev, desc->num_icc_hws, sizeof(*icd), GFP_KERNEL);
|
|
|
|
if (!icd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < desc->num_icc_hws; i++) {
|
|
|
|
icd[i].master_id = desc->icc_hws[i].master_id;
|
|
|
|
icd[i].slave_id = desc->icc_hws[i].slave_id;
|
|
|
|
hws = &desc->clks[desc->icc_hws[i].clk_id]->hw;
|
|
|
|
icd[i].clk = devm_clk_hw_get_clk(dev, hws, "icc");
|
|
|
|
if (!icd[i].clk)
|
|
|
|
return dev_err_probe(dev, -ENOENT,
|
|
|
|
"(%d) clock entry is null\n", i);
|
|
|
|
icd[i].name = clk_hw_get_name(hws);
|
|
|
|
}
|
|
|
|
|
|
|
|
return devm_icc_clk_register(dev, desc->icc_first_node_id,
|
|
|
|
desc->num_icc_hws, icd);
|
|
|
|
}
|
|
|
|
|
2025-05-30 18:50:51 +05:30
|
|
|
static int qcom_cc_clk_pll_configure(const struct qcom_cc_driver_data *data,
|
|
|
|
struct regmap *regmap)
|
|
|
|
{
|
|
|
|
const struct clk_init_data *init;
|
|
|
|
struct clk_alpha_pll *pll;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < data->num_alpha_plls; i++) {
|
|
|
|
pll = data->alpha_plls[i];
|
|
|
|
init = pll->clkr.hw.init;
|
|
|
|
|
|
|
|
if (!pll->config || !pll->regs) {
|
|
|
|
pr_err("%s: missing pll config or regs\n", init->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
qcom_clk_alpha_pll_configure(pll, regmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qcom_cc_clk_regs_configure(struct device *dev, const struct qcom_cc_driver_data *data,
|
|
|
|
struct regmap *regmap)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < data->num_clk_cbcrs; i++)
|
|
|
|
qcom_branch_set_clk_en(regmap, data->clk_cbcrs[i]);
|
|
|
|
|
|
|
|
if (data->clk_regs_configure)
|
|
|
|
data->clk_regs_configure(dev, regmap);
|
|
|
|
}
|
|
|
|
|
2024-06-05 20:45:40 +08:00
|
|
|
int qcom_cc_really_probe(struct device *dev,
|
2014-07-15 14:59:21 -07:00
|
|
|
const struct qcom_cc_desc *desc, struct regmap *regmap)
|
|
|
|
{
|
2014-03-21 17:59:37 -07:00
|
|
|
int i, ret;
|
|
|
|
struct qcom_reset_controller *reset;
|
|
|
|
struct qcom_cc *cc;
|
2015-12-01 21:42:11 +05:30
|
|
|
struct gdsc_desc *scd;
|
2014-03-21 17:59:37 -07:00
|
|
|
size_t num_clks = desc->num_clks;
|
|
|
|
struct clk_regmap **rclks = desc->clks;
|
2019-02-10 13:14:05 -07:00
|
|
|
size_t num_clk_hws = desc->num_clk_hws;
|
|
|
|
struct clk_hw **clk_hws = desc->clk_hws;
|
2014-03-21 17:59:37 -07:00
|
|
|
|
2016-08-16 15:38:27 -07:00
|
|
|
cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL);
|
2014-03-21 17:59:37 -07:00
|
|
|
if (!cc)
|
|
|
|
return -ENOMEM;
|
2025-01-17 13:54:09 +00:00
|
|
|
|
|
|
|
ret = devm_pm_domain_attach_list(dev, NULL, &cc->pd_list);
|
|
|
|
if (ret < 0 && ret != -EEXIST)
|
|
|
|
return ret;
|
2014-03-21 17:59:37 -07:00
|
|
|
|
2025-05-30 18:50:50 +05:30
|
|
|
if (desc->use_rpm) {
|
|
|
|
ret = devm_pm_runtime_enable(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = pm_runtime_resume_and_get(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2025-05-30 18:50:51 +05:30
|
|
|
if (desc->driver_data) {
|
|
|
|
ret = qcom_cc_clk_pll_configure(desc->driver_data, regmap);
|
|
|
|
if (ret)
|
|
|
|
goto put_rpm;
|
|
|
|
|
|
|
|
qcom_cc_clk_regs_configure(dev, desc->driver_data, regmap);
|
|
|
|
}
|
|
|
|
|
2014-03-21 17:59:37 -07:00
|
|
|
reset = &cc->reset;
|
|
|
|
reset->rcdev.of_node = dev->of_node;
|
|
|
|
reset->rcdev.ops = &qcom_reset_ops;
|
|
|
|
reset->rcdev.owner = dev->driver->owner;
|
|
|
|
reset->rcdev.nr_resets = desc->num_resets;
|
|
|
|
reset->regmap = regmap;
|
|
|
|
reset->reset_map = desc->resets;
|
|
|
|
|
2017-09-01 16:16:41 -07:00
|
|
|
ret = devm_reset_controller_register(dev, &reset->rcdev);
|
2015-12-23 17:57:20 +05:30
|
|
|
if (ret)
|
2025-05-30 18:50:50 +05:30
|
|
|
goto put_rpm;
|
2014-03-21 17:59:37 -07:00
|
|
|
|
2015-08-06 16:07:43 +05:30
|
|
|
if (desc->gdscs && desc->num_gdscs) {
|
2015-12-01 21:42:11 +05:30
|
|
|
scd = devm_kzalloc(dev, sizeof(*scd), GFP_KERNEL);
|
2025-05-30 18:50:50 +05:30
|
|
|
if (!scd) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto put_rpm;
|
|
|
|
}
|
2015-12-01 21:42:11 +05:30
|
|
|
scd->dev = dev;
|
|
|
|
scd->scs = desc->gdscs;
|
|
|
|
scd->num = desc->num_gdscs;
|
clk: qcom: Support attaching GDSCs to multiple parents
When a clock-controller lists multiple power-domains we need make each GDSC a
subdomain of each of the clock-controller's listed power-domains.
GDSCs without an explicitly defined parent should be a subdomain of each of
the clock-controller's listed power-domains.
GDSCs with an explicitly defined parent should attach only to the parent
GDSC and not the listed power-domains. Any votes will trickle through the
hierarchy up to the external power-domains.
========================================
:: arch/arm64/boot/dts/example.dtsi ::
========================================
clockcc: clock-controller@0 {
compat ="qcom,example-clockcc";
power-domains = <&pd_a, &pd_b>;
}
========================================
:: drivers/clk/qcom/example-clockcc.c ::
========================================
static struct gdsc parent_gdsc = {
.pd = {
.name = "parent_gdsc",
},
};
static struct gdsc child0_gdsc = {
.pd = {
.name = "child0_gdsc",
},
.parent = &parent_gdsc.pd,
};
static struct gdsc child1_gdsc = {
.pd = {
.name = "child1_gdsc",
},
.parent = &parent_gdsc.pd,
};
========================================
:: power-subdomains ::
========================================
pm-domain::pd_a
└── pm-subdomain::clockcc::parent_gdsc
├── pm-subdomain::clockcc::child0_gdsc
└── pm-subdomain::clockcc::child1_gdsc
pm-domain::pd_b
└── pm-subdomain::clockcc::parent_gdsc
├── pm-subdomain::clockcc::child1_gdsc
└── pm-subdomain::clockcc::child2_gdsc
The performance states will percolate through the pm-domain hierarchy to
the domains that handle the relevant states.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Link: https://lore.kernel.org/r/20250117-b4-linux-next-24-11-18-clock-multiple-power-domains-v10-4-13f2bb656dad@linaro.org
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
2025-01-17 13:54:10 +00:00
|
|
|
scd->pd_list = cc->pd_list;
|
2015-12-01 21:42:11 +05:30
|
|
|
ret = gdsc_register(scd, &reset->rcdev, regmap);
|
|
|
|
if (ret)
|
2025-05-30 18:50:50 +05:30
|
|
|
goto put_rpm;
|
2015-12-01 21:42:11 +05:30
|
|
|
ret = devm_add_action_or_reset(dev, qcom_cc_gdsc_unregister,
|
|
|
|
scd);
|
2015-08-06 16:07:43 +05:30
|
|
|
if (ret)
|
2025-05-30 18:50:50 +05:30
|
|
|
goto put_rpm;
|
2015-08-06 16:07:43 +05:30
|
|
|
}
|
|
|
|
|
2025-07-15 09:19:01 +02:00
|
|
|
if (desc->driver_data &&
|
|
|
|
desc->driver_data->dfs_rcgs &&
|
|
|
|
desc->driver_data->num_dfs_rcgs) {
|
|
|
|
ret = qcom_cc_register_rcg_dfs(regmap,
|
|
|
|
desc->driver_data->dfs_rcgs,
|
|
|
|
desc->driver_data->num_dfs_rcgs);
|
|
|
|
if (ret)
|
|
|
|
goto put_rpm;
|
|
|
|
}
|
|
|
|
|
2018-03-23 13:56:15 +05:30
|
|
|
cc->rclks = rclks;
|
|
|
|
cc->num_rclks = num_clks;
|
|
|
|
|
2018-11-05 11:40:11 -08:00
|
|
|
qcom_cc_drop_protected(dev, cc);
|
|
|
|
|
2019-02-10 13:14:05 -07:00
|
|
|
for (i = 0; i < num_clk_hws; i++) {
|
|
|
|
ret = devm_clk_hw_register(dev, clk_hws[i]);
|
|
|
|
if (ret)
|
2025-05-30 18:50:50 +05:30
|
|
|
goto put_rpm;
|
2019-02-10 13:14:05 -07:00
|
|
|
}
|
|
|
|
|
2018-03-23 13:56:15 +05:30
|
|
|
for (i = 0; i < num_clks; i++) {
|
|
|
|
if (!rclks[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = devm_clk_register_regmap(dev, rclks[i]);
|
|
|
|
if (ret)
|
2025-05-30 18:50:50 +05:30
|
|
|
goto put_rpm;
|
2018-03-23 13:56:15 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
ret = devm_of_clk_add_hw_provider(dev, qcom_cc_clk_hw_get, cc);
|
|
|
|
if (ret)
|
2025-05-30 18:50:50 +05:30
|
|
|
goto put_rpm;
|
|
|
|
|
|
|
|
ret = qcom_cc_icc_register(dev, desc);
|
|
|
|
|
|
|
|
put_rpm:
|
|
|
|
if (desc->use_rpm)
|
|
|
|
pm_runtime_put(dev);
|
2018-03-23 13:56:15 +05:30
|
|
|
|
2025-05-30 18:50:50 +05:30
|
|
|
return ret;
|
2014-03-21 17:59:37 -07:00
|
|
|
}
|
2014-07-15 14:59:21 -07:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_really_probe);
|
|
|
|
|
|
|
|
int qcom_cc_probe(struct platform_device *pdev, const struct qcom_cc_desc *desc)
|
|
|
|
{
|
|
|
|
struct regmap *regmap;
|
|
|
|
|
|
|
|
regmap = qcom_cc_map(pdev, desc);
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
|
2024-06-05 20:45:40 +08:00
|
|
|
return qcom_cc_really_probe(&pdev->dev, desc, regmap);
|
2014-07-15 14:59:21 -07:00
|
|
|
}
|
2014-03-21 17:59:37 -07:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_probe);
|
|
|
|
|
2019-07-26 14:53:28 +05:30
|
|
|
int qcom_cc_probe_by_index(struct platform_device *pdev, int index,
|
|
|
|
const struct qcom_cc_desc *desc)
|
|
|
|
{
|
|
|
|
struct regmap *regmap;
|
|
|
|
void __iomem *base;
|
|
|
|
|
2021-09-07 16:48:50 +08:00
|
|
|
base = devm_platform_ioremap_resource(pdev, index);
|
2019-07-26 14:53:28 +05:30
|
|
|
if (IS_ERR(base))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
regmap = devm_regmap_init_mmio(&pdev->dev, base, desc->config);
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
|
2024-06-05 20:45:40 +08:00
|
|
|
return qcom_cc_really_probe(&pdev->dev, desc, regmap);
|
2019-07-26 14:53:28 +05:30
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_probe_by_index);
|
|
|
|
|
2015-07-24 11:55:42 -07:00
|
|
|
MODULE_LICENSE("GPL v2");
|
2024-05-16 17:19:10 -07:00
|
|
|
MODULE_DESCRIPTION("QTI Common Clock module");
|