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