// SPDX-License-Identifier: GPL-2.0
#include <linux/bug.h>
#include <linux/kernel.h>
#include <linux/bitops.h>
#include <linux/math64.h>
#include <linux/log2.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/units.h>
#include "qcom-vadc-common.h"
/* Voltage to temperature */
static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = {
{1758, -40},
{1742, -35},
{1719, -30},
{1691, -25},
{1654, -20},
{1608, -15},
{1551, -10},
{1483, -5},
{1404, 0},
{1315, 5},
{1218, 10},
{1114, 15},
{1007, 20},
{900, 25},
{795, 30},
{696, 35},
{605, 40},
{522, 45},
{448, 50},
{383, 55},
{327, 60},
{278, 65},
{237, 70},
{202, 75},
{172, 80},
{146, 85},
{125, 90},
{107, 95},
{92, 100},
{79, 105},
{68, 110},
{59, 115},
{51, 120},
{44, 125}
};
/*
* Voltage to temperature table for 100k pull up for NTCG104EF104 with
* 1.875V reference.
*/
static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
{ 1831, -40000 },
{ 1814, -35000 },
{ 1791, -30000 },
{ 1761, -25000 },
{ 1723, -20000 },
{ 1675, -15000 },
{ 1616, -10000 },
{ 1545, -5000 },
{ 1463, 0 },
{ 1370, 5000 },
{ 1268, 10000 },
{ 1160, 15000 },
{ 1049, 20000 },
{ 937, 25000 },
{ 828, 30000 },
{ 726, 35000 },
{ 630, 40000 },
{ 544, 45000 },
{ 467, 50000 },
{ 399, 55000 },
{ 340, 60000 },
{ 290, 65000 },
{ 247, 70000 },
{ 209, 75000 },
{ 179, 80000 },
{ 153, 85000 },
{ 130, 90000 },
{ 112, 95000 },
{ 96, 100000 },
{ 82, 105000 },
{ 71, 110000 },
{ 62, 115000 },
{ 53, 120000 },
{ 46, 125000 },
};
static const struct vadc_map_pt adcmap7_die_temp[] = {
{ 433700, 1967},
{ 473100, 1964},
{ 512400, 1957},
{ 551500, 1949},
{ 590500, 1940},
{ 629300, 1930},
{ 667900, 1921},
{ 706400, 1910},
{ 744600, 1896},
{ 782500, 1878},
{ 820100, 1859},
{ 857300, 0},
};
/*
* Resistance to temperature table for 100k pull up for NTCG104EF104.
*/
static const struct vadc_map_pt adcmap7_100k[] = {
{ 4250657, -40960 },
{ 3962085, -39936 },
{ 3694875, -38912 },
{ 3447322, -37888 },
{ 3217867, -36864 },
{ 3005082, -35840 },
{ 2807660, -34816 },
{ 2624405, -33792 },
{ 2454218, -32768 },
{ 2296094, -31744 },
{ 2149108, -30720 },
{ 2012414, -29696 },
{ 1885232, -28672 },
{ 1766846, -27648 },
{ 1656598, -26624 },
{ 1553884, -25600 },
{ 1458147, -24576 },
{ 1368873, -23552 },
{ 1285590, -22528 },
{ 1207863, -21504 },
{ 1135290, -20480 },
{ 1067501, -19456 },
{ 1004155, -18432 },
{ 944935, -17408 },
{ 889550, -16384 },
{ 837731, -15360 },
{ 789229, -14336 },
{ 743813, -13312 },
{ 701271, -12288 },
{ 661405, -11264 },
{ 624032, -10240 },
{ 588982, -9216 },
{ 556100, -8192 },
{ 525239, -7168 },
{ 496264, -6144 },
{ 469050, -5120 },
{ 443480, -4096 },
{ 419448, -3072 },
{ 396851, -2048 },
{ 375597, -1024 },
{ 355598, 0 },
{ 336775, 1024 },
{ 319052, 2048 },
{ 302359, 3072 },
{ 286630, 4096 },
{ 271806, 5120 },
{ 257829, 6144 },
{ 244646, 7168 },
{ 232209, 8192 },
{ 220471, 9216 },
{ 209390, 10240 },
{ 198926, 11264 },
{ 189040, 12288 },
{ 179698, 13312 },
{ 170868, 14336 },
{ 162519, 15360 },
{ 154622, 16384 },
{ 147150, 17408 },
{ 140079, 18432 },
{ 133385, 19456 },
{ 127046, 20480 },
{ 121042, 21504 },
{ 115352, 22528 },
{ 109960, 23552 },
{ 104848, 24576 },
{ 100000, 2560