18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * OMAP4 Bandgap temperature sensor driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
68c2ecf20Sopenharmony_ci * Contact:
78c2ecf20Sopenharmony_ci *   Eduardo Valentin <eduardo.valentin@ti.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef __TI_BANDGAP_H
108c2ecf20Sopenharmony_ci#define __TI_BANDGAP_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
138c2ecf20Sopenharmony_ci#include <linux/types.h>
148c2ecf20Sopenharmony_ci#include <linux/err.h>
158c2ecf20Sopenharmony_ci#include <linux/cpu_pm.h>
168c2ecf20Sopenharmony_ci#include <linux/device.h>
178c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h>
188c2ecf20Sopenharmony_ci#include <linux/pm.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct gpio_desc;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/**
238c2ecf20Sopenharmony_ci * DOC: bandgap driver data structure
248c2ecf20Sopenharmony_ci * ==================================
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *   +----------+----------------+
278c2ecf20Sopenharmony_ci *   | struct temp_sensor_regval |
288c2ecf20Sopenharmony_ci *   +---------------------------+
298c2ecf20Sopenharmony_ci *              * (Array of)
308c2ecf20Sopenharmony_ci *              |
318c2ecf20Sopenharmony_ci *              |
328c2ecf20Sopenharmony_ci *   +-------------------+   +-----------------+
338c2ecf20Sopenharmony_ci *   | struct ti_bandgap |-->| struct device * |
348c2ecf20Sopenharmony_ci *   +----------+--------+   +-----------------+
358c2ecf20Sopenharmony_ci *              |
368c2ecf20Sopenharmony_ci *              |
378c2ecf20Sopenharmony_ci *              V
388c2ecf20Sopenharmony_ci *   +------------------------+
398c2ecf20Sopenharmony_ci *   | struct ti_bandgap_data |
408c2ecf20Sopenharmony_ci *   +------------------------+
418c2ecf20Sopenharmony_ci *              |
428c2ecf20Sopenharmony_ci *              |
438c2ecf20Sopenharmony_ci *              * (Array of)
448c2ecf20Sopenharmony_ci * +------------+------------------------------------------------------+
458c2ecf20Sopenharmony_ci * | +----------+------------+   +-------------------------+           |
468c2ecf20Sopenharmony_ci * | | struct ti_temp_sensor |-->| struct temp_sensor_data |           |
478c2ecf20Sopenharmony_ci * | +-----------------------+   +------------+------------+           |
488c2ecf20Sopenharmony_ci * |            |                                                      |
498c2ecf20Sopenharmony_ci * |            +                                                      |
508c2ecf20Sopenharmony_ci * |            V                                                      |
518c2ecf20Sopenharmony_ci * | +----------+-------------------+                                  |
528c2ecf20Sopenharmony_ci * | | struct temp_sensor_registers |                                  |
538c2ecf20Sopenharmony_ci * | +------------------------------+                                  |
548c2ecf20Sopenharmony_ci * |                                                                   |
558c2ecf20Sopenharmony_ci * +-------------------------------------------------------------------+
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * Above is a simple diagram describing how the data structure below
588c2ecf20Sopenharmony_ci * are organized. For each bandgap device there should be a ti_bandgap_data
598c2ecf20Sopenharmony_ci * containing the device instance configuration, as well as, an array of
608c2ecf20Sopenharmony_ci * sensors, representing every sensor instance present in this bandgap.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/**
648c2ecf20Sopenharmony_ci * struct temp_sensor_registers - descriptor to access registers and bitfields
658c2ecf20Sopenharmony_ci * @temp_sensor_ctrl: TEMP_SENSOR_CTRL register offset
668c2ecf20Sopenharmony_ci * @bgap_tempsoff_mask: mask to temp_sensor_ctrl.tempsoff
678c2ecf20Sopenharmony_ci * @bgap_soc_mask: mask to temp_sensor_ctrl.soc
688c2ecf20Sopenharmony_ci * @bgap_eocz_mask: mask to temp_sensor_ctrl.eocz
698c2ecf20Sopenharmony_ci * @bgap_dtemp_mask: mask to temp_sensor_ctrl.dtemp
708c2ecf20Sopenharmony_ci * @bgap_mask_ctrl: BANDGAP_MASK_CTRL register offset
718c2ecf20Sopenharmony_ci * @mask_hot_mask: mask to bandgap_mask_ctrl.mask_hot
728c2ecf20Sopenharmony_ci * @mask_cold_mask: mask to bandgap_mask_ctrl.mask_cold
738c2ecf20Sopenharmony_ci * @mask_counter_delay_mask: mask to bandgap_mask_ctrl.mask_counter_delay
748c2ecf20Sopenharmony_ci * @mask_freeze_mask: mask to bandgap_mask_ctrl.mask_free
758c2ecf20Sopenharmony_ci * @bgap_mode_ctrl: BANDGAP_MODE_CTRL register offset
768c2ecf20Sopenharmony_ci * @mode_ctrl_mask: mask to bandgap_mode_ctrl.mode_ctrl
778c2ecf20Sopenharmony_ci * @bgap_counter: BANDGAP_COUNTER register offset
788c2ecf20Sopenharmony_ci * @counter_mask: mask to bandgap_counter.counter
798c2ecf20Sopenharmony_ci * @bgap_threshold: BANDGAP_THRESHOLD register offset (TALERT thresholds)
808c2ecf20Sopenharmony_ci * @threshold_thot_mask: mask to bandgap_threhold.thot
818c2ecf20Sopenharmony_ci * @threshold_tcold_mask: mask to bandgap_threhold.tcold
828c2ecf20Sopenharmony_ci * @tshut_threshold: TSHUT_THRESHOLD register offset (TSHUT thresholds)
838c2ecf20Sopenharmony_ci * @tshut_hot_mask: mask to tshut_threhold.thot
848c2ecf20Sopenharmony_ci * @tshut_cold_mask: mask to tshut_threhold.thot
858c2ecf20Sopenharmony_ci * @bgap_status: BANDGAP_STATUS register offset
868c2ecf20Sopenharmony_ci * @status_hot_mask: mask to bandgap_status.hot
878c2ecf20Sopenharmony_ci * @status_cold_mask: mask to bandgap_status.cold
888c2ecf20Sopenharmony_ci * @ctrl_dtemp_1: CTRL_DTEMP1 register offset
898c2ecf20Sopenharmony_ci * @ctrl_dtemp_2: CTRL_DTEMP2 register offset
908c2ecf20Sopenharmony_ci * @bgap_efuse: BANDGAP_EFUSE register offset
918c2ecf20Sopenharmony_ci *
928c2ecf20Sopenharmony_ci * The register offsets and bitfields might change across
938c2ecf20Sopenharmony_ci * OMAP and variants versions. Hence this struct serves as a
948c2ecf20Sopenharmony_ci * descriptor map on how to access the registers and the bitfields.
958c2ecf20Sopenharmony_ci *
968c2ecf20Sopenharmony_ci * This descriptor contains registers of all versions of bandgap chips.
978c2ecf20Sopenharmony_ci * Not all versions will use all registers, depending on the available
988c2ecf20Sopenharmony_ci * features. Please read TRMs for descriptive explanation on each bitfield.
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistruct temp_sensor_registers {
1028c2ecf20Sopenharmony_ci	u32	temp_sensor_ctrl;
1038c2ecf20Sopenharmony_ci	u32	bgap_tempsoff_mask;
1048c2ecf20Sopenharmony_ci	u32	bgap_soc_mask;
1058c2ecf20Sopenharmony_ci	u32	bgap_eocz_mask;
1068c2ecf20Sopenharmony_ci	u32	bgap_dtemp_mask;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	u32	bgap_mask_ctrl;
1098c2ecf20Sopenharmony_ci	u32	mask_hot_mask;
1108c2ecf20Sopenharmony_ci	u32	mask_cold_mask;
1118c2ecf20Sopenharmony_ci	u32	mask_counter_delay_mask;
1128c2ecf20Sopenharmony_ci	u32	mask_freeze_mask;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	u32	bgap_mode_ctrl;
1158c2ecf20Sopenharmony_ci	u32	mode_ctrl_mask;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	u32	bgap_counter;
1188c2ecf20Sopenharmony_ci	u32	counter_mask;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	u32	bgap_threshold;
1218c2ecf20Sopenharmony_ci	u32	threshold_thot_mask;
1228c2ecf20Sopenharmony_ci	u32	threshold_tcold_mask;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	u32	tshut_threshold;
1258c2ecf20Sopenharmony_ci	u32	tshut_hot_mask;
1268c2ecf20Sopenharmony_ci	u32	tshut_cold_mask;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	u32	bgap_status;
1298c2ecf20Sopenharmony_ci	u32	status_hot_mask;
1308c2ecf20Sopenharmony_ci	u32	status_cold_mask;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	u32	ctrl_dtemp_1;
1338c2ecf20Sopenharmony_ci	u32	ctrl_dtemp_2;
1348c2ecf20Sopenharmony_ci	u32	bgap_efuse;
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/**
1388c2ecf20Sopenharmony_ci * struct temp_sensor_data - The thresholds and limits for temperature sensors.
1398c2ecf20Sopenharmony_ci * @tshut_hot: temperature to trigger a thermal reset (initial value)
1408c2ecf20Sopenharmony_ci * @tshut_cold: temp to get the plat out of reset due to thermal (init val)
1418c2ecf20Sopenharmony_ci * @t_hot: temperature to trigger a thermal alert (high initial value)
1428c2ecf20Sopenharmony_ci * @t_cold: temperature to trigger a thermal alert (low initial value)
1438c2ecf20Sopenharmony_ci * @min_freq: sensor minimum clock rate
1448c2ecf20Sopenharmony_ci * @max_freq: sensor maximum clock rate
1458c2ecf20Sopenharmony_ci *
1468c2ecf20Sopenharmony_ci * This data structure will hold the required thresholds and temperature limits
1478c2ecf20Sopenharmony_ci * for a specific temperature sensor, like shutdown temperature, alert
1488c2ecf20Sopenharmony_ci * temperature, clock / rate used, ADC conversion limits and update intervals
1498c2ecf20Sopenharmony_ci */
1508c2ecf20Sopenharmony_cistruct temp_sensor_data {
1518c2ecf20Sopenharmony_ci	u32	tshut_hot;
1528c2ecf20Sopenharmony_ci	u32	tshut_cold;
1538c2ecf20Sopenharmony_ci	u32	t_hot;
1548c2ecf20Sopenharmony_ci	u32	t_cold;
1558c2ecf20Sopenharmony_ci	u32	min_freq;
1568c2ecf20Sopenharmony_ci	u32	max_freq;
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistruct ti_bandgap_data;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/**
1628c2ecf20Sopenharmony_ci * struct temp_sensor_regval - temperature sensor register values and priv data
1638c2ecf20Sopenharmony_ci * @bg_mode_ctrl: temp sensor control register value
1648c2ecf20Sopenharmony_ci * @bg_ctrl: bandgap ctrl register value
1658c2ecf20Sopenharmony_ci * @bg_counter: bandgap counter value
1668c2ecf20Sopenharmony_ci * @bg_threshold: bandgap threshold register value
1678c2ecf20Sopenharmony_ci * @tshut_threshold: bandgap tshut register value
1688c2ecf20Sopenharmony_ci * @data: private data
1698c2ecf20Sopenharmony_ci *
1708c2ecf20Sopenharmony_ci * Data structure to save and restore bandgap register set context. Only
1718c2ecf20Sopenharmony_ci * required registers are shadowed, when needed.
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_cistruct temp_sensor_regval {
1748c2ecf20Sopenharmony_ci	u32			bg_mode_ctrl;
1758c2ecf20Sopenharmony_ci	u32			bg_ctrl;
1768c2ecf20Sopenharmony_ci	u32			bg_counter;
1778c2ecf20Sopenharmony_ci	u32			bg_threshold;
1788c2ecf20Sopenharmony_ci	u32			tshut_threshold;
1798c2ecf20Sopenharmony_ci	void			*data;
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/**
1838c2ecf20Sopenharmony_ci * struct ti_bandgap - bandgap device structure
1848c2ecf20Sopenharmony_ci * @dev: struct device pointer
1858c2ecf20Sopenharmony_ci * @base: io memory base address
1868c2ecf20Sopenharmony_ci * @conf: struct with bandgap configuration set (# sensors, conv_table, etc)
1878c2ecf20Sopenharmony_ci * @regval: temperature sensor register values
1888c2ecf20Sopenharmony_ci * @fclock: pointer to functional clock of temperature sensor
1898c2ecf20Sopenharmony_ci * @div_clk: pointer to divider clock of temperature sensor fclk
1908c2ecf20Sopenharmony_ci * @lock: spinlock for ti_bandgap structure
1918c2ecf20Sopenharmony_ci * @irq: MPU IRQ number for thermal alert
1928c2ecf20Sopenharmony_ci * @tshut_gpio: GPIO where Tshut signal is routed
1938c2ecf20Sopenharmony_ci * @clk_rate: Holds current clock rate
1948c2ecf20Sopenharmony_ci *
1958c2ecf20Sopenharmony_ci * The bandgap device structure representing the bandgap device instance.
1968c2ecf20Sopenharmony_ci * It holds most of the dynamic stuff. Configurations and sensor specific
1978c2ecf20Sopenharmony_ci * entries are inside the @conf structure.
1988c2ecf20Sopenharmony_ci */
1998c2ecf20Sopenharmony_cistruct ti_bandgap {
2008c2ecf20Sopenharmony_ci	struct device			*dev;
2018c2ecf20Sopenharmony_ci	void __iomem			*base;
2028c2ecf20Sopenharmony_ci	const struct ti_bandgap_data	*conf;
2038c2ecf20Sopenharmony_ci	struct temp_sensor_regval	*regval;
2048c2ecf20Sopenharmony_ci	struct clk			*fclock;
2058c2ecf20Sopenharmony_ci	struct clk			*div_clk;
2068c2ecf20Sopenharmony_ci	spinlock_t			lock; /* shields this struct */
2078c2ecf20Sopenharmony_ci	int				irq;
2088c2ecf20Sopenharmony_ci	struct gpio_desc		*tshut_gpiod;
2098c2ecf20Sopenharmony_ci	u32				clk_rate;
2108c2ecf20Sopenharmony_ci	struct notifier_block		nb;
2118c2ecf20Sopenharmony_ci	unsigned int is_suspended:1;
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/**
2158c2ecf20Sopenharmony_ci * struct ti_temp_sensor - bandgap temperature sensor configuration data
2168c2ecf20Sopenharmony_ci * @ts_data: pointer to struct with thresholds, limits of temperature sensor
2178c2ecf20Sopenharmony_ci * @registers: pointer to the list of register offsets and bitfields
2188c2ecf20Sopenharmony_ci * @domain: the name of the domain where the sensor is located
2198c2ecf20Sopenharmony_ci * @slope_pcb: sensor gradient slope info for hotspot extrapolation equation
2208c2ecf20Sopenharmony_ci *             with no external influence
2218c2ecf20Sopenharmony_ci * @constant_pcb: sensor gradient const info for hotspot extrapolation equation
2228c2ecf20Sopenharmony_ci *             with no external influence
2238c2ecf20Sopenharmony_ci * @register_cooling: function to describe how this sensor is going to be cooled
2248c2ecf20Sopenharmony_ci * @unregister_cooling: function to release cooling data
2258c2ecf20Sopenharmony_ci *
2268c2ecf20Sopenharmony_ci * Data structure to describe a temperature sensor handled by a bandgap device.
2278c2ecf20Sopenharmony_ci * It should provide configuration details on this sensor, such as how to
2288c2ecf20Sopenharmony_ci * access the registers affecting this sensor, shadow register buffer, how to
2298c2ecf20Sopenharmony_ci * assess the gradient from hotspot, how to cooldown the domain when sensor
2308c2ecf20Sopenharmony_ci * reports too hot temperature.
2318c2ecf20Sopenharmony_ci */
2328c2ecf20Sopenharmony_cistruct ti_temp_sensor {
2338c2ecf20Sopenharmony_ci	struct temp_sensor_data		*ts_data;
2348c2ecf20Sopenharmony_ci	struct temp_sensor_registers	*registers;
2358c2ecf20Sopenharmony_ci	char				*domain;
2368c2ecf20Sopenharmony_ci	/* for hotspot extrapolation */
2378c2ecf20Sopenharmony_ci	const int			slope_pcb;
2388c2ecf20Sopenharmony_ci	const int			constant_pcb;
2398c2ecf20Sopenharmony_ci	int (*register_cooling)(struct ti_bandgap *bgp, int id);
2408c2ecf20Sopenharmony_ci	int (*unregister_cooling)(struct ti_bandgap *bgp, int id);
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/**
2448c2ecf20Sopenharmony_ci * DOC: ti bandgap feature types
2458c2ecf20Sopenharmony_ci *
2468c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_TSHUT - used when the thermal shutdown signal output
2478c2ecf20Sopenharmony_ci *      of a bandgap device instance is routed to the processor. This means
2488c2ecf20Sopenharmony_ci *      the system must react and perform the shutdown by itself (handle an
2498c2ecf20Sopenharmony_ci *      IRQ, for instance).
2508c2ecf20Sopenharmony_ci *
2518c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_TSHUT_CONFIG - used when the bandgap device has control
2528c2ecf20Sopenharmony_ci *      over the thermal shutdown configuration. This means that the thermal
2538c2ecf20Sopenharmony_ci *      shutdown thresholds are programmable, for instance.
2548c2ecf20Sopenharmony_ci *
2558c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_TALERT - used when the bandgap device instance outputs
2568c2ecf20Sopenharmony_ci *      a signal representing violation of programmable alert thresholds.
2578c2ecf20Sopenharmony_ci *
2588c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_MODE_CONFIG - used when it is possible to choose which
2598c2ecf20Sopenharmony_ci *      mode, continuous or one shot, the bandgap device instance will operate.
2608c2ecf20Sopenharmony_ci *
2618c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_COUNTER - used when the bandgap device instance allows
2628c2ecf20Sopenharmony_ci *      programming the update interval of its internal state machine.
2638c2ecf20Sopenharmony_ci *
2648c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_POWER_SWITCH - used when the bandgap device allows
2658c2ecf20Sopenharmony_ci *      itself to be switched on/off.
2668c2ecf20Sopenharmony_ci *
2678c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_CLK_CTRL - used when the clocks feeding the bandgap
2688c2ecf20Sopenharmony_ci *      device are gateable or not.
2698c2ecf20Sopenharmony_ci *
2708c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_FREEZE_BIT - used when the bandgap device features
2718c2ecf20Sopenharmony_ci *      a history buffer that its update can be freezed/unfreezed.
2728c2ecf20Sopenharmony_ci *
2738c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_COUNTER_DELAY - used when the bandgap device features
2748c2ecf20Sopenharmony_ci *	a delay programming based on distinct values.
2758c2ecf20Sopenharmony_ci *
2768c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_HISTORY_BUFFER - used when the bandgap device features
2778c2ecf20Sopenharmony_ci *	a history buffer of temperatures.
2788c2ecf20Sopenharmony_ci *
2798c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_ERRATA_814 - used to workaorund when the bandgap device
2808c2ecf20Sopenharmony_ci *	has Errata 814
2818c2ecf20Sopenharmony_ci * TI_BANDGAP_FEATURE_UNRELIABLE - used when the sensor readings are too
2828c2ecf20Sopenharmony_ci *	inaccurate.
2838c2ecf20Sopenharmony_ci * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a
2848c2ecf20Sopenharmony_ci *      specific feature (above) or not. Return non-zero, if yes.
2858c2ecf20Sopenharmony_ci */
2868c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_TSHUT		BIT(0)
2878c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_TSHUT_CONFIG		BIT(1)
2888c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_TALERT		BIT(2)
2898c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_MODE_CONFIG		BIT(3)
2908c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_COUNTER		BIT(4)
2918c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_POWER_SWITCH		BIT(5)
2928c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_CLK_CTRL		BIT(6)
2938c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_FREEZE_BIT		BIT(7)
2948c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_COUNTER_DELAY	BIT(8)
2958c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_HISTORY_BUFFER	BIT(9)
2968c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_ERRATA_814		BIT(10)
2978c2ecf20Sopenharmony_ci#define TI_BANDGAP_FEATURE_UNRELIABLE		BIT(11)
2988c2ecf20Sopenharmony_ci#define TI_BANDGAP_HAS(b, f)			\
2998c2ecf20Sopenharmony_ci			((b)->conf->features & TI_BANDGAP_FEATURE_ ## f)
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci/**
3028c2ecf20Sopenharmony_ci * struct ti_bandgap_data - ti bandgap data configuration structure
3038c2ecf20Sopenharmony_ci * @features: a bitwise flag set to describe the device features
3048c2ecf20Sopenharmony_ci * @conv_table: Pointer to ADC to temperature conversion table
3058c2ecf20Sopenharmony_ci * @adc_start_val: ADC conversion table starting value
3068c2ecf20Sopenharmony_ci * @adc_end_val: ADC conversion table ending value
3078c2ecf20Sopenharmony_ci * @fclock_name: clock name of the functional clock
3088c2ecf20Sopenharmony_ci * @div_ck_name: clock name of the clock divisor
3098c2ecf20Sopenharmony_ci * @sensor_count: count of temperature sensor within this bandgap device
3108c2ecf20Sopenharmony_ci * @report_temperature: callback to report thermal alert to thermal API
3118c2ecf20Sopenharmony_ci * @expose_sensor: callback to export sensor to thermal API
3128c2ecf20Sopenharmony_ci * @remove_sensor: callback to destroy sensor from thermal API
3138c2ecf20Sopenharmony_ci * @sensors: array of sensors present in this bandgap instance
3148c2ecf20Sopenharmony_ci *
3158c2ecf20Sopenharmony_ci * This is a data structure which should hold most of the static configuration
3168c2ecf20Sopenharmony_ci * of a bandgap device instance. It should describe which features this instance
3178c2ecf20Sopenharmony_ci * is capable of, the clock names to feed this device, the amount of sensors and
3188c2ecf20Sopenharmony_ci * their configuration representation, and how to export and unexport them to
3198c2ecf20Sopenharmony_ci * a thermal API.
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_cistruct ti_bandgap_data {
3228c2ecf20Sopenharmony_ci	unsigned int			features;
3238c2ecf20Sopenharmony_ci	const int			*conv_table;
3248c2ecf20Sopenharmony_ci	u32				adc_start_val;
3258c2ecf20Sopenharmony_ci	u32				adc_end_val;
3268c2ecf20Sopenharmony_ci	char				*fclock_name;
3278c2ecf20Sopenharmony_ci	char				*div_ck_name;
3288c2ecf20Sopenharmony_ci	int				sensor_count;
3298c2ecf20Sopenharmony_ci	int (*report_temperature)(struct ti_bandgap *bgp, int id);
3308c2ecf20Sopenharmony_ci	int (*expose_sensor)(struct ti_bandgap *bgp, int id, char *domain);
3318c2ecf20Sopenharmony_ci	int (*remove_sensor)(struct ti_bandgap *bgp, int id);
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	/* this needs to be at the end */
3348c2ecf20Sopenharmony_ci	struct ti_temp_sensor		sensors[];
3358c2ecf20Sopenharmony_ci};
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ciint ti_bandgap_read_thot(struct ti_bandgap *bgp, int id, int *thot);
3388c2ecf20Sopenharmony_ciint ti_bandgap_write_thot(struct ti_bandgap *bgp, int id, int val);
3398c2ecf20Sopenharmony_ciint ti_bandgap_read_tcold(struct ti_bandgap *bgp, int id, int *tcold);
3408c2ecf20Sopenharmony_ciint ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val);
3418c2ecf20Sopenharmony_ciint ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id,
3428c2ecf20Sopenharmony_ci				    int *interval);
3438c2ecf20Sopenharmony_ciint ti_bandgap_write_update_interval(struct ti_bandgap *bgp, int id,
3448c2ecf20Sopenharmony_ci				     u32 interval);
3458c2ecf20Sopenharmony_ciint ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id,
3468c2ecf20Sopenharmony_ci				  int *temperature);
3478c2ecf20Sopenharmony_ciint ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data);
3488c2ecf20Sopenharmony_civoid *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id);
3498c2ecf20Sopenharmony_ciint ti_bandgap_get_trend(struct ti_bandgap *bgp, int id, int *trend);
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci#ifdef CONFIG_OMAP3_THERMAL
3528c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data omap34xx_data;
3538c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data omap36xx_data;
3548c2ecf20Sopenharmony_ci#else
3558c2ecf20Sopenharmony_ci#define omap34xx_data					NULL
3568c2ecf20Sopenharmony_ci#define omap36xx_data					NULL
3578c2ecf20Sopenharmony_ci#endif
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci#ifdef CONFIG_OMAP4_THERMAL
3608c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data omap4430_data;
3618c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data omap4460_data;
3628c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data omap4470_data;
3638c2ecf20Sopenharmony_ci#else
3648c2ecf20Sopenharmony_ci#define omap4430_data					NULL
3658c2ecf20Sopenharmony_ci#define omap4460_data					NULL
3668c2ecf20Sopenharmony_ci#define omap4470_data					NULL
3678c2ecf20Sopenharmony_ci#endif
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci#ifdef CONFIG_OMAP5_THERMAL
3708c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data omap5430_data;
3718c2ecf20Sopenharmony_ci#else
3728c2ecf20Sopenharmony_ci#define omap5430_data					NULL
3738c2ecf20Sopenharmony_ci#endif
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci#ifdef CONFIG_DRA752_THERMAL
3768c2ecf20Sopenharmony_ciextern const struct ti_bandgap_data dra752_data;
3778c2ecf20Sopenharmony_ci#else
3788c2ecf20Sopenharmony_ci#define dra752_data					NULL
3798c2ecf20Sopenharmony_ci#endif
3808c2ecf20Sopenharmony_ci#endif
381