Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b9c58c7 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: tsens: Add Tsens driver snapshot"

parents 8456aba1 7064434d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -396,6 +396,16 @@ config GENERIC_ADC_THERMAL
	  to this driver. This driver reports the temperature by reading ADC
	  channel and converts it to temperature based on lookup table.

config THERMAL_TSENS
	tristate "Qualcomm Technologies Inc. TSENS Temperature driver"
	depends on THERMAL
	help
	  This enables the thermal sysfs driver for the TSENS device. It shows
	  up in Sysfs as a thermal zone with multiple trip points. Also able
	  to set threshold temperature for both warm and cool and update
	  thermal userspace client when a threshold is reached. Warm/Cool
	  temperature thresholds can be set independently for each sensor.

menu "Qualcomm thermal drivers"
depends on (ARCH_QCOM && OF) || COMPILE_TEST
source "drivers/thermal/qcom/Kconfig"
+2 −0
Original line number Diff line number Diff line
@@ -54,3 +54,5 @@ obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
obj-$(CONFIG_GENERIC_ADC_THERMAL)	+= thermal-generic-adc.o
obj-$(CONFIG_ZX2967_THERMAL)	+= zx2967_thermal.o
obj-$(CONFIG_UNIPHIER_THERMAL)	+= uniphier_thermal.o
obj-$(CONFIG_THERMAL_TSENS)     += msm-tsens-driver.o
msm-tsens-driver-objs     := msm-tsens.o tsens2xxx.o tsens-dbg.o tsens-mtc.o tsens1xxx.o tsens-calib.o
+396 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
 */

#include <linux/err.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/thermal.h>
#include "tsens.h"
#include "thermal_core.h"

LIST_HEAD(tsens_device_list);

static int tsens_get_temp(void *data, int *temp)
{
	struct tsens_sensor *s = data;
	struct tsens_device *tmdev = s->tmdev;

	return tmdev->ops->get_temp(s, temp);
}

static int tsens_get_min_temp(void *data, int *temp)
{
	struct tsens_sensor *s = data;

	return tsens_2xxx_get_min_temp(s, temp);
}

static int tsens_set_trip_temp(void *data, int low_temp, int high_temp)
{
	struct tsens_sensor *s = data;
	struct tsens_device *tmdev = s->tmdev;

	if (tmdev->ops->set_trips)
		return tmdev->ops->set_trips(s, low_temp, high_temp);

	return 0;
}

static int tsens_init(struct tsens_device *tmdev)
{
	return tmdev->ops->hw_init(tmdev);
}

static int tsens_calib(struct tsens_device *tmdev)
{
	return tmdev->ops->calibrate(tmdev);
}

static int tsens_register_interrupts(struct tsens_device *tmdev)
{
	if (tmdev->ops->interrupts_reg)
		return tmdev->ops->interrupts_reg(tmdev);

	return 0;
}

static const struct of_device_id tsens_table[] = {
	{	.compatible = "qcom,msm8996-tsens",
		.data = &data_tsens2xxx,
	},
	{	.compatible = "qcom,msm8953-tsens",
		.data = &data_tsens2xxx,
	},
	{	.compatible = "qcom,msm8998-tsens",
		.data = &data_tsens2xxx,
	},
	{	.compatible = "qcom,msmhamster-tsens",
		.data = &data_tsens2xxx,
	},
	{	.compatible = "qcom,sdm660-tsens",
		.data = &data_tsens23xx,
	},
	{	.compatible = "qcom,sdm630-tsens",
		.data = &data_tsens23xx,
	},
	{	.compatible = "qcom,sm6150-tsens",
		.data = &data_tsens23xx,
	},
	{	.compatible = "qcom,sdm845-tsens",
		.data = &data_tsens24xx,
	},
	{	.compatible = "qcom,tsens24xx",
		.data = &data_tsens24xx,
	},
	{	.compatible = "qcom,tsens26xx",
		.data = &data_tsens26xx,
	},
	{	.compatible = "qcom,msm8937-tsens",
		.data = &data_tsens14xx,
	},
	{	.compatible = "qcom,qcs405-tsens",
		.data = &data_tsens14xx_405,
	},
	{}
};
MODULE_DEVICE_TABLE(of, tsens_table);

