Files
2022-09-13 10:34:22 +08:00

208 lines
3.3 KiB
C

#include<linux/kernel.h>
typedef struct {
int r;
int temperature;
} ntc_table_t;
static ntc_table_t ntc[] = {
{188424, -40},
{177892, -39},
{168031, -38},
{158793, -37},
{150135, -36},
{142016, -35},
{134398, -34},
{127247, -33},
{120531, -32},
{114221, -31},
{108289, -30},
{102711, -29},
{97461, -28},
{92519, -27},
{87865, -26},
{83480, -25},
{79346, -24},
{75447, -23},
{71769, -22},
{68297, -21},
{65019, -20},
{61922, -19},
{58995, -18},
{56228, -17},
{53610, -16},
{51133, -15},
{48789, -14},
{46568, -13},
{44465, -12},
{42472, -11},
{40582, -10},
{38789, -9},
{37089, -8},
{35475, -7},
{33942, -6},
{32486, -5},
{31103, -4},
{29789, -3},
{28539, -2},
{27350, -1},
{26219, 0},
{25142, 1},
{24117, 2},
{23140, 3},
{22210, 4},
{21324, 5},
{20479, 6},
{19673, 7},
{18904, 8},
{18170, 9},
{17470, 10},
{16801, 11},
{16162, 12},
{15552, 13},
{14969, 14},
{14412, 15},
{13879, 16},
{13369, 17},
{12881, 18},
{12414, 19},
{11967, 20},
{11539, 21},
{11129, 22},
{10737, 23},
{10360, 24},
{10000, 25},
{9617, 26},
{9252, 27},
{8902, 28},
{8569, 29},
{8249, 30},
{7944, 31},
{7652, 32},
{7372, 33},
{7104, 34},
{6848, 35},
{6602, 36},
{6367, 37},
{6142, 38},
{5926, 39},
{5719, 40},
{5520, 41},
{5329, 42},
{5147, 43},
{4971, 44},
{4803, 45},
{4641, 46},
{4486, 47},
{4336, 48},
{4193, 49},
{4055, 50},
{3923, 51},
{3795, 52},
{3673, 53},
{3555, 54},
{3442, 55},
{3333, 56},
{3228, 57},
{3127, 58},
{3029, 59},
{2936, 60},
{2845, 61},
{2758, 62},
{2674, 63},
{2593, 64},
{2516, 65},
{2440, 66},
{2368, 67},
{2298, 68},
{2230, 69},
{2165, 70},
{2103, 71},
{2042, 72},
{1983, 73},
{1927, 74},
{1872, 75},
{1819, 76},
{1768, 77},
{1719, 78},
{1671, 79},
{1625, 80},
{1580, 81},
{1537, 82},
{1496, 83},
{1455, 84},
{1416, 85},
{1378, 86},
{1342, 87},
{1306, 88},
{1272, 89},
{1239, 90},
{1207, 91},
{1176, 92},
{1145, 93},
{1116, 94},
{1088, 95},
{1060, 96},
{1034, 97},
{1008, 98},
{983, 99},
{958, 100},
{935, 101},
{912, 102},
{890, 103},
{868, 104},
{847, 105},
{827, 106},
{807, 107},
{788, 108},
{769, 109},
{751, 110},
{734, 111},
{717, 112},
{700, 113},
{684, 114},
{668, 115},
{653, 116},
{638, 117},
{624, 118},
{610, 119},
{596, 120},
{583, 121},
{570, 122},
{558, 123},
{545, 124},
{534, 125},
};
static unsigned int ntc_abs(int a, int b)
{
if(a > b) {
return (a - b);
}
return b - a;
}
#define RX(mv) (10000*(mv)/(1800-mv))
int get_ntc_temperature(int mv)
{
int num = sizeof(ntc) / sizeof(ntc[0]);
int i = 0;
unsigned int d = 0xfffffff;
int t;
int r = RX(mv);
while(i < num) {
if (ntc_abs(r, ntc[i].r) < d) {
t = ntc[i].temperature;
d = ntc_abs(r, ntc[i].r);
}
i++;
}
printk(KERN_DEBUG "v: %d, r: %d, t: %d\n", mv, r, t);
return t;
}