162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2014-2018, 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#include <linux/module.h>
1762306a36Sopenharmony_ci#include <linux/platform_device.h>
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#include <dt-bindings/thermal/tegra124-soctherm.h>
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#include "soctherm.h"
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_ANY_EN_MASK		(0x1 << 28)
2462306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_MEM_EN_MASK		(0x1 << 27)
2562306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_GPU_EN_MASK		(0x1 << 26)
2662306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_CPU_EN_MASK		(0x1 << 25)
2762306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_TSENSE_EN_MASK	(0x1 << 24)
2862306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_GPUMEM_THRESH_MASK	(0xff << 16)
2962306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_CPU_THRESH_MASK	(0xff << 8)
3062306a36Sopenharmony_ci#define TEGRA132_THERMTRIP_TSENSE_THRESH_MASK	0xff
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define TEGRA132_THERMCTL_LVL0_UP_THRESH_MASK	(0xff << 17)
3362306a36Sopenharmony_ci#define TEGRA132_THERMCTL_LVL0_DN_THRESH_MASK	(0xff << 9)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define TEGRA132_THRESH_GRAIN			1000
3662306a36Sopenharmony_ci#define TEGRA132_BPTT				8
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistatic const struct tegra_tsensor_configuration tegra132_tsensor_config = {
3962306a36Sopenharmony_ci	.tall = 16300,
4062306a36Sopenharmony_ci	.tiddq_en = 1,
4162306a36Sopenharmony_ci	.ten_count = 1,
4262306a36Sopenharmony_ci	.tsample = 120,
4362306a36Sopenharmony_ci	.tsample_ate = 480,
4462306a36Sopenharmony_ci};
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra132_tsensor_group_cpu = {
4762306a36Sopenharmony_ci	.id = TEGRA124_SOCTHERM_SENSOR_CPU,
4862306a36Sopenharmony_ci	.name = "cpu",
4962306a36Sopenharmony_ci	.sensor_temp_offset = SENSOR_TEMP1,
5062306a36Sopenharmony_ci	.sensor_temp_mask = SENSOR_TEMP1_CPU_TEMP_MASK,
5162306a36Sopenharmony_ci	.pdiv = 8,
5262306a36Sopenharmony_ci	.pdiv_ate = 8,
5362306a36Sopenharmony_ci	.pdiv_mask = SENSOR_PDIV_CPU_MASK,
5462306a36Sopenharmony_ci	.pllx_hotspot_diff = 10,
5562306a36Sopenharmony_ci	.pllx_hotspot_mask = SENSOR_HOTSPOT_CPU_MASK,
5662306a36Sopenharmony_ci	.thermtrip_any_en_mask = TEGRA132_THERMTRIP_ANY_EN_MASK,
5762306a36Sopenharmony_ci	.thermtrip_enable_mask = TEGRA132_THERMTRIP_CPU_EN_MASK,
5862306a36Sopenharmony_ci	.thermtrip_threshold_mask = TEGRA132_THERMTRIP_CPU_THRESH_MASK,
5962306a36Sopenharmony_ci	.thermctl_isr_mask = THERM_IRQ_CPU_MASK,
6062306a36Sopenharmony_ci	.thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_CPU,
6162306a36Sopenharmony_ci	.thermctl_lvl0_up_thresh_mask = TEGRA132_THERMCTL_LVL0_UP_THRESH_MASK,
6262306a36Sopenharmony_ci	.thermctl_lvl0_dn_thresh_mask = TEGRA132_THERMCTL_LVL0_DN_THRESH_MASK,
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra132_tsensor_group_gpu = {
6662306a36Sopenharmony_ci	.id = TEGRA124_SOCTHERM_SENSOR_GPU,
6762306a36Sopenharmony_ci	.name = "gpu",
6862306a36Sopenharmony_ci	.sensor_temp_offset = SENSOR_TEMP1,
6962306a36Sopenharmony_ci	.sensor_temp_mask = SENSOR_TEMP1_GPU_TEMP_MASK,
7062306a36Sopenharmony_ci	.pdiv = 8,
7162306a36Sopenharmony_ci	.pdiv_ate = 8,
7262306a36Sopenharmony_ci	.pdiv_mask = SENSOR_PDIV_GPU_MASK,
7362306a36Sopenharmony_ci	.pllx_hotspot_diff = 5,
7462306a36Sopenharmony_ci	.pllx_hotspot_mask = SENSOR_HOTSPOT_GPU_MASK,
7562306a36Sopenharmony_ci	.thermtrip_any_en_mask = TEGRA132_THERMTRIP_ANY_EN_MASK,
7662306a36Sopenharmony_ci	.thermtrip_enable_mask = TEGRA132_THERMTRIP_GPU_EN_MASK,
7762306a36Sopenharmony_ci	.thermtrip_threshold_mask = TEGRA132_THERMTRIP_GPUMEM_THRESH_MASK,
7862306a36Sopenharmony_ci	.thermctl_isr_mask = THERM_IRQ_GPU_MASK,
7962306a36Sopenharmony_ci	.thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_GPU,
8062306a36Sopenharmony_ci	.thermctl_lvl0_up_thresh_mask = TEGRA132_THERMCTL_LVL0_UP_THRESH_MASK,
8162306a36Sopenharmony_ci	.thermctl_lvl0_dn_thresh_mask = TEGRA132_THERMCTL_LVL0_DN_THRESH_MASK,
8262306a36Sopenharmony_ci};
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra132_tsensor_group_pll = {
8562306a36Sopenharmony_ci	.id = TEGRA124_SOCTHERM_SENSOR_PLLX,
8662306a36Sopenharmony_ci	.name = "pll",
8762306a36Sopenharmony_ci	.sensor_temp_offset = SENSOR_TEMP2,
8862306a36Sopenharmony_ci	.sensor_temp_mask = SENSOR_TEMP2_PLLX_TEMP_MASK,
8962306a36Sopenharmony_ci	.pdiv = 8,
9062306a36Sopenharmony_ci	.pdiv_ate = 8,
9162306a36Sopenharmony_ci	.pdiv_mask = SENSOR_PDIV_PLLX_MASK,
9262306a36Sopenharmony_ci	.thermtrip_any_en_mask = TEGRA132_THERMTRIP_ANY_EN_MASK,
9362306a36Sopenharmony_ci	.thermtrip_enable_mask = TEGRA132_THERMTRIP_TSENSE_EN_MASK,
9462306a36Sopenharmony_ci	.thermtrip_threshold_mask = TEGRA132_THERMTRIP_TSENSE_THRESH_MASK,
9562306a36Sopenharmony_ci	.thermctl_isr_mask = THERM_IRQ_TSENSE_MASK,
9662306a36Sopenharmony_ci	.thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_TSENSE,
9762306a36Sopenharmony_ci	.thermctl_lvl0_up_thresh_mask = TEGRA132_THERMCTL_LVL0_UP_THRESH_MASK,
9862306a36Sopenharmony_ci	.thermctl_lvl0_dn_thresh_mask = TEGRA132_THERMCTL_LVL0_DN_THRESH_MASK,
9962306a36Sopenharmony_ci};
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra132_tsensor_group_mem = {
10262306a36Sopenharmony_ci	.id = TEGRA124_SOCTHERM_SENSOR_MEM,
10362306a36Sopenharmony_ci	.name = "mem",
10462306a36Sopenharmony_ci	.sensor_temp_offset = SENSOR_TEMP2,
10562306a36Sopenharmony_ci	.sensor_temp_mask = SENSOR_TEMP2_MEM_TEMP_MASK,
10662306a36Sopenharmony_ci	.pdiv = 8,
10762306a36Sopenharmony_ci	.pdiv_ate = 8,
10862306a36Sopenharmony_ci	.pdiv_mask = SENSOR_PDIV_MEM_MASK,
10962306a36Sopenharmony_ci	.pllx_hotspot_diff = 0,
11062306a36Sopenharmony_ci	.pllx_hotspot_mask = SENSOR_HOTSPOT_MEM_MASK,
11162306a36Sopenharmony_ci	.thermtrip_any_en_mask = TEGRA132_THERMTRIP_ANY_EN_MASK,
11262306a36Sopenharmony_ci	.thermtrip_enable_mask = TEGRA132_THERMTRIP_MEM_EN_MASK,
11362306a36Sopenharmony_ci	.thermtrip_threshold_mask = TEGRA132_THERMTRIP_GPUMEM_THRESH_MASK,
11462306a36Sopenharmony_ci	.thermctl_isr_mask = THERM_IRQ_MEM_MASK,
11562306a36Sopenharmony_ci	.thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_MEM,
11662306a36Sopenharmony_ci	.thermctl_lvl0_up_thresh_mask = TEGRA132_THERMCTL_LVL0_UP_THRESH_MASK,
11762306a36Sopenharmony_ci	.thermctl_lvl0_dn_thresh_mask = TEGRA132_THERMCTL_LVL0_DN_THRESH_MASK,
11862306a36Sopenharmony_ci};
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_cistatic const struct tegra_tsensor_group *tegra132_tsensor_groups[] = {
12162306a36Sopenharmony_ci	&tegra132_tsensor_group_cpu,
12262306a36Sopenharmony_ci	&tegra132_tsensor_group_gpu,
12362306a36Sopenharmony_ci	&tegra132_tsensor_group_pll,
12462306a36Sopenharmony_ci	&tegra132_tsensor_group_mem,
12562306a36Sopenharmony_ci};
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_cistatic struct tegra_tsensor tegra132_tsensors[] = {
12862306a36Sopenharmony_ci	{
12962306a36Sopenharmony_ci		.name = "cpu0",
13062306a36Sopenharmony_ci		.base = 0xc0,
13162306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
13262306a36Sopenharmony_ci		.calib_fuse_offset = 0x098,
13362306a36Sopenharmony_ci		.fuse_corr_alpha = 1126600,
13462306a36Sopenharmony_ci		.fuse_corr_beta = -9433500,
13562306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_cpu,
13662306a36Sopenharmony_ci	}, {
13762306a36Sopenharmony_ci		.name = "cpu1",
13862306a36Sopenharmony_ci		.base = 0xe0,
13962306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
14062306a36Sopenharmony_ci		.calib_fuse_offset = 0x084,
14162306a36Sopenharmony_ci		.fuse_corr_alpha = 1110800,
14262306a36Sopenharmony_ci		.fuse_corr_beta = -7383000,
14362306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_cpu,
14462306a36Sopenharmony_ci	}, {
14562306a36Sopenharmony_ci		.name = "cpu2",
14662306a36Sopenharmony_ci		.base = 0x100,
14762306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
14862306a36Sopenharmony_ci		.calib_fuse_offset = 0x088,
14962306a36Sopenharmony_ci		.fuse_corr_alpha = 1113800,
15062306a36Sopenharmony_ci		.fuse_corr_beta = -6215200,
15162306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_cpu,
15262306a36Sopenharmony_ci	}, {
15362306a36Sopenharmony_ci		.name = "cpu3",
15462306a36Sopenharmony_ci		.base = 0x120,
15562306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
15662306a36Sopenharmony_ci		.calib_fuse_offset = 0x12c,
15762306a36Sopenharmony_ci		.fuse_corr_alpha = 1129600,
15862306a36Sopenharmony_ci		.fuse_corr_beta = -8196100,
15962306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_cpu,
16062306a36Sopenharmony_ci	}, {
16162306a36Sopenharmony_ci		.name = "mem0",
16262306a36Sopenharmony_ci		.base = 0x140,
16362306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
16462306a36Sopenharmony_ci		.calib_fuse_offset = 0x158,
16562306a36Sopenharmony_ci		.fuse_corr_alpha = 1132900,
16662306a36Sopenharmony_ci		.fuse_corr_beta = -6755300,
16762306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_mem,
16862306a36Sopenharmony_ci	}, {
16962306a36Sopenharmony_ci		.name = "mem1",
17062306a36Sopenharmony_ci		.base = 0x160,
17162306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
17262306a36Sopenharmony_ci		.calib_fuse_offset = 0x15c,
17362306a36Sopenharmony_ci		.fuse_corr_alpha = 1142300,
17462306a36Sopenharmony_ci		.fuse_corr_beta = -7374200,
17562306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_mem,
17662306a36Sopenharmony_ci	}, {
17762306a36Sopenharmony_ci		.name = "gpu",
17862306a36Sopenharmony_ci		.base = 0x180,
17962306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
18062306a36Sopenharmony_ci		.calib_fuse_offset = 0x154,
18162306a36Sopenharmony_ci		.fuse_corr_alpha = 1125100,
18262306a36Sopenharmony_ci		.fuse_corr_beta = -6350400,
18362306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_gpu,
18462306a36Sopenharmony_ci	}, {
18562306a36Sopenharmony_ci		.name = "pllx",
18662306a36Sopenharmony_ci		.base = 0x1a0,
18762306a36Sopenharmony_ci		.config = &tegra132_tsensor_config,
18862306a36Sopenharmony_ci		.calib_fuse_offset = 0x160,
18962306a36Sopenharmony_ci		.fuse_corr_alpha = 1118100,
19062306a36Sopenharmony_ci		.fuse_corr_beta = -8208800,
19162306a36Sopenharmony_ci		.group = &tegra132_tsensor_group_pll,
19262306a36Sopenharmony_ci	},
19362306a36Sopenharmony_ci};
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci/*
19662306a36Sopenharmony_ci * Mask/shift bits in FUSE_TSENSOR_COMMON and
19762306a36Sopenharmony_ci * FUSE_TSENSOR_COMMON, which are described in
19862306a36Sopenharmony_ci * tegra_soctherm_fuse.c
19962306a36Sopenharmony_ci */
20062306a36Sopenharmony_cistatic const struct tegra_soctherm_fuse tegra132_soctherm_fuse = {
20162306a36Sopenharmony_ci	.fuse_base_cp_mask = 0x3ff,
20262306a36Sopenharmony_ci	.fuse_base_cp_shift = 0,
20362306a36Sopenharmony_ci	.fuse_base_ft_mask = 0x7ff << 10,
20462306a36Sopenharmony_ci	.fuse_base_ft_shift = 10,
20562306a36Sopenharmony_ci	.fuse_shift_ft_mask = 0x1f << 21,
20662306a36Sopenharmony_ci	.fuse_shift_ft_shift = 21,
20762306a36Sopenharmony_ci	.fuse_spare_realignment = 0x1fc,
20862306a36Sopenharmony_ci};
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ciconst struct tegra_soctherm_soc tegra132_soctherm = {
21162306a36Sopenharmony_ci	.tsensors = tegra132_tsensors,
21262306a36Sopenharmony_ci	.num_tsensors = ARRAY_SIZE(tegra132_tsensors),
21362306a36Sopenharmony_ci	.ttgs = tegra132_tsensor_groups,
21462306a36Sopenharmony_ci	.num_ttgs = ARRAY_SIZE(tegra132_tsensor_groups),
21562306a36Sopenharmony_ci	.tfuse = &tegra132_soctherm_fuse,
21662306a36Sopenharmony_ci	.thresh_grain = TEGRA132_THRESH_GRAIN,
21762306a36Sopenharmony_ci	.bptt = TEGRA132_BPTT,
21862306a36Sopenharmony_ci	.use_ccroc = true,
21962306a36Sopenharmony_ci};
220