xref: /linux/drivers/thermal/tegra/soctherm.h (revision ce0dbf04f685d48ffdec64a17ebb4965f828c3ff)
165b6d57cSWei Ni /*
265b6d57cSWei Ni  * Copyright (c) 2014-2016, NVIDIA CORPORATION.  All rights reserved.
365b6d57cSWei Ni  *
465b6d57cSWei Ni  * This software is licensed under the terms of the GNU General Public
565b6d57cSWei Ni  * License version 2, as published by the Free Software Foundation, and
665b6d57cSWei Ni  * may be copied, distributed, and modified under those terms.
765b6d57cSWei Ni  *
865b6d57cSWei Ni  * This program is distributed in the hope that it will be useful,
965b6d57cSWei Ni  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1065b6d57cSWei Ni  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1165b6d57cSWei Ni  * GNU General Public License for more details.
1265b6d57cSWei Ni  *
1365b6d57cSWei Ni  */
1465b6d57cSWei Ni 
1565b6d57cSWei Ni #ifndef __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
1665b6d57cSWei Ni #define __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
1765b6d57cSWei Ni 
18*ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_CPU               0x0
19*ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_GPU		0x4
20*ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_MEM		0x8
21*ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_TSENSE		0xc
22*ce0dbf04SWei Ni 
2365b6d57cSWei Ni #define SENSOR_CONFIG2                          8
24d753b22dSWei Ni #define SENSOR_CONFIG2_THERMA_MASK		(0xffff << 16)
2565b6d57cSWei Ni #define SENSOR_CONFIG2_THERMA_SHIFT		16
26d753b22dSWei Ni #define SENSOR_CONFIG2_THERMB_MASK		0xffff
2765b6d57cSWei Ni #define SENSOR_CONFIG2_THERMB_SHIFT		0
2865b6d57cSWei Ni 
292a895871SWei Ni #define THERMCTL_THERMTRIP_CTL			0x80
302a895871SWei Ni /* BITs are defined in device file */
312a895871SWei Ni 
3265b6d57cSWei Ni #define SENSOR_PDIV				0x1c0
3365b6d57cSWei Ni #define SENSOR_PDIV_CPU_MASK			(0xf << 12)
3465b6d57cSWei Ni #define SENSOR_PDIV_GPU_MASK			(0xf << 8)
3565b6d57cSWei Ni #define SENSOR_PDIV_MEM_MASK			(0xf << 4)
3665b6d57cSWei Ni #define SENSOR_PDIV_PLLX_MASK			(0xf << 0)
3765b6d57cSWei Ni 
3865b6d57cSWei Ni #define SENSOR_HOTSPOT_OFF			0x1c4
3965b6d57cSWei Ni #define SENSOR_HOTSPOT_CPU_MASK			(0xff << 16)
4065b6d57cSWei Ni #define SENSOR_HOTSPOT_GPU_MASK			(0xff << 8)
4165b6d57cSWei Ni #define SENSOR_HOTSPOT_MEM_MASK			(0xff << 0)
4265b6d57cSWei Ni 
4365b6d57cSWei Ni #define SENSOR_TEMP1				0x1c8
4465b6d57cSWei Ni #define SENSOR_TEMP1_CPU_TEMP_MASK		(0xffff << 16)
4565b6d57cSWei Ni #define SENSOR_TEMP1_GPU_TEMP_MASK		0xffff
4665b6d57cSWei Ni #define SENSOR_TEMP2				0x1cc
4765b6d57cSWei Ni #define SENSOR_TEMP2_MEM_TEMP_MASK		(0xffff << 16)
4865b6d57cSWei Ni #define SENSOR_TEMP2_PLLX_TEMP_MASK		0xffff
4965b6d57cSWei Ni 
5065b6d57cSWei Ni /**
5165b6d57cSWei Ni  * struct tegra_tsensor_group - SOC_THERM sensor group data
5265b6d57cSWei Ni  * @name: short name of the temperature sensor group
5365b6d57cSWei Ni  * @id: numeric ID of the temperature sensor group
5465b6d57cSWei Ni  * @sensor_temp_offset: offset of the SENSOR_TEMP* register
5565b6d57cSWei Ni  * @sensor_temp_mask: bit mask for this sensor group in SENSOR_TEMP* register
5665b6d57cSWei Ni  * @pdiv: the sensor count post-divider to use during runtime
5765b6d57cSWei Ni  * @pdiv_ate: the sensor count post-divider used during automated test
5865b6d57cSWei Ni  * @pdiv_mask: register bitfield mask for the PDIV field for this sensor
5965b6d57cSWei Ni  * @pllx_hotspot_diff: hotspot offset from the PLLX sensor, must be 0 for
6065b6d57cSWei Ni     PLLX sensor group
6165b6d57cSWei Ni  * @pllx_hotspot_mask: register bitfield mask for the HOTSPOT field
6265b6d57cSWei Ni  */
6365b6d57cSWei Ni struct tegra_tsensor_group {
6465b6d57cSWei Ni 	const char *name;
6565b6d57cSWei Ni 	u8 id;
6665b6d57cSWei Ni 	u16 sensor_temp_offset;
6765b6d57cSWei Ni 	u32 sensor_temp_mask;
6865b6d57cSWei Ni 	u32 pdiv, pdiv_ate, pdiv_mask;
6965b6d57cSWei Ni 	u32 pllx_hotspot_diff, pllx_hotspot_mask;
702a895871SWei Ni 	u32 thermtrip_enable_mask;
712a895871SWei Ni 	u32 thermtrip_any_en_mask;
722a895871SWei Ni 	u32 thermtrip_threshold_mask;
73*ce0dbf04SWei Ni 	u16 thermctl_lvl0_offset;
74*ce0dbf04SWei Ni 	u32 thermctl_lvl0_up_thresh_mask;
75*ce0dbf04SWei Ni 	u32 thermctl_lvl0_dn_thresh_mask;
7665b6d57cSWei Ni };
7765b6d57cSWei Ni 
7865b6d57cSWei Ni struct tegra_tsensor_configuration {
7965b6d57cSWei Ni 	u32 tall, tiddq_en, ten_count, pdiv, pdiv_ate, tsample, tsample_ate;
8065b6d57cSWei Ni };
8165b6d57cSWei Ni 
8265b6d57cSWei Ni struct tegra_tsensor {
8365b6d57cSWei Ni 	const char *name;
8465b6d57cSWei Ni 	const u32 base;
8565b6d57cSWei Ni 	const struct tegra_tsensor_configuration *config;
8665b6d57cSWei Ni 	const u32 calib_fuse_offset;
8765b6d57cSWei Ni 	/*
8865b6d57cSWei Ni 	 * Correction values used to modify values read from
8965b6d57cSWei Ni 	 * calibration fuses
9065b6d57cSWei Ni 	 */
9165b6d57cSWei Ni 	const s32 fuse_corr_alpha, fuse_corr_beta;
9265b6d57cSWei Ni 	const struct tegra_tsensor_group *group;
9365b6d57cSWei Ni };
9465b6d57cSWei Ni 
9565b6d57cSWei Ni struct tegra_soctherm_fuse {
9665b6d57cSWei Ni 	u32 fuse_base_cp_mask, fuse_base_cp_shift;
9765b6d57cSWei Ni 	u32 fuse_base_ft_mask, fuse_base_ft_shift;
9865b6d57cSWei Ni 	u32 fuse_shift_ft_mask, fuse_shift_ft_shift;
9965b6d57cSWei Ni 	u32 fuse_spare_realignment;
10065b6d57cSWei Ni };
10165b6d57cSWei Ni 
10265b6d57cSWei Ni struct tsensor_shared_calib {
10365b6d57cSWei Ni 	u32 base_cp, base_ft;
10465b6d57cSWei Ni 	u32 actual_temp_cp, actual_temp_ft;
10565b6d57cSWei Ni };
10665b6d57cSWei Ni 
10765b6d57cSWei Ni struct tegra_soctherm_soc {
10865b6d57cSWei Ni 	const struct tegra_tsensor *tsensors;
10965b6d57cSWei Ni 	const unsigned int num_tsensors;
11065b6d57cSWei Ni 	const struct tegra_tsensor_group **ttgs;
11165b6d57cSWei Ni 	const unsigned int num_ttgs;
11265b6d57cSWei Ni 	const struct tegra_soctherm_fuse *tfuse;
1132a895871SWei Ni 	const int thresh_grain;
114*ce0dbf04SWei Ni 	const unsigned int bptt;
115*ce0dbf04SWei Ni 	const bool use_ccroc;
11665b6d57cSWei Ni };
11765b6d57cSWei Ni 
11865b6d57cSWei Ni int tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse,
11965b6d57cSWei Ni 			    struct tsensor_shared_calib *shared);
12065b6d57cSWei Ni int tegra_calc_tsensor_calib(const struct tegra_tsensor *sensor,
12165b6d57cSWei Ni 			     const struct tsensor_shared_calib *shared,
12265b6d57cSWei Ni 			     u32 *calib);
12365b6d57cSWei Ni 
12465b6d57cSWei Ni #ifdef CONFIG_ARCH_TEGRA_124_SOC
12565b6d57cSWei Ni extern const struct tegra_soctherm_soc tegra124_soctherm;
12665b6d57cSWei Ni #endif
12765b6d57cSWei Ni 
12844cb6a7dSWei Ni #ifdef CONFIG_ARCH_TEGRA_132_SOC
12944cb6a7dSWei Ni extern const struct tegra_soctherm_soc tegra132_soctherm;
13044cb6a7dSWei Ni #endif
13144cb6a7dSWei Ni 
1328204104fSWei Ni #ifdef CONFIG_ARCH_TEGRA_210_SOC
1338204104fSWei Ni extern const struct tegra_soctherm_soc tegra210_soctherm;
1348204104fSWei Ni #endif
1358204104fSWei Ni 
13665b6d57cSWei Ni #endif
13765b6d57cSWei Ni 
138