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