linux/drivers/thermal/mediatek/auxadc_thermal.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2015 MediaTek Inc.
 * Author: Hanyi Wu <[email protected]>
 *         Sascha Hauer <[email protected]>
 *         Dawei Chien <[email protected]>
 *         Louis Yu <[email protected]>
 */

#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/nvmem-consumer.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/thermal.h>
#include <linux/reset.h>
#include <linux/types.h>

#include "../thermal_hwmon.h"

/* AUXADC Registers */
#define AUXADC_CON1_SET_V
#define AUXADC_CON1_CLR_V
#define AUXADC_CON2_V
#define AUXADC_DATA(channel)

#define APMIXED_SYS_TS_CON0
#define APMIXED_SYS_TS_CON1

/* Thermal Controller Registers */
#define TEMP_MONCTL0
#define TEMP_MONCTL1
#define TEMP_MONCTL2
#define TEMP_MONIDET0
#define TEMP_MONIDET1
#define TEMP_MSRCTL0
#define TEMP_MSRCTL1
#define TEMP_AHBPOLL
#define TEMP_AHBTO
#define TEMP_ADCPNP0
#define TEMP_ADCPNP1
#define TEMP_ADCPNP2
#define TEMP_ADCPNP3

#define TEMP_ADCMUX
#define TEMP_ADCEN
#define TEMP_PNPMUXADDR
#define TEMP_ADCMUXADDR
#define TEMP_ADCENADDR
#define TEMP_ADCVALIDADDR
#define TEMP_ADCVOLTADDR
#define TEMP_RDCTRL
#define TEMP_ADCVALIDMASK
#define TEMP_ADCVOLTAGESHIFT
#define TEMP_ADCWRITECTRL
#define TEMP_MSR0
#define TEMP_MSR1
#define TEMP_MSR2
#define TEMP_MSR3

#define TEMP_SPARE0

#define TEMP_ADCPNP0_1
#define TEMP_ADCPNP1_1
#define TEMP_ADCPNP2_1
#define TEMP_MSR0_1
#define TEMP_MSR1_1
#define TEMP_MSR2_1
#define TEMP_ADCPNP3_1
#define TEMP_MSR3_1

#define PTPCORESEL

#define TEMP_MONCTL1_PERIOD_UNIT(x)

#define TEMP_MONCTL2_FILTER_INTERVAL(x)
#define TEMP_MONCTL2_SENSOR_INTERVAL(x)

#define TEMP_AHBPOLL_ADC_POLL_INTERVAL(x)

#define TEMP_ADCWRITECTRL_ADC_PNP_WRITE
#define TEMP_ADCWRITECTRL_ADC_MUX_WRITE

#define TEMP_ADCVALIDMASK_VALID_HIGH
#define TEMP_ADCVALIDMASK_VALID_POS(bit)

/* MT8173 thermal sensors */
#define MT8173_TS1
#define MT8173_TS2
#define MT8173_TS3
#define MT8173_TS4
#define MT8173_TSABB

/* AUXADC channel 11 is used for the temperature sensors */
#define MT8173_TEMP_AUXADC_CHANNEL

/* The total number of temperature sensors in the MT8173 */
#define MT8173_NUM_SENSORS

/* The number of banks in the MT8173 */
#define MT8173_NUM_ZONES

/* The number of sensing points per bank */
#define MT8173_NUM_SENSORS_PER_ZONE

/* The number of controller in the MT8173 */
#define MT8173_NUM_CONTROLLER

/* The calibration coefficient of sensor  */
#define MT8173_CALIBRATION

/* Valid temperatures range */
#define MT8173_TEMP_MIN
#define MT8173_TEMP_MAX

/*
 * Layout of the fuses providing the calibration data
 * These macros could be used for MT8183, MT8173, MT2701, and MT2712.
 * MT8183 has 6 sensors and needs 6 VTS calibration data.
 * MT8173 has 5 sensors and needs 5 VTS calibration data.
 * MT2701 has 3 sensors and needs 3 VTS calibration data.
 * MT2712 has 4 sensors and needs 4 VTS calibration data.
 */
#define CALIB_BUF0_VALID_V1
#define CALIB_BUF1_ADC_GE_V1(x)
#define CALIB_BUF0_VTS_TS1_V1(x)
#define CALIB_BUF0_VTS_TS2_V1(x)
#define CALIB_BUF1_VTS_TS3_V1(x)
#define CALIB_BUF2_VTS_TS4_V1(x)
#define CALIB_BUF2_VTS_TS5_V1(x)
#define CALIB_BUF2_VTS_TSABB_V1(x)
#define CALIB_BUF0_DEGC_CALI_V1(x)
#define CALIB_BUF0_O_SLOPE_V1(x)
#define CALIB_BUF0_O_SLOPE_SIGN_V1(x)
#define CALIB_BUF1_ID_V1(x)

