Skip to content

Commit fe49dd5

Browse files
majorzpopcornmix
authored andcommitted
leds: pca963x: Fix open-drain initialization
commit 6975290 upstream. Before commit bb29b9c ("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: bb29b9c ("leds: pca963x: Add bindings to invert polarity") Signed-off-by: Zahari Petkov <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent ac9ed1e commit fe49dd5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/leds/leds-pca963x.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define PCA963X_LED_PWM 0x2 /* Controlled through PWM */
4141
#define PCA963X_LED_GRP_PWM 0x3 /* Controlled through PWM/GRPPWM */
4242

43+
#define PCA963X_MODE2_OUTDRV 0x04 /* Open-drain or totem pole */
44+
#define PCA963X_MODE2_INVRT 0x10 /* Normal or inverted direction */
4345
#define PCA963X_MODE2_DMBLNK 0x20 /* Enable blinking */
4446

4547
#define PCA963X_MODE1 0x00
@@ -438,12 +440,12 @@ static int pca963x_probe(struct i2c_client *client,
438440
PCA963X_MODE2);
439441
/* Configure output: open-drain or totem pole (push-pull) */
440442
if (pdata->outdrv == PCA963X_OPEN_DRAIN)
441-
mode2 |= 0x01;
443+
mode2 &= ~PCA963X_MODE2_OUTDRV;
442444
else
443-
mode2 |= 0x05;
445+
mode2 |= PCA963X_MODE2_OUTDRV;
444446
/* Configure direction: normal or inverted */
445447
if (pdata->dir == PCA963X_INVERTED)
446-
mode2 |= 0x10;
448+
mode2 |= PCA963X_MODE2_INVRT;
447449
i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2,
448450
mode2);
449451
}

0 commit comments

Comments
 (0)