All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const
@ 2021-06-10 13:46 Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 1/4] iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too Marc Kleine-Budde
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-06-10 13:46 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron, Lars-Peter Clausen, kernel

Hello,

here are 3 bug-fixes (probably stable material) and 1 enhancement for
the ltr501 driver.

regards,
Marc

changes since v1:
- all: add Andy Shevchenko's Reviewed-by
- 3/4: move endianness conversion to the callee




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/4] iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too
  2021-06-10 13:46 [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const Marc Kleine-Budde
@ 2021-06-10 13:46 ` Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 2/4] iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR Marc Kleine-Budde
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-06-10 13:46 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, Lars-Peter Clausen, kernel, Marc Kleine-Budde,
	Oliver Lang, Andy Shevchenko

The regmap is configured for 8 bit registers, uses a RB-Tree cache and
marks several registers as volatile (i.e. do not cache).

The ALS and PS data registers in the chip are 16 bit wide and spans
two regmap registers. In the current driver only the base register is
marked as volatile, resulting in the upper register only read once.

Further the data sheet notes:

| When the I2C read operation starts, all four ALS data registers are
| locked until the I2C read operation of register 0x8B is completed.

Which results in the registers never update after the 2nd read.

This patch fixes the problem by marking the upper 8 bits of the ALS
and PS registers as volatile, too.

Fixes: 2f2c96338afc ("iio: ltr501: Add regmap support.")
Reported-by: Oliver Lang <Oliver.Lang@gossenmetrawatt.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/iio/light/ltr501.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index b4323d2db0b1..0ed3392a33cf 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -32,9 +32,12 @@
 #define LTR501_PART_ID 0x86
 #define LTR501_MANUFAC_ID 0x87
 #define LTR501_ALS_DATA1 0x88 /* 16-bit, little endian */
+#define LTR501_ALS_DATA1_UPPER 0x89 /* upper 8 bits of LTR501_ALS_DATA1 */
 #define LTR501_ALS_DATA0 0x8a /* 16-bit, little endian */
+#define LTR501_ALS_DATA0_UPPER 0x8b /* upper 8 bits of LTR501_ALS_DATA0 */
 #define LTR501_ALS_PS_STATUS 0x8c
 #define LTR501_PS_DATA 0x8d /* 16-bit, little endian */
+#define LTR501_PS_DATA_UPPER 0x8e /* upper 8 bits of LTR501_PS_DATA */
 #define LTR501_INTR 0x8f /* output mode, polarity, mode */
 #define LTR501_PS_THRESH_UP 0x90 /* 11 bit, ps upper threshold */
 #define LTR501_PS_THRESH_LOW 0x92 /* 11 bit, ps lower threshold */
@@ -1354,9 +1357,12 @@ static bool ltr501_is_volatile_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
 	case LTR501_ALS_DATA1:
+	case LTR501_ALS_DATA1_UPPER:
 	case LTR501_ALS_DATA0:
+	case LTR501_ALS_DATA0_UPPER:
 	case LTR501_ALS_PS_STATUS:
 	case LTR501_PS_DATA:
+	case LTR501_PS_DATA_UPPER:
 		return true;
 	default:
 		return false;
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/4] iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR
  2021-06-10 13:46 [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 1/4] iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too Marc Kleine-Budde
@ 2021-06-10 13:46 ` Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 3/4] iio: ltr501: ltr501_read_ps(): add missing endianness conversion Marc Kleine-Budde
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-06-10 13:46 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, Lars-Peter Clausen, kernel, Oliver Lang,
	Andy Shevchenko, Marc Kleine-Budde

From: Oliver Lang <Oliver.Lang@gossenmetrawatt.com>

The ltr559 chip uses only the lowest bit of the ALS_CONTR register to
configure between active and stand-by mode. In the original driver
BIT(1) is used, which does a software reset instead.

This patch fixes the problem by using BIT(0) as als_mode_active for
the ltr559 chip.

