xref: /OK3568_Linux_fs/kernel/drivers/thermal/tegra/soctherm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2014-2016, NVIDIA CORPORATION.  All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This software is licensed under the terms of the GNU General Public
6*4882a593Smuzhiyun  * License version 2, as published by the Free Software Foundation, and
7*4882a593Smuzhiyun  * may be copied, distributed, and modified under those terms.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful,
10*4882a593Smuzhiyun  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*4882a593Smuzhiyun  * GNU General Public License for more details.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifndef __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
17*4882a593Smuzhiyun #define __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define THERMCTL_LEVEL0_GROUP_CPU               0x0
20*4882a593Smuzhiyun #define THERMCTL_LEVEL0_GROUP_GPU		0x4
21*4882a593Smuzhiyun #define THERMCTL_LEVEL0_GROUP_MEM		0x8
22*4882a593Smuzhiyun #define THERMCTL_LEVEL0_GROUP_TSENSE		0xc
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define SENSOR_CONFIG2                          8
25*4882a593Smuzhiyun #define SENSOR_CONFIG2_THERMA_MASK		(0xffff << 16)
26*4882a593Smuzhiyun #define SENSOR_CONFIG2_THERMA_SHIFT		16
27*4882a593Smuzhiyun #define SENSOR_CONFIG2_THERMB_MASK		0xffff
28*4882a593Smuzhiyun #define SENSOR_CONFIG2_THERMB_SHIFT		0
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define THERMCTL_THERMTRIP_CTL			0x80
31*4882a593Smuzhiyun /* BITs are defined in device file */
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define THERMCTL_INTR_ENABLE			0x88
34*4882a593Smuzhiyun #define THERMCTL_INTR_DISABLE			0x8c
35*4882a593Smuzhiyun #define TH_INTR_UP_DN_EN			0x3
36*4882a593Smuzhiyun #define THERM_IRQ_MEM_MASK			(TH_INTR_UP_DN_EN << 24)
37*4882a593Smuzhiyun #define THERM_IRQ_GPU_MASK			(TH_INTR_UP_DN_EN << 16)
38*4882a593Smuzhiyun #define THERM_IRQ_CPU_MASK			(TH_INTR_UP_DN_EN << 8)
39*4882a593Smuzhiyun #define THERM_IRQ_TSENSE_MASK			(TH_INTR_UP_DN_EN << 0)
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #define SENSOR_PDIV				0x1c0
42*4882a593Smuzhiyun #define SENSOR_PDIV_CPU_MASK			(0xf << 12)
43*4882a593Smuzhiyun #define SENSOR_PDIV_GPU_MASK			(0xf << 8)
44*4882a593Smuzhiyun #define SENSOR_PDIV_MEM_MASK			(0xf << 4)
45*4882a593Smuzhiyun #define SENSOR_PDIV_PLLX_MASK			(0xf << 0)
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #define SENSOR_HOTSPOT_OFF			0x1c4
48*4882a593Smuzhiyun #define SENSOR_HOTSPOT_CPU_MASK			(0xff << 16)
49*4882a593Smuzhiyun #define SENSOR_HOTSPOT_GPU_MASK			(0xff << 8)
50*4882a593Smuzhiyun #define SENSOR_HOTSPOT_MEM_MASK			(0xff << 0)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define SENSOR_TEMP1				0x1c8
53*4882a593Smuzhiyun #define SENSOR_TEMP1_CPU_TEMP_MASK		(0xffff << 16)
54*4882a593Smuzhiyun #define SENSOR_TEMP1_GPU_TEMP_MASK		0xffff
55*4882a593Smuzhiyun #define SENSOR_TEMP2				0x1cc
56*4882a593Smuzhiyun #define SENSOR_TEMP2_MEM_TEMP_MASK		(0xffff << 16)
57*4882a593Smuzhiyun #define SENSOR_TEMP2_PLLX_TEMP_MASK		0xffff
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /**
60*4882a593Smuzhiyun  * struct tegra_tsensor_group - SOC_THERM sensor group data
61*4882a593Smuzhiyun  * @name: short name of the temperature sensor group
62*4882a593Smuzhiyun  * @id: numeric ID of the temperature sensor group
63*4882a593Smuzhiyun  * @sensor_temp_offset: offset of the SENSOR_TEMP* register
64*4882a593Smuzhiyun  * @sensor_temp_mask: bit mask for this sensor group in SENSOR_TEMP* register
65*4882a593Smuzhiyun  * @pdiv: the sensor count post-divider to use during runtime
66*4882a593Smuzhiyun  * @pdiv_ate: the sensor count post-divider used during automated test
67*4882a593Smuzhiyun  * @pdiv_mask: register bitfield mask for the PDIV field for this sensor
68*4882a593Smuzhiyun  * @pllx_hotspot_diff: hotspot offset from the PLLX sensor, must be 0 for
69*4882a593Smuzhiyun     PLLX sensor group
70*4882a593Smuzhiyun  * @pllx_hotspot_mask: register bitfield mask for the HOTSPOT field
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun struct tegra_tsensor_group {
73*4882a593Smuzhiyun 	const char *name;
74*4882a593Smuzhiyun 	u8 id;
75*4882a593Smuzhiyun 	u16 sensor_temp_offset;
76*4882a593Smuzhiyun 	u32 sensor_temp_mask;
77*4882a593Smuzhiyun 	u32 pdiv, pdiv_ate, pdiv_mask;
78*4882a593Smuzhiyun 	u32 pllx_hotspot_diff, pllx_hotspot_mask;
79*4882a593Smuzhiyun 	u32 thermtrip_enable_mask;
80*4882a593Smuzhiyun 	u32 thermtrip_any_en_mask;
81*4882a593Smuzhiyun 	u32 thermtrip_threshold_mask;
82*4882a593Smuzhiyun 	u32 thermctl_isr_mask;
83*4882a593Smuzhiyun 	u16 thermctl_lvl0_offset;
84*4882a593Smuzhiyun 	u32 thermctl_lvl0_up_thresh_mask;
85*4882a593Smuzhiyun 	u32 thermctl_lvl0_dn_thresh_mask;
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun struct tegra_tsensor_configuration {
89*4882a593Smuzhiyun 	u32 tall, tiddq_en, ten_count, pdiv, pdiv_ate, tsample, tsample_ate;
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun struct tegra_tsensor {
93*4882a593Smuzhiyun 	const char *name;
94*4882a593Smuzhiyun 	const u32 base;
95*4882a593Smuzhiyun 	const struct tegra_tsensor_configuration *config;
96*4882a593Smuzhiyun 	const u32 calib_fuse_offset;
97*4882a593Smuzhiyun 	/*
98*4882a593Smuzhiyun 	 * Correction values used to modify values read from
99*4882a593Smuzhiyun 	 * calibration fuses
100*4882a593Smuzhiyun 	 */
101*4882a593Smuzhiyun 	const s32 fuse_corr_alpha, fuse_corr_beta;
102*4882a593Smuzhiyun 	const struct tegra_tsensor_group *group;
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun struct tsensor_group_thermtrips {
106*4882a593Smuzhiyun 	u8 id;
107*4882a593Smuzhiyun 	u32 temp;
108*4882a593Smuzhiyun };
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun struct tegra_soctherm_fuse {
111*4882a593Smuzhiyun 	u32 fuse_base_cp_mask, fuse_base_cp_shift;
112*4882a593Smuzhiyun 	u32 fuse_base_ft_mask, fuse_base_ft_shift;
113*4882a593Smuzhiyun 	u32 fuse_shift_ft_mask, fuse_shift_ft_shift;
114*4882a593Smuzhiyun 	u32 fuse_spare_realignment;
115*4882a593Smuzhiyun };
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun struct tsensor_shared_calib {
118*4882a593Smuzhiyun 	u32 base_cp, base_ft;
119*4882a593Smuzhiyun 	u32 actual_temp_cp, actual_temp_ft;
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun struct tegra_soctherm_soc {
123*4882a593Smuzhiyun 	const struct tegra_tsensor *tsensors;
124*4882a593Smuzhiyun 	const unsigned int num_tsensors;
125*4882a593Smuzhiyun 	const struct tegra_tsensor_group **ttgs;
126*4882a593Smuzhiyun 	const unsigned int num_ttgs;
127*4882a593Smuzhiyun 	const struct tegra_soctherm_fuse *tfuse;
128*4882a593Smuzhiyun 	const int thresh_grain;
129*4882a593Smuzhiyun 	const unsigned int bptt;
130*4882a593Smuzhiyun 	const bool use_ccroc;
131*4882a593Smuzhiyun 	struct tsensor_group_thermtrips *thermtrips;
132*4882a593Smuzhiyun };
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun int tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse,
135*4882a593Smuzhiyun 			    struct tsensor_shared_calib *shared);
136*4882a593Smuzhiyun int tegra_calc_tsensor_calib(const struct tegra_tsensor *sensor,
137*4882a593Smuzhiyun 			     const struct tsensor_shared_calib *shared,
138*4882a593Smuzhiyun 			     u32 *calib);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun #ifdef CONFIG_ARCH_TEGRA_124_SOC
141*4882a593Smuzhiyun extern const struct tegra_soctherm_soc tegra124_soctherm;
142*4882a593Smuzhiyun #endif
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun #ifdef CONFIG_ARCH_TEGRA_132_SOC
145*4882a593Smuzhiyun extern const struct tegra_soctherm_soc tegra132_soctherm;
146*4882a593Smuzhiyun #endif
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun #ifdef CONFIG_ARCH_TEGRA_210_SOC
149*4882a593Smuzhiyun extern const struct tegra_soctherm_soc tegra210_soctherm;
150*4882a593Smuzhiyun #endif
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun #endif
153*4882a593Smuzhiyun 
154