Skip to content

Commit 4424419

Browse files
committed
Merge tag 'samsung-drivers-firmware-clk-6.19' of https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux into clk-samsung
Pull Samsung clk driver updates from Krzysztof Kozlowski: Extend Samsung ACPM (Alive Clock and Power Manager) firmware drivers: - Add support for passing DVFS (Dynamic Voltage and Frequency) messages to configure the clocks in ACPM device. - Add Exynos ACPM clock driver, which exposes to Linux several clocks handled by the ACPM (firmware) * tag 'samsung-drivers-firmware-clk-6.19' of https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux: firmware: exynos-acpm: add empty method to allow compile test MAINTAINERS: add ACPM clock bindings and driver clk: samsung: add Exynos ACPM clock driver firmware: exynos-acpm: register ACPM clocks pdev firmware: exynos-acpm: add DVFS protocol dt-bindings: firmware: google,gs101-acpm-ipc: add ACPM clocks
2 parents 3a86608 + 6837c00 commit 4424419

11 files changed

Lines changed: 384 additions & 2 deletions

File tree

Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ properties:
2424
compatible:
2525
const: google,gs101-acpm-ipc
2626

27+
"#clock-cells":
28+
const: 1
29+
description:
30+
Clocks that are variable and index based. These clocks don't provide
31+
an entire range of values between the limits but only discrete points
32+
within the range. The firmware also manages the voltage scaling
33+
appropriately with the clock scaling. The argument is the ID of the
34+
clock contained by the firmware messages.
35+
2736
mboxes:
2837
maxItems: 1
2938

@@ -45,6 +54,7 @@ properties:
4554

4655
required:
4756
- compatible
57+
- "#clock-cells"
4858
- mboxes
4959
- shmem
5060

