]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/gpio/pca953x_gpio.c
dm: core: Replace of_offset with accessor
[people/ms/u-boot.git] / drivers / gpio / pca953x_gpio.c
index 987d10e967e4f8475d690292bb66205a61922855..b81f0fa90c2f04d98bce36ac2484ba43b5a1ed33 100644 (file)
@@ -16,8 +16,8 @@
  *
  * TODO:
  * 1. Support PCA957X_TYPE
- * 2. Support max 40 gpio pins
- * 3. Support Plolarity Inversion
+ * 2. Support 24 gpio pins
+ * 3. Support Polarity Inversion
  */
 
 #include <common.h>
@@ -47,7 +47,7 @@ enum {
        PCA953X_DIRECTION_OUT,
 };
 
-#define MAX_BANK 3
+#define MAX_BANK 5
 #define BANK_SZ 8
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -121,6 +121,9 @@ static int pca953x_read_regs(struct udevice *dev, int reg, u8 *val)
                ret = dm_i2c_read(dev, reg, val, 1);
        } else if (info->gpio_count <= 16) {
                ret = dm_i2c_read(dev, reg << 1, val, info->bank_count);
+       } else if (info->gpio_count == 40) {
+               /* Auto increment */
+               ret = dm_i2c_read(dev, (reg << 3) | 0x80, val, info->bank_count);
        } else {
                dev_err(dev, "Unsupported now\n");
                return -EINVAL;
@@ -145,11 +148,13 @@ static int pca953x_get_value(struct udevice *dev, unsigned offset)
        int ret;
        u8 val = 0;
 
+       int off = offset % BANK_SZ;
+
        ret = pca953x_read_single(dev, PCA953X_INPUT, &val, offset);
        if (ret)
                return ret;
 
-       return (val >> offset) & 0x1;
+       return (val >> off) & 0x1;
 }
 
 static int pca953x_set_value(struct udevice *dev, unsigned offset,
@@ -260,7 +265,7 @@ static int pca953x_probe(struct udevice *dev)
                return -ENODEV;
        }
 
-       addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "reg", 0);
+       addr = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "reg", 0);
        if (addr == 0)
                return -ENODEV;