xref: /openbmc/linux/drivers/thermal/st/st_thermal.h (revision 657c45b3)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * ST Thermal Sensor Driver for STi series of SoCs
4  * Author: Ajit Pal Singh <ajitpal.singh@st.com>
5  *
6  * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
7  */
8 
9 #ifndef __STI_THERMAL_SYSCFG_H
10 #define __STI_THERMAL_SYSCFG_H
11 
12 #include <linux/interrupt.h>
13 #include <linux/platform_device.h>
14 #include <linux/regmap.h>
15 #include <linux/thermal.h>
16 
17 enum st_thermal_regfield_ids {
18 	INT_THRESH_HI = 0, /* Top two regfield IDs are mutually exclusive */
19 	TEMP_PWR = 0,
20 	DCORRECT,
21 	OVERFLOW,
22 	DATA,
23 	INT_ENABLE,
24 
25 	MAX_REGFIELDS
26 };
27 
28 /* Thermal sensor power states */
29 enum st_thermal_power_state {
30 	POWER_OFF = 0,
31 	POWER_ON
32 };
33 
34 struct st_thermal_sensor;
35 
36 /**
37  * Description of private thermal sensor ops.
38  *
39  * @power_ctrl:		Function for powering on/off a sensor. Clock to the
40  *			sensor is also controlled from this function.
41  * @alloc_regfields: 	Allocate regmap register fields, specific to a sensor.
42  * @do_memmap_regmap: 	Memory map the thermal register space and init regmap
43  *			instance or find regmap instance.
44  * @register_irq: 	Register an interrupt handler for a sensor.
45  */
46 struct st_thermal_sensor_ops {
47 	int (*power_ctrl)(struct st_thermal_sensor *, enum st_thermal_power_state);
48 	int (*alloc_regfields)(struct st_thermal_sensor *);
49 	int (*regmap_init)(struct st_thermal_sensor *);
50 	int (*register_enable_irq)(struct st_thermal_sensor *);
51 	int (*enable_irq)(struct st_thermal_sensor *);
52 };
53 
54 /**
55  * Description of thermal driver compatible data.
56  *
57  * @reg_fields:		Pointer to the regfields array for a sensor.
58  * @sys_compat:		Pointer to the syscon node compatible string.
59  * @ops: 		Pointer to private thermal ops for a sensor.
60  * @calibration_val: 	Default calibration value to be written to the DCORRECT
61  *			register field for a sensor.
62  * @temp_adjust_val: 	Value to be added/subtracted from the data read from
63  *			the sensor. If value needs to be added please provide a
64  *			positive value and if it is to be subtracted please
65  * 			provide a negative value.
66  * @crit_temp: 		The temperature beyond which the SoC should be shutdown
67  * 			to prevent damage.
68  */
69 struct st_thermal_compat_data {
70 	char *sys_compat;
71 	const struct reg_field *reg_fields;
72 	const struct st_thermal_sensor_ops *ops;
73 	unsigned int calibration_val;
74 	int temp_adjust_val;
75 	int crit_temp;
76 };
77 
78 struct st_thermal_sensor {
79 	struct device *dev;
80 	struct thermal_zone_device *thermal_dev;
81 	const struct st_thermal_sensor_ops *ops;
82 	const struct st_thermal_compat_data *cdata;
83 	struct clk *clk;
84 	struct regmap *regmap;
85 	struct regmap_field *pwr;
86 	struct regmap_field *dcorrect;
87 	struct regmap_field *overflow;
88 	struct regmap_field *temp_data;
89 	struct regmap_field *int_thresh_hi;
90 	struct regmap_field *int_enable;
91 	int irq;
92 	void __iomem *mmio_base;
93 };
94 
95 extern int st_thermal_register(struct platform_device *pdev,
96 			       const struct of_device_id *st_thermal_of_match);
97 extern void st_thermal_unregister(struct platform_device *pdev);
98 extern const struct dev_pm_ops st_thermal_pm_ops;
99 
100 #endif /* __STI_RESET_SYSCFG_H */
101