@@ -56,6 +66,7 @@ examples:
5666
5767
power-management {
5868
compatible = "google,gs101-acpm-ipc";
69+
#clock-cells = <1>;
5970
mboxes = <&ap2apm_mailbox>;
6071
shmem = <&apm_sram>;
6172

MAINTAINERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10601,7 +10601,7 @@ F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml
1060110601
F: arch/arm64/boot/dts/exynos/google/
1060210602
F: drivers/clk/samsung/clk-gs101.c
1060310603
F: drivers/phy/samsung/phy-gs101-ufs.c
10604-
F: include/dt-bindings/clock/google,gs101.h
10604+
F: include/dt-bindings/clock/google,gs101*
1060510605
K: [gG]oogle.?[tT]ensor
1060610606

1060710607
GPD FAN DRIVER
@@ -22761,6 +22761,7 @@ L: linux-kernel@vger.kernel.org
2276122761
L: linux-samsung-soc@vger.kernel.org
2276222762
S: Supported
2276322763
F: Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml
22764+
F: drivers/clk/samsung/clk-acpm.c
2276422765
F: drivers/firmware/samsung/exynos-acpm*
2276522766
F: include/linux/firmware/samsung/exynos-acpm-protocol.h
2276622767

drivers/clk/samsung/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ config EXYNOS_CLKOUT
9595
status of the certains clocks from SoC, but it could also be tied to
9696
other devices as an input clock.
9797

98+
config EXYNOS_ACPM_CLK
99+
tristate "Clock driver controlled via ACPM interface"
100+
depends on EXYNOS_ACPM_PROTOCOL || (COMPILE_TEST && !EXYNOS_ACPM_PROTOCOL)
101+
help
102+
This driver provides support for clocks that are controlled by
103+
firmware that implements the ACPM interface.
104+
105+
This driver uses the ACPM interface to interact with the firmware
106+
providing all the clock controlls.
107+
98108
config TESLA_FSD_COMMON_CLK
99109
bool "Tesla FSD clock controller support" if COMPILE_TEST
100110
depends on COMMON_CLK_SAMSUNG

drivers/clk/samsung/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynos990.o
2828
obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynosautov9.o
2929
obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynosautov920.o
3030
obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-gs101.o
31+
obj-$(CONFIG_EXYNOS_ACPM_CLK) += clk-acpm.o
3132
obj-$(CONFIG_S3C64XX_COMMON_CLK) += clk-s3c64xx.o
3233
obj-$(CONFIG_S5PV210_COMMON_CLK) += clk-s5pv210.o clk-s5pv210-audss.o
3334
obj-$(CONFIG_TESLA_FSD_COMMON_CLK) += clk-fsd.o

drivers/clk/samsung/clk-acpm.c

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Samsung Exynos ACPM protocol based clock driver.
4+
*
5+
* Copyright 2025 Linaro Ltd.
6+
*/
7+
8+
#include <linux/array_size.h>
9+
#include <linux/clk-provider.h>
10+
#include <linux/container_of.h>
11+
#include <linux/device/devres.h>
12+
#include <linux/device.h>
13+
#include <linux/err.h>
14+
#include <linux/firmware/samsung/exynos-acpm-protocol.h>
15+
#include <linux/module.h>
16+
#include <linux/platform_device.h>
17+
#include <linux/types.h>
18+
19+
struct acpm_clk {
20+
u32 id;
21+
struct clk_hw hw;
22+
unsigned int mbox_chan_id;
23+
const struct acpm_handle *handle;
24+
};
25+
26+
struct acpm_clk_variant {
27+
const char *name;
28+
};
29+
30+
struct acpm_clk_driver_data {
31+
const struct acpm_clk_variant *clks;
32+
unsigned int nr_clks;
33+
unsigned int mbox_chan_id;
34+
};
35+
36+
#define to_acpm_clk(clk) container_of(clk, struct acpm_clk, hw)
37+
38+
#define ACPM_CLK(cname) \
39+
{ \
40+
.name = cname, \
41+
}
42+
43+
static const struct acpm_clk_variant gs101_acpm_clks[] = {
44+
ACPM_CLK("mif"),
45+
ACPM_CLK("int"),
46+
ACPM_CLK("cpucl0"),
47+
ACPM_CLK("cpucl1"),
48+
ACPM_CLK("cpucl2"),
49+
ACPM_CLK("g3d"),
50+
ACPM_CLK("g3dl2"),
51+
ACPM_CLK("tpu"),
52+
ACPM_CLK("intcam"),
53+
ACPM_CLK("tnr"),
54+
ACPM_CLK("cam"),
55+
ACPM_CLK("mfc"),
56+
ACPM_CLK("disp"),
57+
ACPM_CLK("bo"),
58+
};
59+
60+
static const struct acpm_clk_driver_data acpm_clk_gs101 = {
61+
.clks = gs101_acpm_clks,
62+
.nr_clks = ARRAY_SIZE(gs101_acpm_clks),
63+
.mbox_chan_id = 0,
64+
};
65+
66+
static unsigned long acpm_clk_recalc_rate(struct clk_hw *hw,
67+
unsigned long parent_rate)
68+
{
69+
struct acpm_clk *clk = to_acpm_clk(hw);
70+
71+
return clk->handle->ops.dvfs_ops.get_rate(clk->handle,
72+
clk->mbox_chan_id, clk->id);
73+
}
74+
75+
static int acpm_clk_determine_rate(struct clk_hw *hw,
76+
struct clk_rate_request *req)
77+
{
78+
/*
79+
* We can't figure out what rate it will be, so just return the
80+
* rate back to the caller. acpm_clk_recalc_rate() will be called
81+
* after the rate is set and we'll know what rate the clock is
82+
* running at then.
83+
*/
84+
return 0;
85+
}
86+
87+
static int acpm_clk_set_rate(struct clk_hw *hw, unsigned long rate,
88+
unsigned long parent_rate)
89+
{
90+
struct acpm_clk *clk = to_acpm_clk(hw);
91+
92+
return clk->handle->ops.dvfs_ops.set_rate(clk->handle,
93+
clk->mbox_chan_id, clk->id, rate);
94+
}
95+
96+
static const struct clk_ops acpm_clk_ops = {
97+
.recalc_rate = acpm_clk_recalc_rate,
98+
.determine_rate = acpm_clk_determine_rate,
99+
.set_rate = acpm_clk_set_rate,
100+
};
101+
102+
static int acpm_clk_register(struct device *dev, struct acpm_clk *aclk,
103+
const char *name)
104+
{
105+
struct clk_init_data init = {};
106+
107+
init.name = name;
108+
init.ops = &acpm_clk_ops;
109+
aclk->hw.init = &init;
110+
111+
return devm_clk_hw_register(dev, &aclk->hw);
112+
}
113+
114+
static int acpm_clk_probe(struct platform_device *pdev)
115+
{
116+
const struct acpm_handle *acpm_handle;
117+
struct clk_hw_onecell_data *clk_data;
118+
struct clk_hw **hws;
119+
struct device *dev = &pdev->dev;
120+
struct acpm_clk *aclks;
121+
unsigned int mbox_chan_id;
122+
int i, err, count;
123+
124+
acpm_handle = devm_acpm_get_by_node(dev, dev->parent->of_node);
125+
if (IS_ERR(acpm_handle))
126+
return dev_err_probe(dev, PTR_ERR(acpm_handle),
127+
"Failed to get acpm handle\n");
128+
129+
count = acpm_clk_gs101.nr_clks;
130+
mbox_chan_id = acpm_clk_gs101.mbox_chan_id;
131+
132+
clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count),
133+
GFP_KERNEL);
134+
if (!clk_data)
135+
return -ENOMEM;
136+
137+
clk_data->num = count;
138+
hws = clk_data->hws;
139+
140+
aclks = devm_kcalloc(dev, count, sizeof(*aclks), GFP_KERNEL);
141+
if (!aclks)
142+
return -ENOMEM;
143+
144+
for (i = 0; i < count; i++) {
145+
struct acpm_clk *aclk = &aclks[i];
146+
147+
/*
148+
* The code assumes the clock IDs start from zero,
149+
* are sequential and do not have gaps.
150+
*/
151+
aclk->id = i;
152+
aclk->handle = acpm_handle;
153+
aclk->mbox_chan_id = mbox_chan_id;
154+
155+
hws[i] = &aclk->hw;
156+
157+
err = acpm_clk_register(dev, aclk,
158+
acpm_clk_gs101.clks[i].name);
159+
if (err)
160+
return dev_err_probe(dev, err,
161+
"Failed to register clock\n");
162+
}
163+
164+
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
165+
clk_data);
166+
}
167+
168+
static const struct platform_device_id acpm_clk_id[] = {
169+
{ "gs101-acpm-clk" },
170+
{}
171+
};
172+
MODULE_DEVICE_TABLE(platform, acpm_clk_id);
173+
174+
static struct platform_driver acpm_clk_driver = {
175+
.driver = {
176+
.name = "acpm-clocks",
177+
},
178+
.probe = acpm_clk_probe,
179+
.id_table = acpm_clk_id,
180+
};
181+
module_platform_driver(acpm_clk_driver);
182+
183+
MODULE_AUTHOR("Tudor Ambarus <tudor.ambarus@linaro.org>");
184+
MODULE_DESCRIPTION("Samsung Exynos ACPM clock driver");
185+
MODULE_LICENSE("GPL");

