18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016, NVIDIA CORPORATION.  All rights reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This software is licensed under the terms of the GNU General Public
68c2ecf20Sopenharmony_ci * License version 2, as published by the Free Software Foundation, and
78c2ecf20Sopenharmony_ci * may be copied, distributed, and modified under those terms.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
108c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
118c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
128c2ecf20Sopenharmony_ci * GNU General Public License for more details.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#ifndef __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
178c2ecf20Sopenharmony_ci#define __DRIVERS_THERMAL_TEGRA_SOCTHERM_H
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_CPU               0x0
208c2ecf20Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_GPU		0x4
218c2ecf20Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_MEM		0x8
228c2ecf20Sopenharmony_ci#define THERMCTL_LEVEL0_GROUP_TSENSE		0xc
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define SENSOR_CONFIG2                          8
258c2ecf20Sopenharmony_ci#define SENSOR_CONFIG2_THERMA_MASK		(0xffff << 16)
268c2ecf20Sopenharmony_ci#define SENSOR_CONFIG2_THERMA_SHIFT		16
278c2ecf20Sopenharmony_ci#define SENSOR_CONFIG2_THERMB_MASK		0xffff
288c2ecf20Sopenharmony_ci#define SENSOR_CONFIG2_THERMB_SHIFT		0
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define THERMCTL_THERMTRIP_CTL			0x80
318c2ecf20Sopenharmony_ci/* BITs are defined in device file */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define THERMCTL_INTR_ENABLE			0x88
348c2ecf20Sopenharmony_ci#define THERMCTL_INTR_DISABLE			0x8c
358c2ecf20Sopenharmony_ci#define TH_INTR_UP_DN_EN			0x3
368c2ecf20Sopenharmony_ci#define THERM_IRQ_MEM_MASK			(TH_INTR_UP_DN_EN << 24)
378c2ecf20Sopenharmony_ci#define THERM_IRQ_GPU_MASK			(TH_INTR_UP_DN_EN << 16)
388c2ecf20Sopenharmony_ci#define THERM_IRQ_CPU_MASK			(TH_INTR_UP_DN_EN << 8)
398c2ecf20Sopenharmony_ci#define THERM_IRQ_TSENSE_MASK			(TH_INTR_UP_DN_EN << 0)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define SENSOR_PDIV				0x1c0
428c2ecf20Sopenharmony_ci#define SENSOR_PDIV_CPU_MASK			(0xf << 12)
438c2ecf20Sopenharmony_ci#define SENSOR_PDIV_GPU_MASK			(0xf << 8)
448c2ecf20Sopenharmony_ci#define SENSOR_PDIV_MEM_MASK			(0xf << 4)
458c2ecf20Sopenharmony_ci#define SENSOR_PDIV_PLLX_MASK			(0xf << 0)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define SENSOR_HOTSPOT_OFF			0x1c4
488c2ecf20Sopenharmony_ci#define SENSOR_HOTSPOT_CPU_MASK			(0xff << 16)
498c2ecf20Sopenharmony_ci#define SENSOR_HOTSPOT_GPU_MASK			(0xff << 8)
508c2ecf20Sopenharmony_ci#define SENSOR_HOTSPOT_MEM_MASK			(0xff << 0)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define SENSOR_TEMP1				0x1c8
538c2ecf20Sopenharmony_ci#define SENSOR_TEMP1_CPU_TEMP_MASK		(0xffff << 16)
548c2ecf20Sopenharmony_ci#define SENSOR_TEMP1_GPU_TEMP_MASK		0xffff
558c2ecf20Sopenharmony_ci#define SENSOR_TEMP2				0x1cc
568c2ecf20Sopenharmony_ci#define SENSOR_TEMP2_MEM_TEMP_MASK		(0xffff << 16)
578c2ecf20Sopenharmony_ci#define SENSOR_TEMP2_PLLX_TEMP_MASK		0xffff
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/**
608c2ecf20Sopenharmony_ci * struct tegra_tsensor_group - SOC_THERM sensor group data
618c2ecf20Sopenharmony_ci * @name: short name of the temperature sensor group
628c2ecf20Sopenharmony_ci * @id: numeric ID of the temperature sensor group
638c2ecf20Sopenharmony_ci * @sensor_temp_offset: offset of the SENSOR_TEMP* register
648c2ecf20Sopenharmony_ci * @sensor_temp_mask: bit mask for this sensor group in SENSOR_TEMP* register
658c2ecf20Sopenharmony_ci * @pdiv: the sensor count post-divider to use during runtime
668c2ecf20Sopenharmony_ci * @pdiv_ate: the sensor count post-divider used during automated test
678c2ecf20Sopenharmony_ci * @pdiv_mask: register bitfield mask for the PDIV field for this sensor
688c2ecf20Sopenharmony_ci * @pllx_hotspot_diff: hotspot offset from the PLLX sensor, must be 0 for
698c2ecf20Sopenharmony_ci    PLLX sensor group
708c2ecf20Sopenharmony_ci * @pllx_hotspot_mask: register bitfield mask for the HOTSPOT field
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_cistruct tegra_tsensor_group {
738c2ecf20Sopenharmony_ci	const char *name;
748c2ecf20Sopenharmony_ci	u8 id;
758c2ecf20Sopenharmony_ci	u16 sensor_temp_offset;
768c2ecf20Sopenharmony_ci	u32 sensor_temp_mask;
778c2ecf20Sopenharmony_ci	u32 pdiv, pdiv_ate, pdiv_mask;
788c2ecf20Sopenharmony_ci	u32 pllx_hotspot_diff, pllx_hotspot_mask;
798c2ecf20Sopenharmony_ci	u32 thermtrip_enable_mask;
808c2ecf20Sopenharmony_ci	u32 thermtrip_any_en_mask;
818c2ecf20Sopenharmony_ci	u32 thermtrip_threshold_mask;
828c2ecf20Sopenharmony_ci	u32 thermctl_isr_mask;
838c2ecf20Sopenharmony_ci	u16 thermctl_lvl0_offset;
848c2ecf20Sopenharmony_ci	u32 thermctl_lvl0_up_thresh_mask;
858c2ecf20Sopenharmony_ci	u32 thermctl_lvl0_dn_thresh_mask;
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct tegra_tsensor_configuration {
898c2ecf20Sopenharmony_ci	u32 tall, tiddq_en, ten_count, pdiv, pdiv_ate, tsample, tsample_ate;
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct tegra_tsensor {
938c2ecf20Sopenharmony_ci	const char *name;
948c2ecf20Sopenharmony_ci	const u32 base;
958c2ecf20Sopenharmony_ci	const struct tegra_tsensor_configuration *config;
968c2ecf20Sopenharmony_ci	const u32 calib_fuse_offset;
978c2ecf20Sopenharmony_ci	/*
988c2ecf20Sopenharmony_ci	 * Correction values used to modify values read from
998c2ecf20Sopenharmony_ci	 * calibration fuses
1008c2ecf20Sopenharmony_ci	 */
1018c2ecf20Sopenharmony_ci	const s32 fuse_corr_alpha, fuse_corr_beta;
1028c2ecf20Sopenharmony_ci	const struct tegra_tsensor_group *group;
1038c2ecf20Sopenharmony_ci};
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistruct tsensor_group_thermtrips {
1068c2ecf20Sopenharmony_ci	u8 id;
1078c2ecf20Sopenharmony_ci	u32 temp;
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistruct tegra_soctherm_fuse {
1118c2ecf20Sopenharmony_ci	u32 fuse_base_cp_mask, fuse_base_cp_shift;
1128c2ecf20Sopenharmony_ci	u32 fuse_base_ft_mask, fuse_base_ft_shift;
1138c2ecf20Sopenharmony_ci	u32 fuse_shift_ft_mask, fuse_shift_ft_shift;
1148c2ecf20Sopenharmony_ci	u32 fuse_spare_realignment;
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistruct tsensor_shared_calib {
1188c2ecf20Sopenharmony_ci	u32 base_cp, base_ft;
1198c2ecf20Sopenharmony_ci	u32 actual_temp_cp, actual_temp_ft;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct tegra_soctherm_soc {
1238c2ecf20Sopenharmony_ci	const struct tegra_tsensor *tsensors;
1248c2ecf20Sopenharmony_ci	const unsigned int num_tsensors;
1258c2ecf20Sopenharmony_ci	const struct tegra_tsensor_group **ttgs;
1268c2ecf20Sopenharmony_ci	const unsigned int num_ttgs;
1278c2ecf20Sopenharmony_ci	const struct tegra_soctherm_fuse *tfuse;
1288c2ecf20Sopenharmony_ci	const int thresh_grain;
1298c2ecf20Sopenharmony_ci	const unsigned int bptt;
1308c2ecf20Sopenharmony_ci	const bool use_ccroc;
1318c2ecf20Sopenharmony_ci	struct tsensor_group_thermtrips *thermtrips;
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciint tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse,
1358c2ecf20Sopenharmony_ci			    struct tsensor_shared_calib *shared);
1368c2ecf20Sopenharmony_ciint tegra_calc_tsensor_calib(const struct tegra_tsensor *sensor,
1378c2ecf20Sopenharmony_ci			     const struct tsensor_shared_calib *shared,
1388c2ecf20Sopenharmony_ci			     u32 *calib);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_124_SOC
1418c2ecf20Sopenharmony_ciextern const struct tegra_soctherm_soc tegra124_soctherm;
1428c2ecf20Sopenharmony_ci#endif
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_132_SOC
1458c2ecf20Sopenharmony_ciextern const struct tegra_soctherm_soc tegra132_soctherm;
1468c2ecf20Sopenharmony_ci#endif
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_210_SOC
1498c2ecf20Sopenharmony_ciextern const struct tegra_soctherm_soc tegra210_soctherm;
1508c2ecf20Sopenharmony_ci#endif
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#endif
1538c2ecf20Sopenharmony_ci
154