Skip to contentSkip to conversation

iio: accell: mma8452: Reduce sleep time when data not ready

PATCH Superseded Richard Tresidder 2 participants 8 messages May 7, 2018 – May 10, 2018 IIO

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: accell: mma8452: Reduce sleep time when data not ready

Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Fix Fallthru warning in case statement Signed-off-by: Richard Tresidder <[email protected]> -- diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 7a2da7f..948740d 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -106,6 +106,7 @@ struct mma8452_data { u8 ctrl_reg1; u8 data_cfg; const struct mma_chip_info *chip_info; + int sleep_val; }; /** @@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data) if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY) return 0; - msleep(20); + if (data->sleep_val <= 20) + usleep_range(data->sleep_val * 250, data->sleep_val * 500); + else + msleep(20); } dev_err(&data->client->dev, "data not ready\n"); @@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int mma8452_calculate_sleep(struct mma8452_data *data) +{ + int ret, i = mma8452_get_odr_index(data); + + if (mma8452_samp_freq[i][0] > 0) + ret = 1000 / mma8452_samp_freq[i][0]; + else + ret = 1000; + + return ret == 0 ? 1 : ret; +} + static int mma8452_standby(struct mma8452_data *data) { return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, @@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; + data->sleep_val = mma8452_calculate_sleep(data); + ret = mma8452_change_config(data, MMA8452_CTRL_REG1, data->ctrl_reg1); break; @@ -1528,6 +1546,7 @@ static int mma8452_probe(struct i2c_client *client, case FXLS8471_DEVICE_ID: if (ret == data->chip_info->chip_id) break; + /* FALLTHRU */ default: return -ENODEV; } @@ -1593,6 +1612,9 @@ static int mma8452_probe(struct i2c_client *client, data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT); + + data->sleep_val = mma8452_calculate_sleep(data); + ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, data->ctrl_reg1); if (ret < 0)

#1 lore raw

PATCH v2 1/1 iio: accell: mma8452: Reduce sleep time when data not ready

Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Fix Fallthru warning in case statement

--

drivers/iio/accel/mma8452.c +23 -1
index 7a2da7f..948740d 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
 	u8 ctrl_reg1;
 	u8 data_cfg;
 	const struct mma_chip_info *chip_info;
+	int sleep_val;
 };
 
  /**
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
 		if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
 			return 0;
 
-		msleep(20);
+		if (data->sleep_val <= 20)
+			usleep_range(data->sleep_val * 250, data->sleep_val * 500);
+		else
+			msleep(20);
 	}
 
 	dev_err(&data->client->dev, "data not ready\n");
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+	int ret, i = mma8452_get_odr_index(data);
+	
+	if (mma8452_samp_freq[i][0] > 0)
+		ret = 1000 / mma8452_samp_freq[i][0];
+	else 
+		ret = 1000;
+
+	return ret == 0 ? 1 : ret;
+}
+
 static int mma8452_standby(struct mma8452_data *data)
 {
 	return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
 		data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
 		data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
 
+		data->sleep_val = mma8452_calculate_sleep(data);
+
 		ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
 					    data->ctrl_reg1);
 		break;
@@ -1528,6 +1546,7 @@ static int mma8452_probe(struct i2c_client *client,
 	case FXLS8471_DEVICE_ID:
 		if (ret == data->chip_info->chip_id)
 			break;
+		/* FALLTHRU */
 	default:
 		return -ENODEV;
 	}
@@ -1593,6 +1612,9 @@ static int mma8452_probe(struct i2c_client *client,
 
 	data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
 			  (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
+				
+	data->sleep_val = mma8452_calculate_sleep(data);
+
 	ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
 					data->ctrl_reg1);
 	if (ret < 0)
#2 lore raw
Quoted 58 lines · Richard Tresidder

Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Fix Fallthru warning in case statement

--

drivers/iio/accel/mma8452.c +19 -1
index 7a2da7f..948740d 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
  	u8 ctrl_reg1;
  	u8 data_cfg;
  	const struct mma_chip_info *chip_info;
+	int sleep_val;
  };
 
   /**
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
  		if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
  			return 0;
 
-		msleep(20);
+		if (data->sleep_val <= 20)
+			usleep_range(data->sleep_val * 250, data->sleep_val * 500);
+		else
+			msleep(20);
  	}
 
  	dev_err(&data->client->dev, "data not ready\n");
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
  	return -EINVAL;
  }
 
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+	int ret, i = mma8452_get_odr_index(data);
+	
+	if (mma8452_samp_freq[i][0] > 0)
+		ret = 1000 / mma8452_samp_freq[i][0];
+	else
+		ret = 1000;
+
+	return ret == 0 ? 1 : ret;
+}
+
  static int mma8452_standby(struct mma8452_data *data)
  {
  	return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
  		data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
  		data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
 
+		data->sleep_val = mma8452_calculate_sleep(data);
+
  		ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
  					    data->ctrl_reg1);
  		break;

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1549

Quoted 4 lines
drivers/iio/accel/mma8452.c +1 -0
@@ -1528,6 +1546,7 @@ static int mma8452_probe(struct i2c_client *client,
  	case FXLS8471_DEVICE_ID:
  		if (ret == data->chip_info->chip_id)
  			break;
+		/* FALLTHRU */

