mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-16 16:54:20 +08:00
Merge branch 'icc-cbf' into icc-next
On MSM8996 two CPU clusters are interconnected using the Core Bus Fabric (CBF). In order for the CPU clusters to function properly, it should be clocked following the core's frequencies to provide adequate bandwidth. Register CBF as a clock (required for CPU to boot) and add a tiny interconnect layer on top of it to let cpufreq/opp scale the CBF clock. * icc-cbf dt-bindings: interconnect/msm8996-cbf: add defines to be used by CBF interconnect: add clk-based icc provider support clk: qcom: cbf-msm8996: scale CBF clock according to the CPUfreq interconnect: icc-clk: fix modular build Link: https://lore.kernel.org/r/20230512001334.2983048-1-dmitry.baryshkov@linaro.org Signed-off-by: Georgi Djakov <djakov@kernel.org>
This commit is contained in:
commit
7f1ed4659b
@ -48,6 +48,7 @@ config QCOM_CLK_APCS_MSM8916
|
||||
config QCOM_CLK_APCC_MSM8996
|
||||
tristate "MSM8996 CPU Clock Controller"
|
||||
select QCOM_KRYO_L2_ACCESSORS
|
||||
select INTERCONNECT_CLK if INTERCONNECT
|
||||
depends on ARM64
|
||||
help
|
||||
Support for the CPU clock controller on msm8996 devices.
|
||||
|
@ -5,11 +5,15 @@
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/clk-provider.h>
|
||||
#include <linux/interconnect-clk.h>
|
||||
#include <linux/interconnect-provider.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
|
||||
#include <dt-bindings/interconnect/qcom,msm8996-cbf.h>
|
||||
|
||||
#include "clk-alpha-pll.h"
|
||||
#include "clk-regmap.h"
|
||||
|
||||
@ -223,6 +227,49 @@ static const struct regmap_config cbf_msm8996_regmap_config = {
|
||||
.val_format_endian = REGMAP_ENDIAN_LITTLE,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_INTERCONNECT
|
||||
|
||||
/* Random ID that doesn't clash with main qnoc and OSM */
|
||||
#define CBF_MASTER_NODE 2000
|
||||
|
||||
static int qcom_msm8996_cbf_icc_register(struct platform_device *pdev, struct clk_hw *cbf_hw)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct clk *clk = devm_clk_hw_get_clk(dev, cbf_hw, "cbf");
|
||||
const struct icc_clk_data data[] = {
|
||||
{ .clk = clk, .name = "cbf", },
|
||||
};
|
||||
struct icc_provider *provider;
|
||||
|
||||
provider = icc_clk_register(dev, CBF_MASTER_NODE, ARRAY_SIZE(data), data);
|
||||
if (IS_ERR(provider))
|
||||
return PTR_ERR(provider);
|
||||
|
||||
platform_set_drvdata(pdev, provider);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_msm8996_cbf_icc_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct icc_provider *provider = platform_get_drvdata(pdev);
|
||||
|
||||
icc_clk_unregister(provider);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#define qcom_msm8996_cbf_icc_sync_state icc_sync_state
|
||||
#else
|
||||
static int qcom_msm8996_cbf_icc_register(struct platform_device *pdev, struct clk_hw *cbf_hw)
|
||||
{
|
||||
dev_warn(&pdev->dev, "CONFIG_INTERCONNECT is disabled, CBF clock is fixed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#define qcom_msm8996_cbf_icc_remove(pdev) (0)
|
||||
#define qcom_msm8996_cbf_icc_sync_state NULL
|
||||
#endif
|
||||
|
||||
static int qcom_msm8996_cbf_probe(struct platform_device *pdev)
|
||||
{
|
||||
void __iomem *base;
|
||||
@ -281,7 +328,16 @@ static int qcom_msm8996_cbf_probe(struct platform_device *pdev)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &cbf_mux.clkr.hw);
|
||||
ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &cbf_mux.clkr.hw);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return qcom_msm8996_cbf_icc_register(pdev, &cbf_mux.clkr.hw);
|
||||
}
|
||||
|
||||
static int qcom_msm8996_cbf_remove(struct platform_device *pdev)
|
||||
{
|
||||
return qcom_msm8996_cbf_icc_remove(pdev);
|
||||
}
|
||||
|
||||
static const struct of_device_id qcom_msm8996_cbf_match_table[] = {
|
||||
@ -292,9 +348,11 @@ MODULE_DEVICE_TABLE(of, qcom_msm8996_cbf_match_table);
|
||||
|
||||
static struct platform_driver qcom_msm8996_cbf_driver = {
|
||||
.probe = qcom_msm8996_cbf_probe,
|
||||
.remove = qcom_msm8996_cbf_remove,
|
||||
.driver = {
|
||||
.name = "qcom-msm8996-cbf",
|
||||
.of_match_table = qcom_msm8996_cbf_match_table,
|
||||
.sync_state = qcom_msm8996_cbf_icc_sync_state,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -15,4 +15,10 @@ source "drivers/interconnect/imx/Kconfig"
|
||||
source "drivers/interconnect/qcom/Kconfig"
|
||||
source "drivers/interconnect/samsung/Kconfig"
|
||||
|
||||
config INTERCONNECT_CLK
|
||||
tristate
|
||||
depends on COMMON_CLK
|
||||
help
|
||||
Support for wrapping clocks into the interconnect nodes.
|
||||
|
||||
endif
|
||||
|
@ -7,3 +7,5 @@ obj-$(CONFIG_INTERCONNECT) += icc-core.o
|
||||
obj-$(CONFIG_INTERCONNECT_IMX) += imx/
|
||||
obj-$(CONFIG_INTERCONNECT_QCOM) += qcom/
|
||||
obj-$(CONFIG_INTERCONNECT_SAMSUNG) += samsung/
|
||||
|
||||
obj-$(CONFIG_INTERCONNECT_CLK) += icc-clk.o
|
||||
|
174
drivers/interconnect/icc-clk.c
Normal file
174
drivers/interconnect/icc-clk.c
Normal file
@ -0,0 +1,174 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 2023, Linaro Ltd.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/interconnect-clk.h>
|
||||
#include <linux/interconnect-provider.h>
|
||||
|
||||
struct icc_clk_node {
|
||||
struct clk *clk;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
struct icc_clk_provider {
|
||||
struct icc_provider provider;
|
||||
int num_clocks;
|
||||
struct icc_clk_node clocks[];
|
||||
};
|
||||
|
||||
#define to_icc_clk_provider(_provider) \
|
||||
container_of(_provider, struct icc_clk_provider, provider)
|
||||
|
||||
static int icc_clk_set(struct icc_node *src, struct icc_node *dst)
|
||||
{
|
||||
struct icc_clk_node *qn = src->data;
|
||||
int ret;
|
||||
|
||||
if (!qn || !qn->clk)
|
||||
return 0;
|
||||
|
||||
if (!src->peak_bw) {
|
||||
if (qn->enabled)
|
||||
clk_disable_unprepare(qn->clk);
|
||||
qn->enabled = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!qn->enabled) {
|
||||
ret = clk_prepare_enable(qn->clk);
|
||||
if (ret)
|
||||
return ret;
|
||||
qn->enabled = true;
|
||||
}
|
||||
|
||||
return clk_set_rate(qn->clk, icc_units_to_bps(src->peak_bw));
|
||||
}
|
||||
|
||||
static int icc_clk_get_bw(struct icc_node *node, u32 *avg, u32 *peak)
|
||||
{
|
||||
struct icc_clk_node *qn = node->data;
|
||||
|
||||
if (!qn || !qn->clk)
|
||||
*peak = INT_MAX;
|
||||
else
|
||||
*peak = Bps_to_icc(clk_get_rate(qn->clk));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* icc_clk_register() - register a new clk-based interconnect provider
|
||||
* @dev: device supporting this provider
|
||||
* @first_id: an ID of the first provider's node
|
||||
* @num_clocks: number of instances of struct icc_clk_data
|
||||
* @data: data for the provider
|
||||
*
|
||||
* Registers and returns a clk-based interconnect provider. It is a simple
|
||||
* wrapper around COMMON_CLK framework, allowing other devices to vote on the
|
||||
* clock rate.
|
||||
*
|
||||
* Return: 0 on success, or an error code otherwise
|
||||
*/
|
||||
struct icc_provider *icc_clk_register(struct device *dev,
|
||||
unsigned int first_id,
|
||||
unsigned int num_clocks,
|
||||
const struct icc_clk_data *data)
|
||||
{
|
||||
struct icc_clk_provider *qp;
|
||||
struct icc_provider *provider;
|
||||
struct icc_onecell_data *onecell;
|
||||
struct icc_node *node;
|
||||
int ret, i, j;
|
||||
|
||||
onecell = devm_kzalloc(dev, struct_size(onecell, nodes, 2 * num_clocks), GFP_KERNEL);
|
||||
if (!onecell)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
qp = devm_kzalloc(dev, struct_size(qp, clocks, num_clocks), GFP_KERNEL);
|
||||
if (!qp)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
qp->num_clocks = num_clocks;
|
||||
|
||||
provider = &qp->provider;
|
||||
provider->dev = dev;
|
||||
provider->get_bw = icc_clk_get_bw;
|
||||
provider->set = icc_clk_set;
|
||||
provider->aggregate = icc_std_aggregate;
|
||||
provider->xlate = of_icc_xlate_onecell;
|
||||
INIT_LIST_HEAD(&provider->nodes);
|
||||
provider->data = onecell;
|
||||
|
||||
icc_provider_init(provider);
|
||||
|
||||
for (i = 0, j = 0; i < num_clocks; i++) {
|
||||
qp->clocks[i].clk = data[i].clk;
|
||||
|
||||
node = icc_node_create(first_id + j);
|
||||
if (IS_ERR(node)) {
|
||||
ret = PTR_ERR(node);
|
||||
goto err;
|
||||
}
|
||||
|
||||
node->name = devm_kasprintf(dev, GFP_KERNEL, "%s_master", data[i].name);
|
||||
node->data = &qp->clocks[i];
|
||||
icc_node_add(node, provider);
|
||||
/* link to the next node, slave */
|
||||
icc_link_create(node, first_id + j + 1);
|
||||
onecell->nodes[j++] = node;
|
||||
|
||||
node = icc_node_create(first_id + j);
|
||||
if (IS_ERR(node)) {
|
||||
ret = PTR_ERR(node);
|
||||
goto err;
|
||||
}
|
||||
|
||||
node->name = devm_kasprintf(dev, GFP_KERNEL, "%s_slave", data[i].name);
|
||||
/* no data for slave node */
|
||||
icc_node_add(node, provider);
|
||||
onecell->nodes[j++] = node;
|
||||
}
|
||||
|
||||
onecell->num_nodes = j;
|
||||
|
||||
ret = icc_provider_register(provider);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
return provider;
|
||||
|
||||
err:
|
||||
icc_nodes_remove(provider);
|
||||
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(icc_clk_register);
|
||||
|
||||
/**
|
||||
* icc_clk_unregister() - unregister a previously registered clk interconnect provider
|
||||
* @provider: provider returned by icc_clk_register()
|
||||
*/
|
||||
void icc_clk_unregister(struct icc_provider *provider)
|
||||
{
|
||||
struct icc_clk_provider *qp = container_of(provider, struct icc_clk_provider, provider);
|
||||
int i;
|
||||
|
||||
icc_provider_deregister(&qp->provider);
|
||||
icc_nodes_remove(&qp->provider);
|
||||
|
||||
for (i = 0; i < qp->num_clocks; i++) {
|
||||
struct icc_clk_node *qn = &qp->clocks[i];
|
||||
|
||||
if (qn->enabled)
|
||||
clk_disable_unprepare(qn->clk);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(icc_clk_unregister);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Interconnect wrapper for clocks");
|
||||
MODULE_AUTHOR("Dmitry Baryshkov <dmitry.baryshkov@linaro.org>");
|
12
include/dt-bindings/interconnect/qcom,msm8996-cbf.h
Normal file
12
include/dt-bindings/interconnect/qcom,msm8996-cbf.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
|
||||
/*
|
||||
* Copyright (C) 2023 Linaro Ltd. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __DT_BINDINGS_INTERCONNECT_QCOM_MSM8996_CBF_H
|
||||
#define __DT_BINDINGS_INTERCONNECT_QCOM_MSM8996_CBF_H
|
||||
|
||||
#define MASTER_CBF_M4M 0
|
||||
#define SLAVE_CBF_M4M 1
|
||||
|
||||
#endif
|
22
include/linux/interconnect-clk.h
Normal file
22
include/linux/interconnect-clk.h
Normal file
@ -0,0 +1,22 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 2023, Linaro Ltd.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_INTERCONNECT_CLK_H
|
||||
#define __LINUX_INTERCONNECT_CLK_H
|
||||
|
||||
struct device;
|
||||
|
||||
struct icc_clk_data {
|
||||
struct clk *clk;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
struct icc_provider *icc_clk_register(struct device *dev,
|
||||
unsigned int first_id,
|
||||
unsigned int num_clocks,
|
||||
const struct icc_clk_data *data);
|
||||
void icc_clk_unregister(struct icc_provider *provider);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user