Skip to content

Commit b452937

Browse files
AngeloGioacchino Del RegnoGeorgi Djakov
authored andcommitted
interconnect: mediatek: Add MediaTek MT8183/8195 EMI Interconnect driver
Add an interconnect driver for the External Memory Interface (EMI), voting for bus bandwidth over the Dynamic Voltage and Frequency Scaling Resource Collector (DVFSRC). ICC provider ICC Nodes ---- ---- --------- |CPU | |--- |VPU | ----- | |----- ---- | ---- |DRAM |--|DRAM | ---- | ---- | |--|scheduler|----- |GPU | |--- |DISP| | |--|(EMI) | ---- | ---- | |--| | ----- | ---- ----- | |----- |MMSYS|--|--- |VDEC| --------- ----- | ---- /|\ | ---- |change DRAM freq |--- |VENC| ---------- | ---- | DVFSR | | | | | ---- ---------- |--- |IMG | | ---- | ---- |--- |CAM | ---- Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Georgi Djakov <[email protected]>
1 parent 1a8009e commit b452937

File tree

8 files changed

+711
-0
lines changed

8 files changed

+711
-0
lines changed

drivers/interconnect/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ menuconfig INTERCONNECT
1212
if INTERCONNECT
1313

1414
source "drivers/interconnect/imx/Kconfig"
15+
source "drivers/interconnect/mediatek/Kconfig"
1516
source "drivers/interconnect/qcom/Kconfig"
1617
source "drivers/interconnect/samsung/Kconfig"
1718

drivers/interconnect/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ icc-core-objs := core.o bulk.o debugfs-client.o
55

66
obj-$(CONFIG_INTERCONNECT) += icc-core.o
77
obj-$(CONFIG_INTERCONNECT_IMX) += imx/
8+
obj-$(CONFIG_INTERCONNECT_MTK) += mediatek/
89
obj-$(CONFIG_INTERCONNECT_QCOM) += qcom/
910
obj-$(CONFIG_INTERCONNECT_SAMSUNG) += samsung/
1011

