1// SPDX-License-Identifier: GPL-2.0
2/*
3 * RPM over SMD communication wrapper for interconnects
4 *
5 * Copyright (C) 2019 Linaro Ltd
6 * Author: Georgi Djakov <georgi.djakov@linaro.org>
7 */
8
9#include <linux/interconnect-provider.h>
10#include <linux/module.h>
11#include <linux/of.h>
12#include <linux/of_platform.h>
13#include <linux/platform_device.h>
14#include <linux/soc/qcom/smd-rpm.h>
15
16#include "smd-rpm.h"
17
18#define RPM_KEY_BW		0x00007762
19
20static struct qcom_smd_rpm *icc_smd_rpm;
21
22struct icc_rpm_smd_req {
23	__le32 key;
24	__le32 nbytes;
25	__le32 value;
26};
27
28bool qcom_icc_rpm_smd_available(void)
29{
30	return !!icc_smd_rpm;
31}
32EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_available);
33
34int qcom_icc_rpm_smd_send(int ctx, int rsc_type, int id, u32 val)
35{
36	struct icc_rpm_smd_req req = {
37		.key = cpu_to_le32(RPM_KEY_BW),
38		.nbytes = cpu_to_le32(sizeof(u32)),
39		.value = cpu_to_le32(val),
40	};
41
42	return qcom_rpm_smd_write(icc_smd_rpm, ctx, rsc_type, id, &req,
43				  sizeof(req));
44}
45EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_send);
46
47static int qcom_icc_rpm_smd_remove(struct platform_device *pdev)
48{
49	icc_smd_rpm = NULL;
50
51	return 0;
52}
53
54static int qcom_icc_rpm_smd_probe(struct platform_device *pdev)
55{
56	icc_smd_rpm = dev_get_drvdata(pdev->dev.parent);
57
58	if (!icc_smd_rpm) {
59		dev_err(&pdev->dev, "unable to retrieve handle to RPM\n");
60		return -ENODEV;
61	}
62
63	return 0;
64}
65
66static struct platform_driver qcom_interconnect_rpm_smd_driver = {
67	.driver = {
68		.name		= "icc_smd_rpm",
69	},
70	.probe = qcom_icc_rpm_smd_probe,
71	.remove = qcom_icc_rpm_smd_remove,
72};
73module_platform_driver(qcom_interconnect_rpm_smd_driver);
74MODULE_AUTHOR("Georgi Djakov <georgi.djakov@linaro.org>");
75MODULE_DESCRIPTION("Qualcomm SMD RPM interconnect proxy driver");
76MODULE_LICENSE("GPL v2");
77MODULE_ALIAS("platform:icc_smd_rpm");
78