From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Subject: Re: [PATCH v3 2/2] iio: adc: ti-ads1015: Make use of device property API
Date: Sat, 7 Dec 2019 11:09:37 +0000 [thread overview]
Message-ID: <20191207110937.6a0c1229@archlinux> (raw)
In-Reply-To: <20191205174637.47610-2-andriy.shevchenko@linux.intel.com>
On Thu, 5 Dec 2019 19:46:37 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> Make use of device property API in this driver so that both OF based
> system and ACPI based system can use this driver.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Applied.
Thanks,
Jonathan
> ---
> v2:
> - use device_for_each_child_node()
> - leave 'node' variable name (reduce churn)
> drivers/iio/adc/ti-ads1015.c | 57 ++++++++++++++++--------------------
> 1 file changed, 26 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> index 3b123b4f0b99..5ea4f45d6bad 100644
> --- a/drivers/iio/adc/ti-ads1015.c
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -12,10 +12,10 @@
> */
>
> #include <linux/module.h>
> -#include <linux/of_device.h>
> #include <linux/init.h>
> #include <linux/irq.h>
> #include <linux/i2c.h>
> +#include <linux/property.h>
> #include <linux/regmap.h>
> #include <linux/pm_runtime.h>
> #include <linux/mutex.h>
> @@ -77,6 +77,7 @@
> #define ADS1015_DEFAULT_CHAN 0
>
> enum chip_ids {
> + ADSXXXX = 0,
> ADS1015,
> ADS1115,
> };
> @@ -843,65 +844,58 @@ static const struct iio_info ads1115_info = {
> .attrs = &ads1115_attribute_group,
> };
>
> -#ifdef CONFIG_OF
> -static int ads1015_get_channels_config_of(struct i2c_client *client)
> +static int ads1015_client_get_channels_config(struct i2c_client *client)
> {
> struct iio_dev *indio_dev = i2c_get_clientdata(client);
> struct ads1015_data *data = iio_priv(indio_dev);
> - struct device_node *node;
> + struct device *dev = &client->dev;
> + struct fwnode_handle *node;
> + int i = -1;
>
> - if (!client->dev.of_node ||
> - !of_get_next_child(client->dev.of_node, NULL))
> - return -EINVAL;
> -
> - for_each_child_of_node(client->dev.of_node, node) {
> + device_for_each_child_node(dev, node) {
> u32 pval;
> unsigned int channel;
> unsigned int pga = ADS1015_DEFAULT_PGA;
> unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
>
> - if (of_property_read_u32(node, "reg", &pval)) {
> - dev_err(&client->dev, "invalid reg on %pOF\n",
> - node);
> + if (fwnode_property_read_u32(node, "reg", &pval)) {
> + dev_err(dev, "invalid reg on %pfw\n", node);
> continue;
> }
>
> channel = pval;
> if (channel >= ADS1015_CHANNELS) {
> - dev_err(&client->dev,
> - "invalid channel index %d on %pOF\n",
> + dev_err(dev, "invalid channel index %d on %pfw\n",
> channel, node);
> continue;
> }
>
> - if (!of_property_read_u32(node, "ti,gain", &pval)) {
> + if (!fwnode_property_read_u32(node, "ti,gain", &pval)) {
> pga = pval;
> if (pga > 6) {
> - dev_err(&client->dev, "invalid gain on %pOF\n",
> - node);
> - of_node_put(node);
> + dev_err(dev, "invalid gain on %pfw\n", node);
> + fwnode_handle_put(node);
> return -EINVAL;
> }
> }
>
> - if (!of_property_read_u32(node, "ti,datarate", &pval)) {
> + if (!fwnode_property_read_u32(node, "ti,datarate", &pval)) {
> data_rate = pval;
> if (data_rate > 7) {
> - dev_err(&client->dev,
> - "invalid data_rate on %pOF\n",
> - node);
> - of_node_put(node);
> + dev_err(dev, "invalid data_rate on %pfw\n", node);
> + fwnode_handle_put(node);
> return -EINVAL;
> }
> }
>
> data->channel_data[channel].pga = pga;
> data->channel_data[channel].data_rate = data_rate;
> +
> + i++;
> }
>
> - return 0;
> + return i < 0 ? -EINVAL : 0;
> }
> -#endif
>
> static void ads1015_get_channels_config(struct i2c_client *client)
> {
> @@ -910,10 +904,9 @@ static void ads1015_get_channels_config(struct i2c_client *client)
> struct iio_dev *indio_dev = i2c_get_clientdata(client);
> struct ads1015_data *data = iio_priv(indio_dev);
>
> -#ifdef CONFIG_OF
> - if (!ads1015_get_channels_config_of(client))
> + if (!ads1015_client_get_channels_config(client))
> return;
> -#endif
> +
> /* fallback on default configuration */
> for (k = 0; k < ADS1015_CHANNELS; ++k) {
> data->channel_data[k].pga = ADS1015_DEFAULT_PGA;
> @@ -951,9 +944,8 @@ static int ads1015_probe(struct i2c_client *client,
> indio_dev->name = ADS1015_DRV_NAME;
> indio_dev->modes = INDIO_DIRECT_MODE;
>
> - if (client->dev.of_node)
> - chip = (enum chip_ids)of_device_get_match_data(&client->dev);
> - else
> + chip = (enum chip_ids)device_get_match_data(&client->dev);
> + if (chip == ADSXXXX)
> chip = id->driver_data;
> switch (chip) {
> case ADS1015:
> @@ -968,6 +960,9 @@ static int ads1015_probe(struct i2c_client *client,
> indio_dev->info = &ads1115_info;
> data->data_rate = (unsigned int *) &ads1115_data_rate;
> break;
> + default:
> + dev_err(&client->dev, "Unknown chip %d\n", chip);
> + return -EINVAL;
> }
>
> data->event_channel = ADS1015_CHANNELS;
next prev parent reply other threads:[~2019-12-07 11:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 17:46 [PATCH v3 1/2] iio: adc: ti-ads1025: Get rid of legacy platform data Andy Shevchenko
2019-12-05 17:46 ` [PATCH v3 2/2] iio: adc: ti-ads1015: Make use of device property API Andy Shevchenko
2019-12-07 11:09 ` Jonathan Cameron [this message]
2019-12-09 14:39 ` Andy Shevchenko
2019-12-07 11:09 ` [PATCH v3 1/2] iio: adc: ti-ads1025: Get rid of legacy platform data Jonathan Cameron
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=20191207110937.6a0c1229@archlinux \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.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