Linux-LEDs Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] leds: pca963x: Fix open-drain initialization
@ 2019-11-18 21:02 Zahari Petkov
  2019-12-21 19:02 ` Pavel Machek
  0 siblings, 1 reply; 2+ messages in thread
From: Zahari Petkov @ 2019-11-18 21:02 UTC (permalink / raw)
  To: Pavel Machek, Jacek Anaszewski, Dan Murphy
  Cc: linux-leds, linux-kernel, Zahari Petkov

Before commit bb29b9cccd95 ("leds: pca963x: Add bindings to invert
polarity") Mode register 2 was initialized directly with either 0x01
or 0x05 for open-drain or totem pole (push-pull) configuration.

Afterwards, MODE2 initialization started using bitwise operations on
top of the default MODE2 register value (0x05). Using bitwise OR for
setting OUTDRV with 0x01 and 0x05 does not produce correct results.
When open-drain is used, instead of setting OUTDRV to 0, the driver
keeps it as 1:

Open-drain: 0x05 | 0x01 -> 0x05 (0b101 - incorrect)
Totem pole: 0x05 | 0x05 -> 0x05 (0b101 - correct but still wrong)

Now OUTDRV setting uses correct bitwise operations for initialization:

Open-drain: 0x05 & ~0x04 -> 0x01 (0b001 - correct)
Totem pole: 0x05 | 0x04 -> 0x05 (0b101 - correct)

Additional MODE2 register definitions are introduced now as well.

Fixes: bb29b9cccd95 ("leds: pca963x: Add bindings to invert polarity")
Signed-off-by: Zahari Petkov <zahari@balena.io>
---
 drivers/leds/leds-pca963x.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 4afc317901a8..66cdc003b8f4 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -40,6 +40,8 @@
 #define PCA963X_LED_PWM		0x2	/* Controlled through PWM */
 #define PCA963X_LED_GRP_PWM	0x3	/* Controlled through PWM/GRPPWM */
 
+#define PCA963X_MODE2_OUTDRV	0x04	/* Open-drain or totem pole */
+#define PCA963X_MODE2_INVRT	0x10	/* Normal or inverted direction */
 #define PCA963X_MODE2_DMBLNK	0x20	/* Enable blinking */
 
 #define PCA963X_MODE1		0x00
@@ -438,12 +440,12 @@ static int pca963x_probe(struct i2c_client *client,
 						    PCA963X_MODE2);
 		/* Configure output: open-drain or totem pole (push-pull) */
 		if (pdata->outdrv == PCA963X_OPEN_DRAIN)
-			mode2 |= 0x01;
+			mode2 &= ~PCA963X_MODE2_OUTDRV;
 		else
-			mode2 |= 0x05;
+			mode2 |= PCA963X_MODE2_OUTDRV;
 		/* Configure direction: normal or inverted */
 		if (pdata->dir == PCA963X_INVERTED)
-			mode2 |= 0x10;
+			mode2 |= PCA963X_MODE2_INVRT;
 		i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2,
 					  mode2);
 	}
-- 
2.24.0


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

* Re: [PATCH v2] leds: pca963x: Fix open-drain initialization
  2019-11-18 21:02 [PATCH v2] leds: pca963x: Fix open-drain initialization Zahari Petkov
@ 2019-12-21 19:02 ` Pavel Machek
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2019-12-21 19:02 UTC (permalink / raw)
  To: Zahari Petkov; +Cc: Jacek Anaszewski, Dan Murphy, linux-leds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1141 bytes --]

On Mon 2019-11-18 23:02:55, Zahari Petkov wrote:
> Before commit bb29b9cccd95 ("leds: pca963x: Add bindings to invert
> polarity") Mode register 2 was initialized directly with either 0x01
> or 0x05 for open-drain or totem pole (push-pull) configuration.
> 
> Afterwards, MODE2 initialization started using bitwise operations on
> top of the default MODE2 register value (0x05). Using bitwise OR for
> setting OUTDRV with 0x01 and 0x05 does not produce correct results.
> When open-drain is used, instead of setting OUTDRV to 0, the driver
> keeps it as 1:
> 
> Open-drain: 0x05 | 0x01 -> 0x05 (0b101 - incorrect)
> Totem pole: 0x05 | 0x05 -> 0x05 (0b101 - correct but still wrong)
> 
> Now OUTDRV setting uses correct bitwise operations for initialization:
> 
> Open-drain: 0x05 & ~0x04 -> 0x01 (0b001 - correct)
> Totem pole: 0x05 | 0x04 -> 0x05 (0b101 - correct)
> 
> Additional MODE2 register definitions are introduced now as well.

Thanks, applied.
								Pavel
								
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-18 21:02 [PATCH v2] leds: pca963x: Fix open-drain initialization Zahari Petkov
2019-12-21 19:02 ` Pavel Machek

Linux-LEDs Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-leds/0 linux-leds/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-leds linux-leds/ https://lore.kernel.org/linux-leds \
		linux-leds@vger.kernel.org
	public-inbox-index linux-leds

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-leds


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git