linux/drivers/thermal/rockchip_thermal.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2014-2016, Fuzhou Rockchip Electronics Co., Ltd
 * Caesar Wang <[email protected]>
 */

#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/reset.h>
#include <linux/thermal.h>
#include <linux/mfd/syscon.h>
#include <linux/pinctrl/consumer.h>

/*
 * If the temperature over a period of time High,
 * the resulting TSHUT gave CRU module,let it reset the entire chip,
 * or via GPIO give PMIC.
 */
enum tshut_mode {};

/*
 * The system Temperature Sensors tshut(tshut) polarity
 * the bit 8 is tshut polarity.
 * 0: low active, 1: high active
 */
enum tshut_polarity {};

/*
 * The conversion table has the adc value and temperature.
 * ADC_DECREMENT: the adc value is of diminishing.(e.g. rk3288_code_table)
 * ADC_INCREMENT: the adc value is incremental.(e.g. rk3368_code_table)
 */
enum adc_sort_mode {};

#include "thermal_hwmon.h"

/**
 * struct chip_tsadc_table - hold information about chip-specific differences
 * @id: conversion table
 * @length: size of conversion table
 * @data_mask: mask to apply on data inputs
 * @mode: sort mode of this adc variant (incrementing or decrementing)
 */
struct chip_tsadc_table {};

/**
 * struct rockchip_tsadc_chip - hold the private data of tsadc chip
 * @chn_offset: the channel offset of the first channel
 * @chn_num: the channel number of tsadc chip
 * @tshut_temp: the hardware-controlled shutdown temperature value
 * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO)
 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
 * @initialize: SoC special initialize tsadc controller method
 * @irq_ack: clear the interrupt
 * @control: enable/disable method for the tsadc controller
 * @get_temp: get the temperature
 * @set_alarm_temp: set the high temperature interrupt
 * @set_tshut_temp: set the hardware-controlled shutdown temperature
 * @set_tshut_mode: set the hardware-controlled shutdown mode
 * @table: the chip-specific conversion table
 */
struct rockchip_tsadc_chip {};

/**
 * struct rockchip_thermal_sensor - hold the information of thermal sensor
 * @thermal:  pointer to the platform/configuration data
 * @tzd: pointer to a thermal zone
 * @id: identifier of the thermal sensor
 */
struct rockchip_thermal_sensor {};

/**
 * struct rockchip_thermal_data - hold the private data of thermal driver
 * @chip: pointer to the platform/configuration data
 * @pdev: platform device of thermal
 * @reset: the reset controller of tsadc
 * @sensors: array of thermal sensors
 * @clk: the controller clock is divided by the exteral 24MHz
 * @pclk: the advanced peripherals bus clock
 * @grf: the general register file will be used to do static set by software
 * @regs: the base address of tsadc controller
 * @tshut_temp: the hardware-controlled shutdown temperature value
 * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO)
 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
 */
struct rockchip_thermal_data {};

/*
 * TSADC Sensor Register description:
 *
 * TSADCV2_* are used for RK3288 SoCs, the other chips can reuse it.
 * TSADCV3_* are used for newer SoCs than RK3288. (e.g: RK3228, RK3399)
 *
 */
#define TSADCV2_USER_CON
#define TSADCV2_AUTO_CON
#define TSADCV2_INT_EN
#define TSADCV2_INT_PD
#define TSADCV3_AUTO_SRC_CON
#define TSADCV3_HT_INT_EN
#define TSADCV3_HSHUT_GPIO_INT_EN
#define TSADCV3_HSHUT_CRU_INT_EN
#define TSADCV3_INT_PD
#define TSADCV3_HSHUT_PD
#define TSADCV2_DATA(chn)
#define TSADCV2_COMP_INT(chn)
#define TSADCV2_COMP_SHUT(chn)
#define TSADCV3_DATA(chn)
#define TSADCV3_COMP_INT(chn)
#define TSADCV3_COMP_SHUT(chn)
#define TSADCV2_HIGHT_INT_DEBOUNCE
#define TSADCV2_HIGHT_TSHUT_DEBOUNCE
#define TSADCV3_HIGHT_INT_DEBOUNCE
#define TSADCV3_HIGHT_TSHUT_DEBOUNCE
#define TSADCV2_AUTO_PERIOD
#define TSADCV2_AUTO_PERIOD_HT
#define TSADCV3_AUTO_PERIOD
#define TSADCV3_AUTO_PERIOD_HT

#define TSADCV2_AUTO_EN
#define TSADCV2_AUTO_EN_MASK
#define TSADCV2_AUTO_SRC_EN(chn)
#define TSADCV3_AUTO_SRC_EN(chn)
#define TSADCV3_AUTO_SRC_EN_MASK(chn)
#define TSADCV2_AUTO_TSHUT_POLARITY_HIGH
#define TSADCV2_AUTO_TSHUT_POLARITY_MASK

