linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooks <andrew.cooks@opengear.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Cc: platypus-sw@opengear.com, Andrew Cooks <andrew.cooks@opengear.com>
Subject: [PATCH] gpio-pca953x: fall back to byte-at-a-time for 24-bit io
Date: Tue,  5 Dec 2017 12:17:22 +1000	[thread overview]
Message-ID: <1512440242-8983-1-git-send-email-andrew.cooks@opengear.com> (raw)

Using TCA6424A with i2c-piix4 bus driver requires byte-at-a-time IO,
because the i2c-piix4 driver (and probably some SMBus controllers) don't
support I2C_SMBUS_I2C_BLOCK_DATA.

Signed-off-by: Andrew Cooks <andrew.cooks@opengear.com>
---
 drivers/gpio/gpio-pca953x.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 1b9dbf6..9e74934 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -205,11 +205,23 @@ static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 
 static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val)
 {
+	int ret, i;
 	int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
 
-	return i2c_smbus_write_i2c_block_data(chip->client,
+	if (i2c_check_functionality(chip->client->adapter,
+				    I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+		return i2c_smbus_write_i2c_block_data(chip->client,
 					      (reg << bank_shift) | REG_ADDR_AI,
 					      NBANK(chip), val);
+	} else {
+		for (i = 0; i < NBANK(chip); i++) {
+			ret = i2c_smbus_write_byte_data(chip->client,
+							(reg << 1) + i, val[i]);
+			if (ret < 0)
+				return ret;
+		}
+		return ret;
+	}
 }
 
 static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
@@ -249,7 +261,7 @@ static int pca953x_read_regs_24(struct pca953x_chip *chip, int reg, u8 *val)
 {
 	int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
 
-	return i2c_smbus_read_i2c_block_data(chip->client,
+	return i2c_smbus_read_i2c_block_data_or_emulated(chip->client,
 					     (reg << bank_shift) | REG_ADDR_AI,
 					     NBANK(chip), val);
 }
-- 
2.7.4


             reply	other threads:[~2017-12-05  2:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05  2:17 Andrew Cooks [this message]
2017-12-29  9:44 ` [PATCH] gpio-pca953x: fall back to byte-at-a-time for 24-bit io Andy Shevchenko
2018-01-29  4:11   ` Andrew Cooks
2018-02-08 12:10     ` Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512440242-8983-1-git-send-email-andrew.cooks@opengear.com \
    --to=andrew.cooks@opengear.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platypus-sw@opengear.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).