summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorYe Li <ye.li@nxp.com>2017-08-18 01:57:43 -0500
committerYe Li <ye.li@nxp.com>2018-04-27 02:21:24 -0700
commite799a09b72f81f0e2d580220ceeec31cf808fd74 (patch)
tree72c38021baa9720000c90637ad37009142056a09 /drivers/gpio
parent29aa878ffb740a31a932a582e27dc0ea3c0d45e3 (diff)
MLK-16219 pca953x_gpio: Clear the polarity invert register at init
The pca953x_gpio driver uses default value of polarity inversion register. For some devices like PCA9557 and MAX7310, their polarity inversion register default value is 0xf0. So for high 4 ports, when reading their values, the values are inverted as the actual level. This patch clears the polarity inversion register to 0 at init. So that the port read and write values are aligned. Signed-off-by: Ye Li <ye.li@nxp.com> Acked-by: Fugang Duan <fugang.duan@nxp.com> Acked-by: Peng Fan <peng.fan@nxp.com> (cherry picked from commit cc4e6b3786671ec2ce2ea74dc6334f72587cc756)
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/pca953x_gpio.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/gpio/pca953x_gpio.c b/drivers/gpio/pca953x_gpio.c
index 08742f90c6..b1be6db85b 100644
--- a/drivers/gpio/pca953x_gpio.c
+++ b/drivers/gpio/pca953x_gpio.c
@@ -131,6 +131,26 @@ static int pca953x_read_regs(struct udevice *dev, int reg, u8 *val)
return ret;
}
+static int pca953x_write_regs(struct udevice *dev, int reg, u8 *val)
+{
+ struct pca953x_info *info = dev_get_platdata(dev);
+ int ret = 0;
+
+ if (info->gpio_count <= 8) {
+ ret = dm_i2c_write(dev, reg, val, 1);
+ } else if (info->gpio_count <= 16) {
+ ret = dm_i2c_write(dev, reg << 1, val, info->bank_count);
+ } else if (info->gpio_count == 40) {
+ /* Auto increment */
+ ret = dm_i2c_write(dev, (reg << 3) | 0x80, val, info->bank_count);
+ } else {
+ dev_err(dev, "Unsupported now\n");
+ return -EINVAL;
+ }
+
+ return ret;
+}
+
static int pca953x_is_output(struct udevice *dev, int offset)
{
struct pca953x_info *info = dev_get_platdata(dev);
@@ -252,6 +272,7 @@ static int pca953x_probe(struct udevice *dev)
int ret;
int size;
const u8 *tmp;
+ u8 val[MAX_BANK];
addr = dev_read_addr(dev);
if (addr == 0)
@@ -287,6 +308,14 @@ static int pca953x_probe(struct udevice *dev)
return ret;
}
+ /* Clear the polarity registers to no invert */
+ memset(val, 0, MAX_BANK);
+ ret = pca953x_write_regs(dev, PCA953X_INVERT, val);
+ if (ret) {
+ dev_err(dev, "Error writing invert register\n");
+ return ret;
+ }
+
tmp = dev_read_prop(dev, "label", &size);
if (tmp) {