162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * This software is licensed under the terms of the GNU General Public 662306a36Sopenharmony_ci * License version 2, as published by the Free Software Foundation, and 762306a36Sopenharmony_ci * may be copied, distributed, and modified under those terms. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, 1062306a36Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 1162306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1262306a36Sopenharmony_ci * GNU General Public License for more details. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci */ 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#ifndef __DRIVERS_THERMAL_TEGRA_SOCTHERM_H 1762306a36Sopenharmony_ci#define __DRIVERS_THERMAL_TEGRA_SOCTHERM_H 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_CPU 0x0 2062306a36Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_GPU 0x4 2162306a36Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_MEM 0x8 2262306a36Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_TSENSE 0xc 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define SENSOR_CONFIG2 8 2562306a36Sopenharmony_ci#define SENSOR_CONFIG2_THERMA_MASK (0xffff << 16) 2662306a36Sopenharmony_ci#define SENSOR_CONFIG2_THERMA_SHIFT 16 2762306a36Sopenharmony_ci#define SENSOR_CONFIG2_THERMB_MASK 0xffff 2862306a36Sopenharmony_ci#define SENSOR_CONFIG2_THERMB_SHIFT 0 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define THERMCTL_THERMTRIP_CTL 0x80 3162306a36Sopenharmony_ci/* BITs are defined in device file */ 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define THERMCTL_INTR_ENABLE 0x88 3462306a36Sopenharmony_ci#define THERMCTL_INTR_DISABLE 0x8c 3562306a36Sopenharmony_ci#define TH_INTR_UP_DN_EN 0x3 3662306a36Sopenharmony_ci#define THERM_IRQ_MEM_MASK (TH_INTR_UP_DN_EN << 24) 3762306a36Sopenharmony_ci#define THERM_IRQ_GPU_MASK (TH_INTR_UP_DN_EN << 16) 3862306a36Sopenharmony_ci#define THERM_IRQ_CPU_MASK (TH_INTR_UP_DN_EN << 8) 3962306a36Sopenharmony_ci#define THERM_IRQ_TSENSE_MASK (TH_INTR_UP_DN_EN << 0) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define SENSOR_PDIV 0x1c0 4262306a36Sopenharmony_ci#define SENSOR_PDIV_CPU_MASK (0xf << 12) 4362306a36Sopenharmony_ci#define SENSOR_PDIV_GPU_MASK (0xf << 8) 4462306a36Sopenharmony_ci#define SENSOR_PDIV_MEM_MASK (0xf << 4) 4562306a36Sopenharmony_ci#define SENSOR_PDIV_PLLX_MASK (0xf << 0) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#define SENSOR_HOTSPOT_OFF 0x1c4 4862306a36Sopenharmony_ci#define SENSOR_HOTSPOT_CPU_MASK (0xff << 16) 4962306a36Sopenharmony_ci#define SENSOR_HOTSPOT_GPU_MASK (0xff << 8) 5062306a36Sopenharmony_ci#define SENSOR_HOTSPOT_MEM_MASK (0xff << 0) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define SENSOR_TEMP1 0x1c8 5362306a36Sopenharmony_ci#define SENSOR_TEMP1_CPU_TEMP_MASK (0xffff << 16) 5462306a36Sopenharmony_ci#define SENSOR_TEMP1_GPU_TEMP_MASK 0xffff 5562306a36Sopenharmony_ci#define SENSOR_TEMP2 0x1cc 5662306a36Sopenharmony_ci#define SENSOR_TEMP2_MEM_TEMP_MASK (0xffff << 16) 5762306a36Sopenharmony_ci#define SENSOR_TEMP2_PLLX_TEMP_MASK 0xffff 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/** 6062306a36Sopenharmony_ci * struct tegra_tsensor_group - SOC_THERM sensor group data 6162306a36Sopenharmony_ci * @name: short name of the temperature sensor group 6262306a36Sopenharmony_ci * @id: numeric ID of the temperature sensor group 6362306a36Sopenharmony_ci * @sensor_temp_offset: offset of the SENSOR_TEMP* register 6462306a36Sopenharmony_ci * @sensor_temp_mask: bit mask for this sensor group in SENSOR_TEMP* register 6562306a36Sopenharmony_ci * @pdiv: the sensor count post-divider to use during runtime 6662306a36Sopenharmony_ci * @pdiv_ate: the sensor count post-divider used during automated test 6762306a36Sopenharmony_ci * @pdiv_mask: register bitfield mask for the PDIV field for this sensor 6862306a36Sopenharmony_ci * @pllx_hotspot_diff: hotspot offset from the PLLX sensor, must be 0 for 6962306a36Sopenharmony_ci PLLX sensor group 7062306a36Sopenharmony_ci * @pllx_hotspot_mask: register bitfield mask for the HOTSPOT field 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_cistruct tegra_tsensor_group { 7362306a36Sopenharmony_ci const char *name; 7462306a36Sopenharmony_ci u8 id; 7562306a36Sopenharmony_ci u16 sensor_temp_offset; 7662306a36Sopenharmony_ci u32 sensor_temp_mask; 7762306a36Sopenharmony_ci u32 pdiv, pdiv_ate, pdiv_mask; 7862306a36Sopenharmony_ci u32 pllx_hotspot_diff, pllx_hotspot_mask; 7962306a36Sopenharmony_ci u32 thermtrip_enable_mask; 8062306a36Sopenharmony_ci u32 thermtrip_any_en_mask; 8162306a36Sopenharmony_ci u32 thermtrip_threshold_mask; 8262306a36Sopenharmony_ci u32 thermctl_isr_mask; 8362306a36Sopenharmony_ci u16 thermctl_lvl0_offset; 8462306a36Sopenharmony_ci u32 thermctl_lvl0_up_thresh_mask; 8562306a36Sopenharmony_ci u32 thermctl_lvl0_dn_thresh_mask; 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_cistruct tegra_tsensor_configuration { 8962306a36Sopenharmony_ci u32 tall, tiddq_en, ten_count, pdiv, pdiv_ate, tsample, tsample_ate; 9062306a36Sopenharmony_ci}; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistruct tegra_tsensor { 9362306a36Sopenharmony_ci const char *name; 9462306a36Sopenharmony_ci const u32 base; 9562306a36Sopenharmony_ci const struct tegra_tsensor_configuration *config; 9662306a36Sopenharmony_ci const u32 calib_fuse_offset; 9762306a36Sopenharmony_ci /* 9862306a36Sopenharmony_ci * Correction values used to modify values read from 9962306a36Sopenharmony_ci * calibration fuses 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_ci const s32 fuse_corr_alpha, fuse_corr_beta; 10262306a36Sopenharmony_ci const struct tegra_tsensor_group *group; 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistruct tsensor_group_thermtrips { 10662306a36Sopenharmony_ci u8 id; 10762306a36Sopenharmony_ci u32 temp; 10862306a36Sopenharmony_ci}; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistruct tegra_soctherm_fuse { 11162306a36Sopenharmony_ci u32 fuse_base_cp_mask, fuse_base_cp_shift; 11262306a36Sopenharmony_ci u32 fuse_base_ft_mask, fuse_base_ft_shift; 11362306a36Sopenharmony_ci u32 fuse_shift_ft_mask, fuse_shift_ft_shift; 11462306a36Sopenharmony_ci u32 fuse_spare_realignment; 11562306a36Sopenharmony_ci}; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_cistruct tsensor_shared_calib { 11862306a36Sopenharmony_ci u32 base_cp, base_ft; 11962306a36Sopenharmony_ci u32 actual_temp_cp, actual_temp_ft; 12062306a36Sopenharmony_ci}; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_cistruct tegra_soctherm_soc { 12362306a36Sopenharmony_ci const struct tegra_tsensor *tsensors; 12462306a36Sopenharmony_ci const unsigned int num_tsensors; 12562306a36Sopenharmony_ci const struct tegra_tsensor_group **ttgs; 12662306a36Sopenharmony_ci const unsigned int num_ttgs; 12762306a36Sopenharmony_ci const struct tegra_soctherm_fuse *tfuse; 12862306a36Sopenharmony_ci const int thresh_grain; 12962306a36Sopenharmony_ci const unsigned int bptt; 13062306a36Sopenharmony_ci const bool use_ccroc; 13162306a36Sopenharmony_ci struct tsensor_group_thermtrips *thermtrips; 13262306a36Sopenharmony_ci}; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ciint tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse, 13562306a36Sopenharmony_ci struct tsensor_shared_calib *shared); 13662306a36Sopenharmony_ciint tegra_calc_tsensor_calib(const struct tegra_tsensor *sensor, 13762306a36Sopenharmony_ci const struct tsensor_shared_calib *shared, 13862306a36Sopenharmony_ci u32 *calib); 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_124_SOC 14162306a36Sopenharmony_ciextern const struct tegra_soctherm_soc tegra124_soctherm; 14262306a36Sopenharmony_ci#endif 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_132_SOC 14562306a36Sopenharmony_ciextern const struct tegra_soctherm_soc tegra132_soctherm; 14662306a36Sopenharmony_ci#endif 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_210_SOC 14962306a36Sopenharmony_ciextern const struct tegra_soctherm_soc tegra210_soctherm; 15062306a36Sopenharmony_ci#endif 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci#endif 15362306a36Sopenharmony_ci 154