leds: pca963x: Add bindings to invert polarity
authorAnders Darander <anders@chargestorm.se>
Thu, 27 Apr 2017 06:37:33 +0000 (08:37 +0200)
committerJacek Anaszewski <jacek.anaszewski@gmail.com>
Sun, 14 May 2017 11:01:29 +0000 (13:01 +0200)
Add a new DT property, nxp,inverted-out, to invert the polarity
of the output.

Tested on PCA9634.

Signed-off-by: Anders Darander <anders@chargestorm.se>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Documentation/devicetree/bindings/leds/pca963x.txt
drivers/leds/leds-pca963x.c
include/linux/platform_data/leds-pca963x.h

index dfbdb123a9bfcbc4992a34c5f96afd52b62340fa..4eee41482041f50f6267a05e3c8090f645cf00c9 100644 (file)
@@ -10,6 +10,7 @@ Optional properties:
 - nxp,period-scale : In some configurations, the chip blinks faster than expected.
                     This parameter provides a scaling ratio (fixed point, decimal divided
                     by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.
+- nxp,inverted-out: invert the polarity of the generated PWM
 
 Each led is represented as a sub-node of the nxp,pca963x device.
 
index ded1e4dac36af465c9a0dd5833965ae3a3ef6275..3bf9a127181927d84f374c1b60cc9373dafad149 100644 (file)
@@ -342,6 +342,12 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
        if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
                chip->scaling = 1000;
 
+       /* default to non-inverted output, unless inverted is specified */
+       if (of_property_read_bool(np, "nxp,inverted-out"))
+               pdata->dir = PCA963X_INVERTED;
+       else
+               pdata->dir = PCA963X_NORMAL;
+
        return pdata;
 }
 
@@ -452,11 +458,18 @@ static int pca963x_probe(struct i2c_client *client,
        i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4));
 
        if (pdata) {
+               u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client,
+                                                   PCA963X_MODE2);
                /* Configure output: open-drain or totem pole (push-pull) */
                if (pdata->outdrv == PCA963X_OPEN_DRAIN)
-                       i2c_smbus_write_byte_data(client, PCA963X_MODE2, 0x01);
+                       mode2 |= 0x01;
                else
-                       i2c_smbus_write_byte_data(client, PCA963X_MODE2, 0x05);
+                       mode2 |= 0x05;
+               /* Configure direction: normal or inverted */
+               if (pdata->dir == PCA963X_INVERTED)
+                       mode2 |= 0x10;
+               i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2,
+                                         mode2);
        }
 
        return 0;
index e731f0036329c424dfe31d85d0d9224e65dfc67e..54e845ffb5edebf269a58a3224a3bdc41f13e5cb 100644 (file)
@@ -33,10 +33,16 @@ enum pca963x_blink_type {
        PCA963X_HW_BLINK,
 };
 
+enum pca963x_direction {
+       PCA963X_NORMAL,
+       PCA963X_INVERTED,
+};
+
 struct pca963x_platform_data {
        struct led_platform_data leds;
        enum pca963x_outdrv outdrv;
        enum pca963x_blink_type blink_type;
+       enum pca963x_direction dir;
 };
 
 #endif /* __LINUX_PCA963X_H*/