Linux 6.13-rc4
[linux.git] / drivers / interconnect / qcom / smd-rpm.c
blob8316c87a2c60f5f99edece3443cc60e9e75fa11f
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * RPM over SMD communication wrapper for interconnects
5 * Copyright (C) 2019 Linaro Ltd
6 * Author: Georgi Djakov <georgi.djakov@linaro.org>
7 */
9 #include <linux/interconnect-provider.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/soc/qcom/smd-rpm.h>
14 #include "icc-rpm.h"
16 #define RPM_KEY_BW 0x00007762
17 #define QCOM_RPM_SMD_KEY_RATE 0x007a484b
19 static struct qcom_smd_rpm *icc_smd_rpm;
21 struct icc_rpm_smd_req {
22 __le32 key;
23 __le32 nbytes;
24 __le32 value;
27 bool qcom_icc_rpm_smd_available(void)
29 return !!icc_smd_rpm;
31 EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_available);
33 int qcom_icc_rpm_smd_send(int ctx, int rsc_type, int id, u32 val)
35 struct icc_rpm_smd_req req = {
36 .key = cpu_to_le32(RPM_KEY_BW),
37 .nbytes = cpu_to_le32(sizeof(u32)),
38 .value = cpu_to_le32(val),
41 return qcom_rpm_smd_write(icc_smd_rpm, ctx, rsc_type, id, &req,
42 sizeof(req));
44 EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_send);
46 int qcom_icc_rpm_set_bus_rate(const struct rpm_clk_resource *clk, int ctx, u32 rate)
48 struct clk_smd_rpm_req req = {
49 .key = cpu_to_le32(QCOM_RPM_SMD_KEY_RATE),
50 .nbytes = cpu_to_le32(sizeof(u32)),
53 /* Branch clocks are only on/off */
54 if (clk->branch)
55 rate = !!rate;
57 req.value = cpu_to_le32(rate);
58 return qcom_rpm_smd_write(icc_smd_rpm,
59 ctx,
60 clk->resource_type,
61 clk->clock_id,
62 &req, sizeof(req));
64 EXPORT_SYMBOL_GPL(qcom_icc_rpm_set_bus_rate);
66 static void qcom_icc_rpm_smd_remove(struct platform_device *pdev)
68 icc_smd_rpm = NULL;
71 static int qcom_icc_rpm_smd_probe(struct platform_device *pdev)
73 icc_smd_rpm = dev_get_drvdata(pdev->dev.parent);
75 if (!icc_smd_rpm) {
76 dev_err(&pdev->dev, "unable to retrieve handle to RPM\n");
77 return -ENODEV;
80 return 0;
83 static struct platform_driver qcom_interconnect_rpm_smd_driver = {
84 .driver = {
85 .name = "icc_smd_rpm",
87 .probe = qcom_icc_rpm_smd_probe,
88 .remove = qcom_icc_rpm_smd_remove,
90 module_platform_driver(qcom_interconnect_rpm_smd_driver);
91 MODULE_AUTHOR("Georgi Djakov <georgi.djakov@linaro.org>");
92 MODULE_DESCRIPTION("Qualcomm SMD RPM interconnect proxy driver");
93 MODULE_LICENSE("GPL v2");
94 MODULE_ALIAS("platform:icc_smd_rpm");