aboutsummaryrefslogtreecommitdiff
path: root/drivers/interconnect/qcom/smd-rpm.c
blob: 0cf772f51642eff9ce98d960f517c209c8246f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-License-Identifier: GPL-2.0
/*
 * RPM over SMD communication wrapper for interconects
 *
 * Copyright (C) 2018 Linaro Ltd
 * Author: Georgi Djakov <georgi.djakov@linaro.org>
 */

#include <linux/interconnect-provider.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/soc/qcom/smd-rpm.h>
#include "smd-rpm.h"

#define	RPM_KEY_BW	0x00007762

static struct qcom_icc_rpm {
	struct qcom_smd_rpm *rpm;
} icc_rpm_smd;

struct icc_rpm_smd_req {
	__le32 key;
	__le32 nbytes;
	__le32 value;
};

bool qcom_icc_rpm_smd_available(void)
{
	if (!icc_rpm_smd.rpm)
		return false;

	return true;
}

int qcom_icc_rpm_smd_send(int ctx, int rsc_type, int id, u32 val)
{
	struct icc_rpm_smd_req req = {
		.key = cpu_to_le32(RPM_KEY_BW),
		.nbytes = cpu_to_le32(sizeof(u32)),
		.value = cpu_to_le32(val),
	};

	return qcom_rpm_smd_write(icc_rpm_smd.rpm, ctx, rsc_type, id, &req,
				  sizeof(req));
}
EXPORT_SYMBOL(qcom_icc_rpm_smd_send);

static int qcom_icc_rpm_smd_probe(struct platform_device *pdev)
{
	icc_rpm_smd.rpm = dev_get_drvdata(pdev->dev.parent);
	if (!icc_rpm_smd.rpm) {
		dev_err(&pdev->dev, "unable to retrieve handle to RPM\n");
		return -ENODEV;
	}

	return 0;
}

static const struct of_device_id qcom_icc_rpm_smd_dt_match[] = {
	{ .compatible = "qcom,interconnect-smd-rpm", },
	{ },
};

MODULE_DEVICE_TABLE(of, qcom_interconnect_rpm_smd_dt_match);

static struct platform_driver qcom_interconnect_rpm_smd_driver = {
	.driver = {
		.name		= "qcom-interconnect-smd-rpm",
		.of_match_table	= qcom_icc_rpm_smd_dt_match,
	},
	.probe = qcom_icc_rpm_smd_probe,
};

static int __init rpm_smd_interconnect_init(void)
{
	return platform_driver_register(&qcom_interconnect_rpm_smd_driver);
}
subsys_initcall(rpm_smd_interconnect_init);

static void __exit rpm_smd_interconnect_exit(void)
{
	platform_driver_unregister(&qcom_interconnect_rpm_smd_driver);
}
module_exit(rpm_smd_interconnect_exit)

MODULE_AUTHOR("Georgi Djakov <georgi.djakov@linaro.org>");
MODULE_DESCRIPTION("Qualcomm SMD RPM interconnect driver");
MODULE_LICENSE("GPL v2");