All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-iio@vger.kernel.org, Daniel Baluta <daniel.baluta@intel.com>
Subject: Re: [PATCH 4/8] iio: adc: ti-ads1015: enable conversion when CONFIG_PM is not set
Date: Sat, 15 Jul 2017 13:24:14 +0100	[thread overview]
Message-ID: <20170715132414.4080c158@kernel.org> (raw)
In-Reply-To: <1499877124-21658-5-git-send-email-akinobu.mita@gmail.com>

On Thu, 13 Jul 2017 01:32:00 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:

> The ADS1015 device have two operating modes, continuous conversion mode
> and single-shot mode.  This driver assumes that the continuous conversion
> mode is selected by runtime resume callback when the ADC result is
> requested.
> 
> If CONFIG_PM is disabled, the device is always in the default single-shot
> mode and no one begins a single conversion.  So the conversion register
> doesn't contain valid ADC result.  Fix it by changing the continuous mode
> in probe function.  This also adds a helper function to set conversion
> mode as there are a fair number of users.
> 
> Cc: Daniel Baluta <daniel.baluta@intel.com>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Two patches please.  First one is a fix to make it work without config_pm
second can do the refactor (and can be applied after the first one
has gone to stable and worked it's way back to our upstream).

Good catch,

Jonathan
> ---
>  drivers/iio/adc/ti-ads1015.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> index 1edf323..984d4bb 100644
> --- a/drivers/iio/adc/ti-ads1015.c
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -556,6 +556,13 @@ static void ads1015_get_channels_config(struct i2c_client *client)
>  	}
>  }
>  
> +static int ads1015_set_conv_mode(struct ads1015_data *data, int mode)
> +{
> +	return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
> +				  ADS1015_CFG_MOD_MASK,
> +				  mode << ADS1015_CFG_MOD_SHIFT);
> +}
> +
>  static int ads1015_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *id)
>  {
> @@ -613,6 +620,11 @@ static int ads1015_probe(struct i2c_client *client,
>  		dev_err(&client->dev, "iio triggered buffer setup failed\n");
>  		return ret;
>  	}
> +
> +	ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
> +	if (ret)
> +		return ret;
> +
>  	ret = pm_runtime_set_active(&client->dev);
>  	if (ret)
>  		goto err_buffer_cleanup;
> @@ -648,9 +660,7 @@ static int ads1015_remove(struct i2c_client *client)
>  	iio_triggered_buffer_cleanup(indio_dev);
>  
>  	/* power down single shot mode */
> -	return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
> -				  ADS1015_CFG_MOD_MASK,
> -				  ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
> +	return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
>  }
>  
>  #ifdef CONFIG_PM
> @@ -659,9 +669,7 @@ static int ads1015_runtime_suspend(struct device *dev)
>  	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>  	struct ads1015_data *data = iio_priv(indio_dev);
>  
> -	return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
> -				  ADS1015_CFG_MOD_MASK,
> -				  ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
> +	return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
>  }
>  
>  static int ads1015_runtime_resume(struct device *dev)
> @@ -669,9 +677,7 @@ static int ads1015_runtime_resume(struct device *dev)
>  	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>  	struct ads1015_data *data = iio_priv(indio_dev);
>  
> -	return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
> -				  ADS1015_CFG_MOD_MASK,
> -				  ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
> +	return ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
>  }
>  #endif
>  


  reply	other threads:[~2017-07-15 12:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12 16:31 [PATCH 0/8] iio: adc: ti-ads1015: fixes, cleanups, and threshold event support Akinobu Mita
2017-07-12 16:31 ` [PATCH 1/8] iio: adc: ti-ads1015: fix incorrect data rate setting update Akinobu Mita
2017-07-15 12:16   ` Jonathan Cameron
2017-07-12 16:31 ` [PATCH 2/8] iio: adc: ti-ads1015: remove unnecessary config register update Akinobu Mita
2017-07-15 12:19   ` Jonathan Cameron
2017-07-12 16:31 ` [PATCH 3/8] iio: adc: ti-ads1015: fix scale information for ADS1115 Akinobu Mita
2017-07-15 12:21   ` Jonathan Cameron
2017-07-12 16:32 ` [PATCH 4/8] iio: adc: ti-ads1015: enable conversion when CONFIG_PM is not set Akinobu Mita
2017-07-15 12:24   ` Jonathan Cameron [this message]
2017-07-12 16:32 ` [PATCH 5/8] iio: adc: ti-ads1015: avoid getting stale result after runtime resume Akinobu Mita
2017-07-15 12:25   ` Jonathan Cameron
2017-07-12 16:32 ` [PATCH 6/8] iio: adc: ti-ads1015: use devm_iio_triggered_buffer_setup Akinobu Mita
2017-07-15 12:28   ` Jonathan Cameron
2017-07-16 16:02     ` Akinobu Mita
2017-07-17 11:52       ` Jonathan Cameron
2017-07-12 16:32 ` [PATCH 7/8] iio: adc: ti-ads1015: use iio_device_claim_direct_mode() Akinobu Mita
2017-07-15 12:30   ` Jonathan Cameron
2017-07-12 16:32 ` [PATCH 8/8] iio: adc: ti-ads1015: add threshold event support Akinobu Mita
2017-07-15 12:45   ` Jonathan Cameron
2017-07-17 16:45     ` Akinobu Mita
2017-07-17 20:35       ` 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=20170715132414.4080c158@kernel.org \
    --to=jic23@kernel.org \
    --cc=akinobu.mita@gmail.com \
    --cc=daniel.baluta@intel.com \
    --cc=linux-iio@vger.kernel.org \
    /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 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.