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