All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data
@ 2021-11-25  2:08 Linus Walleij
  2021-11-25  2:08 ` [PATCH 1/4] hwmon: (ntc_thermistor) Merge platform data into driver Linus Walleij
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Linus Walleij @ 2021-11-25  2:08 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: linux-hwmon, Linus Walleij, Peter Rosin, Chris Lesiak

Since this driver was merged in 2011 nothing in the kernel
has ever used the platform data intended for boardfiles.

Drop this support burden: everyone and their dog is using
this with OF and IIO now.

If there are out-of-tree users who need this, this is the
time to start submitting that platform upstream and stop
working in the shadows. (This will invariably involve having
to convert the platform to OF (or ACPI!).)

Linus Walleij (4):
  hwmon: (ntc_thermistor) Merge platform data into driver
  hwmon: (ntc_thermistor) Drop get_ohm()
  hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO
  hwmon: (ntc_thermistor) Merge platform data

Cc: Peter Rosin <peda@axentia.se>
Cc: Chris Lesiak <chris.lesiak@licor.com>

 drivers/hwmon/Kconfig                        |   5 +-
 drivers/hwmon/ntc_thermistor.c               | 148 ++++++++-----------
 include/linux/platform_data/ntc_thermistor.h |  50 -------
 3 files changed, 66 insertions(+), 137 deletions(-)
 delete mode 100644 include/linux/platform_data/ntc_thermistor.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] hwmon: (ntc_thermistor) Merge platform data into driver
  2021-11-25  2:08 [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data Linus Walleij
@ 2021-11-25  2:08 ` Linus Walleij
  2021-11-25  2:08 ` [PATCH 2/4] hwmon: (ntc_thermistor) Drop get_ohm() Linus Walleij
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-11-25  2:08 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: linux-hwmon, Linus Walleij, Peter Rosin, Chris Lesiak

Platform data is supposed to be used with "board files",
device descriptions in C. Since the introduction of the
NTC driver in 2011, no such platforms have been submitted
to the Linux kernel, and their use is strongly discouraged
in favor of Device Tree, ACPI or as last resort software
firmware nodes.

Drop the external header and copy the platform data into
the driver file.

Cc: Peter Rosin <peda@axentia.se>
Cc: Chris Lesiak <chris.lesiak@licor.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/hwmon/ntc_thermistor.c               | 41 ++++++++++++++--
 include/linux/platform_data/ntc_thermistor.h | 50 --------------------
 2 files changed, 36 insertions(+), 55 deletions(-)
 delete mode 100644 include/linux/platform_data/ntc_thermistor.h

diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index cf26c44f2b88..034ef55d0706 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -14,12 +14,45 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/fixp-arith.h>
+#include <linux/iio/consumer.h>
+#include <linux/hwmon.h>
 
-#include <linux/platform_data/ntc_thermistor.h>
+enum ntc_thermistor_type {
+	TYPE_B57330V2103,
+	TYPE_B57891S0103,
+	TYPE_NCPXXWB473,
+	TYPE_NCPXXWF104,
+	TYPE_NCPXXWL333,
+	TYPE_NCPXXXH103,
+};
 
-#include <linux/iio/consumer.h>
+struct ntc_thermistor_platform_data {
+	/*
+	 * One (not both) of read_uV and read_ohm should be provided and only
+	 * one of the two should be provided.
+	 * Both functions should return negative value for an error case.
+	 *
+	 * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use
+	 * read_uV()
+	 *
+	 * How to setup pullup_ohm, pulldown_ohm, and connect is
+	 * described at Documentation/hwmon/ntc_thermistor.rst
+	 *
+	 * pullup/down_ohm: 0 for infinite / not-connected
+	 *
+	 * chan: iio_channel pointer to communicate with the ADC which the
+	 * thermistor is using for conversion of the analog values.
+	 */
+	int (*read_uv)(struct ntc_thermistor_platform_data *);
+	unsigned int pullup_uv;
 
-#include <linux/hwmon.h>
+	unsigned int pullup_ohm;
+	unsigned int pulldown_ohm;
+	enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
+	struct iio_channel *chan;
+
+	int (*read_ohm)(void);
+};
 
 struct ntc_compensation {
 	int		temp_c;
@@ -651,8 +684,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
 	pdata = ntc_thermistor_parse_dt(dev);
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
-	else if (pdata == NULL)
-		pdata = dev_get_platdata(dev);
 
 	if (!pdata) {
 		dev_err(dev, "No platform init data supplied.\n");
diff --git a/include/linux/platform_data/ntc_thermistor.h b/include/linux/platform_data/ntc_thermistor.h
deleted file mode 100644
index b324d03e580c..000000000000
--- a/include/linux/platform_data/ntc_thermistor.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * ntc_thermistor.h - NTC Thermistors
- *
- *  Copyright (C) 2010 Samsung Electronics
- *  MyungJoo Ham <myungjoo.ham@samsung.com>
- */
-#ifndef _LINUX_NTC_H
-#define _LINUX_NTC_H
-
-struct iio_channel;
-
-enum ntc_thermistor_type {
-	TYPE_B57330V2103,
-	TYPE_B57891S0103,
-	TYPE_NCPXXWB473,
-	TYPE_NCPXXWF104,
-	TYPE_NCPXXWL333,
-	TYPE_NCPXXXH103,
-};
-
-struct ntc_thermistor_platform_data {
-	/*
-	 * One (not both) of read_uV and read_ohm should be provided and only
-	 * one of the two should be provided.
-	 * Both functions should return negative value for an error case.
-	 *
-	 * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use
-	 * read_uV()
-	 *
-	 * How to setup pullup_ohm, pulldown_ohm, and connect is
-	 * described at Documentation/hwmon/ntc_thermistor.rst
-	 *
-	 * pullup/down_ohm: 0 for infinite / not-connected
-	 *
-	 * chan: iio_channel pointer to communicate with the ADC which the
-	 * thermistor is using for conversion of the analog values.
-	 */
-	int (*read_uv)(struct ntc_thermistor_platform_data *);
-	unsigned int pullup_uv;
-
-	unsigned int pullup_ohm;
-	unsigned int pulldown_ohm;
-	enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
-	struct iio_channel *chan;
-
-	int (*read_ohm)(void);
-};
-
-#endif /* _LINUX_NTC_H */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] hwmon: (ntc_thermistor) Drop get_ohm()
  2021-11-25  2:08 [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data Linus Walleij
  2021-11-25  2:08 ` [PATCH 1/4] hwmon: (ntc_thermistor) Merge platform data into driver Linus Walleij
