linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: Linux I2C <linux-i2c@vger.kernel.org>
Cc: Wolfram Sang <wsa@kernel.org>
Subject: [PATCH 3/7] i2cget: Add support for SMBus block read
Date: Tue, 8 Jun 2021 17:29:59 +0200	[thread overview]
Message-ID: <20210608172959.6d773000@endymion> (raw)
In-Reply-To: <20210608172338.0cf520a1@endymion>

Now that i2cget supports I2C block read, adding support for SMBus
block read is trivial. This restores the symmetry between i2cset and
i2cget, and paves the road for the removal of SMBus block read
support from i2cdump.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
 tools/i2cget.8 |    6 +++---
 tools/i2cget.c |   18 ++++++++++++++++--
 2 files changed, 19 insertions(+), 5 deletions(-)

--- i2c-tools.orig/tools/i2cget.c	2021-06-08 16:47:56.290473081 +0200
+++ i2c-tools/tools/i2cget.c	2021-06-08 16:47:58.553503929 +0200
@@ -1,6 +1,6 @@
 /*
     i2cget.c - A user-space program to read an I2C register.
-    Copyright (C) 2005-2012  Jean Delvare <jdelvare@suse.de>
+    Copyright (C) 2005-2021  Jean Delvare <jdelvare@suse.de>
 
     Based on i2cset.c:
     Copyright (C) 2001-2003  Frodo Looijaard <frodol@dds.nl>, and
@@ -48,6 +48,7 @@ static void help(void)
 		"    b (read byte data, default)\n"
 		"    w (read word data)\n"
 		"    c (write byte/read byte)\n"
+		"    s (read SMBus block data)\n"
 		"    i (read I2C block data)\n"
 		"    Append p for SMBus PEC\n"
 		"  LENGTH is the I2C block data length\n");
@@ -92,6 +93,13 @@ static int check_funcs(int file, int siz
 		}
 		break;
 
+	case I2C_SMBUS_BLOCK_DATA:
+		if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
+			fprintf(stderr, MISSING_FUNC_FMT, "SMBus read block data");
+			return -1;
+		}
+		break;
+
 	case I2C_SMBUS_I2C_BLOCK_DATA:
 		if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus read I2C block data");
@@ -149,6 +157,7 @@ static int confirm(const char *filename,
 			size == I2C_SMBUS_BYTE ? (daddress < 0 ?
 			"read byte" : "write byte/read byte") :
 			size == I2C_SMBUS_BYTE_DATA ? "read byte data" :
+			size == I2C_SMBUS_BLOCK_DATA ? "read SMBus block data" :
 			"read word data");
 	if (pec)
 		fprintf(stderr, "PEC checking enabled.\n");
@@ -224,6 +233,7 @@ int main(int argc, char *argv[])
 		case 'b': size = I2C_SMBUS_BYTE_DATA; break;
 		case 'w': size = I2C_SMBUS_WORD_DATA; break;
 		case 'c': size = I2C_SMBUS_BYTE; break;
+		case 's': size = I2C_SMBUS_BLOCK_DATA; break;
 		case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break;
 		default:
 			fprintf(stderr, "Error: Invalid mode!\n");
@@ -278,6 +288,9 @@ int main(int argc, char *argv[])
 	case I2C_SMBUS_WORD_DATA:
 		res = i2c_smbus_read_word_data(file, daddress);
 		break;
+	case I2C_SMBUS_BLOCK_DATA:
+		res = i2c_smbus_read_block_data(file, daddress, block_data);
+		break;
 	case I2C_SMBUS_I2C_BLOCK_DATA:
 		res = i2c_smbus_read_i2c_block_data(file, daddress, length, block_data);
 		break;
@@ -291,7 +304,8 @@ int main(int argc, char *argv[])
 		exit(2);
 	}
 
-	if (size == I2C_SMBUS_I2C_BLOCK_DATA) {
+	if (size == I2C_SMBUS_BLOCK_DATA ||
+	    size == I2C_SMBUS_I2C_BLOCK_DATA) {
 		int i;
 
 		for (i = 0; i < res - 1; ++i)
--- i2c-tools.orig/tools/i2cget.8	2021-06-08 16:47:58.553503929 +0200
+++ i2c-tools/tools/i2cget.8	2021-06-08 16:48:35.473009351 +0200
@@ -50,9 +50,9 @@ will be read (if that makes sense for th
 .PP
 The \fImode\fR parameter, if specified, is one of the letters \fBb\fP,
 \fBw\fP, \fBc\fP, or \fBi\fP, corresponding to a read byte data, a read
-word data, a write byte/read byte, or a read I2C block transaction,
-respectively. A \fBp\fP can also be appended to the \fImode\fR parameter to
-enable PEC, except for I2C block transactions. If the \fImode\fR
+word data, a write byte/read byte, a read SMBus block, or a read I2C block
+transaction, respectively. A \fBp\fP can also be appended to the \fImode\fR
+parameter to enable PEC, except for I2C block transactions. If the \fImode\fR
 parameter is omitted,
 i2cget defaults to a read byte data transaction, unless \fIdata-address\fR is
 also omitted, in which case the default (and only valid) transaction is a

-- 
Jean Delvare
SUSE L3 Support

  parent reply	other threads:[~2021-06-08 15:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 15:23 [PATCH 0/7] Rework block read support among i2cget and i2cdump Jean Delvare
2021-06-08 15:28 ` [PATCH 1/7] i2cget: Add support for I2C block data Jean Delvare
2021-06-27 10:11   ` Wolfram Sang
2021-07-12  9:36     ` Jean Delvare
2021-06-08 15:29 ` [PATCH 2/7] i2cget: Document the support of I2C block reads Jean Delvare
2021-06-08 15:29 ` Jean Delvare [this message]
2021-06-08 15:30 ` [PATCH 4/7] i2cdump: Remove dead code Jean Delvare
2021-06-08 15:30 ` [PATCH 5/7] i2cdump: Add range support with mode i (I2C block) Jean Delvare
2021-06-08 15:31 ` [PATCH 6/7] i2cdump: Deprecate SMBus block mode Jean Delvare
2021-06-08 15:32 ` [PATCH 7/7] i2cdump: Remove support for " Jean Delvare
2021-06-26 15:30 ` [PATCH 0/7] Rework block read support among i2cget and i2cdump Wolfram Sang
2021-07-12  9:58   ` Jean Delvare
2021-07-19 15:19     ` Wolfram Sang
2021-06-27 10:27 ` Wolfram Sang
2021-07-13  8:21   ` 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=20210608172959.6d773000@endymion \
    --to=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@kernel.org \
    /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).