Skip to content

Commit bb29b9c

Browse files
daranderjacek-anaszewski
authored andcommitted
leds: pca963x: Add bindings to invert polarity
Add a new DT property, nxp,inverted-out, to invert the polarity of the output. Tested on PCA9634. Signed-off-by: Anders Darander <[email protected]> Acked-by: Pavel Machek <[email protected]> Signed-off-by: Jacek Anaszewski <[email protected]>
1 parent 2ea659a commit bb29b9c

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Documentation/devicetree/bindings/leds/pca963x.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Optional properties:
1010
- nxp,period-scale : In some configurations, the chip blinks faster than expected.
1111
This parameter provides a scaling ratio (fixed point, decimal divided
1212
by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.
13+
- nxp,inverted-out: invert the polarity of the generated PWM
1314

1415
Each led is represented as a sub-node of the nxp,pca963x device.
1516

drivers/leds/leds-pca963x.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
342342
if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
343343
chip->scaling = 1000;
344344

345+
/* default to non-inverted output, unless inverted is specified */
346+
if (of_property_read_bool(np, "nxp,inverted-out"))
347+
pdata->dir = PCA963X_INVERTED;
348+
else
349+
pdata->dir = PCA963X_NORMAL;
350+
345351
return pdata;
346352
}
347353

@@ -452,11 +458,18 @@ static int pca963x_probe(struct i2c_client *client,
452458
i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4));
453459

454460
if (pdata) {
461+
u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client,
462+
PCA963X_MODE2);
455463
/* Configure output: open-drain or totem pole (push-pull) */
456464
if (pdata->outdrv == PCA963X_OPEN_DRAIN)
457-
i2c_smbus_write_byte_data(client, PCA963X_MODE2, 0x01);
465+
mode2 |= 0x01;
458466
else
459-
i2c_smbus_write_byte_data(client, PCA963X_MODE2, 0x05);
467+
mode2 |= 0x05;
468+
/* Configure direction: normal or inverted */
469+
if (pdata->dir == PCA963X_INVERTED)
470+
mode2 |= 0x10;
471+
i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2,
472+
mode2);
460473
}
461474

462475
return 0;

include/linux/platform_data/leds-pca963x.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ enum pca963x_blink_type {
3333
PCA963X_HW_BLINK,
3434
};
3535

36+
enum pca963x_direction {
37+
PCA963X_NORMAL,
38+
PCA963X_INVERTED,
39+
};
40+
3641
struct pca963x_platform_data {
3742
struct led_platform_data leds;
3843
enum pca963x_outdrv outdrv;
3944
enum pca963x_blink_type blink_type;
45+
enum pca963x_direction dir;
4046
};
4147

4248
#endif /* __LINUX_PCA963X_H*/

0 commit comments

Comments
 (0)