xref: /linux/drivers/thermal/st/st_thermal.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
260aef7ceSLee Jones /*
360aef7ceSLee Jones  * ST Thermal Sensor Driver for STi series of SoCs
460aef7ceSLee Jones  * Author: Ajit Pal Singh <ajitpal.singh@st.com>
560aef7ceSLee Jones  *
660aef7ceSLee Jones  * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
760aef7ceSLee Jones  */
860aef7ceSLee Jones 
960aef7ceSLee Jones #ifndef __STI_THERMAL_SYSCFG_H
1060aef7ceSLee Jones #define __STI_THERMAL_SYSCFG_H
1160aef7ceSLee Jones 
1260aef7ceSLee Jones #include <linux/interrupt.h>
1360aef7ceSLee Jones #include <linux/platform_device.h>
1460aef7ceSLee Jones #include <linux/regmap.h>
1560aef7ceSLee Jones #include <linux/thermal.h>
1660aef7ceSLee Jones 
1760aef7ceSLee Jones enum st_thermal_regfield_ids {
1860aef7ceSLee Jones 	INT_THRESH_HI = 0, /* Top two regfield IDs are mutually exclusive */
1960aef7ceSLee Jones 	TEMP_PWR = 0,
2060aef7ceSLee Jones 	DCORRECT,
2160aef7ceSLee Jones 	OVERFLOW,
2260aef7ceSLee Jones 	DATA,
2360aef7ceSLee Jones 	INT_ENABLE,
2460aef7ceSLee Jones 
2560aef7ceSLee Jones 	MAX_REGFIELDS
2660aef7ceSLee Jones };
2760aef7ceSLee Jones 
2860aef7ceSLee Jones /* Thermal sensor power states */
2960aef7ceSLee Jones enum st_thermal_power_state {
3060aef7ceSLee Jones 	POWER_OFF = 0,
3160aef7ceSLee Jones 	POWER_ON
3260aef7ceSLee Jones };
3360aef7ceSLee Jones 
3460aef7ceSLee Jones struct st_thermal_sensor;
3560aef7ceSLee Jones 
3660aef7ceSLee Jones /**
3760aef7ceSLee Jones  * Description of private thermal sensor ops.
3860aef7ceSLee Jones  *
3960aef7ceSLee Jones  * @power_ctrl:		Function for powering on/off a sensor. Clock to the
4060aef7ceSLee Jones  *			sensor is also controlled from this function.
4160aef7ceSLee Jones  * @alloc_regfields:	Allocate regmap register fields, specific to a sensor.
4260aef7ceSLee Jones  * @do_memmap_regmap:	Memory map the thermal register space and init regmap
4360aef7ceSLee Jones  *			instance or find regmap instance.
4460aef7ceSLee Jones  * @register_irq:	Register an interrupt handler for a sensor.
4560aef7ceSLee Jones  */
4660aef7ceSLee Jones struct st_thermal_sensor_ops {
4760aef7ceSLee Jones 	int (*power_ctrl)(struct st_thermal_sensor *, enum st_thermal_power_state);
4860aef7ceSLee Jones 	int (*alloc_regfields)(struct st_thermal_sensor *);
4960aef7ceSLee Jones 	int (*regmap_init)(struct st_thermal_sensor *);
5060aef7ceSLee Jones 	int (*register_enable_irq)(struct st_thermal_sensor *);
5160aef7ceSLee Jones 	int (*enable_irq)(struct st_thermal_sensor *);
5260aef7ceSLee Jones };
5360aef7ceSLee Jones 
5460aef7ceSLee Jones /**
5560aef7ceSLee Jones  * Description of thermal driver compatible data.
5660aef7ceSLee Jones  *
5760aef7ceSLee Jones  * @reg_fields:		Pointer to the regfields array for a sensor.
5860aef7ceSLee Jones  * @sys_compat:		Pointer to the syscon node compatible string.
5960aef7ceSLee Jones  * @ops:		Pointer to private thermal ops for a sensor.
6060aef7ceSLee Jones  * @calibration_val:	Default calibration value to be written to the DCORRECT
6160aef7ceSLee Jones  *			register field for a sensor.
6260aef7ceSLee Jones  * @temp_adjust_val:	Value to be added/subtracted from the data read from
6360aef7ceSLee Jones  *			the sensor. If value needs to be added please provide a
6460aef7ceSLee Jones  *			positive value and if it is to be subtracted please
6560aef7ceSLee Jones  *			provide a negative value.
6660aef7ceSLee Jones  * @crit_temp:		The temperature beyond which the SoC should be shutdown
6760aef7ceSLee Jones  *			to prevent damage.
6860aef7ceSLee Jones  */
6960aef7ceSLee Jones struct st_thermal_compat_data {
7060aef7ceSLee Jones 	char *sys_compat;
7160aef7ceSLee Jones 	const struct reg_field *reg_fields;
7260aef7ceSLee Jones 	const struct st_thermal_sensor_ops *ops;
7360aef7ceSLee Jones 	unsigned int calibration_val;
7460aef7ceSLee Jones 	int temp_adjust_val;
7560aef7ceSLee Jones 	int crit_temp;
7660aef7ceSLee Jones };
7760aef7ceSLee Jones 
7860aef7ceSLee Jones struct st_thermal_sensor {
7960aef7ceSLee Jones 	struct device *dev;
8060aef7ceSLee Jones 	struct thermal_zone_device *thermal_dev;
8160aef7ceSLee Jones 	const struct st_thermal_sensor_ops *ops;
8260aef7ceSLee Jones 	const struct st_thermal_compat_data *cdata;
8360aef7ceSLee Jones 	struct clk *clk;
8460aef7ceSLee Jones 	struct regmap *regmap;
8560aef7ceSLee Jones 	struct regmap_field *pwr;
8660aef7ceSLee Jones 	struct regmap_field *dcorrect;
8760aef7ceSLee Jones 	struct regmap_field *overflow;
8860aef7ceSLee Jones 	struct regmap_field *temp_data;
8960aef7ceSLee Jones 	struct regmap_field *int_thresh_hi;
9060aef7ceSLee Jones 	struct regmap_field *int_enable;
9160aef7ceSLee Jones 	int irq;
9260aef7ceSLee Jones 	void __iomem *mmio_base;
9360aef7ceSLee Jones };
9460aef7ceSLee Jones 
9560aef7ceSLee Jones extern int st_thermal_register(struct platform_device *pdev,
9660aef7ceSLee Jones 			       const struct of_device_id *st_thermal_of_match);
97*2ef95331SUwe Kleine-König extern void st_thermal_unregister(struct platform_device *pdev);
9860aef7ceSLee Jones extern const struct dev_pm_ops st_thermal_pm_ops;
9960aef7ceSLee Jones 
10060aef7ceSLee Jones #endif /* __STI_RESET_SYSCFG_H */
101