brcm2708: rename target to bcm27xx
[openwrt/staging/mkresin.git] / target / linux / bcm27xx / patches-4.19 / 950-0786-leds-pca963x-Fix-open-drain-initialization.patch
1 From 1738aaf187e0c8e97fbdd9661960b835f45e8985 Mon Sep 17 00:00:00 2001
2 From: Zahari Petkov <zahari@balena.io>
3 Date: Mon, 18 Nov 2019 23:02:55 +0200
4 Subject: [PATCH] leds: pca963x: Fix open-drain initialization
5
6 commit 697529091ac7a0a90ca349b914bb30641c13c753 upstream.
7
8 Before commit bb29b9cccd95 ("leds: pca963x: Add bindings to invert
9 polarity") Mode register 2 was initialized directly with either 0x01
10 or 0x05 for open-drain or totem pole (push-pull) configuration.
11
12 Afterwards, MODE2 initialization started using bitwise operations on
13 top of the default MODE2 register value (0x05). Using bitwise OR for
14 setting OUTDRV with 0x01 and 0x05 does not produce correct results.
15 When open-drain is used, instead of setting OUTDRV to 0, the driver
16 keeps it as 1:
17
18 Open-drain: 0x05 | 0x01 -> 0x05 (0b101 - incorrect)
19 Totem pole: 0x05 | 0x05 -> 0x05 (0b101 - correct but still wrong)
20
21 Now OUTDRV setting uses correct bitwise operations for initialization:
22
23 Open-drain: 0x05 & ~0x04 -> 0x01 (0b001 - correct)
24 Totem pole: 0x05 | 0x04 -> 0x05 (0b101 - correct)
25
26 Additional MODE2 register definitions are introduced now as well.
27
28 Fixes: bb29b9cccd95 ("leds: pca963x: Add bindings to invert polarity")
29 Signed-off-by: Zahari Petkov <zahari@balena.io>
30 Signed-off-by: Pavel Machek <pavel@ucw.cz>
31 ---
32 drivers/leds/leds-pca963x.c | 8 +++++---
33 1 file changed, 5 insertions(+), 3 deletions(-)
34
35 --- a/drivers/leds/leds-pca963x.c
36 +++ b/drivers/leds/leds-pca963x.c
37 @@ -43,6 +43,8 @@
38 #define PCA963X_LED_PWM 0x2 /* Controlled through PWM */
39 #define PCA963X_LED_GRP_PWM 0x3 /* Controlled through PWM/GRPPWM */
40
41 +#define PCA963X_MODE2_OUTDRV 0x04 /* Open-drain or totem pole */
42 +#define PCA963X_MODE2_INVRT 0x10 /* Normal or inverted direction */
43 #define PCA963X_MODE2_DMBLNK 0x20 /* Enable blinking */
44
45 #define PCA963X_MODE1 0x00
46 @@ -462,12 +464,12 @@ static int pca963x_probe(struct i2c_clie
47 PCA963X_MODE2);
48 /* Configure output: open-drain or totem pole (push-pull) */
49 if (pdata->outdrv == PCA963X_OPEN_DRAIN)
50 - mode2 |= 0x01;
51 + mode2 &= ~PCA963X_MODE2_OUTDRV;
52 else
53 - mode2 |= 0x05;
54 + mode2 |= PCA963X_MODE2_OUTDRV;
55 /* Configure direction: normal or inverted */
56 if (pdata->dir == PCA963X_INVERTED)
57 - mode2 |= 0x10;
58 + mode2 |= PCA963X_MODE2_INVRT;
59 i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2,
60 mode2);
61 }