Fixes: 8592a7eefa54 ("iio: ltr501: Add support for ltr559 chip")
Signed-off-by: Oliver Lang <Oliver.Lang@gossenmetrawatt.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/iio/light/ltr501.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 0ed3392a33cf..79898b72fe73 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -1208,7 +1208,7 @@ static struct ltr501_chip_info ltr501_chip_info_tbl[] = {
 		.als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
 		.ps_gain = ltr559_ps_gain_tbl,
 		.ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
-		.als_mode_active = BIT(1),
+		.als_mode_active = BIT(0),
 		.als_gain_mask = BIT(2) | BIT(3) | BIT(4),
 		.als_gain_shift = 2,
 		.info = &ltr501_info,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/4] iio: ltr501: ltr501_read_ps(): add missing endianness conversion
  2021-06-10 13:46 [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 1/4] iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 2/4] iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR Marc Kleine-Budde
@ 2021-06-10 13:46 ` Marc Kleine-Budde
  2021-06-10 13:46 ` [PATCH v2 4/4] iio: ltr501: mark ltr501_chip_info as const Marc Kleine-Budde
  2021-06-10 19:20 ` [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs " Nikita Travkin
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-06-10 13:46 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, Lars-Peter Clausen, kernel, Oliver Lang,
	Andy Shevchenko, Marc Kleine-Budde

From: Oliver Lang <Oliver.Lang@gossenmetrawatt.com>

The PS ADC Channel data is spread over 2 registers in little-endian
form. This patch adds the missing endianness conversion.

Fixes: 2690be905123 ("iio: Add Lite-On ltr501 ambient light / proximity sensor driver")
Signed-off-by: Oliver Lang <Oliver.Lang@gossenmetrawatt.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Changes since v1:
- move endianness conversion ltr501_read_ps()

 drivers/iio/light/ltr501.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 79898b72fe73..74ed2d88a3ed 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -409,18 +409,19 @@ static int ltr501_read_als(const struct ltr501_data *data, __le16 buf[2])
 
 static int ltr501_read_ps(const struct ltr501_data *data)
 {
-	int ret, status;
+	__le16 status;
+	int ret;
 
 	ret = ltr501_drdy(data, LTR501_STATUS_PS_RDY);
 	if (ret < 0)
 		return ret;
 
 	ret = regmap_bulk_read(data->regmap, LTR501_PS_DATA,
-			       &status, 2);
+			       &status, sizeof(status));
 	if (ret < 0)
 		return ret;
 
-	return status;
+	return le16_to_cpu(status);
 }
 
 static int ltr501_read_intr_prst(const struct ltr501_data *data,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/4] iio: ltr501: mark ltr501_chip_info as const
  2021-06-10 13:46 [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2021-06-10 13:46 ` [PATCH v2 3/4] iio: ltr501: ltr501_read_ps(): add missing endianness conversion Marc Kleine-Budde
