From: Peter Rosin <peda@axentia.se>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Peter Rosin <peda@axentia.se>, Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Subject: [PATCH 2/2] hwmon: (ntc_thermistor) use a table to lookup the thermistor type
Date: Wed, 21 Nov 2018 16:03:46 +0000 [thread overview]
Message-ID: <20181121160327.16772-3-peda@axentia.se> (raw)
In-Reply-To: <20181121160327.16772-1-peda@axentia.se>
Sort the entries while at it.
Signed-off-by: Peter Rosin <peda@axentia.se>
---
drivers/hwmon/ntc_thermistor.c | 47 +++++++++++++---------------
include/linux/platform_data/ntc_thermistor.h | 6 ++--
2 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 7747c1ed1f02..56d83b2472c8 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -315,6 +315,23 @@ static const struct ntc_compensation b57891s0103[] = {
{ .temp_c = 155.0, .ohm = 168 },
};
+struct ntc_type {
+ const struct ntc_compensation *comp;
+ int n_comp;
+};
+
+#define NTC_TYPE(ntc, compensation) \
+[(ntc)] = { .comp = (compensation), .n_comp = ARRAY_SIZE(compensation) }
+
+static const struct ntc_type ntc_type[] = {
+ NTC_TYPE(TYPE_B57330V2103, b57330v2103),
+ NTC_TYPE(TYPE_B57891S0103, b57891s0103),
+ NTC_TYPE(TYPE_NCPXXWB473, ncpXXwb473),
+ NTC_TYPE(TYPE_NCPXXWF104, ncpXXwf104),
+ NTC_TYPE(TYPE_NCPXXWL333, ncpXXwl333),
+ NTC_TYPE(TYPE_NCPXXXH103, ncpXXxh103),
+};
+
struct ntc_data {
struct ntc_thermistor_platform_data *pdata;
const struct ntc_compensation *comp;
@@ -671,37 +688,15 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
data->pdata = pdata;
- switch (pdev_id->driver_data) {
- case TYPE_NCPXXWB473:
- data->comp = ncpXXwb473;
- data->n_comp = ARRAY_SIZE(ncpXXwb473);
- break;
- case TYPE_NCPXXWL333:
- data->comp = ncpXXwl333;
- data->n_comp = ARRAY_SIZE(ncpXXwl333);
- break;
- case TYPE_B57330V2103:
- data->comp = b57330v2103;
- data->n_comp = ARRAY_SIZE(b57330v2103);
- break;
- case TYPE_NCPXXWF104:
- data->comp = ncpXXwf104;
- data->n_comp = ARRAY_SIZE(ncpXXwf104);
- break;
- case TYPE_NCPXXXH103:
- data->comp = ncpXXxh103;
- data->n_comp = ARRAY_SIZE(ncpXXxh103);
- break;
- case TYPE_B57891S0103:
- data->comp = b57891s0103;
- data->n_comp = ARRAY_SIZE(b57891s0103);
- break;
- default:
+ if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) {
dev_err(dev, "Unknown device type: %lu(%s)\n",
pdev_id->driver_data, pdev_id->name);
return -EINVAL;
}
+ data->comp = ntc_type[pdev_id->driver_data].comp;
+ data->n_comp = ntc_type[pdev_id->driver_data].n_comp;
+
hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name,
data, ntc_groups);
if (IS_ERR(hwmon_dev)) {
diff --git a/include/linux/platform_data/ntc_thermistor.h b/include/linux/platform_data/ntc_thermistor.h
index 231a27c302ec..ee03d429742b 100644
--- a/include/linux/platform_data/ntc_thermistor.h
+++ b/include/linux/platform_data/ntc_thermistor.h
@@ -24,12 +24,12 @@
struct iio_channel;
enum ntc_thermistor_type {
- TYPE_NCPXXWB473,
- TYPE_NCPXXWL333,
TYPE_B57330V2103,
+ TYPE_B57891S0103,
+ TYPE_NCPXXWB473,
TYPE_NCPXXWF104,
+ TYPE_NCPXXWL333,
TYPE_NCPXXXH103,
- TYPE_B57891S0103,
};
struct ntc_thermistor_platform_data {
--
2.11.0
next prev parent reply other threads:[~2018-11-21 16:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-17 12:12 [PATCH 1/2] dt-bindings: hwmon: add B57891S0103 thermistor from Epcos Peter Rosin
2018-11-17 12:13 ` [PATCH 2/2] hwmon: (ntc_thermistor): add support for B57891S0103 " Peter Rosin
2018-11-19 17:07 ` Guenter Roeck
2018-11-19 21:16 ` Peter Rosin
2018-11-19 21:28 ` Guenter Roeck
2018-11-21 6:06 ` Peter Rosin
2018-11-21 8:42 ` Guenter Roeck
2018-11-21 16:03 ` [PATCH 0/2] hwmon: (ntc_thermistor) sort thermistors Peter Rosin
2018-11-21 16:03 ` [PATCH 1/2] hwmon: (ntc_thermistor) sort thermistor id lists alphabetically Peter Rosin
2018-12-01 18:39 ` Guenter Roeck
2018-11-21 16:03 ` Peter Rosin [this message]
2018-12-01 18:40 ` [PATCH 2/2] hwmon: (ntc_thermistor) use a table to lookup the thermistor type Guenter Roeck
2018-12-01 18:38 ` [PATCH 2/2] hwmon: (ntc_thermistor): add support for B57891S0103 from Epcos Guenter Roeck
2018-12-01 18:37 ` [PATCH 1/2] dt-bindings: hwmon: add B57891S0103 thermistor " Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181121160327.16772-3-peda@axentia.se \
--to=peda@axentia.se \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).