drivers/firmware/samsung/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
acpm-protocol-objs := exynos-acpm.o exynos-acpm-pmic.o
3+
acpm-protocol-objs := exynos-acpm.o
4+
acpm-protocol-objs += exynos-acpm-pmic.o
5+
acpm-protocol-objs += exynos-acpm-dvfs.o
46
obj-$(CONFIG_EXYNOS_ACPM_PROTOCOL) += acpm-protocol.o
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright 2020 Samsung Electronics Co., Ltd.
4+
* Copyright 2020 Google LLC.
5+
* Copyright 2025 Linaro Ltd.
6+
*/
7+
8+
#include <linux/bitfield.h>
9+
#include <linux/firmware/samsung/exynos-acpm-protocol.h>
10+
#include <linux/ktime.h>
11+
#include <linux/types.h>
12+
#include <linux/units.h>
13+
14+
#include "exynos-acpm.h"
15+
#include "exynos-acpm-dvfs.h"
16+
17+
#define ACPM_DVFS_ID GENMASK(11, 0)
18+
#define ACPM_DVFS_REQ_TYPE GENMASK(15, 0)
19+
20+
#define ACPM_DVFS_FREQ_REQ 0
21+
#define ACPM_DVFS_FREQ_GET 1
22+
23+
static void acpm_dvfs_set_xfer(struct acpm_xfer *xfer, u32 *cmd, size_t cmdlen,
24+
unsigned int acpm_chan_id, bool response)
25+
{
26+
xfer->acpm_chan_id = acpm_chan_id;
27+
xfer->txd = cmd;
28+
xfer->txlen = cmdlen;
29+
30+
if (response) {
31+
xfer->rxd = cmd;
32+
xfer->rxlen = cmdlen;
33+
}
34+
}
35+
36+
static void acpm_dvfs_init_set_rate_cmd(u32 cmd[4], unsigned int clk_id,
37+
unsigned long rate)
38+
{
39+
cmd[0] = FIELD_PREP(ACPM_DVFS_ID, clk_id);
40+
cmd[1] = rate / HZ_PER_KHZ;
41+
cmd[2] = FIELD_PREP(ACPM_DVFS_REQ_TYPE, ACPM_DVFS_FREQ_REQ);
42+
cmd[3] = ktime_to_ms(ktime_get());
43+
}
44+
45+
int acpm_dvfs_set_rate(const struct acpm_handle *handle,
46+
unsigned int acpm_chan_id, unsigned int clk_id,
47+
unsigned long rate)
48+
{
49+
struct acpm_xfer xfer = {0};
50+
u32 cmd[4];
51+
52+
acpm_dvfs_init_set_rate_cmd(cmd, clk_id, rate);
53+
acpm_dvfs_set_xfer(&xfer, cmd, sizeof(cmd), acpm_chan_id, false);
54+
55+
return acpm_do_xfer(handle, &xfer);
56+
}
57+
58+
static void acpm_dvfs_init_get_rate_cmd(u32 cmd[4], unsigned int clk_id)
59+
{
60+
cmd[0] = FIELD_PREP(ACPM_DVFS_ID, clk_id);
61+
cmd[2] = FIELD_PREP(ACPM_DVFS_REQ_TYPE, ACPM_DVFS_FREQ_GET);
62+
cmd[3] = ktime_to_ms(ktime_get());
63+
}
64+
65+
unsigned long acpm_dvfs_get_rate(const struct acpm_handle *handle,
66+
unsigned int acpm_chan_id, unsigned int clk_id)
67+
{
68+
struct acpm_xfer xfer;
69+
unsigned int cmd[4] = {0};
70+
int ret;
71+
72+
acpm_dvfs_init_get_rate_cmd(cmd, clk_id);
73+
acpm_dvfs_set_xfer(&xfer, cmd, sizeof(cmd), acpm_chan_id, true);
74+
75+
ret = acpm_do_xfer(handle, &xfer);
76+
if (ret)
77+
return 0;
78+
79+
return xfer.rxd[1] * HZ_PER_KHZ;
80+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright 2020 Samsung Electronics Co., Ltd.
4+
* Copyright 2020 Google LLC.
5+
* Copyright 2025 Linaro Ltd.
6+
*/
7+
#ifndef __EXYNOS_ACPM_DVFS_H__
8+
#define __EXYNOS_ACPM_DVFS_H__
9+
10+
#include <linux/types.h>
11+
12+
struct acpm_handle;
13+
14+
int acpm_dvfs_set_rate(const struct acpm_handle *handle,
15+
unsigned int acpm_chan_id, unsigned int id,
16+
unsigned long rate);
17+
unsigned long acpm_dvfs_get_rate(const struct acpm_handle *handle,
18+
unsigned int acpm_chan_id,
19+
unsigned int clk_id);
20+
21+
#endif /* __EXYNOS_ACPM_DVFS_H__ */

0 commit comments

Comments
 (0)