/*
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *      http://www.samsung.com
 * Akshay Saraswat <akshay.s@samsung.com>
 *
 * EXYNOS - Thermal Management Unit
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <errno.h>
#include <fdtdec.h>
#include <log.h>
#include <time.h>
#include <tmu.h>
#include <asm/io.h>
#include <asm/arch/tmu.h>
#include <asm/arch/power.h>

#define TRIMINFO_RELOAD		1
#define CORE_EN			1
#define THERM_TRIP_EN		(1 << 12)

#define INTEN_RISE0		1
#define INTEN_RISE1		(1 << 4)
#define INTEN_RISE2		(1 << 8)
#define INTEN_FALL0		(1 << 16)
#define INTEN_FALL1		(1 << 20)
#define INTEN_FALL2		(1 << 24)

#define TRIM_INFO_MASK		0xff

#define INTCLEAR_RISE0		1
#define INTCLEAR_RISE1		(1 << 4)
#define INTCLEAR_RISE2		(1 << 8)
#define INTCLEAR_FALL0		(1 << 16)
#define INTCLEAR_FALL1		(1 << 20)
#define INTCLEAR_FALL2		(1 << 24)
#define INTCLEARALL		(INTCLEAR_RISE0 | INTCLEAR_RISE1 | \
				 INTCLEAR_RISE2 | INTCLEAR_FALL0 | \
				 INTCLEAR_FALL1 | INTCLEAR_FALL2)

/* Tmeperature threshold values for various thermal events */
struct temperature_params {
	/* minimum value in temperature code range */
	unsigned min_val;
	/* maximum value in temperature code range */
	unsigned max_val;
	/* temperature threshold to start warning */
	unsigned start_warning;
	/* temperature threshold CPU tripping */
	unsigned start_tripping;
	/* temperature threshold for HW tripping */
	unsigned hardware_tripping;
};

/* Pre-defined values and thresholds for calibration of current temperature */
struct tmu_data {
	/* pre-defined temperature thresholds */
	struct temperature_params ts;
	/* pre-defined efuse range minimum value */
	unsigned efuse_min_value;
	/* pre-defined efuse value for temperature calibration */
	unsigned efuse_value;
	/* pre-defined efuse range maximum value */
	unsigned efuse_max_value;
	/* current temperature sensing slope */
	unsigned slope;
};

/* TMU device specific details and status */
struct tmu_info {
	/* base Address for the TMU */
	struct exynos5_tmu_reg *tmu_base;
	/* mux Address for the TMU */
	int tmu_mux;
	/* pre-defined values for calibration and thresholds */
	struct tmu_data data;
	/* value required for triminfo_25 calibration */
	unsigned te1;
	/* value required for triminfo_85 calibration */
	unsigned te2;
	/* Value for measured data calibration */
	int dc_value;
	/* enum value indicating status of the TMU */
	int tmu_state;
};

/* Global struct tmu_info variable to store init values */
static struct tmu_info gbl_info;

/*
 * Get current temperature code from register,
 * then calculate and calibrate it's value
 * in degree celsius.
 *
 * Return:	current temperature of the chip as sensed by TMU
 */
static int get_cur_temp(struct tmu_info *info)
{
	struct exynos5_tmu_reg *reg = info->tmu_base;
	ulong start;
	int cur_temp = 0;

	/*
	 * Temperature code range between min 25 and max 125.
	 * May run more than once for first call as initial sensing
	 * has not yet happened.
	 */
	if (info->tmu_state == TMU_STATUS_NORMAL) {
		start = get_timer(0);
		do {
			cur_temp = readl(&reg->current_temp) & 0xff;
		} while ((cur_temp == 0) || (get_timer(start) > 100));
	}

	if (cur_temp == 0)
		return cur_temp;

	/* Calibrate current temperature */
	cur_temp = cur_temp - info->te1 + info->dc_value;

	return cur_temp;
}

/*
 * Monitors status of the TMU device and exynos temperature
 *
 * @param temp	pointer to the current temperature value
 * Return:	enum tmu_status_t value, code indicating event to execute
 */
enum tmu_status_t tmu_monitor(int *temp)
{
	int cur_temp;
	struct tmu_data *data = &gbl_info.data;

	if (gbl_info.tmu_state == TMU_STATUS_INIT)
		return TMU_STATUS_INIT;

	/* Read current temperature of the SOC */
	cur_temp = get_cur_temp(&gbl_info);

	if (!cur_temp)
		goto out;

	*temp = cur_temp;

	/* Temperature code lies between min 25 and max 125 */
	if ((cur_temp >= data->ts.start_tripping) &&
	    (cur_temp <= data->ts.max_val))
		return TMU_STATUS_TRIPPED;

	if (cur_temp >= data->ts.start_warning)
		return TMU_STATUS_WARNING;

	if ((cur_temp < data->ts.start_warning) &&
	    (cur_temp >= data->ts.min_val))
		return TMU_STATUS_NORMAL;

 out:
	/* Temperature code does not lie between min 25 and max 125 */
	gbl_info.tmu_state = TMU_STATUS_INIT;
	debug("EXYNOS_TMU: Thermal reading failed\n");
	return TMU_STATUS_INIT;
}

/*
 * Get TMU specific pre-defined values from FDT
 *
 * @param info	pointer to the tmu_info struct
 * @param blob  FDT blob
 * Return:	int value, 0 for success
 */