Please do this in a seperate patch.

Quoted 14 lines
drivers/iio/accel/mma8452.c +3 -0
  	default:
  		return -ENODEV;
  	}
@@ -1593,6 +1612,9 @@ static int mma8452_probe(struct i2c_client *client,
 
  	data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
  			  (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
+				
+	data->sleep_val = mma8452_calculate_sleep(data);
+
  	ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
  					data->ctrl_reg1);
  	if (ret < 0)
#3 lore raw

Hi Martin
Thanks, I'll remove that /*FALLTHRU*/ compiler "disable warning" comment
I assume it is the correct comment to use to shut the compiler up?
I've also fixed up a couple of whitespace issues that checkpatch pulled me up on. Hard to know when to merge something or not.. seen that one merged in a few times in logs..

Regards
Richard

Quoted 81 lines · Martin Kepplinger
Quoted 57 lines · Richard Tresidder

Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Fix Fallthru warning in case statement

--

drivers/iio/accel/mma8452.c +1 -0
index 7a2da7f..948740d 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
       u8 ctrl_reg1;
       u8 data_cfg;
       const struct mma_chip_info *chip_info;
+    int sleep_val;
   };


   /**

drivers/iio/accel/mma8452.c +0 -0
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
           if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
               return 0;


-        msleep(20);
+        if (data->sleep_val <= 20)
+            usleep_range(data->sleep_val * 250, data->sleep_val * 500); +        else
+            msleep(20);
      }

      dev_err(&data->client->dev, "data not ready\n");

drivers/iio/accel/mma8452.c +0 -0
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
       return -EINVAL;
   }

drivers/iio/accel/mma8452.c +12 -0
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+    int ret, i = mma8452_get_odr_index(data);
+    
+    if (mma8452_samp_freq[i][0] > 0)
+        ret = 1000 / mma8452_samp_freq[i][0];
+    else
+        ret = 1000;
+
+    return ret == 0 ? 1 : ret;
+}
+

  static int mma8452_standby(struct mma8452_data *data)
  {
      return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,

drivers/iio/accel/mma8452.c +0 -0
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
           data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
           data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;


+        data->sleep_val = mma8452_calculate_sleep(data); +
          ret = mma8452_change_config(data, MMA8452_CTRL_REG1, data->ctrl_reg1);
          break;

drivers/iio/accel/mma8452.c +0 -0
@@ -1528,6 +1546,7 @@ static int mma8452_probe(struct i2c_client *client,
Quoted 4 lines

      case FXLS8471_DEVICE_ID:
          if (ret == data->chip_info->chip_id)
              break;
+        /* FALLTHRU */

Please do this in a seperate patch.

Quoted 5 lines

      default:
          return -ENODEV;
      }

drivers/iio/accel/mma8452.c +0 -0
@@ -1593,6 +1612,9 @@ static int mma8452_probe(struct i2c_client *client,

Quoted 8 lines

      data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT); +
+    data->sleep_val = mma8452_calculate_sleep(data);
+
      ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, data->ctrl_reg1);
      if (ret < 0)

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 2 lines · Richard Tresidder

Hi Martin
Thanks, I'll remove that /*FALLTHRU*/ compiler "disable warning" comment > I assume it is the correct comment to use to shut the compiler up?

Please use /* fallthrough */ instead.

Quoted 2 lines

I've also fixed up a couple of whitespace issues that checkpatch pulled me up on. Hard to know when to merge something or not.. seen that one merged in a few times in logs..

just like the fallthrough marker, make it a follow-up patch to your change (the sleep fix).

Quoted 87 lines

Regards
Richard

Quoted 81 lines · Martin Kepplinger
Quoted 57 lines · Richard Tresidder

Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Fix Fallthru warning in case statement

--

drivers/iio/accel/mma8452.c +19 -1
index 7a2da7f..948740d 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
       u8 ctrl_reg1;
       u8 data_cfg;
       const struct mma_chip_info *chip_info;
