162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * OMAP4 thermal driver.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2011-2012 Texas Instruments Inc.
662306a36Sopenharmony_ci * Contact:
762306a36Sopenharmony_ci *	Eduardo Valentin <eduardo.valentin@ti.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include "ti-thermal.h"
1162306a36Sopenharmony_ci#include "ti-bandgap.h"
1262306a36Sopenharmony_ci#include "omap4xxx-bandgap.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci * OMAP4430 has one instance of thermal sensor for MPU
1662306a36Sopenharmony_ci * need to describe the individual bit fields
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_cistatic struct temp_sensor_registers
1962306a36Sopenharmony_ciomap4430_mpu_temp_sensor_registers = {
2062306a36Sopenharmony_ci	.temp_sensor_ctrl = OMAP4430_TEMP_SENSOR_CTRL_OFFSET,
2162306a36Sopenharmony_ci	.bgap_tempsoff_mask = OMAP4430_BGAP_TEMPSOFF_MASK,
2262306a36Sopenharmony_ci	.bgap_soc_mask = OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK,
2362306a36Sopenharmony_ci	.bgap_eocz_mask = OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK,
2462306a36Sopenharmony_ci	.bgap_dtemp_mask = OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK,
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	.bgap_mode_ctrl = OMAP4430_TEMP_SENSOR_CTRL_OFFSET,
2762306a36Sopenharmony_ci	.mode_ctrl_mask = OMAP4430_CONTINUOUS_MODE_MASK,
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci	.bgap_efuse = OMAP4430_FUSE_OPP_BGAP,
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci/* Thresholds and limits for OMAP4430 MPU temperature sensor */
3362306a36Sopenharmony_cistatic struct temp_sensor_data omap4430_mpu_temp_sensor_data = {
3462306a36Sopenharmony_ci	.min_freq = OMAP4430_MIN_FREQ,
3562306a36Sopenharmony_ci	.max_freq = OMAP4430_MAX_FREQ,
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/*
3962306a36Sopenharmony_ci * Temperature values in milli degree celsius
4062306a36Sopenharmony_ci * ADC code values from 13 to 107, see TRM
4162306a36Sopenharmony_ci * "18.4.10.2.3 ADC Codes Versus Temperature".
4262306a36Sopenharmony_ci */
4362306a36Sopenharmony_cistatic const int
4462306a36Sopenharmony_ciomap4430_adc_to_temp[OMAP4430_ADC_END_VALUE - OMAP4430_ADC_START_VALUE + 1] = {
4562306a36Sopenharmony_ci	-40000, -38000, -35000, -34000, -32000, -30000, -28000, -26000, -24000,
4662306a36Sopenharmony_ci	-22000,	-20000, -18500, -17000, -15000, -13500, -12000, -10000, -8000,
4762306a36Sopenharmony_ci	-6500, -5000, -3500, -1500, 0, 2000, 3500, 5000, 6500, 8500, 10000,
4862306a36Sopenharmony_ci	12000, 13500, 15000, 17000, 19000, 21000, 23000, 25000, 27000, 28500,
4962306a36Sopenharmony_ci	30000, 32000, 33500, 35000, 37000, 38500, 40000, 42000, 43500, 45000,
5062306a36Sopenharmony_ci	47000, 48500, 50000, 52000, 53500, 55000, 57000, 58500, 60000, 62000,
5162306a36Sopenharmony_ci	64000, 66000, 68000, 70000, 71500, 73500, 75000, 77000, 78500, 80000,
5262306a36Sopenharmony_ci	82000, 83500, 85000, 87000, 88500, 90000, 92000, 93500, 95000, 97000,
5362306a36Sopenharmony_ci	98500, 100000, 102000, 103500, 105000, 107000, 109000, 111000, 113000,
5462306a36Sopenharmony_ci	115000, 117000, 118500, 120000, 122000, 123500, 125000,
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* OMAP4430 data */
5862306a36Sopenharmony_ciconst struct ti_bandgap_data omap4430_data = {
5962306a36Sopenharmony_ci	.features = TI_BANDGAP_FEATURE_MODE_CONFIG |
6062306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_CLK_CTRL |
6162306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_POWER_SWITCH |
6262306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_CONT_MODE_ONLY,
6362306a36Sopenharmony_ci	.fclock_name = "bandgap_fclk",
6462306a36Sopenharmony_ci	.div_ck_name = "bandgap_fclk",
6562306a36Sopenharmony_ci	.conv_table = omap4430_adc_to_temp,
6662306a36Sopenharmony_ci	.adc_start_val = OMAP4430_ADC_START_VALUE,
6762306a36Sopenharmony_ci	.adc_end_val = OMAP4430_ADC_END_VALUE,
6862306a36Sopenharmony_ci	.expose_sensor = ti_thermal_expose_sensor,
6962306a36Sopenharmony_ci	.remove_sensor = ti_thermal_remove_sensor,
7062306a36Sopenharmony_ci	.sensors = {
7162306a36Sopenharmony_ci		{
7262306a36Sopenharmony_ci		.registers = &omap4430_mpu_temp_sensor_registers,
7362306a36Sopenharmony_ci		.ts_data = &omap4430_mpu_temp_sensor_data,
7462306a36Sopenharmony_ci		.domain = "cpu",
7562306a36Sopenharmony_ci		.slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4430,
7662306a36Sopenharmony_ci		.constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4430,
7762306a36Sopenharmony_ci		.register_cooling = ti_thermal_register_cpu_cooling,
7862306a36Sopenharmony_ci		.unregister_cooling = ti_thermal_unregister_cpu_cooling,
7962306a36Sopenharmony_ci		},
8062306a36Sopenharmony_ci	},
8162306a36Sopenharmony_ci	.sensor_count = 1,
8262306a36Sopenharmony_ci};
8362306a36Sopenharmony_ci/*
8462306a36Sopenharmony_ci * OMAP4460 has one instance of thermal sensor for MPU
8562306a36Sopenharmony_ci * need to describe the individual bit fields
8662306a36Sopenharmony_ci */
8762306a36Sopenharmony_cistatic struct temp_sensor_registers
8862306a36Sopenharmony_ciomap4460_mpu_temp_sensor_registers = {
8962306a36Sopenharmony_ci	.temp_sensor_ctrl = OMAP4460_TEMP_SENSOR_CTRL_OFFSET,
9062306a36Sopenharmony_ci	.bgap_tempsoff_mask = OMAP4460_BGAP_TEMPSOFF_MASK,
9162306a36Sopenharmony_ci	.bgap_soc_mask = OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK,
9262306a36Sopenharmony_ci	.bgap_eocz_mask = OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK,
9362306a36Sopenharmony_ci	.bgap_dtemp_mask = OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK,
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	.bgap_mask_ctrl = OMAP4460_BGAP_CTRL_OFFSET,
9662306a36Sopenharmony_ci	.mask_hot_mask = OMAP4460_MASK_HOT_MASK,
9762306a36Sopenharmony_ci	.mask_cold_mask = OMAP4460_MASK_COLD_MASK,
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	.bgap_mode_ctrl = OMAP4460_BGAP_CTRL_OFFSET,
10062306a36Sopenharmony_ci	.mode_ctrl_mask = OMAP4460_CONTINUOUS_MODE_MASK,
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	.bgap_counter = OMAP4460_BGAP_COUNTER_OFFSET,
10362306a36Sopenharmony_ci	.counter_mask = OMAP4460_COUNTER_MASK,
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	.bgap_threshold = OMAP4460_BGAP_THRESHOLD_OFFSET,
10662306a36Sopenharmony_ci	.threshold_thot_mask = OMAP4460_T_HOT_MASK,
10762306a36Sopenharmony_ci	.threshold_tcold_mask = OMAP4460_T_COLD_MASK,
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	.tshut_threshold = OMAP4460_BGAP_TSHUT_OFFSET,
11062306a36Sopenharmony_ci	.tshut_hot_mask = OMAP4460_TSHUT_HOT_MASK,
11162306a36Sopenharmony_ci	.tshut_cold_mask = OMAP4460_TSHUT_COLD_MASK,
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	.bgap_status = OMAP4460_BGAP_STATUS_OFFSET,
11462306a36Sopenharmony_ci	.status_hot_mask = OMAP4460_HOT_FLAG_MASK,
11562306a36Sopenharmony_ci	.status_cold_mask = OMAP4460_COLD_FLAG_MASK,
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci	.bgap_efuse = OMAP4460_FUSE_OPP_BGAP,
11862306a36Sopenharmony_ci};
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci/* Thresholds and limits for OMAP4460 MPU temperature sensor */
12162306a36Sopenharmony_cistatic struct temp_sensor_data omap4460_mpu_temp_sensor_data = {
12262306a36Sopenharmony_ci	.tshut_hot = OMAP4460_TSHUT_HOT,
12362306a36Sopenharmony_ci	.tshut_cold = OMAP4460_TSHUT_COLD,
12462306a36Sopenharmony_ci	.t_hot = OMAP4460_T_HOT,
12562306a36Sopenharmony_ci	.t_cold = OMAP4460_T_COLD,
12662306a36Sopenharmony_ci	.min_freq = OMAP4460_MIN_FREQ,
12762306a36Sopenharmony_ci	.max_freq = OMAP4460_MAX_FREQ,
12862306a36Sopenharmony_ci};
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci/*
13162306a36Sopenharmony_ci * Temperature values in milli degree celsius
13262306a36Sopenharmony_ci * ADC code values from 530 to 923
13362306a36Sopenharmony_ci */
13462306a36Sopenharmony_cistatic const int
13562306a36Sopenharmony_ciomap4460_adc_to_temp[OMAP4460_ADC_END_VALUE - OMAP4460_ADC_START_VALUE + 1] = {
13662306a36Sopenharmony_ci	-40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600, -38200,
13762306a36Sopenharmony_ci	-37800, -37300, -36800, -36400, -36000, -35600, -35200, -34800,
13862306a36Sopenharmony_ci	-34300, -33800, -33400, -33000, -32600, -32200, -31800, -31300,
13962306a36Sopenharmony_ci	-30800, -30400, -30000, -29600, -29200, -28700, -28200, -27800,
14062306a36Sopenharmony_ci	-27400, -27000, -26600, -26200, -25700, -25200, -24800, -24400,
14162306a36Sopenharmony_ci	-24000, -23600, -23200, -22700, -22200, -21800, -21400, -21000,
14262306a36Sopenharmony_ci	-20600, -20200, -19700, -19200, -18800, -18400, -18000, -17600,
14362306a36Sopenharmony_ci	-17200, -16700, -16200, -15800, -15400, -15000, -14600, -14200,
14462306a36Sopenharmony_ci	-13700, -13200, -12800, -12400, -12000, -11600, -11200, -10700,
14562306a36Sopenharmony_ci	-10200, -9800, -9400, -9000, -8600, -8200, -7700, -7200, -6800,
14662306a36Sopenharmony_ci	-6400, -6000, -5600, -5200, -4800, -4300, -3800, -3400, -3000,
14762306a36Sopenharmony_ci	-2600, -2200, -1800, -1300, -800, -400, 0, 400, 800, 1200, 1600,
14862306a36Sopenharmony_ci	2100, 2600, 3000, 3400, 3800, 4200, 4600, 5100, 5600, 6000, 6400,
14962306a36Sopenharmony_ci	6800, 7200, 7600, 8000, 8500, 9000, 9400, 9800, 10200, 10600, 11000,
15062306a36Sopenharmony_ci	11400, 11900, 12400, 12800, 13200, 13600, 14000, 14400, 14800,
15162306a36Sopenharmony_ci	15300, 15800, 16200, 16600, 17000, 17400, 17800, 18200, 18700,
15262306a36Sopenharmony_ci	19200, 19600, 20000, 20400, 20800, 21200, 21600, 22100, 22600,
15362306a36Sopenharmony_ci	23000, 23400, 23800, 24200, 24600, 25000, 25400, 25900, 26400,
15462306a36Sopenharmony_ci	26800, 27200, 27600, 28000, 28400, 28800, 29300, 29800, 30200,
15562306a36Sopenharmony_ci	30600, 31000, 31400, 31800, 32200, 32600, 33100, 33600, 34000,
15662306a36Sopenharmony_ci	34400, 34800, 35200, 35600, 36000, 36400, 36800, 37300, 37800,
15762306a36Sopenharmony_ci	38200, 38600, 39000, 39400, 39800, 40200, 40600, 41100, 41600,
15862306a36Sopenharmony_ci	42000, 42400, 42800, 43200, 43600, 44000, 44400, 44800, 45300,
15962306a36Sopenharmony_ci	45800, 46200, 46600, 47000, 47400, 47800, 48200, 48600, 49000,
16062306a36Sopenharmony_ci	49500, 50000, 50400, 50800, 51200, 51600, 52000, 52400, 52800,
16162306a36Sopenharmony_ci	53200, 53700, 54200, 54600, 55000, 55400, 55800, 56200, 56600,
16262306a36Sopenharmony_ci	57000, 57400, 57800, 58200, 58700, 59200, 59600, 60000, 60400,
16362306a36Sopenharmony_ci	60800, 61200, 61600, 62000, 62400, 62800, 63300, 63800, 64200,
16462306a36Sopenharmony_ci	64600, 65000, 65400, 65800, 66200, 66600, 67000, 67400, 67800,
16562306a36Sopenharmony_ci	68200, 68700, 69200, 69600, 70000, 70400, 70800, 71200, 71600,
16662306a36Sopenharmony_ci	72000, 72400, 72800, 73200, 73600, 74100, 74600, 75000, 75400,
16762306a36Sopenharmony_ci	75800, 76200, 76600, 77000, 77400, 77800, 78200, 78600, 79000,
16862306a36Sopenharmony_ci	79400, 79800, 80300, 80800, 81200, 81600, 82000, 82400, 82800,
16962306a36Sopenharmony_ci	83200, 83600, 84000, 84400, 84800, 85200, 85600, 86000, 86400,
17062306a36Sopenharmony_ci	86800, 87300, 87800, 88200, 88600, 89000, 89400, 89800, 90200,
17162306a36Sopenharmony_ci	90600, 91000, 91400, 91800, 92200, 92600, 93000, 93400, 93800,
17262306a36Sopenharmony_ci	94200, 94600, 95000, 95500, 96000, 96400, 96800, 97200, 97600,
17362306a36Sopenharmony_ci	98000, 98400, 98800, 99200, 99600, 100000, 100400, 100800, 101200,
17462306a36Sopenharmony_ci	101600, 102000, 102400, 102800, 103200, 103600, 104000, 104400,
17562306a36Sopenharmony_ci	104800, 105200, 105600, 106100, 106600, 107000, 107400, 107800,
17662306a36Sopenharmony_ci	108200, 108600, 109000, 109400, 109800, 110200, 110600, 111000,
17762306a36Sopenharmony_ci	111400, 111800, 112200, 112600, 113000, 113400, 113800, 114200,
17862306a36Sopenharmony_ci	114600, 115000, 115400, 115800, 116200, 116600, 117000, 117400,
17962306a36Sopenharmony_ci	117800, 118200, 118600, 119000, 119400, 119800, 120200, 120600,
18062306a36Sopenharmony_ci	121000, 121400, 121800, 122200, 122600, 123000, 123400, 123800, 124200,
18162306a36Sopenharmony_ci	124600, 124900, 125000, 125000, 125000, 125000
18262306a36Sopenharmony_ci};
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/* OMAP4460 data */
18562306a36Sopenharmony_ciconst struct ti_bandgap_data omap4460_data = {
18662306a36Sopenharmony_ci	.features = TI_BANDGAP_FEATURE_TSHUT |
18762306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_TSHUT_CONFIG |
18862306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_TALERT |
18962306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_MODE_CONFIG |
19062306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_POWER_SWITCH |
19162306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_CLK_CTRL |
19262306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_COUNTER,
19362306a36Sopenharmony_ci	.fclock_name = "bandgap_ts_fclk",
19462306a36Sopenharmony_ci	.div_ck_name = "div_ts_ck",
19562306a36Sopenharmony_ci	.conv_table = omap4460_adc_to_temp,
19662306a36Sopenharmony_ci	.adc_start_val = OMAP4460_ADC_START_VALUE,
19762306a36Sopenharmony_ci	.adc_end_val = OMAP4460_ADC_END_VALUE,
19862306a36Sopenharmony_ci	.expose_sensor = ti_thermal_expose_sensor,
19962306a36Sopenharmony_ci	.remove_sensor = ti_thermal_remove_sensor,
20062306a36Sopenharmony_ci	.report_temperature = ti_thermal_report_sensor_temperature,
20162306a36Sopenharmony_ci	.sensors = {
20262306a36Sopenharmony_ci		{
20362306a36Sopenharmony_ci		.registers = &omap4460_mpu_temp_sensor_registers,
20462306a36Sopenharmony_ci		.ts_data = &omap4460_mpu_temp_sensor_data,
20562306a36Sopenharmony_ci		.domain = "cpu",
20662306a36Sopenharmony_ci		.slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4460,
20762306a36Sopenharmony_ci		.constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4460,
20862306a36Sopenharmony_ci		.register_cooling = ti_thermal_register_cpu_cooling,
20962306a36Sopenharmony_ci		.unregister_cooling = ti_thermal_unregister_cpu_cooling,
21062306a36Sopenharmony_ci		},
21162306a36Sopenharmony_ci	},
21262306a36Sopenharmony_ci	.sensor_count = 1,
21362306a36Sopenharmony_ci};
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci/* OMAP4470 data */
21662306a36Sopenharmony_ciconst struct ti_bandgap_data omap4470_data = {
21762306a36Sopenharmony_ci	.features = TI_BANDGAP_FEATURE_TSHUT |
21862306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_TSHUT_CONFIG |
21962306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_TALERT |
22062306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_MODE_CONFIG |
22162306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_POWER_SWITCH |
22262306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_CLK_CTRL |
22362306a36Sopenharmony_ci			TI_BANDGAP_FEATURE_COUNTER,
22462306a36Sopenharmony_ci	.fclock_name = "bandgap_ts_fclk",
22562306a36Sopenharmony_ci	.div_ck_name = "div_ts_ck",
22662306a36Sopenharmony_ci	.conv_table = omap4460_adc_to_temp,
22762306a36Sopenharmony_ci	.adc_start_val = OMAP4460_ADC_START_VALUE,
22862306a36Sopenharmony_ci	.adc_end_val = OMAP4460_ADC_END_VALUE,
22962306a36Sopenharmony_ci	.expose_sensor = ti_thermal_expose_sensor,
23062306a36Sopenharmony_ci	.remove_sensor = ti_thermal_remove_sensor,
23162306a36Sopenharmony_ci	.report_temperature = ti_thermal_report_sensor_temperature,
23262306a36Sopenharmony_ci	.sensors = {
23362306a36Sopenharmony_ci		{
23462306a36Sopenharmony_ci		.registers = &omap4460_mpu_temp_sensor_registers,
23562306a36Sopenharmony_ci		.ts_data = &omap4460_mpu_temp_sensor_data,
23662306a36Sopenharmony_ci		.domain = "cpu",
23762306a36Sopenharmony_ci		.slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4470,
23862306a36Sopenharmony_ci		.constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4470,
23962306a36Sopenharmony_ci		.register_cooling = ti_thermal_register_cpu_cooling,
24062306a36Sopenharmony_ci		.unregister_cooling = ti_thermal_unregister_cpu_cooling,
24162306a36Sopenharmony_ci		},
24262306a36Sopenharmony_ci	},
24362306a36Sopenharmony_ci	.sensor_count = 1,
24462306a36Sopenharmony_ci};
245