linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>, linux-iio@vger.kernel.org
Subject: Re: [PATCH 12/15 v2] iio: accel: kxsd9: Fetch and handle regulators
Date: Sun, 18 Sep 2016 11:35:34 +0100	[thread overview]
Message-ID: <c1a91fdd-9371-730d-3116-e772dbdda163@kernel.org> (raw)
In-Reply-To: <9ba2fe58-58b5-0f7b-9268-f98e1e813ef5@kernel.org>

On 04/09/16 17:43, Jonathan Cameron wrote:
> On 01/09/16 10:44, Linus Walleij wrote:
>> This adds supply regulator handling for the VDD and IOVDD inputs
>> on the KXSD9 component, makes sure to bring the regulators online
>> during probe and disable them on remove or the errorpath.
>>
>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> I'm lazy and tested this without actually checking the regs were
> either configured correctly in my board file (unlikely ;) or
> actually enabled.  It doesn't break that case :)
Applied.
> 
> Jonathan
>> ---
>> ChangeLog v1->v2:
>> - Rebase on the rest of the series.
>> ---
>>  drivers/iio/accel/kxsd9.c | 88 +++++++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 85 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
>> index 8c6a4559256e..dc53f70e616e 100644
>> --- a/drivers/iio/accel/kxsd9.c
>> +++ b/drivers/iio/accel/kxsd9.c
>> @@ -21,6 +21,8 @@
>>  #include <linux/module.h>
>>  #include <linux/regmap.h>
>>  #include <linux/bitops.h>
>> +#include <linux/delay.h>
>> +#include <linux/regulator/consumer.h>
>>  #include <linux/iio/iio.h>
>>  #include <linux/iio/sysfs.h>
>>  #include <linux/iio/buffer.h>
>> @@ -65,10 +67,12 @@
>>   * struct kxsd9_state - device related storage
>>   * @dev: pointer to the parent device
>>   * @map: regmap to the device
>> + * @regs: regulators for this device, VDD and IOVDD
>>   */
>>  struct kxsd9_state {
>>  	struct device *dev;
>>  	struct regmap *map;
>> +	struct regulator_bulk_data regs[2];
>>  };
>>  
>>  #define KXSD9_SCALE_2G "0.011978"
>> @@ -81,6 +85,12 @@ static const int kxsd9_micro_scales[4] = { 47853, 35934, 23927, 11978 };
>>  
>>  #define KXSD9_ZERO_G_OFFSET -2048
>>  
>> +/*
>> + * Regulator names
>> + */
>> +static const char kxsd9_reg_vdd[] = "vdd";
>> +static const char kxsd9_reg_iovdd[] = "iovdd";
>> +
>>  static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro)
>>  {
>>  	int ret, i;
>> @@ -252,12 +262,69 @@ static int kxsd9_power_up(struct kxsd9_state *st)
>>  {
>>  	int ret;
>>  
>> -	ret = regmap_write(st->map, KXSD9_REG_CTRL_B, 0x40);
>> +	/* Enable the regulators */
>> +	ret = regulator_bulk_enable(ARRAY_SIZE(st->regs), st->regs);
>> +	if (ret) {
>> +		dev_err(st->dev, "Cannot enable regulators\n");
>> +		return ret;
>> +	}
>> +
>> +	/* Power up */
>> +	ret = regmap_write(st->map,
>> +			   KXSD9_REG_CTRL_B,
>> +			   KXSD9_CTRL_B_ENABLE);
>>  	if (ret)
>>  		return ret;
>> -	return regmap_write(st->map, KXSD9_REG_CTRL_C, 0x9b);
>> +
>> +	/*
>> +	 * Set 1000Hz LPF, 2g fullscale, motion wakeup threshold 1g,
>> +	 * latched wakeup
>> +	 */
>> +	ret = regmap_write(st->map,
>> +			   KXSD9_REG_CTRL_C,
>> +			   KXSD9_CTRL_C_LP_1000HZ |
>> +			   KXSD9_CTRL_C_MOT_LEV	|
>> +			   KXSD9_CTRL_C_MOT_LAT |
>> +			   KXSD9_CTRL_C_FS_2G);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/*
>> +	 * Power-up time depends on the LPF setting, but typ 15.9 ms, let's
>> +	 * set 20 ms to allow for some slack.
>> +	 */
>> +	msleep(20);
>> +
>> +	return 0;
>>  };
>>  
>> +static int kxsd9_power_down(struct kxsd9_state *st)
>> +{
>> +	int ret;
>> +
>> +	/*
>> +	 * Set into low power mode - since there may be more users of the
>> +	 * regulators this is the first step of the power saving: it will
>> +	 * make sure we conserve power even if there are others users on the
>> +	 * regulators.
>> +	 */
>> +	ret = regmap_update_bits(st->map,
>> +				 KXSD9_REG_CTRL_B,
>> +				 KXSD9_CTRL_B_ENABLE,
>> +				 0);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/* Disable the regulators */
>> +	ret = regulator_bulk_disable(ARRAY_SIZE(st->regs), st->regs);
>> +	if (ret) {
>> +		dev_err(st->dev, "Cannot disable regulators\n");
>> +		return ret;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>  static const struct iio_info kxsd9_info = {
>>  	.read_raw = &kxsd9_read_raw,
>>  	.write_raw = &kxsd9_write_raw,
>> @@ -292,6 +359,17 @@ int kxsd9_common_probe(struct device *parent,
>>  	indio_dev->modes = INDIO_DIRECT_MODE;
>>  	indio_dev->available_scan_masks = kxsd9_scan_masks;
>>  
>> +	/* Fetch and turn on regulators */
>> +	st->regs[0].supply = kxsd9_reg_vdd;
>> +	st->regs[1].supply = kxsd9_reg_iovdd;
>> +	ret = devm_regulator_bulk_get(parent,
>> +				      ARRAY_SIZE(st->regs),
>> +				      st->regs);
>> +	if (ret) {
>> +		dev_err(parent, "Cannot get regulators\n");
>> +		return ret;
>> +	}
>> +
>>  	kxsd9_power_up(st);
>>  
>>  	ret = iio_triggered_buffer_setup(indio_dev,
>> @@ -300,7 +378,7 @@ int kxsd9_common_probe(struct device *parent,
>>  					 NULL);
>>  	if (ret) {
>>  		dev_err(parent, "triggered buffer setup failed\n");
>> -		return ret;
>> +		goto err_power_down;
>>  	}
>>  
>>  	ret = iio_device_register(indio_dev);
>> @@ -313,6 +391,8 @@ int kxsd9_common_probe(struct device *parent,
>>  
>>  err_cleanup_buffer:
>>  	iio_triggered_buffer_cleanup(indio_dev);
>> +err_power_down:
>> +	kxsd9_power_down(st);
>>  
>>  	return ret;
>>  }
>> @@ -321,9 +401,11 @@ EXPORT_SYMBOL(kxsd9_common_probe);
>>  int kxsd9_common_remove(struct device *parent)
>>  {
>>  	struct iio_dev *indio_dev = dev_get_drvdata(parent);
>> +	struct kxsd9_state *st = iio_priv(indio_dev);
>>  
>>  	iio_triggered_buffer_cleanup(indio_dev);
>>  	iio_device_unregister(indio_dev);
>> +	kxsd9_power_down(st);
>>  
>>  	return 0;
>>  }
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


  reply	other threads:[~2016-09-18 10:35 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-01  9:44 [PATCH 01/15 v2] iio: accel: kxsd9: Fix scaling bug Linus Walleij
2016-09-01  9:44 ` [PATCH 02/15 v2] iio: accel: kxsd9: Split out transport mechanism Linus Walleij
2016-09-03 17:37   ` Jonathan Cameron
2016-09-03 19:29     ` Jonathan Cameron
2016-09-04 20:46       ` Linus Walleij
2016-09-18 10:06   ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 03/15 v2] iio: accel: kxsd9: split out a common remove() function Linus Walleij
2016-09-03 17:38   ` Jonathan Cameron
2016-09-03 19:29     ` Jonathan Cameron
2016-09-18 10:08       ` Jonathan Cameron
2016-09-04 16:33   ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 04/15 v2] iio: accel: kxsd9: Split out SPI transport Linus Walleij
2016-09-03 19:24   ` Jonathan Cameron
2016-09-03 19:29     ` Jonathan Cameron
2016-09-18 10:09       ` Jonathan Cameron
2016-09-04 16:33   ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 05/15 v2] iio: accel: kxsd9: Do away with the write2 helper Linus Walleij
2016-09-03 19:25   ` Jonathan Cameron
2016-09-03 19:30     ` Jonathan Cameron
2016-09-18 10:27       ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 06/15 v2] iio: accel: kxsd9: Convert to use regmap for transport Linus Walleij
2016-09-18 10:28   ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 07/15 v2] iio: accel: kxsd9: Add I2C transport Linus Walleij
2016-09-18 10:29   ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 08/15 v2] iio: accel: kxsd9: Drop the buffer lock Linus Walleij
2016-09-01  9:44 ` [PATCH 09/15 v2] iio: accel: kxsd9: Fix up offset and scaling Linus Walleij
2016-09-18 10:31   ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 10/15 v2] iio: accel: kxsd9: Add triggered buffer handling Linus Walleij
2016-09-04 16:40   ` Jonathan Cameron
2016-09-18 10:32     ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 11/15 v2] iio: accel: kxsd9: Deploy proper register bit defines Linus Walleij
2016-09-04 16:42   ` Jonathan Cameron
2016-09-18 10:33     ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 12/15 v2] iio: accel: kxsd9: Fetch and handle regulators Linus Walleij
2016-09-04 16:43   ` Jonathan Cameron
2016-09-18 10:35     ` Jonathan Cameron [this message]
2016-09-01  9:44 ` [PATCH 13/15 v2] iio: accel: kxsd9: Replace "parent" with "dev" Linus Walleij
2016-09-04 16:46   ` Jonathan Cameron
2016-09-18 10:35     ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 14/15 v2] iio: accel: kxsd9: Deploy system and runtime PM Linus Walleij
2016-09-04 16:48   ` Jonathan Cameron
2016-09-18 10:36     ` Jonathan Cameron
2016-09-01  9:44 ` [PATCH 15/15 v2] iio: accel: kxsd9: Support reading a mounting matrix Linus Walleij
2016-09-04 16:51   ` Jonathan Cameron
2016-09-18 10:36     ` Jonathan Cameron
2016-09-03 17:31 ` [PATCH 01/15 v2] iio: accel: kxsd9: Fix scaling bug 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=c1a91fdd-9371-730d-3116-e772dbdda163@kernel.org \
    --to=jic23@kernel.org \
    --cc=linus.walleij@linaro.org \
    --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 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).