+    int sleep_val;
   };
 
    /**
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
           if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
               return 0;
 
-        msleep(20);
+        if (data->sleep_val <= 20)
+            usleep_range(data->sleep_val * 250, data->sleep_val * 500);
+        else
+            msleep(20);
       }
 
       dev_err(&data->client->dev, "data not ready\n");
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
       return -EINVAL;
   }
 
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+    int ret, i = mma8452_get_odr_index(data);
+
+    if (mma8452_samp_freq[i][0] > 0)
+        ret = 1000 / mma8452_samp_freq[i][0];
+    else
+        ret = 1000;
+
+    return ret == 0 ? 1 : ret;
+}
+
   static int mma8452_standby(struct mma8452_data *data)
   {
       return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
           data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
           data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
 
+        data->sleep_val = mma8452_calculate_sleep(data);
+
           ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
                           data->ctrl_reg1);
           break;

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1549

Quoted 4 lines
drivers/iio/accel/mma8452.c +1 -0
@@ -1528,6 +1546,7 @@ static int mma8452_probe(struct i2c_client *client,
       case FXLS8471_DEVICE_ID:
           if (ret == data->chip_info->chip_id)
               break;
+        /* FALLTHRU */

Please do this in a seperate patch.

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1620

Quoted 13 lines
drivers/iio/accel/mma8452.c +3 -0
       default:
           return -ENODEV;
       }
