drm/rockchip: ebc: Add fitipower fp9931 thermal driver

Signed-off-by: Chaoyi Chen <chaoyi.chen@rock-chips.com>
Change-Id: Ic3eec14043c3e8c3b6aae5de03f9b952dc3c6e3e
This commit is contained in:
Chaoyi Chen
2024-07-15 16:21:05 +08:00
committed by Tao Huang
parent 070ed95476
commit 235d738c60
3 changed files with 93 additions and 1 deletions

View File

@@ -4,4 +4,4 @@ obj-$(CONFIG_ROCKCHIP_EBC_DEV) += ebc_pmic.o
obj-$(CONFIG_EPD_TPS65185_SENSOR) += tps65185.o
obj-$(CONFIG_ROCKCHIP_EBC_DEV) += ebc_pmic_mfd.o
obj-$(CONFIG_EPD_SY7636A_PMIC) += sy7636a-regulator.o sy7636a-thermal.o
obj-$(CONFIG_EPD_FP9931_PMIC) += fp9931-regulator.o
obj-$(CONFIG_EPD_FP9931_PMIC) += fp9931-regulator.o fp9931-thermal.o

View File

@@ -74,6 +74,7 @@ static struct pmic_mfd_data silergy_sy7636a = {
static const struct mfd_cell fp9931_cells[] = {
{ .name = "fp9931-regulator", },
{ .name = "fp9931-thermal", },
};
static struct pmic_mfd_data fitipower_fp9931 = {

View File

@@ -0,0 +1,91 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2024 Rockchip Electronics Co., Ltd.
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/thermal.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include "fp9931.h"
struct fp9931_data {
struct regmap *regmap;
struct thermal_zone_device *thermal_zone_dev;
struct regulator *regulator;
};
static int fp9931_get_temp(struct thermal_zone_device *dev, int *res)
{
unsigned int reg_val;
int ret = 0;
struct fp9931_data *data = dev->devdata;
ret = regulator_is_enabled(data->regulator);
if (ret <= 0)
return -EBUSY;
ret = regmap_read(data->regmap, FP9931_TMST_VALUE, &reg_val);
if (!ret) {
*res = *((signed char *)&reg_val);
*res *= 1000;
}
return ret;
}
static const struct thermal_zone_device_ops ops = {
.get_temp = fp9931_get_temp,
};
static int fp9931_thermal_probe(struct platform_device *pdev)
{
struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL);
struct fp9931_data *data;
if (!regmap)
return -EPROBE_DEFER;
data = devm_kzalloc(&pdev->dev, sizeof(struct fp9931_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
platform_set_drvdata(pdev, data);
data->regulator = devm_regulator_get(&pdev->dev, "vcom");
if (IS_ERR(data->regulator)) {
dev_err(&pdev->dev, "Unable to get fp9931 vcom regulator, returned %ld\n",
PTR_ERR(data->regulator));
return PTR_ERR(data->regulator);
}
data->regmap = regmap;
data->thermal_zone_dev = devm_thermal_of_zone_register(pdev->dev.parent, 0, data, &ops);
if (IS_ERR(data->thermal_zone_dev)) {
dev_err(&pdev->dev, "Fail to create fp9931 thermal zone\n");
return PTR_ERR(data->thermal_zone_dev);
}
return 0;
}
static const struct platform_device_id fp9931_thermal_id_table[] = {
{ "fp9931-thermal", },
{ },
};
MODULE_DEVICE_TABLE(platform, fp9931_thermal_id_table);
static struct platform_driver fp9931_thermal_driver = {
.driver = {
.name = "fp9931-thermal",
},
.probe = fp9931_thermal_probe,
.id_table = fp9931_thermal_id_table,
};
module_platform_driver(fp9931_thermal_driver);
MODULE_DESCRIPTION("fp9931 thermal driver");
MODULE_LICENSE("GPL");