drivers/interconnect/mediatek/Kconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
config INTERCONNECT_MTK
4+
bool "MediaTek interconnect drivers"
5+
depends on ARCH_MEDIATEK || COMPILE_TEST
6+
help
7+
Support for MediaTek's bus interconnect hardware.
8+
9+
config INTERCONNECT_MTK_DVFSRC_EMI
10+
tristate "MediaTek DVFSRC EMI interconnect driver"
11+
depends on INTERCONNECT_MTK && MTK_DVFSRC
12+
help
13+
This is a driver for the MediaTek External Memory Interface
14+
interconnect on SoCs equipped with the integrated Dynamic
15+
Voltage Frequency Scaling Resource Collector (DVFSRC) MCU
16+
17+
config INTERCONNECT_MTK_MT8183
18+
tristate "MediaTek MT8183 interconnect driver"
19+
depends on INTERCONNECT_MTK_DVFSRC_EMI
20+
help
21+
This is a driver for the MediaTek bus interconnect on MT8183-based
22+
platforms.
23+
24+
config INTERCONNECT_MTK_MT8195
25+
tristate "MediaTek MT8195 interconnect driver"
26+
depends on INTERCONNECT_MTK_DVFSRC_EMI
27+
help
28+
This is a driver for the MediaTek bus interconnect on MT8195-based
29+
platforms.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
obj-$(CONFIG_INTERCONNECT_MTK_DVFSRC_EMI) += icc-emi.o
4+
obj-$(CONFIG_INTERCONNECT_MTK_MT8183) += mt8183.o
5+
obj-$(CONFIG_INTERCONNECT_MTK_MT8195) += mt8195.o
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* MediaTek External Memory Interface (EMI) Interconnect driver
4+
*
5+
* Copyright (c) 2021 MediaTek Inc.
6+
* Copyright (c) 2024 Collabora Ltd.
7+
* AngeloGioacchino Del Regno <[email protected]>
8+
*/
9+
10+
#include <linux/interconnect.h>
11+
#include <linux/interconnect-provider.h>
12+
#include <linux/module.h>
13+
#include <linux/of.h>
14+
#include <linux/of_platform.h>
15+
#include <linux/platform_device.h>
16+
#include <linux/soc/mediatek/dvfsrc.h>
17+
18+
#include "icc-emi.h"
19+
20+
static int mtk_emi_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
21+
u32 peak_bw, u32 *agg_avg, u32 *agg_peak)
22+
{
23+
struct mtk_icc_node *in = node->data;
24+
25+
*agg_avg += avg_bw;
26+
*agg_peak = max_t(u32, *agg_peak, peak_bw);
27+
28+
in->sum_avg = *agg_avg;
29+
in->max_peak = *agg_peak;
30+
31+
return 0;
32+
}
33+
34+
static int mtk_emi_icc_set(struct icc_node *src, struct icc_node *dst)
35+
{
36+
struct mtk_icc_node *node = dst->data;
37+
struct device *dev;
38+
int ret;
39+
40+
if (unlikely(!src->provider))
41+
return -EINVAL;
42+
43+
dev = src->provider->dev;
44+
45+
switch (node->ep) {
46+
case 0:
47+
break;
48+
case 1:
49+
ret = mtk_dvfsrc_send_request(dev, MTK_DVFSRC_CMD_PEAK_BW, node->max_peak);
50+
if (ret) {
51+
dev_err(dev, "Cannot send peak bw request: %d\n", ret);
52+
return ret;
53+
}
54+
55+
ret = mtk_dvfsrc_send_request(dev, MTK_DVFSRC_CMD_BW, node->sum_avg);
56+
if (ret) {
57+
dev_err(dev, "Cannot send bw request: %d\n", ret);
58+
return ret;
59+
}
60+
break;
61+
case 2:
62+
ret = mtk_dvfsrc_send_request(dev, MTK_DVFSRC_CMD_HRT_BW, node->sum_avg);
63+
if (ret) {
64+
dev_err(dev, "Cannot send HRT bw request: %d\n", ret);
65+
return ret;
66+
}
67+
break;
68+
default:
69+
dev_err(src->provider->dev, "Unknown endpoint %u\n", node->ep);
70+
return -EINVAL;
71+
};
72+
73+
return 0;
74+
}
75+
76+
int mtk_emi_icc_probe(struct platform_device *pdev)
77+
{
78+
const struct mtk_icc_desc *desc;
79+
struct device *dev = &pdev->dev;
80+
struct icc_node *node;
81+
struct icc_onecell_data *data;
82+
struct icc_provider *provider;
83+
struct mtk_icc_node **mnodes;
84+
int i, j, ret;
85+
86+
desc = of_device_get_match_data(dev);
87+
if (!desc)
88+
return -EINVAL;
89+
90+
mnodes = desc->nodes;
91+
92+
provider = devm_kzalloc(dev, sizeof(*provider), GFP_KERNEL);
93+
if (!provider)
94+
return -ENOMEM;
95+
96+
data = devm_kzalloc(dev, struct_size(data, nodes, desc->num_nodes), GFP_KERNEL);
97+
if (!data)
98+
return -ENOMEM;
99+
100+
provider->dev = pdev->dev.parent;
101+
provider->set = mtk_emi_icc_set;
102+
provider->aggregate = mtk_emi_icc_aggregate;
103+
provider->xlate = of_icc_xlate_onecell;
104+
INIT_LIST_HEAD(&provider->nodes);
105+
provider->data = data;
106+
107+
for (i = 0; i < desc->num_nodes; i++) {
108+
if (!mnodes[i])
109+
continue;
110+
111+
node = icc_node_create(mnodes[i]->id);
112+
if (IS_ERR(node)) {
113+
ret = PTR_ERR(node);
114+
goto err;
115+
}
116+
117+
node->name = mnodes[i]->name;
118+
node->data = mnodes[i];
119+
icc_node_add(node, provider);
120+
121+
for (j = 0; j < mnodes[i]->num_links; j++)
122+
icc_link_create(node, mnodes[i]->links[j]);
123+
124+
data->nodes[i] = node;
125+
}
126+
data->num_nodes = desc->num_nodes;
127+
128+
ret = icc_provider_register(provider);
129+
if (ret)
130+
goto err;
131+
132+
platform_set_drvdata(pdev, provider);
133+
134+
return 0;
135+
err:
136+
icc_nodes_remove(provider);
137+
return ret;
138+
}
139+
EXPORT_SYMBOL_GPL(mtk_emi_icc_probe);
140+
141+
void mtk_emi_icc_remove(struct platform_device *pdev)
142+
{
143+
struct icc_provider *provider = platform_get_drvdata(pdev);
144+
145+
icc_provider_deregister(provider);
146+
icc_nodes_remove(provider);
147+
}
148+
EXPORT_SYMBOL_GPL(mtk_emi_icc_remove);
149+
150+
MODULE_AUTHOR("AngeloGioacchino Del Regno <[email protected]>");
151+
MODULE_AUTHOR("Henry Chen <[email protected]>");
152+
MODULE_DESCRIPTION("MediaTek External Memory Interface interconnect driver");
153+
MODULE_LICENSE("GPL");
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (c) 2021 MediaTek Inc.
4+
* Copyright (c) 2024 Collabora Ltd.
5+
* AngeloGioacchino Del Regno <[email protected]>
6+
*/
7+
8+
#ifndef __DRIVERS_INTERCONNECT_MEDIATEK_ICC_EMI_H
9+
#define __DRIVERS_INTERCONNECT_MEDIATEK_ICC_EMI_H
10+
11+
/**
12+
* struct mtk_icc_node - Mediatek EMI Interconnect Node
13+
* @name: The interconnect node name which is shown in debugfs
14+
* @ep: Type of this endpoint
15+
* @id: Unique node identifier
16+
* @sum_avg: Current sum aggregate value of all average bw requests in kBps
17+
* @max_peak: Current max aggregate value of all peak bw requests in kBps
18+
* @num_links: The total number of @links
19+
* @links: Array of @id linked to this node
20+
*/
21+
struct mtk_icc_node {
22+
unsigned char *name;
23+
int ep;
24+
u16 id;
25+
u64 sum_avg;
26+
u64 max_peak;
27+
28+
u16 num_links;
29+
u16 links[] __counted_by(num_links);
30+
};
31+
32+
struct mtk_icc_desc {
33+
struct mtk_icc_node **nodes;
34+
size_t num_nodes;
35+
};
36+
37+
int mtk_emi_icc_probe(struct platform_device *pdev);
38+
void mtk_emi_icc_remove(struct platform_device *pdev);
39+
40+
#endif /* __DRIVERS_INTERCONNECT_MEDIATEK_ICC_EMI_H */
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2021 MediaTek Inc.
4+
* Copyright (c) 2024 Collabora Ltd.
5+
* AngeloGioacchino Del Regno <[email protected]>
6+
*/
7+
8+
#include <linux/device.h>
9+
#include <linux/interconnect.h>
10+
#include <linux/interconnect-provider.h>
11+
#include <linux/mod_devicetable.h>
12+
#include <linux/module.h>
13+
#include <linux/platform_device.h>
14+
#include <dt-bindings/interconnect/mediatek,mt8183.h>
15+
16+
#include "icc-emi.h"
17+
18+
static struct mtk_icc_node ddr_emi = {
19+
.name = "ddr-emi",
20+
.id = SLAVE_DDR_EMI,
21+
.ep = 1,
22+
};
23+
24+
static struct mtk_icc_node mcusys = {
25+
.name = "mcusys",
26+
.id = MASTER_MCUSYS,
27+
.ep = 0,
28+
.num_links = 1,
29+
.links = { SLAVE_DDR_EMI }
30+
};
31+
32+
static struct mtk_icc_node gpu = {
33+
.name = "gpu",
34+
.id = MASTER_MFG,
35+
.ep = 0,
36+
.num_links = 1,
37+
.links = { SLAVE_DDR_EMI }
38+
};
39+
40+
static struct mtk_icc_node mmsys = {
41+
.name = "mmsys",
42+
.id = MASTER_MMSYS,
43+
.ep = 0,
44+
.num_links = 1,
45+
.links = { SLAVE_DDR_EMI }
46+
};
47+
48+
static struct mtk_icc_node mm_vpu = {
49+
.name = "mm-vpu",
50+
.id = MASTER_MM_VPU,
51+
.ep = 0,
52+
.num_links = 1,
53+
.links = { MASTER_MMSYS }
54+
};
55+
56+
static struct mtk_icc_node mm_disp = {
57+
.name = "mm-disp",
58+
.id = MASTER_MM_DISP,
59+
.ep = 0,
60+
.num_links = 1,
61+
.links = { MASTER_MMSYS }
62+
};
63+
64+
static struct mtk_icc_node mm_vdec = {
65+
.name = "mm-vdec",
66+
.id = MASTER_MM_VDEC,
67+
.ep = 0,
68+
.num_links = 1,
69+
.links = { MASTER_MMSYS }
70+
};
71+
72+
static struct mtk_icc_node mm_venc = {
73+
.name = "mm-venc",
74+
.id = MASTER_MM_VENC,
75+
.ep = 0,
76+
.num_links = 1,
77+
.links = { MASTER_MMSYS }
78+
};
79+
80+
static struct mtk_icc_node mm_cam = {
81+
.name = "mm-cam",
82+
.id = MASTER_MM_CAM,
83+
.ep = 0,
84+
.num_links = 1,
85+
.links = { MASTER_MMSYS }
86+
};
87+
88+
static struct mtk_icc_node mm_img = {
89+
.name = "mm-img",
90+
.id = MASTER_MM_IMG,
91+
.ep = 0,
92+
.num_links = 1,
93+
.links = { MASTER_MMSYS }
94+
};
95+
96+
static struct mtk_icc_node mm_mdp = {
97+
.name = "mm-mdp",
98+
.id = MASTER_MM_MDP,
99+
.ep = 0,
100+
.num_links = 1,
101+
.links = { MASTER_MMSYS }
102+
};
103+
104+
static struct mtk_icc_node *mt8183_emi_icc_nodes[] = {
105+
[SLAVE_DDR_EMI] = &ddr_emi,
106+
[MASTER_MCUSYS] = &mcusys,
107+
[MASTER_MFG] = &gpu,
108+
[MASTER_MMSYS] = &mmsys,
109+
[MASTER_MM_VPU] = &mm_vpu,
110+
[MASTER_MM_DISP] = &mm_disp,
111+
[MASTER_MM_VDEC] = &mm_vdec,
112+
[MASTER_MM_VENC] = &mm_venc,
113+
[MASTER_MM_CAM] = &mm_cam,
114+
[MASTER_MM_IMG] = &mm_img,
115+
[MASTER_MM_MDP] = &mm_mdp
116+
};
117+
118+
static const struct mtk_icc_desc mt8183_emi_icc = {
119+
.nodes = mt8183_emi_icc_nodes,
120+
.num_nodes = ARRAY_SIZE(mt8183_emi_icc_nodes),
121+
};
122+
123+
static const struct of_device_id mtk_mt8183_emi_icc_of_match[] = {
124+
{ .compatible = "mediatek,mt8183-emi", .data = &mt8183_emi_icc },
125+
{ /* sentinel */ },
126+
};
127+
MODULE_DEVICE_TABLE(of, mtk_mt8183_emi_icc_of_match);
128+
129+
static struct platform_driver mtk_emi_icc_mt8183_driver = {
130+
.driver = {
131+
.name = "emi-icc-mt8183",
132+
.of_match_table = mtk_mt8183_emi_icc_of_match,
133+
.sync_state = icc_sync_state,
134+
},
135+
.probe = mtk_emi_icc_probe,
136+
.remove_new = mtk_emi_icc_remove,
137+
138+
};
139+
module_platform_driver(mtk_emi_icc_mt8183_driver);
140+
141+
MODULE_AUTHOR("AngeloGioacchino Del Regno <[email protected]>");
142+
MODULE_DESCRIPTION("MediaTek MT8183 EMI ICC driver");
143+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)