// SPDX-License-Identifier: GPL-2.0-or-later
/*
* ntc_thermistor.c - NTC Thermistors
*
* Copyright (C) 2010 Samsung Electronics
* MyungJoo Ham <myungjoo.ham@samsung.com>
*/
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/math64.h>
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/err.h>
#include <linux/fixp-arith.h>
#include <linux/iio/consumer.h>
#include <linux/hwmon.h>
enum ntc_thermistor_type {
TYPE_B57330V2103,
TYPE_B57891S0103,
TYPE_NCPXXWB473,
TYPE_NCPXXWF104,
TYPE_NCPXXWL333,
TYPE_NCPXXXH103,
TYPE_NCPXXWM474,
};
struct ntc_compensation {
int temp_c;
unsigned int ohm;
};
/*
* Used as index in a zero-terminated array, holes not allowed so
* that NTC_LAST is the first empty array entry.
*/
enum {
NTC_B57330V2103,
NTC_B57891S0103,
NTC_NCP03WB473,
NTC_NCP03WF104,
NTC_NCP15WB473,
NTC_NCP15WL333,
NTC_NCP15XH103,
NTC_NCP18WB473,
NTC_NCP21WB473,
NTC_SSG1404001221,
NTC_NCP18WM474,
NTC_LAST,
};
static const struct platform_device_id ntc_thermistor_id[] = {
[NTC_B57330V2103] = { "b57330v2103", TYPE_B57330V2103 },
[NTC_B57891S0103] = { "b57891s0103", TYPE_B57891S0103 },
[NTC_NCP03WB473] = { "ncp03wb473", TYPE_NCPXXWB473 },
[NTC_NCP03WF104] = { "ncp03wf104", TYPE_NCPXXWF104 },
[NTC_NCP15WB473] = { "ncp15wb473", TYPE_NCPXXWB473 },
[NTC_NCP15WL333] = { "ncp15wl333", TYPE_NCPXXWL333 },
[NTC_NCP15XH103] = { "ncp15xh103", TYPE_NCPXXXH103 },
[NTC_NCP18WB473] = { "ncp18wb473", TYPE_NCPXXWB473 },
[NTC_NCP21WB473] = { "ncp21wb473", TYPE_NCPXXWB473 },
[NTC_SSG1404001221] = { "ssg1404_001221", TYPE_NCPXXWB473 },
[NTC_NCP18WM474] = { "ncp18wm474", TYPE_NCPXXWM474 },
[NTC_LAST] = { },
};
MODULE_DEVICE_TABLE(platform, ntc_thermistor_id);
/*
* A compensation table should be sorted by the values of .ohm
* in descending order.
* The following compensation tables are from the specification of Murata NTC
* Thermistors Datasheet
*/
static const struct ntc_compensation ncpXXwb473[] = {
{ .temp_c = -40, .ohm = 1747920 },
{ .temp_c = -35, .ohm = 1245428 },
{ .temp_c = -30, .ohm = 898485 },
{ .temp_c = -25, .ohm = 655802 },
{ .temp_c = -20, .ohm = 483954 },
{ .temp_c = -15, .ohm = 360850 },
{ .temp_c = -10, .ohm = 271697 },
{ .temp_c = -5, .ohm = 206463 },
{ .temp_c = 0, .ohm = 158214 },
{ .temp_c = 5, .ohm = 122259 },
{ .temp_c = 10, .ohm = 95227 },
{ .temp_c = 15, .ohm = 74730 },
{ .temp_c = 20, .ohm = 59065 },
{ .temp_c = 25, .ohm = 47000 },
{ .temp_c = 30, .ohm = 37643 },
{ .temp_c = 35, .ohm = 30334 },
{ .temp_c = 40, .ohm = 24591 },
{ .temp_c = 45, .ohm = 20048 },
{ .temp_c = 50, .ohm = 16433 },
{ .temp_c = 55, .ohm = 13539 },
{ .temp_c = 60, .ohm = 11209 },
{ .temp_c = 65, .ohm = 9328 },
{ .temp_c = 70, .ohm = 7798 },
{ .temp_c = 75, .ohm = 6544 },
{ .temp_c = 80, .ohm = 5518 },
{ .temp_c = 85, .ohm = 4674 },
{ .temp_c = 90, .ohm = 3972 },
{ .temp_c = 95, .ohm = 3388 },
{ .temp_c = 100, .ohm = 2902 },
{ .temp_c = 105, .ohm = 2494 },
{ .temp_c = 110, .ohm = 2150 },
{ .temp_c = 115, .ohm = 1860 },
{ .temp_c = 120, .ohm = 1615 },
{ .temp_c = 125, .ohm = 1406 },
};
static const struct ntc_compensation ncpXXwl333[] = {
{ .temp_c = -40, .ohm = 1610154 },
{ .temp_c = -35, .ohm = 1130850 },
{ .temp_c = -30, .ohm = 802609 },
{ .temp_c = -25, .ohm = 575385 },
{ .temp_c = -20, .ohm = 416464 },
{ .temp_c = -15, .ohm = 304219 },
{ .temp_c = -10, .ohm = 224193 },
{ .temp_c = -5, .ohm = 166623 },
{ .temp_c = 0, .ohm