static struct thermal_zone_of_device_ops tsens_tm_thermal_zone_ops = {
	.get_temp = tsens_get_temp,
	.set_trips = tsens_set_trip_temp,
};

static struct thermal_zone_of_device_ops tsens_tm_min_thermal_zone_ops = {
	.get_temp = tsens_get_min_temp,
};

static int get_device_tree_data(struct platform_device *pdev,
				struct tsens_device *tmdev)
{
	struct device_node *of_node = pdev->dev.of_node;
	const struct of_device_id *id;
	const struct tsens_data *data;
	int rc = 0;
	struct resource *res_tsens_mem;
	u32 min_temp_id;

	if (!of_match_node(tsens_table, of_node)) {
		pr_err("Need to read SoC specific fuse map\n");
		return -ENODEV;
	}

	id = of_match_node(tsens_table, of_node);
	if (id == NULL) {
		pr_err("can not find tsens_table of_node\n");
		return -ENODEV;
	}

	data = id->data;
	tmdev->ops = data->ops;
	tmdev->ctrl_data = data;
	tmdev->pdev = pdev;

	if (!tmdev->ops || !tmdev->ops->hw_init || !tmdev->ops->get_temp) {
		pr_err("Invalid ops\n");
		return -EINVAL;
	}

	/* TSENS register region */
	res_tsens_mem = platform_get_resource_byname(pdev,
				IORESOURCE_MEM, "tsens_srot_physical");
	if (!res_tsens_mem) {
		pr_err("Could not get tsens physical address resource\n");
		return -EINVAL;
	}

	tmdev->tsens_srot_addr = devm_ioremap_resource(&pdev->dev,
							res_tsens_mem);
	if (IS_ERR(tmdev->tsens_srot_addr)) {
		dev_err(&pdev->dev, "Failed to IO map TSENS registers.\n");
		return PTR_ERR(tmdev->tsens_srot_addr);
	}

	/* TSENS TM register region */
	res_tsens_mem = platform_get_resource_byname(pdev,
				IORESOURCE_MEM, "tsens_tm_physical");
	if (!res_tsens_mem) {
		pr_err("Could not get tsens physical address resource\n");
		return -EINVAL;
	}

	tmdev->tsens_tm_addr = devm_ioremap_resource(&pdev->dev,
								res_tsens_mem);
	if (IS_ERR(tmdev->tsens_tm_addr)) {
		dev_err(&pdev->dev, "Failed to IO map TSENS TM registers.\n");
		return PTR_ERR(tmdev->tsens_tm_addr);
	}

	tmdev->phys_addr_tm = res_tsens_mem->start;

	/* TSENS eeprom register region */
	res_tsens_mem = platform_get_resource_byname(pdev,
				IORESOURCE_MEM, "tsens_eeprom_physical");
	if (!res_tsens_mem) {
		pr_debug("Could not get tsens physical address resource\n");
	} else {
		tmdev->tsens_calib_addr = devm_ioremap_resource(&pdev->dev,
								res_tsens_mem);
		if (IS_ERR(tmdev->tsens_calib_addr)) {
			dev_err(&pdev->dev, "Failed to IO map TSENS EEPROM registers.\n");
			rc = PTR_ERR(tmdev->tsens_calib_addr);
		}  else {
			rc = tsens_calib(tmdev);
			if (rc) {
				pr_err("Error initializing TSENS controller\n");
				return rc;
			}
		}
	}

	if (!of_property_read_u32(of_node, "0C-sensor-num", &min_temp_id))
		tmdev->min_temp_sensor_id = (int)min_temp_id;
	else
		tmdev->min_temp_sensor_id = MIN_TEMP_DEF_OFFSET;

