]> git.sur5r.net Git - u-boot/blobdiff - drivers/gpio/pca953x_gpio.c
spi: mxc_spi: Fix chipselect on DM_SPI driver uclass
[u-boot] / drivers / gpio / pca953x_gpio.c
index b81f0fa90c2f04d98bce36ac2484ba43b5a1ed33..535b2f12eade9a920357518e6196da3e35ec0edd 100644 (file)
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Take linux kernel driver drivers/gpio/gpio-pca953x.c for reference.
  *
  * Copyright (C) 2016 Peng Fan <van.freenix@gmail.com>
  *
- * SPDX-License-Identifier:    GPL-2.0+
- *
  */
 
 /*
@@ -50,8 +49,6 @@ enum {
 #define MAX_BANK 5
 #define BANK_SZ 8
 
-DECLARE_GLOBAL_DATA_PTR;
-
 /*
  * struct pca953x_info - Data for pca953x
  *
@@ -123,7 +120,8 @@ static int pca953x_read_regs(struct udevice *dev, int reg, u8 *val)
                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);
+               ret = dm_i2c_read(dev, (reg << 3) | 0x80, val,
+                                 info->bank_count);
        } else {
                dev_err(dev, "Unsupported now\n");
                return -EINVAL;
@@ -143,7 +141,7 @@ static int pca953x_is_output(struct udevice *dev, int offset)
        return !(info->reg_direction[bank] & (1 << off));
 }
 
-static int pca953x_get_value(struct udevice *dev, unsigned offset)
+static int pca953x_get_value(struct udevice *dev, uint offset)
 {
        int ret;
        u8 val = 0;
@@ -157,8 +155,7 @@ static int pca953x_get_value(struct udevice *dev, unsigned offset)
        return (val >> off) & 0x1;
 }
 
-static int pca953x_set_value(struct udevice *dev, unsigned offset,
-                            int value)
+static int pca953x_set_value(struct udevice *dev, uint offset, int value)
 {
        struct pca953x_info *info = dev_get_platdata(dev);
        int bank = offset / BANK_SZ;
@@ -180,7 +177,7 @@ static int pca953x_set_value(struct udevice *dev, unsigned offset,
        return 0;
 }
 
-static int pca953x_set_direction(struct udevice *dev, unsigned offset, int dir)
+static int pca953x_set_direction(struct udevice *dev, uint offset, int dir)
 {
        struct pca953x_info *info = dev_get_platdata(dev);
        int bank = offset / BANK_SZ;
@@ -202,13 +199,12 @@ static int pca953x_set_direction(struct udevice *dev, unsigned offset, int dir)
        return 0;
 }
 
-static int pca953x_direction_input(struct udevice *dev, unsigned offset)
+static int pca953x_direction_input(struct udevice *dev, uint offset)
 {
        return pca953x_set_direction(dev, offset, PCA953X_DIRECTION_IN);
 }
 
-static int pca953x_direction_output(struct udevice *dev, unsigned offset,
-                                   int value)
+static int pca953x_direction_output(struct udevice *dev, uint offset, int value)
 {
        /* Configure output value. */
        pca953x_set_value(dev, offset, value);
@@ -219,7 +215,7 @@ static int pca953x_direction_output(struct udevice *dev, unsigned offset,
        return 0;
 }
 
-static int pca953x_get_function(struct udevice *dev, unsigned offset)
+static int pca953x_get_function(struct udevice *dev, uint offset)
 {
        if (pca953x_is_output(dev, offset))
                return GPIOF_OUTPUT;
@@ -228,10 +224,10 @@ static int pca953x_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int pca953x_xlate(struct udevice *dev, struct gpio_desc *desc,
-                        struct fdtdec_phandle_args *args)
+                        struct ofnode_phandle_args *args)
 {
        desc->offset = args->args[0];
-       desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
+       desc->flags = args->args[1] & (GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0);
 
        return 0;
 }
@@ -249,23 +245,14 @@ static int pca953x_probe(struct udevice *dev)
 {
        struct pca953x_info *info = dev_get_platdata(dev);
        struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
-       char name[32], *str;
+       char name[32], label[8], *str;
        int addr;
        ulong driver_data;
        int ret;
+       int size;
+       const u8 *tmp;
 
-       if (!info) {
-               dev_err(dev, "platdata not ready\n");
-               return -ENOMEM;
-       }
-
-       if (!chip) {
-               dev_err(dev, "i2c not ready\n");
-               return -ENODEV;
-       }
-
-       addr = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "reg", 0);
+       addr = dev_read_addr(dev);
        if (addr == 0)
                return -ENODEV;
 
@@ -299,7 +286,16 @@ static int pca953x_probe(struct udevice *dev)
                return ret;
        }
 
-       snprintf(name, sizeof(name), "gpio@%x_", info->addr);
+       tmp = dev_read_prop(dev, "label", &size);
+
+       if (tmp) {
+               memcpy(label, tmp, sizeof(label) - 1);
+               label[sizeof(label) - 1] = '\0';
+               snprintf(name, sizeof(name), "%s@%x_", label, info->addr);
+       } else {
+               snprintf(name, sizeof(name), "gpio@%x_", info->addr);
+       }
+
        str = strdup(name);
        if (!str)
                return -ENOMEM;