static int get_tmu_fdt_values(struct tmu_info *info, const void *blob)
{
#if CONFIG_IS_ENABLED(OF_CONTROL)
	fdt_addr_t addr;
	int node;
	int error = 0;

	/* Get the node from FDT for TMU */
	node = fdtdec_next_compatible(blob, 0,
				      COMPAT_SAMSUNG_EXYNOS_TMU);
	if (node < 0) {
		debug("EXYNOS_TMU: No node for tmu in device tree\n");
		return -ENODEV;
	}

	/*
	 * Get the pre-defined TMU specific values from FDT.
	 * All of these are expected to be correct otherwise
	 * miscalculation of register values in tmu_setup_parameters
	 * may result in misleading current temperature.
	 */
	addr = fdtdec_get_addr(blob, node, "reg");
	if (addr == FDT_ADDR_T_NONE) {
		debug("%s: Missing tmu-base\n", __func__);
		return -ENODEV;
	}
	info->tmu_base = (struct exynos5_tmu_reg *)addr;

	/* Optional field. */
	info->tmu_mux = fdtdec_get_int(blob,
				node, "samsung,mux", -1);
	/* Take default value as per the user manual b(110) */
	if (info->tmu_mux == -1)
		info->tmu_mux = 0x6;

	info->data.ts.min_val = fdtdec_get_int(blob,
				node, "samsung,min-temp", -1);
	error |= (info->data.ts.min_val == -1);
	info->data.ts.max_val = fdtdec_get_int(blob,
				node, "samsung,max-temp", -1);
	error |= (info->data.ts.max_val == -1);
	info->data.ts.start_warning = fdtdec_get_int(blob,
				node, "samsung,start-warning", -1);
	error |= (info->data.ts.start_warning == -1);
	info->data.ts.start_tripping = fdtdec_get_int(blob,
				node, "samsung,start-tripping", -1);
	error |= (info->data.ts.start_tripping == -1);
	info->data.ts.hardware_tripping = fdtdec_get_int(blob,
				node, "samsung,hw-tripping", -1);
	error |= (info->data.ts.hardware_tripping == -1);
	info->data.efuse_min_value = fdtdec_get_int(blob,
				node, "samsung,efuse-min-value", -1);
	error |= (info->data.efuse_min_value == -1);
	info->data.efuse_value = fdtdec_get_int(blob,
				node, "samsung,efuse-value", -1);
	error |= (info->data.efuse_value == -1);
	info->data.efuse_max_value = fdtdec_get_int(blob,
				node, "samsung,efuse-max-value", -1);
	error |= (info->data.efuse_max_value == -1);
	info->data.slope = fdtdec_get_int(blob,
				node, "samsung,slope", -1);
	error |= (info->data.slope == -1);
	info->dc_value = fdtdec_get_int(blob,
				node, "samsung,dc-value", -1);
	error |= (info->dc_value == -1);

	if (error) {
		debug("fail to get tmu node properties\n");
		return -EINVAL;
	}
#else
	/* Non DT support may never be added. Just in case  */
	return -ENODEV;
#endif

	return 0;
}

/*
 * Calibrate and calculate threshold values and
 * enable interrupt levels
 *
 * @param	info pointer to the tmu_info struct
 */
static void tmu_setup_parameters(struct tmu_info *info)
{
	unsigned te_code, con;
	unsigned warning_code, trip_code, hwtrip_code;
	unsigned cooling_temp;
	unsigned rising_value;
	struct tmu_data *data = &info->data;
	struct exynos5_tmu_reg *reg = info->tmu_base;

	/* Must reload for reading efuse value from triminfo register */
	writel(TRIMINFO_RELOAD, &reg->triminfo_control);

	/* Get the compensation parameter */
	te_code = readl(&reg->triminfo);
	info->te1 = te_code & TRIM_INFO_MASK;
	info->te2 = ((te_code >> 8) & TRIM_INFO_MASK);

	if ((data->efuse_min_value > info->te1) ||
			(info->te1 > data->efuse_max_value)
			||  (info->te2 != 0))
		info->te1 = data->efuse_value;

	/* Get RISING & FALLING Threshold value */
	warning_code = data->ts.start_warning
			+ info->te1 - info->dc_value;
	trip_code = data->ts.start_tripping
			+ info->te1 - info->dc_value;
	hwtrip_code = data->ts.hardware_tripping
			+ info->te1 - info->dc_value;

	cooling_temp = 0;

	rising_value = ((warning_code << 8) |
			(trip_code << 16) |
			(hwtrip_code << 24));

	/* Set interrupt level */
	writel(rising_value, &reg->threshold_temp_rise);
	writel(cooling_temp, &reg->threshold_temp_fall);

	/*
	 * Init TMU control tuning parameters
	 * [28:24] VREF - Voltage reference
	 * [15:13] THERM_TRIP_MODE - Tripping mode
	 * [12] THERM_TRIP_EN - Thermal tripping enable
	 * [11:8] BUF_SLOPE_SEL - Gain of amplifier
	 * [6] THERM_TRIP_BY_TQ_EN - Tripping by TQ pin
	 */
	writel(data->slope, &reg->tmu_control);

	writel(INTCLEARALL, &reg->intclear);

	/* TMU core enable */
	con = readl(&reg->tmu_control);
	con |= THERM_TRIP_EN | CORE_EN | (info->tmu_mux << 20);

	writel(con, &reg->tmu_control);

	/* Enable HW thermal trip */
	set_hw_thermal_trip();

	/* LEV1 LEV2 interrupt enable */
	writel(INTEN_RISE1 | INTEN_RISE2, &reg->inten);
}

/*
 * Initialize TMU device
 *
 * @param blob  FDT blob
 * Return:	int value, 0 for success
 */
int tmu_init(const void *blob)
{
	gbl_info.tmu_state = TMU_STATUS_INIT;
	if (get_tmu_fdt_values(&gbl_info, blob) < 0)
		goto ret;

	tmu_setup_parameters(&gbl_info);
	gbl_info.tmu_state = TMU_STATUS_NORMAL;
ret:
	return gbl_info.tmu_state;
}
