]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/gpio/pca953x.c
Add more SPDX-License-Identifier tags
[people/ms/u-boot.git] / drivers / gpio / pca953x.c
index be1374592151b415c428182340a463c3c48492e0..932dfe9f34e1238768c9e30b1d950fb137fa0610 100644 (file)
@@ -1,19 +1,7 @@
 /*
  * Copyright 2008 Extreme Engineering Solutions, Inc.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * Version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 /*
@@ -47,9 +35,6 @@ struct pca953x_chip_ngpio {
 static struct pca953x_chip_ngpio pca953x_chip_ngpios[] =
     CONFIG_SYS_I2C_PCA953X_WIDTH;
 
-#define NUM_CHIP_GPIOS (sizeof(pca953x_chip_ngpios) / \
-                       sizeof(struct pca953x_chip_ngpio))
-
 /*
  * Determine the number of GPIO pins supported. If we don't know we assume
  * 8 pins.
@@ -58,7 +43,7 @@ static int pca953x_ngpio(uint8_t chip)
 {
        int i;
 
-       for (i = 0; i < NUM_CHIP_GPIOS; i++)
+       for (i = 0; i < ARRAY_SIZE(pca953x_chip_ngpios); i++)
                if (pca953x_chip_ngpios[i].chip == chip)
                        return pca953x_chip_ngpios[i].ngpio;
 
@@ -91,8 +76,10 @@ static int pca953x_reg_write(uint8_t chip, uint addr, uint mask, uint data)
                if (i2c_read(chip, addr << 1, 1, (u8*)&valw, 2))
                        return -1;
 
+               valw = le16_to_cpu(valw);
                valw &= ~mask;
                valw |= data;
+               valw = cpu_to_le16(valw);
 
                return i2c_write(chip, addr << 1, 1, (u8*)&valw, 2);
        }
@@ -110,7 +97,7 @@ static int pca953x_reg_read(uint8_t chip, uint addr, uint *data)
        } else {
                if (i2c_read(chip, addr << 1, 1, (u8*)&valw, 2))
                        return -1;
-               *data = (int)valw;
+               *data = (uint)le16_to_cpu(valw);
        }
        return 0;
 }