xref: /linux/drivers/thermal/tegra/soctherm.h (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
1*5c9d6ac2SWei Ni /* SPDX-License-Identifier: GPL-2.0 */
265b6d57cSWei Ni /*
365b6d57cSWei Ni  * Copyright (c) 2014-2016, NVIDIA CORPORATION.  All rights reserved.
465b6d57cSWei Ni  *
565b6d57cSWei Ni  * This software is licensed under the terms of the GNU General Public
665b6d57cSWei Ni  * License version 2, as published by the Free Software Foundation, and
765b6d57cSWei Ni  * may be copied, distributed, and modified under those terms.
865b6d57cSWei Ni  *
965b6d57cSWei Ni  * This program is distributed in the hope that it will be useful,
1065b6d57cSWei Ni  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1165b6d57cSWei Ni  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1265b6d57cSWei Ni  * GNU General Public License for more details.
1365b6d57cSWei Ni  *
1465b6d57cSWei Ni  */
1565b6d57cSWei Ni 
1665b6d57cSWei Ni #ifndef __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
1765b6d57cSWei Ni #define __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
1865b6d57cSWei Ni 
19ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_CPU               0x0
20ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_GPU		0x4
21ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_MEM		0x8
22ce0dbf04SWei Ni #define THERMCTL_LEVEL0_GROUP_TSENSE		0xc
23ce0dbf04SWei Ni 
2465b6d57cSWei Ni #define SENSOR_CONFIG2                          8
25d753b22dSWei Ni #define SENSOR_CONFIG2_THERMA_MASK		(0xffff << 16)
2665b6d57cSWei Ni #define SENSOR_CONFIG2_THERMA_SHIFT		16
27d753b22dSWei Ni #define SENSOR_CONFIG2_THERMB_MASK		0xffff
2865b6d57cSWei Ni #define SENSOR_CONFIG2_THERMB_SHIFT		0
2965b6d57cSWei Ni 
302a895871SWei Ni #define THERMCTL_THERMTRIP_CTL			0x80
312a895871SWei Ni /* BITs are defined in device file */
322a895871SWei Ni 
33*5c9d6ac2SWei Ni #define THERMCTL_INTR_ENABLE			0x88
34*5c9d6ac2SWei Ni #define THERMCTL_INTR_DISABLE			0x8c
35*5c9d6ac2SWei Ni #define TH_INTR_UP_DN_EN			0x3
36*5c9d6ac2SWei Ni #define THERM_IRQ_MEM_MASK			(TH_INTR_UP_DN_EN << 24)
37*5c9d6ac2SWei Ni #define THERM_IRQ_GPU_MASK			(TH_INTR_UP_DN_EN << 16)
38*5c9d6ac2SWei Ni #define THERM_IRQ_CPU_MASK			(TH_INTR_UP_DN_EN << 8)
39*5c9d6ac2SWei Ni #define THERM_IRQ_TSENSE_MASK			(TH_INTR_UP_DN_EN << 0)
40*5c9d6ac2SWei Ni 
4165b6d57cSWei Ni #define SENSOR_PDIV				0x1c0
4265b6d57cSWei Ni #define SENSOR_PDIV_CPU_MASK			(0xf << 12)
4365b6d57cSWei Ni #define SENSOR_PDIV_GPU_MASK			(0xf << 8)
4465b6d57cSWei Ni #define SENSOR_PDIV_MEM_MASK			(0xf << 4)
4565b6d57cSWei Ni #define SENSOR_PDIV_PLLX_MASK			(0xf << 0)
4665b6d57cSWei Ni 
4765b6d57cSWei Ni #define SENSOR_HOTSPOT_OFF			0x1c4
4865b6d57cSWei Ni #define SENSOR_HOTSPOT_CPU_MASK			(0xff << 16)
4965b6d57cSWei Ni #define SENSOR_HOTSPOT_GPU_MASK			(0xff << 8)
5065b6d57cSWei Ni #define SENSOR_HOTSPOT_MEM_MASK			(0xff << 0)
5165b6d57cSWei Ni 
5265b6d57cSWei Ni #define SENSOR_TEMP1				0x1c8
5365b6d57cSWei Ni #define SENSOR_TEMP1_CPU_TEMP_MASK		(0xffff << 16)
5465b6d57cSWei Ni #define SENSOR_TEMP1_GPU_TEMP_MASK		0xffff
5565b6d57cSWei Ni #define SENSOR_TEMP2				0x1cc
5665b6d57cSWei Ni #define SENSOR_TEMP2_MEM_TEMP_MASK		(0xffff << 16)
5765b6d57cSWei Ni #define SENSOR_TEMP2_PLLX_TEMP_MASK		0xffff
5865b6d57cSWei Ni 
5965b6d57cSWei Ni /**
6065b6d57cSWei Ni  * struct tegra_tsensor_group - SOC_THERM sensor group data
6165b6d57cSWei Ni  * @name: short name of the temperature sensor group
6265b6d57cSWei Ni  * @id: numeric ID of the temperature sensor group
6365b6d57cSWei Ni  * @sensor_temp_offset: offset of the SENSOR_TEMP* register
6465b6d57cSWei Ni  * @sensor_temp_mask: bit mask for this sensor group in SENSOR_TEMP* register
6565b6d57cSWei Ni  * @pdiv: the sensor count post-divider to use during runtime
6665b6d57cSWei Ni  * @pdiv_ate: the sensor count post-divider used during automated test
6765b6d57cSWei Ni  * @pdiv_mask: register bitfield mask for the PDIV field for this sensor
6865b6d57cSWei Ni  * @pllx_hotspot_diff: hotspot offset from the PLLX sensor, must be 0 for
6965b6d57cSWei Ni     PLLX sensor group
7065b6d57cSWei Ni  * @pllx_hotspot_mask: register bitfield mask for the HOTSPOT field
7165b6d57cSWei Ni  */
7265b6d57cSWei Ni struct tegra_tsensor_group {
7365b6d57cSWei Ni 	const char *name;
7465b6d57cSWei Ni 	u8 id;
7565b6d57cSWei Ni 	u16 sensor_temp_offset;
7665b6d57cSWei Ni 	u32 sensor_temp_mask;
7765b6d57cSWei Ni 	u32 pdiv, pdiv_ate, pdiv_mask;
7865b6d57cSWei Ni 	u32 pllx_hotspot_diff, pllx_hotspot_mask;
792a895871SWei Ni 	u32 thermtrip_enable_mask;
802a895871SWei Ni 	u32 thermtrip_any_en_mask;
812a895871SWei Ni 	u32 thermtrip_threshold_mask;
82*5c9d6ac2SWei Ni 	u32 thermctl_isr_mask;
83ce0dbf04SWei Ni 	u16 thermctl_lvl0_offset;
84ce0dbf04SWei Ni 	u32 thermctl_lvl0_up_thresh_mask;
85ce0dbf04SWei Ni 	u32 thermctl_lvl0_dn_thresh_mask;
8665b6d57cSWei Ni };
8765b6d57cSWei Ni 
8865b6d57cSWei Ni struct tegra_tsensor_configuration {
8965b6d57cSWei Ni 	u32 tall, tiddq_en, ten_count, pdiv, pdiv_ate, tsample, tsample_ate;
9065b6d57cSWei Ni };
9165b6d57cSWei Ni 
9265b6d57cSWei Ni struct tegra_tsensor {
9365b6d57cSWei Ni 	const char *name;
9465b6d57cSWei Ni 	const u32 base;
9565b6d57cSWei Ni 	const struct tegra_tsensor_configuration *config;
9665b6d57cSWei Ni 	const u32 calib_fuse_offset;
9765b6d57cSWei Ni 	/*
9865b6d57cSWei Ni 	 * Correction values used to modify values read from
9965b6d57cSWei Ni 	 * calibration fuses
10065b6d57cSWei Ni 	 */
10165b6d57cSWei Ni 	const s32 fuse_corr_alpha, fuse_corr_beta;
10265b6d57cSWei Ni 	const struct tegra_tsensor_group *group;
10365b6d57cSWei Ni };
10465b6d57cSWei Ni 
1052510aa56SWei Ni struct tsensor_group_thermtrips {
1062510aa56SWei Ni 	u8 id;
1072510aa56SWei Ni 	u32 temp;
1082510aa56SWei Ni };
1092510aa56SWei Ni 
11065b6d57cSWei Ni struct tegra_soctherm_fuse {
11165b6d57cSWei Ni 	u32 fuse_base_cp_mask, fuse_base_cp_shift;
11265b6d57cSWei Ni 	u32 fuse_base_ft_mask, fuse_base_ft_shift;
11365b6d57cSWei Ni 	u32 fuse_shift_ft_mask, fuse_shift_ft_shift;
11465b6d57cSWei Ni 	u32 fuse_spare_realignment;
11565b6d57cSWei Ni };
11665b6d57cSWei Ni 
11765b6d57cSWei Ni struct tsensor_shared_calib {
11865b6d57cSWei Ni 	u32 base_cp, base_ft;
11965b6d57cSWei Ni 	u32 actual_temp_cp, actual_temp_ft;
12065b6d57cSWei Ni };
12165b6d57cSWei Ni 
12265b6d57cSWei Ni struct tegra_soctherm_soc {
12365b6d57cSWei Ni 	const struct tegra_tsensor *tsensors;
12465b6d57cSWei Ni 	const unsigned int num_tsensors;
12565b6d57cSWei Ni 	const struct tegra_tsensor_group **ttgs;
12665b6d57cSWei Ni 	const unsigned int num_ttgs;
12765b6d57cSWei Ni 	const struct tegra_soctherm_fuse *tfuse;
1282a895871SWei Ni 	const int thresh_grain;
129ce0dbf04SWei Ni 	const unsigned int bptt;
130ce0dbf04SWei Ni 	const bool use_ccroc;
1312510aa56SWei Ni 	struct tsensor_group_thermtrips *thermtrips;
13265b6d57cSWei Ni };
13365b6d57cSWei Ni 
13465b6d57cSWei Ni int tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse,
13565b6d57cSWei Ni 			    struct tsensor_shared_calib *shared);
13665b6d57cSWei Ni int tegra_calc_tsensor_calib(const struct tegra_tsensor *sensor,
13765b6d57cSWei Ni 			     const struct tsensor_shared_calib *shared,
13865b6d57cSWei Ni 			     u32 *calib);
13965b6d57cSWei Ni 
14065b6d57cSWei Ni #ifdef CONFIG_ARCH_TEGRA_124_SOC
14165b6d57cSWei Ni extern const struct tegra_soctherm_soc tegra124_soctherm;
14265b6d57cSWei Ni #endif
14365b6d57cSWei Ni 
14444cb6a7dSWei Ni #ifdef CONFIG_ARCH_TEGRA_132_SOC
14544cb6a7dSWei Ni extern const struct tegra_soctherm_soc tegra132_soctherm;
14644cb6a7dSWei Ni #endif
14744cb6a7dSWei Ni 
1488204104fSWei Ni #ifdef CONFIG_ARCH_TEGRA_210_SOC
1498204104fSWei Ni extern const struct tegra_soctherm_soc tegra210_soctherm;
1508204104fSWei Ni #endif
1518204104fSWei Ni 
15265b6d57cSWei Ni #endif
15365b6d57cSWei Ni 
154