2018-09-12 17:52:47 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2016-05-05 16:51:39 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
|
|
|
|
*/
|
2018-09-12 17:52:47 +08:00
|
|
|
|
2016-05-05 16:51:39 +08:00
|
|
|
#ifndef __QCOM_TSENS_H__
|
|
|
|
#define __QCOM_TSENS_H__
|
|
|
|
|
|
|
|
#define ONE_PT_CALIB 0x1
|
|
|
|
#define ONE_PT_CALIB2 0x2
|
|
|
|
#define TWO_PT_CALIB 0x3
|
|
|
|
|
2016-06-22 16:42:03 +08:00
|
|
|
#include <linux/thermal.h>
|
|
|
|
|
2016-05-05 16:51:39 +08:00
|
|
|
struct tsens_device;
|
|
|
|
|
2019-03-20 21:17:41 +08:00
|
|
|
/**
|
|
|
|
* struct tsens_sensor - data for each sensor connected to the tsens device
|
|
|
|
* @tmdev: tsens device instance that this sensor is connected to
|
|
|
|
* @tzd: pointer to the thermal zone that this sensor is in
|
|
|
|
* @offset: offset of temperature adjustment curve
|
|
|
|
* @id: Sensor ID
|
|
|
|
* @hw_id: HW ID can be used in case of platform-specific IDs
|
|
|
|
* @slope: slope of temperature adjustment curve
|
|
|
|
* @status: 8960-specific variable to track 8960 and 8660 status register offset
|
|
|
|
*/
|
2016-05-05 16:51:39 +08:00
|
|
|
struct tsens_sensor {
|
|
|
|
struct tsens_device *tmdev;
|
|
|
|
struct thermal_zone_device *tzd;
|
|
|
|
int offset;
|
|
|
|
int id;
|
|
|
|
int hw_id;
|
|
|
|
int slope;
|
|
|
|
u32 status;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct tsens_ops - operations as supported by the tsens device
|
|
|
|
* @init: Function to initialize the tsens device
|
|
|
|
* @calibrate: Function to calibrate the tsens device
|
|
|
|
* @get_temp: Function which returns the temp in millidegC
|
|
|
|
* @enable: Function to enable (clocks/power) tsens device
|
|
|
|
* @disable: Function to disable the tsens device
|
|
|
|
* @suspend: Function to suspend the tsens device
|
|
|
|
* @resume: Function to resume the tsens device
|
|
|
|
* @get_trend: Function to get the thermal/temp trend
|
|
|
|
*/
|
|
|
|
struct tsens_ops {
|
|
|
|
/* mandatory callbacks */
|
|
|
|
int (*init)(struct tsens_device *);
|
|
|
|
int (*calibrate)(struct tsens_device *);
|
|
|
|
int (*get_temp)(struct tsens_device *, int, int *);
|
|
|
|
/* optional callbacks */
|
|
|
|
int (*enable)(struct tsens_device *, int);
|
|
|
|
void (*disable)(struct tsens_device *);
|
|
|
|
int (*suspend)(struct tsens_device *);
|
|
|
|
int (*resume)(struct tsens_device *);
|
2016-06-22 16:42:03 +08:00
|
|
|
int (*get_trend)(struct tsens_device *, int, enum thermal_trend *);
|
2016-05-05 16:51:39 +08:00
|
|
|
};
|
|
|
|
|
2018-09-12 17:52:52 +08:00
|
|
|
enum reg_list {
|
|
|
|
SROT_CTRL_OFFSET,
|
|
|
|
|
|
|
|
REG_ARRAY_SIZE,
|
|
|
|
};
|
|
|
|
|
2016-05-05 16:51:39 +08:00
|
|
|
/**
|
2019-03-20 21:17:41 +08:00
|
|
|
* struct tsens_data - tsens platform data
|
|
|
|
* @num_sensors: Number of sensors supported by platform
|
2016-05-05 16:51:39 +08:00
|
|
|
* @ops: operations the tsens instance supports
|
|
|
|
* @hw_ids: Subset of sensors ids supported by platform, if not the first n
|
2018-09-12 17:52:52 +08:00
|
|
|
* @reg_offsets: Register offsets for commonly used registers
|
2016-05-05 16:51:39 +08:00
|
|
|
*/
|
|
|
|
struct tsens_data {
|
|
|
|
const u32 num_sensors;
|
|
|
|
const struct tsens_ops *ops;
|
2018-09-12 17:52:52 +08:00
|
|
|
const u16 reg_offsets[REG_ARRAY_SIZE];
|
2016-05-05 16:51:39 +08:00
|
|
|
unsigned int *hw_ids;
|
|
|
|
};
|
|
|
|
|
2019-03-20 21:17:41 +08:00
|
|
|
/**
|
|
|
|
* struct tsens_context - Registers to be saved/restored across a context loss
|
|
|
|
*/
|
2016-05-05 16:51:39 +08:00
|
|
|
struct tsens_context {
|
|
|
|
int threshold;
|
|
|
|
int control;
|
|
|
|
};
|
|
|
|
|
2019-03-20 21:17:41 +08:00
|
|
|
/**
|
|
|
|
* struct tsens_device - private data for each instance of the tsens IP
|
|
|
|
* @dev: pointer to struct device
|
|
|
|
* @num_sensors: number of sensors enabled on this device
|
|
|
|
* @tm_map: pointer to TM register address space
|
|
|
|
* @srot_map: pointer to SROT register address space
|
|
|
|
* @tm_offset: deal with old device trees that don't address TM and SROT
|
|
|
|
* address space separately
|
|
|
|
* @reg_offsets: array of offsets to important regs for this version of IP
|
|
|
|
* @ctx: registers to be saved and restored during suspend/resume
|
|
|
|
* @ops: pointer to list of callbacks supported by this device
|
|
|
|
* @sensor: list of sensors attached to this device
|
|
|
|
*/
|
2016-05-05 16:51:39 +08:00
|
|
|
struct tsens_device {
|
|
|
|
struct device *dev;
|
|
|
|
u32 num_sensors;
|
2018-09-12 17:52:49 +08:00
|
|
|
struct regmap *tm_map;
|
2018-09-12 17:52:50 +08:00
|
|
|
struct regmap *srot_map;
|
2018-07-18 14:43:09 +08:00
|
|
|
u32 tm_offset;
|
2018-09-12 17:52:52 +08:00
|
|
|
u16 reg_offsets[REG_ARRAY_SIZE];
|
2016-05-05 16:51:39 +08:00
|
|
|
struct tsens_context ctx;
|
|
|
|
const struct tsens_ops *ops;
|
|
|
|
struct tsens_sensor sensor[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
char *qfprom_read(struct device *, const char *);
|
|
|
|
void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);
|
|
|
|
int init_common(struct tsens_device *);
|
|
|
|
int get_temp_common(struct tsens_device *, int, int *);
|
|
|
|
|
2018-07-18 14:43:12 +08:00
|
|
|
/* TSENS v1 targets */
|
|
|
|
extern const struct tsens_data data_8916, data_8974, data_8960;
|
|
|
|
/* TSENS v2 targets */
|
|
|
|
extern const struct tsens_data data_8996, data_tsens_v2;
|
2016-05-05 16:51:40 +08:00
|
|
|
|
2016-05-05 16:51:39 +08:00
|
|
|
#endif /* __QCOM_TSENS_H__ */
|