@@ -1593,6 +1612,9 @@ static int mma8452_probe(struct i2c_client *client,
 
       data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
                 (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
+
+    data->sleep_val = mma8452_calculate_sleep(data);
+
       ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
                       data->ctrl_reg1);
       if (ret < 0)

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH v3 1/1 iio: accell: mma8452: Reduce sleep time when data not ready

Modified the sleep method when data is not ready to allow for sampling > 50sps to work.

---
v3: Changes from v2
* Removed fallthrough fix (will submit separately)
* Fixed some blank lines, trailing white spaces.

v2: Changes from v1
* Remove whitespace changes
* Added fallthrough fix (subsequently removed)

drivers/iio/accel/mma8452.c | 23 ++++++++++++++++++++++-

1 file changed, 22 insertions(+), 1 deletion(-)
drivers/iio/accel/mma8452.c +22 -1
index 7a2da7f..5650b59 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
 	u8 ctrl_reg1;
 	u8 data_cfg;
 	const struct mma_chip_info *chip_info;
+	int sleep_val;
 };
 
  /**
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
 		if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
 			return 0;
 
-		msleep(20);
+		if (data->sleep_val <= 20)
+			usleep_range(data->sleep_val * 250, data->sleep_val * 500);
+		else
+			msleep(20);
 	}
 
 	dev_err(&data->client->dev, "data not ready\n");
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+	int ret, i = mma8452_get_odr_index(data);
+
+	if (mma8452_samp_freq[i][0] > 0)
+		ret = 1000 / mma8452_samp_freq[i][0];
+	else
+		ret = 1000;
+
+	return ret == 0 ? 1 : ret;
+}
+
 static int mma8452_standby(struct mma8452_data *data)
 {
 	return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
 		data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
 		data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
 
+		data->sleep_val = mma8452_calculate_sleep(data);
+
 		ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
 					    data->ctrl_reg1);
 		break;
@@ -1593,6 +1611,9 @@ static int mma8452_probe(struct i2c_client *client,
 
 	data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
 			  (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
+
+	data->sleep_val = mma8452_calculate_sleep(data);
+
 	ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
 					data->ctrl_reg1);
 	if (ret < 0)
#6 lore raw
Quoted 28 lines · Richard Tresidder

Modified the sleep method when data is not ready to allow for sampling > 50sps to work.

---
v3: Changes from v2
* Removed fallthrough fix (will submit separately)
* Fixed some blank lines, trailing white spaces.

v2: Changes from v1
* Remove whitespace changes
* Added fallthrough fix (subsequently removed)

drivers/iio/accel/mma8452.c | 23 ++++++++++++++++++++++-

1 file changed, 22 insertions(+), 1 deletion(-)
drivers/iio/accel/mma8452.c +1 -0
index 7a2da7f..5650b59 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
 	u8 ctrl_reg1;
 	u8 data_cfg;
 	const struct mma_chip_info *chip_info;
+	int sleep_val;
 };
 
  /**

drivers/iio/accel/mma8452.c static int mma8452_drdy(struct mma8452_data *data) · line 198

Quoted 6 lines
drivers/iio/accel/mma8452.c +2 -1
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
 		if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
 			return 0;
 
-		msleep(20);
+		if (data->sleep_val <= 20)
+			usleep_range(data->sleep_val * 250, data->sleep_val * 500);

line over 80 chars. please use 2 lines.

Also, have you run checkpatch on this? You seem to have DOS line-endlings.

Quoted 44 lines
drivers/iio/accel/mma8452.c +19 -0
+		else
+			msleep(20);
 	}
 
 	dev_err(&data->client->dev, "data not ready\n");
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+	int ret, i = mma8452_get_odr_index(data);
+
+	if (mma8452_samp_freq[i][0] > 0)
+		ret = 1000 / mma8452_samp_freq[i][0];
+	else
+		ret = 1000;
+
+	return ret == 0 ? 1 : ret;
+}
+
 static int mma8452_standby(struct mma8452_data *data)
 {
 	return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
 		data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
 		data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
 
+		data->sleep_val = mma8452_calculate_sleep(data);
+
 		ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
 					    data->ctrl_reg1);
 		break;
@@ -1593,6 +1611,9 @@ static int mma8452_probe(struct i2c_client *client,
 
 	data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
 			  (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
+
+	data->sleep_val = mma8452_calculate_sleep(data);
+
 	ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
 					data->ctrl_reg1);
 	if (ret < 0)
#7 lore raw

I'll take a look at the CRLF issue, seems the mail client is doing it.... strike 3 for thunderbird..
Yes did run checkpatch
Yes did note that line was 3 chars longer than 80 "0);" Aware that the coding standards allow this where it doesn't hide anything substantial and I think it's more readable..
I'm ok to change it, just think it looks messy when split given it's in an un-bracketed if else statement.
Theres over 100 of lines in the iio code alone that currently do the same thing on the last variable (including this file), so I thought it'd be ok.

Cheers
   Richard

Quoted 2 lines · Martin Kepplinger
Quoted 1 line · Richard Tresidder

Modified the sleep method when data is not ready to allow for

sampling > 50sps to work.

Quoted 36 lines
Quoted 27 lines

---
v3: Changes from v2
   * Removed fallthrough fix (will submit separately)
   * Fixed some blank lines, trailing white spaces.

v2: Changes from v1
   * Remove whitespace changes
   * Added fallthrough fix (subsequently removed)

drivers/iio/accel/mma8452.c | 23 ++++++++++++++++++++++-

1 file changed, 22 insertions(+), 1 deletion(-)
drivers/iio/accel/mma8452.c +1 -0
index 7a2da7f..5650b59 100644
@@ -106,6 +106,7 @@ struct mma8452_data {
       u8 ctrl_reg1;
       u8 data_cfg;
       const struct mma_chip_info *chip_info;
+    int sleep_val;
   };
 
    /**

drivers/iio/accel/mma8452.c static int mma8452_drdy(struct mma8452_data *data) · line 198

Quoted 6 lines
drivers/iio/accel/mma8452.c +2 -1
@@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data)
           if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
               return 0;
 
-        msleep(20);
+        if (data->sleep_val <= 20)
+            usleep_range(data->sleep_val * 250, data->sleep_val * 500);

line over 80 chars. please use 2 lines.

Quoted 8 lines

Also, have you run checkpatch on this? You seem to have DOS line-endlings.

drivers/iio/accel/mma8452.c static int mma8452_read_raw(struct iio_dev

Quoted 6 lines
drivers/iio/accel/mma8452.c +2 -0
+        else
+            msleep(20);
       }
 
       dev_err(&data->client->dev, "data not ready\n");
@@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev

*indio_dev,

Quoted 19 lines

drivers/iio/accel/mma8452.c static int mma8452_write_raw(struct iio_dev

Quoted 19 lines
drivers/iio/accel/mma8452.c +12 -0
       return -EINVAL;
   }
 
+static int mma8452_calculate_sleep(struct mma8452_data *data)
+{
+    int ret, i = mma8452_get_odr_index(data);
+
+    if (mma8452_samp_freq[i][0] > 0)
+        ret = 1000 / mma8452_samp_freq[i][0];
+    else
+        ret = 1000;
+
+    return ret == 0 ? 1 : ret;
+}
+
   static int mma8452_standby(struct mma8452_data *data)
   {
       return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev

*indio_dev,

Quoted 22 lines
Quoted 19 lines
drivers/iio/accel/mma8452.c +2 -0
           data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
           data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
 
+        data->sleep_val = mma8452_calculate_sleep(data);
+
           ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
                           data->ctrl_reg1);
           break;
@@ -1593,6 +1611,9 @@ static int mma8452_probe(struct i2c_client *client,
 

      data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);

drivers/iio/accel/mma8452.c +3 -0
+
+    data->sleep_val = mma8452_calculate_sleep(data);
+

      ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, data->ctrl_reg1);
      if (ret < 0)