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 18 static struct qcom_smd_rpm *icc_smd_rpm; 19 20 struct icc_rpm_smd_req { 21 __le32 key; 22 __le32 nbytes; 23 __le32 value; 24 }; 25 26 bool qcom_icc_rpm_smd_available(void) 27 { 28 return !!icc_smd_rpm; 29 } 30 EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_available); 31 32 int qcom_icc_rpm_smd_send(int ctx, int rsc_type, int id, u32 val) 33 { 34 struct icc_rpm_smd_req req = { 35 .key = cpu_to_le32(RPM_KEY_BW), 36 .nbytes = cpu_to_le32(sizeof(u32)), 37 .value = cpu_to_le32(val), 38 }; 39 40 return qcom_rpm_smd_write(icc_smd_rpm, ctx, rsc_type, id, &req, 41 sizeof(req)); 42 } 43 EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_send); 44 45 int qcom_icc_rpm_set_bus_rate(const struct rpm_clk_resource *clk, int ctx, u32 rate) 46 { 47 struct clk_smd_rpm_req req = { 48 .key = cpu_to_le32(QCOM_RPM_SMD_KEY_RATE), 49 .nbytes = cpu_to_le32(sizeof(u32)), 50 }; 51 52 /* Branch clocks are only on/off */ 53 if (clk->branch) 54 rate = !!rate; 55 56 req.value = cpu_to_le32(rate); 57 return qcom_rpm_smd_write(icc_smd_rpm, 58 ctx, 59 clk->resource_type, 60 clk->clock_id, 61 &req, sizeof(req)); 62 } 63 EXPORT_SYMBOL_GPL(qcom_icc_rpm_set_bus_rate); 64 65 static void qcom_icc_rpm_smd_remove(struct platform_device *pdev) 66 { 67 icc_smd_rpm = NULL; 68 } 69 70 static int qcom_icc_rpm_smd_probe(struct platform_device *pdev) 71 { 72 icc_smd_rpm = dev_get_drvdata(pdev->dev.parent); 73 74 if (!icc_smd_rpm) { 75 dev_err(&pdev->dev, "unable to retrieve handle to RPM\n"); 76 return -ENODEV; 77 } 78 79 return 0; 80 } 81 82 static struct platform_driver qcom_interconnect_rpm_smd_driver = { 83 .driver = { 84 .name = "icc_smd_rpm", 85 }, 86 .probe = qcom_icc_rpm_smd_probe, 87 .remove = qcom_icc_rpm_smd_remove, 88 }; 89 module_platform_driver(qcom_interconnect_rpm_smd_driver); 90 MODULE_AUTHOR("Georgi Djakov <georgi.djakov@linaro.org>"); 91 MODULE_DESCRIPTION("Qualcomm SMD RPM interconnect proxy driver"); 92 MODULE_LICENSE("GPL v2"); 93 MODULE_ALIAS("platform:icc_smd_rpm"); 94