	tmdev->tsens_reinit_wa =
		of_property_read_bool(of_node, "tsens-reinit-wa");
	return rc;
}

static int tsens_thermal_zone_register(struct tsens_device *tmdev)
{
	int i = 0, sensor_missing = 0;

	for (i = 0; i < TSENS_MAX_SENSORS; i++) {
		tmdev->sensor[i].tmdev = tmdev;
		tmdev->sensor[i].hw_id = i;
		if (tmdev->ops->sensor_en(tmdev, i)) {
			tmdev->sensor[i].tzd =
				devm_thermal_zone_of_sensor_register(
				&tmdev->pdev->dev, i,
				&tmdev->sensor[i], &tsens_tm_thermal_zone_ops);
			if (IS_ERR(tmdev->sensor[i].tzd)) {
				pr_debug("Error registering sensor:%d\n", i);
				sensor_missing++;
				continue;
			}
		} else {
			pr_debug("Sensor not enabled:%d\n", i);
		}
	}

	if (sensor_missing == TSENS_MAX_SENSORS) {
		pr_err("No TSENS sensors to register?\n");
		return -ENODEV;
	}

	if (tmdev->min_temp_sensor_id != MIN_TEMP_DEF_OFFSET) {
		tmdev->min_temp.tmdev = tmdev;
		tmdev->min_temp.hw_id = tmdev->min_temp_sensor_id;
		tmdev->min_temp.tzd =
			devm_thermal_zone_of_sensor_register(
			&tmdev->pdev->dev, tmdev->min_temp_sensor_id,
			&tmdev->min_temp, &tsens_tm_min_thermal_zone_ops);
		if (IS_ERR(tmdev->min_temp.tzd))
			pr_err("Error registering min temp sensor\n");
	}


	return 0;
}

static int tsens_tm_remove(struct platform_device *pdev)
{
	platform_set_drvdata(pdev, NULL);

	return 0;
}

static void tsens_therm_fwk_notify(struct work_struct *work)
{
	int i, rc, temp;
	struct tsens_device *tmdev =
		container_of(work, struct tsens_device, therm_fwk_notify);

	TSENS_DBG(tmdev, "Controller %pK\n", &tmdev->phys_addr_tm);
	for (i = 0; i < TSENS_MAX_SENSORS; i++) {
		if (tmdev->ops->sensor_en(tmdev, i)) {
			rc = tsens_get_temp(&tmdev->sensor[i], &temp);
			if (rc) {
				pr_err("%s: Error:%d reading temp sensor:%d\n",
					__func__, rc, i);
				continue;
			}
			TSENS_DBG(tmdev, "Calling trip_temp for sensor %d\n",
					i);
			of_thermal_handle_trip_temp(tmdev->dev,
				tmdev->sensor[i].tzd, temp);
		}
	}
	if (tmdev->min_temp_sensor_id != MIN_TEMP_DEF_OFFSET) {
		rc = tsens_get_temp(&tmdev->min_temp, &temp);
		if (rc) {
			pr_err("%s: Error:%d reading temp sensor:%d\n",
				   __func__, rc, i);
			return;
		}
		TSENS_DBG(tmdev, "Calling trip_temp for sensor %d\n", i);
		of_thermal_handle_trip_temp(tmdev->dev,
			tmdev->min_temp.tzd, temp);
	}
}