#define TSADCV3_AUTO_Q_SEL_EN

#define TSADCV2_INT_SRC_EN(chn)
#define TSADCV2_INT_SRC_EN_MASK(chn)
#define TSADCV2_SHUT_2GPIO_SRC_EN(chn)
#define TSADCV2_SHUT_2CRU_SRC_EN(chn)

#define TSADCV2_INT_PD_CLEAR_MASK
#define TSADCV3_INT_PD_CLEAR_MASK
#define TSADCV4_INT_PD_CLEAR_MASK

#define TSADCV2_DATA_MASK
#define TSADCV3_DATA_MASK
#define TSADCV4_DATA_MASK

#define TSADCV2_HIGHT_INT_DEBOUNCE_COUNT
#define TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT
#define TSADCV2_AUTO_PERIOD_TIME
#define TSADCV2_AUTO_PERIOD_HT_TIME
#define TSADCV3_AUTO_PERIOD_TIME
#define TSADCV3_AUTO_PERIOD_HT_TIME

#define TSADCV5_AUTO_PERIOD_TIME
#define TSADCV5_AUTO_PERIOD_HT_TIME
#define TSADCV6_AUTO_PERIOD_TIME
#define TSADCV6_AUTO_PERIOD_HT_TIME

#define TSADCV2_USER_INTER_PD_SOC
#define TSADCV5_USER_INTER_PD_SOC

#define GRF_SARADC_TESTBIT
#define GRF_TSADC_TESTBIT_L
#define GRF_TSADC_TESTBIT_H

#define PX30_GRF_SOC_CON2

#define RK3568_GRF_TSADC_CON
#define RK3568_GRF_TSADC_ANA_REG0
#define RK3568_GRF_TSADC_ANA_REG1
#define RK3568_GRF_TSADC_ANA_REG2
#define RK3568_GRF_TSADC_TSEN

#define RK3588_GRF0_TSADC_CON

#define RK3588_GRF0_TSADC_TRM
#define RK3588_GRF0_TSADC_SHUT_2CRU
#define RK3588_GRF0_TSADC_SHUT_2GPIO

#define GRF_SARADC_TESTBIT_ON
#define GRF_TSADC_TESTBIT_H_ON
#define GRF_TSADC_VCM_EN_L
#define GRF_TSADC_VCM_EN_H

#define GRF_CON_TSADC_CH_INV

/**
 * struct tsadc_table - code to temperature conversion table
 * @code: the value of adc channel
 * @temp: the temperature
 * Note:
 * code to temperature mapping of the temperature sensor is a piece wise linear
 * curve.Any temperature, code faling between to 2 give temperatures can be
 * linearly interpolated.
 * Code to Temperature mapping should be updated based on manufacturer results.
 */
struct tsadc_table {};

static const struct tsadc_table rv1108_table[] =;

static const struct tsadc_table rk3228_code_table[] =;

static const struct tsadc_table rk3288_code_table[] =;

static const struct tsadc_table rk3328_code_table[] =;

static const struct tsadc_table rk3368_code_table[] =;

static const struct tsadc_table rk3399_code_table[] =;

static const struct tsadc_table rk3568_code_table[] =;

static const struct tsadc_table rk3588_code_table[] =;

static u32 rk_tsadcv2_temp_to_code(const struct chip_tsadc_table *table,
				   int temp)
{}

static int rk_tsadcv2_code_to_temp(const struct chip_tsadc_table *table,
				   u32 code, int *temp)
{}

/**
 * rk_tsadcv2_initialize - initialize TASDC Controller.
 * @grf: the general register file will be used to do static set by software
 * @regs: the base address of tsadc controller
 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
 *
 * (1) Set TSADC_V2_AUTO_PERIOD:
 *     Configure the interleave between every two accessing of
 *     TSADC in normal operation.
 *
 * (2) Set TSADCV2_AUTO_PERIOD_HT:
 *     Configure the interleave between every two accessing of
 *     TSADC after the temperature is higher than COM_SHUT or COM_INT.
 *
 * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE:
 *     If the temperature is higher than COMP_INT or COMP_SHUT for
 *     "debounce" times, TSADC controller will generate interrupt or TSHUT.
 */
static void rk_tsadcv2_initialize(struct regmap *grf, void __iomem *regs,
				  enum tshut_polarity tshut_polarity)
{}

/**
 * rk_tsadcv3_initialize - initialize TASDC Controller.
 * @grf: the general register file will be used to do static set by software
 * @regs: the base address of tsadc controller
 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
 *
 * (1) The tsadc control power sequence.
 *
 * (2) Set TSADC_V2_AUTO_PERIOD:
 *     Configure the interleave between every two accessing of
 *     TSADC in normal operation.
 *
 * (2) Set TSADCV2_AUTO_PERIOD_HT:
 *     Configure the interleave between every two accessing of
 *     TSADC after the temperature is higher than COM_SHUT or COM_INT.
 *
 * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE:
 *     If the temperature is higher than COMP_INT or COMP_SHUT for
 *     "debounce" times, TSADC controller will generate interrupt or TSHUT.
 */
