xref: /rk3399_rockchip-uboot/drivers/thermal/fp9931_thermal.c (revision d14891961a79eab2f5235a020d3fe6d0e915e5fa)
1*d1489196SChaoyi Chen // SPDX-License-Identifier: GPL-2.0
2*d1489196SChaoyi Chen /*
3*d1489196SChaoyi Chen  * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
4*d1489196SChaoyi Chen  */
5*d1489196SChaoyi Chen 
6*d1489196SChaoyi Chen #include <common.h>
7*d1489196SChaoyi Chen #include <dm.h>
8*d1489196SChaoyi Chen #include <thermal.h>
9*d1489196SChaoyi Chen #include <power/pmic.h>
10*d1489196SChaoyi Chen #include <power/fp9931.h>
11*d1489196SChaoyi Chen 
12*d1489196SChaoyi Chen DECLARE_GLOBAL_DATA_PTR;
13*d1489196SChaoyi Chen 
fp9931_get_temp(struct udevice * dev,int * temp)14*d1489196SChaoyi Chen static int fp9931_get_temp(struct udevice *dev, int *temp)
15*d1489196SChaoyi Chen {
16*d1489196SChaoyi Chen 	struct udevice *pmic = dev_get_parent(dev);
17*d1489196SChaoyi Chen 	int ret;
18*d1489196SChaoyi Chen 
19*d1489196SChaoyi Chen 	ret = pmic_reg_read(pmic, FP9931_TMST_VALUE);
20*d1489196SChaoyi Chen 	if (ret < 0)
21*d1489196SChaoyi Chen 		return ret;
22*d1489196SChaoyi Chen 
23*d1489196SChaoyi Chen 	*temp = *((signed char *)&ret);
24*d1489196SChaoyi Chen 
25*d1489196SChaoyi Chen 	return 0;
26*d1489196SChaoyi Chen }
27*d1489196SChaoyi Chen 
28*d1489196SChaoyi Chen static const struct dm_thermal_ops fp9931_thermal_ops = {
29*d1489196SChaoyi Chen 	.get_temp = fp9931_get_temp,
30*d1489196SChaoyi Chen };
31*d1489196SChaoyi Chen 
32*d1489196SChaoyi Chen static const struct udevice_id fp9931_thermal_of_match[] = {
33*d1489196SChaoyi Chen 	{ .compatible = FP9931_THERMAL_COMTATIBLE_NAME },
34*d1489196SChaoyi Chen 	{ }
35*d1489196SChaoyi Chen };
36*d1489196SChaoyi Chen 
37*d1489196SChaoyi Chen U_BOOT_DRIVER(fp9931_thermal) = {
38*d1489196SChaoyi Chen 	.name		= FP9931_THERMAL_COMTATIBLE_NAME,
39*d1489196SChaoyi Chen 	.id		= UCLASS_THERMAL,
40*d1489196SChaoyi Chen 	.of_match	= fp9931_thermal_of_match,
41*d1489196SChaoyi Chen 	.ops		= &fp9931_thermal_ops,
42*d1489196SChaoyi Chen };
43