static int tsens_tm_probe(struct platform_device *pdev)
{
	struct tsens_device *tmdev = NULL;
	int rc;
	char tsens_name[40];

	if (!(pdev->dev.of_node))
		return -ENODEV;

	tmdev = devm_kzalloc(&pdev->dev,
			sizeof(struct tsens_device) +
			TSENS_MAX_SENSORS *
			sizeof(struct tsens_sensor),
			GFP_KERNEL);
	if (tmdev == NULL)
		return -ENOMEM;

	rc = get_device_tree_data(pdev, tmdev);
	if (rc) {
		pr_err("Error reading TSENS DT\n");
		return rc;
	}

	rc = tsens_init(tmdev);
	if (rc) {
		pr_err("Error initializing TSENS controller\n");
		return rc;
	}

	snprintf(tsens_name, sizeof(tsens_name), "tsens_wq_%pa",
		&tmdev->phys_addr_tm);

	tmdev->tsens_reinit_work = alloc_workqueue(tsens_name,
		WQ_HIGHPRI, 0);
	if (!tmdev->tsens_reinit_work) {
		rc = -ENOMEM;
		return rc;
	}
	INIT_WORK(&tmdev->therm_fwk_notify, tsens_therm_fwk_notify);
	rc = tsens_thermal_zone_register(tmdev);
	if (rc) {
		pr_err("Error registering the thermal zone\n");
		return rc;
	}

	rc = tsens_register_interrupts(tmdev);
	if (rc < 0) {
		pr_err("TSENS interrupt register failed:%d\n", rc);
		return rc;
	}

	snprintf(tsens_name, sizeof(tsens_name), "tsens_%pa_0",
					&tmdev->phys_addr_tm);

	tmdev->ipc_log0 = ipc_log_context_create(IPC_LOGPAGES,
							tsens_name, 0);
	if (!tmdev->ipc_log0)
		pr_err("%s : unable to create IPC Logging 0 for tsens %pa\n",
					__func__, &tmdev->phys_addr_tm);

	snprintf(tsens_name, sizeof(tsens_name), "tsens_%pa_1",
					&tmdev->phys_addr_tm);

	tmdev->ipc_log1 = ipc_log_context_create(IPC_LOGPAGES,
							tsens_name, 0);
	if (!tmdev->ipc_log1)
		pr_err("%s : unable to create IPC Logging 1 for tsens %pa\n",
					__func__, &tmdev->phys_addr_tm);

	snprintf(tsens_name, sizeof(tsens_name), "tsens_%pa_2",
					&tmdev->phys_addr_tm);

	tmdev->ipc_log2 = ipc_log_context_create(IPC_LOGPAGES,
							tsens_name, 0);
	if (!tmdev->ipc_log2)
		pr_err("%s : unable to create IPC Logging 2 for tsens %pa\n",
					__func__, &tmdev->phys_addr_tm);

	list_add_tail(&tmdev->list, &tsens_device_list);
	platform_set_drvdata(pdev, tmdev);

	return rc;
}

static struct platform_driver tsens_tm_driver = {
	.probe = tsens_tm_probe,
	.remove = tsens_tm_remove,
	.driver = {
		.name = "msm-tsens",
		.of_match_table = tsens_table,
	},
};

static int __init tsens_tm_init_driver(void)
{
	return platform_driver_register(&tsens_tm_driver);
}
subsys_initcall(tsens_tm_init_driver);

static void __exit tsens_tm_deinit(void)
{
	platform_driver_unregister(&tsens_tm_driver);
}
module_exit(tsens_tm_deinit);

MODULE_ALIAS("platform:" TSENS_DRIVER_NAME);
MODULE_LICENSE("GPL v2");
+298 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
 */

#include <linux/platform_device.h>
#include <linux/module.h>
#include "tsens.h"

/* eeprom layout data for 8937 */
#define BASE0_MASK_8937				0x000000ff
#define BASE1_MASK_8937				0xff000000
#define BASE1_SHIFT_8937			24

#define S0_P1_MASK_8937				0x000001f8
#define S1_P1_MASK_8937				0x001f8000
#define S2_P1_MASK_0_4_8937			0xf8000000
#define S2_P1_MASK_5_8937			0x00000001
#define S3_P1_MASK_8937				0x00001f80
#define S4_P1_MASK_8937				0x01f80000
#define S5_P1_MASK_8937				0x00003f00
#define S6_P1_MASK_8937				0x03f00000
#define S7_P1_MASK_8937				0x0000003f
#define S8_P1_MASK_8937				0x0003f000
#define S9_P1_MASK_8937				0x0000003f
#define S10_P1_MASK_8937			0x0003f000