/*
 * Layout of the fuses providing the calibration data
 * These macros could be used for MT7622.
 */
#define CALIB_BUF0_ADC_OE_V2(x)
#define CALIB_BUF0_ADC_GE_V2(x)
#define CALIB_BUF0_DEGC_CALI_V2(x)
#define CALIB_BUF0_O_SLOPE_V2(x)
#define CALIB_BUF1_VTS_TS1_V2(x)
#define CALIB_BUF1_VTS_TS2_V2(x)
#define CALIB_BUF1_VTS_TSABB_V2(x)
#define CALIB_BUF1_VALID_V2(x)
#define CALIB_BUF1_O_SLOPE_SIGN_V2(x)

/*
 * Layout of the fuses providing the calibration data
 * These macros can be used for MT7981 and MT7986.
 */
#define CALIB_BUF0_ADC_GE_V3(x)
#define CALIB_BUF0_DEGC_CALI_V3(x)
#define CALIB_BUF0_O_SLOPE_V3(x)
#define CALIB_BUF1_VTS_TS1_V3(x)
#define CALIB_BUF1_VTS_TS2_V3(x)
#define CALIB_BUF1_VTS_TSABB_V3(x)
#define CALIB_BUF1_VALID_V3(x)
#define CALIB_BUF1_O_SLOPE_SIGN_V3(x)
#define CALIB_BUF1_ID_V3(x)

enum {};

enum mtk_thermal_version {};

/* MT2701 thermal sensors */
#define MT2701_TS1
#define MT2701_TS2
#define MT2701_TSABB

/* AUXADC channel 11 is used for the temperature sensors */
#define MT2701_TEMP_AUXADC_CHANNEL

/* The total number of temperature sensors in the MT2701 */
#define MT2701_NUM_SENSORS

/* The number of sensing points per bank */
#define MT2701_NUM_SENSORS_PER_ZONE

/* The number of controller in the MT2701 */
#define MT2701_NUM_CONTROLLER

/* The calibration coefficient of sensor  */
#define MT2701_CALIBRATION

/* MT2712 thermal sensors */
#define MT2712_TS1
#define MT2712_TS2
#define MT2712_TS3
#define MT2712_TS4

/* AUXADC channel 11 is used for the temperature sensors */
#define MT2712_TEMP_AUXADC_CHANNEL

/* The total number of temperature sensors in the MT2712 */
#define MT2712_NUM_SENSORS

/* The number of sensing points per bank */
#define MT2712_NUM_SENSORS_PER_ZONE

/* The number of controller in the MT2712 */
#define MT2712_NUM_CONTROLLER

/* The calibration coefficient of sensor  */
#define MT2712_CALIBRATION

#define MT7622_TEMP_AUXADC_CHANNEL
#define MT7622_NUM_SENSORS
#define MT7622_NUM_ZONES
#define MT7622_NUM_SENSORS_PER_ZONE
#define MT7622_TS1
#define MT7622_NUM_CONTROLLER

/* The maximum number of banks */
#define MAX_NUM_ZONES

/* The calibration coefficient of sensor  */
#define MT7622_CALIBRATION

/* MT8183 thermal sensors */
#define MT8183_TS1
#define MT8183_TS2
#define MT8183_TS3
#define MT8183_TS4
#define MT8183_TS5
#define MT8183_TSABB

/* AUXADC channel  is used for the temperature sensors */
#define MT8183_TEMP_AUXADC_CHANNEL

/* The total number of temperature sensors in the MT8183 */
#define MT8183_NUM_SENSORS

/* The number of banks in the MT8183 */
#define MT8183_NUM_ZONES

/* The number of sensing points per bank */
#define MT8183_NUM_SENSORS_PER_ZONE

/* The number of controller in the MT8183 */
#define MT8183_NUM_CONTROLLER

/* The calibration coefficient of sensor  */
#define MT8183_CALIBRATION

/* AUXADC channel 11 is used for the temperature sensors */
#define MT7986_TEMP_AUXADC_CHANNEL

/* The total number of temperature sensors in the MT7986 */
#define MT7986_NUM_SENSORS

/* The number of banks in the MT7986 */
#define MT7986_NUM_ZONES

/* The number of sensing points per bank */
#define MT7986_NUM_SENSORS_PER_ZONE

/* MT7986 thermal sensors */
#define MT7986_TS1

/* The number of controller in the MT7986 */
#define MT7986_NUM_CONTROLLER

/* The calibration coefficient of sensor  */
#define MT7986_CALIBRATION

