public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Irina Tirdea <irina.tirdea@intel.com>,
	linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>
Cc: linux-kernel@vger.kernel.org, Vlad Dogaru <vlad.dogaru@intel.com>
Subject: Re: [PATCH v2 13/17] iio: accel: mma9553: refactor mma9553_read_raw
Date: Sun, 26 Apr 2015 19:53:45 +0100	[thread overview]
Message-ID: <553D3439.50802@kernel.org> (raw)
In-Reply-To: <1428939664-12503-14-git-send-email-irina.tirdea@intel.com>

On 13/04/15 16:41, Irina Tirdea wrote:
> Refactor code for simplicity and clarity.
> 
> Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
> Suggested-by: Hartmut Knaack <knaack.h@gmx.de>
Applied.
> ---
>  drivers/iio/accel/mma9553.c | 101 +++++++++++++++-----------------------------
>  1 file changed, 33 insertions(+), 68 deletions(-)
> 
> diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c
> index 5755977..8bfc618 100644
> --- a/drivers/iio/accel/mma9553.c
> +++ b/drivers/iio/accel/mma9553.c
> @@ -440,6 +440,32 @@ static int mma9553_init(struct mma9553_data *data)
>  	return mma9551_set_device_state(data->client, true);
>  }
>  
> +static int mma9553_read_status_word(struct mma9553_data *data, u16 reg,
> +				    u16 *tmp)
> +{
> +	bool powered_on;
> +	int ret;
> +
> +	/*
> +	 * The HW only counts steps and other dependent
> +	 * parameters (speed, distance, calories, activity)
> +	 * if power is on (from enabling an event or the
> +	 * step counter).
> +	 */
> +	powered_on = mma9553_is_any_event_enabled(data, false, 0) ||
> +		     data->stepcnt_enabled;
> +	if (!powered_on) {
> +		dev_err(&data->client->dev, "No channels enabled\n");
> +		return -EINVAL;
> +	}
> +
> +	mutex_lock(&data->mutex);
> +	ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER,
> +				       reg, tmp);
> +	mutex_unlock(&data->mutex);
> +	return ret;
> +}
> +
>  static int mma9553_read_raw(struct iio_dev *indio_dev,
>  			    struct iio_chan_spec const *chan,
>  			    int *val, int *val2, long mask)
> @@ -448,70 +474,30 @@ static int mma9553_read_raw(struct iio_dev *indio_dev,
>  	int ret;
>  	u16 tmp;
>  	u8 activity;
> -	bool powered_on;
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_PROCESSED:
>  		switch (chan->type) {
>  		case IIO_STEPS:
> -			/*
> -			 * The HW only counts steps and other dependent
> -			 * parameters (speed, distance, calories, activity)
> -			 * if power is on (from enabling an event or the
> -			 * step counter).
> -			 */
> -			powered_on =
> -			    mma9553_is_any_event_enabled(data, false, 0) ||
> -			    data->stepcnt_enabled;
> -			if (!powered_on) {
> -				dev_err(&data->client->dev,
> -					"No channels enabled\n");
> -				return -EINVAL;
> -			}
> -			mutex_lock(&data->mutex);
> -			ret = mma9551_read_status_word(data->client,
> -						       MMA9551_APPID_PEDOMETER,
> +			ret = mma9553_read_status_word(data,
>  						       MMA9553_REG_STEPCNT,
>  						       &tmp);
> -			mutex_unlock(&data->mutex);
>  			if (ret < 0)
>  				return ret;
>  			*val = tmp;
>  			return IIO_VAL_INT;
>  		case IIO_DISTANCE:
> -			powered_on =
> -			    mma9553_is_any_event_enabled(data, false, 0) ||
> -			    data->stepcnt_enabled;
> -			if (!powered_on) {
> -				dev_err(&data->client->dev,
> -					"No channels enabled\n");
> -				return -EINVAL;
> -			}
> -			mutex_lock(&data->mutex);
> -			ret = mma9551_read_status_word(data->client,
> -						       MMA9551_APPID_PEDOMETER,
> +			ret = mma9553_read_status_word(data,
>  						       MMA9553_REG_DISTANCE,
>  						       &tmp);
> -			mutex_unlock(&data->mutex);
>  			if (ret < 0)
>  				return ret;
>  			*val = tmp;
>  			return IIO_VAL_INT;
>  		case IIO_ACTIVITY:
> -			powered_on =
> -			    mma9553_is_any_event_enabled(data, false, 0) ||
> -			    data->stepcnt_enabled;
> -			if (!powered_on) {
> -				dev_err(&data->client->dev,
> -					"No channels enabled\n");
> -				return -EINVAL;
> -			}
> -			mutex_lock(&data->mutex);
> -			ret = mma9551_read_status_word(data->client,
> -						       MMA9551_APPID_PEDOMETER,
> +			ret = mma9553_read_status_word(data,
>  						       MMA9553_REG_STATUS,
>  						       &tmp);
> -			mutex_unlock(&data->mutex);
>  			if (ret < 0)
>  				return ret;
>  
> @@ -536,38 +522,17 @@ static int mma9553_read_raw(struct iio_dev *indio_dev,
>  		case IIO_VELOCITY:	/* m/h */
>  			if (chan->channel2 != IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z)
>  				return -EINVAL;
> -			powered_on =
> -			    mma9553_is_any_event_enabled(data, false, 0) ||
> -			    data->stepcnt_enabled;
> -			if (!powered_on) {
> -				dev_err(&data->client->dev,
> -					"No channels enabled\n");
> -				return -EINVAL;
> -			}
> -			mutex_lock(&data->mutex);
> -			ret = mma9551_read_status_word(data->client,
> -						       MMA9551_APPID_PEDOMETER,
> -						       MMA9553_REG_SPEED, &tmp);
> -			mutex_unlock(&data->mutex);
> +			ret = mma9553_read_status_word(data,
> +						       MMA9553_REG_SPEED,
> +						       &tmp);
>  			if (ret < 0)
>  				return ret;
>  			*val = tmp;
>  			return IIO_VAL_INT;
>  		case IIO_ENERGY:	/* Cal or kcal */
> -			powered_on =
> -			    mma9553_is_any_event_enabled(data, false, 0) ||
> -			    data->stepcnt_enabled;
> -			if (!powered_on) {
> -				dev_err(&data->client->dev,
> -					"No channels enabled\n");
> -				return -EINVAL;
> -			}
> -			mutex_lock(&data->mutex);
> -			ret = mma9551_read_status_word(data->client,
> -						       MMA9551_APPID_PEDOMETER,
> +			ret = mma9553_read_status_word(data,
>  						       MMA9553_REG_CALORIES,
>  						       &tmp);
> -			mutex_unlock(&data->mutex);
>  			if (ret < 0)
>  				return ret;
>  			*val = tmp;
> 


  reply	other threads:[~2015-04-26 18:53 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 15:40 [PATCH v2 00/17] Fixes for the mma9553 driver Irina Tirdea
2015-04-13 15:40 ` [PATCH v2 01/17] iio: accel: mma9553: fix endianness issue when reading status Irina Tirdea
2015-04-26 18:40   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 02/17] iio: accel: mma9553: check input value for activity period Irina Tirdea
2015-04-26 18:43   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 03/17] iio: accel: mma9551_core: prevent buffer overrun Irina Tirdea
2015-04-26 18:41   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 04/17] iio: accel: mma9553: add enable channel for activity Irina Tirdea
2015-04-26 18:42   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 05/17] iio: accel: mma9551_core: wrong doc fixes Irina Tirdea
2015-04-26 18:45   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 06/17] iio: accel: mma9551_core: typo fix in RSC APP ID Irina Tirdea
2015-04-26 18:46   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 07/17] iio: accel: mma9553: check for error in reading initial activity and stepcnt Irina Tirdea
2015-04-26 18:47   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 08/17] iio: accel: mma9553: return 0 as indication of success Irina Tirdea
2015-04-13 15:40 ` [PATCH v2 09/17] iio: accel: mma9553: comment and error message fixes Irina Tirdea
2015-04-26 18:48   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 10/17] iio: accel: mma9553: use GENMASK Irina Tirdea
2015-04-26 18:49   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 11/17] iio: accel: mma9553: prefix naming fixes Irina Tirdea
2015-04-26 18:49   ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 12/17] iio: accel: mma9553: fix gpio bitnum init value Irina Tirdea
2015-04-26 18:53   ` Jonathan Cameron
2015-04-13 15:41 ` [PATCH v2 13/17] iio: accel: mma9553: refactor mma9553_read_raw Irina Tirdea
2015-04-26 18:53   ` Jonathan Cameron [this message]
2015-04-13 15:41 ` [PATCH v2 14/17] iio: accel: mma9551_core: use size in words for word buffers Irina Tirdea
2015-04-26 19:04   ` Jonathan Cameron
2015-04-29 12:20     ` Tirdea, Irina
2015-06-14 15:00       ` Jonathan Cameron
2015-06-23 14:17         ` Tirdea, Irina
2015-04-13 15:41 ` [PATCH v2 15/17] iio: accel: mma9553: fix alignment issues Irina Tirdea
2015-06-14 15:01   ` Jonathan Cameron
2015-04-13 15:41 ` [PATCH v2 16/17] iio: accel: mma9553: document use of mutex Irina Tirdea
2015-06-14 15:02   ` Jonathan Cameron
2015-04-13 15:41 ` [PATCH v2 17/17] iio: accel: mma9553: use unsigned counters Irina Tirdea
2015-06-14 15:04   ` Jonathan Cameron
2015-06-23 14:17     ` Tirdea, Irina
2015-04-26 21:50 ` [PATCH v2 00/17] Fixes for the mma9553 driver Hartmut Knaack

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=553D3439.50802@kernel.org \
    --to=jic23@kernel.org \
    --cc=irina.tirdea@intel.com \
    --cc=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vlad.dogaru@intel.com \
    /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