#define S0_P2_MASK_8937				0x00007e00
#define S1_P2_MASK_8937				0x07e00000
#define S2_P2_MASK_8937				0x0000007e
#define S3_P2_MASK_8937				0x0007e000
#define S4_P2_MASK_8937				0x7e000000
#define S5_P2_MASK_8937				0x000fc000
#define S6_P2_MASK_8937				0xfc000000
#define S7_P2_MASK_8937				0x00000fc0
#define S8_P2_MASK_8937				0x00fc0000
#define S9_P2_MASK_8937				0x00000fc0
#define S10_P2_MASK_8937			0x00fc0000

#define S0_P1_SHIFT_8937			3
#define S1_P1_SHIFT_8937			15
#define S2_P1_SHIFT_0_4_8937			27
#define S2_P1_SHIFT_5_8937			5
#define S3_P1_SHIFT_8937			7
#define S4_P1_SHIFT_8937			19
#define S5_P1_SHIFT_8937			8
#define S6_P1_SHIFT_8937			20
#define S8_P1_SHIFT_8937			12
#define S10_P1_SHIFT_8937			12

#define S0_P2_SHIFT_8937			9
#define S1_P2_SHIFT_8937			21
#define S2_P2_SHIFT_8937			1
#define S3_P2_SHIFT_8937			13
#define S4_P2_SHIFT_8937			25
#define S5_P2_SHIFT_8937			14
#define S6_P2_SHIFT_8937			26
#define S7_P2_SHIFT_8937			6
#define S8_P2_SHIFT_8937			18
#define S9_P2_SHIFT_8937			6
#define S10_P2_SHIFT_8937			18

#define CAL_SEL_MASK_8937			0x00000007

/* eeprom layout data for qcs405 */
#define BASE0_MASK_405				0x000007F8
#define BASE1_MASK_405				0x0007F800
#define BASE0_SHIFT_405				0x3
#define BASE1_SHIFT_405				0xB

#define S0_P1_MASK_405				0x0000003F
#define S1_P1_MASK_405				0x0003F000
#define S2_P1_MASK_405				0x3F000000
#define S3_P1_MASK_405				0x000003F0
#define S4_P1_MASK_405				0x003F0000
#define S5_P1_MASK_405				0x0000003F
#define S6_P1_MASK_405				0x0003F000
#define S7_P1_MASK_405				0x3F000000
#define S8_P1_MASK_405				0x000003F0
#define S9_P1_MASK_405				0x003F0000

#define S0_P2_MASK_405				0x00000FC0
#define S1_P2_MASK_405				0x00FC0000
#define S2_P2_MASK_0_1_405			0xC0000000
#define S2_P2_MASK_2_5_405			0x0000000F
#define S3_P2_MASK_405				0x0000FC00
#define S4_P2_MASK_405				0x0FC00000
#define S5_P2_MASK_405				0x00000FC0
#define S6_P2_MASK_405				0x00FC0000
#define S7_P2_MASK_0_1_405			0xC0000000
#define S7_P2_MASK_2_5_405			0x0000000F
#define S8_P2_MASK_405				0x0000FC00
#define S9_P2_MASK_405				0x0FC00000

#define S0_P1_SHIFT_405				0x0
#define S1_P1_SHIFT_405				0xC
#define S2_P1_SHIFT_405				0x18
#define S3_P1_SHIFT_405				0x4
#define S4_P1_SHIFT_405				0x10
#define S5_P1_SHIFT_405				0x0
#define S6_P1_SHIFT_405				0xC
#define S7_P1_SHIFT_405				0x18
#define S8_P1_SHIFT_405				0x4
#define S9_P1_SHIFT_405				0x10

