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/platform_device.h> 12 #include <linux/soc/qcom/smd-rpm.h> 13 14 #include "icc-rpm.h" 15 16 #define RPM_KEY_BW 0x00007762 17 #define QCOM_RPM_SMD_KEY_RATE 0x007a484b 18 19 static struct qcom_smd_rpm *icc_smd_rpm; 20 21 struct icc_rpm_smd_req { 22 __le32 key; 23 __le32 nbytes; 24 __le32 value; 25 }; 26 27 bool qcom_icc_rpm_smd_available(void) 28 { 29 return !!icc_smd_rpm; 30 } 31 EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_available); 32 33 int qcom_icc_rpm_smd_send(int ctx, int rsc_type, int id, u32 val) 34 { 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), 39 }; 40 41 return qcom_rpm_smd_write(icc_smd_rpm, ctx, rsc_type, id, &req, 42 sizeof(req)); 43 } 44 EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_send); 45 46 int qcom_icc_rpm_set_bus_rate(const struct rpm_clk_resource *clk, int ctx, u32 rate) 47 { 48 struct clk_smd_rpm_req req = { 49 .key = cpu_to_le32(QCOM_RPM_SMD_KEY_RATE), 50 .nbytes = cpu_to_le32(sizeof(u32)), 51 }; 52 53 /* Branch clocks are only on/off */ 54 if (clk->branch) 55 rate = !!rate; 56 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)); 63 } 64 EXPORT_SYMBOL_GPL(qcom_icc_rpm_set_bus_rate); 65 66 static void qcom_icc_rpm_smd_remove(struct platform_device *pdev) 67 { 68 icc_smd_rpm = NULL; 69 } 70 71 static int qcom_icc_rpm_smd_probe(struct platform_device *pdev) 72 { 73 icc_smd_rpm = dev_get_drvdata(pdev->dev.parent); 74 75 if (!icc_smd_rpm) { 76 dev_err(&pdev->dev, "unable to retrieve handle to RPM\n"); 77 return -ENODEV; 78 } 79 80 return 0; 81 } 82 83 static struct platform_driver qcom_interconnect_rpm_smd_driver = { 84 .driver = { 85 .name = "icc_smd_rpm", 86 }, 87 .probe = qcom_icc_rpm_smd_probe, 88 .remove = qcom_icc_rpm_smd_remove, 89 }; 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"); 95