static void rk_tsadcv3_initialize(struct regmap *grf, void __iomem *regs,
				  enum tshut_polarity tshut_polarity)
{}

static void rk_tsadcv4_initialize(struct regmap *grf, void __iomem *regs,
				  enum tshut_polarity tshut_polarity)
{}

static void rk_tsadcv7_initialize(struct regmap *grf, void __iomem *regs,
				  enum tshut_polarity tshut_polarity)
{}

static void rk_tsadcv8_initialize(struct regmap *grf, void __iomem *regs,
				  enum tshut_polarity tshut_polarity)
{}

static void rk_tsadcv2_irq_ack(void __iomem *regs)
{}

static void rk_tsadcv3_irq_ack(void __iomem *regs)
{}

static void rk_tsadcv4_irq_ack(void __iomem *regs)
{}

static void rk_tsadcv2_control(void __iomem *regs, bool enable)
{}

/**
 * rk_tsadcv3_control - the tsadc controller is enabled or disabled.
 * @regs: the base address of tsadc controller
 * @enable: boolean flag to enable the controller
 *
 * NOTE: TSADC controller works at auto mode, and some SoCs need set the
 * tsadc_q_sel bit on TSADCV2_AUTO_CON[1]. The (1024 - tsadc_q) as output
 * adc value if setting this bit to enable.
 */
static void rk_tsadcv3_control(void __iomem *regs, bool enable)
{}

static void rk_tsadcv4_control(void __iomem *regs, bool enable)
{}

static int rk_tsadcv2_get_temp(const struct chip_tsadc_table *table,
			       int chn, void __iomem *regs, int *temp)
{}

static int rk_tsadcv4_get_temp(const struct chip_tsadc_table *table,
			       int chn, void __iomem *regs, int *temp)
{}

static int rk_tsadcv2_alarm_temp(const struct chip_tsadc_table *table,
				 int chn, void __iomem *regs, int temp)
{}

static int rk_tsadcv3_alarm_temp(const struct chip_tsadc_table *table,
				 int chn, void __iomem *regs, int temp)
{}

static int rk_tsadcv2_tshut_temp(const struct chip_tsadc_table *table,
				 int chn, void __iomem *regs, int temp)
{}

static int rk_tsadcv3_tshut_temp(const struct chip_tsadc_table *table,
				 int chn, void __iomem *regs, int temp)
{}

static void rk_tsadcv2_tshut_mode(int chn, void __iomem *regs,
				  enum tshut_mode mode)
{}

static void rk_tsadcv3_tshut_mode(int chn, void __iomem *regs,
				  enum tshut_mode mode)
{}

static const struct rockchip_tsadc_chip px30_tsadc_data =;

static const struct rockchip_tsadc_chip rv1108_tsadc_data =;

static const struct rockchip_tsadc_chip rk3228_tsadc_data =;

static const struct rockchip_tsadc_chip rk3288_tsadc_data =;

static const struct rockchip_tsadc_chip rk3328_tsadc_data =;

static const struct rockchip_tsadc_chip rk3366_tsadc_data =;

static const struct rockchip_tsadc_chip rk3368_tsadc_data =;

static const struct rockchip_tsadc_chip rk3399_tsadc_data =;

static const struct rockchip_tsadc_chip rk3568_tsadc_data =;

static const struct rockchip_tsadc_chip rk3588_tsadc_data =;

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

static void
rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)
{}

static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)
{}

static int rockchip_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{}

static int rockchip_thermal_get_temp(struct thermal_zone_device *tz, int *out_temp)
{}

static const struct thermal_zone_device_ops rockchip_of_thermal_ops =;

static int rockchip_configure_from_dt(struct device *dev,
				      struct device_node *np,
				      struct rockchip_thermal_data *thermal)
{}

static int
rockchip_thermal_register_sensor(struct platform_device *pdev,
				 struct rockchip_thermal_data *thermal,
				 struct rockchip_thermal_sensor *sensor,
				 int id)
{}

/**
 * rockchip_thermal_reset_controller - Reset TSADC Controller, reset all tsadc registers.
 * @reset: the reset controller of tsadc
 */
static void rockchip_thermal_reset_controller(struct reset_control *reset)
{}

static int rockchip_thermal_probe(struct platform_device *pdev)
{}

static void rockchip_thermal_remove(struct platform_device *pdev)
{}

static int __maybe_unused rockchip_thermal_suspend(struct device *dev)
{}

static int __maybe_unused rockchip_thermal_resume(struct device *dev)
{}

static SIMPLE_DEV_PM_OPS(rockchip_thermal_pm_ops,
			 rockchip_thermal_suspend, rockchip_thermal_resume);

static struct platform_driver rockchip_thermal_driver =;

module_platform_driver();

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