* [PATCH v2 1/7] iio: chemical: bme680: use clamp macro
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-15 20:38 ` [PATCH v2 2/7] iio: chemical: bme680: cleanup bme680_read_calib formatting David Frey
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680_core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index 7d9bb62baa3f..b4c012bc0a82 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -408,10 +408,7 @@ static u32 bme680_compensate_humid(struct bme680_data *data,
var6 = (var4 * var5) >> 1;
calc_hum = (((var3 + var6) >> 10) * 1000) >> 12;
- if (calc_hum > 100000) /* Cap at 100%rH */
- calc_hum = 100000;
- else if (calc_hum < 0)
- calc_hum = 0;
+ calc_hum = clamp(calc_hum, 0, 100000); /* clamp between 0-100 %rH */
return calc_hum;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 2/7] iio: chemical: bme680: cleanup bme680_read_calib formatting
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
2018-08-15 20:38 ` [PATCH v2 1/7] iio: chemical: bme680: use clamp macro David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-15 20:38 ` [PATCH v2 3/7] iio: chemical: bme680: indent #defines consistently David Frey
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680_core.c | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index b4c012bc0a82..49bb6b84f181 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -102,16 +102,14 @@ static int bme680_read_calib(struct bme680_data *data,
__le16 buf;
/* Temperature related coefficients */
- ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_T1_LSB_REG\n");
return ret;
}
calib->par_t1 = le16_to_cpu(buf);
- ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_T2_LSB_REG\n");
return ret;
@@ -126,16 +124,14 @@ static int bme680_read_calib(struct bme680_data *data,
calib->par_t3 = tmp;
/* Pressure related coefficients */
- ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_P1_LSB_REG\n");
return ret;
}
calib->par_p1 = le16_to_cpu(buf);
- ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_P2_LSB_REG\n");
return ret;
@@ -149,16 +145,14 @@ static int bme680_read_calib(struct bme680_data *data,
}
calib->par_p3 = tmp;
- ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_P4_LSB_REG\n");
return ret;
}
calib->par_p4 = le16_to_cpu(buf);
- ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_P5_LSB_REG\n");
return ret;
@@ -179,16 +173,14 @@ static int bme680_read_calib(struct bme680_data *data,
}
calib->par_p7 = tmp;
- ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_P8_LSB_REG\n");
return ret;
}
calib->par_p8 = le16_to_cpu(buf);
- ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG, (u8 *) &buf, 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_P9_LSB_REG\n");
return ret;
@@ -208,30 +200,26 @@ static int bme680_read_calib(struct bme680_data *data,
dev_err(dev, "failed to read BME680_H1_MSB_REG\n");
return ret;
}
-
ret = regmap_read(data->regmap, BME680_H1_LSB_REG, &tmp_lsb);
if (ret < 0) {
dev_err(dev, "failed to read BME680_H1_LSB_REG\n");
return ret;
}
-
calib->par_h1 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) |
- (tmp_lsb & BME680_BIT_H1_DATA_MSK);
+ (tmp_lsb & BME680_BIT_H1_DATA_MSK);
ret = regmap_read(data->regmap, BME680_H2_MSB_REG, &tmp_msb);
if (ret < 0) {
dev_err(dev, "failed to read BME680_H2_MSB_REG\n");
return ret;
}
-
ret = regmap_read(data->regmap, BME680_H2_LSB_REG, &tmp_lsb);
if (ret < 0) {
dev_err(dev, "failed to read BME680_H2_LSB_REG\n");
return ret;
}
-
calib->par_h2 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) |
- (tmp_lsb >> BME680_HUM_REG_SHIFT_VAL);
+ (tmp_lsb >> BME680_HUM_REG_SHIFT_VAL);
ret = regmap_read(data->regmap, BME680_H3_REG, &tmp);
if (ret < 0) {
@@ -276,8 +264,8 @@ static int bme680_read_calib(struct bme680_data *data,
}
calib->par_gh1 = tmp;
- ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG,
- (u8 *) &buf, 2);
+ ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG, (u8 *) &buf,
+ 2);
if (ret < 0) {
dev_err(dev, "failed to read BME680_GH2_LSB_REG\n");
return ret;
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 3/7] iio: chemical: bme680: indent #defines consistently
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
2018-08-15 20:38 ` [PATCH v2 1/7] iio: chemical: bme680: use clamp macro David Frey
2018-08-15 20:38 ` [PATCH v2 2/7] iio: chemical: bme680: cleanup bme680_read_calib formatting David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-15 20:38 ` [PATCH v2 4/7] iio: chemical: bme680: change MSK->MASK in #defines David Frey
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680.h | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h
index e049323f209a..dd4247d364a0 100644
--- a/drivers/iio/chemical/bme680.h
+++ b/drivers/iio/chemical/bme680.h
@@ -4,10 +4,10 @@
#define BME680_REG_CHIP_I2C_ID 0xD0
#define BME680_REG_CHIP_SPI_ID 0x50
-#define BME680_CHIP_ID_VAL 0x61
+#define BME680_CHIP_ID_VAL 0x61
#define BME680_REG_SOFT_RESET_I2C 0xE0
#define BME680_REG_SOFT_RESET_SPI 0x60
-#define BME680_CMD_SOFTRESET 0xB6
+#define BME680_CMD_SOFTRESET 0xB6
#define BME680_REG_STATUS 0x73
#define BME680_SPI_MEM_PAGE_BIT BIT(4)
#define BME680_SPI_MEM_PAGE_1_VAL 1
@@ -18,6 +18,7 @@
#define BME680_REG_GAS_MSB 0x2A
#define BME680_REG_GAS_R_LSB 0x2B
#define BME680_GAS_STAB_BIT BIT(4)
+#define BME680_GAS_RANGE_MASK 0x0F
#define BME680_REG_CTRL_HUMIDITY 0x72
#define BME680_OSRS_HUMIDITY_MASK GENMASK(2, 0)
@@ -26,9 +27,8 @@
#define BME680_OSRS_TEMP_MASK GENMASK(7, 5)
#define BME680_OSRS_PRESS_MASK GENMASK(4, 2)
#define BME680_MODE_MASK GENMASK(1, 0)
-
-#define BME680_MODE_FORCED 1
-#define BME680_MODE_SLEEP 0
+#define BME680_MODE_FORCED 1
+#define BME680_MODE_SLEEP 0
#define BME680_REG_CONFIG 0x75
#define BME680_FILTER_MASK GENMASK(4, 2)
@@ -42,13 +42,12 @@
#define BME680_BIT_H1_DATA_MSK 0x0F
#define BME680_REG_RES_HEAT_RANGE 0x02
-#define BME680_RHRANGE_MSK 0x30
+#define BME680_RHRANGE_MSK 0x30
#define BME680_REG_RES_HEAT_VAL 0x00
#define BME680_REG_RANGE_SW_ERR 0x04
-#define BME680_RSERROR_MSK 0xF0
+#define BME680_RSERROR_MSK 0xF0
#define BME680_REG_RES_HEAT_0 0x5A
#define BME680_REG_GAS_WAIT_0 0x64
-#define BME680_GAS_RANGE_MASK 0x0F
#define BME680_ADC_GAS_RES_SHIFT 6
#define BME680_AMB_TEMP 25
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 4/7] iio: chemical: bme680: change MSK->MASK in #defines
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
` (2 preceding siblings ...)
2018-08-15 20:38 ` [PATCH v2 3/7] iio: chemical: bme680: indent #defines consistently David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-15 21:03 ` David Frey
2018-08-15 20:38 ` [PATCH v2 5/7] iio: chemical: bme680: use GENMASK macro David Frey
` (3 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Convert all defines to use "MASK" instead of a mix of "MSK" and "MASK"
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680.h | 6 +++---
drivers/iio/chemical/bme680_core.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h
index dd4247d364a0..437d75c2bad5 100644
--- a/drivers/iio/chemical/bme680.h
+++ b/drivers/iio/chemical/bme680.h
@@ -39,13 +39,13 @@
#define BME680_MAX_OVERFLOW_VAL 0x40000000
#define BME680_HUM_REG_SHIFT_VAL 4
-#define BME680_BIT_H1_DATA_MSK 0x0F
+#define BME680_BIT_H1_DATA_MASK 0x0F
#define BME680_REG_RES_HEAT_RANGE 0x02
-#define BME680_RHRANGE_MSK 0x30
+#define BME680_RHRANGE_MASK 0x30
#define BME680_REG_RES_HEAT_VAL 0x00
#define BME680_REG_RANGE_SW_ERR 0x04
-#define BME680_RSERROR_MSK 0xF0
+#define BME680_RSERROR_MASK 0xF0
#define BME680_REG_RES_HEAT_0 0x5A
#define BME680_REG_GAS_WAIT_0 0x64
#define BME680_ADC_GAS_RES_SHIFT 6
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index 49bb6b84f181..d62cb88af481 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -285,7 +285,7 @@ static int bme680_read_calib(struct bme680_data *data,
dev_err(dev, "failed to read resistance heat range\n");
return ret;
}
- calib->res_heat_range = (tmp & BME680_RHRANGE_MSK) / 16;
+ calib->res_heat_range = (tmp & BME680_RHRANGE_MASK) / 16;
ret = regmap_read(data->regmap, BME680_REG_RES_HEAT_VAL, &tmp);
if (ret < 0) {
@@ -299,7 +299,7 @@ static int bme680_read_calib(struct bme680_data *data,
dev_err(dev, "failed to read range software error\n");
return ret;
}
- calib->range_sw_err = (tmp & BME680_RSERROR_MSK) / 16;
+ calib->range_sw_err = (tmp & BME680_RSERROR_MASK) / 16;
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v2 4/7] iio: chemical: bme680: change MSK->MASK in #defines
2018-08-15 20:38 ` [PATCH v2 4/7] iio: chemical: bme680: change MSK->MASK in #defines David Frey
@ 2018-08-15 21:03 ` David Frey
2018-08-16 6:17 ` Himanshu Jha
0 siblings, 1 reply; 12+ messages in thread
From: David Frey @ 2018-08-15 21:03 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640
On 8/15/2018 1:38 PM, David Frey wrote:
<snip>
> diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
> index 49bb6b84f181..d62cb88af481 100644
> --- a/drivers/iio/chemical/bme680_core.c
> +++ b/drivers/iio/chemical/bme680_core.c
When splitting the patches apart, I screwed this one up slightly. The
patch should also include this hunk:
> @@ -206,7 +206,7 @@ static int bme680_read_calib(struct bme680_data *data,
> return ret;
> }
> calib->par_h1 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) |
> - (tmp_lsb & BME680_BIT_H1_DATA_MSK);
> + (tmp_lsb & BME680_BIT_H1_DATA_MASK);
>
> ret = regmap_read(data->regmap, BME680_H2_MSB_REG, &tmp_msb);
> if (ret < 0) {
What is the correct course of action in the situation? Should I resend
just this one patch immediately? Would it get a new version number
"[PATCH v3 4/7]"? I think the version number refers to the whole patch
series, so it seems wrong to bump the revision of one patch and not
transmit the whole series.
Thanks,
David Frey
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 4/7] iio: chemical: bme680: change MSK->MASK in #defines
2018-08-15 21:03 ` David Frey
@ 2018-08-16 6:17 ` Himanshu Jha
0 siblings, 0 replies; 12+ messages in thread
From: Himanshu Jha @ 2018-08-16 6:17 UTC (permalink / raw)
To: David Frey; +Cc: linux-iio, jic23
On Wed, Aug 15, 2018 at 02:03:31PM -0700, David Frey wrote:
> On 8/15/2018 1:38 PM, David Frey wrote:
>
> <snip>
>
> > diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
> > index 49bb6b84f181..d62cb88af481 100644
> > --- a/drivers/iio/chemical/bme680_core.c
> > +++ b/drivers/iio/chemical/bme680_core.c
>
> When splitting the patches apart, I screwed this one up slightly. The patch
> should also include this hunk:
>
> > @@ -206,7 +206,7 @@ static int bme680_read_calib(struct bme680_data *data,
> > return ret;
> > }
> > calib->par_h1 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) |
> > - (tmp_lsb & BME680_BIT_H1_DATA_MSK);
> > + (tmp_lsb & BME680_BIT_H1_DATA_MASK);
> >
> > ret = regmap_read(data->regmap, BME680_H2_MSB_REG, &tmp_msb);
> > if (ret < 0) {
>
> What is the correct course of action in the situation? Should I resend just
> this one patch immediately? Would it get a new version number "[PATCH v3
> 4/7]"? I think the version number refers to the whole patch series, so it
> seems wrong to bump the revision of one patch and not transmit the whole
> series.
The rule is send the whole series again with the changelog mentioned
below the '---' and in your case mentioning
"no changes in this patch" in the changelog for all other patches in
series would be nice.
Another issue which I see is that you would need to rebase on top of my
patch that I sent a while ago because otherwise the patch won't apply
cleanly to the iio tree.
https://lore.kernel.org/lkml/20180811102636.6171-1-himanshujha199640@gmail.com/t/#u
As soon as you would next version, I would get it tested.
Thanks
--
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 5/7] iio: chemical: bme680: use GENMASK macro
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
` (3 preceding siblings ...)
2018-08-15 20:38 ` [PATCH v2 4/7] iio: chemical: bme680: change MSK->MASK in #defines David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-15 20:38 ` [PATCH v2 6/7] iio: chemical: bme680: use FIELD_GET macro David Frey
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Replace hardcoded bit masks with GENMASK macro
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h
index 437d75c2bad5..a9f2a9a6abc5 100644
--- a/drivers/iio/chemical/bme680.h
+++ b/drivers/iio/chemical/bme680.h
@@ -18,7 +18,7 @@
#define BME680_REG_GAS_MSB 0x2A
#define BME680_REG_GAS_R_LSB 0x2B
#define BME680_GAS_STAB_BIT BIT(4)
-#define BME680_GAS_RANGE_MASK 0x0F
+#define BME680_GAS_RANGE_MASK GENMASK(3, 0)
#define BME680_REG_CTRL_HUMIDITY 0x72
#define BME680_OSRS_HUMIDITY_MASK GENMASK(2, 0)
@@ -39,13 +39,13 @@
#define BME680_MAX_OVERFLOW_VAL 0x40000000
#define BME680_HUM_REG_SHIFT_VAL 4
-#define BME680_BIT_H1_DATA_MASK 0x0F
+#define BME680_BIT_H1_DATA_MASK GENMASK(3, 0)
#define BME680_REG_RES_HEAT_RANGE 0x02
-#define BME680_RHRANGE_MASK 0x30
+#define BME680_RHRANGE_MASK GENMASK(5, 4)
#define BME680_REG_RES_HEAT_VAL 0x00
#define BME680_REG_RANGE_SW_ERR 0x04
-#define BME680_RSERROR_MASK 0xF0
+#define BME680_RSERROR_MASK GENMASK(7, 4)
#define BME680_REG_RES_HEAT_0 0x5A
#define BME680_REG_GAS_WAIT_0 0x64
#define BME680_ADC_GAS_RES_SHIFT 6
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 6/7] iio: chemical: bme680: use FIELD_GET macro
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
` (4 preceding siblings ...)
2018-08-15 20:38 ` [PATCH v2 5/7] iio: chemical: bme680: use GENMASK macro David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-15 20:38 ` [PATCH v2 7/7] iio: chemical: bme680: simplify oversampling handling David Frey
2018-08-16 6:24 ` [PATCH v2 0/7] bme680 cleanup Himanshu Jha
7 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Use the FIELD_GET macro instead of explicit mask and shift.
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index d62cb88af481..c96e4a991a61 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -285,7 +285,7 @@ static int bme680_read_calib(struct bme680_data *data,
dev_err(dev, "failed to read resistance heat range\n");
return ret;
}
- calib->res_heat_range = (tmp & BME680_RHRANGE_MASK) / 16;
+ calib->res_heat_range = FIELD_GET(BME680_RHRANGE_MASK, tmp);
ret = regmap_read(data->regmap, BME680_REG_RES_HEAT_VAL, &tmp);
if (ret < 0) {
@@ -299,7 +299,7 @@ static int bme680_read_calib(struct bme680_data *data,
dev_err(dev, "failed to read range software error\n");
return ret;
}
- calib->range_sw_err = (tmp & BME680_RSERROR_MASK) / 16;
+ calib->range_sw_err = FIELD_GET(BME680_RSERROR_MASK, tmp);
return 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 7/7] iio: chemical: bme680: simplify oversampling handling
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
` (5 preceding siblings ...)
2018-08-15 20:38 ` [PATCH v2 6/7] iio: chemical: bme680: use FIELD_GET macro David Frey
@ 2018-08-15 20:38 ` David Frey
2018-08-16 6:24 ` [PATCH v2 0/7] bme680 cleanup Himanshu Jha
7 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-15 20:38 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, himanshujha199640, David Frey
Temperature, pressure and humidity all expose and oversampling setting
that works in the same way. Provide common handling for the
oversampling sysfs attributes.
Signed-off-by: David Frey <dpfrey@gmail.com>
---
drivers/iio/chemical/bme680_core.c | 99 ++++++++++++++------------------------
1 file changed, 36 insertions(+), 63 deletions(-)
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index c96e4a991a61..799389e8c0d9 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -91,8 +91,6 @@ static const struct iio_chan_spec bme680_channels[] = {
},
};
-static const int bme680_oversampling_avail[] = { 1, 2, 4, 8, 16 };
-
static int bme680_read_calib(struct bme680_data *data,
struct bme680_calib *calib)
{
@@ -503,12 +501,20 @@ static int bme680_set_mode(struct bme680_data *data, bool mode)
return ret;
}
+static u8 bme680_oversampling_to_reg(u8 val)
+{
+ return ilog2(val) + 1;
+}
+
static int bme680_chip_config(struct bme680_data *data)
{
struct device *dev = regmap_get_device(data->regmap);
int ret;
- u8 osrs = FIELD_PREP(BME680_OSRS_HUMIDITY_MASK,
- data->oversampling_humid + 1);
+ u8 osrs;
+
+ osrs = FIELD_PREP(
+ BME680_OSRS_HUMIDITY_MASK,
+ bme680_oversampling_to_reg(data->oversampling_humid));
/*
* Highly recommended to set oversampling of humidity before
* temperature/pressure oversampling.
@@ -529,12 +535,12 @@ static int bme680_chip_config(struct bme680_data *data)
return ret;
}
- osrs = FIELD_PREP(BME680_OSRS_TEMP_MASK, data->oversampling_temp + 1) |
- FIELD_PREP(BME680_OSRS_PRESS_MASK, data->oversampling_press + 1);
-
+ osrs = FIELD_PREP(BME680_OSRS_TEMP_MASK,
+ bme680_oversampling_to_reg(data->oversampling_temp)) |
+ FIELD_PREP(BME680_OSRS_PRESS_MASK,
+ bme680_oversampling_to_reg(data->oversampling_press));
ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
- BME680_OSRS_TEMP_MASK |
- BME680_OSRS_PRESS_MASK,
+ BME680_OSRS_TEMP_MASK | BME680_OSRS_PRESS_MASK,
osrs);
if (ret < 0)
dev_err(dev, "failed to write ctrl_meas register\n");
@@ -767,13 +773,13 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
switch (chan->type) {
case IIO_TEMP:
- *val = 1 << data->oversampling_temp;
+ *val = data->oversampling_temp;
return IIO_VAL_INT;
case IIO_PRESSURE:
- *val = 1 << data->oversampling_press;
+ *val = data->oversampling_press;
return IIO_VAL_INT;
case IIO_HUMIDITYRELATIVE:
- *val = 1 << data->oversampling_humid;
+ *val = data->oversampling_humid;
return IIO_VAL_INT;
default:
return -EINVAL;
@@ -783,52 +789,9 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
}
}
-static int bme680_write_oversampling_ratio_temp(struct bme680_data *data,
- int val)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(bme680_oversampling_avail); i++) {
- if (bme680_oversampling_avail[i] == val) {
- data->oversampling_temp = ilog2(val);
-
- return bme680_chip_config(data);
- }
- }
-
- return -EINVAL;
-}
-
-static int bme680_write_oversampling_ratio_press(struct bme680_data *data,
- int val)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(bme680_oversampling_avail); i++) {
- if (bme680_oversampling_avail[i] == val) {
- data->oversampling_press = ilog2(val);
-
- return bme680_chip_config(data);
- }
- }
-
- return -EINVAL;
-}
-
-static int bme680_write_oversampling_ratio_humid(struct bme680_data *data,
- int val)
+static bool bme680_is_valid_oversampling(int rate)
{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(bme680_oversampling_avail); i++) {
- if (bme680_oversampling_avail[i] == val) {
- data->oversampling_humid = ilog2(val);
-
- return bme680_chip_config(data);
- }
- }
-
- return -EINVAL;
+ return (rate > 0 && rate <= 16 && is_power_of_2(rate));
}
static int bme680_write_raw(struct iio_dev *indio_dev,
@@ -839,16 +802,26 @@ static int bme680_write_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ {
+ if (!bme680_is_valid_oversampling(val))
+ return -EINVAL;
+
switch (chan->type) {
case IIO_TEMP:
- return bme680_write_oversampling_ratio_temp(data, val);
+ data->oversampling_temp = val;
+ break;
case IIO_PRESSURE:
- return bme680_write_oversampling_ratio_press(data, val);
+ data->oversampling_press = val;
+ break;
case IIO_HUMIDITYRELATIVE:
- return bme680_write_oversampling_ratio_humid(data, val);
+ data->oversampling_humid = val;
+ break;
default:
return -EINVAL;
}
+
+ return bme680_chip_config(data);
+ }
default:
return -EINVAL;
}
@@ -910,9 +883,9 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
indio_dev->modes = INDIO_DIRECT_MODE;
/* default values for the sensor */
- data->oversampling_humid = ilog2(2); /* 2X oversampling rate */
- data->oversampling_press = ilog2(4); /* 4X oversampling rate */
- data->oversampling_temp = ilog2(8); /* 8X oversampling rate */
+ data->oversampling_humid = 2; /* 2X oversampling rate */
+ data->oversampling_press = 4; /* 4X oversampling rate */
+ data->oversampling_temp = 8; /* 8X oversampling rate */
data->heater_temp = 320; /* degree Celsius */
data->heater_dur = 150; /* milliseconds */
--
2.11.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v2 0/7] bme680 cleanup
2018-08-15 20:38 [PATCH v2 0/7] bme680 cleanup David Frey
` (6 preceding siblings ...)
2018-08-15 20:38 ` [PATCH v2 7/7] iio: chemical: bme680: simplify oversampling handling David Frey
@ 2018-08-16 6:24 ` Himanshu Jha
2018-08-16 12:55 ` David Frey
7 siblings, 1 reply; 12+ messages in thread
From: Himanshu Jha @ 2018-08-16 6:24 UTC (permalink / raw)
To: David Frey; +Cc: linux-iio, jic23
On Wed, Aug 15, 2018 at 01:38:28PM -0700, David Frey wrote:
> Note that I don't currently have bme680 hardware available, so I am hoping that
> Himanshu is willing to validate the changes.
Another thing that is screwed up is Jonathan's email ;)
It is jic23@kernel.org and not jic23@vger.kernel.org
You can use:
$ ./scripts/get_maintainer.pl <patch>
Thanks
--
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 0/7] bme680 cleanup
2018-08-16 6:24 ` [PATCH v2 0/7] bme680 cleanup Himanshu Jha
@ 2018-08-16 12:55 ` David Frey
0 siblings, 0 replies; 12+ messages in thread
From: David Frey @ 2018-08-16 12:55 UTC (permalink / raw)
To: Himanshu Jha; +Cc: linux-iio, jic23
On 8/15/2018 11:24 PM, Himanshu Jha wrote:
> On Wed, Aug 15, 2018 at 01:38:28PM -0700, David Frey wrote:
>> Note that I don't currently have bme680 hardware available, so I am hoping that
>> Himanshu is willing to validate the changes.
>
> Another thing that is screwed up is Jonathan's email ;)
>
> It is jic23@kernel.org and not jic23@vger.kernel.org
>
> You can use:
>
> $ ./scripts/get_maintainer.pl <patch>
Yes... I realized that shortly after I received 8 bounce e-mails in reply.
^ permalink raw reply [flat|nested] 12+ messages in thread