/* MT8365 */
#define MT8365_TEMP_AUXADC_CHANNEL
#define MT8365_CALIBRATION
#define MT8365_NUM_CONTROLLER
#define MT8365_NUM_BANKS
#define MT8365_NUM_SENSORS
#define MT8365_NUM_SENSORS_PER_ZONE
#define MT8365_TS1
#define MT8365_TS2
#define MT8365_TS3

struct mtk_thermal;

struct thermal_bank_cfg {};

struct mtk_thermal_bank {};

struct mtk_thermal_data {};

struct mtk_thermal {};

/* MT8183 thermal sensor data */
static const int mt8183_bank_data[MT8183_NUM_SENSORS] =;

static const int mt8183_msr[MT8183_NUM_SENSORS_PER_ZONE] =;

static const int mt8183_adcpnp[MT8183_NUM_SENSORS_PER_ZONE] =;

static const int mt8183_mux_values[MT8183_NUM_SENSORS] =;
static const int mt8183_tc_offset[MT8183_NUM_CONTROLLER] =;

static const int mt8183_vts_index[MT8183_NUM_SENSORS] =;

/* MT8173 thermal sensor data */
static const int mt8173_bank_data[MT8173_NUM_ZONES][3] =;

static const int mt8173_msr[MT8173_NUM_SENSORS_PER_ZONE] =;

static const int mt8173_adcpnp[MT8173_NUM_SENSORS_PER_ZONE] =;

static const int mt8173_mux_values[MT8173_NUM_SENSORS] =;
static const int mt8173_tc_offset[MT8173_NUM_CONTROLLER] =;

static const int mt8173_vts_index[MT8173_NUM_SENSORS] =;

/* MT2701 thermal sensor data */
static const int mt2701_bank_data[MT2701_NUM_SENSORS] =;

static const int mt2701_msr[MT2701_NUM_SENSORS_PER_ZONE] =;

static const int mt2701_adcpnp[MT2701_NUM_SENSORS_PER_ZONE] =;

static const int mt2701_mux_values[MT2701_NUM_SENSORS] =;
static const int mt2701_tc_offset[MT2701_NUM_CONTROLLER] =;

static const int mt2701_vts_index[MT2701_NUM_SENSORS] =;

/* MT2712 thermal sensor data */
static const int mt2712_bank_data[MT2712_NUM_SENSORS] =;

static const int mt2712_msr[MT2712_NUM_SENSORS_PER_ZONE] =;

static const int mt2712_adcpnp[MT2712_NUM_SENSORS_PER_ZONE] =;

static const int mt2712_mux_values[MT2712_NUM_SENSORS] =;
static const int mt2712_tc_offset[MT2712_NUM_CONTROLLER] =;

static const int mt2712_vts_index[MT2712_NUM_SENSORS] =;

/* MT7622 thermal sensor data */
static const int mt7622_bank_data[MT7622_NUM_SENSORS] =;
static const int mt7622_msr[MT7622_NUM_SENSORS_PER_ZONE] =;
static const int mt7622_adcpnp[MT7622_NUM_SENSORS_PER_ZONE] =;
static const int mt7622_mux_values[MT7622_NUM_SENSORS] =;
static const int mt7622_vts_index[MT7622_NUM_SENSORS] =;
static const int mt7622_tc_offset[MT7622_NUM_CONTROLLER] =;

/* MT7986 thermal sensor data */
static const int mt7986_bank_data[MT7986_NUM_SENSORS] =;
static const int mt7986_msr[MT7986_NUM_SENSORS_PER_ZONE] =;
static const int mt7986_adcpnp[MT7986_NUM_SENSORS_PER_ZONE] =;
static const int mt7986_mux_values[MT7986_NUM_SENSORS] =;
static const int mt7986_vts_index[MT7986_NUM_SENSORS] =;
static const int mt7986_tc_offset[MT7986_NUM_CONTROLLER] =;

/* MT8365 thermal sensor data */
static const int mt8365_bank_data[MT8365_NUM_SENSORS] =;

static const int mt8365_msr[MT8365_NUM_SENSORS_PER_ZONE] =;

static const int mt8365_adcpnp[MT8365_NUM_SENSORS_PER_ZONE] =;

static const int mt8365_mux_values[MT8365_NUM_SENSORS] =;
static const int mt8365_tc_offset[MT8365_NUM_CONTROLLER] =;

static const int mt8365_vts_index[MT8365_NUM_SENSORS] =;

/*
 * The MT8173 thermal controller has four banks. Each bank can read up to
 * four temperature sensors simultaneously. The MT8173 has a total of 5
 * temperature sensors. We use each bank to measure a certain area of the
 * SoC. Since TS2 is located centrally in the SoC it is influenced by multiple
 * areas, hence is used in different banks.
 *
 * The thermal core only gets the maximum temperature of all banks, so
 * the bank concept wouldn't be necessary here. However, the SVS (Smart
 * Voltage Scaling) unit makes its decisions based on the same bank
 * data, and this indeed needs the temperatures of the individual banks
 * for making better decisions.
 */
