From: Guenter Roeck <linux@roeck-us.net>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jean Delvare <jdelvare@suse.com>,
linux-hwmon@vger.kernel.org, Peter Rosin <peda@axentia.se>,
Chris Lesiak <chris.lesiak@licor.com>
Subject: Re: [PATCH 2/3 v2] hwmon: (ntc_thermistor): Switch to generic firmware props
Date: Tue, 7 Dec 2021 09:33:22 -0800 [thread overview]
Message-ID: <20211207173322.GA659106@roeck-us.net> (raw)
In-Reply-To: <20211206020423.62402-2-linus.walleij@linaro.org>
On Mon, Dec 06, 2021 at 03:04:22AM +0100, Linus Walleij wrote:
> This switches to retrieveing the configuration of the NTC
> from generic firmware properties so that we get neutral from
> device tree: now ACPI or, more importantly, software nodes
> can be used to spawn NTC devices provided they have the
> required properties.
>
> This was inspired by the similar changes made to the IIO
> drivers.
>
> This was tested on the Ux500 HREF with the NTC devices
> probing from device tree just as fine after this as before.
>
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Chris Lesiak <chris.lesiak@licor.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Applied.
Thanks,
Guenter
> ---
> ChangeLog v1->v2:
> - Rebase on the changes keeping the props parsing code in
> a separate function.
> ---
> drivers/hwmon/ntc_thermistor.c | 36 ++++++++++++++++++----------------
> 1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
> index 12435ef66530..0c8b3dbcb38b 100644
> --- a/drivers/hwmon/ntc_thermistor.c
> +++ b/drivers/hwmon/ntc_thermistor.c
> @@ -9,10 +9,10 @@
> #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/of.h>
> -#include <linux/of_device.h>
> #include <linux/fixp-arith.h>
> #include <linux/iio/consumer.h>
> #include <linux/hwmon.h>
> @@ -595,12 +595,11 @@ static const struct hwmon_chip_info ntc_chip_info = {
> .info = ntc_info,
> };
>
> -static int ntc_thermistor_parse_dt(struct device *dev,
> - struct ntc_data *data)
> +static int ntc_thermistor_parse_props(struct device *dev,
> + struct ntc_data *data)
> {
> struct iio_channel *chan;
> enum iio_chan_type type;
> - struct device_node *np = dev->of_node;
> int ret;
>
> chan = devm_iio_channel_get(dev, NULL);
> @@ -614,14 +613,19 @@ static int ntc_thermistor_parse_dt(struct device *dev,
> if (type != IIO_VOLTAGE)
> return -EINVAL;
>
> - if (of_property_read_u32(np, "pullup-uv", &data->pullup_uv))
> - return -ENODEV;
> - if (of_property_read_u32(np, "pullup-ohm", &data->pullup_ohm))
> - return -ENODEV;
> - if (of_property_read_u32(np, "pulldown-ohm", &data->pulldown_ohm))
> - return -ENODEV;
> + ret = device_property_read_u32(dev, "pullup-uv", &data->pullup_uv);
> + if (ret)
> + return dev_err_probe(dev, ret, "pullup-uv not specified\n");
> +
> + ret = device_property_read_u32(dev, "pullup-ohm", &data->pullup_ohm);
> + if (ret)
> + return dev_err_probe(dev, ret, "pullup-ohm not specified\n");
> +
> + ret = device_property_read_u32(dev, "pulldown-ohm", &data->pulldown_ohm);
> + if (ret)
> + return dev_err_probe(dev, ret, "pulldown-ohm not specified\n");
>
> - if (of_find_property(np, "connected-positive", NULL))
> + if (device_property_read_bool(dev, "connected-positive"))
> data->connect = NTC_CONNECTED_POSITIVE;
> else /* status change should be possible if not always on. */
> data->connect = NTC_CONNECTED_GROUND;
> @@ -634,8 +638,6 @@ static int ntc_thermistor_parse_dt(struct device *dev,
> static int ntc_thermistor_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> - const struct of_device_id *of_id =
> - of_match_device(of_match_ptr(ntc_match), dev);
> const struct platform_device_id *pdev_id;
> struct device *hwmon_dev;
> struct ntc_data *data;
> @@ -645,7 +647,7 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
> if (!data)
> return -ENOMEM;
>
> - ret = ntc_thermistor_parse_dt(dev, data);
> + ret = ntc_thermistor_parse_props(dev, data);
> if (ret)
> return ret;
>
> @@ -660,7 +662,7 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
> + pdev_id = device_get_match_data(dev);
>
> if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) {
> dev_err(dev, "Unknown device type: %lu(%s)\n",
> @@ -688,7 +690,7 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
> static struct platform_driver ntc_thermistor_driver = {
> .driver = {
> .name = "ntc-thermistor",
> - .of_match_table = of_match_ptr(ntc_match),
> + .of_match_table = ntc_match,
> },
> .probe = ntc_thermistor_probe,
> .id_table = ntc_thermistor_id,
next prev parent reply other threads:[~2021-12-07 17:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-06 2:04 [PATCH 1/3 v2] hwmon: (ntc_thermistor): Move and refactor DT parsing Linus Walleij
2021-12-06 2:04 ` [PATCH 2/3 v2] hwmon: (ntc_thermistor): Switch to generic firmware props Linus Walleij
2021-12-07 17:33 ` Guenter Roeck [this message]
2021-12-06 2:04 ` [PATCH 3/3 v2] hwmon: (ntc_thermistor): Move DT matches to the driver block Linus Walleij
2021-12-07 17:33 ` [PATCH 1/3 v2] hwmon: (ntc_thermistor): Move and refactor DT parsing 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=20211207173322.GA659106@roeck-us.net \
--to=linux@roeck-us.net \
--cc=chris.lesiak@licor.com \
--cc=jdelvare@suse.com \
--cc=linus.walleij@linaro.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=peda@axentia.se \
/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