#define S0_P2_SHIFT_405				0x6
#define S1_P2_SHIFT_405				0x12
#define S2_P2_SHIFT_0_1_405			0x1E
#define S2_P2_SHIFT_2_5_405			0x0
#define S3_P2_SHIFT_405				0xA
#define S4_P2_SHIFT_405				0x16
#define S5_P2_SHIFT_405				0x6
#define S6_P2_SHIFT_405				0x12
#define S7_P2_SHIFT_0_1_405			0x1E
#define S7_P2_SHIFT_2_5_405			0x0
#define S8_P2_SHIFT_405				0xA
#define S9_P2_SHIFT_405				0x16

#define CAL_SEL_MASK_405			0x7

#define CAL_DEGC_PT1				30
#define CAL_DEGC_PT2				120

/*
 * Use this function on devices where slope and offset calculations
 * depend on calibration data read from qfprom. On others the slope
 * and offset values are derived from tz->tzp->slope and tz->tzp->offset
 * resp.
 */
static void compute_intercept_slope(struct tsens_device *tmdev, u32 *p1,
	u32 *p2, u32 mode)
{
	int i;
	int num, den;

	for (i = 0; i < tmdev->ctrl_data->num_sensors; i++) {
		pr_debug(
			"sensor%d - data_point1:%#x data_point2:%#x\n",
			i, p1[i], p2[i]);

		tmdev->sensor[i].slope = SLOPE_DEFAULT;
		if (mode == TWO_PT_CALIB) {
			/*
			 * slope (m) = adc_code2 - adc_code1 (y2 - y1)/
			 *	temp_120_degc - temp_30_degc (x2 - x1)
			 */
			num = p2[i] - p1[i];
			num *= SLOPE_FACTOR;
			den = CAL_DEGC_PT2 - CAL_DEGC_PT1;
			tmdev->sensor[i].slope = num / den;
		}

		tmdev->sensor[i].offset = (p1[i] * SLOPE_FACTOR) -
			(CAL_DEGC_PT1 *
			tmdev->sensor[i].slope);
		pr_debug("offset:%d\n", tmdev->sensor[i].offset);
	}
}