static const struct mtk_thermal_data mt8173_thermal_data =;

/*
 * The MT2701 thermal controller has one bank, which can read up to
 * three temperature sensors simultaneously. The MT2701 has a total of 3
 * temperature sensors.
 *
 * The thermal core only gets the maximum temperature of this one bank,
 * so the bank concept wouldn't be necessary here. However, the SVS (Smart
 * Voltage Scaling) unit makes its decisions based on the same bank
 * data.
 */
static const struct mtk_thermal_data mt2701_thermal_data =;

/*
 * The MT8365 thermal controller has one bank, which can read up to
 * four temperature sensors simultaneously. The MT8365 has a total of 3
 * temperature sensors.
 *
 * The thermal core only gets the maximum temperature of this one bank,
 * so the bank concept wouldn't be necessary here. However, the SVS (Smart
 * Voltage Scaling) unit makes its decisions based on the same bank
 * data.
 */
static const struct mtk_thermal_data mt8365_thermal_data =;

/*
 * The MT2712 thermal controller has one bank, which can read up to
 * four temperature sensors simultaneously. The MT2712 has a total of 4
 * temperature sensors.
 *
 * The thermal core only gets the maximum temperature of this one bank,
 * so the bank concept wouldn't be necessary here. However, the SVS (Smart
 * Voltage Scaling) unit makes its decisions based on the same bank
 * data.
 */
static const struct mtk_thermal_data mt2712_thermal_data =;

/*
 * MT7622 have only one sensing point which uses AUXADC Channel 11 for raw data
 * access.
 */
static const struct mtk_thermal_data mt7622_thermal_data =;

/*
 * The MT8183 thermal controller has one bank for the current SW framework.
 * The MT8183 has a total of 6 temperature sensors.
 * There are two thermal controller to control the six sensor.
 * The first one bind 2 sensor, and the other bind 4 sensors.
 * The thermal core only gets the maximum temperature of all sensor, so
 * the bank concept wouldn't be necessary here. However, the SVS (Smart
 * Voltage Scaling) unit makes its decisions based on the same bank
 * data, and this indeed needs the temperatures of the individual banks
 * for making better decisions.
 */
static const struct mtk_thermal_data mt8183_thermal_data =;

/*
 * MT7986 uses AUXADC Channel 11 for raw data access.
 */
static const struct mtk_thermal_data mt7986_thermal_data =;

static bool mtk_thermal_temp_is_valid(int temp)
{}

/**
 * raw_to_mcelsius_v1 - convert a raw ADC value to mcelsius
 * @mt:	The thermal controller
 * @sensno:	sensor number
 * @raw:	raw ADC value
 *
 * This converts the raw ADC value to mcelsius using the SoC specific
 * calibration constants
 */
static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw)
{}

static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw)
{}

static int raw_to_mcelsius_v3(struct mtk_thermal *mt, int sensno, s32 raw)
{}

/**
 * mtk_thermal_get_bank - get bank
 * @bank:	The bank
 *
 * The bank registers are banked, we have to select a bank in the
 * PTPCORESEL register to access it.
 */
static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank)
{}

/**
 * mtk_thermal_put_bank - release bank
 * @bank:	The bank
 *
 * release a bank previously taken with mtk_thermal_get_bank,
 */
static void mtk_thermal_put_bank(struct mtk_thermal_bank *bank)
{}

/**
 * mtk_thermal_bank_temperature - get the temperature of a bank
 * @bank:	The bank
 *
 * The temperature of a bank is considered the maximum temperature of
 * the sensors associated to the bank.
 */
static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
{}

static int mtk_read_temp(struct thermal_zone_device *tz, int *temperature)
{}

static const struct thermal_zone_device_ops mtk_thermal_ops =;

static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
				  u32 apmixed_phys_base, u32 auxadc_phys_base,
				  int ctrl_id)
{}

static u64 of_get_phys_base(struct device_node *np)
{}

static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf)
{}

static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf)
{}

static int mtk_thermal_extract_efuse_v3(struct mtk_thermal *mt, u32 *buf)
{}

static int mtk_thermal_get_calibration_data(struct device *dev,
					    struct mtk_thermal *mt)
{}

static const struct of_device_id mtk_thermal_of_match[] =;
MODULE_DEVICE_TABLE(of, mtk_thermal_of_match);

static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt,
				       void __iomem *apmixed_base)
{}

static void mtk_thermal_release_periodic_ts(struct mtk_thermal *mt,
					    void __iomem *auxadc_base)
{}

static int mtk_thermal_probe(struct platform_device *pdev)
{}

static struct platform_driver mtk_thermal_driver =;

module_platform_driver();

MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();