All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Adriana Reus <adriana.reus@intel.com>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	robh+dt@kernel.org, ijc+devicetree@hellion.org.uk,
	galak@codeaurora.org, pawel.moll@arm.com, pmeerw@pmeerw.net,
	lars@metafoo.de
Subject: Re: [PATCH 3/5] iio: light: us5182d: Add functions for selectively enabling als and proximity
Date: Sun, 29 Nov 2015 16:13:15 +0000	[thread overview]
Message-ID: <565B241B.3000100@kernel.org> (raw)
In-Reply-To: <1448362792-5181-4-git-send-email-adriana.reus@intel.com>

On 24/11/15 10:59, Adriana Reus wrote:
> Keep track of the als and px enabled/disabled status in
> order to enable them selectively.
> 
> Signed-off-by: Adriana Reus <adriana.reus@intel.com>
Couple more nitpicks, but again fixed up during apply.
> ---
>  drivers/iio/light/us5182d.c | 64 ++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 60 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c
> index 7993014..3d959f3 100644
> --- a/drivers/iio/light/us5182d.c
> +++ b/drivers/iio/light/us5182d.c
> @@ -119,6 +119,9 @@ struct us5182d_data {
>  	u8 opmode;
>  	u8 power_mode;
>  
> +	bool als_enabled;
> +	bool px_enabled;
> +
>  	bool default_continuous;
>  };
>  
> @@ -227,6 +230,48 @@ static int us5182d_set_opmode(struct us5182d_data *data, u8 mode)
>  	return 0;
>  }
>  
> +static int us5182d_als_enable(struct us5182d_data *data)
> +{
> +	int ret;
> +	u8 mode;
> +
> +	if (data->power_mode == US5182D_ONESHOT)
> +		return us5182d_set_opmode(data, US5182D_ALS_ONLY);
> +
> +	if (data->als_enabled)
> +		return 0;
> +
> +	mode = data->px_enabled ? US5182D_ALS_PX : US5182D_ALS_ONLY;
> +
> +	ret = us5182d_set_opmode(data, mode);
> +	if (ret < 0)
> +		return ret;
> +
> +	data->als_enabled = true;
Blank line here ideally.
> +	return 0;
> +}
> +
> +static int us5182d_px_enable(struct us5182d_data *data)
> +{
> +	int ret;
> +	u8 mode;
> +
> +	if (data->power_mode == US5182D_ONESHOT)
> +		return us5182d_set_opmode(data, US5182D_PX_ONLY);
> +
> +	if (data->px_enabled)
> +		return 0;
> +
> +	mode = data->als_enabled ? US5182D_ALS_PX : US5182D_PX_ONLY;
> +
> +	ret = us5182d_set_opmode(data, mode);
> +	if (ret < 0)
> +		return ret;
> +
> +	data->px_enabled = true;
And here...
> +	return 0;
> +}
> +
>  static int us5182d_shutdown_en (struct us5182d_data *data, u8 state)
>  {
>  	int ret;
> @@ -241,7 +286,16 @@ static int us5182d_shutdown_en (struct us5182d_data *data, u8 state)
>  	ret = ret & ~US5182D_CFG0_SHUTDOWN_EN;
>  	ret = ret | state;
>  
> -	return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret);
> +	ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (state & US5182D_CFG0_SHUTDOWN_EN) {
> +		data->als_enabled = false;
> +		data->px_enabled = false;
> +	}
> +
> +	return ret;
>  }
>  
>  static int us5182d_read_raw(struct iio_dev *indio_dev,
> @@ -261,7 +315,7 @@ static int us5182d_read_raw(struct iio_dev *indio_dev,
>  				if (ret < 0)
>  					goto out_err;
>  			}
> -			ret = us5182d_set_opmode(data, US5182D_OPMODE_ALS);
> +			ret = us5182d_als_enable(data);
>  			if (ret < 0)
>  				goto out_err;
>  
> @@ -278,7 +332,7 @@ static int us5182d_read_raw(struct iio_dev *indio_dev,
>  				if (ret < 0)
>  					goto out_err;
>  			}
> -			ret = us5182d_set_opmode(data, US5182D_OPMODE_PX);
> +			ret = us5182d_px_enable(data);
>  			if (ret < 0)
>  				goto out_err;
>  
> @@ -421,6 +475,9 @@ static int us5182d_init(struct iio_dev *indio_dev)
>  			return ret;
>  	}
>  
> +	data->als_enabled = true;
> +	data->px_enabled = true;
> +
>  	if (!data->default_continuous) {
>  		ret = us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN);
>  		if (ret < 0)
> @@ -428,7 +485,6 @@ static int us5182d_init(struct iio_dev *indio_dev)
>  		data->power_mode = US5182D_ONESHOT;
>  	}
>  
> -
>  	return ret;
>  }
>  
> 


  reply	other threads:[~2015-11-29 16:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 10:59 [PATCH 0/5] iio: light: us5281d: Add power managmenet and interrupt support Adriana Reus
2015-11-24 10:59 ` Adriana Reus
2015-11-24 10:59 ` [PATCH 1/5] iio: light: us5182d: Add property for choosing default power mode Adriana Reus
2015-11-29 14:35   ` Jonathan Cameron
2015-11-24 10:59 ` [PATCH 2/5] Documentation: devicetree: Add property for controlling power saving mode for the us5182 als sensor Adriana Reus
2015-11-25  0:01   ` Rob Herring
2015-11-25  0:01     ` Rob Herring
2015-11-25  9:50     ` Adriana Reus
2015-11-25 23:55       ` Rob Herring
2015-11-25 23:55         ` Rob Herring
2015-11-29 14:36         ` Jonathan Cameron
2015-11-24 10:59 ` [PATCH 3/5] iio: light: us5182d: Add functions for selectively enabling als and proximity Adriana Reus
2015-11-24 10:59   ` Adriana Reus
2015-11-29 16:13   ` Jonathan Cameron [this message]
2015-11-24 10:59 ` [PATCH 4/5] iio: light: us8152d: Add power management support Adriana Reus
2015-11-29 14:59   ` Jonathan Cameron
2015-11-24 10:59 ` [PATCH 5/5] iio: light: us5182d: Add interrupt support and events Adriana Reus
2015-11-29 14:59   ` 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=565B241B.3000100@kernel.org \
    --to=jic23@kernel.org \
    --cc=adriana.reus@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pawel.moll@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@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.