int calibrate_8937(struct tsens_device *tmdev)
{
	int base0 = 0, base1 = 0, i;
	u32 p1[TSENS_NUM_SENSORS_8937], p2[TSENS_NUM_SENSORS_8937];
	int mode = 0, tmp = 0;
	u32 qfprom_cdata[5] = { 0, 0, 0, 0, 0 };

	qfprom_cdata[0] = readl_relaxed(tmdev->tsens_calib_addr + 0x1D8);
	qfprom_cdata[1] = readl_relaxed(tmdev->tsens_calib_addr + 0x1DC);
	qfprom_cdata[2] = readl_relaxed(tmdev->tsens_calib_addr + 0x210);
	qfprom_cdata[3] = readl_relaxed(tmdev->tsens_calib_addr + 0x214);
	qfprom_cdata[4] = readl_relaxed(tmdev->tsens_calib_addr + 0x230);

	mode = (qfprom_cdata[2] & CAL_SEL_MASK_8937);
	pr_debug("calibration mode is %d\n", mode);

	switch (mode) {
	case TWO_PT_CALIB:
		base1 = (qfprom_cdata[1] & BASE1_MASK_8937) >> BASE1_SHIFT_8937;
		p2[0] = (qfprom_cdata[2] & S0_P2_MASK_8937) >> S0_P2_SHIFT_8937;
		p2[1] = (qfprom_cdata[2] & S1_P2_MASK_8937) >> S1_P2_SHIFT_8937;
		p2[2] = (qfprom_cdata[3] & S2_P2_MASK_8937) >> S2_P2_SHIFT_8937;
		p2[3] = (qfprom_cdata[3] & S3_P2_MASK_8937) >> S3_P2_SHIFT_8937;
		p2[4] = (qfprom_cdata[3] & S4_P2_MASK_8937) >> S4_P2_SHIFT_8937;
		p2[5] = (qfprom_cdata[0] & S5_P2_MASK_8937) >> S5_P2_SHIFT_8937;
		p2[6] = (qfprom_cdata[0] & S6_P2_MASK_8937) >> S6_P2_SHIFT_8937;
		p2[7] = (qfprom_cdata[1] & S7_P2_MASK_8937) >> S7_P2_SHIFT_8937;
		p2[8] = (qfprom_cdata[1] & S8_P2_MASK_8937) >> S8_P2_SHIFT_8937;
		p2[9] = (qfprom_cdata[4] & S9_P2_MASK_8937) >> S9_P2_SHIFT_8937;
		p2[10] = ((qfprom_cdata[4] & S10_P2_MASK_8937)
					>> S10_P2_SHIFT_8937);

		for (i = 0; i < TSENS_NUM_SENSORS_8937; i++)
			p2[i] = ((base1 + p2[i]) << 2);
		/* Fall through */
	case ONE_PT_CALIB2:
		base0 = (qfprom_cdata[0] & BASE0_MASK_8937);
		p1[0] = (qfprom_cdata[2] & S0_P1_MASK_8937) >> S0_P1_SHIFT_8937;
		p1[1] = (qfprom_cdata[2] & S1_P1_MASK_8937) >> S1_P1_SHIFT_8937;
		p1[2] = ((qfprom_cdata[2] & S2_P1_MASK_0_4_8937)
					>> S2_P1_SHIFT_0_4_8937);
		tmp = ((qfprom_cdata[3] & S2_P1_MASK_5_8937)
					<< S2_P1_SHIFT_5_8937);
		p1[2] |= tmp;
		p1[3] = (qfprom_cdata[3] & S3_P1_MASK_8937) >> S3_P1_SHIFT_8937;
		p1[4] = (qfprom_cdata[3] & S4_P1_MASK_8937) >> S4_P1_SHIFT_8937;
		p1[5] = (qfprom_cdata[0] & S5_P1_MASK_8937) >> S5_P1_SHIFT_8937;
		p1[6] = (qfprom_cdata[0] & S6_P1_MASK_8937) >> S6_P1_SHIFT_8937;
		p1[7] = (qfprom_cdata[1] & S7_P1_MASK_8937);
		p1[8] = (qfprom_cdata[1] & S8_P1_MASK_8937) >> S8_P1_SHIFT_8937;
		p1[9] = (qfprom_cdata[4] & S9_P1_MASK_8937);
		p1[10] = ((qfprom_cdata[4] & S10_P1_MASK_8937)
					>> S10_P1_SHIFT_8937);

		for (i = 0; i < TSENS_NUM_SENSORS_8937; i++)
			p1[i] = (((base0)+p1[i]) << 2);
		break;
	default:
		for (i = 0; i < TSENS_NUM_SENSORS_8937; i++) {
			p1[i] = 500;
			p2[i] = 780;
		}
		break;
	}

	compute_intercept_slope(tmdev, p1, p2, mode);

	return 0;
}

