[U-Boot] Fwd: [PATCH 1/1] gpio: pca953x: Fix support chips with 24 GPIOs
Максим Паймушкин
maxim.paymushkin at gmail.com
Mon Jul 17 23:32:19 UTC 2017
---------- Переадресованное сообщение ----------
От: "Maxim Paymushkin" <maxim.paymushkin at gmail.com>
Дата: 15 июл. 2017 г. 19:12
Тема: [PATCH 1/1] gpio: pca953x: Fix support chips with 24 GPIOs
Кому: <u-boot-patches at bugs.denx.de>
Копия: "Maxim Paymushkin" <maxim.paymushkin at gmail.com>
A bug in the pca953x driver prevents correct detection the chips
with 24 GPIOs.
Generalized function of reading register for all implemented chips.
This patch fixes the reading behaviour.
---
drivers/gpio/pca953x_gpio.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/gpio/pca953x_gpio.c b/drivers/gpio/pca953x_gpio.c
index 4962f25..7122774 100644
--- a/drivers/gpio/pca953x_gpio.c
+++ b/drivers/gpio/pca953x_gpio.c
@@ -35,6 +35,8 @@
#define PCA953X_INVERT 2
#define PCA953X_DIRECTION 3
+#define REG_ADDR_AI 0x80
+
#define PCA_GPIO_MASK 0x00FF
#define PCA_INT 0x0100
#define PCA953X_TYPE 0x1000
@@ -115,19 +117,15 @@ static int pca953x_read_single(struct udevice *dev,
int reg, u8 *val,
static int pca953x_read_regs(struct udevice *dev, int reg, u8 *val)
{
struct pca953x_info *info = dev_get_platdata(dev);
+ int bank_shift = fls((info->gpio_count - 1) / BANK_SZ);
int ret = 0;
- if (info->gpio_count <= 8) {
- 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;
- }
+ reg <<= bank_shift;
+
+ if (info->gpio_count >= BANK_SZ * 3)
+ reg |= REG_ADDR_AI;
+
+ ret = dm_i2c_read(dev, reg, val, info->bank_count);
return ret;
}
--
2.7.4
More information about the U-Boot
mailing list