Merge "drivers: thermal: Add support for RPM SMD cooling device"
This commit is contained in:
commit
015e146b4f
@ -196,3 +196,21 @@ config THERMAL_TSENS_LEGACY
|
||||
to set threshold temperature for both warm and cool and update
|
||||
thermal userspace client when a threshold is reached. Warm/Cool
|
||||
temperature thresholds can be set independently for each sensor.
|
||||
|
||||
config QTI_CX_IPEAK_COOLING_DEVICE
|
||||
tristate "QTI CX IPeak cooling device"
|
||||
depends on THERMAL && THERMAL_OF
|
||||
help
|
||||
This implements a mitigation device to place a thermal client vote
|
||||
to CXIP LM hardware. When all pre-defined clients on CX rail including
|
||||
thermal client set their vote, CXIP LM hardware throttles the clients
|
||||
on the CX rail.
|
||||
|
||||
config QTI_RPM_SMD_COOLING_DEVICE
|
||||
tristate "Qualcomm Technologies Inc. RPM SMD cooling device driver"
|
||||
depends on MSM_RPM_SMD && THERMAL_OF
|
||||
help
|
||||
This implements a mitigation device to send temperature band
|
||||
level to RPM hardware via SMD protocol. This mitigation device
|
||||
will be used by temperature reliability rules to restrict a
|
||||
railway at predefined voltage corner using RPM hardware.
|
@ -28,3 +28,5 @@ obj-${CONFIG_QTI_SDPM_CLOCK_MONITOR} += sdpm_clk.o
|
||||
obj-$(CONFIG_QTI_THERMAL_MINIDUMP) += thermal_minidump.o
|
||||
obj-$(CONFIG_THERMAL_TSENS_LEGACY) += msm-tsens-driver.o
|
||||
msm-tsens-driver-y += msm-tsens.o tsens2xxx.o tsens-dbg.o
|
||||
obj-$(CONFIG_QTI_CX_IPEAK_COOLING_DEVICE) += cx_ipeak_cdev.o
|
||||
obj-$(CONFIG_QTI_RPM_SMD_COOLING_DEVICE) += rpm_smd_cooling_device.o
|
||||
|
257
drivers/thermal/qcom/cx_ipeak_cdev.c
Normal file
257
drivers/thermal/qcom/cx_ipeak_cdev.c
Normal file
@ -0,0 +1,257 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2018-2019, 2021 The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) "%s:%s " fmt, KBUILD_MODNAME, __func__
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/thermal.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/io.h>
|
||||
|
||||
#define CXIP_LM_CDEV_DRIVER "cx-ipeak-cooling-device"
|
||||
#define CXIP_LM_CDEV_MAX_STATE 1
|
||||
|
||||
#define CXIP_LM_VOTE_STATUS 0x0
|
||||
#define CXIP_LM_BYPASS 0x4
|
||||
#define CXIP_LM_VOTE_CLEAR 0x8
|
||||
#define CXIP_LM_VOTE_SET 0xc
|
||||
#define CXIP_LM_FEATURE_EN 0x10
|
||||
#define CXIP_LM_BYPASS_VAL 0xff20
|
||||
#define CXIP_LM_THERM_VOTE_VAL 0x80
|
||||
#define CXIP_LM_FEATURE_EN_VAL 0x1
|
||||
|
||||
struct cxip_lm_cooling_device {
|
||||
struct thermal_cooling_device *cool_dev;
|
||||
char cdev_name[THERMAL_NAME_LENGTH];
|
||||
void *cx_ip_reg_base;
|
||||
unsigned int therm_clnt;
|
||||
unsigned int *bypass_clnts;
|
||||
unsigned int bypass_clnt_cnt;
|
||||
bool state;
|
||||
};
|
||||
|
||||
static void cxip_lm_therm_vote_apply(struct cxip_lm_cooling_device *cxip_dev,
|
||||
bool vote)
|
||||
{
|
||||
int vote_offset = 0, val = 0, sts_offset = 0;
|
||||
|
||||
if (!cxip_dev->therm_clnt) {
|
||||
vote_offset = vote ? CXIP_LM_VOTE_SET : CXIP_LM_VOTE_CLEAR;
|
||||
val = CXIP_LM_THERM_VOTE_VAL;
|
||||
sts_offset = CXIP_LM_VOTE_STATUS;
|
||||
} else {
|
||||
vote_offset = cxip_dev->therm_clnt;
|
||||
val = vote ? 0x1 : 0x0;
|
||||
sts_offset = vote_offset;
|
||||
}
|
||||
|
||||
writel_relaxed(val, cxip_dev->cx_ip_reg_base + vote_offset);
|
||||
pr_debug("%s vote for cxip_lm. vote:0x%x\n",
|
||||
vote ? "Applied" : "Cleared",
|
||||
readl_relaxed(cxip_dev->cx_ip_reg_base + sts_offset));
|
||||
}
|
||||
|
||||
static void cxip_lm_initialize_cxip_hw(struct cxip_lm_cooling_device *cxip_dev)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/* Set CXIP LM proxy vote for clients who are not participating */
|
||||
if (cxip_dev->bypass_clnt_cnt)
|
||||
for (i = 0; i < cxip_dev->bypass_clnt_cnt; i++)
|
||||
writel_relaxed(0x1, cxip_dev->cx_ip_reg_base +
|
||||
cxip_dev->bypass_clnts[i]);
|
||||
else if (!cxip_dev->therm_clnt)
|
||||
writel_relaxed(CXIP_LM_BYPASS_VAL,
|
||||
cxip_dev->cx_ip_reg_base + CXIP_LM_BYPASS);
|
||||
|
||||
/* Enable CXIP LM HW */
|
||||
writel_relaxed(CXIP_LM_FEATURE_EN_VAL, cxip_dev->cx_ip_reg_base +
|
||||
CXIP_LM_FEATURE_EN);
|
||||
}
|
||||
|
||||
static int cxip_lm_get_max_state(struct thermal_cooling_device *cdev,
|
||||
unsigned long *state)
|
||||
{
|
||||
*state = CXIP_LM_CDEV_MAX_STATE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cxip_lm_set_cur_state(struct thermal_cooling_device *cdev,
|
||||
unsigned long state)
|
||||
{
|
||||
struct cxip_lm_cooling_device *cxip_dev = cdev->devdata;
|
||||
int ret = 0;
|
||||
|
||||
if (state > CXIP_LM_CDEV_MAX_STATE)
|
||||
return -EINVAL;
|
||||
|
||||
if (cxip_dev->state == state)
|
||||
return 0;
|
||||
|
||||
cxip_lm_therm_vote_apply(cxip_dev, state);
|
||||
cxip_dev->state = state;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cxip_lm_get_cur_state(struct thermal_cooling_device *cdev,
|
||||
unsigned long *state)
|
||||
{
|
||||
struct cxip_lm_cooling_device *cxip_dev = cdev->devdata;
|
||||
|
||||
*state = cxip_dev->state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct thermal_cooling_device_ops cxip_lm_device_ops = {
|
||||
.get_max_state = cxip_lm_get_max_state,
|
||||
.get_cur_state = cxip_lm_get_cur_state,
|
||||
.set_cur_state = cxip_lm_set_cur_state,
|
||||
};
|
||||
|
||||
static int cxip_lm_cdev_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct cxip_lm_cooling_device *cxip_dev =
|
||||
(struct cxip_lm_cooling_device *)dev_get_drvdata(&pdev->dev);
|
||||
|
||||
if (cxip_dev) {
|
||||
if (cxip_dev->cool_dev) {
|
||||
thermal_cooling_device_unregister(cxip_dev->cool_dev);
|
||||
cxip_dev->cool_dev = NULL;
|
||||
}
|
||||
|
||||
if (cxip_dev->cx_ip_reg_base)
|
||||
cxip_lm_therm_vote_apply(cxip_dev->cx_ip_reg_base,
|
||||
false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cxip_lm_get_devicetree_data(struct platform_device *pdev,
|
||||
struct cxip_lm_cooling_device *cxip_dev,
|
||||
struct device_node *np)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = of_property_read_u32(np, "qcom,thermal-client-offset",
|
||||
&cxip_dev->therm_clnt);
|
||||
if (ret) {
|
||||
dev_dbg(&pdev->dev,
|
||||
"error for qcom,thermal-client-offset. ret:%d\n",
|
||||
ret);
|
||||
cxip_dev->therm_clnt = 0;
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = of_property_count_u32_elems(np, "qcom,bypass-client-list");
|
||||
if (ret <= 0) {
|
||||
dev_dbg(&pdev->dev, "Invalid number of clients err:%d\n", ret);
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
cxip_dev->bypass_clnt_cnt = ret;
|
||||
|
||||
cxip_dev->bypass_clnts = devm_kcalloc(&pdev->dev,
|
||||
cxip_dev->bypass_clnt_cnt,
|
||||
sizeof(*cxip_dev->bypass_clnts), GFP_KERNEL);
|
||||
if (!cxip_dev->bypass_clnts)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = of_property_read_u32_array(np, "qcom,bypass-client-list",
|
||||
cxip_dev->bypass_clnts, cxip_dev->bypass_clnt_cnt);
|
||||
if (ret) {
|
||||
dev_dbg(&pdev->dev, "bypass client list err:%d, cnt:%d\n",
|
||||
ret, cxip_dev->bypass_clnt_cnt);
|
||||
cxip_dev->bypass_clnt_cnt = 0;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cxip_lm_cdev_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct cxip_lm_cooling_device *cxip_dev = NULL;
|
||||
int ret = 0;
|
||||
struct device_node *np;
|
||||
struct resource *res = NULL;
|
||||
|
||||
np = dev_of_node(&pdev->dev);
|
||||
if (!np) {
|
||||
dev_err(&pdev->dev,
|
||||
"of node not available for cxip_lm cdev\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cxip_dev = devm_kzalloc(&pdev->dev, sizeof(*cxip_dev), GFP_KERNEL);
|
||||
if (!cxip_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = cxip_lm_get_devicetree_data(pdev, cxip_dev, np);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
if (!res) {
|
||||
dev_err(&pdev->dev,
|
||||
"cxip_lm platform get resource failed\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
cxip_dev->cx_ip_reg_base = devm_ioremap(&pdev->dev, res->start,
|
||||
resource_size(res));
|
||||
if (!cxip_dev->cx_ip_reg_base) {
|
||||
dev_err(&pdev->dev, "cxip_lm reg remap failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
cxip_lm_initialize_cxip_hw(cxip_dev);
|
||||
|
||||
/* Set thermal vote till we get first vote from TF */
|
||||
cxip_dev->state = true;
|
||||
cxip_lm_therm_vote_apply(cxip_dev, cxip_dev->state);
|
||||
|
||||
strscpy(cxip_dev->cdev_name, np->name, THERMAL_NAME_LENGTH);
|
||||
cxip_dev->cool_dev = thermal_of_cooling_device_register(
|
||||
np, cxip_dev->cdev_name, cxip_dev,
|
||||
&cxip_lm_device_ops);
|
||||
if (IS_ERR(cxip_dev->cool_dev)) {
|
||||
ret = PTR_ERR(cxip_dev->cool_dev);
|
||||
dev_err(&pdev->dev, "cxip_lm cdev register err:%d\n",
|
||||
ret);
|
||||
cxip_dev->cool_dev = NULL;
|
||||
cxip_lm_therm_vote_apply(cxip_dev->cx_ip_reg_base,
|
||||
false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_set_drvdata(&pdev->dev, cxip_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct of_device_id cxip_lm_cdev_of_match[] = {
|
||||
{.compatible = "qcom,cxip-lm-cooling-device", },
|
||||
{}
|
||||
};
|
||||
|
||||
static struct platform_driver cxip_lm_cdev_driver = {
|
||||
.driver = {
|
||||
.name = CXIP_LM_CDEV_DRIVER,
|
||||
.of_match_table = cxip_lm_cdev_of_match,
|
||||
},
|
||||
.probe = cxip_lm_cdev_probe,
|
||||
.remove = cxip_lm_cdev_remove,
|
||||
};
|
||||
module_platform_driver(cxip_lm_cdev_driver);
|
||||
MODULE_DESCRIPTION(CX IPEAK cooling device driver);
|
||||
MODULE_LICENSE("GPL");
|
202
drivers/thermal/qcom/rpm_smd_cooling_device.c
Normal file
202
drivers/thermal/qcom/rpm_smd_cooling_device.c
Normal file
@ -0,0 +1,202 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2018, 2020, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) "%s:%s " fmt, KBUILD_MODNAME, __func__
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/thermal.h>
|
||||
#include <linux/err.h>
|
||||
#include <soc/qcom/rpm-smd.h>
|
||||
|
||||
#define RPM_SMD_CDEV_DRIVER "rpm-smd-cooling-device"
|
||||
#define RPM_SMD_RES_TYPE 0x6d726874
|
||||
#define RPM_SMD_RES_ID 0
|
||||
#define RPM_SMD_KEY 1
|
||||
|
||||
enum rpm_smd_temp_band {
|
||||
RPM_SMD_COLD_CRITICAL = 1,
|
||||
RPM_SMD_COLD,
|
||||
RPM_SMD_COOL,
|
||||
RPM_SMD_NORMAL,
|
||||
RPM_SMD_WARM,
|
||||
RPM_SMD_HOT,
|
||||
RPM_SMD_HOT_CRITICAL,
|
||||
RPM_SMD_TEMP_MAX_NR,
|
||||
};
|
||||
|
||||
struct rpm_smd_cdev {
|
||||
struct thermal_cooling_device *cool_dev;
|
||||
char dev_name[THERMAL_NAME_LENGTH];
|
||||
unsigned int state;
|
||||
struct msm_rpm_request *rpm_handle;
|
||||
};
|
||||
|
||||
static int rpm_smd_send_request_to_rpm(struct rpm_smd_cdev *rpm_smd_dev,
|
||||
unsigned int state)
|
||||
{
|
||||
unsigned int band;
|
||||
int msg_id, ret;
|
||||
|
||||
if (!rpm_smd_dev || !rpm_smd_dev->rpm_handle) {
|
||||
pr_err("Invalid RPM SMD handle\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (rpm_smd_dev->state == state)
|
||||
return 0;
|
||||
|
||||
/* if state is zero, then send RPM_SMD_NORMAL band */
|
||||
if (!state)
|
||||
band = RPM_SMD_NORMAL;
|
||||
else
|
||||
band = state;
|
||||
|
||||
ret = msm_rpm_add_kvp_data(rpm_smd_dev->rpm_handle, RPM_SMD_KEY,
|
||||
(const uint8_t *)&band, (int)sizeof(band));
|
||||
if (ret) {
|
||||
pr_err("Adding KVP data failed. err:%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
msg_id = msm_rpm_send_request(rpm_smd_dev->rpm_handle);
|
||||
if (!msg_id) {
|
||||
pr_err("RPM SMD send request failed\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
ret = msm_rpm_wait_for_ack(msg_id);
|
||||
if (ret) {
|
||||
pr_err("RPM SMD wait for ACK failed. err:%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
rpm_smd_dev->state = state;
|
||||
|
||||
pr_debug("Requested RPM SMD band:%d for %s\n", band,
|
||||
rpm_smd_dev->dev_name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rpm_smd_get_max_state(struct thermal_cooling_device *cdev,
|
||||
unsigned long *state)
|
||||
{
|
||||
*state = RPM_SMD_TEMP_MAX_NR - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rpm_smd_set_cur_state(struct thermal_cooling_device *cdev,
|
||||
unsigned long state)
|
||||
{
|
||||
struct rpm_smd_cdev *rpm_smd_dev = cdev->devdata;
|
||||
int ret = 0;
|
||||
|
||||
if (state > (RPM_SMD_TEMP_MAX_NR - 1))
|
||||
return -EINVAL;
|
||||
|
||||
ret = rpm_smd_send_request_to_rpm(rpm_smd_dev, (unsigned int)state);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rpm_smd_get_cur_state(struct thermal_cooling_device *cdev,
|
||||
unsigned long *state)
|
||||
{
|
||||
struct rpm_smd_cdev *rpm_smd_dev = cdev->devdata;
|
||||
|
||||
*state = rpm_smd_dev->state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct thermal_cooling_device_ops rpm_smd_device_ops = {
|
||||
.get_max_state = rpm_smd_get_max_state,
|
||||
.get_cur_state = rpm_smd_get_cur_state,
|
||||
.set_cur_state = rpm_smd_set_cur_state,
|
||||
};
|
||||
|
||||
static int rpm_smd_cdev_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct rpm_smd_cdev *rpm_smd_dev =
|
||||
(struct rpm_smd_cdev *)dev_get_drvdata(&pdev->dev);
|
||||
|
||||
if (rpm_smd_dev) {
|
||||
if (rpm_smd_dev->cool_dev)
|
||||
thermal_cooling_device_unregister(
|
||||
rpm_smd_dev->cool_dev);
|
||||
|
||||
rpm_smd_send_request_to_rpm(rpm_smd_dev, RPM_SMD_NORMAL);
|
||||
msm_rpm_free_request(rpm_smd_dev->rpm_handle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rpm_smd_cdev_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct rpm_smd_cdev *rpm_smd_dev;
|
||||
int ret = 0;
|
||||
struct device_node *np;
|
||||
|
||||
np = dev_of_node(&pdev->dev);
|
||||
if (!np) {
|
||||
dev_err(&pdev->dev,
|
||||
"of node not available for rpm smd cooling device\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rpm_smd_dev = devm_kzalloc(&pdev->dev, sizeof(*rpm_smd_dev),
|
||||
GFP_KERNEL);
|
||||
if (!rpm_smd_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
rpm_smd_dev->rpm_handle = msm_rpm_create_request(MSM_RPM_CTX_ACTIVE_SET,
|
||||
RPM_SMD_RES_TYPE, RPM_SMD_RES_ID, 1);
|
||||
if (!rpm_smd_dev->rpm_handle) {
|
||||
dev_err(&pdev->dev, "Creating RPM SMD request handle failed\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
strscpy(rpm_smd_dev->dev_name, np->name, THERMAL_NAME_LENGTH);
|
||||
|
||||
/* Be pro-active and mitigate till we get first vote from TF */
|
||||
rpm_smd_send_request_to_rpm(rpm_smd_dev, RPM_SMD_COLD);
|
||||
|
||||
rpm_smd_dev->cool_dev = thermal_of_cooling_device_register(
|
||||
np, rpm_smd_dev->dev_name, rpm_smd_dev,
|
||||
&rpm_smd_device_ops);
|
||||
if (IS_ERR(rpm_smd_dev->cool_dev)) {
|
||||
ret = PTR_ERR(rpm_smd_dev->cool_dev);
|
||||
dev_err(&pdev->dev, "rpm_smd cdev register err:%d\n", ret);
|
||||
rpm_smd_dev->cool_dev = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_set_drvdata(&pdev->dev, rpm_smd_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct of_device_id rpm_smd_cdev_of_match[] = {
|
||||
{.compatible = "qcom,rpm-smd-cooling-device", },
|
||||
{},
|
||||
};
|
||||
|
||||
static struct platform_driver rpm_smd_cdev_driver = {
|
||||
.driver = {
|
||||
.name = RPM_SMD_CDEV_DRIVER,
|
||||
.of_match_table = rpm_smd_cdev_of_match,
|
||||
},
|
||||
.probe = rpm_smd_cdev_probe,
|
||||
.remove = rpm_smd_cdev_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(rpm_smd_cdev_driver);
|
||||
MODULE_DESCRIPTION(RPM shared memory cooling device);
|
||||
MODULE_LICENSE("GPL");
|
Loading…
Reference in New Issue
Block a user