int calibrate_405(struct tsens_device *tmdev)
{
	int base0 = 0, base1 = 0, i;
	u32 p1[TSENS_NUM_SENSORS_405], p2[TSENS_NUM_SENSORS_405];
	int mode = 0, tmp = 0;
	u32 qfprom_cdata[5] = { 0, 0, 0, 0, 0 };

	qfprom_cdata[0] = readl_relaxed(tmdev->tsens_calib_addr + 0x1F8);
	qfprom_cdata[1] = readl_relaxed(tmdev->tsens_calib_addr + 0x1FC);
	qfprom_cdata[2] = readl_relaxed(tmdev->tsens_calib_addr + 0x200);
	qfprom_cdata[3] = readl_relaxed(tmdev->tsens_calib_addr + 0x204);
	qfprom_cdata[4] = readl_relaxed(tmdev->tsens_calib_addr + 0x208);

	mode = (qfprom_cdata[4] & CAL_SEL_MASK_405);
	pr_debug("calibration mode is %d\n", mode);

	switch (mode) {
	case TWO_PT_CALIB:
		base1 = (qfprom_cdata[4] & BASE1_MASK_405) >> BASE1_SHIFT_405;
		p2[0] = (qfprom_cdata[0] & S0_P2_MASK_405) >> S0_P2_SHIFT_405;
		p2[1] = (qfprom_cdata[0] & S1_P2_MASK_405) >> S1_P2_SHIFT_405;
		tmp = ((qfprom_cdata[0] & S2_P2_MASK_0_1_405)
				>> S2_P2_SHIFT_0_1_405);
		p2[2] = ((qfprom_cdata[1] & S2_P2_MASK_2_5_405)
				>> S2_P2_SHIFT_2_5_405) | tmp;
		p2[3] = (qfprom_cdata[1] & S3_P2_MASK_405) >> S3_P2_SHIFT_405;
		p2[4] = (qfprom_cdata[1] & S4_P2_MASK_405) >> S4_P2_SHIFT_405;
		p2[5] = (qfprom_cdata[2] & S5_P2_MASK_405) >> S5_P2_SHIFT_405;
		p2[6] = (qfprom_cdata[2] & S6_P2_MASK_405) >> S6_P2_SHIFT_405;
		tmp = ((qfprom_cdata[2] & S7_P2_MASK_0_1_405)
				>> S7_P2_SHIFT_0_1_405);
		p2[7] = ((qfprom_cdata[3] & S7_P2_MASK_2_5_405)
				>> S7_P2_SHIFT_2_5_405) | tmp;
		p2[8] = (qfprom_cdata[3] & S8_P2_MASK_405) >> S8_P2_SHIFT_405;
		p2[9] = (qfprom_cdata[3] & S9_P2_MASK_405) >> S9_P2_SHIFT_405;

		for (i = 0; i < TSENS_NUM_SENSORS_405; i++)
			p2[i] = ((base1 + p2[i]) << 2);
		/* Fall through */
	case ONE_PT_CALIB2:
		base0 = (qfprom_cdata[4] & BASE0_MASK_405) >> BASE0_SHIFT_405;
		p1[0] = (qfprom_cdata[0] & S0_P1_MASK_405) >> S0_P1_SHIFT_405;
		p1[1] = (qfprom_cdata[0] & S1_P1_MASK_405) >> S1_P1_SHIFT_405;
		p1[2] = (qfprom_cdata[0] & S2_P1_MASK_405) >> S2_P1_SHIFT_405;
		p1[3] = (qfprom_cdata[1] & S3_P1_MASK_405) >> S3_P1_SHIFT_405;
		p1[4] = (qfprom_cdata[1] & S4_P1_MASK_405) >> S4_P1_SHIFT_405;
		p1[5] = (qfprom_cdata[2] & S5_P1_MASK_405) >> S5_P1_SHIFT_405;
		p1[6] = (qfprom_cdata[2] & S6_P1_MASK_405) >> S6_P1_SHIFT_405;
		p1[7] = (qfprom_cdata[2] & S7_P1_MASK_405) >> S7_P1_SHIFT_405;
		p1[8] = (qfprom_cdata[3] & S8_P1_MASK_405) >> S8_P1_SHIFT_405;
		p1[9] = (qfprom_cdata[3] & S9_P1_MASK_405) >> S9_P1_SHIFT_405;

		for (i = 0; i < TSENS_NUM_SENSORS_405; i++)
			p1[i] = (((base0)+p1[i]) << 2);
		break;
	default:
		for (i = 0; i < TSENS_NUM_SENSORS_405; i++) {
			p1[i] = 500;
			p2[i] = 780;
		}
		break;
	}

	compute_intercept_slope(tmdev, p1, p2, mode);

	return 0;
}

MODULE_LICENSE("GPL v2");
+419 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading