diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index f8daf44d643f..8d7b072ef19d 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -1247,5 +1247,13 @@ config MSM_SLATECOM_INTERFACE from hardware. Hardware will provide access to read registers and read/write AHB memory in the device. +config QCOM_AOP_SET_DDR + tristate "Sysfs to communicate with AOP using QMP protocol" + help + This options enables a driver which allows clients to send messages + to Alway On processor using QMP transport. Users can echo a frequency + into an exposed sysfs node to send to AOP. The driver expects the Cap + frequency of DDR based on SKU. + source "drivers/soc/qcom/icnss2/Kconfig" endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index a896e1bf5903..16eb908971bf 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -112,3 +112,4 @@ obj-$(CONFIG_RENAME_BLOCK_DEVICE) += rename_block_device.o obj-$(CONFIG_QCOM_ADSP_MANUAL_VOTE) += adsp_vote_qmi.o adsp_lpm_voting_v01.o obj-$(CONFIG_MSM_SLATECOM) += slatecom_spi.o obj-$(CONFIG_MSM_SLATECOM_INTERFACE) += slatecom_interface.o +obj-$(CONFIG_QCOM_AOP_SET_DDR) += aop-set-ddr.o diff --git a/drivers/soc/qcom/aop-set-ddr.c b/drivers/soc/qcom/aop-set-ddr.c new file mode 100644 index 000000000000..b435b45f5060 --- /dev/null +++ b/drivers/soc/qcom/aop-set-ddr.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2021, The Linux Foundation. All rights reserved. */ + +#include +#include +#include +#include +#include +#include + +#define MAX_MSG_SIZE 96 /* Imposed by the remote */ + +struct set_ddr_freq_data { + struct qmp_pkt pkt; + char buf[MAX_MSG_SIZE + 1]; +}; + +static struct set_ddr_freq_data data_pkt; +static struct mbox_chan *chan; +static struct mbox_client *cl; + +static ssize_t set_ddr_capped_freq_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + unsigned int freq = 0; + + if (kstrtou32(buf, 0, &freq)) { + pr_err("%s: failed to read boot info from string\n", __func__); + return -EINVAL; + } + + memset(&data_pkt, 0, sizeof(data_pkt)); + snprintf(data_pkt.buf, MAX_MSG_SIZE, + "{class:ddr, res:capped, val: %d}", freq); + pr_debug("%s : data: %s\n", __func__, data_pkt.buf); + + /* Controller expects a 4 byte aligned buffer */ + data_pkt.pkt.size = (strlen(data_pkt.buf) + 0x3) & ~0x3; + data_pkt.pkt.data = data_pkt.buf; + + if (mbox_send_message(chan, &(data_pkt.pkt)) < 0) + pr_err("Failed to send qmp request\n"); + + return len; +} +static DEVICE_ATTR_WO(set_ddr_capped_freq); + +static int set_ddr_freq_probe(struct platform_device *pdev) +{ + int ret = 0; + + cl = devm_kzalloc(&pdev->dev, sizeof(*cl), GFP_KERNEL); + if (!cl) + return -ENOMEM; + + cl->dev = &pdev->dev; + cl->tx_block = true; + cl->tx_tout = 1000; + cl->knows_txdone = false; + + chan = mbox_request_channel(cl, 0); + if (IS_ERR(chan)) { + dev_err(&pdev->dev, "Failed to mbox channel\n"); + return PTR_ERR(chan); + } + + ret = device_create_file(&pdev->dev, &dev_attr_set_ddr_capped_freq); + if (ret) + dev_err(&pdev->dev, "Couldn't create sysfs attribute\n"); + + return 0; +} + +static const struct of_device_id aop_qmp_match_tbl[] = { + {.compatible = "qcom,aop-set-ddr-freq"}, + {}, +}; + +static struct platform_driver aop_qmp_msg_driver = { + .probe = set_ddr_freq_probe, + .driver = { + .name = "aop-set-ddr-freq", + .suppress_bind_attrs = true, + .of_match_table = aop_qmp_match_tbl, + }, +}; +builtin_platform_driver(aop_qmp_msg_driver);