@ 2021-11-25  2:08 ` Linus Walleij
  2021-11-25  2:08 ` [PATCH 3/4] hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO Linus Walleij
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-11-25  2:08 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: linux-hwmon, Linus Walleij, Peter Rosin, Chris Lesiak

Nothing in the kernel (this driver) is using the callback to
read ohms directly. We always read a voltage and convert it
to a resistance. Drop this callback.

Cc: Peter Rosin <peda@axentia.se>
Cc: Chris Lesiak <chris.lesiak@licor.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/hwmon/ntc_thermistor.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 034ef55d0706..8a78e899fa12 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -28,10 +28,6 @@ enum ntc_thermistor_type {
 
 struct ntc_thermistor_platform_data {
 	/*
-	 * One (not both) of read_uV and read_ohm should be provided and only
-	 * one of the two should be provided.
-	 * Both functions should return negative value for an error case.
-	 *
 	 * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use
 	 * read_uV()
 	 *
@@ -50,8 +46,6 @@ struct ntc_thermistor_platform_data {
 	unsigned int pulldown_ohm;
 	enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
 	struct iio_channel *chan;
-
-	int (*read_ohm)(void);
 };
 
 struct ntc_compensation {
@@ -600,9 +594,6 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
 {
 	int read_uv;
 
-	if (data->pdata->read_ohm)
-		return data->pdata->read_ohm();
-
 	if (data->pdata->read_uv) {
 		read_uv = data->pdata->read_uv(data->pdata);
 		if (read_uv < 0)
@@ -690,19 +681,11 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	/* Either one of the two is required. */
-	if (!pdata->read_uv && !pdata->read_ohm) {
-		dev_err(dev,
-			"Both read_uv and read_ohm missing. Need either one of the two.\n");
+	if (!pdata->read_uv) {
+		dev_err(dev, "read_uv missing\n");
 		return -EINVAL;
 	}
 
-	if (pdata->read_uv && pdata->read_ohm) {
-		dev_warn(dev,
-			 "Only one of read_uv and read_ohm is needed; ignoring read_uv.\n");
-		pdata->read_uv = NULL;
-	}
-
 	if (pdata->read_uv && (pdata->pullup_uv == 0 ||
 				(pdata->pullup_ohm == 0 && pdata->connect ==
 				 NTC_CONNECTED_GROUND) ||
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO
  2021-11-25  2:08 [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data Linus Walleij
  2021-11-25  2:08 ` [PATCH 1/4] hwmon: (ntc_thermistor) Merge platform data into driver Linus Walleij
  2021-11-25  2:08 ` [PATCH 2/4] hwmon: (ntc_thermistor) Drop get_ohm() Linus Walleij
@ 2021-11-25  2:08 ` Linus Walleij
  2021-11-25  2:08 ` [PATCH 4/4] hwmon: (ntc_thermistor) Merge platform data Linus Walleij
  2021-11-28 18:00 ` [PATCH 0/4] hwmon: (ntc_thermistor) Drop " Guenter Roeck
  4 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-11-25  2:08 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: linux-hwmon, Linus Walleij, Peter Rosin, Chris Lesiak

The only possible assignment of a function to get a voltage to
convert to a resistance is to use the internal function
ntc_adc_iio_read() which is only available when using IIO
and OF.

Bite the bullet and mandate OF and IIO, drop the read_uv()
callback abstraction and some ifdefs.

As no board is using the platform data, all users are using
OF and IIO anyway.

Cc: Peter Rosin <peda@axentia.se>
Cc: Chris Lesiak <chris.lesiak@licor.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/hwmon/Kconfig          |  5 ++--
 drivers/hwmon/ntc_thermistor.c | 49 +++++++++-------------------------
 2 files changed, 16 insertions(+), 38 deletions(-)

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 64bd3dfba2c4..e491e8f354bb 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1414,8 +1414,9 @@ config SENSORS_PC87427
 	  will be called pc87427.
 
 config SENSORS_NTC_THERMISTOR
-	tristate "NTC thermistor support from Murata"
-	depends on !OF || IIO=n || IIO
+	tristate "NTC thermistor support"
+	depends on OF
+	depends on IIO
 	depends on THERMAL || !THERMAL_OF
 	help
 	  This driver supports NTC thermistors sensor reading and its
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 8a78e899fa12..cedb3ee0f762 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -28,8 +28,7 @@ enum ntc_thermistor_type {
 
 struct ntc_thermistor_platform_data {
 	/*
-	 * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use
-	 * read_uV()
+	 * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required.
 	 *
 	 * How to setup pullup_ohm, pulldown_ohm, and connect is
 	 * described at Documentation/hwmon/ntc_thermistor.rst
@@ -39,9 +38,7 @@ struct ntc_thermistor_platform_data {
 	 * chan: iio_channel pointer to communicate with the ADC which the
 	 * thermistor is using for conversion of the analog values.
 	 */
-	int (*read_uv)(struct ntc_thermistor_platform_data *);
 	unsigned int pullup_uv;
-
 	unsigned int pullup_ohm;
 	unsigned int pulldown_ohm;
 	enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
@@ -346,7 +343,6 @@ struct ntc_data {
 	int n_comp;
 };
 
-#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO)
 static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
 {
 	struct iio_channel *channel = pdata->chan;
@@ -451,20 +447,9 @@ ntc_thermistor_parse_dt(struct device *dev)
 		pdata->connect = NTC_CONNECTED_GROUND;
 
 	pdata->chan = chan;
-	pdata->read_uv = ntc_adc_iio_read;
 
 	return pdata;
 }
-#else
-static struct ntc_thermistor_platform_data *
-ntc_thermistor_parse_dt(struct device *dev)
-{
-	return NULL;
-}
-
-#define ntc_match	NULL
-
-#endif
 
 static inline u64 div64_u64_safe(u64 dividend, u64 divisor)
 {
@@ -594,13 +579,10 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
 {
 	int read_uv;
 
-	if (data->pdata->read_uv) {
-		read_uv = data->pdata->read_uv(data->pdata);
-		if (read_uv < 0)
-			return read_uv;
-		return get_ohm_of_thermistor(data, read_uv);
-	}
-	return -EINVAL;
+	read_uv = ntc_adc_iio_read(data->pdata);
+	if (read_uv < 0)
+		return read_uv;
+	return get_ohm_of_thermistor(data, read_uv);
 }
 
 static int ntc_read(struct device *dev, enum hwmon_sensor_types type,
@@ -681,19 +663,14 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	if (!pdata->read_uv) {
-		dev_err(dev, "read_uv missing\n");
-		return -EINVAL;
-	}
-
-	if (pdata->read_uv && (pdata->pullup_uv == 0 ||
-				(pdata->pullup_ohm == 0 && pdata->connect ==
-				 NTC_CONNECTED_GROUND) ||
-				(pdata->pulldown_ohm == 0 && pdata->connect ==
-				 NTC_CONNECTED_POSITIVE) ||
-				(pdata->connect != NTC_CONNECTED_POSITIVE &&
-				 pdata->connect != NTC_CONNECTED_GROUND))) {
-		dev_err(dev, "Required data to use read_uv not supplied.\n");
+	if (pdata->pullup_uv == 0 ||
+	    (pdata->pullup_ohm == 0 && pdata->connect ==
+	     NTC_CONNECTED_GROUND) ||
+	    (pdata->pulldown_ohm == 0 && pdata->connect ==
+	     NTC_CONNECTED_POSITIVE) ||
+	    (pdata->connect != NTC_CONNECTED_POSITIVE &&
+	     pdata->connect != NTC_CONNECTED_GROUND)) {
+		dev_err(dev, "Required data to use NTC driver not supplied.\n");
 		return -EINVAL;
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] hwmon: (ntc_thermistor) Merge platform data
  2021-11-25  2:08 [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data Linus Walleij
                   ` (2 preceding siblings ...)
  2021-11-25  2:08 ` [PATCH 3/4] hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO Linus Walleij
@ 2021-11-25  2:08 ` Linus Walleij
  2021-11-28 18:00 ` [PATCH 0/4] hwmon: (ntc_thermistor) Drop " Guenter Roeck
  4 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-11-25  2:08 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: linux-hwmon, Linus Walleij, Peter Rosin, Chris Lesiak

Allocate one state container for the device: struct ntc_data.
Move all items from struct ntc_thermistor_platform_data into
this struct and simplify.

Cc: Peter Rosin <peda@axentia.se>
Cc: Chris Lesiak <chris.lesiak@licor.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/hwmon/ntc_thermistor.c | 109 +++++++++++++++------------------
 1 file changed, 48 insertions(+), 61 deletions(-)

diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index cedb3ee0f762..ed638ebd0923 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -26,25 +26,6 @@ enum ntc_thermistor_type {
 	TYPE_NCPXXXH103,
 };
 
-struct ntc_thermistor_platform_data {
-	/*
-	 * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required.
-	 *
-	 * How to setup pullup_ohm, pulldown_ohm, and connect is
-	 * described at Documentation/hwmon/ntc_thermistor.rst
-	 *
-	 * pullup/down_ohm: 0 for infinite / not-connected
-	 *
-	 * chan: iio_channel pointer to communicate with the ADC which the
-	 * thermistor is using for conversion of the analog values.
-	 */
-	unsigned int pullup_uv;
-	unsigned int pullup_ohm;
-	unsigned int pulldown_ohm;
-	enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
-	struct iio_channel *chan;
-};
-
 struct ntc_compensation {
 	int		temp_c;
 	unsigned int	ohm;
@@ -337,15 +318,30 @@ static const struct ntc_type ntc_type[] = {
 	NTC_TYPE(TYPE_NCPXXXH103,  ncpXXxh103),
 };
 
+/*
+ * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required.
+ *
+ * How to setup pullup_ohm, pulldown_ohm, and connect is
+ * described at Documentation/hwmon/ntc_thermistor.rst
+ *
+ * pullup/down_ohm: 0 for infinite / not-connected
+ *
+ * chan: iio_channel pointer to communicate with the ADC which the
+ * thermistor is using for conversion of the analog values.
+ */
 struct ntc_data {
-	struct ntc_thermistor_platform_data *pdata;
 	const struct ntc_compensation *comp;
 	int n_comp;
+	unsigned int pullup_uv;
+	unsigned int pullup_ohm;
+	unsigned int pulldown_ohm;
+	enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
+	struct iio_channel *chan;
 };
 
-static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
+static int ntc_adc_iio_read(struct ntc_data *data)
 {
-	struct iio_channel *channel = pdata->chan;
+	struct iio_channel *channel = data->chan;
 	int uv, ret;
 
 	ret = iio_read_channel_processed_scale(channel, &uv, 1000);
@@ -365,7 +361,7 @@ static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
 		ret = iio_convert_raw_to_processed(channel, raw, &uv, 1000);
 		if (ret < 0) {
 			/* Assume 12 bit ADC with vref at pullup_uv */
-			uv = (pdata->pullup_uv * (s64)raw) >> 12;
+			uv = (data->pullup_uv * (s64)raw) >> 12;
 		}
 	}
 
@@ -407,20 +403,19 @@ static const struct of_device_id ntc_match[] = {
 };
 MODULE_DEVICE_TABLE(of, ntc_match);
 
-static struct ntc_thermistor_platform_data *
-ntc_thermistor_parse_dt(struct device *dev)
+static struct ntc_data *ntc_thermistor_parse_dt(struct device *dev)
 {
+	struct ntc_data *data;
 	struct iio_channel *chan;
 	enum iio_chan_type type;
 	struct device_node *np = dev->of_node;
-	struct ntc_thermistor_platform_data *pdata;
 	int ret;
 
 	if (!np)
 		return NULL;
 
-	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
-	if (!pdata)
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
 		return ERR_PTR(-ENOMEM);
 
 	chan = devm_iio_channel_get(dev, NULL);
@@ -434,21 +429,21 @@ ntc_thermistor_parse_dt(struct device *dev)
 	if (type != IIO_VOLTAGE)
 		return ERR_PTR(-EINVAL);
 
-	if (of_property_read_u32(np, "pullup-uv", &pdata->pullup_uv))
+	if (of_property_read_u32(np, "pullup-uv", &data->pullup_uv))
 		return ERR_PTR(-ENODEV);
-	if (of_property_read_u32(np, "pullup-ohm", &pdata->pullup_ohm))
+	if (of_property_read_u32(np, "pullup-ohm", &data->pullup_ohm))
 		return ERR_PTR(-ENODEV);
-	if (of_property_read_u32(np, "pulldown-ohm", &pdata->pulldown_ohm))
+	if (of_property_read_u32(np, "pulldown-ohm", &data->pulldown_ohm))
 		return ERR_PTR(-ENODEV);
 
 	if (of_find_property(np, "connected-positive", NULL))
-		pdata->connect = NTC_CONNECTED_POSITIVE;
+		data->connect = NTC_CONNECTED_POSITIVE;
 	else /* status change should be possible if not always on. */
-		pdata->connect = NTC_CONNECTED_GROUND;
+		data->connect = NTC_CONNECTED_GROUND;
 
-	pdata->chan = chan;
+	data->chan = chan;
 
-	return pdata;
+	return data;
 }
 
 static inline u64 div64_u64_safe(u64 dividend, u64 divisor)
@@ -462,24 +457,23 @@ static inline u64 div64_u64_safe(u64 dividend, u64 divisor)
 
 static int get_ohm_of_thermistor(struct ntc_data *data, unsigned int uv)
 {
-	struct ntc_thermistor_platform_data *pdata = data->pdata;
-	u32 puv = pdata->pullup_uv;
+	u32 puv = data->pullup_uv;
 	u64 n, puo, pdo;
-	puo = pdata->pullup_ohm;
-	pdo = pdata->pulldown_ohm;
+	puo = data->pullup_ohm;
+	pdo = data->pulldown_ohm;
 
 	if (uv == 0)
-		return (pdata->connect == NTC_CONNECTED_POSITIVE) ?
+		return (data->connect == NTC_CONNECTED_POSITIVE) ?
 			INT_MAX : 0;
 	if (uv >= puv)
-		return (pdata->connect == NTC_CONNECTED_POSITIVE) ?
+		return (data->connect == NTC_CONNECTED_POSITIVE) ?
 			0 : INT_MAX;
 
-	if (pdata->connect == NTC_CONNECTED_POSITIVE && puo == 0)
+	if (data->connect == NTC_CONNECTED_POSITIVE && puo == 0)
 		n = div_u64(pdo * (puv - uv), uv);
-	else if (pdata->connect == NTC_CONNECTED_GROUND && pdo == 0)
+	else if (data->connect == NTC_CONNECTED_GROUND && pdo == 0)
 		n = div_u64(puo * uv, puv - uv);
-	else if (pdata->connect == NTC_CONNECTED_POSITIVE)
+	else if (data->connect == NTC_CONNECTED_POSITIVE)
 		n = div64_u64_safe(pdo * puo * (puv - uv),
 				puo * uv - pdo * (puv - uv));
 	else
@@ -579,7 +573,7 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
 {
 	int read_uv;
 
-	read_uv = ntc_adc_iio_read(data->pdata);
+	read_uv = ntc_adc_iio_read(data);
 	if (read_uv < 0)
 		return read_uv;
 	return get_ohm_of_thermistor(data, read_uv);
@@ -650,38 +644,31 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
 	const struct of_device_id *of_id =
 			of_match_device(of_match_ptr(ntc_match), dev);
 	const struct platform_device_id *pdev_id;
-	struct ntc_thermistor_platform_data *pdata;
 	struct device *hwmon_dev;
 	struct ntc_data *data;
 
-	pdata = ntc_thermistor_parse_dt(dev);
-	if (IS_ERR(pdata))
-		return PTR_ERR(pdata);
+	data = ntc_thermistor_parse_dt(dev);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
 
-	if (!pdata) {
+	if (!data) {
 		dev_err(dev, "No platform init data supplied.\n");
 		return -ENODEV;
 	}
 
-	if (pdata->pullup_uv == 0 ||
-	    (pdata->pullup_ohm == 0 && pdata->connect ==
+	if (data->pullup_uv == 0 ||
+	    (data->pullup_ohm == 0 && data->connect ==
 	     NTC_CONNECTED_GROUND) ||
-	    (pdata->pulldown_ohm == 0 && pdata->connect ==
+	    (data->pulldown_ohm == 0 && data->connect ==
 	     NTC_CONNECTED_POSITIVE) ||
-	    (pdata->connect != NTC_CONNECTED_POSITIVE &&
-	     pdata->connect != NTC_CONNECTED_GROUND)) {
+	    (data->connect != NTC_CONNECTED_POSITIVE &&
+	     data->connect != NTC_CONNECTED_GROUND)) {
 		dev_err(dev, "Required data to use NTC driver not supplied.\n");
 		return -EINVAL;
 	}
 
-	data = devm_kzalloc(dev, sizeof(struct ntc_data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
 	pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
 
-	data->pdata = pdata;
-
 	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);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data
  2021-11-25  2:08 [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data Linus Walleij
                   ` (3 preceding siblings ...)
  2021-11-25  2:08 ` [PATCH 4/4] hwmon: (ntc_thermistor) Merge platform data Linus Walleij
@ 2021-11-28 18:00 ` Guenter Roeck
  4 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2021-11-28 18:00 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Jean Delvare, linux-hwmon, Peter Rosin, Chris Lesiak

On Thu, Nov 25, 2021 at 03:08:37AM +0100, Linus Walleij wrote:
> Since this driver was merged in 2011 nothing in the kernel
> has ever used the platform data intended for boardfiles.
> 
> Drop this support burden: everyone and their dog is using
> this with OF and IIO now.
> 
> If there are out-of-tree users who need this, this is the
> time to start submitting that platform upstream and stop
> working in the shadows. (This will invariably involve having
> to convert the platform to OF (or ACPI!).)
> 
> Linus Walleij (4):
>   hwmon: (ntc_thermistor) Merge platform data into driver
>   hwmon: (ntc_thermistor) Drop get_ohm()
>   hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO
>   hwmon: (ntc_thermistor) Merge platform data
> 
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Chris Lesiak <chris.lesiak@licor.com>
> 
>  drivers/hwmon/Kconfig                        |   5 +-
>  drivers/hwmon/ntc_thermistor.c               | 148 ++++++++-----------
>  include/linux/platform_data/ntc_thermistor.h |  50 -------
>  3 files changed, 66 insertions(+), 137 deletions(-)
>  delete mode 100644 include/linux/platform_data/ntc_thermistor.h
> 

The series looks reasonable to me. I'll apply it to hwmon-next.

Guenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-28 18:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25  2:08 [PATCH 0/4] hwmon: (ntc_thermistor) Drop platform data Linus Walleij
2021-11-25  2:08 ` [PATCH 1/4] hwmon: (ntc_thermistor) Merge platform data into driver Linus Walleij
2021-11-25  2:08 ` [PATCH 2/4] hwmon: (ntc_thermistor) Drop get_ohm() Linus Walleij
2021-11-25  2:08 ` [PATCH 3/4] hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO Linus Walleij
2021-11-25  2:08 ` [PATCH 4/4] hwmon: (ntc_thermistor) Merge platform data Linus Walleij
2021-11-28 18:00 ` [PATCH 0/4] hwmon: (ntc_thermistor) Drop " Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.