@ 2021-06-10 13:46 ` Marc Kleine-Budde
  2021-06-10 19:20 ` [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs " Nikita Travkin
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-06-10 13:46 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, Lars-Peter Clausen, kernel, Marc Kleine-Budde,
	Andy Shevchenko

This patch marks the struct ltr501_chip_info as constant.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/iio/light/ltr501.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 74ed2d88a3ed..1830221da48d 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -152,7 +152,7 @@ struct ltr501_chip_info {
 struct ltr501_data {
 	struct i2c_client *client;
 	struct mutex lock_als, lock_ps;
-	struct ltr501_chip_info *chip_info;
+	const struct ltr501_chip_info *chip_info;
 	u8 als_contr, ps_contr;
 	int als_period, ps_period; /* period in micro seconds */
 	struct regmap *regmap;
@@ -739,7 +739,7 @@ static int ltr501_write_raw(struct iio_dev *indio_dev,
 {
 	struct ltr501_data *data = iio_priv(indio_dev);
 	int i, ret, freq_val, freq_val2;
-	struct ltr501_chip_info *info = data->chip_info;
+	const struct ltr501_chip_info *info = data->chip_info;
 
 	ret = iio_device_claim_direct_mode(indio_dev);
 	if (ret)
@@ -1086,7 +1086,7 @@ static ssize_t ltr501_show_proximity_scale_avail(struct device *dev,
 						 char *buf)
 {
 	struct ltr501_data *data = iio_priv(dev_to_iio_dev(dev));
-	struct ltr501_chip_info *info = data->chip_info;
+	const struct ltr501_chip_info *info = data->chip_info;
 	ssize_t len = 0;
 	int i;
 
@@ -1108,7 +1108,7 @@ static ssize_t ltr501_show_intensity_scale_avail(struct device *dev,
 						 char *buf)
 {
 	struct ltr501_data *data = iio_priv(dev_to_iio_dev(dev));
-	struct ltr501_chip_info *info = data->chip_info;
+	const struct ltr501_chip_info *info = data->chip_info;
 	ssize_t len = 0;
 	int i;
 
@@ -1188,7 +1188,7 @@ static const struct iio_info ltr301_info = {
 	.write_event_config	= &ltr501_write_event_config,
 };
 
-static struct ltr501_chip_info ltr501_chip_info_tbl[] = {
+static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
 	[ltr501] = {
 		.partid = 0x08,
 		.als_gain = ltr501_als_gain_tbl,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const
  2021-06-10 13:46 [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2021-06-10 13:46 ` [PATCH v2 4/4] iio: ltr501: mark ltr501_chip_info as const Marc Kleine-Budde
@ 2021-06-10 19:20 ` Nikita Travkin
  2021-06-11 17:44   ` Jonathan Cameron
  4 siblings, 1 reply; 7+ messages in thread
From: Nikita Travkin @ 2021-06-10 19:20 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, kernel

Marc Kleine-Budde писал 10.06.2021 18:46:
> Hello,
> 
> here are 3 bug-fixes (probably stable material) and 1 enhancement for
> the ltr501 driver.
> 
> regards,
> Marc
> 
> changes since v1:
> - all: add Andy Shevchenko's Reviewed-by
> - 3/4: move endianness conversion to the callee

Hi,
Tested this series on Wileyfox Swift (Longcheer L8150) with ltr559,
it works nicely now, thank you!

Tested-by: Nikita Travkin <nikita@trvn.ru> # ltr559

-- 
regards,
Nikita

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const
  2021-06-10 19:20 ` [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs " Nikita Travkin
@ 2021-06-11 17:44   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2021-06-11 17:44 UTC (permalink / raw)
  To: Nikita Travkin; +Cc: Marc Kleine-Budde, linux-iio, Lars-Peter Clausen, kernel

On Fri, 11 Jun 2021 00:20:35 +0500
Nikita Travkin <nikita@trvn.ru> wrote:

> Marc Kleine-Budde писал 10.06.2021 18:46:
> > Hello,
> > 
> > here are 3 bug-fixes (probably stable material) and 1 enhancement for
> > the ltr501 driver.
> > 
> > regards,
> > Marc
> > 
> > changes since v1:
> > - all: add Andy Shevchenko's Reviewed-by
> > - 3/4: move endianness conversion to the callee  
> 
> Hi,
> Tested this series on Wileyfox Swift (Longcheer L8150) with ltr559,
> it works nicely now, thank you!
> 
> Tested-by: Nikita Travkin <nikita@trvn.ru> # ltr559
> 

Nice.  All applied to the togreg branch of iio.git as we are rather late in the
cycle to go round trying to merge this fixes first then the final patch
+ it's been broken a while so what's a few more weeks?

Fixes all marked for stable.

I'll push the togreg branch out as testing first to let 0-day see if we
missed anything.

Thanks,

Jonathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-11 17:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 13:46 [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs as const Marc Kleine-Budde
2021-06-10 13:46 ` [PATCH v2 1/4] iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too Marc Kleine-Budde
2021-06-10 13:46 ` [PATCH v2 2/4] iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR Marc Kleine-Budde
2021-06-10 13:46 ` [PATCH v2 3/4] iio: ltr501: ltr501_read_ps(): add missing endianness conversion Marc Kleine-Budde
2021-06-10 13:46 ` [PATCH v2 4/4] iio: ltr501: mark ltr501_chip_info as const Marc Kleine-Budde
2021-06-10 19:20 ` [PATCH v2 0/4] fix regmap, initialization of ltr559, endianness and mark structs " Nikita Travkin
2021-06-11 17:44   ` Jonathan Cameron

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.