162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * ST Thermal Sensor Driver for STi series of SoCs
462306a36Sopenharmony_ci * Author: Ajit Pal Singh <ajitpal.singh@st.com>
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __STI_THERMAL_SYSCFG_H
1062306a36Sopenharmony_ci#define __STI_THERMAL_SYSCFG_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/interrupt.h>
1362306a36Sopenharmony_ci#include <linux/platform_device.h>
1462306a36Sopenharmony_ci#include <linux/regmap.h>
1562306a36Sopenharmony_ci#include <linux/thermal.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cienum st_thermal_regfield_ids {
1862306a36Sopenharmony_ci	INT_THRESH_HI = 0, /* Top two regfield IDs are mutually exclusive */
1962306a36Sopenharmony_ci	TEMP_PWR = 0,
2062306a36Sopenharmony_ci	DCORRECT,
2162306a36Sopenharmony_ci	OVERFLOW,
2262306a36Sopenharmony_ci	DATA,
2362306a36Sopenharmony_ci	INT_ENABLE,
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	MAX_REGFIELDS
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* Thermal sensor power states */
2962306a36Sopenharmony_cienum st_thermal_power_state {
3062306a36Sopenharmony_ci	POWER_OFF = 0,
3162306a36Sopenharmony_ci	POWER_ON
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistruct st_thermal_sensor;
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/**
3762306a36Sopenharmony_ci * Description of private thermal sensor ops.
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci * @power_ctrl:		Function for powering on/off a sensor. Clock to the
4062306a36Sopenharmony_ci *			sensor is also controlled from this function.
4162306a36Sopenharmony_ci * @alloc_regfields: 	Allocate regmap register fields, specific to a sensor.
4262306a36Sopenharmony_ci * @do_memmap_regmap: 	Memory map the thermal register space and init regmap
4362306a36Sopenharmony_ci *			instance or find regmap instance.
4462306a36Sopenharmony_ci * @register_irq: 	Register an interrupt handler for a sensor.
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_cistruct st_thermal_sensor_ops {
4762306a36Sopenharmony_ci	int (*power_ctrl)(struct st_thermal_sensor *, enum st_thermal_power_state);
4862306a36Sopenharmony_ci	int (*alloc_regfields)(struct st_thermal_sensor *);
4962306a36Sopenharmony_ci	int (*regmap_init)(struct st_thermal_sensor *);
5062306a36Sopenharmony_ci	int (*register_enable_irq)(struct st_thermal_sensor *);
5162306a36Sopenharmony_ci	int (*enable_irq)(struct st_thermal_sensor *);
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/**
5562306a36Sopenharmony_ci * Description of thermal driver compatible data.
5662306a36Sopenharmony_ci *
5762306a36Sopenharmony_ci * @reg_fields:		Pointer to the regfields array for a sensor.
5862306a36Sopenharmony_ci * @sys_compat:		Pointer to the syscon node compatible string.
5962306a36Sopenharmony_ci * @ops: 		Pointer to private thermal ops for a sensor.
6062306a36Sopenharmony_ci * @calibration_val: 	Default calibration value to be written to the DCORRECT
6162306a36Sopenharmony_ci *			register field for a sensor.
6262306a36Sopenharmony_ci * @temp_adjust_val: 	Value to be added/subtracted from the data read from
6362306a36Sopenharmony_ci *			the sensor. If value needs to be added please provide a
6462306a36Sopenharmony_ci *			positive value and if it is to be subtracted please
6562306a36Sopenharmony_ci * 			provide a negative value.
6662306a36Sopenharmony_ci * @crit_temp: 		The temperature beyond which the SoC should be shutdown
6762306a36Sopenharmony_ci * 			to prevent damage.
6862306a36Sopenharmony_ci */
6962306a36Sopenharmony_cistruct st_thermal_compat_data {
7062306a36Sopenharmony_ci	char *sys_compat;
7162306a36Sopenharmony_ci	const struct reg_field *reg_fields;
7262306a36Sopenharmony_ci	const struct st_thermal_sensor_ops *ops;
7362306a36Sopenharmony_ci	unsigned int calibration_val;
7462306a36Sopenharmony_ci	int temp_adjust_val;
7562306a36Sopenharmony_ci	int crit_temp;
7662306a36Sopenharmony_ci};
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_cistruct st_thermal_sensor {
7962306a36Sopenharmony_ci	struct device *dev;
8062306a36Sopenharmony_ci	struct thermal_zone_device *thermal_dev;
8162306a36Sopenharmony_ci	const struct st_thermal_sensor_ops *ops;
8262306a36Sopenharmony_ci	const struct st_thermal_compat_data *cdata;
8362306a36Sopenharmony_ci	struct clk *clk;
8462306a36Sopenharmony_ci	struct regmap *regmap;
8562306a36Sopenharmony_ci	struct regmap_field *pwr;
8662306a36Sopenharmony_ci	struct regmap_field *dcorrect;
8762306a36Sopenharmony_ci	struct regmap_field *overflow;
8862306a36Sopenharmony_ci	struct regmap_field *temp_data;
8962306a36Sopenharmony_ci	struct regmap_field *int_thresh_hi;
9062306a36Sopenharmony_ci	struct regmap_field *int_enable;
9162306a36Sopenharmony_ci	int irq;
9262306a36Sopenharmony_ci	void __iomem *mmio_base;
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciextern int st_thermal_register(struct platform_device *pdev,
9662306a36Sopenharmony_ci			       const struct of_device_id *st_thermal_of_match);
9762306a36Sopenharmony_ciextern void st_thermal_unregister(struct platform_device *pdev);
9862306a36Sopenharmony_ciextern const struct dev_pm_ops st_thermal_pm_ops;
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#endif /* __STI_RESET_SYSCFG_H */
101